function addQty(formName, qtyName) {
		qtyName = qtyName.replace(":","_");
		qtyName = qtyName.replace(":","_");

		//var myForm
		//myForm = document.forms[formName];
		//var objQty = myForm.elements(qtyName);
		var objQty = eval("document."+formName+"."+qtyName);
		if ( (objQty == "undefined") || (objQty != null) ) {
			if (objQty.value == "") {
				objQty.value = "0";
			}
			var qt = parseInt(objQty.value)
			if ( isNaN(qt) ) {
				qt = 0;
			}
			qt++;
			objQty.value = qt;
		}
		return false;
}

function removeQty(formName, qtyName) {
		qtyName = qtyName.replace(":","_");
		qtyName = qtyName.replace(":","_");

		//var myForm
		//myForm = document.forms[formName];
		//var objQty = myForm.elements(qtyName);
		var objQty = eval("document."+formName+"."+qtyName);
		if ((objQty == "undefined") || (objQty != null)) {
			if (objQty.value == "") {
				objQty.value = "0";
			}

			var qt = parseInt(objQty.value)
			if ( isNaN(qt) ) {
				qt = 0;
			} 
			qt--;
			if ( qt < 1) 
				qt = 1;
			objQty.value = qt
		}
		return false;
}
pUpdateBtn = "gifs/btn_update.gif";
pAddBtn = "gifs/btn_addtocart.gif";
pRemoveBtn = "gifs/btn_remove.gif";

xsrc = "gifs/x.gif";

function cartAdd(addImage, removeImage, prodCode, formName, qtyName) {
		qtyName = qtyName.replace(":","_");
		qtyName = qtyName.replace(":","_");

		// trim the formName
		//alert(document.forms[0].name);
		//alert("Complted");

		//var myForm
		//myForm = document.forms[formName];
		var qtyValue = 1;
		//var objQty = myForm.elements(qtyName);
		//alert(objQty);
		var objQty = eval("document."+formName+"."+qtyName);
		if ((objQty == "undefined") || (objQty != null)) {
			if (objQty.value == "") {
			   objQty.value = 1;
			} else {
				qtyValue = objQty.value;
			}
		}

		document[addImage].src = pUpdateBtn;
		document[addImage].alt = 'Update';
		
		document[removeImage].src = pRemoveBtn;
		document[removeImage].alt = 'Remove';
		
		popUpAddToCart(prodCode, qtyValue);
}

function cartRemove(addImage, removeImage, prodCode, formName, qtyName) {
		qtyName = qtyName.replace(":","_");
		qtyName = qtyName.replace(":","_");

		//var myForm
		//myForm = document.forms[formName];

		var removeImageUrl = document[removeImage].src;
		var removeIndex = removeImageUrl.indexOf("x.gif")
		if ( removeIndex == -1 ) {
			document[addImage].src = pAddBtn;
			document[addImage].alt = 'Add To Cart';
			
			document[removeImage].src = xsrc;
			document[removeImage].alt = '';
			
			var objQty = eval("document."+formName+"."+qtyName);
			//var objQty = myForm.elements(qtyName);
			if (objQty != null) {
				objQty.value = "";
			}
			
			popUpRemoveFromCart(prodCode);
		}
}

function popUpAddToCart(id, qty){
	var width=400
	var height=500
	//LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	//TopPosition = (screen.height) ? (screen.height-height)/2 : 0;		
	LeftPosition = 10 
	TopPosition = 10
	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,resizable=1,copyhistory=no,Width='+width+',Height='+height+',top='+TopPosition+',left='+LeftPosition+'';
	win = window.open('AddToCart.aspx?productCode='+id+'&qty='+qty,'PopupAddToCart',settings);
	if(!win) {
		alert('Popup blocker has blocked the window.  \nTo open press Ctrl and click on the link again.');
		return false;
	} else {
		win.focus();
		return true;
	}
}

function popUpAddToCart1(id, qty){
	var width=400
	var height=500
	//LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	//TopPosition = (screen.height) ? (screen.height-height)/2 : 0;	
	LeftPosition = 10;
	TopPosition = 10;
	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,resizable=1,copyhistory=no,Width='+width+',Height='+height+',top='+TopPosition+',left='+LeftPosition+'';
	win = window.open('AddToCart.aspx?productCode='+id+'&qty='+qty,'PopupAddToCart',settings);
	win.focus();	
}

function popUpcartAddRemove(addProdCode, removeProdCode, addQty, removeQty) {
	alert("popUpcartAddRemove");
	var width=400
	var height=500
	//LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	//TopPosition = (screen.height) ? (screen.height-height)/2 : 0;		
	LeftPosition = 10 
	TopPosition = 10
	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,resizable=1,copyhistory=no,Width='+width+',Height='+height+',top='+TopPosition+',left='+LeftPosition+'';
	win = window.open('AddToCart.aspx?action=addremove&productCode='+addProdCode+'&removeproductcode='+removeProdCode+'&qty=1','PopupAddToCart',settings);
	if(!win) {
		alert('Popup blocker has blocked the window.  \nTo open press Ctrl and click on the link again.');
		return false;
	} else {
		win.focus();
		return true;
	}
}

function popUpRemoveFromCart(id){
	var width=400
	var height=500
	//LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	//TopPosition = (screen.height) ? (screen.height-height)/2 : 0;		
	LeftPosition = 10 
	TopPosition = 10

	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,resizable=1,copyhistory=no,Width='+width+',Height='+height+',top='+TopPosition+',left='+LeftPosition+'';
	win = window.open('AddToCart.aspx?productCode='+id+'&action=remove','PopupAddToCart',settings);
	if(!win) {
		alert('Popup blocker has blocked the window.  \nTo open press Ctrl and click on the link again.');
		return false;
	} else {
		win.focus();
		return true;
	}
}

function popUpGlossary(){
	var width=600
	var height=500
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;		
	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,resizable=1,copyhistory=no,Width='+width+',Height='+height+',top='+TopPosition+',left='+LeftPosition+'';
	win = window.open('Glossary.html','PopupGlossary',settings);
	if(!win)	{
		alert('Popup blocker has blocked the window.  \nTo open press Ctrl and click on the link again.');
	} else {
		win.focus();	
	}
}

function popUpAddToWishList(id){
	var width=10
	var height=10
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;		
	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,resizable=1,copyhistory=no,Width='+width+',Height='+height+',top='+TopPosition+',left='+LeftPosition+'';
	win = window.open('AddToWishList.aspx?productCode='+id+'&calltype=popup','PopupAddToCart',settings);
	//win.focus();
	if(!win)	{
			alert('Popup blocker has blocked the window.  \nTo open press Ctrl and click on the link again.');
	}
}

function popUpWindowName(url, name,width,height) {
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;		
	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,resizable=1,copyhistory=no,Width='+width+',Height='+height+',top='+TopPosition+',left='+LeftPosition+'';
	win = window.open(url,name,settings);
	if(win) {
		win.focus();
		//win.close();	
	}
}

function popUpWindowName(name,width,height) {
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;		
	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,resizable=1,copyhistory=no,Width='+width+',Height='+height+',top='+TopPosition+',left='+LeftPosition+'';
	win = window.open("blank.html",name,settings);
	if(win) {
		win.focus();
		//win.close();	
	}
}

function popUpWindow(url,width,height) {
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;		
	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,resizable=1,copyhistory=no,Width='+width+',Height='+height+',top='+TopPosition+',left='+LeftPosition+'';
	win = window.open(url,'PopupeGWindow',settings);
	if(!win)	{
		alert('Popup blocker has blocked the window.  \nTo open press Ctrl and click on the link again.');
	} else {
		win.focus();	
	}
}



function popUpProductDetail(id){
	var width=600
	var height=390
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;		
	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,resizable=1,copyhistory=no,Width='+width+',Height='+height+',top='+TopPosition+',left='+LeftPosition+'';
	//win = window.open('ProductDetail.aspx?productCode='+id,'eGAddToCart',settings);
	win = window.open('ShowProductDetail'+id+'.aspx','eGAddToCart',settings);
	if(!win)	{
		alert('Popup blocker has blocked the window.  \nTo open press Ctrl and click on the link again.');
	} else {
		win.focus();	
	}
}

function popUpFreeGift(id, name, uom){
	var width=300
	var height=440
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;		
	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=0,resizable=1,copyhistory=no,Width='+width+',Height='+height+',top='+TopPosition+',left='+LeftPosition+'';
	win = window.open('FreeGiftPopup.aspx?code='+id+'&name='+name+'&uom='+uom,'PopupAddToCart',settings);
	if(!win)	{
		alert('Popup blocker has blocked the window.  \nTo open press Ctrl and click on the link again.');
	} else {
		win.focus();	
	}
}


function CheckUserName(ctrl, name)
{
	var value = ctrl.value
    if (StringTrim(value).length == 0)
        return true;
    var rx = new RegExp("^[\\w\\s\\.\\,]{1,200}$");
    var matches = rx.exec(value);
    if (matches != null) 
    {
		return true;
	} else {
		alert(name + " Allowed Charcter, Numerics and underscore")
		ctrl.focus();
		return false;
    }

}

function CheckUserId(ctrl, name)
{
	var value = ctrl.value
    if (StringTrim(value).length == 0)
        return true;
    var rx = new RegExp("^\\w{1,200}$");
    var matches = rx.exec(value);
    if (matches != null) 
    {
		return true;
	} else {
		alert(name + " Allowed Charcter, Numerics and underscore")
		ctrl.focus();
		return false;
    }

}

function CheckAddress(ctrl, name)
{
	var value = ctrl.value
    if (StringTrim(value).length == 0)
        return true;
    var rx = new RegExp("^[^<>@]{1,2000}$");
    var matches = rx.exec(value);
    if (matches != null) 
    {
		return true;
	} else {
		alert(name + " Allowed Charcter, Numerics and underscore")
		ctrl.focus();
		return false;
    }
}

function StringTrim(s) {
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}
