// JavaScript Document

var ie4 = false; if(document.all) { ie4 = true; }

function getObject(id) {
	if(ie4){
		return document.all[id]
	}
	else{
    	return document.getElementById(id);
	}
}
  
function hideDiv(divId) {
	var d = getObject(divId);
	d.style.display = 'none';
}

function showDiv(divId) {
	var d = getObject(divId);
	d.style.display = 'block';
}

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function codename() {
	if(document.orderform.agreebox.checked)
	{
		document.orderform.submit.disabled = false;
	}
	else
	{
		document.orderform.submit.disabled = true;
	}
}

function hideAll() {
   hideDiv('ECU');
   hideDiv('AirFlow');
   hideDiv('SpeedCut');
   hideDiv('FuelCut');
   hideDiv('InjectorSize');
   hideDiv('InjectorBrand');
   hideDiv('RevLimit');
   hideDiv('LaunchControl');
   hideDiv('Submit');
   hideDiv('Comments');
   hideDiv('checkbox');
}


function validate_string(field){
  if ( field.value == '' ){
    alert("You must enter a value into this field.");
    field.focus();
    field.select();
    return false;
  }
  return true;
}

function validate_num(field) {
  if ( ! validate_string(field) ) return false;
   var valid = "0123456789 ()";
   var ok = "yes";
   var temp;
   for (var i=0; i<field.value.length; i++) {
      temp = "" + field.value.substring(i, i+1);
      if (valid.indexOf(temp) == "-1") ok = "no";
   }
   if (ok == "no") {
      alert("Invalid entry!  Only numbers are accepted!");
      field.focus();
      field.select();
      return false;
   }
   return true;
}

//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  strEmail = document.forms[0].email.value;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      alert('A valid e-mail address is required.\nPlease amend and retry');
      return false;
    } 
    return true; 
}
