﻿// JScript File
	function calculate(n,prodSFperUNIT,prodSF,qty)
	{
	
	  var totalctns = 0;
	  var minctns = 5;
	  var minorder = Math.ceil(prodSFperUNIT * minctns)
	  var SQFT = 0;

	  if (isNaN(document.getElementById(prodSF).value)) {
	      alert("Please enter the square feet as a number");
	      return false;
	  }
	  else {
	      SQFT = Math.ceil(document.getElementById(prodSF).value);
	  }
	  
	  //if (document.getElementById(prodSF).value == "") {
	      //alert("Please enter sq.footage in numbers only");
	      //document.getElementById(prodSF).value = "";
	      //document.getElementById(prodSF).focus();
	      //return false;
	  //}

	 //if(isNaN(document.getElementById(prodSF).value))
	  //{
	    //alert("Please enter sq.footage in numbers only");
	    //document.getElementById(prodSF).value="";
	    //document.getElementById(prodSF).focus();
	    //return false;
	  //}

	  if (SQFT > prodSFperUNIT) {
	      totalctns = Math.ceil(SQFT / prodSFperUNIT);
	      //if (totalctns < minctns) {
	          //totalctns = minctns;
	      //}
	      document.getElementById(qty).value = totalctns;
	  }
	  else { }

	  document.getElementById(prodSF).focus();
	  
	  return false;
	}
	
function DoAddToCart(qty){

//var objForm = document.orderAform<%=varCnt%>
var valid = "0123456789";
var ok = "yes";
var temp;

//-- check for blanks --\\
if(document.getElementById(qty).value == ""){
 alert("Please enter a carton amount.\nIf you have entered your amount in Sq. Ft.,\nplease click the 'Calculate' button.");
 document.getElementById(qty).focus();
 return false;
}

//-- check for numbers --\\
for (var i=0; i<document.getElementById(qty).value.length; i++) {
  temp = "" + document.getElementById(qty).value.substring(i, i+1);
  if (valid.indexOf(temp) == "-1") ok = "no";
}

if (ok == "no") {
  alert("Please enter a valid carton amount");
  document.getElementById(qty).focus();
  return false;
}

//-- check for at least 1 --\\
if(Number(document.getElementById(qty).value) < 1){
 alert("Please enter a carton amount greater than 0.\nIf you have entered your amount in Sq. Ft.,\nplease click the 'Calculate' button.");
 document.getElementById(qty).focus();
 return false;
}

return true;

}
var M6=window,D6=document;function fnAddtoCart(id,qtyid,callbackfunction,minimumorder,flag){if(flag==1 || flag==0 || DoAddToCart(qtyid)){if(flag!=1){if(D6.getElementById(qtyid).value.length==0){alert('Please enter number of '+D6.getElementById(id+'_packageLabel').value+' for add to cart.');return false;}if(parseInt(D6.getElementById(qtyid).value)< minimumorder){alert('You must order at least '+minimumorder+' '+D6.getElementById(id+'_packageLabel').value+'');return false;}}var productID=D6.getElementById(id+'_productID').value;var departmentID=D6.getElementById(id+'_departmentID').value;var customerID=D6.getElementById(id+'_customerID').value;var createDate=D6.getElementById(id+'_createDate').value;var SKU=D6.getElementById(id+'_SKU').value;var colorName=D6.getElementById(id+'_colorName').value;var cartDescription=D6.getElementById(id+'_cartDescription').value;if(flag==1)cartDescription="Sample of "+cartDescription;var brandName=D6.getElementById(id+'_brandName').value;var unitLabel=D6.getElementById(id+'_unitLabel').value;if(flag==1)unitLabel="EA.";var packageLabel=D6.getElementById(id+'_packageLabel').value;if(flag==1)packageLabel="Sample";var unitsPerPackage=D6.getElementById(id+'_unitsPerPackage').value;if(flag==1)unitsPerPackage="1";var unitPrice=D6.getElementById(id+'_unitPrice').value;if(flag==1)unitPrice="2";var quantity=0;if(flag!=1)quantity=D6.getElementById(qtyid).value;else
quantity=qtyid;var weight=D6.getElementById(id+'_weight').value;var isParcel=D6.getElementById(id+'_isParcel').value;var extendedPrice=D6.getElementById(id+'_extendedPrice').value;var itemType=D6.getElementById(id+'_itemType').value;if(flag==1)itemType="S";var productOption="Not";if(D6.getElementById(id+'_ProductOptionsID')!=null){var productOptionID=D6.getElementById(id+'_ProductOptionsID').value;var arrOption=productOptionID.split(";");for(i=0;i<arrOption.length;i++){if(i==0)productOption=D6.getElementById(arrOption[i]).value.split(";")[0];else
productOption=productOption+";"+D6.getElementById(arrOption[i]).value.split(";")[0];}}var postData='ID='+encodeURIComponent(id)+'&';postData=postData+'productID='+encodeURIComponent(productID)+'&';postData=postData+'departmentID='+encodeURIComponent(departmentID)+'&';postData=postData+'customerID='+encodeURIComponent(customerID)+'&';postData=postData+'createDate='+encodeURIComponent(createDate)+'&';postData=postData+'SKU='+encodeURIComponent(SKU)+'&';postData=postData+'colorName='+encodeURIComponent(colorName)+'&';postData=postData+'cartDescription='+encodeURIComponent(cartDescription)+'&';postData=postData+'brandName='+encodeURIComponent(brandName)+'&';postData=postData+'unitLabel='+encodeURIComponent(unitLabel)+'&';postData=postData+'packageLabel='+encodeURIComponent(packageLabel)+'&';postData=postData+'unitsPerPackage='+encodeURIComponent(unitsPerPackage)+'&';postData=postData+'unitPrice='+encodeURIComponent(unitPrice)+'&';postData=postData+'quantity='+encodeURIComponent(quantity)+'&';postData=postData+'weight='+encodeURIComponent(weight)+'&';postData=postData+'isParcel='+encodeURIComponent(isParcel)+'&';postData=postData+'extendedPrice='+encodeURIComponent(extendedPrice)+'&';postData=postData+'itemType='+encodeURIComponent(itemType)+'&';postData=postData+'ProductOptionsID='+encodeURIComponent(productOption);SendAjaxRequest(varWebsiteRoot+'/AddToCart.aspx',callbackfunction,postData);D6.getElementById(id+'_AjaxLoader').style.display='block';}return false;}
function RoundDecimal(num)
{

var rnum = parseFloat(num);
var rlength = 2; // The number of decimal places to round to
if (rnum > 8191 && rnum < 10485) {
rnum = rnum-5000;
var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
newnumber = newnumber+5000;
} else {

var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
}
 newnumber;

  var s = "" + Math.round(newnumber * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t


}
function SendAjaxRequest(FormName,CallBackFunc,Postdata)
{
    
    if(FormName.length==0)
	{
		alert ("Please specify form name.")
		return false;
	}
    xmlHttp=GetXmlHttpObject1();
    if(xmlHttp==null)
	{
		alert('Browser does not support ajax.');
		return false;
	}
	else
	{
		var url=FormName;
		xmlHttp.onreadystatechange=function() { CallBackFunc(xmlHttp) };
    	xmlHttp.open("POST",url,true)
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(Postdata)
		return true;
	}
	
	xmlHttp=null;
}
function GetXmlHttpObject1()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}