childwindow = 0

function emailsupport() {
  if ( childwindow != 0 )childwindow.close();
  childwindow = window.open("/autofind/emailsupport.do?type=0","Email","toolbar=no,width=440,height=475,directories=no,status=no,scrollbars=yes,resizable=no");
}

function OpenWindow(url, title, width, height, scrollbars)
{
  win1=open(url,title,"width="+width+",height="+height+",scrollbars="+scrollbars);
  if (win1.focus != null)
    win1.focus();
}


function goto(url)
{
	location.href=url;
}

function emailenquire() {
  if ( childwindow != 0 )childwindow.close();
  childwindow = window.open("/emailsupport.do?type=1","Email","toolbar=no,width=440,height=475,directories=no,status=no,scrollbars=yes,resizable=no");
}


function mouseover(p) {
  p.className = "btnh";
}
function mouseout(p) {
  p.className = "btn";
}

function login() {

  if ( document.getElementById("dealerId").value == "" )  {
    alert("Dealer ID cannot be blank");
    document.getElementById("dealerId").focus();
    return;
  }

  if ( document.getElementById("password").value == "" )  {
    alert("Password cannot be blank");
    document.getElementById("password").focus();
    return;
  }


  document.getElementById("message").value = "Checking your Details";
  setTimeout("document.LoginForm.submit()",1000);
}


function isInt(x) {

for( var i = 0; i < x.length; i++) {
  if (x.charAt(i) < '0' ) return 0;
  if (x.charAt(i) > '9' ) return 0;
}

return 1
}

function isAlphaInt(x) {

  for( var i = 0; i < x.length; i++) {
    if ( (x.charAt(i) >= '0' && x.charAt(i) <= '9' ) ||
         (x.charAt(i) >= 'a' && x.charAt(i) <= 'z' ) ||
         (x.charAt(i) >= 'A' && x.charAt(i) <= 'Z' ) )
     {}
    else return 0
  }

return 1
}

function isSpchar(x) {

  for( var i = 0; i < x.length; i++) {
    if ( (x.charAt(i) >= ' ' && x.charAt(i) <= 'z') || x.charAt(i) == "£"  )
     { if  (x.charAt(i) == "'") return 1; }
    else return 1;
  }

return 0;
}

function remcr(str) {

  if ( str.value.indexOf(String.fromCharCode(13) ) < 0 ){return;}

  cr = String.fromCharCode(13);
  var s = new String;
  s.value = "";
  sp = 0;

  for( var i = 0; i < str.value.length; i++) {
    if ( str.value.charCodeAt(i) ==  13 || str.value.charCodeAt(i) == 10 ) {
      if (!sp) s.value += " ";
      if ( str.value.charCodeAt(i) ==  13 ) sp =1; else sp = 0;
    }
    else {
      s.value += str.value.charAt(i);
    }
  }
  str.value = s.value;
  return;
}


function init() {
  document.getElementById("dealerId").focus();
}

function sendemail() {

      if ( document.getElementById("fromaddr").value.indexOf("@") < 0 )  {
        alert("Invalid Email address");
        document.all.fromaddr.focus();
        return
      }

      if ( document.getElementById("fromaddr").value.indexOf(".") < 0 )  {
        alert("Invalid Email address");
        document.all.fromaddr.focus();
        return
      }

      charmess = "Invalid characater, single quote or return in ";

      if ( isSpchar(document.getElementById("fromaddr").value)  == 1 ) {
        alert(charmess + "Your Email Address");
        document.all.fromaddr.focus();
        return;
      }

      if ( isSpchar(document.getElementById("contact").value)  == 1 ) {
        alert(charmess + "Contact name");
        document.getElementById("contact").focus();
        return;
      }

      if ( isSpchar(document.getElementById("dlrname").value)  == 1 ) {
        alert(charmess + "Dealer name");
        document.getElementById("dlrname").focus();
        return;
      }

      if ( isInt(document.getElementById("dlrsysid").value)  == 0 ) {
        alert("Your login id must be a Number \n Enter 0 if you do not have an ID")
        document.getElementById("dlrsysid").focus();
        return;
      }

      if ( isSpchar(document.getElementById("phone").value)  == 1 ) {
        alert(charmess + "Phone");
        document.getElementById("phone").focus();
        return;
      }

      if ( isSpchar(document.getElementById("subject").value)  == 1 ) {
        alert(charmess + "Subject");
        document.getElementById("subject").focus();
        return;
      }

      var support;
      remcr(document.getElementById("support"));
      support = document.getElementById("support").value;
      for (var i=1; i<5; i++)support = support.replace("'","");
      document.getElementById("support").value = support ;

      if ( isSpchar(document.getElementById("support").value)  == 1 ) {
        alert(charmess + "Support Question");
        document.getElementById("support").focus();
        return;
      }

      document.getElementById("AF_EMAILSUPPORTFORM").submit();
    }
