﻿function GetSearch(sstr) {
    if (sstr != 'Search') {
        location.href = '/productList.aspx?p=search&catID=0&subID=0&sstr=' + sstr;
    }
    else {
        document.getElementById('divMsg').style.display = 'block';
        document.getElementById('divMsgTitle').innerHTML = 'Search Message';
        document.getElementById('divMsgBody').innerHTML = '<table><tr><td>Please enter the items your are searching for in the Search box!<br /><br /></td></tr><tr><td align=right><a href="javascript:;" onclick="CloseMsg(\'txtSearch\', 0);return false;">Close</a></td></tr></table>';
    }
}
function CloseMsg(obj, oType) {
    document.getElementById('divMsg').style.display = 'none';
    if (oType == 0) {
        $get(obj).focus();
    }
}
function GetOptionSelected(ProdID) {
    location.href = "/category.aspx?AddID=" + ProdID + "&opt1=" + document.getElementById('List1').value + "&opt2=" + document.getElementById('List2').value;
}
function ChangeImg(objImg,objID,objType){
    document.getElementById(objImg).src = "/img/list/opt" + objID + objType + ".jpg";
}

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        $("#popupContact").fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup() {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();
    //centering
    $("#popupContact").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    //only need force for IE6

    $("#backgroundPopup").css({
        "height": windowHeight
    });

}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {

    //LOADING POPUP
    //Click the button event!
    $("#popupButton").click(function() {
    //centering with css
        centerPopup();
        //load popup
        loadPopup();
    });

    //CLOSING POPUP
    //Click the x event!
    $("#popupContactClose").click(function() {
        disablePopup();
    });
    //Click out event!
    $("#backgroundPopup").click(function() {
        disablePopup();
    });
    //Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });

});
function changeImage(obj) {
    document.getElementById('ctl00_Cph_imgProduct').src = "/img/detail/opt" + obj.value + ".jpg";
    var prodName = obj.options[obj.selectedIndex].text;
    var pos1 = prodName.indexOf("(") + 1;
    var pos2 = prodName.indexOf(")");
    var newPrice = prodName.substring(pos1, pos2);
    document.getElementById('ctl00_Cph_plProductPrice').innerHTML = newPrice;
    document.getElementById('spProdSubTitle').innerHTML = " - " + prodName;
    clrActiveSub();
    document.getElementById('liSubImageID_' + obj.value).className = 'active';
}
function clrActiveSub() {
    arrID = curIDList.split(",");
    for (var i = 0; i < arrID.length; i++) {
        try {
            document.getElementById('liSubImageID_' + arrID[i]).className = '';
        }
        catch (objErr) {}
    }
}
function chgClass(oNewClass, oObject, oID) {
    if (oID != curID) {
        oObject.className = oNewClass;
    }
}
function ChgByImg(oID) {
    newObj = document.getElementById('ctl00_Cph_Options_List');
    for (i = 0; i < newObj.length; i++) {
        if (newObj.options[i].value == oID) {
            document.getElementById('ctl00_Cph_Options_List').selectedIndex = i;
            break;
        }
    }
    curID = oID;
    changeImage(document.getElementById('ctl00_Cph_Options_List'));
}
function emailCheck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false
	 }

	 return true					
}

