var OpenWin;

function productDetail(frmObj,linkurl,prodcode,groupcode)
{
var strProdCode = prodcode;
var strGroupCode = groupcode;
if (frmObj){
	var strCboProduct = frmObj.value;
	//alert (strCboProduct);
	var strProdValues = strCboProduct.split("|");
	strProdCode = strProdValues[0];
	
}
document.location.href ="productdetails.aspx?"+linkurl+'&hdnGroupCode='+strGroupCode+'&hdnProdCode='+strProdCode
}


function addToCart(mem, linkurl) {
    var blnSubmit = false;
    var blnValidate = true;
    
    if (!document.getElementsByName("chkProductCode")) {
        alert("No Products To Select")
    }
    else {
        if (document.getElementsByName("chkProductCode").length==1) {
            if (document.frmProduct.chkProductCode.checked == true) {
                var qtybox = document.frmProduct.txtQty.value;
                var perm = document.frmProduct.hdnProductPerM.value;
                var custtxt;
                if (document.getElementById("hdncusttext0").value == 'Y') {
                    custtxt = document.getElementById("txtCustom0");
                }
                blnValidate = true;
                if (qtybox == '' || qtybox == 0 || qtybox < 0) {

                    alert("Please specify the quantity to be added to the Shopping Cart");
                    document.frmProduct.txtQty.focus();
                    blnValidate = false;
                    return;
                }
                else if (isNaN(qtybox)) {
                    alert("Invalid quantity value. Please enter a proper quantity.");
                    document.frmProduct.txtQty.focus();
                    blnValidate = false;
                    return;
                }
                else if (qtybox.indexOf(".") != -1) {
                    alert("Please do not enter decimal values.");
                    document.frmProduct.txtQty.focus();
                    blnValidate = false;
                    return;
                }
                else if (custtxt != null) {
                    if (document.getElementById("txtCustom0").value == "") {
                        alert("Please enter in the text to be added to the sign.");
                        document.getElementById("txtCustom0").focus();
                        blnValidate = false;
                        return;
                    }
                    else if (document.getElementById("txtCustom0").value.charAt(0) == ' ') {
                        alert("You have not entered this field properly.\nPlease remove the leading spaces");
                        document.getElementById("txtCustom0").focus();
                        blnValidate = false;
                        return;
                    }
                    else if (perm == 'T') {

                        var strProdCode = document.frmProduct.hdnProductCode.value;
                        var strGroupCode = document.frmProduct.hdnGroupCode.value;
                        alert(strProdCode + ',' + strGroupCode);
                        objCbo = 'document.frmProduct.cboProducts' + eval(i);
                        if (eval(objCbo)) {

                            strCboProduct = eval(objCbo);
                            strCboProduct = strCboProduct.value;
                            var strProdValues = strCboProduct.split("|");
                            strProdCode = strProdValues[0];
                        }
                        blnValidate = false;
                        document.location.href = "productdetails.aspx?" + linkurl + '&hdnGroupCode=' + strGroupCode + '&hdnProdCode=' + strProdCode
                        return;
                    }
                    else {

                        blnSubmit = true;
                    }
                }
                else if (perm == 'T') {
                var strProdCode = document.frmProduct.hdnProductCode.value;
                var strGroupCode = document.frmProduct.hdnGroupCode.value;

                    objCbo = 'document.frmProduct.cboProducts' + eval(i);
                    if (eval(objCbo)) {

                        strCboProduct = eval(objCbo);
                        strCboProduct = strCboProduct.value;
                        var strProdValues = strCboProduct.split("|");
                        strProdCode = strProdValues[0];
                    }
                    blnValidate = false;
                    document.location.href = "productdetails.aspx?" + linkurl + '&hdnGroupCode=' + strGroupCode + '&hdnProdCode=' + strProdCode
                    return;
                }
                else {

                    blnSubmit = true;
                }

            }
        }
        else {
            for (var i = 0; i < document.getElementsByName("chkProductCode").length; i++) {
                if (document.frmProduct.chkProductCode[i].checked == true) {
                    var qtybox = document.frmProduct.txtQty[i].value;
                    var perm = document.frmProduct.hdnProductPerM[i].value;
                    var custtxt;
                    if (document.getElementById("hdncusttext" + i).value == 'Y') {
                        custtxt = document.getElementById("txtCustom" + i);
                    }
                    blnValidate = true;
                    if (qtybox == '' || qtybox == 0 || qtybox < 0) {
                        alert("Please specify the quantity to be added to the Shopping Cart");
                        document.frmProduct.txtQty[i].focus();
                        blnValidate = false;
                        return;
                    }
                    else if (isNaN(qtybox)) {
                        alert("Invalid quantity value. Please enter a proper quantity.");
                        document.frmProduct.txtQty[i].focus();
                        blnValidate = false;
                        return;
                    }
                    else if (qtybox.indexOf(".") != -1) {
                        alert("Please do not enter decimal values.");
                        document.frmProduct.txtQty[i].focus();
                        blnValidate = false;
                        return;
                    }
                    else if (custtxt != null) {
                    if (document.getElementById("txtCustom" + i).value == "") {
                            alert("Please enter in the text to be added to the sign.");
                            document.getElementById("txtCustom" + i).focus();
                            blnValidate = false;
                            return;
                        }
                        else if (document.getElementById("txtCustom" + i).value.charAt(0) == ' ') {
                            alert("You have not entered this field properly.\nPlease remove the leading spaces");
                            document.getElementById("txtCustom" + i).focus();
                            blnValidate = false;
                            return;
                        }
                        else if (perm == 'T') {
                            var strProdCode = document.frmProduct.hdnProductCode[i].value;
                            var strGroupCode = document.frmProduct.hdnGroupCode[i].value;
                            objCbo = 'document.frmProduct.cboProducts' + eval(i);
                            if (eval(objCbo)) {

                                strCboProduct = eval(objCbo);
                                strCboProduct = strCboProduct.value;
                                var strProdValues = strCboProduct.split("|");
                                strProdCode = strProdValues[0];
                            }
                            blnValidate = false;
                            document.location.href = "productdetails.aspx?" + linkurl + '&hdnGroupCode=' + strGroupCode + '&hdnProdCode=' + strProdCode
                            return;

                        }

                        else {

                            blnSubmit = true;
                        }
                    }
                    else if (perm == 'T') {
                        var strProdCode = document.frmProduct.hdnProductCode[i].value;
                        var strGroupCode = document.frmProduct.hdnGroupCode[i].value;
                        objCbo = 'document.frmProduct.cboProducts' + eval(i);
                        if (eval(objCbo)) {

                            strCboProduct = eval(objCbo);
                            strCboProduct = strCboProduct.value;
                            var strProdValues = strCboProduct.split("|");
                            strProdCode = strProdValues[0];
                        }
                        blnValidate = false;
                        document.location.href = "productdetails.aspx?" + linkurl + '&hdnGroupCode=' + strGroupCode + '&hdnProdCode=' + strProdCode
                        return;

                    }

                    else {

                        blnSubmit = true;
                    }
                }
            }
        }
        if (blnValidate == true) {

            if (blnSubmit == false) {
                alert("Please select at least one product to add to your shopping cart.");
            }
            else {

                if (document.getElementsByName("chkProductCode").length==1) {
                    strProdCode = document.frmProduct.chkProductCode.value;
                    var strPrice = document.frmProduct.hdnProductPrice.value;
                    var ctext = "";
                    if (document.getElementById("hdncusttext0").value == 'Y') {
                        ctext = document.getElementById("txtCustom0").value;
                    }
                    objCbo = document.frmProduct.cboProducts0;

                    if (objCbo) {
                        strCboProduct = objCbo;
                        strCboProduct = strCboProduct.value;
                        strProdValues = strCboProduct.split("|");
                        strProdCode = strProdValues[0];
                        strPrice = strProdValues[1];
                    }

                    document.frmProduct.chkProductCode.value = strProdCode + '|' + document.frmProduct.txtQty.value + '|' + strPrice + '|0|0||' + ctext;



                }
                else {
                    for (var i = 0; i < document.getElementsByName("chkProductCode").length; i++) {
                        if (document.frmProduct.chkProductCode[i].checked == true) {

                            strProdCode = document.frmProduct.chkProductCode[i].value;
                            var strPrice = document.frmProduct.hdnProductPrice[i].value;
                            var ctext = "";
                            if (document.getElementById("hdncusttext" + i).value == 'Y') {
                                ctext = document.getElementById("txtCustom" + i).value;
                            }
                            objCbo = 'document.frmProduct.cboProducts' + eval(i);
                            if (eval(objCbo)) {
                                strCboProduct = eval(objCbo);
                                strCboProduct = strCboProduct.value;
                                strProdValues = strCboProduct.split("|");
                                strProdCode = strProdValues[0];
                                strPrice = strProdValues[1];
                            }
                            document.frmProduct.chkProductCode[i].value = strProdCode + '|' + document.frmProduct.txtQty[i].value + '|' + strPrice + '|0|0||' + ctext;
                            //alert(document.frmProduct.chkProductCode[i].value);
                        }
                    }
                }
                document.getElementById("hdnCart").value = "addCartMultiple";
                document.frmProduct.submit();
            }
        }
    }

}


function getOtherProduct(teaser, strGroupCode, linkurl) {
    //alert(teaser);
    var e = document.getElementById("cboProducts" + teaser);
    if (e) {
        var strCboProduct = e.options[e.selectedIndex].value;
        //alert (strCboProduct);
        var strProdValues = strCboProduct.split("|");
        //alert(strProdValues);
        var strProdCode = strProdValues[0];
    }
    //alert (linkurl);
    if (linkurl != '') {
        document.location.href = "productdetails.aspx?" + linkurl + '&hdnGroupCode=' + strGroupCode + '&hdnProdCode=' + strProdCode;
    }
    else {
        document.location.href = "productdetails.aspx?hdnGroupCode=" + strGroupCode + '&hdnProdCode=' + strProdCode;
    }

}


function productDetailImage(prodcode)
{
if (winproduct == 'ProductDetailWindow'){
OpenWin.close();
}
winproduct = 'ProductDetailWindowImage'
var feat= 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=280,height=400,left=50,screenx=35,top=0,screenY=50';
var page='productdetails.aspx?hdnProdCode='+prodcode;
OpenWinImage= this.open(page, winproduct, feat);
OpenWinImage.focus();
}

function openTDS(techurl)
{
var wintech = 'TdsWindow';
var feat = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=400,left=50,screenx=35,top=0,screenY=50';
var page=techurl;
OpenWin = this.open(page, wintech, feat);	
}


function enlargedImage(imgurl)
{
var page='/images/large_images/'+imgurl;

var feat = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=320,height=320,left=50,screenx=35,top=0,screenY=50';
var generator=window.open('','enlargedWindow',feat);
  generator.document.write('<html><head><title>Leowallties - Enlarged Image</title><script language="javascript">function resize(){window.resizeTo(document.getElementById("enlimage").width+70,document.getElementById("enlimage").height+110);}window.focus();</script>');
  generator.document.write('<link href="/images/nsit_redesign.htm" rel="stylesheet" type="text/css">');
  generator.document.write('</head><body onload=resize();>');
  generator.document.write('<table width="100%" border="0" align="center" cellpadding="3" cellspacing="3" bordercolor="#CCCCCC">');
  
  generator.document.write('<tr><td align="center"><img id="enlimage" src='+page+' border="0"></td></tr>');
  generator.document.write('<tr><td align="center" height="18" valign="top" ><div align="center"><a href="javascript:window.close()" ><font class="pro_txt">Close Window&nbsp;</font></a></div></td></tr></table>');
 
  generator.document.write('</body></html>');
  generator.document.close();


}

function AddToCartDetail(mem, teaser, perm, customtext) {

    var qtybox = document.getElementById("txtQty" + teaser).value;
    if (qtybox == '' || qtybox == 0 || qtybox < 0) {
        alert("Please specify the quantity to be added to the Shopping Cart");
        document.getElementById("txtQty" + teaser).focus();
    }
    else if (isNaN(qtybox)) {
        alert("Invalid quantity value. Please enter a proper quantity.");
        document.getElementById("txtQty" + teaser).focus();
    }
    else if (qtybox.indexOf(".") != -1) {
        alert("Please do not enter decimal values.");
        document.getElementById("txtQty" + teaser).focus();
    }
    else if (customtext == 'Y' && document.getElementById("txtCustom").value == "") {
        alert("Please enter in the text to be added to the sign.");
        document.getElementById("txtCustom").focus();
    }
    else if (customtext == 'Y' && document.getElementById("txtCustom").value.charAt(0) == ' ') {
        alert("You have not entered this field properly.\nPlease remove the leading spaces");
        document.getElementById("txtCustom").focus();
    }
    else if (perm == 'Y') {
        if ((document.getElementById("txtHeight").value == '' || document.getElementById("txtHeight").value == '0') && (perm == 'Y')) {
            alert("Height or Width cannot be zero.");
            document.getElementById("txtHeight").focus();
        }
        else if ((document.getElementById("txtWidth").value == '' || document.getElementById("txtWidth").value == '0') && (perm == 'Y')) {
            alert("Height or Width cannot be zero.");
            document.getElementById("txtWidth").focus();
        }
        else if (isNaN(document.getElementById("txtHeight").value) != '' && perm == 'Y') {
            alert("Please enter in only numbers.");
            document.getElementById("txtHeight").focus();
        }
        else if (isNaN(document.getElementById("txtWidth").value) != '' && perm == 'Y') {
            alert("Please enter in only numbers.");
            document.getElementById("txtWidth").focus();
        }
        else if (checkForDecimals(document.getElementById("txtHeight")) != '' && perm == 'Y') {
            alert("Please enter in only 2 nos after decimal.");
            document.getElementById("txtHeight").focus();
        }
        else if (checkForDecimals(document.getElementById("txtWidth")) != '' && perm == 'Y') {
            alert("Please enter in only 2 nos after decimal.");
            document.getElementById("txtWidth").focus();
        }
        else {
            document.getElementById("hdnCart").value = "addtocart";
            document.getElementById("hdnqty").value = document.getElementById("txtQty" + teaser).value;
            document.forms[0].submit();
        }

    }
    else {
        document.getElementById("hdnCart").value = "addtocart";
        document.getElementById("hdnqty").value = document.getElementById("txtQty" + teaser).value;
        document.forms[0].submit();
    }
}

function checkForDecimals(txtcheck)
{
	var strError="";
	if(txtcheck.value != ""){
		if (isNaN(txtcheck.value)){
			strError = "Please enter in only numbers.";
			txtcheck.focus();
			return strError;
		}
		else
		{
			if(txtcheck.value.indexOf(".")!= -1){
				if (txtcheck.value.substr(txtcheck.value.indexOf(".")).length > 3){
				strError = "Please enter in only 2 nos after decimal.";
				txtcheck.focus();
				return strError;
				}
			}
		}
	}
	return strError;
}
