﻿// JavaScript Document
//Added by ecsr, on 6 Mar 2006
//Shipamt and OrderOver amount changed
var ConstShipAmt = 5.95 // 5 Constant Declared for shipping cost.
var ConstOrderOverAmt = 89 // 99 Constant Declared for Orders Over Amount.
var ConstVitalzym = 84.99 //Constant Declared for Orders Over Amount.



function openpopup()
{
	//alert("haneef")
	//window.open("/popup/pop-ups.asp","Avicenna","height=420,width=350")
	//new window.open("http://server2/popup/pop-ups.htm")
} 

/**************************************************************
 FormatNumber: Returns an expression formatted as a number.

 Parameters:
      Expression            = Expression to be formatted.
      NumDigitsAfterDecimal = Numeric value indicating how
                              many places to the right of the
                              decimal are displayed.

 Returns: String
***************************************************************/
function FormatNumber(Expression, NumDigitsAfterDecimal)
{
	var iNumDecimals = NumDigitsAfterDecimal;
	var dbInVal = Expression;
	var bNegative = false;
	var iInVal = 0;
	var strInVal
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals)
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (bNegative)
	{
		return "-" + strWhole + "." + strDec;
	}
	else
	{
		return strWhole + "." + strDec;
	}
}


function fillShipCountry(country)
{	
	for(var i=0;i<document.frmViewcart.txtShipCountry.length;i++)
	{
		if (document.frmViewcart.txtShipCountry.options[i].value==country)
		{
			document.frmViewcart.txtShipCountry.selectedIndex = i;
			break;
		}  
	}
}

function CountryChange(shipzip)
{	
	//alert(document.frmViewcart.txtShipCountry.value);
	if (document.frmViewcart.txtShipCountry.value!="US")
	{
		document.frmViewcart.ship_zip.value="";
		document.frmViewcart.ship_zip.disabled=true;
	}
	else
	{	document.frmViewcart.ship_zip.disabled=false;
		document.frmViewcart.ship_zip.value=shipzip;
	}

}
				
	
	
			
function SubmitPage(page)
{
	var isvalidity,i,tmpstr,regexp;
	isvalidity=true;

	if (isvalidity==true )	
	{
			
		if (page=="update")
			document.frmViewcart.submit();  
		else{
					
			if(page=="cs")
				document.frmViewcart.action="/shop/xq/asp/cs.y/qx/viewcart.asp";
			else
				document.frmViewcart.action="/shop/xq/asp/ckout.y/qx/viewcart.asp";

				if(page=="QO")
				document.frmViewcart.action="/shop/expressorder.asp";
				if(page=="MO")
				document.frmViewcart.action="/shop/manualorder.asp";
				
		document.frmViewcart.method="post";
		document.frmViewcart.submit();      
		}
	}
	else
		return false;
	
}
//Here code goes for blinking colors to the text



<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; 

	}
}
function initArray() {
	this.length = initArray.arguments.length;
	for (var i = 0; i < this.length; i++) {
	this[i] = initArray.arguments[i];
	   }
}


function MM_CalcMargin(Productcost,Price,AdjPrice,Qty,PName,PTID)
{
	var MgnBeforeDIscount,MgnAfterDiscount,MgnBeforeDIscountAmt,MgnAfterDiscountAmt;
	var Finalmargin1,FinalMargin2,PName1;
	
	MM_showHideLayers('Layer2','','show');
	
	MgnBeforeDIscount=((Price-Productcost)/Price)*100 ;
	
	MgnAfterDiscount=((AdjPrice-Productcost)/Price)*100; 
	
	MgnBeforeDIscountAmt=(Price-Productcost)*Qty;
	
	MgnAfterDiscountAmt=(AdjPrice-Productcost)*Qty;
	
	Finalmargin1=new String();
	
	Finalmargin1= "$"+FormatNumber((Price-Productcost),2)  + "x" + Qty +  " = $" + FormatNumber(MgnBeforeDIscountAmt,2) ;
	Finalmargin1=Finalmargin1+ " (" + FormatNumber(MgnBeforeDIscount,2) + "%)"
	Finalmargin1="<Strong><font color='#006633' size='2' face='Arial, Helvetica, sans-serif'>" + Finalmargin1 + "</font></Strong>"
	
	
	Finalmargin2=new String();
	
	Finalmargin2="$"+FormatNumber((AdjPrice-Productcost),2) +"x" +  Qty +     " = $" + FormatNumber(MgnAfterDiscountAmt,2) ;
	Finalmargin2=Finalmargin2+ " (" + FormatNumber(MgnAfterDiscount,2) + "%)"
	Finalmargin2="<Strong><font color='#006633' size='2' face='Arial, Helvetica, sans-serif'>" + Finalmargin2 + "</font></storng>"
	
	document.getElementById("PName").innerHTML="<Strong><font color='#CC0000' size='2' face='Arial, Helvetica, sans-serif'>" + "Our Margin On " + PName + "(SKU:" + PTID + ")" + "</font></strong>" ; 
	document.getElementById("BeforeDisc").innerHTML=Finalmargin1  ; 
	
	document.getElementById("AfterDisc").innerHTML=Finalmargin2   ;

	
}


//-->

function checkqty(txtqtyid,txtqtyvalue)
{
	
	if (Trim(txtqtyvalue)=="" )
	{
		document.getElementById(txtqtyid).innerText="0"
		return false;
	}
	else if( isNaN(Trim(txtqtyvalue))==true)
	{
		alert("Please enter numbers only in Qty")
		document.getElementById(txtqtyid).select();
		return false;
	}
	else if( parseInt(Trim(txtqtyvalue))<=0)
	{
		alert("Please enter positive numbers only in Qty")
		document.getElementById(txtqtyid).select();
		return false;
	} 
  
  //Addec by ECSR
  //Validating the text box, checking for "." in text box
  //Start   
	 else if(txtqtyvalue.length>=1)
	 {
		 var nLen = txtqtyvalue.length
		 for (var nI=0; nI<nLen; nI++){
			if(txtqtyvalue.charAt(nI)=="."){
				alert("Please enter numbers only in Qty, Special characters not allowed.");
				document.getElementById(txtqtyid).select();
				return false;
			}
		 }
	}	 
  //Addec by ECSR
  //Validating the text box, checking for "." in text box
  //End   
		 
return true;
}

function checkDisc(txtdiscid,txtdiscvalue,txtadjpriceid,tmpUP)
{
	var tmpadjprice
	if (Trim(txtdiscvalue)!="" )
	{
		if( isNaN(Trim(txtdiscvalue))==true)
		{
			alert("Please enter numbers only in Discount %")
			document.getElementById(txtdiscid).innerText=""
		}
		else if( parseInt(Trim(txtdiscvalue))<0)
		{
			alert("Please enter positive numbers only in Discount %")
			document.getElementById(txtdiscid).innerText=""
		}
		else //calculate adjusted price 
		{
			tmpadjprice=(1-(txtdiscvalue/100.0))*tmpUP
			document.getElementById(txtadjpriceid).setAttribute("value",FormatNumber(tmpadjprice,2))
			document.getElementById(txtdiscid).innerText=""
		}
		 
	}
	
}
function checkAdjPrice(txtadjpriceid,txtadjpricevalue)
{
	if (Trim(txtadjpricevalue)!="" )
	{
		if( isNaN(Trim(txtadjpricevalue))==true)
		{
			alert("Please enter numbers only in Adjusted Price ")
			document.getElementById(txtadjpriceid).innerText=""
		}
		else if( parseInt(Trim(txtadjpricevalue))<0)
		{
			alert("Please enter positive numbers only in Adjusted Price")
			document.getElementById(txtadjpriceid).innerText=""
		}
		
	}


}

function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' &&
		    String.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' &&
			String.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

function Trim(String)
{
	if (String == null)
		return (false);

	return RTrim(LTrim(String));
}


					function addLayer()
					{
					
						if(navigator.appName == "Netscape") {
						document.write('<layer id="c" class="wp"><center>'+ctext+'</center></layer>');
						}
						if (navigator.appVersion.indexOf("MSIE") != -1){
						document.write('<span id="c" class="wp">'+ctext+'</span>');
						}
					}	
					function addLayer_congrats()
					{
					
						if(navigator.appName == "Netscape") {
						document.write('<layer id="c" class="wp"><center>'+congratstext+'</center></layer>');
						}
						if (navigator.appVersion.indexOf("MSIE") != -1){
						document.write('<span id="c" class="wp">'+congratstext+'</span>');
						}
					}	
					function chcolor(){ 
						if(navigator.appName == "Netscape") {
							document.c.document.write('<font color="'+color[x]);
							document.c.document.write('">'+ctext+'</font></strong>');
							document.c.document.close();
						}
						else if (navigator.appVersion.indexOf("MSIE") != -1)
						{
						document.all.c.style.color = color[x];
						
						}
						(x < color.length-1) ? x++ : x = 0;
					}
					

					function chcolor1(){ 
					if(navigator.appName == "Netscape") {
					document.c1.document.write('<Strong><font size=3 color="'+color1[x1]);
					document.c1.document.write('">'+ctext1+'</font></strong>');
					document.c1.document.close();
					}
					else if (navigator.appVersion.indexOf("MSIE") != -1){
					document.all.c1.style.color = color1[x1];
					}
					(x1 < color1.length-1) ? x1++ : x1 = 0;
					}


function FormatCurrency(Expression)
{
	var iNumDecimals = 2;
	var dbInVal = Expression;
	var bNegative = false;
	var iInVal = 0;
	var strInVal
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals)
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (bNegative)
	{
		return "-$" + strWhole + "." + strDec;
	}
	else
	{
		return "$" + strWhole + "." + strDec;
	}
}

function submitZipCode(ActionBy)
{
	document.frmViewcart.ship_zip.value=Trim(document.frmViewcart.ship_zip.value);
//	cmbchange
	<!-- commented by riyaz on july 21 ,2005 Because for Now decided not to show Residential commercial in the site
	/*if (document.frmViewcart.SELResidential.value=="")
	{
		alert("Please Select your desire ship area")
		document.frmViewcart.SELResidential.focus();
		return false;
	}*/
	 if (document.frmViewcart.ship_zip.value=="" && document.frmViewcart.txtShipCountry.value=="US" && parseInt(ActionBy)==1)
	{
		alert("Please enter zip Code")
		document.frmViewcart.ship_zip.focus();
		return false;
	}
	else if (validateZipCode(document.frmViewcart.ship_zip.value)==false && document.frmViewcart.txtShipCountry.value=="US" && parseInt(ActionBy)==1)
	{
		//alert("Please enter a valid 5 digit U.S zip code. Please note that all international orders are charged a flat shipping charge of $25 for all orders less than $89. All orders of value $89 and over receive a shipping credit of $5.95.For details please see our shipping policy.");
		alert("Please enter a valid 5 digit U.S zip code.");
		document.frmViewcart.ship_zip.focus();
		return false;
	
	}
	else
	{
		///shop/xq/asp/ckout.y/qx/viewcart.asp
		document.frmViewcart.action="/shop/xq/asp/qx/viewcart.asp";

		// To fill hidden field when go button clicked By Vijay
		if (parseInt(ActionBy)==1){
			document.frmViewcart.hidGo.value="Go";
		}
	
		if (document.frmViewcart.ship_zip.value=="")
		{document.frmViewcart.method="post";}
		else
		{document.frmViewcart.method="post";}

		document.frmViewcart.submit();      
	}

}
function validateZipCode(postalCode)
{
	var pcodelen;
	pcodelen=postalCode.length;
	
	if (pcodelen<5 || pcodelen>5)
	{
		return false;
	}
	else if(postalCode=="00000")
	{return false;}
	else if (isNaN(postalCode))
	{
		return false;
	}
	return true;	
}

function showViewcartTotals(viewcartSubTotal,viewcartTax,ComboExist,vitalzymexist)
{	
	var viewcart_GTotal,viewcart_ShipCharges,viewcart_ShipchargesComboValue,viewcart_ShipchargesFromCombo,intDollarDiscount;
	var intAscrDiscount;
	viewcart_ShipchargesComboValue=new Array(2)
	intDollarDiscount=0;
	intAscrDiscount=0;
	/*alert(viewcartSubTotal);
	alert(viewcartTax);
	alert(ComboExist);
	*/
	var shipcredit,totshipwt;
	shipcredit=document.frmViewcart.shipcredit.value;
	totshipwt=document.frmViewcart.totshipwt.value;
	viewcart_ShipCharges=0;
	if (ComboExist==1)
	{
		//viewcart_ShipCharges=document.frmViewcart.cmbShippingCharges.value;
		viewcart_ShipchargesComboValue=Split(document.frmViewcart.cmbShippingCharges.value,",");
		viewcart_ShipCharges=viewcart_ShipchargesComboValue[0];		
	}

	viewcart_GTotal= parseFloat(viewcartSubTotal)+parseFloat(viewcartTax)+parseFloat(viewcart_ShipCharges);

	
	if (((viewcartSubTotal>=ConstOrderOverAmt) || (vitalzymexist==1 && viewcartSubTotal>=ConstVitalzym )) && ComboExist==1)
	{		
		if (parseFloat(viewcart_ShipCharges)<parseFloat(shipcredit)) {			
			viewcart_GTotal=viewcart_GTotal-viewcart_ShipCharges;
			viewcart_ShipCharges=0;
		} else {
			viewcart_GTotal=viewcart_GTotal-shipcredit;
			viewcart_ShipCharges=parseFloat(viewcart_ShipCharges)-shipcredit;
		}		
	}	
	if (viewcart_GTotal==0)
	{
		document.getElementById("viewCartGrandTotal").innerHTML="$0.00";
		document.frmViewcart.viewCartGrandTotal1.value="0.00";
	}
	else if (viewcart_GTotal>0)
	{
	    intDollarDiscount=document.frmViewcart.hdnDollarDiscount.value;
	    intAscrDiscount=document.frmViewcart.hdnASCRDiscount.value;
		document.getElementById("viewCartGrandTotal").innerHTML=FormatCurrency(viewcart_GTotal-intDollarDiscount-intAscrDiscount);
		document.frmViewcart.viewCartGrandTotal1.value=viewcart_GTotal;
	}
	
	if (viewcart_ShipCharges==0)
	{
		document.getElementById("FinalShipping").innerHTML="$0.00";
		document.frmViewcart.FinalShipping1.value="$0.00";
	}
	else if (viewcart_ShipCharges>0)
	{
		document.getElementById("FinalShipping").innerHTML=FormatCurrency(viewcart_ShipCharges);
		document.frmViewcart.FinalShipping1.value=FormatCurrency(viewcart_ShipCharges);
	}

}




