﻿
function changecss(src) {
    //alert(src.className);

    if (src.id.indexOf("lbtnRecent") > -1) {
        src.className = "recentSelected";
        document.getElementById("lnkpopular").className = "popular";
        document.getElementById("lnkunans").className = "unAnswered";
        document.getElementById("lnkfeatured").className = "featured";
    }
    else if (src.id.indexOf("lnkpopular") > -1) {
        src.className = "popularSelected";
        document.getElementById("lnkrecent").className = "recent";
        document.getElementById("lnkunans").className = "unAnswered";
        document.getElementById("lnkfeatured").className = "featured";
    }
    else if (src.id.indexOf("lnkunans") > -1) {
        src.className = "unAnsweredSelected";
        document.getElementById("lnkrecent").className = "recent";
        document.getElementById("lnkpopular").className = "popular";
        document.getElementById("lnkfeatured").className = "featured";
    }
    else if (src.id.indexOf("lnkfeatured") > -1) {
        src.className = "featuredSelected";
        document.getElementById("lnkpopular").className = "popular";
        document.getElementById("lnkunans").className = "unAnswered";
        document.getElementById("lnkrecent").className = "recent";

    }

}

function openWindow() {

    var wind = window.open('', 'welcome', 'width=300,height=200,menubar=no,status=no,location=yes,toolbar=no,scrollbars=no;resizable=no');
    wind.document.write("<h3>Comming soon.</h3>");
}

function populateImage(src) {

    if (src.value.toLowerCase().indexOf("jpg") > 0 || src.value.toLowerCase().indexOf("jpeg") > 0 || src.value.toLowerCase().indexOf("png") > 0 || src.value.toLowerCase().indexOf("gif") > 0) {
        /*
        document.getElementById("img").src = "images/tempImages/"+ src.value;
        document.getElementById("img").alt = src.value.substring(src.value.lastIndexOf("/"));
        */
        return true;
    }
    else {
        src.value = "";
        alert("Only jpg and png Images not larger then 2Mb, are allowed.");
        return false;
    }
}


var popupStatus = 0;

//loading popup with jQuery magic!  
function loadPopup(popupId) {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        if (document.getElementById("backgroundPopup") != null) {
            $("#backgroundPopup").css(
            {
                "opacity": "0.7"
            });

            $("#backgroundPopup").fadeIn("slow");
        }
        else {
            $("#backgroundUW").css(
            {
                "opacity": "0.7"
            });

            $("#backgroundUW").fadeIn("slow");
        }
        $("#" + popupId).fadeIn("slow");

        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!  
function disablePopup() {
    //disables popup only if it is enabled  
    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");

        if (document.getElementById("backgroundUW") != null) {
            $("#backgroundUW").fadeOut("slow");
        }

        if (document.getElementById("popupSpam") != null) {
            $("#popupSpam").fadeOut("slow");
        }

        /*
        alert($("#popupSpam"));
        alert($("#popupCategory"));
        */


        $("#popupCategory").css("display", "none");

        if (document.getElementById("popupUW") != null) {
            $("#popupUW").fadeOut("slow");
        }
        /*
            
        $("#popupCategory").css("visiblity", "hidden"); 
        $("#popupCategory").hide();
            
        $("#popupCategory").css(
        {
        "visibility": "hidden",
        "display":"none"
        });
        */

        popupStatus = 0;
    }
}


function centerPopup(popupid) {
    //request data for centering  
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#" + popupid).height();
    var popupWidth = $("#" + popupid).width();
    //centering  
    $("#" + popupid).css(
        {
            "position": "fixed",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });
    //only need force for IE6  

    //$("#"+ popupid).focus();
        if (document.getElementById("backgroundPopup") != null) {
            $("#backgroundPopup").css(
        {
            "height": windowHeight
        });
        }
        else {
            $("#backgroundUW").css(
        {
            "height": windowHeight
        });
        }


}


//disable enter button
function disableEnter(e) {
    if (e.keyCode) {
        keycode = e.keyCode;
    }
    else {
        keycode = e.which;
    }

    char = String.fromCharCode(keycode);
    xCode = char.charCodeAt(0);

    //Enter key is pressed!!
    if (xCode == 13) {
        //window.event.keyCode = 0;
        e.preventDefault ? e.preventDefault() : e.returnValue = false;
    }
    else {
        return true;
    }
}
