function amt_calculate(qty, price, index)
{
	document.getElementById('strAmount' + index).value = formatNumber(qty * Number(replace(price,',','')),'#,##0.00');
	if (document.getElementById('txtSubtotal') != null)
	{
		CalSubtotal(1);
	}else{
		CalSubtotal(0);
	}
}

function isDigit(pElem)
{
	var v =cleanNumber(pElem.value);
	var bInvalid = false;

	if (isNaN(Number(v)))
	{
		bInvalid = true;
	}
	numFormat(pElem, '','',1,999999);
	return(true);
}

function setFeeCharge(sValue, iCase)
{
	document.frmData.txtDeliveryFee.value = formatNumber(sValue, "0.00");
	CalSubtotal(iCase);
}

function CalTotal(v1, v2)
{
	val = v1 + v2;
	document.frmData.txtTotal.value = formatNumber(val, "0.00");
}

function CalSubtotal(s)
{
	var sum = 0;
	for(var i = 1; Number(eval("document.getElementById('strAmount' + i) != null? 1 : 0;"))== 1 ;i++)
	{
		sum += Number(replace(document.getElementById('strAmount' + i).value, ',','',''));
	}

	if (Number(s) == 1 && document.getElementById('txtSubtotal') != null && document.getElementById('txtTotal') != null)
	{
		document.getElementById('txtSubtotal').value = formatNumber(sum,"#,##0.00");
		tmp = Number(replace(document.getElementById('txtSubtotal').value,',','',''));
		tmp = Number(tmp) + Number(replace(document.getElementById('txtDeliveryFee').value,',','',''));
		document.getElementById('txtTotal').value = formatNumber(tmp, "#,##0.00")
	}
	if(Number(s) == 0 && document.getElementById('txtTotal') != null)
	{
		document.getElementById('txtTotal').value = formatNumber(sum, "#,##0.00");
	}
	showCalculate("true");
}

function CheckTime(s)
{
	s = s + "";
	s.toLowerCase();

	var h, m, p;

	sTmp = s.split(":");

	if (sTmp.length > 1)
	{
		h = Number(sTmp[0]);
		m = sTmp[1];

		sTmp2 = m.split(" ")
		if (sTmp.length > 1)
		{
			m = Number(sTmp2[0]);
			p = sTmp2[1] + "";
		}
		p = p.toLowerCase();
		if (!isNaN(h) && h <= 12  && !isNaN(m) && m <= 59 && (p == "am" || p == "pm" || p.length == 0 || p == "PM" || p == "AM" ))
		{
			return true;
		}
	}
	return false;
}

function RemoveItem(sCartNo, s)
{
	var oForm = document.frmData;
	var tmpId = "";
	var url = "remove_shoppingcartitem.asp?cart=" + sCartNo + "&case=" + s + "&pId=";

	sCartNo = sCartNo + "";

	if (sCartNo.length == 0 || oForm.chkRemove == null)
	{
		return ;
	}

	if (!oForm.chkRemove.length)
	{
		if(oForm.chkRemove.checked)
		{
			tmpId = oForm.chkRemove.value;
		}
	}else{
		for (var i = 0; i < oForm.chkRemove.length; i++)
		{
			if (oForm.chkRemove[i].checked == true)
			{
				if (tmpId.length > 0 && i)
				{
					tmpId = tmpId + ","
				}
				tmpId = tmpId + oForm.chkRemove[i].value
			}
		}
	}

	var chk = tmpId.split(",");



	if (tmpId.length > 0)
	{
		if (chk.length > 1){
			if(confirm("Are you sure you want to remove the selected items?"))
			{
				window.location = url + tmpId;
			}
		}else{
			if(confirm("Are you sure you want to remove the selected item?"))
			{
				window.location = url + tmpId;
			}
		}
	}
}
function CheckOut(s)
{
	s = s + "";
	s = s.toLowerCase();
	if (s == "false")
	{
		alert("Your shopping cart is empty, cannot process to check out.");
		return;
	}
	if (document.all.button_bar1 != null){
		document.all.button_bar1.innerHTML = "";
	}
	if (document.all.holiday_greeting != null){
		//document.all.holiday_greeting.innerHTML = "";
	}
	if (document.all.button_checkout != null){
		document.all.button_checkout.innerHTML = "";
	}
}

function ChangeDeliveryType(s,c)
{
	var text = "";
	var pTmp = "";

	if (Number(s) < 0 && Number(s) > 1)
	{
		return;
	}

	if (Number(s) == 1)
	{
		text = "International Delivery";
		s = 0;
	}else{
		text = "Delivery in Thailand";
		s = 1;
	}

	if(confirm("Are you sure you want to change delivery type to " + text + "?"))
	{
		//window.location = "changedeliverytype.asp?cart=" + c + "&case=" + s + "&pack=" + pTmp;
		document.frmData.action = "updateshoppingcart.asp?cart=" + c + "&case=" + s;
		document.frmData.submit();
	}
}

function CancelShopping(s)
{
	if(confirm("Are you sure you want to cancel shopping?"))
	{
		window.location = "cancelshopping.asp?cart=" + s;
	}
}

function getPricingGuide(iDType, sCode, iPack1, iPack5)
{
	this.DeliveryType = iDType;
	this.Code = sCode;
	this.Pack1 = iPack1;
	this.Pack5 = iPack5;
}

function ChangePackageSize(val, idx, delivery_type)
{
	var code = document.getElementById('strCode' + idx).value;
	var qty = document.getElementById('strUnit'+ idx).value;

	var pTmp = 0.0;

	for(var i = 0; i < PricingGuide.length; i++)
	{
		if (PricingGuide[i].Code.toLowerCase() == code.toLowerCase() && PricingGuide[i].DeliveryType == delivery_type)
		{
            alert(PricingGuide[i].Code.toLowerCase());

			if (Number(val) == 1)
			{
				pTmp = formatNumber(PricingGuide[i].Pack1,"#,##0.00");

			}else{
				pTmp = formatNumber(PricingGuide[i].Pack5,"#,##0.00");
			}
			document.getElementById('strPrice' + idx).value = pTmp;
			document.getElementById('unit_price' + idx).innerHTML = pTmp + "';";
			amt_calculate(Number(qty), pTmp, idx);
		}
	}
}

function setCardPrice(delivery_type)
{
	for(var i = 1; Number(eval("document.frmData.strAmount" + i + " != null? 1 : 0;"))== 1 ;i++)
	{
		eval("var tmp = document.frmData.intPackageSize" + i + " != null? 1 : 0;");
		if (tmp)
		{
			eval("var val = document.frmData.intPackageSize" + i + ".value;");
			ChangePackageSize(val, i, delivery_type);
		}
	}
}

function showCalculate(sFlag)
{
	return;
	var strBtnCal = "<input type=\"button\" id=\"btnUpdateShoppingCart\" name=\"btnUpdateShoppingCart\" value=\"UPDATE SHOPPING CART\" class=\"botton_style2\" onClick=\"UpdateShoppingCart();\">";
	if (document.all.button_update_shoppingcart != null)
	{
		if (document.all.button_update_shoppingcart != null)
		{
			if (sFlag == "true")
			{
				document.getElementById('button_update_shoppingcart').innerHTML = strBtnCal;
			}else{
				document.getElementById('button_update_shoppingcart').innerHTML = "<img src='IMAGES/clear.gif' height='40'>";
			}
		}
	}
}

function DisabledShippingAddress(s)
{
	var oForm = document.frmData;
	var flag = false;

	if (oForm.hdn_delivery_type != null)
	{
		if(oForm.hdn_delivery_type.value == "1")
		{

			if (oForm.intCountry.options[oForm.intCountry.selectedIndex].text.toLowerCase() != "thailand")
			{
				if(oForm.chkBilling.checked == true)
				{
					alert("For delivery in Thailand, your delivery address must be in Thailand.")
					oForm.chkBilling.checked = false;
				}
			}
		}else{
			if (oForm.intCountry.options[oForm.intCountry.selectedIndex].text.toLowerCase() == "thailand")
			{
				if(oForm.chkBilling.checked == true)
				{
					alert("For International Delivery, your delivery address must be International.")
					oForm.chkBilling.checked = false;
				}
			}
		}
	}

	flag = false;
	if(oForm.chkBilling != null)
	{
		if ((oForm.chkBilling.checked == true)||(oForm.optDelivery.value==1))
		{
			flag = true;
		}

		if (oForm.optDelivery != null && oForm.optDelivery.value == 1)
		{
			oForm.chkBilling.disabled = true;
			flag = true;
		}else{
			oForm.chkBilling.disabled = false;
		}
	}

	if (oForm.strShippingFirstName != null){
		oForm.strShippingFirstName.disabled = flag;
	}

	if (oForm.strShippingLastName != null){
		oForm.strShippingLastName.disabled = flag;
	}
	if(oForm.strShippingAddress != null){
		oForm.strShippingAddress.disabled = flag;
	}
	if (oForm.strShippingCity != null){
		oForm.strShippingCity.disabled = flag;
	}
	if (oForm.strShippingProvince != null){
		oForm.strShippingProvince.disabled = flag;
	}
	if (oForm.strShippingZip != null){
		oForm.strShippingZip.disabled = flag;
	}
	if (oForm.intShippingCountry != null){
		oForm.intShippingCountry.disabled = flag;
	}
	if (oForm.strShippingPhone != null){
		oForm.strShippingPhone.disabled = flag;
	}
	if (oForm.strShippingFax != null){
		oForm.strShippingFax.disabled = flag;
	}
}
function ContinueShopping(rPage)
{
	document.frmData.action = "updateshoppingcart.asp?returnpage=" + rPage;
	document.frmData.submit();
}
function UpdateShoppingCart()
{
	document.frmData.action = "updateshoppingcart.asp";
	document.frmData.submit();
}
function CheckOutShoppingCart()
{
	var oForm = document.frmData;
	var co = 0;

	//if (oForm.optDelivery != null && oForm.optDelivery.type == "radio")
	if (oForm.optDelivery != null && oForm.optDelivery.length > 0 )
	{
		for(var i = 0 ; i < oForm.optDelivery.length; i++)
		{
			if (oForm.optDelivery[i].checked == true)
			{
				break;
			}
			co = i;
		}
		if(co >= oForm.optDelivery.length - 1)
		{
			alert("Please select delivery option.");
			return false;
		}
	}
	document.frmData.action = "updateshoppingcart.asp?case=3";
	document.frmData.submit();
}

function optPaymentCheck()
{
	var oCreditCard = document.frmData.optCreditCard;
	var oPayment = document.frmData.optPayment;
	var oForm = document.frmData;

	if(oForm.optDelivery.value != 1 && oPayment[2] != null && oPayment[2].checked == true)
	{
		oPayment[2].checked = false;
		alert(" Can not use this option. ");
		return;
	}

	if (oPayment[0].checked == true)
	{
		/*
		if (oCreditCard[0] != null && oCreditCard[0].checked == true || (oCreditCard[0] != null && oCreditCard[0].checked == false && oCreditCard[1] != null && oCreditCard[1].checked == false && oCreditCard[2] != null && oCreditCard[2].checked == false)){
			oForm.strExpiryDate.disabled = true;
			oForm.strCardNo.disabled = true;
			oForm.strCardHolder.disabled = true;
			oForm.btnSubmit.disabled = false;
		}else{
			oForm.strExpiryDate.disabled = false;
			oForm.strCardNo.disabled = false;
			oForm.strCardHolder.disabled = false;
			oForm.btnSubmit.disabled = true;
		}

		for (i = 0; i < oCreditCard.length;i++)
		{
			oCreditCard[i].disabled = false;
		}
		*/

		if (oForm.strDate != null){
			oForm.strDate.disabled = true;
			oForm.strTime.disabled = true;
			oForm.strTime1.disabled = true;
		}
	}else{
		/*
		for (i = 0; i < oCreditCard.length;i++)
		{
			oCreditCard[i].disabled = true;
		}
		//oForm.strExpiryDate.disabled = true;
		//oForm.strExpiryDate.value = "";
		//oForm.strCardNo.disabled = true;
		//oForm.strCardNo.value = "";
		//oForm.strCardHolder.disabled = true;
		//oForm.strCardHolder.value = "";
		//oForm.btnSubmit.disabled = false;

		*/

		if(oPayment[2] != null && oPayment[2].checked == false)
		{
			if ((oForm.strDate != null) && (oForm.strTime != null)){
				oForm.strDate.disabled = true;
				oForm.strDate.value = "MM/DD/YYYY";
				oForm.strTime.disabled = true;
				oForm.strTime.value = "HH:MM AM/PM";
				oForm.strTime1.disabled = true;
			}
		}else{
			if ((oForm.strDate != null) && (oForm.strTime != null)){
				oForm.strDate.disabled = false;
				oForm.strTime.disabled = false;
				oForm.strTime1.disabled = false;
			}
		}

	}
}

function SubmitForms()
{
	var oForm = document.frmData;
	if (oForm.strFirstName.value.length == 0)
	{
		alert("A billing first name is required.");
		return false;
	}
		if (oForm.strLastName.value.length == 0)
	{
		alert("A billing last name is required.");
		return false;

	}
	if(oForm.strAddress.value.length == 0)
	{
		alert("A billing address is required.");
		return false;
	}
	if(oForm.strAddress.value.length > 500)
	{
		alert("A billing address length must be between 1 to 500 characters.");
		return false;
	}
	if (oForm.strCity.value.length == 0)
	{
		alert("A billing city is required.");
		return false;
	}
		if (oForm.strProvince.value.length == 0)
	{
		alert("A billing state/province is required.");
		return false;
	}
		if (oForm.strZip.value.length == 0)
	{
		alert("A billing zip code is required.");
		return false;
	}
	if (oForm.intCountry.selectedIndex < 1)
	{
		alert("A billing country is required.");
		return false;
	}
	if (oForm.strEmail.value.length == 0)
	{
		alert("An email address is required.");
		return false;
	}else{
		if (checkEmailValid(oForm.strEmail.value) != "0")
		{
			alert(checkEmailValid(oForm.strEmail.value))
			return false;

	}
		if (oForm.strLetUsKnow.value.length == 0)
	{
		alert("How You Heard About Us is required. Thank you!");
		return false;

			}
	}


	if ((oForm.chkBilling.checked == false) && (oForm.optDelivery.value !=1))
	{
		if (oForm.strShippingFirstName.value.length == 0)
		{
			alert("A delivery first name is required.");
			return false;
		}
		if (oForm.strShippingLastName.value.length == 0)
		{
			alert("A delivery last name is required.");
			return false;
		}
		if(oForm.strShippingAddress.value.length == 0)
		{
			alert("A delivery address is required.");
			return false;
		}
		if(oForm.strShippingAddress.value.length > 500)
		{
			alert("A delivery address length must be between 1 to 500 characters.");
			return false;
		}

		if (oForm.strShippingCity.value.length == 0)
		{
			alert("A delivery city is required.");
			return false;
		}
				if (oForm.strShippingProvince.value.length == 0)
		{
			alert("A delivery state/province is required.");
			return false;
		}
				if (oForm.strShippingZip.value.length == 0)
		{
			alert("A delivery zip code is required.");
			return false;
		}
		if (oForm.intShippingCountry != null)
		{
			if (oForm.intShippingCountry.options[oForm.intShippingCountry.selectedIndex].value <= 1 || oForm.intShippingCountry.options[oForm.intShippingCountry.selectedIndex].value.length == 0)
			{
				alert("A delivery country is required.");
				return false;
			}
		}
	}
	var iPayment = false

	for(var i = 0; i < oForm.optPayment.length ; i++)
	{
		if (oForm.optPayment[i].checked == true)
		{
			iPayment = true;
			break;
		}
	}

	if (iPayment == false)
	{
		alert("Please select payment method.");
		return false;
	}

	if (oForm.optPayment[0].checked == true)
	{
		/*
		var blnCredit = false;
		for(var i = 0; i < oForm.optCreditCard.length; i++)
		{
			if (oForm.optCreditCard[i].checked == true)
			{
				blnCredit = true;
			}
		}
		if (!blnCredit)
		{
			alert("Please select credit card type.");
			return false;
		} */
	}
	/*if (oForm.optPayment[0].checked == true)
	{
		var strVal = CheckMMYY(oForm.strExpiryDate.value);
		if (oForm.strExpiryDate.value == "MM/YY" || oForm.strExpiryDate.value.length == 0)
		{
			alert("A credit card expiry date is required.");
			return false
		}
		if ( strVal == false)
		{
			alert("The credit card expiry date is in the incorrect format.");
			return false;
		}else{
			if(IsExpiryDate(oForm.strExpiryDate.value)== false)
			{
				alert("The credit card expiry date is expired.");
				return false;
			}
			oForm.strHdnExpiryDate.value = strVal
		}
		if (oForm.strCardNo.value.length == 0)
		{
			alert("A credit card number is required.");
			return false;
		}
		if(oForm.strCardHolder.value.length == 0)
		{
			alert("The credit card holder's name is required.");
			return false;
		}
	}
	*/
	if ((oForm.optPayment[2] != null) && (oForm.optPayment[2].checked == true)){
		if(!DateCheck(oForm.strDate, true,true)){
			return false;
		}else{
			if(isRangeDate(oForm.strDate.value,"12/31/2078") == false || isRangeDate("01/01/1900",oForm.strDate.value) == false )
			{
				alert("Date must be between 01/01/1900 and 12/31/2078.");
				return false;
			}
		}
		if (IsExpiryDate(oForm.strDate.value))
		{
			alert("The pick up date must be greater than current date.");
			return false;
		}
		//if(oForm.strTime.value == "HH:MM AM/PM" || oForm.strTime.value.length == 0 )
		//{
			//alert("The pick up time is required.");
			//return false;
		//}
		//if(CheckTime(oForm.strTime.value) == false){
			//alert("The pick up time is in the incorrect format.");
			//return false;
		//}
		if(oForm.strTime1.value.length == 0)
		{
			alert("The pick up time is required.");
			return false;
		}
	}
	document.frmData.action = "shoppingcartaction.asp?do=submit"
	document.frmData.submit();
}

function DateValid(DateField,ROption,PopMsg)	{
 //return 0 If  Data is in Currect Format and the value is possible.
  var dateFormat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
  var matchArray = DateField.value.match(dateFormat);
  var ErrMessage="";
    if (matchArray == null) {
     if ((DateField.length>0) || (DateField.value !="")) {
	 	ErrMessage=ErrMessage+"Date format is incorrect ! [MM/DD/YYYY], ";
		}
		else {
		  if (ROption==true) {
	    	  ErrMessage="Can not be empty Date value, ";
			}
		 }  //if Length
     }
	  else //Check data Value
       {
	    day = matchArray[3];
    	month = matchArray[1];
		year = matchArray[4];
		if (day < 1 || day > 31) {
			ErrMessage=ErrMessage+" Day must be between 1 and 31, ";}
	  	if (month < 1 || month > 12) {
			ErrMessage=ErrMessage+ " Month must be between 1 and 12, ";}
	  	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			ErrMessage=ErrMessage+" - Month "+month+" doesn't have 31 days!, ";}
	  	if (month == 2) {
	    	 var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
         	  if (day>29 || (day==29 && !isleap)) {
                 ErrMessage=ErrMessage+" - February " + year + " doesn't have " + day + " days!, "; }
	       }
	 }//end else null
	 if ((ErrMessage.length>0) ||  (ErrMessage != "")) {
		if (ROption==true) {
			 alert("Error Message  !!\r"+ErrMessage+"\r  It must have value, Please input data again.");
			  return ErrMessage;
		   }
		   else {
			  if (PopMsg==true) {
			    alert("Error Message  !!\r"+ErrMessage+"\r");
			  }
			  return ErrMessage;
		    } //End MOption
	  }
  	   else
	    {
			return "0";
	    }
}//End function

function DateCheck(Field,ROption,PopMsg) {
 var Msg=DateValid(Field,false,false);
 if (Msg != "0") {
	if (ROption==true) {
	  alert("Error Message  !!\r"+Msg+"\r  It must have value, Please input data again.");
	  Field.select();
	  Field.focus();
	  return false;
	  }
	  else
	   {
		  if (PopMsg==true) {
		    alert("Error Message  !!\r"+Msg+"\r");
			Field.value="";
		  }
		  return false;
	   } //End ROption
   }//End IF Error
   return true;
}

function isRangeDate(DateStr1,DateStr2){
 var xDate1=new Date(DateStr1);
 var xDate2=new Date(DateStr2);
 if (xDate2 >=xDate1) {
 	return true;}
  else {
  	return false;}
}

function CheckMMYY(s)
{
	s = s + "";
	s.toLowerCase();

	var  m, y;
	var arrMonth = new Array(
		"january",
		"february",
		"march",
		"april",
		"may",
		"june",
		"july",
		"august",
		"september",
		"october",
		"november",
		"december"
	);


	sTmp = s.split("/");
	if (sTmp.length != 2 || sTmp.length < 2 || sTmp.length > 2)
	{
		return false;
	}
	if(isNaN(Number(sTmp[0])) || Number(sTmp[0]) > 12 || Number(sTmp[0]) < 1)
	{
		return false;
	}
	if (isNaN(Number(sTmp[1])) || sTmp[1].length != 2)
	{
		return false;
	}
	for(var i = 0 ; i < arrMonth.length; i++)
	{
		if (i + 1 == Number(sTmp[0]))
		{
			if (sTmp[1].length <= 2)
			{
				if(Number(sTmp[1]) <= 78)
				{
					sTmp[1] = "20" + sTmp[1];
				}else{
					sTmp[1] = "19" + sTmp[1];
				}
			}
			sVal = arrMonth [i] + " 01, " + sTmp[1];
			return sVal;
		}
	}
}

function IsExpiryDate(sDate)
{
	var curDate = new Date();
	var chkDate = new Date(sDate);

	var arrMMYY = sDate.split("/");

	var curDay = curDate.getDate();
	var curMonth = curDate.getMonth() + 1;
	var curYear = curDate.getYear();

	var strDate = curMonth + "/" + curDay + "/" + curYear;

	var chkDay = "";
	var chkMonth = "";
	var chkYear = "";

	if (isNaN(chkDate) && (CheckMMYY(sDate) == false))
	{
		return false;
	}else{
		if (isNaN(chkDate)){
			chkMonth = arrMMYY[0];
			chkYear = arrMMYY[1];
			if (Number(chkYear) < 79)
			{
				chkYear = "20" + chkYear;
			}else{
				chkYear = "19" + chkYear;
			}
			if (Number(chkYear) < curYear)
			{
				return false;
			}else{
				if (Number(chkMonth) < curMonth && curYear == Number(chkYear))
				{
					return false;
				}
			}
		}else{
			if(isRangeDate(strDate,sDate)== true)
			{
				return false;
			}
		}
	}
	return true;
}

function DisabledCreditCardDesc(flag)
{
	var oForm = document.frmData;
	if (oForm.strExpiryDate != null){
		oForm.strExpiryDate.disabled = flag;
	}

	if (oForm.strCardNo != null){
		oForm.strCardNo.disabled = flag;
	}

	if (oForm.strCardHolder != null){
		oForm.strCardHolder.disabled = flag;
	}
	oForm.btnSubmit.disabled = !flag;
}

   // Original JavaScript code by Duncan Crombie: dcrombie@chirp.com.au
   // Please acknowledge use of this code by including this header.

   // CONSTANTS
  var separator = ",";  // use comma as 000's separator
  var decpoint = ".";  // use period as decimal point
  var percent = "%";
  var currency = "$";  // use dollar sign for currency

  function formatNumber(number, format, print) {  // use: formatNumber(number, "format")
    if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

    if (number - 0 != number) return null;  // if number is NaN return null
    var useSeparator = format.indexOf(separator) != -1;  // use separators in number
    var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
    var useCurrency = format.indexOf(currency) != -1;  // use currency format
    var isNegative = (number < 0);
    number = Math.abs (number);
    if (usePercent) number *= 100;
    format = strip(format, separator + percent + currency);  // remove key characters
    number = "" + number;  // convert number input to string

     // split input value into LHS and RHS using decpoint as divider
    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

     // split format string into LHS and RHS using decpoint as divider
    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

     // adjust decimal places by cropping or adding zeros to LHS of number
    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

 // patch provided by Patti Marcoux 1999/08/06
      while (srightEnd.length > nrightEnd.length) {
        nrightEnd = "0" + nrightEnd;
      }

      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
        else break;
      }
    }

     // adjust leading zeros
    sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length) {
      nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
    }

    if (useSeparator) nleftEnd = separate(nleftEnd, separator);  // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
    if (isNegative) {
      // patch suggested by Tom Denn 25/4/2001
      output = (useCurrency) ? "(" + output + ")" : "-" + output;
    }
    return output;
  }

  function strip(input, chars) {  // strip all characters in 'chars' from input
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return output;
  }

  function separate(input, separator) {  // format input using 'separator' to mark 000's
     input = "" + input;
     var output = "";  // initialise output string
  for (var i=0; i < input.length; i++) {
      if (i != 0 && (input.length - i) % 3 == 0) output += separator;
     output += input.charAt(i);
   }
    return output;
  }


//---------- disable right click
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
var EnableRightClick = 0;
if(isNS)
document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
  if(EnableRightClick==1){ return true; }
  else {return false; }
}
function mousehandler(e){
  if(EnableRightClick==1){ return true; }
  var myevent = (isNS) ? e : event;
  var eventbutton = (isNS) ? myevent.which : myevent.button;
  if((eventbutton==2)||(eventbutton==3)) return false;
}
function keyhandler(e) {
  var myevent = (isNS) ? e : window.event;
  if (myevent.keyCode==96)
    EnableRightClick = 1;
  return;
}
document.oncontextmenu = mischandler;
document.onkeypress = keyhandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;

//-----------------------------------------
function openWindowContactLog(url,name)
    {

	var widgets ="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,left=230,top=110,resizable=no,width=380,height=350"
	popupWin = window.open (url,name,widgets);
	popupWin.focus();
    }
	function openWindowOrderItem(url,name)
    {

	var widgets ="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,left=50,top=50,resizable=yes,width=700,height=400"
	popupWin = window.open (url,name,widgets);
	popupWin.focus();
    }
function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth;
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0;
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}

 function openWindow(url,name)
    {

	var widgets ="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,left=250,top=150,resizable=no,width=370,height=350"
	popupWin = window.open (url,name,widgets);
	popupWin.focus();
    }

//Email Address
function checkEmailValid(emailStr)
{
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var errMsg="The email address is not correct.";
var matchArray=emailStr.match(emailPat)

if (matchArray==null)
{
   //errMsg=errMsg+"The email address seems incorrect (please check @ and .)!";
   return errMsg;
}
else
{
  var user=matchArray[1]
  var domain=matchArray[2]
  if (user.match(userPat)==null)
  {
    //errMsg=errMsg+"your username is invalid! ";
	return errMsg;
  }
  var IPArray=domain.match(ipDomainPat)
  if (IPArray!=null)
  {
	  for (var i=1;i<=4;i++)
          {
	    if (IPArray[i]>255)
            {
	        //errMsg=errMsg+"destination IP address is invalid! ";
			return errMsg;
            }//IF
          }//for
   }//IP Array
   var domainArray=domain.match(domainPat)
   if (domainArray==null)
   {
	 //errMsg=errMsg+"The domain name is invalid!";
	 return errMsg;
   }
   var atomPat=new RegExp(atom,"g")
   var domArr=domain.match(atomPat)
   var len=domArr.length
   if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
   {
     //errMsg=errMsg+"The email address must end with a three-letter domain, or two letter country!";
	 return errMsg;
   }
   if (len<2)
   {
     //errMsg=errMsg+"Your email address does not have a hostname!";
	 return errMsg;
   }
 }//End  Match
return "0";
}

function checkLogon()
{
var strUserName = document.frmData.strLoginName.value;
var strPassword = document.frmData.strPassword.value;
if(strUserName=="")
{
   alert("Your logon name is required to sign in!");
   return false;
}
if(strPassword=="")
{
  alert("Your password is required to sign in!");
  return false;
}
return true;
}

function goControlPanel()
{
var loc = "index.asp";
  window.location.href  = loc;
}

function goHome()
{
var loc = "http://www.nancychandler.net";
  window.location.href  = loc;
}


function goMainPage(strPage)
{
var loc = strPage;
  window.location.href  = loc;
}

function checkDuplicate()
  {

           if (document.frmData.chkDup.value == "True")
      {
        alert("Sorry - The " + document.frmData.inputName.value + " " + document.frmData.inputData.value + " already exists in system");
        return false;
     }
     return true;
  }

function checkDateAndDuplicate()
 {
	   if (document.frmData.chkDup.value == "True")
  {
	alert("Sorry - The " + document.frmData.inputName.value + " " + document.frmData.inputData.value + " already exists in system!");
	return false;
  }
       if (document.frmData.chkErrDate.value == "True")
  {
    alert(document.frmData.errDate.value);
	return false;
  }
 return true;
}

function checkAdministrator()
{
if (document.frmData.strLoginName.value=="")
{
   alert("The logon name is required information!");
   return false;
}
if (document.frmData.strPassword.value=="")
{
   alert("The password is required information!");
   return false;
}
if (document.frmData.strConfPassword.value=="")
{
   alert("The confirmation  password is required information!");
   return false;
}
if (document.frmData.strPassword.value !=document.frmData.strConfPassword.value)
{
   alert("The password and the comfirmation password do not match!");
   return false;
}
}

function checkCityBox()
  {
  	if  (document.frmData.strCityName.value == "")
      {
        alert("The city name is required information!");
        return false;
      }

return true;
}

function checkCountryBox()
  {
  	if  (document.frmData.strCountryName.value == "")
      {
        alert("The country name is required information!");
        return false;
      }

return true;
}

function checkUpdateCategoryBox()
  {
  	if  (document.frmData.strUpdateCategoryName.value == "")
      {
        alert("The update category name is required information!");
        return false;
      }

return true;
}



function checkCompanyBox()
  {
   var strMainEmail = document.frmData.strMainEmail.value;

	if  (document.frmData.strCompanyName.value == "")
      {
        alert("The company name is required information!");
        return false;
      }

	if  (document.frmData.strTradingName.value == "")
      {
        alert("The trading name is required information!");
        return false;
      }

	if  (strMainEmail == "")
      {
        alert("The main email is required information!");
        return false;
      }
     	else
      {
   	if (checkEmailValid(strMainEmail) !="0")
            {
      	alert( checkEmailValid(strMainEmail));
      	return false;
            }
    }

    	   if(document.frmData.strSlogan.value.length > 100)
  {
	  alert("The length of slogan must be smaller than 100 characters!");
  	  return false;
  }
	 if  (document.frmData.strAddress.value.length>200)
    {
        alert("The length of  address must be smaller than 200 characters!");
         return false;
   }
        return true;
  }

function checkCityEventBox()
{
	if  (document.frmData.strEventName.value == "")
      {
        alert("The event name is required information!");
        return false;
      }
	if  (document.frmData.intCityId.value == 0)
      {
        alert("The city is required information!");
        return false;
      }

	if  (document.frmData.strDescription.value == "")
      {
        alert("The descriptions is required information!");
        return false;
      }
    else
    {

                        if  (document.frmData.strDescription.value.length>1000)
       {
            alert("The length of descriptions must be smaller than 1000 characters!");
            return false;
       }
   }

	if  (document.frmData.txtDate.value == " Click The Icon >>")
      {
        alert("The start date is missing!");
        return false;
      }
	if  (document.frmData.txtDate2.value == " Click The Icon >>")
      {
        alert("The end date is missing!");
        return false;
      }

return true;
}

function checkProductCategoryBox()
{
	if  (document.frmData.strProductCategoryName.value == "")
      {
        alert("The product category name is required information!");
        return false;
      }
	   if  (document.frmData.strProductCategorySubTitle.value.length>500)
    {
        alert("The length of sub title must be smaller than 500 characters!");
         return false;
   }
	   if  (document.frmData.strDescription.value.length>2000)
    {
        alert("The length of descriptions must be smaller than 2000 characters!");
         return false;
   }
return true;
}

function checkContactCategoryBox()
{
var strEmailTo = document.frmData.strEmailTo.value;

	if  (document.frmData.strContactCategoryName.value == "")
      {
        alert("The contact category name is required information!");
        return false;
      }
	if (strEmailTo  != "")
   {
	if (checkEmailValid(strEmailTo) !="0")
      {
     alert( checkEmailValid(strEmailTo));
      	return false;
            }
  }
return true;
}

function format(value, lead, sep)
{
	var strValue = new String(value);
	var len = strValue.length;
	var n;
	var strRet = '';
	var ctChar = 3 - (len%3);
	if (ctChar == 3) ctChar =0;
	for (n=0; len > n; n++) {
		if (ctChar == 3) {
			strRet += sep;
			ctChar = 0;
		}
		ctChar++;
		strRet += strValue.substring(n,n+1)
	}
	if (lead == '%')
	{
		return strRet + lead;
	}
	else
	{
		return lead + strRet;
	}
}

//Numeric Format
function numFormat(elem, lead, sep, Min, Max)
{
	if (elem.value == '')
	{
		elem.value = format(Min, lead, sep);
		return true;
	}
	var value = parseInt(cleanNumber(elem.value), 10);
	if (lead == '')
	{
		if (Min > value)
		{
			alert('You have exceeded the range for the interior size.\nPlease check your information and try again!');
			value = Min;
		}
		if (value > Max)
		{
			alert('You have exceeded the range for the interior size.\nPlease check your information and try again!');
			value = Max;
		}
	}
	if (isNaN(value))
	{
		alert('You have entered an incorrect character on this field. \nPlease check your information and try again!');
		elem.value = format(Min, lead, sep);
		elem.focus();
		return false;
	}
	elem.value = format(value, lead, sep);
	return true;
}


function replace(szBuf, szFind, szReplace, lStart)
{
	var lFind = 0;
	if (!lStart) lStart = 0;

	while (lFind != -1) {
		lFind = szBuf.indexOf(szFind, lStart);

		if (lFind != -1) {
			szBuf = szBuf.substring(0,lFind) + szReplace + szBuf.substring(lFind + szFind.length);
			lStart = lFind + szReplace.length;
		}
	}
	return szBuf;
}

function cleanNumber(strNum)
{
	if (!strNum) return strNum;
	strNum = replace(strNum, '$', '', 0);
	strNum = replace(strNum, ',', '', 0);
	strNum = replace(strNum, '%', '', 0);
	return strNum;
}

function onFloatChange(pElem)
{
	var v =cleanNumber(pElem.value);
	var N=0.00;
	if (isNaN(Number(v)))
	{
		alert('Data entry is not correct !.\r Data must be number.');
		pElem.value='0';
		pElem.focus();
		return false;
	}
	else
	{
	 N=parseFloat(v);

	    if (!((N>=0) && (N<=9999999))) {
		alert('Data entry is not correct !.\r Range of data in [0..9999999].');
		pElem.value='0';
		pElem.focus();
		return false;
	    }

	}
	return(true);
}

function onTinyIntChange(pElem)
{
	var v =cleanNumber(pElem.value);
	var bInvalid = false;

	if (isNaN(Number(v)))
	{
		bInvalid = true;
	}
	numFormat(pElem, '', '',1,255);
	return(true);
}

function onPriceChange(pElem)
{
	var v =cleanNumber(pElem.value);
	var N=0.00;
	if  (v!='')
	{
		if (isNaN(Number(v)))
		{
			alert('Data entry is not correct !.\r Data must be number.');
			pElem.value='';
			pElem.focus();
			return false;
		}
		else
		{
		 N=parseFloat(v);

			if (!((N>=0) && (N<=9999999))) {
			alert('Data entry is not correct !.\r Range of data in [0..9999999].');
			pElem.value='';
			pElem.focus();
			return false;
			}
		}
	}
	return(true);
}
function checkProductBox()
{

	if  (document.frmData.strProductName.value == "")
      {
        alert("The product name is required information!");
        return false;
      }
	if  (document.frmData.intProductCategoryId.value == "0")
      {
        alert("The product category is required information!");
        return false;
      }

		 if  (document.frmData.strDescription.value.length>3000)
    {
        alert("The length of descriptions must be smaller than 3000 characters!");
         return false;
   }

		 if  (document.frmData.strOtherDetail.value.length>500)
    {
        alert("The length of other descriptions must be smaller than 500 characters!");
         return false;
   }

	if (document.frmData.txtDate.value.toLowerCase() == "mm/dd/yyyy")
	{
		document.frmData.txtDate.value = "";
	}
	if (document.frmData.txtDate2.value.toLowerCase() == "mm/dd/yyyy")
	{
		document.frmData.txtDate2.value = "";
	}
	if (document.frmData.txtDate3.value .toLowerCase() == "mm/dd/yyyy")
	{
		document.frmData.txtDate3.value = "";
	}

	if (document.frmData.txtDate.value.length > 0)
	{
		return DateCheck(document.frmData.txtDate, false,true);
	}

	if (document.frmData.txtDate2.value.length > 0)
	{
		if (!DateCheck(document.frmData.txtDate2, false,true))
		{
			return  false;
		}
	}
	if (document.frmData.txtDate3.value.length > 0)
	{
		if (!DateCheck(document.frmData.txtDate3, false,true))
		{
			return false;
		}
	}

return true;
}

function CheckEnterPermission()
{
	alert('Please enter the date by clicking on the calendar icon!');
	document.frmData.btnSave.focus();
}

function checkCommentBox()
{
	var strEmail = document.frmData.strEmail.value;

	if  (document.frmData.strKicker.value == "")
      {
        alert("The kicker is required information!");
        return false;
      }
	 if (document.frmData.strKicker.value.length > 300)
	 {
	 	alert("The length of  kicker must be smaller than 300 characters!");
		return false
	 }

	if  (document.frmData.strSource.value == "")
      {
        alert("The source is required information!");
        return false;
      }
	 if  (document.frmData.strTrailer.value.length>500)
    {
        alert("The length of  trailer must be smaller than 500 characters!");
         return false;
   }

	if (strEmail  != "")
   {
		if (checkEmailValid(strEmail) !="0")
      {
                     alert( checkEmailValid(strEmail));
      	return false;
      }
 }

return true;
}

function checkReviewBox()
{

	if  (document.frmData.strKicker.value == "")
      {
        alert("The kicker is required information!");
        return false;
      }
	if (document.frmData.strKicker.value.length > 300)
	{
        alert("The length of  kicker must be smaller than 300 characters!");
         return false;
	}
	if  (document.frmData.strSource.value == "")
      {
        alert("The source is required information!");
        return false;
      }

	 if  (document.frmData.strTrailer.value.length>500)
    {
        alert("The length of  trailer must be smaller than 500 characters!");
         return false;
   }

return true;
}

function checkProductImageBox()
{

	if  (document.frmData.strLoc.value == "")
      {
        alert("The image location is required information!");
        return false;
      }

return true;
}

function checkProductUpdateBox()
{

	if  (document.frmData.intUpdateCategoryId.value == "0")
      {
        alert("The update category  is required information!");
        return false;
      }

	if  (document.frmData.strHeader.value == "")
      {
        alert("The header is required information!");
        return false;
      }
	 if  (document.frmData.strDescription.value.length>1000)
    {
        alert("The length of descriptions must be smaller than 1,000 characters!");
         return false;
   }
	return true;
}


function checkNewContactlog()
{

	if  (document.frmData.strContactName.value == "")
      {
        alert("Please enter your Contact Name!");
        return false;
      }
	var e=document.frmData.strEmail.value;
	if (e=="")
	{
		alert("Please enter your Email Address!");
		return false;
	}
	else
	{
		if (checkEmailValid(e) !="0")
		{
			alert( checkEmailValid(e));
			return false;
		}
	}

	if (document.frmData.intCategoryId.value==0)
	{
		alert("Please enter your category!")
		return false;
	}

	if (document.frmData.strMessage.value.length > 2000)
	{
		  alert("The length of message must be smaller than 2000 characters!");
		  return false;
	}
	return true;
}


function OptControl(sName){
	var oForm = document.frmData;
	var s = sName.toLowerCase();
	if (s == "chkismain")
	{
		if (oForm.chkIsMain.checked)
		{
			oForm.chkIsPreview.checked = false;
		}
	}

	if (s == "chkispreview")
	{
		if (oForm.chkIsPreview.checked)
		{
			oForm.chkIsMain.checked = false;
		}
	}
}

function checkPaymentStatusBox()
{
	   if  (document.frmData.strPaymentStatusDesc.value=="")
    {
       alert("The payment status description is required information!");
         return false;
   }
return true;
}

function checkOrderStatusBox()
{
	   if  (document.frmData.strOrderStatusDesc.value=="")
    {
	   alert("The order status description is required information!");
	   return false;
   }
return true;
}

function checkPricingGuideBox()
{
  if  (document.frmData.strCode.value=="")
    {
	   alert("The code is required information!");
	   return false;
   }
   return true;
}

function right(e)
{
	var errmsg = "All images copyright Nancy Chandler. Please do not copy without permission.";

	if (navigator.appName == 'Netscape' && e.which == 3)
    {
	  alert(errmsg);
	  return false;
	}

	if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2)
    {
	  alert(errmsg);
	  return false;
	}
	else return true;
}

function disableclick()
{
  if(document.images)
  {
    for(i=0;i<document.images.length;i++)
    {
      document.images[i].onmousedown = right;
      document.images[i].onmouseup = right;
    }
  }
}

function GotoDelivery(iCase, iPId)
{
  iCase = iCase + "";

  if (iCase.length == 0)
  {
	return;
  }
  window.location = "shoppingcart.asp?pId=" + iPId + "&case=" + iCase;
}

function CheckOutShoppingCart()
{
  window.location = "shoppingcart.asp?case=3";
}

function ShowPicture(url,h,w)
{
  url = url + "";
  if (url.length == 0)
  {
	return false;
  }
  strUrl = "showimages.asp?url=" + url;
  window.open(strUrl,"window_showpicture","toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised,dependent,titlebar=no,width=" + w + ",height=" + h + ",left=100,top=50");
}
