function fnAddProduct(nID, nProductID, nCategoryID) {
	var param_control1 = document.getElementById("Colorlist_" + nProductID);
	var param_control2 = document.getElementById("Sizelist_" + nProductID);
	var param_control3 = document.getElementById("Brandlist_" + nProductID);
	var param_control4 = document.getElementById("quantity" + nProductID);
    var str_param1 = "";
    var str_param2 = "";
    var str_param3 = "";
    var str_param4 = "";
    
    if(param_control3 != null && param_control3 != "undefined")
    {
        if(param_control3.value != "0")
            str_param3 = "&brandid=" + param_control3.value;
         else
        {
            alert("Please select brand !");
            return;
        }
       
    }
    if(param_control1 != null && param_control1 != "undefined") {
      // debugger;
      // var paramDiv = document.getElementById("paramproduct" + nProductID);
     //  if (paramDiv != null && paramDiv) {
      //     if (paramDiv.style.display == "none") {
      //         paramDiv.style.display = "block";
     //          return;
     //      }
     //  }
       if(param_control1.value != "0")
            str_param1 = "&colorid=" + param_control1.value;
       else
       {
            alert("Please select a color! ");
            return;
        }
    }
    
    
    if(param_control2 != null && param_control2 != "undefined")
    {
        if(param_control2.value != "0")
            str_param2 = "&sizeid=" + param_control2.value;
         else
        {
            alert("Please select size !.");
            return;
        }
       
    }

    if(param_control4 != null && param_control4 != "undefined")
    {
        if(param_control4.value != "0")
            str_param4 = "&quantity=" + param_control4.value;
         else
        {
            alert("Please select quantity !");
            return;
        }
       
    }

	if (!isNaN(nID) && !isNaN(nProductID) && !isNaN(nCategoryID)) {
		var url = "_shop/ShoppingCart.asp?ID="+nID+"&ProductID="+nProductID+"&CategoryID="+nCategoryID;
		url = url + str_param1 + str_param2 + str_param3 + str_param4;
		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";
		dbsAddEvent(document.body, "click", fnMsgClicked);
		dbsAddEvent(window, "scroll", fnMsgClose);
		fnHideSelectElemByClass("parametersfilter");
	}
}

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";
			dbsRmoveEvent(document.body, "click", fnMsgClicked);
			dbsRemoveEvent(document.body, "scroll", fnMsgClose);
			fnShowSelectElemByClass("parametersfilter");
		}
		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");
		}
		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";
	}
}
