function fnAddProduct(nID, nProductID, nCategoryID) {
	if (!isNaN(nID) && !isNaN(nProductID) && !isNaN(nCategoryID)) {
		var url = "_shop/ShoppingCart.asp?ID="+nID+"&ProductID="+nProductID+"&CategoryID="+nCategoryID;
		var doc = dbsRequest(url);
		fnUpdateShopCart(doc);		
	}
}

function fnUpdateShopCart(doc) {
	if (doc != null) {
		for (var nChilds = 0; nChilds < doc.childNodes.length; nChilds++) {
		    if (doc.childNodes[nChilds].tagName == "cart") {
			    var sCart;
			    if (window.ActiveXObject)
				    sCart = doc.childNodes[nChilds].text;
			    else if (window.XMLHttpRequest)
				    sCart = doc.childNodes[nChilds].textContent;

			    var ctlShoppingCartContainer = document.getElementById("ShoppingCartContainer");
			    if (ctlShoppingCartContainer != null) {
				    ctlShoppingCartContainer.innerHTML = sCart;
			    }
		    }
		    else if (doc.childNodes[nChilds].tagName == "product") {
			    var sProduct;

			    if (window.ActiveXObject)
				    sProduct = doc.childNodes[nChilds].text;
			    else if (window.XMLHttpRequest)
				    sProduct = doc.childNodes[nChilds].textContent;

			    fnDisplyShopMsg(sProduct.replace(/&quot;/g,'"'));
		    }	
		}	
	}	
}

function fnDisplyShopMsg(sProduct) {
		var ctlProductsMsg = document.getElementById("ctlProductsMsg");
	if (ctlProductsMsg != null) {
		var ctlProductMsg = document.getElementById("ctlProductMsg");
		ctlProductMsg.innerHTML = sProduct;
		ctlProductsMsg.style.display = "block";
		ctlProductsMsg.style.top = (((document.body.clientHeight - ctlProductsMsg.offsetHeight)/2)+document.body.scrollTop-60) + "px";
		ctlProductsMsg.style.left = ((document.body.clientWidth - ctlProductsMsg.offsetWidth)/2)+document.body.scrollLeft + "px";
		
		var bg = document.getElementById("dbsBgGray");
		bg.style.display = "block";
		bg.style.width = "100%";
		bg.style.height = document.getElementById("dbsBgGrayPlaceRef").offsetTop + "px";
		bg.style.left = "0px";
		bg.style.top = "0px";
		addEvent(document.body, "click", fnMsgClicked);
		addEvent(window, "scroll", fnMsgClose);
		fnHideSelectElemByClass("parametersfilter");
	//var ctlProductsMsg = document.getElementById("ctlProductsMsg");
	//if (ctlProductsMsg != null) {
		//fnStopAllMarquee();
		//var ctlProductMsg = document.getElementById("ctlProductMsg");
		//ctlProductMsg.innerHTML = sProduct;
		//ctlProductsMsg.style.display = "block";
		//ctlProductsMsg.style.top = (((document.body.clientHeight - ctlProductsMsg.offsetHeight)/2)+document.body.scrollTop-60) + "px";
		//ctlProductsMsg.style.left = ((document.body.clientWidth - ctlProductsMsg.offsetWidth)/2)+document.body.scrollLeft + "px";
		
		//var bg = document.getElementById("dbsBgGray");
		//bg.style.display = "block";
		//bg.style.width = "100%";
		//bg.style.height = document.getElementById("dbsBgGrayPlaceRef").offsetTop + "px";
		//bg.style.left = "0px";
		//bg.style.top = "0px";
		//dbsAddEvent(document.body, "click", fnMsgClicked);
		//dbsAddEvent(window, "scroll", fnMsgClose);
		//fnHideSelectElemByClass("parametersfilter");
	}
}

function fnStopAllMarquee() {
	var list = document.getElementsByTagName("MARQUEE");	
	for (var i = 0; i < list.length; i++) {
		list[i].stop();
		list[i].stopped = true;
	}
}

function fnStartAllMarquee() {
	var list = document.getElementsByTagName("MARQUEE");	
	for (var i = 0; i < list.length; i++) {
		list[i].start();
		list[i].stopped = false;
	}
}

function fnMsgClose() {
	var ctlProductMsg = document.getElementById("ctlProductMsg");
	ctlProductsMsg.style.display = "none";
	var bg = document.getElementById("dbsBgGray");
	bg.style.display = "none";
	bg.style.height = "1px";
	bg.style.width = "1px";
	dbsRemoveEvent(document.body, "click", fnMsgClicked);
	dbsRemoveEvent(document.body, "scroll", fnMsgClose);
	fnShowSelectElemByClass("parametersfilter");
}

function fnMsgClicked(event) {
	var ctlProductsMsg = document.getElementById("ctlProductsMsg");
	
	if (event.target) {
		if (event.target.id == "butClose") {
			ctlProductsMsg.style.display = "none";
			var bg = document.getElementById("dbsBgGray");
			bg.style.display = "none";
			bg.style.height = "1px";
			bg.style.width = "1px";
			dbsRemoveEvent(document.body, "click", fnMsgClicked);
			dbsRemoveEvent(document.body, "scroll", fnMsgClose);
			fnShowSelectElemByClass("parametersfilter");
			fnStartAllMarquee();
		}
		else if (event.target.id == "butCashbox") {
			//window.location = "?pgcashbox.asp";
		}
		else {
			event.preventDefault();
		}		
	}
	else if (event.srcElement) {		
		if (event.srcElement.id == "butClose") {
			ctlProductsMsg.style.display = "none";
			var bg = document.getElementById("dbsBgGray");
			bg.style.display = "none";
			bg.style.height = "1px";
			bg.style.width = "1px";
			dbsRemoveEvent(document.body, "click", fnMsgClicked);
			dbsRemoveEvent(document.body, "scroll", fnMsgClose);
			fnShowSelectElemByClass("parametersfilter");
			fnStartAllMarquee();
		}
		else if (event.srcElement.id == "butCashbox") {
			//window.location = "?pgcashbox.asp";
		}
		else {
			event.returnValue = false;
		}
	}
	
}

function fnGoToCashbox() {
	window.location = sAppDomain + "/_Shop/CashBox.asp";
}


function fnIsDataValid(oFrm) {
	if (document.forms.frmCart.PaymentType.value != "3" && document.forms.frmCart.PaymentType.value != "2" && document.forms.frmCart.PaymentType.value != "1") {
		//alert("text");
		return false;
	}
	else if (document.forms.frmCart.PaymentType.value == "1") { // By phone
		arrInputs = new Array();
		var field = new fieldValidate("BillingName", 0, "BillingName", 1);
		arrInputs[0] = field;
		field = new fieldValidate("CallbackPhone", 15, "CallbackPhone", 1);
		arrInputs[1] = field;
				
		return IsValidData(oFrm);
	}
	else {
		arrInputs = new Array();
		var field = new fieldValidate("BillingName", 0, "BillingName", 1);
		arrInputs[0] = field;
		field = new fieldValidate("City", 0, "City", 1);
		arrInputs[1] = field;
		field = new fieldValidate("Address", 0, "Address", 1);
		arrInputs[2] = field;
		field = new fieldValidate("Zip", 1, "Zip", 1);
		arrInputs[3] = field;
				
		if (document.frmCart.Address2.checked) {
			field = new fieldValidate("ShippingCity", 0, "ShippingCity", 1);
			arrInputs[4] = field;
			field = new fieldValidate("ShippingAddress", 0, "ShippingAddress", 1);
			arrInputs[5] = field;
			field = new fieldValidate("ShippingZip", 1, "ShippingZip", 1);
			arrInputs[6] = field;
		}
				
		return IsValidData(oFrm);
	}
}

function fnDisplayShippingAddress(bVisible) {
	if (bVisible) {
		document.getElementById("rowShippingCity").style.display="";
		document.getElementById("rowShippingAddress").style.display="";
		document.getElementById("rowShippingZip").style.display="";
	}
	else {
		document.getElementById("rowShippingCity").style.display="none";
		document.getElementById("rowShippingAddress").style.display="none";
		document.getElementById("rowShippingZip").style.display="none";
	}
}

function fnSecurityCodeWin() {
	window.open("SecurityCode.htm","SecurityCode","left=100, top=100, width=520, height=350, scrollbars=yes");
}
