var pop='';
function openwin(nm,width,height) {
   var name=nm;
   if (pop && !pop.closed) {
      pop.close();
   }
   pop=eval("window.open('"+name+"','NewWIN','chrome[4],toolbar=no,left=5,top=5,width="+width+",height="+height+",directories=no,menubar=no,SCROLLBARS=yes,left=2,right=2')");
   if (!pop.opener) popUpWin.opener = self;
}
var pop='';
function openwin1(nm,width,height) {
   var name=nm;
   if (pop && !pop.closed) {
      pop.close();
   }
   pop=eval("window.open('"+name+"','NewWINA','chrome[4],toolbar=no,left=5,top=5,width="+width+",height="+height+",directories=no,menubar=no,SCROLLBARS=yes,left=2,right=2')");
   if (!pop.opener) popUpWin.opener = self;
}

function openwin2(URL)
{
aWin = window.open(URL, "window", "toolbar=yes, width = 500, height = 450, status=yes, , resizable=yes, scrollbars=yes, menubar=yes, location=yes, directories=yes");
}
function openwin3(URL)
{
aWin = window.open(URL);
}

function lead_valid(chk2,chk3) {
   if (chk3=="check" && chk2.leadType.options[chk2.leadType.selectedIndex].value == "x") {
      alert("Select Trade Lead Type");
      chk2.leadType.focus();
      return false; 
   }
   if (chktrim(chk2.productName.value).length==0) {
      alert("Enter Product Name");
      chk2.productName.focus();
      return false; 
   }
   if (chk2.category.options[chk2.category.selectedIndex].value == "x") {
      alert("Select Product Category");
      chk2.category.focus();
      return false; 
   }
   if (chktrim(chk2.quantity.value).length==0) {
      alert("Enter Product Quantity ");
      chk2.quantity.focus();
      return false; 
   }
   if (chk2.unit.options[chk2.unit.selectedIndex].value == "x") {
      alert("Select Unit");
      chk2.unit.focus();
      return false; 
   }
   if (chk2.unit.options[chk2.unit.selectedIndex].value == "x" && chktrim(chk2.otherUnit.value).length==0) {
      alert("Enter Unit ");
      chk2.otherUnit.focus();
      return false;   
   }
   if (chktrim(chk2.indicativePrice.value)>0 && chk2.currency.options[chk2.currency.selectedIndex].value == "Other" && chktrim(chk2.otherCurrency.value).length==0) {
      alert("Enter Currency for Indicative Price");
      chk2.otherCurrency.focus();
      return false;   
   }
   if (chktrim(chk2.indicativePrice.value)>0 && chk2.perUnit.options[chk2.perUnit.selectedIndex].value == "x") {
      alert("Select Currency for Indicative Price");
      chk2.perUnit.focus();
      return false;   
   }
   if (chktrim(chk2.indicativePrice.value)>0 && chk2.perUnit.options[chk2.perUnit.selectedIndex].value == "Other" && chktrim(chk2.otherPerUnit.value).length==0) {
      alert("Enter per Unit for Indicative Price");
      chk2.otherPerUnit.focus();
      return false;   
   }
   if (chktrim(chk2.packaging.value).length==0) {
      alert("Enter Packaging");
      chk2.packaging.focus();
      return false; 
   }   
   if (chk3=="check" && chk2.countryOrigin.options[chk2.countryOrigin.selectedIndex].value == "x" && chk2.leadType.options[chk2.leadType.selectedIndex].value == "Sell") {   
      alert("Select Country Origin");
      chk2.countryOrigin.focus();
      return false; 
   }
   else if (chk2.countryOrigin.options[chk2.countryOrigin.selectedIndex].value == "x" && chk2.leadType.value == "Sell") {   
      alert("Select Country Origin");
      chk2.countryOrigin.focus();
      return false; 
   }

   if (chk2.paymentTerms.options[chk2.paymentTerms.selectedIndex].value == "x") {
      alert("Select Payment Terms");
      chk2.paymentTerms.focus();
      return false; 
   }
   if (chk2.paymentTerms.options[chk2.paymentTerms.selectedIndex].value == "Other" && chktrim(chk2.otherPaymentTerms.value).length==0) {
      alert("Select Other Payment Terms");
      chk2.otherPaymentTerms.focus();
      return false; 
   }
   if (chk2.expDay.options[chk2.expDay.selectedIndex].value == "x") {
      alert("Select Expiry Day");
      chk2.expDay.focus();
      return false; 
   }
   if (chk2.expMonth.options[chk2.expMonth.selectedIndex].value == "x") {
      alert("Select Expiry Month");
      chk2.expMonth.focus();
      return false; 
   }
   if (chk2.expYear.options[chk2.expYear.selectedIndex].value == "x") {
      alert("Select Expiry Year");
      chk2.expYear.focus();
      return false; 
   }
   if (navigator.appVersion.indexOf("MSIE") != -1) {
   var now = new Date();
   var curDate = new Date (now.getYear(), now.getMonth(), now.getDate());
   var entDate  = new Date (chk2.expYear.value, chk2.expMonth.value-1, chk2.expDay.value);
   var daysDiff = (entDate .getTime() - curDate.getTime()) / (1000 * 60 * 60 * 24);
   if (daysDiff>90 || daysDiff<=0) {
      alert("Invalid  Expiry Date");
      chk2.expDay.focus();
      return false;
   }
   }
}

function bidValid(chk2) {
   if (chktrim(chk2.quantity.value).length==0) {
      alert("Enter Product Quantity ");
      chk2.quantity.focus();
      return false; 
   }
   if (chk2.unit.options[chk2.unit.selectedIndex].value == "x") {
      alert("Select Unit");
      chk2.unit.focus();
      return false; 
   }
   if (chk2.unit.options[chk2.unit.selectedIndex].value == "Other" && chktrim(chk2.otherUnit.value).length==0) {
      alert("Enter Other Unit");
      chk2.otherUnit.focus();
      return false; 
   }
   if (chktrim(chk2.indicativePrice.value)==0.00) {
      alert("Enter Indicative Price");
      chk2.indicativePrice.focus();
      return false;   
   }
   if (chk2.currency.options[chk2.currency.selectedIndex].value == "x") {
      alert("Select Currency for Indicative Price");
      chk2.currency.focus();
      return false;   
   }
   if (chk2.currency.options[chk2.currency.selectedIndex].value == "Other" && chktrim(chk2.otherCurrency.value).length==0) {
      alert("Enter Other Currency  for Indicative Price");
      chk2.otherCurrency.focus();
      return false; 
   }
   if (chk2.perUnit.options[chk2.perUnit.selectedIndex].value == "x") {
      alert("Select Unit for Indicative Price");
      chk2.perUnit.focus();
      return false;   
   }
   if (chk2.perUnit.options[chk2.perUnit.selectedIndex].value == "Other" && chktrim(chk2.otherPerUnit.value).length==0) {
      alert("Enter Other Unit for Indicative Price");
      chk2.otherPerUnit.focus();
      return false; 
   }
   if (chk2.hideStatus.options[chk2.hideStatus.selectedIndex].value == "x") {
      alert("Select Display Status for Indicative Price ");
      chk2.hideStatus.focus();
      return false;   
   }
   if (chktrim(chk2.packaging.value).length==0) {
      alert("Enter Packaging");
      chk2.packaging.focus();
      return false; 
   }   
   if (chk2.paymentTerms.options[chk2.paymentTerms.selectedIndex].value == "x") {
      alert("Select Payment Terms");
      chk2.paymentTerms.focus();
      return false; 
   }
   if (chk2.paymentTerms.options[chk2.paymentTerms.selectedIndex].value == "Other" && chktrim(chk2.otherPaymentTerms.value).length==0) {
      alert("Select Other Payment Terms");
      chk2.otherPaymentTerms.focus();
      return false; 
   }
   if (chk2.expDay.options[chk2.expDay.selectedIndex].value == "x") {
      alert("Select Expiry Day");
      chk2.expDay.focus();
      return false; 
   }
   if (chk2.expMonth.options[chk2.expMonth.selectedIndex].value == "x") {
      alert("Select Expiry Month");
      chk2.expMonth.focus();
      return false; 
   }
   if (chk2.expYear.options[chk2.expYear.selectedIndex].value == "x") {
      alert("Select Expiry Year");
      chk2.expYear.focus();
      return false; 
   }
   if (navigator.appVersion.indexOf("MSIE") != -1) {
   var now = new Date();
   var curDate = new Date (now.getYear(), now.getMonth(), now.getDate());
   var entDate  = new Date (chk2.expYear.value, chk2.expMonth.value-1, chk2.expDay.value);
   var daysDiff = (entDate .getTime() - curDate.getTime()) / (1000 * 60 * 60 * 24);
   if (daysDiff>90 || daysDiff<0) {
      alert("Invalid  Expiry Date");
      chk2.expDay.focus();
      return false;
   }
   }
}

function chktrim(inputString) {
    if (typeof inputString != "string") { return inputString; }
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    while (ch == " ") { 
       retValue = retValue.substring(1, retValue.length);
       ch = retValue.substring(0, 1);
    } 
    ch = retValue.substring(retValue.length-1, retValue.length);
    while (ch == " ") { 
       retValue = retValue.substring(0, retValue.length-1);
       ch = retValue.substring(retValue.length-1, retValue.length);
    }
    while (retValue.indexOf("  ") != -1) { 
       retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
    }
    return retValue; 
} 



function user_step1(chk1) {
  if (!chk1.memberLevel[0].checked && !chk1.memberLevel[1].checked && !chk1.memberLevel[2].checked && !chk1.memberLevel[3].checked) {
     alert("Select Membership Level ( Gold/Silver/Bronze/Free )");
     return false;
   }
   if (chk1.country.options[chk1.country.selectedIndex].value == "x") {
      alert("Select Country Name ");
      chk1.country.focus();
      return false;
   }
   if (chk1.username.value != chk1.username2.value){
	alert("Email address does not match\nPlease reenter email address");
	chk1.username.focus();
	return false;
   }
   if (chk1.username.value.length == 0) {
      alert("E-mail address can't be left blank");
      chk1.username.focus();
      return false;
   }
   if (chk1.username.value.indexOf('@') == -1) {
      alert("Error in e-mail address");
      chk1.username.focus();
      return false;
   }
   if (chk1.username.value.indexOf('.') == -1) {
      alert("Error in e-mail address");
      chk1.username.focus();
      return false;
   }
   if (chk1.username.value.indexOf('@') != chk1.username.value.lastIndexOf('@')) {
      alert("Please Specify One E-mail address only");
      chk1.username.focus();
      return false;
   }  
}

function existing_user(chk2) {

   if (chk2.username.value.length == 0) {
      alert("E-mail ID can't be left blank");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('@') == -1) {
      alert("Error in Email ID");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('.') == -1) {
      alert("Error in Email ID");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('@') !=  chk2.username.value.lastIndexOf('@')) {
      alert("Please Specify One Email ID only");
      chk2.username.focus();
      return false;
   }  
   if (chk2.pass.value.length<6) {
      alert("Enter Your Password ");
      chk2.pass.focus();
      return false; 
   }
}

function chngPass(chk2) {
   if (chk2.username.value.length == 0) {
      alert("E-mail ID can't be left blank");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('@') == -1) {
      alert("Error in Email ID");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('.') == -1) {
      alert("Error in Email ID");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('@') !=  chk2.username.value.lastIndexOf('@')) {
      alert("Please Specify One Email ID only");
      chk2.username.focus();
      return false;
   }  
   if (chktrim(chk2.pass.value).length <6) {
      alert("Password must be 6 characters ");
      chk2.pass.focus();
      return false; 
   }
   if (chktrim(chk2.cpass.value).length <6) {
      alert("Confirm Password must be 6 characters ");
      chk2.cpass.focus();
      return false; 
   }
   if (chk2.pass.value != chk2.cpass.value) { 
      alert("Your Password and Re-enter password dosn't match");
      chk2.pass.focus();
      return false; 
   }
}
function user_step2(chk2,chk3) {
   if (chk3=="admin") {
   if (chk2.username.value.length == 0) {
      alert("E-mail ID can't be left blank");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('@') == -1) {
      alert("Error in Email ID");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('.') == -1) {
      alert("Error in Email ID");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('@') !=  chk2.username.value.lastIndexOf('@')) {
      alert("Please Specify One Email ID only");
      chk2.username.focus();
      return false;
   }  
      if (chktrim(chk2.pass.value).length <6) {
         alert("Password must be 6 characters ");
         chk2.pass.focus();
         return false; 
      }
   }
   else if (chk3!="user") {
     if (chktrim(chk2.pass.value).length <6) {
        alert("Password must be 6 characters ");
        chk2.pass.focus();
        return false; 
     }
     if (chktrim(chk2.cpass.value).length <6) {
        alert("Re-enter Password must be 6 characters ");
        chk2.cpass.focus();
        return false; 
     }
     if (chk2.pass.value != chk2.cpass.value) { 
        alert("Your Password and Re-enter password dosn't match");
        chk2.pass.focus();
        return false; 
     }
   }

   if (chktrim(chk2.lName.value).length<1) {
      alert("Enter Last Name");
      chk2.lName.focus();
      return false;
   }
   if (chktrim(chk2.fName.value).length==0) {
      alert("Enter First Name");
      chk2.fName.focus();
      return false;
   }
   if (chktrim(chk2.compName.value).length==0) {
      alert("Enter Company Name");
      chk2.compName.focus();
      return false;
   }
   if (chk2.designation.options[chk2.designation.selectedIndex].value == "x") {
      alert("Enter Your Designation");
      chk2.designation.focus();
      return false;
   }
   if (chktrim(chk2.address1.value).length ==0) {
      alert("Enter your Address");
      chk2.address1.focus();
      return false;
   }
   if (chktrim(chk2.city.value).length ==0) {
      alert("Enter your City");
      chk2.city.focus();
      return false;
   }
   if (chk2.state.type=="select-one" &&  chk2.state.options[chk2.state.selectedIndex].value == "x") {
      alert("Select your State");
      chk2.state.focus();
      return false;
   }
   if (chk2.state.type=="select-one" && chk2.zip.value.length<6) {
      alert("Enter Zip/Postal Code ");
      chk2.zip.focus();
      return false;
   }
   if (!parseInt(chk2.ph_ccode.value)) {
      alert("Incorrect Phone  - Country Code");
      chk2.ph_ccode.focus();
      return false;
   }
   if (chk2.ph_acode.value.length ==0) {
      alert("Enter Phone Number - Area Code");
      chk2.ph_acode.focus();
      return false;
   }
   if (!parseInt(chk2.ph_acode.value)) {
      alert("Incorrect Phone - Area Code");
      chk2.ph_acode.focus();
      return false;
   }
   if (chk2.ph_ccode.value.length ==0) {
      alert("Enter Phone Number - Country Code");
      chk2.ph_ccode.focus();
      return false;
   }
   if (chk2.ph_number.value.length ==0) {
      alert("Enter Phone Number");
      chk2.ph_number.focus();
      return false;
   }
   if (!parseInt(chk2.ph_number.value)) {
      alert("Incorrect Phone Number");
      chk2.ph_number.focus();
      return false;
   }
   if (chktrim(chk2.productList.value).length ==0) {
      alert("Please enter you buy or sell products");
      chk2.productList.focus();
      return false;
   }
   if (chk2.turnover.options[chk2.turnover.selectedIndex].value == "x") {
      alert("Select Turnover of Company ");
      chk2.turnover.focus();
      return false;
   }
   if (chk2.noofEmp.options[chk2.noofEmp.selectedIndex].value == "x") {
      alert("Select Number of Employees");
      chk2.noofEmp.focus();
      return false;
   }
   if (chk2.compType.options[chk2.compType.selectedIndex].value == "x") {
      alert("Select Type of Company");
      chk2.compType.focus();
      return false; 
   }
   if (chk2.yearofOpr.options[chk2.yearofOpr.selectedIndex].value == "x") {
      alert("Select No. of years in Operation");
      chk2.yearofOpr.focus();
      return false; 
   }
   if (chk3!="user" && chk3!="admin") {

   if (chk2.memberLevel.value!="10000" && (!chk2.pymtMode[0].checked) && (!chk2.pymtMode[1].checked) && (!chk2.pymtMode[2].checked)) {
      alert("Select Your Payment Options ");
      chk2.pymtMode[0].focus();
      return false; 
   }
   if (chk2.reference.options[chk2.reference.selectedIndex].value == "x") {
      alert("Select Your Reference");
      chk2.reference.focus();
      return false; 
   }
   }

}

function subs_test(chk2){
   if (chk2.username.value.length == 0) {
      alert("E-mail ID can't be left blank");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('@') == -1) {
      alert("Error in Email ID");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('.') == -1) {
      alert("Error in Email ID");
      chk2.username.focus();
      return false;
   }
   if (chk2.username.value.indexOf('@') !=  chk2.username.value.lastIndexOf('@')) {
      alert("Please Specify One Email ID only");
      chk2.username.focus();
      return false;
   } 
}

function leadcheck(chk2){
	if ((chk2.activeleads.value - chk2.maxleads.value) == 0) {
		alert("Paid membership or Upgrade required");
		return false;
	}
}

function check_boxes() {
if (check.checkall.checked == true ){
for (var i = 0; i < check.elements.length; i++) {
if (check.elements[i].name.match('chk_') == 'chk_')
check.elements[i].checked = true;
}
}
if (check.checkall.checked == false ){
for (i = 0; i < check.elements.length; i++) {
if (check.elements[i].name.match('chk_') == 'chk_')
check.elements[i].checked = false;
}
};

}

function check_all() {
if (form1.checkall.checked == true ){
for (var i = 0; i < form1.elements.length; i++) {
if (form1.elements[i].name.match('chk_') == 'chk_')
form1.elements[i].checked = true;
}
}
if (form1.checkall.checked == false ){
for (i = 0; i < form1.elements.length; i++) {
if (form1.elements[i].name.match('chk_') == 'chk_')
form1.elements[i].checked = false;
}
};
}

   
function reload(chk1){
$sb = document.leadSearch.status;
if ($sb.options[$sb.selectedIndex].value == 1){
	document.leadSearch.action='index.php';
	document.leadSearch.submit();
}
else{
	document.leadSearch.action='inactive-chemical-supplies.php';
	document.leadSearch.submit();
}
}

function catalog_valid(chk2,chk3) {
   if (chk3=="check" && chk2.leadType.options[chk2.leadType.selectedIndex].value == "x") {
      alert("Select Trade Lead Type");
      chk2.leadType.focus();
      return false; 
   }
   if (chktrim(chk2.productName.value).length==0) {
      alert("Enter Product Name");
      chk2.productName.focus();
      return false; 
   }
   if (chk2.category.options[chk2.category.selectedIndex].value == "x") {
      alert("Select Product Category");
      chk2.category.focus();
      return false; 
   }
   if (chktrim(chk2.indicativePrice.value.length)==0 || chktrim(chk2.indicativePrice.value)<=0) {
      alert("Enter Indicative Price");
      chk2.otherCurrency.focus();
      return false;   
   }
   if (chktrim(chk2.indicativePrice.value)>0 && chk2.currency.options[chk2.currency.selectedIndex].value == "Other" && chktrim(chk2.otherCurrency.value).length==0) {
      alert("Enter Currency for Indicative Price");
      chk2.otherCurrency.focus();
      return false;   
   }
   if (chktrim(chk2.indicativePrice.value)>0 && chk2.perUnit.options[chk2.perUnit.selectedIndex].value == "x") {
      alert("Select Currency for Indicative Price");
      chk2.perUnit.focus();
      return false;   
   }
   if (chktrim(chk2.indicativePrice.value)>0 && chk2.perUnit.options[chk2.perUnit.selectedIndex].value == "Other" && chktrim(chk2.otherPerUnit.value).length==0) {
      alert("Enter per Unit for Indicative Price");
      chk2.otherPerUnit.focus();
      return false;   
   }
   if (chktrim(chk2.packaging.value).length==0) {
      alert("Enter Packaging");
      chk2.packaging.focus();
      return false; 
   }   
   if (chk3=="check" && chk2.countryOrigin.options[chk2.countryOrigin.selectedIndex].value == "x" && chk2.leadType.options[chk2.leadType.selectedIndex].value == "Sell") {   
      alert("Select Country Origin");
      chk2.countryOrigin.focus();
      return false; 
   }
   else if (chk2.countryOrigin.options[chk2.countryOrigin.selectedIndex].value == "x" && chk2.leadType.value == "Sell") {   
      alert("Select Country Origin");
      chk2.countryOrigin.focus();
      return false; 
   }
}
