function ctab(iTab) {
  if (iTab == 1) {
    document.getElementById('tabm0').className = "inactive";
    document.getElementById('tabm1').className = "active";
    document.getElementById('tab0').style.visibility = 'hidden';
    document.getElementById('tab1').style.visibility = 'visible';
  } else {
    document.getElementById('tabm0').className = "active";
    document.getElementById('tabm1').className = "inactive";
    document.getElementById('tab0').style.visibility = 'visible';
    document.getElementById('tab1').style.visibility = 'hidden';
  }
}

function applyDiscounts() {
 var myGuide, VATDec;

 VATDec = 1 + (vatRate / 100);

 discPct = Number(document.bidform.discpct.value);
 discDec = 1 - (discPct / 100);

 myGuide = (vehUKPrice * discDec * VATDec) + (vehOptions * discDec) + vehDelivery + vehRoadTax + vehRegFee;
 
 document.bidform.guidePrice.value = parseInt(myGuide);

 calculateTotals();
}

function calculateTotals() {
var delCosts, guidePrice, noPlates, manDelivery, newPrice, totalVehicle, roadTax, regFee, otherCosts, totr, VAT, options, subOptions;

guidePrice = round(Number(document.bidform.guidePrice.value),2);
otherCosts = round(Number(document.bidform.otherCosts.value),2);
delCosts = round(Number(document.bidform.delivery.value),2);

totr = guidePrice + otherCosts + delCosts;

document.bidform.totr.value = String(totr);

return true;
}

function carmakesDeselectAll() {
  list1 = document.getElementById('carmakelist').options;
  for (i = 0; i < list1.length; i++) { 
    list1[i].selected = false;
  }
  return false;
}

function carmakesSelectAll() {
  list1 = document.getElementById('carmakelist').options;
  for (i = 0; i < list1.length; i++) { 
    list1[i].selected = true;
  }
  return false;
}

function selectCarmakesYes() {
  list1 = document.getElementById('new_cc_acct').carmakes;
  list1[2].checked = true;
  return false;
}

function vanmakesDeselectAll() {
  list1 = document.getElementById('vanmakelist').options;
  for (i = 0; i < list1.length; i++) { 
    list1[i].selected = false;
  }
  return false;
}

function vanmakesSelectAll() {
  list1 = document.getElementById('vanmakelist').options;
  for (i = 0; i < list1.length; i++) { 
    list1[i].selected = true;
  }
  return false;
}

function selectVanmakesYes() {
  list1 = document.getElementById('new_cc_acct').vanmakes;
  list1[2].checked = true;
  return false;
}

function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function Validator11() { //used in placebid

calculateTotals();

/*MCE063
if (document.bidform.Username.value == "")
{
alert("Please Enter valid information");
document.bidform.Username.focus();
return (false);
}
if (document.bidform.password.value =="")
{
alert("Please Enter valid information");
document.bidform.password.focus();
return (false);
}
*/
if (document.bidform.input7.value =="")
{
alert("Please Enter the delivery date");
document.bidform.input7.focus();
return (false);
}
if (document.bidform.guidePrice.value =="")
{
alert("Please Enter all required pricing information.  Use 0 as needed");
document.bidform.guidePrice.focus();
return (false);
}
}

function ValidatePro2() {
  if (ValidatePro2A()) {
    return ValidatePro2B();
  } else {
    return false;
  }
} 

function ValidatePro2A() { 
  form1 = document.getElementById('new_cc_acct');
  if (form1.co_name.value == "") {
    alert("Please enter your company name.")
    form1.co_name.focus()
    return(false)
  }
  var m1 = document.getElementById('carmakelist')
  var flag=0;
  var chk1 = false;
  var noMakes = false;
  var m2 = form1.carmakes;
  for (i=0; i<m2.length; i++) {
   	if(m2[i].checked == true) {
  	   flag=1
  	 }
    if (m2[2].checked == true) chk1 = true
    noMakes = (m2[0].checked == true);
  }
  if (flag==0) {
   	alert("Please specify whether you deal with any car makes/manufacturers.");
   	m2[0].focus();
   	return false;
  }

  if (chk1) {
    flag = 0;
    for (i=0; i<m1.length; i++) {
     	if(m1.options[i].selected == true) {
    	   flag=1
    	 }
    }
    if (flag==0) {
     	alert("Please select one or more car makes.");
     	m1.focus();
     	return false;
    }
  }

  m1 = document.getElementById('vanmakelist')
  flag=0;
  chk1 = false;
  m2 = form1.vanmakes;
  for (i=0; i<m2.length; i++) {
   	if(m2[i].checked == true) {
  	   flag=1
  	 }
    if (m2[2].checked == true) chk1 = true;
    noMakes = (m2[0].checked == true && noMakes);
  }
  if (flag==0) {
   	alert("Please specify whether you deal with any van makes/manufacturers.");
   	m2[0].focus();
   	return false;
  }
  if (noMakes) {
   	alert("You need to select some car makes or van makes you deal with.");
   	m2[0].focus();
   	return false;
  }

  if (chk1) {
    flag = 0;
    for (i=0; i<m1.length; i++) {
     	if(m1.options[i].selected == true) {
    	   flag=1
    	 }
    }
    if (flag==0) {
     	alert("Please select one or more van makes.");
     	m1.focus();
     	return false;
    }
  }
  return true;
}

function ValidatePro2B() { 

  form1 = document.getElementById('new_cc_acct');
  if (form1.TOS.checked == false) {
    alert("Please indicate that you accept the Terms and Conditions");
    form1.TOS.focus();
    return (false);
  }
  if (form1.usedCollectFrom.options[form1.usedCollectFrom.selectedIndex].value == "Distance") {
    if (form1.usedDistance.value == "") {
      alert("If you select Distance, you must enter the number of miles")
      form1.usedDistance.focus()
      return(false)
    }
    if (!isNumeric(form1.usedDistance.value)) {
      alert("Please verify that the Distance contains only numeric values.");
      form1.usedDistance.focus();
      return false;
    }
  }
  return true;
}

function ValidatePro() { 
  if (document.login2.email_addr.value == "") {
    alert("Please give your email id.");
    document.login2.email_addr.focus();
    return(false);
  }
  p=document.login2.email_addr.value.indexOf('@')
  if (p<1) {
    alert("Email id that you have given is not valid.");
    document.login2.email_addr.focus();
    return(false);
  }
  
  uname = document.login2.login_name.value;
  if (document.login2.login_name.value == "") {
   	alert("Please select some Username.");
   	document.login2.login_name.focus();
   	return(false);
  } else {
    for (var i=0; i < uname.length; i++ ) {
  		  var ch = uname.substring(i,i+1)
    		if (ch < "0" || ch > "9") {
     			if(ch < "A" || ch > "Z") {
  			    	if(ch < "a" || ch > "z") {
       					if(ch != "_") {
  			      			alert("Sorry! Username can't contain characters other than alphabets,numbers and underscore.")
        						document.login2.login_name.focus();
  				      		return false
       					}
  			    	}
  			   }
  		  }
  	 }
  }
  
  if (document.login2.password.value == "") {
    alert("Please select some Password.");
    document.login2.password.focus();
    return(false);
  }
  if (document.login2.rpassword.value == "") {
    alert("Please confirm your password.");
    document.login2.rpassword.focus();
    return(false);
  }
  pass = document.login2.password.value
  rpass = document.login2.rpassword.value
  if (pass != rpass) {
    alert("Please confirm your password.");
    document.login2.password.focus();
    return(false);
  }
  if (document.login2.login_name.value.length < 4 ) {
    alert("Your Username must be atleat 4 characters long.");
    document.login2.login_name.focus();
    return(false);
  }
  if (document.login2.password.value.length < 6 ) {
    alert("Your password must be atleat 6 characters long.");
    document.login2.password.focus();
    return(false);
  }
  if (document.login2.x_First_Name.value == "") {
    alert("Please enter a value for the \"First Name\" field.")
    document.login2.x_First_Name.focus()
    return(false)
  }
  if (document.login2.x_Last_Name.value == "") {
    alert("Please enter a value for the \"Last Name\" field.");
    document.login2.x_Last_Name.focus();
    return(false);
  }
/*if (document.login2.x_Address.value == "") {
  alert("Please enter a value for the \"Street Address\" field.");
  document.login2.x_Address.focus();
  return(false);
  } */
  
  if (document.login2.x_phone_no.value == "") {
  	 alert("Please enter your phone number.");
  	 document.login2.x_phone_no.focus();
  	 return(false);
  } else if (isPhone(document.login2.x_phone_no.value)) {
  } else {
  	 alert("Please verify that Phone number contains only numeric values\nspace and - character are allowed");
  	 document.login2.x_phone_no.focus();
  	 return false
  }
  
  if (isPhone(document.login2.x_mobile_no.value)) {
  } else {
   	alert("Please verify that mobile number contains only numeric values\nspace and - character are allowed");
   	document.login2.x_mobile_no.focus();
   	return false
  }
  
  if (isNumeric(document.login2.x_fax_no.value)) {
  } else {
  	 alert("Please verify that fax number contains only numeric values");
  	 document.login2.x_fax_no.focus();
   	return false
  }
  if (document.login2.x_Zip.value == "") {
   	alert("Please enter a value for the \"PostCode\" field.");
   	document.login2.x_Zip.focus();
  	 return(false);
  } else if (document.login2.x_Zip.value.length < 5) {
   	alert("Please enter at least 5 characters in the \"PostCode\" field.");
   	document.login2.x_Zip.focus();
   	return(false);
  } else if (document.login2.x_Zip.value.length > 12) {
  	 alert("Please enter at most 12 characters in the \"PostCode\" field.");
  		document.login2.x_Zip.focus();
   	return(false);
  } 
  
  if (document.login2.x_city.value == "") {
    alert("Please enter a value for the \"City\" field.");
    document.login2.x_city.focus();
    return(false);
  }
  if (document.login2.nearCityDist.value == "" &&
      document.login2.x_country.value == "United Kingdom") {
    alert("Please enter a value for the \"Distance\" field.");
    document.login2.nearCityDist.focus();
    return(false);
  }
  if (document.login2.fax_me.checked) {
   	if(document.login2.x_fax_no.value == "") {
    		alert("Please Enter Fax. No. as you have selected to get messages by fax")
  	  	return false;
  	 } else {
  		  return true;
  	 }
  }
  
  if (document.login2.hearaboutus.value == "") {
    alert("Please enter where did you hear of us?")
    document.login2.hearaboutus.focus()
    return(false)
  }
}

function ValidateEmail2() { //v4.0
  if (document.getElementById("registration").email_addr.value == "") {
	   alert("Please Enter the email address.")
	   return (false);
	 }
  
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("registration").email_addr.value)) {
    return (true)
  }
  alert("Invalid E-mail Address! Please re-enter.")
  return (false);
}

function ValidateMess2() { //v4.0
  if (document.messageform.Username.value == "") {
    alert("Please Enter the Username");
    document.messageform.Username.focus();
    return(false);
  }
  if (document.messageform.Password.value == "") {
    alert("Please Enter the Password");
    document.messageform.Password.focus();
    return(false);
  }
  if (document.messageform.posted_message.value == "") {
    alert("Please Enter The Message");
    document.messageform.posted_message.focus();
    return(false);
  }
}

function ValidateMess() { //v4.0
  if (document.messageform.posted_message.value == "") {
    alert("Please Enter The Message");
    document.messageform.posted_message.focus();
    return(false);
  }
}
function ValidateEmpass() { //v4.0
  if (document.getElementById('login').login_name.value == "") {
    alert("Please Enter the User Name");
    document.getElementById('login').login_name.focus();
    return (false);
  }
  if (document.getElementById('login').PASSWORD.value == "") {
    alert("Please Enter the Password");
    document.getElementById('login').PASSWORD.focus();
    return (false);
  }
}
function ValidateEmailOnly() {
  if (document.getElementById('register').email_addr.value == "") {
	   alert("Please enter your email address!")
	   return (false);
	 }
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('register').email_addr.value)) {
    alert("Thank you.  Your password and other account details will be emailed to you.")
    return (true)
  }
  alert("Invalid E-mail Address! Please re-enter.")
  return (false);
}

var NYODprocessed = false;
var NYODchecked = false;
function checkNYODPriceIsRealistic(maxPrice, totalGuidePrice)
{  
  /* validate the numbers are ok */
  if(maxPrice=='')
  {
    alert('That price is not a valid number');
    document.JobPost.NYODPrice.focus();
    return false;
  }
  
  if (maxPrice == null || !maxPrice.toString().match(/^[-]?\d*\.?\d*$/))
  { 
    alert('That price is not a valid number');
    document.JobPost.NYODPrice.focus();
    return false;
  }   
  /* end of validating the numbers */
  
  maxPrice = parseFloat(maxPrice);
  totalGuidePrice = parseFloat(totalGuidePrice);
  
  if(maxPrice!=totalGuidePrice)
  {
      if(maxPrice<totalGuidePrice)
      {
        if (document.JobPost.vehType.value=="Van") {
          minGuide = totalGuidePrice*(1 - .3)
        } else {
          minGuide = totalGuidePrice*(1 - .04)
        }
        if(maxPrice < minGuide - 100)
        {
         	tooLowMessage = "The Maximum Price you have specified is much less than our recommended target and seems unachievable for a NEW vehicle. \n\n"
        		tooLowMessage += "How our Name Your Own Deal (NYOD) service works: \n\n"
         	tooLowMessage += "In order to take advantage of this service you must have been offered a deal on the same basis as our recommended target price.\n"
          tooLowMessage += "That is: based on a NEW UK-supplied vehicle (latest specification) including all costs shown in our pricing.\n\n"
          tooLowMessage += "If you have been offered a genuine deal on this basis for this make and model, please contact us on 0800 033 6022, Mon-Friday 9am-6pm. \n\n"
          tooLowMessage += "What you cannot do is just specify a price based on what you can afford or would like to pay.\n"
          tooLowMessage += "Our target price is based on our experience of what dealers will be able to offer and we can only recommend a different target if you have a genuine offer elsewhere."
          
          if (!NYODchecked) { 
            alert(tooLowMessage);
            NYODchecked = true;
          }
          document.JobPost.NYODPrice.focus();
          return false;
        }
      }
      else // max price is more than guide
      {
        if(maxPrice > totalGuidePrice + document.JobPost.tran_fee.value + 100)
        {
          if (!NYODchecked) { 
            alert('The reserve price is too high compared to our recommended target.')
            NYODchecked = true;
          }
          document.JobPost.NYODPrice.focus();
          return false;
        }
      }
  }
  
  return true // if get here we all good
  
}

function updateMaxPrice() { // Calculate maxprice from NYOD price
  
  NYODPrice = document.JobPost.NYODPrice.value;
  if (NYODPrice != '') {
    NYODPrice = NYODPrice.replace(/,/g,''); 
    NYODPrice = NYODPrice.replace(/£/g,''); 
    
    totalGuidePrice = document.JobPost.TotalGuidePrice.value;
  	 good = checkNYODPriceIsRealistic(NYODPrice, totalGuidePrice)
    if(!good) {
      return false;
    }
  
    NYODPrice = parseFloat(NYODPrice);
    totalGuidePrice = parseFloat(totalGuidePrice);
  
    fee = document.JobPost.tran_fee.value;
    maxPrice = NYODPrice - fee - 100 // extra 100 to ensure favourable price
    maxPrice = Math.round(maxPrice)
    
    document.JobPost.MaxPrice.value = maxPrice;
    document.getElementById("TGPtext").innerHTML = "<strong>Your Reserve Price (NYOD)</strong>: ";
    document.getElementById("TGPvalue").innerHTML = Math.floor(maxPrice);
    document.getElementById("NYODdesc").innerHTML = "The reserve price is based on the Name Your Own Deal price you have entered. Don't forget to tell us where you were offered that price.";
    if (!NYODprocessed) {
      alert("The reserve price has been adjusted by subtracting our fee and \nan additional saving of £100 from the price you have been offered.  The right hand summary section on this page is not updated although your price has been recorded.")
      NYODprocessed = true;
      return false;
    }
    NYODprocessed = true;
  }
  return true;
  
}
function ValidateMax() { // Used in orderform
  
  if (!updateMaxPrice()) {
    NYODchecked = false;
    return false;
  }
  
  if ((document.JobPost.NYODPrice.value != '') && (document.JobPost.NYODPrice.value < document.JobPost.TotalGuidePrice.value) && document.JobPost.supplier.value == "") {
    alert("If you wish to name your own price which is lower than our normal reserve price, please indicate where you found that price.");
    document.JobPost.supplier.focus();      
    return false;
  } 
  else {
    if (document.JobPost.DelTime.value == "") {
      alert("Please specify your required delivery date.");
      return false;
    } else {
 	    return true;
    }
  }
}

function clearNYOD() {
// reset NYOD price etc.

  totalGuidePrice = parseFloat(totalGuidePrice);
  maxPrice = totalGuidePrice;
  document.JobPost.MaxPrice.value = maxPrice;
  document.JobPost.NYODPrice.value = '';
  document.JobPost.supplier.value = '';
  document.getElementById("TGPtext").innerHTML = "<strong>Recommended target price</strong> (reserve): ";
  document.getElementById("TGPvalue").innerHTML = maxPrice;
  document.getElementById("NYODdesc").innerHTML = "<strong>Name Your Own Deal</strong> - If you have been offered a better price already or have seen it advertised elsewhere you may use this to set the reserve price. ";
  document.getElementById("NYODdesc").innerHTML += "Enter the details of the price you have been offered below. ";
  document.getElementById("NYODdesc").innerHTML += "Please note that this price should be a genuine offer for a vehicle on the same terms (options, delivery time, registration type, etc.) as you have specified.  Do not simply enter the price you wish to pay.";

}

function ValidateDates() { //temp until rework function with BidDays
}

function ValidateDatesOld() {
  var delArray;
  delArray = document.JobPost.DelTime.value.split("-");
  dateStr = String(delArray[1]+"/")+String(delArray[0])+"/"+String(delArray[2]);
  var deldate = new Date(Date.parse(dateStr));
  
  delArray = document.JobPost.BidTime.value.split("-");
  dateStr = String(delArray[1]+"/")+String(delArray[0])+"/"+String(delArray[2]);
  var biddate = new Date(Date.parse(dateStr));
  
  delArray = document.JobPost.OrderDate.value.split("-");
  dateStr = String(delArray[1]+"/")+String(delArray[0])+"/"+String(delArray[2]);
  var orddate  = new Date(Date.parse(dateStr));
  var right_now = new Date();
  
  msecperday = 24*60*60*1000
  daysleft  = (deldate.getTime() - biddate.getTime())/ msecperday
  daysleft1 = (deldate.getTime() - orddate.getTime())/ msecperday
  daysleft2 = (orddate.getTime() - right_now.getTime())/ msecperday
  daysleft3 = (biddate.getTime() - right_now.getTime())/ msecperday
  
  if ( biddate > deldate ) {
   	alert("Invalid Date Range!\nVehicle Bidding Date cannot be after Delivery Date!")
   	return false;
  }
  if ( orddate > deldate ) {
   	alert("Invalid Date Range!\nVehicle Order Date cannot be after Delivery Date!")
   	return false;
  }
  if ( daysleft < 2 ) {
   	alert("Invalid Date Range!\nVechicle Delivery Date should be at least 2 days after Bidding Date!")
   	return false;
  }	 
  if ( daysleft1 < 2 ) {
   	alert("Invalid Date Range!\nVechicle Delivery Date should be at least 2 days after Order Date!")
   	return false;
  }
  if ( daysleft2 < 2 ) {
   	alert("Invalid Date Range!\nVechicle Order Date should be at least 2 days from today!")
   	return false;
  }	 
  if ( daysleft3 < 2 ) {
   	alert("Invalid Date Range!\nVechicle Bid Date should be at least 2 days from today!")
   	return false;
  }
}

function checkOrderDelivery() {
 var user_input;
 checkedDelDate = true;

 user_input = document.JobPost.DateFlex.value;

 if(user_input != '4+ weeks') {
  alert("Please note, delivery dates we display are estimates and by not stating you are flexible 4+ weeks many dealers may not bother to offer you a bid if delivery times are slightly longer than the date you have specified. Please feel free to call us during working hours to get a more accurate delivery time on 0207 902 1928");
 }
}

function OrderValidation() {
 if(ValidateMax()) {
  if(confirmOrderDelivery()) {
   if(confirmExtraBids()) {
    return true;
   }
  }
 }
 return false;
}

function confirmOrderDelivery() {
 user_input = document.JobPost.DateFlex.value;

 if(user_input == '-') {
  alert("You must specify your delivery flexibility");
  return false;
 } else {
  return true;
 }
}

function confirmExtraBids() {
 user_input = document.JobPost.extraBids.value;

 if(user_input == '-') {
  alert("You must specify whether you want non-registered suppliers to receive your order");
  return false;
 } else {
  return true;
 }
}

function confirmSubmit()	{
		var agree=confirm("Do you want to delete this order?");
		
		if (agree)
		 	return true ;
		else
			 return false ;
}

function confirm_entry(var_1)
{
  input_box=confirm("Click OK to Cancel the requirement");
  if (input_box==true) { 
    window.location = var_1
  }
}

function confirm_entry2(var_1)
{
//alert(var_1)
  input_box=confirm("Click OK to Reopen the requirement");
  if (input_box==true) { 
// Output when OK is clicked
//alert ("You clicked OK"); 
//window.open(var_1)
    window.location = var_1
  }
}


function ValidateChanges() { //v4.0
// in chempass
  if (document.login2.email_addr.value == "") {
    alert("Please give at least one email address.");
    document.login2.email_addr.focus();
    return(false);
  }
  p=document.login2.email_addr.value.indexOf('@')
  if (p<1) {
    alert("Email id that you have given is not valid.");
    document.login2.email_addr.focus();
    return(false);
  }
  if (document.login2.opassword.value == "") {
    alert("Please enter your current password.");
    document.login2.opassword.focus();
    return(false);
  }

  pass = document.login2.password.value
  rpass = document.login2.rpassword.value
  if (pass != rpass) {
    alert("Please confirm your new password.");
    document.login2.password.focus();
    return(false);
  }
  
  if (document.login2.password.value.length < 6 && document.login2.password.value.length > 0) {
    alert("Your password must be atleat 6 characters long.");
    document.login2.password.focus();
    return(false);
  }
}

var urlun = "checkusername.asp?param="; 
var urlemail = "checkemail.asp?param="; 

function updateName() { 
  var name = document.getElementById("registration").login_name.value;
  if (name == "") {
    document.getElementById('un').innerHTML = "email may not be blank"; 
    alert("Please enter an email address as your username");
    return false;
  } else { 
    document.getElementById('un').innerHTML = "Checking username in database..."; 
    //document.getElementById("registration").email_addr.value=name;
    http.open("GET", urlun + escape(name), true); 
    http.onreadystatechange = handleUsername; 
    http.send(null);
  } 
} 

function handleUsername() { 
  if (http.readyState == 4) { 
    results = http.responseText; 
    var name = document.getElementById("registration").login_name.value; 
    if(results == "") results = "<i>"+name+"</i> is unused"; 
    document.getElementById('un').innerHTML = results; 
  } 
} 
function updateemail() { 
  
  document.getElementById('une').innerHTML = "Checking Email id in database..."; 
  var name = document.getElementById("registration").email_addr.value; 
  http.open("GET", urlemail + escape(name), true); 
  http.onreadystatechange = handleEmail; 
  http.send(null); 
} 

function handleEmail() { 
  if (http.readyState == 4) { 
    results = http.responseText; 
    var name = document.getElementById("registration").email_addr.value; 
    if(results == "") results = "Email address  <i>"+name+"</i> Is Available..."; 
     
    document.getElementById('une').innerHTML = results; 
  } 
} 

function checkStreet()
{
 z = document.getElementById("manStreet");
 if(document.getElementById("street").value == 'Other...') {
  z.style.visibility = 'visible';
 } else {
  z.style.visibility = 'hidden';
 }
}
function checkStreet2()
{
 var z = document.getElementById("manaddress");
 if(document.getElementById("address2").value == 'Other...') {
 	document.getElementById("address2").value ='';
  z.style.visibility = 'visible';
 } else {
 	document.getElementById("registration").address.value = document.getElementById("registration").address2.value
  z.style.visibility = 'hidden';
 }
}
function clearStreet()
{
 if(document.getElementById("otherStreet").value == 'Enter Street Here') {
  document.getElementById("otherStreet").value = '';
  document.getElementById("otherStreet").focus();
 }
}

function isNumeric(str)
{
for (var i=0; i < str.length; i++ ) {
var ch = str.substring(i,i+1)
if (ch < "0" || ch > "9" || str.length == null) {
return false
}
}
return true
}

function isPhone(str)
{
if(str.substring(0,3) == "000") return false;

for (var i=0; i < str.length; i++ ) {
	var ch = str.substring(i,i+1)
	if ( ch < "0" || ch > "9") {
		if ( ch != "-" ) {
			if ( ch != " " ) {
				return false
			}
		}
	}
}
return true
}

function clearTextA() {

 form_registration = document.getElementById("registration")
 form_registration.password.value = '';
 form_registration.password.focus();
}

var forceFull = false;
function ValidateRegn(full) {
  form_registration = document.getElementById("registration")
  if (form_registration.login_name.value == "")
  {
    alert("Please enter your email address as login name");
    form_registration.login_name.focus();
    return (false);
  }
  org_pass=form_registration.password.value
  if (form_registration.password.value =="")
  {
    alert("Please enter a password");
    form_registration.password.focus();
    return (false);
  }
  // regexp for mail verification
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form_registration.login_name.value))
    {
  //  return (true)
  } else {
    document.getElementById('un').innerHTML = "invalid format"; 
    alert("Invalid E-mail Address! Please re-enter.")
    return (false);
    }
  
  if (full || forceFull) {
    return ValidateDet2();
  }
}

function ValidateDet2() {
  form_registration = document.getElementById("registration")
  //alert("V2");
  if (form_registration.name.value == "")
  {
  alert("Please enter your first name");
  form_registration.name.focus();
  return (false);
  }
  if (form_registration.last_name.value == "")
  {
  alert("Please enter your last name");
  form_registration.last_name.focus();
  return (false);
  }
  if (form_registration.address.value == "")
  {
  alert("Please enter your address");
  form_registration.address.focus();
  return (false);
  }
  if (form_registration.city.value == "")
  {
  alert("Please enter the city");
  form_registration.city.focus();
  return (false);
  }
  
  if (form_registration.zip_code.value == "")
  {
  alert("Please enter the postal code");
  form_registration.zip_code.focus();
  return (false);
  }
  //if (form_registration.howHelp.value == "*")
  //{
  //alert("Please enter how we can help");
  //form_registration.howHelp.focus();
  //return (false);
  //}
  //if (form_registration.Profession.value == "")
  //{
  //alert("Please enter your profession");
  //form_registration.Profession.focus();
  //return (false);
  //}
  
  //if (form_registration.paper.value == "")
  //{
  //alert("Please enter the newspaper you read or the name of any publications you read from time to time");
  //form_registration.paper.focus();
  //return (false);
  //}
  
  if (form_registration.phone_number.value == "" &&
      form_registration.office_phone_no.value == "" &&
      form_registration.mobile_no.value == "")
  {
  	alert("Please enter at least one phone number");
  	form_registration.phone_number.focus();
  	return (false);
  }
  
  if (isPhone(form_registration.phone_number.value))
  {
  }
  else{
  	 alert("Please verify that Phone No. contains only numeric characters in the \"Phone\" field, and that it does not start with 000");
    form_registration.phone_number.focus();
   	return false;
  }
  
  if (isPhone(form_registration.office_phone_no.value))
  {
  }
  else{
  	alert("Please verify that DayTime Phone No. contains only numeric characters in the \"DayTime\" field, and that it does not start with 000");
  	form_registration.office_phone_no.focus();
  	return false;
  }
  
  if (isPhone(form_registration.mobile_no.value))
  {
  }
  else{
  	alert("Please verify that Mobile No. contains only numeric characters in the \"Mobile Number\" field, and that it does not start with 000");
  	form_registration.mobile_no.focus();
  	return false;
  }
  
  //MCE008 reactivated cycle check
  if (form_registration.pCycle.value == "*")
  {
  alert("Please tell us where you are in your purchase cycle (how close you are to buying)");
  form_registration.pCycle.focus();
  return (false);
  }

  if (form_registration.howHelp.value == "*")
  {
  alert("Please tell us how we can help");
  form_registration.howHelp.focus();
  return (false);
  }

  if (form_registration.hearaboutus.value == "") {
    alert("Please enter where you heard about Auto eBid")
    form_registration.hearaboutus.focus()
    return(false);
  }
  return (true);
}

function createWindow(u,n,w,h,r)
{
  args = 'width='+w+',height='+h+',resizable=no,scrollbars=yes,status=0';
  remote = window.open(u,n,args);
  if ( remote != null ) {
    if (remote.opener == null) {
      remote.opener = self ;
    }
  }
  if ( r == 1 ) {
    return remote;
  }
}

var attw =null;
var drww =null;

function Attach( url )
{
  if ( !attw || attw.closed ) {
    attw = createWindow( url, 'attachwin', 420, 360, 1) ;
  }
  attw.focus();
}

var popUpWindow=1;

function AttachFocus()
{
  document.JobPost.elements['Atts'].blur();
  if ( popUpWindow==1 ) {
    var msg = 'Click "Upload" to add/remove files';
    window.alert(msg);
    popUpWindow=0;

  }
  document.JobPost.elements['ATT'].focus();
  return false;
}

function Cat( daLink ) {
  var comwin = window.open(daLink,'Cat','width=400,height=280,scrollbars=no,resize=no');
  comwin.focus();
}

var pop = 'yes';

function Popup( daLink ) {
  var comwin = window.open(daLink,'Ad','width=460,height=380,scrollbars=yes,resize=no');
  comwin.focus() ; 
}

function setVarNo() {
  pop = 'no';
}
function checkForPop() {
  if (pop == "yes") {
  }
}

function populateCat(selected) {
  if (selected == '-1') {
    document.select.src="http://images.<%= sitename%>.com/images/basic200.gif"; document.basic.src="http://images.<%= sitename%>/images/basic200.gif"; document.basic.src="http://images.<%= sitename%>/images/basic200.gif"; document.JobPost.select.src="http://images.<%= sitename%>/images/basic200.gif";
  }
}

function doPopup(path) {
	if (navigator.appName.indexOf("WebTV") == -1) {
		hw = window.open(path, "bidwin", "height=275,width=475,status=no,toolbar=no,scrollbars=yes,menubar=no,location=no,resizable=yes,titlebar=no");
		hw.focus();
		return false;
	}
	else { document.location.href = path; }
}

function CheckAll() {
  for (var i=0;i<document.gt_massdelete.elements.length;i++) {
    var e = document.gt_massdelete.elements[i];
    e.checked = 1;
  }
}

function ClearAll() {
  for (var i=0;i<document.gt_massdelete.elements.length;i++) {
    var e = document.gt_massdelete.elements[i];
    e.checked = 0;
  }
}

// used in acarpostLogin if users clicks icon when not logged in
function noEmail() {
  alert('In order to be able to save or email these details, first provide us with an email address'); 
  document.getElementById('register').email_addr.style.background = '#FFFF99';
  document.getElementById('register').email_addr.focus()
}






