function newWindow(page, W, H,scrollbars)
{
 	var w=window.screen.width;
  var h=window.screen.height;
  var X=X||Math.ceil((w-W)/2)
  var Y=Y||Math.ceil((h-H)/2)
  if (scrollbars == 0) 
  {
  	scrollbars = "no"
  }
  else
  {
  	scrollbars = "yes"
  }
  features = "width=" + W + ",height=" + H + ",menubar=no,location=no,scrollbars=" + scrollbars + ",left=" + X + ",top=" + Y;
  top.window_handle = window.open(page, 'Information', features);
}


function mapquest()
{
window.open('http://www.mapquest.com/directions', 'dummyname', 'scrollbars=yes,height=350,width=775', false)
}

function Compute_cost(Mileage)
{
var dist = Mileage.distance.value ;
Mileage.cost.value = 7 ;
var cst = 0;
if  (dist >0) 
    {
     cst = "" + Math.round(((2.00 * dist) + 2.50) *100)/100;
     cst = "" + Math.round(( (.50*Math.floor(5*dist))+ 2.50) *100)/100;
     if(cst.lastIndexOf('.') < 0)
     {
       cst = cst + '.00';
     }
     else if (cst.length - cst.lastIndexOf('.') == 2)
     {
       cst = cst + '0';
     }
    } 
else
   {
    cst  = '2.50' ;
   }
  Mileage.cost.value = cst;
}


function popItUp(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function checkEmail(value)
{
  start = 0;
  funcBool = false;
  characterLoc = 0;
  periodLoc = 0;
  suffixLength = 0;
  domainLength = 0;

  // check for the @ symbol in email
  for (i=start; i<value.length; i++)
  {
    if (value.charAt(i) == "@")
    {
      characterLoc = i;
      funcBool = true;
    }
  }
  // make sure that the @ symbol is not the first letter in email
  if (characterLoc == 0 )
  {
    funcBool = false;
  }

  // look for period in email (suffix check) and make sure the suffix is at least 2 chars long
  periodLoc = value.lastIndexOf(".")
  if(periodLoc != -1)
  {
    suffixLength = value.length - (periodLoc + 1);
    if (suffixLength < 2 )
    {
      funcBool = false;
    }
  }
  else
  {
    funcBool = false;
  }
  
  // make sure there is a domain name 
  domainLength = periodLoc - characterLoc;
  if (domainLength == 1)
  {
    funcBool = false;
  }

  // go ahead and test the boolean and location of the @ symbol
  if (funcBool == false)
  { 
    return false;
  }
  return true;
}


function checkForm(thisForm)
{
  var flag = 0;
  var fname = thisForm.regfname.value;
  var lname = thisForm.reglname.value;
  var email = thisForm.regEmail.value;
  var pass1 = thisForm.regPasswd1.value;
  var pass2 = thisForm.regPasswd2.value;
  
  if (fname == "")
  {
    alert("First name is a required field");
    return false;
  }
  if (lname == "")
  {
    alert("Last name is a required field");
    return false;
  }
  if (email == "")
  {
    alert("Email Address is a required field");
    return false;
  }
  else
  {
  	if (!checkEmail(email))
  	{
       alert("Please enter a vaild email address inculding the @ symbol and an appropriate suffix (.com, .edu, .gov etc.).");
       return false;
  	}
  }	
  if (pass1 == "")
  {
    alert("Password is a required field");
    return false;
  } 
  //else
  //{
  //  if(pass1.length < <%=APPLICATION("PasswordBottom")%> || pass1.length > <%=APPLICATION("PasswordTop")%>)
  //  {
      //alert('Please provide a password that is at least <%=APPLICATION("PasswordBottom")%> characters and no more than <%=APPLICATION("PasswordTop")%>');
      //return false;
  //  }
  //} 
  if (pass2 == "")
  {
    alert("Verification password is a required field");
    return false;
  }
  if (pass1 != pass2)
  {
    alert("Password and verification password do not match.  Please re-type and try again.");
    return false;
  }
  return true;
}


function fillIn(checkValue)
{
  var check = document.Hyper_Form.sameShip.checked;
  if (check == true)
  {
    document.Hyper_Form.shipAddress.value = document.Hyper_Form.Address.value;
    document.Hyper_Form.shipAddress2.value = document.Hyper_Form.Address2.value;
    document.Hyper_Form.shipCity.value = document.Hyper_Form.City.value;
    document.Hyper_Form.shipZip.value = document.Hyper_Form.Zip.value;
    document.Hyper_Form.shipPhone.value = document.Hyper_Form.phone.value;
    document.Hyper_Form.shipFname.focus();
    document.Hyper_Form.shipState.selectedIndex = document.Hyper_Form.State.selectedIndex;
    document.Hyper_Form.Shipping_Country.selectedIndex = document.Hyper_Form.Country.selectedIndex;
  }
  else
  {
    document.Hyper_Form.shipAddress.value = "";
    document.Hyper_Form.shipAddress2.value = "";
    document.Hyper_Form.shipZip.value = "";
    document.Hyper_Form.shipPhone.value = "";
    document.Hyper_Form.shipCity.value = "";
    document.Hyper_Form.shipState.selectedIndex = 1;
    document.Hyper_Form.Shipping_Country.selectedIndex = 221;
  }  
}

function matchFieldSelect (field, select, value)
{
  var property = value ? 'value' : 'text';
  var found = false;
  var crap;
  for (var i = 0; i < select.options.length; i++)
  {
    if ((found = select.options[i][property].indexOf(field.value.toUpperCase()) == 0))
    break;
  }
  if (found)
  {
    select.selectedIndex = i;
  }
  else
  {
    select.selectedIndex = -1;
  }
  
  if (field.createTextRange)
  {
    var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;"
    if (cursorKeys.indexOf(event.keyCode+";") == -1)
    {
      var r1 = field.createTextRange()
      var oldValue = r1.text;
      var newValue = found ? select.options[i][property] : oldValue;
      if (newValue != field.value)
      {
        field.value = newValue
        var rNew = field.createTextRange()
        rNew.moveStart('character', oldValue.length)
        rNew.select()
      }
    }
  }
}
