//global declartions

var chkoutUpdate = 0;
var chkoutDelete = 0;

regName = new RegExp(/^[a-zA-Z ]+$/);
regEmail = new RegExp(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/);
regAddress = new RegExp(/^[a-zA-Z0-9_,-;#&\:\(\)\.\\/ ]+$/);
regPhone = new RegExp(/^(1(\/|-|\s|.|))?(\(?\d{3}\)?)?(\/|-|\s|.|)?\d{3}(\/|-|\s|.|)?\d{4}(\/|-|\s|.|)?((x|ext)(.*)\d+)?$/i)
regPin = new RegExp(/^[0-9]{6}$/);
regAlpNum = new RegExp(/^[a-zA-Z0-9 ]+$/)
regProdName = new RegExp(/^[a-zA-Z0-9\(\)& ]+$/)
regDecimal = new RegExp(/^\d+(\.\d{2})*$/)

//alert(regAddress);

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();

function checkJavaScriptValidity() {

	document.getElementById("jsEnabled").style.visibility = 'visible';
	document.getElementById("jsEnabled").style.display = 'block';
	document.getElementById("jsDisabled").style.visibility = 'hidden';
	document.getElementById("jsDisabled").style.display = 'none';
	document.getElementById("jsDisabled1").style.visibility = 'hidden';
	document.getElementById("jsDisabled1").style.display = 'none';
}

function hide(divID) {
  var item = document.getElementById(divID);
  if(item) {
  	item.style.visibility = 'hidden'; //collapse  hidden
 	item.style.display = 'none';
 }
}

function unhide(divID) {
  var item = document.getElementById(divID);
   if(item) {
  	item.style.visibility = 'visible';
  	item.style.display = 'block';
  }
}


function disProdSel(SelItem,Add2Cart,count)
{
	//hide(SelItem);
	unhide(Add2Cart);
	var i=0;
	do {
		//SelItems = SelItem + i;
		Add2Carts = Add2Cart + i;
		//hide(SelItems);
		unhide(Add2Carts);
		i++;
	}while(i<count);
	
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail ID")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail ID")
	    return false
	 }

	 return true					
}

function IsInteger(strString)
   //  check for valid unsigned integer strings 
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function val_signin(signfrm)
 {
 	if((signfrm.txtUserId.value == '') || (signfrm.txtUserId.value == null)) {
 		alert("Please Enter user name");
		signfrm.txtUserId.focus();
		return false;
 	}
	else if(signfrm.txtUserId.value.length <= 5) {
 		alert("User name should have at least 6 characters");
		signfrm.txtUserId.focus();
		return false;
 	}
 	else if (echeck(signfrm.txtUserId.value)==false){
		signfrm.txtUserId.value=""
		signfrm.txtUserId.focus()
		return false;
	}
	if((signfrm.txtPWD.value == '') || (signfrm.txtPWD.value == null)) {
 		alert("Please enter your password");
		signfrm.txtPWD.focus();
		return false;
 	}
	else if(signfrm.txtPWD.value.length <= 5) {
 		alert("Password should have at least 6 characters");
		signfrm.txtPWD.focus();
		return false;
 	}
 	
 	return true;
 }

 function val_mbl_signin(signfrm)
 {
 	if((signfrm.txtMobileNo.value == '') || (signfrm.txtMobileNo.value == null)) {
 		alert("Please Enter your mobile number");
		signfrm.txtMobileNo.focus();
		return false;
 	}
	else if(signfrm.txtMobileNo.value.length != 10) {
 		alert("Mobile number should have 10 digits");
		signfrm.txtMobileNo.focus();
		return false;
 	}
	else if(!regPhone.test(signfrm.txtMobileNo.value)) {
 		alert("Please enter a valid mobile number");
		signfrm.txtMobileNo.focus();
		return false;
 	}
 	return true;
 }
 
 function val_forgotpassword(forpassfrm)
 {
 	if((forpassfrm.txtUserId.value == '') || (forpassfrm.txtUserId.value == null)) {
 		alert("Please Enter user name");
		forpassfrm.txtUserId.focus();
		return false;
 	}
	else if(forpassfrm.txtUserId.value.length <= 5) {
 		alert("User name should have at least 6 characters");
		forpassfrm.txtUserId.focus();
		return false;
 	}
 	else if (echeck(forpassfrm.txtUserId.value)==false){
		forpassfrm.txtUserId.value=""
		forpassfrm.txtUserId.focus()
		return false
	} 	
 	return true;
 }
 
 function val_register(regfrm)
 {
	/*regfrm.txtCompName.value = trim(regfrm.txtCompName.value);	
	if((regfrm.txtCompName.value != '') && (regfrm.txtCompName.value != null)) {
		if (!regName.test(regfrm.txtCompName.value)) {
			alert("Enter a valid company name");
			regfrm.txtCompName.focus();
			return false;
     		} 	
	}
	regfrm.txtDesignation.value = trim(regfrm.txtDesignation.value);
	if((regfrm.txtDesignation.value != '') && (regfrm.txtDesignation.value != null)) {
		if (!regName.test(regfrm.txtDesignation.value)) {
			alert("Enter a valid designation ");
			regfrm.txtDesignation.focus();
			return false;
     		} 	
	}*/	
 	regfrm.txtName.value = trim(regfrm.txtName.value);
	if((regfrm.txtName.value == '') || (regfrm.txtName.value == null)) {
		alert("Please Enter your name");
		regfrm.txtName.focus();
		return false;
	}
	else if(!regName.test(regfrm.txtName.value)) {
		alert("Please Enter valid name");
		regfrm.txtName.focus();
		return false
	}
	if((regfrm.txtEmailId.value == '') || (regfrm.txtEmailId.value == null)) {
		alert("Please Enter user email id");
		regfrm.txtEmailId.focus();
		return false;
	}
	else if(regfrm.txtEmailId.value.length <= 5) {
		alert("Email id should have at least 6 characters");
		regfrm.txtEmailId.focus();
		return false;
	}
	else if (echeck(regfrm.txtEmailId.value)==false){
		regfrm.txtEmailId.value=""
		regfrm.txtEmailId.focus()
		return false
	}	
 	
	if((regfrm.txtPWD.value == '') || (regfrm.txtPWD.value == null)) {
 		alert("Please enter your password");
		regfrm.txtPWD.focus();
		return false;
 	}
	else if(regfrm.txtPWD.value.length <= 5) {
 		alert("Password should have at least 6 characters");
		regfrm.txtPWD.focus();
		return false;
 	}
	if(regfrm.txtPWD.value != regfrm.txtRePWD.value) {
		alert("Password don't match.");
		regfrm.txtRePWD.focus();
		return false;
	}
	
	/*
	regfrm.txtContNo1.value = trim(regfrm.txtContNo1.value);
	regfrm.txtContNo2.value = trim(regfrm.txtContNo2.value);
	if(((regfrm.txtContNo1.value == '') || (regfrm.txtContNo1.value == null)) && ((regfrm.txtContNo2.value == '') || (regfrm.txtContNo2.value == null))) {
		alert("Please enter any of your contact no");
		regfrm.txtContNo1.focus();
		return false;
	}
	else  {
		if((regfrm.txtContNo1.value != '') && (regfrm.txtContNo1.value != null)) {
			if (!regPhone.test(regfrm.txtContNo1.value)) {
				alert("Phone Number Must Be Entered ");
				regfrm.txtContNo1.focus();
				return false;
			}
		}
		
		if((regfrm.txtContNo2.value != '') && (regfrm.txtContNo2.value != null)) {
			if (!regPhone.test(regfrm.txtContNo2.value)) {
				alert("Enter a valid phone number ");
				regfrm.txtContNo2.focus();
				return false;
			} 	
		}
	}
	*/
	regfrm.txtContNo1.value = trim(regfrm.txtContNo1.value);
	if((regfrm.txtContNo1.value == '') || (regfrm.txtContNo1.value == null)) {
 		alert("Please enter your contact no");
		regfrm.txtContNo1.focus();
		return false;
 	}
	else if (!regPhone.test(regfrm.txtContNo1.value)) {
		alert("Enter a valid phone number");
		regfrm.txtContNo1.focus();
		return false;
     	} 	
     	regfrm.txtContNo2.value = trim(regfrm.txtContNo2.value);
	if((regfrm.txtContNo2.value != '') && (regfrm.txtContNo2.value != null)) {
		if (!regPhone.test(regfrm.txtContNo2.value)) {
			alert("Enter a valid phone number ");
			regfrm.txtContNo2.focus();
			return false;
     		} 	
	}
	
	regfrm.txtAddr1.value = trim(regfrm.txtAddr1.value);
	if((regfrm.txtAddr1.value != '') && (regfrm.txtAddr1.value != null)) {
		if (!regAddress.test(regfrm.txtAddr1.value)) {
			alert("Enter a valid address ");
			regfrm.txtAddr1.focus();
			return false;
     		} 	
	}
	regfrm.txtAddr2.value = trim(regfrm.txtAddr2.value);
	if((regfrm.txtAddr2.value != '') && (regfrm.txtAddr2.value != null)) {
		if (!regAddress.test(regfrm.txtAddr2.value)) {
			alert("Enter a valid address ");
			regfrm.txtAddr2.focus();
			return false;
     		}
	}	
	regfrm.txtPin.value = trim(regfrm.txtPin.value);
	if((regfrm.txtPin.value != '') && (regfrm.txtPin.value != null)) {
		if (!regPin.test(regfrm.txtPin.value)) {
			alert("Enter a valid pin code ");
			regfrm.txtPin.focus();
			return false;
     		}
	}	
	 
 	return true;
 }
 
 function val_editUsrPrf(prffrm)
 {
	/*prffrm.txtCompName.value = trim(prffrm.txtCompName.value);	
	if((prffrm.txtCompName.value != '') && (prffrm.txtCompName.value != null)) {
		if (!regName.test(prffrm.txtCompName.value)) {
			alert("Enter a valid company name");
			prffrm.txtCompName.focus();
			return false;
     		} 	
	}
	prffrm.txtDesignation.value = trim(prffrm.txtDesignation.value);
	if((prffrm.txtDesignation.value != '') && (prffrm.txtDesignation.value != null)) {
		if (!regName.test(prffrm.txtDesignation.value)) {
			alert("Enter a valid designation ");
			prffrm.txtDesignation.focus();
			return false;
     		} 	
	}*/	
 		
	if(prffrm.txtEmailId.value.length <= 5) {
		alert("Email id should have at least 6 characters");
		prffrm.txtEmailId.focus();
		return false;
	}
	else if (echeck(prffrm.txtEmailId.value)==false){
		prffrm.txtEmailId.value=""
		prffrm.txtEmailId.focus()
		return false
	}
	if((prffrm.txtName.value == '') || (prffrm.txtName.value == null)) {
		alert("Please Enter your name");
		prffrm.txtName.focus();
		return false;
	}
	else if(!regName.test(prffrm.txtName.value)) {
		alert("Please Enter valid name");
		prffrm.txtName.focus();
		return false
	}
	if((prffrm.txtEmailId.value == '') || (prffrm.txtEmailId.value == null)) {
		alert("Please Enter user email id");
		prffrm.txtEmailId.focus();
		return false;
	}
	else if(prffrm.txtEmailId.value.length <= 5) {
		alert("Email id should have at least 6 characters");
		prffrm.txtEmailId.focus();
		return false;
	}
	else if (echeck(prffrm.txtEmailId.value)==false){
		prffrm.txtEmailId.value=""
		prffrm.txtEmailId.focus()
		return false
	}	
	
	if(prffrm.txtOldPWD.value != '' ) {
 		if(prffrm.txtOldPWD.value.length <= 5) {
	 		alert("Password should have at least 6 characters");
			prffrm.txtOldPWD.focus();
			return false;
	 	}
	 	
		if((prffrm.txtPWD.value == '') || (prffrm.txtPWD.value == null)) {
	 		alert("Please enter new password");
			prffrm.txtPWD.focus();
			return false;
	 	}
		else if(prffrm.txtPWD.value.length <= 5) {
	 		alert("Password should have at least 6 characters");
			prffrm.txtPWD.focus();
			return false;
	 	}
		if(prffrm.txtPWD.value != prffrm.txtRePWD.value) {
			alert("New Password don't match.");
			prffrm.txtRePWD.focus();
			return false;
		}
 	}
	
	/*
	if(((prffrm.txtContNo1.value == '') || (prffrm.txtContNo1.value == null)) && ((prffrm.txtContNo2.value == '') || (prffrm.txtContNo2.value == null))) {
 		alert("Please enter your contact no");
		prffrm.txtContNo1.focus();
		return false;
 	}
	else  {
		if((prffrm.txtContNo1.value != '') && (prffrm.txtContNo1.value != null)) {
			if (!regPhone.test(prffrm.txtContNo1.value)) {
				alert("Phone Number Must Be Entered ");
				prffrm.txtContNo1.focus();
				return false;
			}
		}
		prffrm.txtContNo2.value = trim(prffrm.txtContNo2.value);
		if((prffrm.txtContNo2.value != '') && (prffrm.txtContNo2.value != null)) {
			if (!regPhone.test(prffrm.txtContNo2.value)) {
				alert("Enter a valid phone number ");
				prffrm.txtContNo2.focus();
				return false;
			} 	
		}
	}
	*/
	
	prffrm.txtContNo1.value = trim(prffrm.txtContNo1.value);
	if((prffrm.txtContNo1.value == '') || (prffrm.txtContNo1.value == null)) {
 		alert("Please enter your contact no");
		prffrm.txtContNo1.focus();
		return false;
 	}
	else if (!regPhone.test(prffrm.txtContNo1.value)) {
		alert("Enter a valid phone number");
		prffrm.txtContNo1.focus();
		return false;
     	} 	
     	prffrm.txtContNo2.value = trim(prffrm.txtContNo2.value);
	if((prffrm.txtContNo2.value != '') && (prffrm.txtContNo2.value != null)) {
		if (!regPhone.test(prffrm.txtContNo2.value)) {
			alert("Enter a valid phone number ");
			prffrm.txtContNo2.focus();
			return false;
     		} 	
	}
	
	prffrm.txtAddr1.value = trim(prffrm.txtAddr1.value);
	if((prffrm.txtAddr1.value != '') && (prffrm.txtAddr1.value != null)) {
		if (!regAddress.test(prffrm.txtAddr1.value)) {
			alert("Enter a valid address ");
			prffrm.txtAddr1.focus();
			return false;
     		} 	
	}
	prffrm.txtAddr2.value = trim(prffrm.txtAddr2.value);
	if((prffrm.txtAddr2.value != '') && (prffrm.txtAddr2.value != null)) {
		if (!regAddress.test(prffrm.txtAddr2.value)) {
			alert("Enter a valid address ");
			prffrm.txtAddr2.focus();
			return false;
     		}
	}	
	prffrm.txtPin.value = trim(prffrm.txtPin.value);
	if((prffrm.txtPin.value != '') && (prffrm.txtPin.value != null)) {
		if (!regPin.test(prffrm.txtPin.value)) {
			alert("Enter a valid pin code ");
			prffrm.txtPin.focus();
			return false;
     		}
	}	     	
 	return true;
 }
 
function val_reqProd(reqfrm) {

	var reqProdName = trim(reqfrm.txtReqProdName.value);
	var reqProdDesc = trim(reqfrm.txtaReqProdDesc.value);
	var reqProdEmail = trim(reqfrm.txtReqProdEmail.value);
	var reqProdContNo = trim(reqfrm.txtReqProdContNo.value);

	if((reqProdName == '' || reqProdName == null) && (reqProdDesc == '' || reqProdDesc == null)) {		
 		alert("Please enter either product name or description of the product");
		reqfrm.txtReqProdName.value = reqProdName;
		reqfrm.txtaReqProdDesc.value = reqProdDesc;
		reqfrm.txtReqProdName.focus();
		return false;
	}
	else
	{
		if((reqProdName != '' && reqProdName != null) ) {
			if(!regAddress.test(reqProdName)) {
				alert("Please enter valid data. Some special characters like quote characters are not allowed");
				reqfrm.txtReqProdName.value = reqProdName;
				reqfrm.txtReqProdName.focus();
				return false;
			}
		}	
		if((reqProdDesc != '' && reqProdDesc != null) ) {
			if(!regAddress.test(reqProdDesc)) {
				alert("Please enter valid data. Some special characters like quote characters are not allowed");
				reqfrm.txtaReqProdDesc.value = reqProdDesc;
				reqfrm.txtaReqProdDesc.focus();
				return false;
			}

		}
	}
	if((reqProdEmail == '' || reqProdEmail == null) && (reqProdContNo == '' || reqProdContNo == null)) {
 		alert("Please enter either email id or contact no");
		reqfrm.txtReqProdEmail.value = reqProdEmail;
		reqfrm.txtReqProdContNo.value = reqProdContNo;
		reqfrm.txtReqProdEmail.focus();
		return false;
 	}
	else {
		if(reqProdEmail != '') {
			if (echeck(reqProdEmail)==false){
				reqfrm.txtReqProdEmail.value = reqProdEmail;		
				reqfrm.txtReqProdEmail.focus()
				return false
			}
		}		
		if(reqProdContNo != '') {
		 	if (!regPhone.test(reqProdContNo)){
				alert('Please enter a valid contact no.');
				reqfrm.txtReqProdContNo.value = reqProdContNo;	
				reqfrm.txtReqProdContNo.focus();
				return false
			}
		}
	}
	reqfrm.txtReqProdName.value = reqProdName;
	reqfrm.txtaReqProdDesc.value = reqProdDesc;
	reqfrm.txtReqProdEmail.value = reqProdEmail;
	reqfrm.txtReqProdContNo.value = reqProdContNo;
	return true;
}

function val_addtocart(frmadd2cart,itemscount) {
	var itemselected = 0;
	var selQuantity = 0;
	for(var i=0;i<itemscount;i++)
	{
		var chksel = document.getElementById('chkSelectItem'+i);
		var quantity = document.getElementById('txtQuantity'+i);
		var hasAttrb = document.getElementById('hdnProductAttributes'+i);
		var quantityval = trim(quantity.value);
		/*if (quantityval != '') {
			chksel.checked = true;
		}*/
		//alert(chksel.checked)
		if(quantityval != '') {
			itemselected = 1;
			//alert(quantity)
			if(hasAttrb.value =="Y")
			{
				var txtAttrb = trim(document.getElementById('txtAttributes'+i));
				txtAttrb.value = trim(txtAttrb.value);
				if(txtAttrb.value != '' || txtAttrb.value == null)
				{
					if(!regAlpNum.test(txtAttrb.value))
					{
						alert('Please enter valid Special request');
						txtAttrb.focus();
						txtAttrb.select();
						return false;
					}
				}
			}
			if(quantityval == null || quantityval =='')
			{
				selQuantity = 1;
				alert('Please enter the quantity for the selected product');
				quantity.focus();
				quantity.select();
				return false;
			}
			else {
				if(isNaN(quantityval) || quantityval == 0) {
				alert('Please enter a numeric value greater then Zero');
					quantity.focus();					
					return false;
				}
				if(!IsInteger(quantityval))
				{
					alert(' Quantity cannot be a fractional value');
					quantity.focus();
					return false;
				}
			}
		}		
		else if(quantityval !='')
		{
			alert('Please ensure the checkbox is selected for all the selected products');			
			return false;			
		}
		quantity.value = quantityval;
	}
	if(itemselected == 0)
	{
		alert('Please select at lease one product to add to cart');
		return false;
	}	
	else if(selQuantity != 0)
	{
		alert('Enter quantity for all the selected products');
		return false;
	}
	return true;
}

function val_order(ordfrm)
 {
 	/*ordfrm.txtCompName.value = trim(ordfrm.txtCompName.value);	
	if((ordfrm.txtCompName.value != '') && (ordfrm.txtCompName.value != null)) {
		if (!regName.test(ordfrm.txtCompName.value)) {
			alert("Enter a valid company name");
			ordfrm.txtCompName.focus();
			return false;
		} 	
	}
	ordfrm.txtDesignation.value = trim(ordfrm.txtDesignation.value);
	if((ordfrm.txtDesignation.value != '') && (ordfrm.txtDesignation.value != null)) {
		if (!regName.test(ordfrm.txtDesignation.value)) {
			alert("Enter a valid designation ");
			ordfrm.txtDesignation.focus();
			return false;
		} 	
	}*/	
 	
 	ordfrm.txtName.value = trim(ordfrm.txtName.value);
	if((ordfrm.txtName.value == '') || (ordfrm.txtName.value == null)) {
		alert("Please Enter your name");
		ordfrm.txtName.focus();
		return false;
	}
	else if(!regName.test(ordfrm.txtName.value)) {
		alert("Please Enter valid name");
		ordfrm.txtName.focus();
		return false
	}
	ordfrm.txtEmailId.value = trim(ordfrm.txtEmailId.value);
	if((ordfrm.txtEmailId.value == '') || (ordfrm.txtEmailId.value == null)) {
		alert("Please Enter user email id");
		ordfrm.txtEmailId.focus();
		return false;
	}
	else if(ordfrm.txtEmailId.value.length <= 5) {
		alert("Email id should have at least 6 characters");
		ordfrm.txtEmailId.focus();
		return false;
	}
	else if (echeck(ordfrm.txtEmailId.value)==false){
		ordfrm.txtEmailId.value=""
		ordfrm.txtEmailId.focus()
		return false
	} 	
	/*
	ordfrm.txtContNo1.value = trim(ordfrm.txtContNo1.value);
	ordfrm.txtContNo2.value = trim(ordfrm.txtContNo2.value);
	if(((ordfrm.txtContNo1.value == '') || (ordfrm.txtContNo1.value == null)) && ((ordfrm.txtContNo2.value == '') || (ordfrm.txtContNo2.value == null))) {
 		alert("Please enter your contact no");
		ordfrm.txtContNo1.focus();
		return false;
 	}
	else {
		if((ordfrm.txtContNo1.value != '') && (ordfrm.txtContNo1.value != null)) {
			if (!regPhone.test(ordfrm.txtContNo1.value)) {
				alert("Enter valid contact number ");
				ordfrm.txtContNo1.focus();
				return false;
			}
		}
     		if((ordfrm.txtContNo2.value != '') && (ordfrm.txtContNo2.value != null)) {
			if (!regPhone.test(ordfrm.txtContNo2.value)) {
			alert("enter valid mobile number ");
			ordfrm.txtContNo2.focus();
			return false;
			}
		}
     	}*/
	ordfrm.txtContNo1.value = trim(ordfrm.txtContNo1.value);
	if((ordfrm.txtContNo1.value == '') || (ordfrm.txtContNo1.value == null)) {
 		alert("Please enter your contact no");
		ordfrm.txtContNo1.focus();
		return false;
 	}
	else if (!regPhone.test(ordfrm.txtContNo1.value)) {
		alert("Enter a valid phone number");
		ordfrm.txtContNo1.focus();
		return false;
     	} 	
     	ordfrm.txtContNo2.value = trim(ordfrm.txtContNo2.value);
	if((ordfrm.txtContNo2.value != '') && (ordfrm.txtContNo2.value != null)) {
		if (!regPhone.test(ordfrm.txtContNo2.value)) {
			alert("Enter a valid phone number ");
			ordfrm.txtContNo2.focus();
			return false;
     		} 	
	}

	/* if((ordfrm.txtContNo2.value == '') || (ordfrm.txtContNo2.value == null)) {
 		alert("Please enter your contact no");
		ordfrm.txtContNo2.focus();
		return false;
 	}
	else if (!regPhone.test(ordfrm.txtContNo2.value)) {
		alert("Phone Number Must Be Entered ");
		ordfrm.txtContNo2.focus();
		return false;
	}*/
	
	ordfrm.txtAddr1.value = trim(ordfrm.txtAddr1.value);
	/*if((ordfrm.txtAddr1.value == '') && (ordfrm.txtAddr1.value == null)) {		
		alert("Enter a your address ");
		ordfrm.txtAddr1.focus();
		return false;     		 	
	}
	else */
	
	if((ordfrm.txtAddr1.value != '') && (ordfrm.txtAddr1.value != null)) {
	
		if (!regAddress.test(ordfrm.txtAddr1.value)) {
			alert("Enter a valid address ");
			ordfrm.txtAddr1.focus();
			return false;
		}
	}
	ordfrm.txtAddr2.value = trim(ordfrm.txtAddr2.value);
	/*if((ordfrm.txtAddr2.value == '') && (ordfrm.txtAddr2.value == null)) {		
		alert("Enter a your address ");
		ordfrm.txtAddr2.focus();
		return false;     		 	
	}
	else */
	if((ordfrm.txtAddr2.value != '') && (ordfrm.txtAddr2.value != null)) {
		if (!regAddress.test(ordfrm.txtAddr2.value)) {
			alert("Enter a valid address ");
			ordfrm.txtAddr2.focus();
			return false;
		}
	}
	ordfrm.selectCity.value = trim(ordfrm.selectCity.value);
	/*if(ordfrm.selectCity.selectedIndex == 0) {
		alert("Please Select the city ");
		ordfrm.selectCity.focus();
		return false;     		
	}*/	
	ordfrm.txtPin.value = trim(ordfrm.txtPin.value);
	/*if((ordfrm.txtPin.value == '') && (ordfrm.txtPin.value == null)) {
		alert("Please enter pin code ");
		ordfrm.txtPin.focus();
		return false;     		
	}
	else */
	
	if((ordfrm.txtPin.value != '') && (ordfrm.txtPin.value != null)) {
		if(!regPin.test(ordfrm.txtPin.value)) {
			alert("Enter a valid pin code ");
			ordfrm.txtPin.focus();
			return false;
		}
	}

 	optionSelected = false;
 	if (isNaN(ordfrm.selPrfDelOption.length)) {
 		if(!ordfrm.selPrfDelOption.checked) {
			alert("Please select a delivery option");
			return false;
 		}
 	}
 	else {
		for (var i=0; i<ordfrm.selPrfDelOption.length; i++) {	
			if(ordfrm.selPrfDelOption[i].checked) {
				optionSelected = true;
			}
		}
		if (!optionSelected)
		{
			alert("Please select a delivery option");
			return false;
		}
	}	
	 
//alert(' checkValues '+ordfrm.checkValues.value+' btnBack '+ordfrm.btnBack.value +' submit '+ordfrm.submit.value );
	if(ordfrm.radSelModePayment.length == '' || ordfrm.radSelModePayment.length == null)
	{
		if(ordfrm.btnBack.value == 'Back')
		{
			if (ordfrm.radSelModePayment.checked == false) {
				alert("Please Select the payment mode");
				return false;
			}
		}
	}
	else
	{	 
		if(ordfrm.btnBack.value == 'Back')
		{
			var radsel = 0;
			for (var i=0; i<ordfrm.radSelModePayment.length; i++) {			
				
				if (ordfrm.radSelModePayment[i].checked) {
					radsel = 1;
					var paymode = ordfrm.radSelModePayment[i].value;
					var paytemp = paymode.split("|");
					var paymodeId = paytemp[0];
					var paymodeType = paytemp[1];
					if (paymodeType == 'Credit Card') {
		
						if (ordfrm.selectCardType.selectedIndex == 0) {
							alert("Please Select the card type");
							ordfrm.selectCardType.focus();
							return false;
						}
			
						if (ordfrm.txtCardNo.value == null || ordfrm.txtCardNo.value == '') {
							alert("Please enter card no.");
							ordfrm.txtCardNo.focus();
							return false;
						}
						else if(isNaN(ordfrm.txtCardNo.value)) {
							alert('Please enter a numeric value');
							ordfrm.txtCardNo.focus();
							return false;
						}
						if(!IsInteger(ordfrm.txtCardNo.value))
						{
							alert('Invalid credit card no.');
							ordfrm.txtCardNo.focus();
							return false;
						}
						else if (ordfrm.txtCardNo.value.length < 12) {
							alert('Invalid credit card no. Please check!!!!!!!!');
							ordfrm.txtCardNo.focus();
							return false;
						}
			
						if (ordfrm.selectMonth.selectedIndex == 0) {
							alert('Please select expery month of credit card.');
							ordfrm.selectMonth.focus();
							return false;
						}
						if (ordfrm.selectYear.selectedIndex == 0) {
							alert('Please select expery year of credit card.');
							ordfrm.selectYear.focus();
							return false;
						}
			
						if (ordfrm.txtCvvNo.value  == null ) {
							alert('Please enter the CVV no.');
							ordfrm.txtCvvNo.focus();
							return false;
						}
						else if(isNaN(ordfrm.txtCvvNo.value)) {
							alert('CVV number should be numeric');
							ordfrm.txtCvvNo.focus();
							return false;
						}
						if(!IsInteger(ordfrm.txtCvvNo.value))
						{
							alert('Please enter a valid CVV number.');
							ordfrm.txtCvvNo.focus();
							return false;
						}
						else if (ordfrm.txtCvvNo.value.length < 3) {
							alert('Please enter a valid CVV number');
							ordfrm.txtCvvNo.focus();
							return false;
						}
	
					}
					else if (paymodeType == 'Internet Banking') 
					{
						if (ordfrm.selectBank.selectedIndex == 0) {
							alert('Please select your bank for internet banking.');
							ordfrm.selectBank.focus();
							return false;
						}					
					}
					else if (paymodeType == 'Demand Draft') 
					{
						if (!ordfrm.chkDemandDraft.checked) {
							alert('Please check the check box for conformation.');
							ordfrm.selectBank.focus();
							return false;
						}					
					}
					else if (paymodeType == 'Others') 
					{
						if (ordfrm.selectOthers.selectedIndex == 0) {
							alert('Please select others paymode.');
							ordfrm.selectOthers.focus();
							return false;
						}					
					}
					
				}
			}
			if(radsel == 0)
			{
			alert("Please Select the payment mode");
			return false;
		}
		}
	}
	
	if(!(ordfrm.chkAgreeTC.checked)) {
 		alert("Please read the Terms & condition and select the check box to agree. ");
		ordfrm.chkAgreeTC.focus();
		return false;
 	}
	 
 	return true;
 }

function val_order_mbl(ordfrm)
 {
 	
 	ordfrm.txtName.value = trim(ordfrm.txtName.value);
	if((ordfrm.txtName.value == '') || (ordfrm.txtName.value == null)) {
		alert("Please Enter your name");
		ordfrm.txtName.focus();
		return false;
	}
	else if(!regName.test(ordfrm.txtName.value)) {
		alert("Please Enter valid name");
		ordfrm.txtName.focus();
		return false
	}
	ordfrm.txtEmailId.value = trim(ordfrm.txtEmailId.value);
	if((ordfrm.txtEmailId.value == '') || (ordfrm.txtEmailId.value == null)) {
		alert("Please Enter user email id");
		ordfrm.txtEmailId.focus();
		return false;
	}
	else if(ordfrm.txtEmailId.value.length <= 5) {
		alert("Email id should have at least 6 characters");
		ordfrm.txtEmailId.focus();
		return false;
	}
	else if (echeck(ordfrm.txtEmailId.value)==false){
		ordfrm.txtEmailId.value=""
		ordfrm.txtEmailId.focus()
		return false
	} 	

	ordfrm.txtContNo1.value = trim(ordfrm.txtContNo1.value);
	if((ordfrm.txtContNo1.value == '') || (ordfrm.txtContNo1.value == null)) {
 		alert("Please enter your contact no");
		ordfrm.txtContNo1.focus();
		return false;
 	}
	else if (!regPhone.test(ordfrm.txtContNo1.value)) {
		alert("Enter a valid phone number");
		ordfrm.txtContNo1.focus();
		return false;
     	} 	
     	ordfrm.txtContNo2.value = trim(ordfrm.txtContNo2.value);
	if((ordfrm.txtContNo2.value != '') && (ordfrm.txtContNo2.value != null)) {
		if (!regPhone.test(ordfrm.txtContNo2.value)) {
			alert("Enter a valid phone number ");
			ordfrm.txtContNo2.focus();
			return false;
     		} 	
	}

	
	ordfrm.txtAddr1.value = trim(ordfrm.txtAddr1.value);
	
	if((ordfrm.txtAddr1.value != '') && (ordfrm.txtAddr1.value != null)) {
	
		if (!regAddress.test(ordfrm.txtAddr1.value)) {
			alert("Enter a valid address ");
			ordfrm.txtAddr1.focus();
			return false;
		}
	}
	ordfrm.txtAddr2.value = trim(ordfrm.txtAddr2.value);
	if((ordfrm.txtAddr2.value != '') && (ordfrm.txtAddr2.value != null)) {
		if (!regAddress.test(ordfrm.txtAddr2.value)) {
			alert("Enter a valid address ");
			ordfrm.txtAddr2.focus();
			return false;
		}
	}
	ordfrm.selectCity.value = trim(ordfrm.selectCity.value);
	ordfrm.txtPin.value = trim(ordfrm.txtPin.value);
	
	if((ordfrm.txtPin.value != '') && (ordfrm.txtPin.value != null)) {
		if(!regPin.test(ordfrm.txtPin.value)) {
			alert("Enter a valid pin code ");
			ordfrm.txtPin.focus();
			return false;
		}
	}

/* 	optionSelected = false;
 	if (isNaN(ordfrm.selPrfDelOption.length)) {
 		if(!ordfrm.selPrfDelOption.checked) {
			alert("Please select a delivery option");
			return false;
 		}
 	}
 	else {
		for (var i=0; i<ordfrm.selPrfDelOption.length; i++) {	
			if(ordfrm.selPrfDelOption[i].checked) {
				optionSelected = true;
			}
		}
		if (!optionSelected)
		{
			alert("Please select a delivery option");
			return false;
		}
	}	
*/	 
//alert(' checkValues '+ordfrm.checkValues.value+' btnBack '+ordfrm.btnBack.value +' submit '+ordfrm.submit.value );
	if(ordfrm.radSelModePayment.length == '' || ordfrm.radSelModePayment.length == null)
	{
		if(ordfrm.btnBack.value == 'Back')
		{
			if (ordfrm.radSelModePayment.checked == false) {
				alert("Please Select the payment mode");
				return false;
			}
		}
	}
	else
	{	 
		if(ordfrm.btnBack.value == 'Back')
		{
			var radsel = 0;
			for (var i=0; i<ordfrm.radSelModePayment.length; i++) {			
				
				if (ordfrm.radSelModePayment[i].checked) {
					radsel = 1;
					var paymode = ordfrm.radSelModePayment[i].value;
					var paytemp = paymode.split("|");
					var paymodeId = paytemp[0];
					var paymodeType = paytemp[1];
					if (paymodeType == 'Credit Card') {
		
						if (ordfrm.selectCardType.selectedIndex == 0) {
							alert("Please Select the card type");
							ordfrm.selectCardType.focus();
							return false;
						}
			
						if (ordfrm.txtCardNo.value == null || ordfrm.txtCardNo.value == '') {
							alert("Please enter card no.");
							ordfrm.txtCardNo.focus();
							return false;
						}
						else if(isNaN(ordfrm.txtCardNo.value)) {
							alert('Please enter a numeric value');
							ordfrm.txtCardNo.focus();
							return false;
						}
						if(!IsInteger(ordfrm.txtCardNo.value))
						{
							alert('Invalid credit card no.');
							ordfrm.txtCardNo.focus();
							return false;
						}
						else if (ordfrm.txtCardNo.value.length < 12) {
							alert('Invalid credit card no. Please check!!!!!!!!');
							ordfrm.txtCardNo.focus();
							return false;
						}
			
						if (ordfrm.selectMonth.selectedIndex == 0) {
							alert('Please select expery month of credit card.');
							ordfrm.selectMonth.focus();
							return false;
						}
						if (ordfrm.selectYear.selectedIndex == 0) {
							alert('Please select expery year of credit card.');
							ordfrm.selectYear.focus();
							return false;
						}
			
						if (ordfrm.txtCvvNo.value  == null ) {
							alert('Please enter the CVV no.');
							ordfrm.txtCvvNo.focus();
							return false;
						}
						else if(isNaN(ordfrm.txtCvvNo.value)) {
							alert('CVV number should be numeric');
							ordfrm.txtCvvNo.focus();
							return false;
						}
						if(!IsInteger(ordfrm.txtCvvNo.value))
						{
							alert('Please enter a valid CVV number.');
							ordfrm.txtCvvNo.focus();
							return false;
						}
						else if (ordfrm.txtCvvNo.value.length < 3) {
							alert('Please enter a valid CVV number');
							ordfrm.txtCvvNo.focus();
							return false;
						}
	
					}
					else if (paymodeType == 'Internet Banking') 
					{
						if (ordfrm.selectBank.selectedIndex == 0) {
							alert('Please select your bank for internet banking.');
							ordfrm.selectBank.focus();
							return false;
						}					
					}
					else if (paymodeType == 'Demand Draft') 
					{
						if (!ordfrm.chkDemandDraft.checked) {
							alert('Please check the check box for conformation.');
							ordfrm.selectBank.focus();
							return false;
						}					
					}
					else if (paymodeType == 'Others') 
					{
						if (ordfrm.selectOthers.selectedIndex == 0) {
							alert('Please select others paymode.');
							ordfrm.selectOthers.focus();
							return false;
						}					
					}
					
				}
			}
			if(radsel == 0)
			{
			alert("Please Select the payment mode");
			return false;
		}
		}
	}
	
	if(!(ordfrm.chkAgreeTC.checked)) {
 		alert("Please read the Terms & condition and select the check box to agree. ");
		ordfrm.chkAgreeTC.focus();
		return false;
 	}
	 
 	return true;
 }
 
 
function shwcart_chkUpd(frmChCart,txtbx,chkUpdateItem )
{
	chkoutUpdate = 1;
	var chkEle = document.getElementById(chkUpdateItem);

	if(trim(txtbx.value) =='')
	{
		chkEle.checked = false;
	}	
	else if(!(chkEle.checked))
	{
		chkEle.checked = true;		
	}
}
function val_chkout()
{
	if(chkoutUpdate == 1)
	{
		var cnf = confirm('You have updated some items.\n Please click Cancel if u want to update and then click Update button.\n If u want to continue without update click OK');
		if(cnf)
		{
			chkoutUpdate = 0;
			return true;
		}
		else
		{
			return false;
		}
	}
	if(chkoutDelete == 1)
	{
		var cnf = confirm('You have checked some elements to delete.\n Please click Cancel if u want to Delete and then click Delete button.\n If u want to continue without deleting click OK');
		if(cnf)
		{
			chkoutDelete = 0;
			return true;
		}
		else
		{
			return false;
		}
	}
	return true;
}

function val_inviteFriends(invFrm)
{
	itemscount = invFrm.hdnNosInvites.value;
	
	var noEntry=1;
	for(var i=1;i<=itemscount;i++)
	{
		
		var refName= document.getElementById('txtRefName'+i);
		var refNameval= trim(document.getElementById('txtRefName'+i).value);
		refName.value = refNameval;
		
		var refEmail= document.getElementById('txtRefEmailId'+i);
		var refEmailval= trim(document.getElementById('txtRefEmailId'+i).value);
		refEmail.value = refEmailval;
		
		if((refNameval != '') || (refEmailval != ''))
		{
			noEntry = 0;
			if((refNameval == '') || (refNameval == null)) {
				alert("Please Enter the name");
				refName.focus();
				return false;
			}
			else if(!regName.test(refNameval)) {
				alert("Please Enter valid name");
				refName.focus();
				return false
			}
			if((refEmailval == '') || (refEmailval == null)) {
				alert("Please Enter email id");
				refEmail.focus();
				return false;
			}
			else if(refEmailval <= 5) {
				alert("Email id should have at least 6 characters");
				refEmail.focus();
				return false;
			}
			else if (echeck(refEmailval)==false){
				refEmail.focus()
				return false
			}
		}
	}
	
	if(noEntry == 1)
	{
		alert('Atleast one entry required.')
		return false;
	}
	return true;
	
}

function val_shwcartUpdate(frmadd2cart,itemscount) {
	var itemselected = 0;
	var selQuantity = 0;

	for(var i=0;i<itemscount;i++)
	{
		var chksel = document.getElementById('chkUpdateItem'+i);
		var quantity = document.getElementById('txtQuantity'+i);
		var quantityval = trim(quantity.value);
		//alert(chksel.checked)
		if(chksel.checked) {
			itemselected = 1;
			//alert(quantity)
			if(quantityval == null || quantityval =='')
			{
				selQuantity = 1;
				alert('Please enter the quantity for the selected product');
				quantity.focus();
				return false;
			}
			else {
				if(isNaN(quantityval) || quantityval == 0) {
					alert('Please enter a numeric value greater then Zero');
					quantity.focus();
					return false;
				}
				if(!IsInteger(quantityval))
				{
					alert(' Quantity cannot be a fractional value');
					quantity.focus();
					return false;
				}
			}
		}		
		/*else if(quantityval !='')
		{
			alert('Please ensure the checkbox is selected for all the selected products');			
			return false;			
		}*/
		quantity.value = quantityval;
	}
	if(itemselected == 0)
	{
		alert('Please change at least one product to Update');
		return false;
	}	
	else if(selQuantity != 0)
	{
		alert('Enter quantity for all the selected products');
		return false;
	}
	chkoutUpdate = 0;
	return true;
}

function shwcart_chkDel(frmChCart,chkSelectItem )
{
	
	var chkEle = document.getElementById(chkSelectItem);
	//var chkEle = chkSelectItem;
	//alert(chkEle);
	
	if((chkEle.checked))
	{
		chkoutDelete = 1;
	}
	else
		chkoutDelete = 0;
}

function shwcart_onchkUpd(frmChCart,chkSelectItem )
{
	
	var chkEle = document.getElementById(chkSelectItem);
	
	if((chkEle.checked))
	{
		chkoutUpdate = 1;
	}
	else
		chkoutUpdate = 0;
}

function val_shwcartDelete(frmadd2cart,itemscount) {
	var itemselected = 0;	

	for(var i=0;i<itemscount;i++)
	{
		var chksel = document.getElementById('chkSelectItem'+i);
			if(chksel.checked) {
				itemselected = 1;			
			}		
	}
	if(itemselected == 0)
	{
		alert('Please select at least one product to Delete');
		return false;
	}	
	chkoutDelete = 0;
	return true;
}

function rolldownMenu() {
var x,y;

    if (document.getElementById("jsEnabled")!=null) {	
	/*
	if (browser.isIE) {
		x = document.getElementById("imgmholder").offsetParent.clientLeft;
		y = document.getElementById("imgmholder").offsetParent.clientTop;
		alert('IE x '+x+' y '+y);
	}
	else{
		x = document.getElementById("imgmholder").offsetParent.offsetLeft //+document.getElementById("imgmholder").offsetWidth
		y = document.getElementById("imgmholder").offsetParent.offsetTop 
		alert('moz x '+x+' y '+y);
	}
	*/
  
	//var absPos = getAbsolutePosition(document.getElementById("imgmholder"));
	//alert('all x '+absPos.x+' y '+absPos.y);
  
	//document.getElementById("jsEnabled").style.left = absPos.x + "px";
	//document.getElementById("jsEnabled").style.top = absPos.y+4 + "px";
	document.getElementById("jsEnabled").style.visibility = 'visible';
	document.getElementById("jsEnabled").style.display = 'block';
    }
}
function rollupMenu() {
	//document.getElementById("jsEnabled").style.visibility = 'hidden';
}

function tab_out(thisid,no)
{
	var tab_id=thisid.id;
	document.getElementById(tab_id+'_head').style.backgroundImage = "url(web/img/white_mid_27.gif)";
	document.getElementById(tab_id+'_left').style.backgroundImage = "url(web/img/yellow_lt_27.gif)";
	document.getElementById(tab_id+'_right').style.backgroundImage = "url(web/img/yellow_rt_27.gif)";

	document.getElementById(tab_id+'_cont').className="tab_head";
	document.getElementById(tab_id+'_head').className="tab_head";
	document.getElementById(tab_id+'_cont').style.color="#000000";
}
function tab_over(thisid,no)
{
	var tab_id=thisid.id;
	document.getElementById(tab_id+'_head').style.backgroundImage = "url(web/img/yellow_mid_27.gif)";
	document.getElementById(tab_id+'_left').style.backgroundImage = "url(web/img/white_lt_27.gif)";
	document.getElementById(tab_id+'_right').style.backgroundImage = "url(web/img/white_rt_27.gif)";
	document.getElementById(tab_id+'_head').className="tab_head_act";
	document.getElementById(tab_id+'_cont').className="tab_head_act";
	document.getElementById(tab_id+'_cont').style.color="#000000";
}
function tab_click(thisid,no)
{
	var tab_id=thisid.id;
	var hreff = document.getElementById(tab_id+'_cont').href;
	document.getElementById(tab_id+'_cont').href = '#';
	window.location=hreff
	
}


function tab_out_topnav(thisid,no)
{
	var tab_id=thisid.id;
	document.getElementById(tab_id).style.backgroundImage = "url(web/img/wt_back_topnav.png)";
	document.getElementById(tab_id+'_left').style.backgroundImage = "url(web/img/wt_left_topnav.png)";
	document.getElementById(tab_id+'_cont').className="topnav_tab_head";
	document.getElementById(tab_id+'_head').className="topnav_tab_head";
}
function tab_over_topnav(thisid,no)
{
	var tab_id=thisid.id;
		
	thisid.style.backgroundImage = "url(web/img/gr_back_topnav.png)";
	document.getElementById(tab_id+'_left').style.backgroundImage = "url(web/img/gr_left_topnav.png)";
	document.getElementById(tab_id+'_head').className="topnav_tab_head_act";
	document.getElementById(tab_id+'_cont').className="topnav_tab_head_act";
	
}
function tab_click_topnav(thisid,no)
{
	var tab_id=thisid.id;
	window.location=document.getElementById(tab_id+'_cont').href
}

function val_search(frm,selSt,txtSrc)
{
	var setStore = document.getElementById(selSt);
	var txtBxSrch = document.getElementById(txtSrc);
	var txtSrch = trim(txtBxSrch.value);
	if(txtSrch == '' || txtSrch == null)
	{
		alert('Please enter search text');
		txtBxSrch.value = txtSrch;
		txtBxSrch.focus();
		return false;
	}
	else if(txtSrch.length<3)
	{
		alert('Please enter at least three characters');
		txtBxSrch.value = txtSrch;
		txtBxSrch.focus();
		return false;
	}
	else if(!regAlpNum.test(txtSrch)) {
		alert("Please Enter valid search string");
		txtBxSrch.focus();
		return false
	}
	
	return true;
}


function getAbsolutePosition(element) {
  var r = { x: element.offsetLeft, y: element.offsetTop };
  if (element.offsetParent) {
    var tmp = getAbsolutePosition(element.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
}

function openPrint() {
	/*if (navigator.appName == "Microsoft Internet Explorer"){
		msgbox = document.getElementById("printOrder");
		msgbox.style.top = 400+"px";
	}*/

	if (navigator.appName == "Microsoft Internet Explorer"){
		changeOpac(20,'siteLayoutPage');
	}
	else {
		opacity('siteLayoutPage', 100, 20, 200);
	}
}
function closePrint() {
	msgbox1 = document.getElementById('printOrder');			
	msgbox1.style.visibility = "hidden";	
	
	if (navigator.appName == "Microsoft Internet Explorer"){
		changeOpac(100,'siteLayoutPage');
	}
	else {
	     opacity('siteLayoutPage', 20, 100, 200);
	}
}

function printFunc(ordId)
{
	url = "print.php?orderId=" + ordId;
	var load = window.open(url,'','scrollbars=1,menubar=no,height=600,width=800,resizable=no,toolbar=no,location=no,status=no');
	closePrint();
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    if (navigator.appName == "Microsoft Internet Explorer"){
	/*
	nv = navigator.appVersion;
	if (parseFloat(nv.substring(nv.indexOf("MSIE") + 5)) > 6) {
	    object.filter = "alpha(opacity=" + opacity + ")"; 
	}
	*/
    }
    else {
	object.filter = "alpha(opacity=" + opacity + ")"; 
    }
} 

function showVariant(chkEle)
{
	var divEle = document.getElementById('divVariant');
	/*if(chkEle == null || chkEle == '')
	{
		chkEle = document.getElementById('chkProdHasVariant');
	}*/
	if(chkEle.checked) {	
		divEle.style.display = "block";
		divEle.style.visibility = "visible";
	}
	else {	
		divEle.style.display = "none";
		divEle.style.visibility = "hidden";
	}	
}

function val_addprod(adprdfrm)
 {
	adprdfrm.txtProdName.value = trim(adprdfrm.txtProdName.value);
	if((adprdfrm.txtProdName.value == '') || (adprdfrm.txtProdName.value == null)) {		
		alert("Enter a enter product name");
		adprdfrm.txtProdName.focus();
		return false;		 	
	}
	else if (!regProdName.test(adprdfrm.txtProdName.value)) {
		alert("Enter a valid product name");
		adprdfrm.txtProdName.focus();
		return false;     		 	
	}
	
	adprdfrm.txtaProdDes.value = trim(adprdfrm.txtaProdDes.value);
	if((adprdfrm.txtaProdDes.value != '') && (adprdfrm.txtaProdDes.value != null)) {
		if (!regProdName.test(adprdfrm.txtaProdDes.value)) {
			alert("Enter a valid designation ");
			adprdfrm.txtaProdDes.focus();
			return false;
     		} 	
	}	
 		
	if(adprdfrm.selectCat.selectedIndex == 0) {
		alert("Please select the category");
		adprdfrm.selectCat.focus();
		return false;
	}
	else if((!adprdfrm.selSubCat.disabled) && adprdfrm.selSubCat.selectedIndex == 0) {
		alert("Please Select Sub Category of the ptoduct");
		adprdfrm.selSubCat.focus();
		return false;
	}
	
	adprdfrm.txtMRP.value = trim(adprdfrm.txtMRP.value);
	adprdfrm.txtCostPrice.value = trim(adprdfrm.txtCostPrice.value);
	
	
	if(!(adprdfrm.chkProdHasVariant.checked)) {
		if((adprdfrm.txtMRP.value == '') || (adprdfrm.txtMRP.value == null)) {
			alert("Please Enter MRP of the product");
			adprdfrm.txtMRP.focus();
			return false;
		}
		else if(!regDecimal.test(adprdfrm.txtMRP.value)) {
			alert("Please Enter valid MRP in X.XX format");
			adprdfrm.txtMRP.focus();
			return false
		}
	
		if(adprdfrm.selectTax.selectedIndex == 0) {
			alert("Please select the tax of the product");
			adprdfrm.selectTax.focus();
			return false;
		}			
		
		if((adprdfrm.txtCostPrice.value != '') && (adprdfrm.txtCostPrice.value != null)) {
			if(!regDecimal.test(adprdfrm.txtCostPrice.value)) {
				alert("Please Enter valid Cost Price in X.XX format");
				adprdfrm.txtCostPrice.focus();
				return false
			}
		}
		if(adprdfrm.selectMeasureUnits.selectedIndex == 0) {
			alert("Please select the measure units of the product");
			adprdfrm.selectMeasureUnits.focus();
			return false;
		}
	}
		     	
 	return true;
 }
 
 function val_editprod(edprdfrm)
  {
  	edprdfrm.txtProdName.value = trim(edprdfrm.txtProdName.value);
 	if((edprdfrm.txtProdName.value == '') || (edprdfrm.txtProdName.value == null)) {		
 		alert("Enter a enter product name");
 		edprdfrm.txtProdName.focus();
 		return false;		 	
 	}
 	else if (!regProdName.test(edprdfrm.txtProdName.value)) {
 		alert("Enter a valid product name");
 		edprdfrm.txtProdName.focus();
 		return false;     		 	
 	}
 	
 	edprdfrm.txtaProdDes.value = trim(edprdfrm.txtaProdDes.value);
 	if((edprdfrm.txtaProdDes.value != '') && (edprdfrm.txtaProdDes.value != null)) {
 		if (!regProdName.test(edprdfrm.txtaProdDes.value)) {
 			alert("Enter a valid product description ");
 			edprdfrm.txtaProdDes.focus();
 			return false;
      		} 	
 	}	
  		
 	if(edprdfrm.selectCat.selectedIndex == 0) {
 		alert("Please select the category");
 		edprdfrm.selectCat.focus();
 		return false;
 	}
 	else if((!edprdfrm.selSubCat.disabled) && edprdfrm.selSubCat.selectedIndex == 0) {
 		alert("Please Select Sub Category of the ptoduct");
 		edprdfrm.selSubCat.focus();
 		return false;
 	}
 	
 	edprdfrm.txtMRP.value = trim(edprdfrm.txtMRP.value); 	
 	edprdfrm.txtCostPrice.value = trim(edprdfrm.txtCostPrice.value);
 	
 	
 	if(!(edprdfrm.chkProdHasVariant.checked)) {
		if((edprdfrm.txtMRP.value == '') || (edprdfrm.txtMRP.value == null)) {
			alert("Please Enter MRP of the product");
			edprdfrm.txtMRP.focus();
			return false;
		}
		else if(!regDecimal.test(edprdfrm.txtMRP.value)) {
			alert("Please Enter valid MRP in X.XX format");
			edprdfrm.txtMRP.focus();
			return false
		}
		
		if(edprdfrm.selectTax.selectedIndex == 0) {
			alert("Please select the tax of the product");
			edprdfrm.selectTax.focus();
			return false;
		}
		
		if((edprdfrm.txtCostPrice.value != '') && (edprdfrm.txtCostPrice.value != null)) {
			if(!regDecimal.test(edprdfrm.txtCostPrice.value)) {
				alert("Please Enter valid Cost Price in X.XX format");
				edprdfrm.txtCostPrice.focus();
				return false
			}
		}		

		if(edprdfrm.selectMeasureUnits.selectedIndex == 0) {
			alert("Please select the measure units of the product");
			edprdfrm.selectMeasureUnits.focus();
			return false;
		}
	}
 		     	
  	return true;
 }

 
function val_addprodVar(adprdvarfrm)
{

	if(adprdvarfrm.selCat.selectedIndex == 0) {
		alert("Please select the category");
		adprdvarfrm.selCat.focus();
		return false;
	}
	else if((!adprdvarfrm.selSubCat.disabled) && adprdvarfrm.selSubCat.selectedIndex == 0) {
		alert("Please Select Sub Category of the ptoduct");
		adprdvarfrm.selSubCat.focus();
		return false;
	}

	if(adprdvarfrm.selProdId.selectedIndex == 0) {
		alert("Please select the product");
		adprdvarfrm.selProdId.focus();
		return false;
	}

	adprdvarfrm.txtProdVarName.value = trim(adprdvarfrm.txtProdVarName.value);
	if((adprdvarfrm.txtProdVarName.value == '') || (adprdvarfrm.txtProdVarName.value == null)) {		
		alert("Enter a enter product name");
		adprdvarfrm.txtProdVarName.focus();
		return false;		 	
	}
	else if (!regProdName.test(adprdvarfrm.txtProdVarName.value)) {
		alert("Enter a valid product name");
		adprdvarfrm.txtProdVarName.focus();
		return false;     		 	
	}

	adprdvarfrm.txtaProdVarDes.value = trim(adprdvarfrm.txtaProdVarDes.value);
	if((adprdvarfrm.txtaProdVarDes.value != '') && (adprdvarfrm.txtaProdVarDes.value != null)) {
		if (!regProdName.test(adprdvarfrm.txtaProdVarDes.value)) {
			alert("Enter a valid product description ");
			adprdvarfrm.txtaProdVarDes.focus();
			return false;
		} 	
	}	


	adprdvarfrm.txtVarMRP.value = trim(adprdvarfrm.txtVarMRP.value);
	if((adprdvarfrm.txtVarMRP.value == '') || (adprdvarfrm.txtVarMRP.value == null)) {
		alert("Please Enter MRP of the product");
		adprdvarfrm.txtVarMRP.focus();
		return false;
	}
	else if(!regDecimal.test(adprdvarfrm.txtVarMRP.value)) {
		alert("Please Enter valid MRP in X.XX format");
		adprdvarfrm.txtVarMRP.focus();
		return false
	}

	if(adprdvarfrm.selectVarTax.selectedIndex == 0) {
		alert("Please select the tax of the product");
		adprdvarfrm.selectVarTax.focus();
		return false;
	}

	adprdvarfrm.txtVarCostPrice.value = trim(adprdvarfrm.txtVarCostPrice.value);
	if((adprdvarfrm.txtVarCostPrice.value != '') && (adprdvarfrm.txtVarCostPrice.value != null)) {
		if(!regDecimal.test(adprdvarfrm.txtVarCostPrice.value)) {
			alert("Please Enter valid Cost Price in X.XX format");
			adprdvarfrm.txtCostPrice.focus();
			return false
		}
	}
	
	if(adprdvarfrm.selectMeasureUnits.selectedIndex == 0) {
		alert("Please select the measure units of the product");
		adprdvarfrm.selectMeasureUnits.focus();
		return false;
	}

	return true;
}


function val_editprodVar(edprdvarfrm)
{

	if(edprdvarfrm.selCat.selectedIndex == 0) {
		alert("Please select the category");
		edprdvarfrm.selCat.focus();
		return false;
	}
	else if((!edprdvarfrm.selSubCat.disabled) && edprdvarfrm.selSubCat.selectedIndex == 0) {
		alert("Please Select Sub Category of the ptoduct");
		edprdvarfrm.selSubCat.focus();
		return false;
	}

	if(edprdvarfrm.selProdId.selectedIndex == 0) {
		alert("Please select the product");
		edprdvarfrm.selProdId.focus();
		return false;
	}
	
	if(edprdvarfrm.selProdVarId.selectedIndex == 0) {
		alert("Please select the variant");
		edprdvarfrm.selProdVarId.focus();
		return false;
	}

	edprdvarfrm.txtProdVarName.value = trim(edprdvarfrm.txtProdVarName.value);
	if((edprdvarfrm.txtProdVarName.value == '') || (edprdvarfrm.txtProdVarName.value == null)) {		
		alert("Enter a enter product name");
		edprdvarfrm.txtProdVarName.focus();
		return false;		 	
	}
	else if (!regProdName.test(edprdvarfrm.txtProdVarName.value)) {
		alert("Enter a valid product name");
		edprdvarfrm.txtProdVarName.focus();
		return false;     		 	
	}

	edprdvarfrm.txtaProdVarDes.value = trim(edprdvarfrm.txtaProdVarDes.value);
	if((edprdvarfrm.txtaProdVarDes.value != '') && (edprdvarfrm.txtaProdVarDes.value != null)) {
		if (!regProdName.test(edprdvarfrm.txtaProdVarDes.value)) {
			alert("Enter a valid product description ");
			edprdvarfrm.txtaProdVarDes.focus();
			return false;
		} 	
	}

	edprdvarfrm.txtVarMRP.value = trim(edprdvarfrm.txtVarMRP.value);
	if((edprdvarfrm.txtVarMRP.value == '') || (edprdvarfrm.txtVarMRP.value == null)) {
		alert("Please Enter MRP of the product");
		edprdvarfrm.txtVarMRP.focus();
		return false;
	}
	else if(!regDecimal.test(edprdvarfrm.txtVarMRP.value)) {
		alert("Please Enter valid MRP in X.XX format");
		edprdvarfrm.txtVarMRP.focus();
		return false
	}

	if(edprdvarfrm.selectVarTax.selectedIndex == 0) {
		alert("Please select the tax of the product");
		edprdvarfrm.selectVarTax.focus();
		return false;
	}

	edprdvarfrm.txtVarCostPrice.value = trim(edprdvarfrm.txtVarCostPrice.value);
	if((edprdvarfrm.txtVarCostPrice.value != '') && (edprdvarfrm.txtVarCostPrice.value != null)) {
		if(!regDecimal.test(edprdvarfrm.txtVarCostPrice.value)) {
			alert("Please Enter valid Cost Price in X.XX format");
			edprdvarfrm.txtCostPrice.focus();
			return false
		}
	}
	
	if(edprdvarfrm.selectMeasureUnits.selectedIndex == 0) {
		alert("Please select the measure units of the product");
		edprdvarfrm.selectMeasureUnits.focus();
		return false;
	}	

	return true;
}



function val_addstorprod(adstrprdfrm)
{

	if(adstrprdfrm.selCat.selectedIndex == 0) {
		alert("Please select the category");
		adstrprdfrm.selCat.focus();
		return false;
	}
	else if((!adstrprdfrm.selSubCat.disabled) && adstrprdfrm.selSubCat.selectedIndex == 0) {
		alert("Please Select Sub Category of the ptoduct");
		adstrprdfrm.selSubCat.focus();
		return false;
	}

	if(adstrprdfrm.selProdId.selectedIndex == 0) {
		alert("Please select the product");
		adstrprdfrm.selProdId.focus();
		return false;
	}
	
	if((!adstrprdfrm.selProdVarId.disabled) && adstrprdfrm.selProdVarId.selectedIndex == 0) {
		alert("Please select the variant");
		adstrprdfrm.selProdVarId.focus();
		return false;
	}
	
	if(adstrprdfrm.selStoreId.selectedIndex == 0) {
		alert("Please select the store");
		adstrprdfrm.selStoreId.focus();
		return false;
	}
	
	adstrprdfrm.txtaStoreProdSKU.value = trim(adstrprdfrm.txtaStoreProdSKU.value);
	if((adstrprdfrm.txtaStoreProdSKU.value != '') && (adstrprdfrm.txtaStoreProdSKU.value != null)) {
		if (!regProdName.test(adstrprdfrm.txtaStoreProdSKU.value)) {
			alert("Enter a valid product SKU ");
			adstrprdfrm.txtaStoreProdSKU.focus();
			return false;
		} 	
	}

	
	adstrprdfrm.txtStoreProdPrice.value = trim(adstrprdfrm.txtStoreProdPrice.value);
	if((adstrprdfrm.txtStoreProdPrice.value == '') || (adstrprdfrm.txtStoreProdPrice.value == null)) {
		alert("Please Enter store price");
		adstrprdfrm.txtStoreProdPrice.focus();
		return false;
	}
	else if(!regDecimal.test(adstrprdfrm.txtStoreProdPrice.value)) {
		alert("Please Enter valid store price in X.XX format");
		adstrprdfrm.txtStoreProdPrice.focus();
		return false
	}

	adstrprdfrm.txtStoreProdDiscount.value = trim(adstrprdfrm.txtStoreProdDiscount.value);
	if((adstrprdfrm.txtStoreProdDiscount.value != '') && (adstrprdfrm.txtStoreProdDiscount.value != null)) {
		if(!IsInteger(adstrprdfrm.txtStoreProdDiscount.value)) {
			alert("Please Enter valid store discount");
			adstrprdfrm.txtStoreProdDiscount.focus();
			return false
		}
	}	
	

	adstrprdfrm.txtStoreProdOffrPrice.value = trim(adstrprdfrm.txtStoreProdOffrPrice.value);
	if((adstrprdfrm.txtStoreProdOffrPrice.value != '') && (adstrprdfrm.txtStoreProdOffrPrice.value != null)) {
		if(!regDecimal.test(adstrprdfrm.txtStoreProdOffrPrice.value)) {
			alert("Please Enter valid store offered price in X.XX format");
			adstrprdfrm.txtStoreProdOffrPrice.focus();
			return false
		}
	}

	return true;
}


function val_addCategory(adcatfrm)
{

	if(adcatfrm.selParCatId.selectedIndex == 0) {
		alert("Please select the category");
		adcatfrm.selParCatId.focus();
		return false;
	}
	
	adcatfrm.txtCatName.value = trim(adcatfrm.txtCatName.value);
	if((adcatfrm.txtCatName.value == '') || (adcatfrm.txtCatName.value == null)) {		
		alert("Enter a enter category name");
		adcatfrm.txtCatName.focus();
		return false;		 	
	}
	else if (!regProdName.test(adcatfrm.txtCatName.value)) {
		alert("Enter a valid category name");
		adcatfrm.txtCatName.focus();
		return false;     		 	
	}

	adcatfrm.txtaCatDes.value = trim(adcatfrm.txtaCatDes.value);
	if((adcatfrm.txtaCatDes.value != '') && (adcatfrm.txtaCatDes.value != null)) {
		if (!regProdName.test(adcatfrm.txtaCatDes.value)) {
			alert("Enter a valid product category ");
			adcatfrm.txtaCatDes.focus();
			return false;
		} 	
	}		

	return true;
}


function val_editCategory(edcatfrm)
{
	if(edcatfrm.selCatId.selectedIndex == 0) {
		alert("Please select the category");
		edcatfrm.selCatId.focus();
		return false;
	}

	/*if(edcatfrm.selParCatId.selectedIndex == 0) {
		alert("Please select the category");
		edcatfrm.selParCatId.focus();
		return false;
	}*/
	
	edcatfrm.txtCatName.value = trim(edcatfrm.txtCatName.value);
	if((edcatfrm.txtCatName.value == '') || (edcatfrm.txtCatName.value == null)) {		
		alert("Enter a enter category name");
		edcatfrm.txtCatName.focus();
		return false;		 	
	}
	else if (!regProdName.test(edcatfrm.txtCatName.value)) {
		alert("Enter a valid category name");
		edcatfrm.txtCatName.focus();
		return false;     		 	
	}

	edcatfrm.txtaCatDes.value = trim(edcatfrm.txtaCatDes.value);
	if((edcatfrm.txtaCatDes.value != '') && (edcatfrm.txtaCatDes.value != null)) {
		if (!regProdName.test(edcatfrm.txtaCatDes.value)) {
			alert("Enter a valid product category ");
			edcatfrm.txtaCatDes.focus();
			return false;
		} 	
	}		

	return true;
}

function val_addOrdItem(adorditmfrm)
{
	if(adorditmfrm.selStoreId.selectedIndex == 0) {
		alert("Please select the store");
		adorditmfrm.selStoreId.focus();
		return false;
	}

	if(adorditmfrm.selCat.selectedIndex == 0) {
		alert("Please select the category");
		adorditmfrm.selCat.focus();
		return false;
	}
	else if((!adorditmfrm.selSubCat.disabled) && adorditmfrm.selSubCat.selectedIndex == 0) {
		alert("Please Select Sub Category of the ptoduct");
		adorditmfrm.selSubCat.focus();
		return false;
	}

	if(adorditmfrm.selProdId.selectedIndex == 0) {
		alert("Please select the product");
		adorditmfrm.selProdId.focus();
		return false;
	}
	
	if((!adorditmfrm.selProdVarId.disabled) && adorditmfrm.selProdVarId.selectedIndex == 0) {
		alert("Please select the variant");
		adorditmfrm.selProdVarId.focus();
		return false;
	}	
	
	
	
	adorditmfrm.txtQuantity.value = trim(adorditmfrm.txtQuantity.value);
	if((adorditmfrm.txtQuantity.value == '') || (adorditmfrm.txtQuantity.value == null)) {
		alert("Please Enter quantity");
		adorditmfrm.txtQuantity.focus();
		return false;
	}
	else if(!IsInteger(adorditmfrm.txtQuantity.value)) {
		alert("Please Enter valid quantity");
		adorditmfrm.txtQuantity.focus();
		return false
	}
	
}



function val_onbehalfsignin(obsignfrm)
 {
 	if((obsignfrm.txtUserId.value == '') || (obsignfrm.txtUserId.value == null)) {
 		alert("Please Enter user name");
		obsignfrm.txtUserId.focus();
		return false;
 	}
	else if(obsignfrm.txtUserId.value.length <= 5) {
 		alert("User name should have at least 6 characters");
		obsignfrm.txtUserId.focus();
		return false;
 	}
 	else if (echeck(obsignfrm.txtUserId.value)==false){
		obsignfrm.txtUserId.value=""
		obsignfrm.txtUserId.focus()
		return false
	}	
 	
 	return true;
 }
 
 

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function JSFX_FloatDiv(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	return el;
}


function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
}

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}
