<!--
if(top!=self){top.location.href=location.href;}

var error_msg = "";

function searchdom(f)
{
  var errcnt = 0, errmes, errpltxt = '';
  var errarray = new Array();
  var patn = /(\.(co|org|me)\.uk|\.(com|net|org|biz|info))$/i;
  var patn1 = /^[a-zA-Z0-9-]+$/;
  var patn2 = /^.{3,}/;
  var patn3 = /(^-.*|.*-$)/;
  var wwwpatn = /^www\./;
  var tldpatn = /\..*$/;


  if(f.query.value.length == 0) {
    errarray[errcnt] = "No domain name entered.\n\n";
    errcnt++;
  }
  else {
    f.query.value = f.query.value.replace(wwwpatn,"");

    if(tldpatn.test(f.query.value) && !patn.test(f.query.value)) {
      errarray[errcnt] = "Invalid domain name extension. Valid extensions:\n\n.com, .net, .org, .biz, .info, .co.uk, .org.uk, .me.uk\n\n";
      errcnt++;
    }

    if(patn.test(f.query.value)) {
      var res = patn.exec(f.query.value);
      f.tld.value = res[0];
    }
 
    if(!errcnt) {
      var domain = f.query.value.replace(patn,"");

      if(!patn1.test(domain)) {
        errarray[errcnt] = "Domain names can only contain:\n\nnumbers (0-9)\nletters (a-z)\nhyphens (-)\n\n";
        errcnt++;
      }
      if(!patn2.test(domain)) {
        errarray[errcnt] = "Domain names cannot be less than 3 characters\n\n";
        errcnt++;
      }
      if (patn3.test(domain)) {
        errarray[errcnt] = "Domains cannot start or end with a hyphen (-)\n\n";
        errcnt++;
      }
    }
  }
  if(errcnt>0) {
    errpltxt = (errcnt>1?" errors":" error")
    errmes = 'You have ' + errcnt + errpltxt + ' in your search:\n\n';
    for(cnt = 0; cnt < errarray.length; cnt++) {
      errmes = errmes + (cnt+1) + '. ' + errarray[cnt];
    }
    alert(errmes);
    return false;
  } else {
    return true;
  }
}



// Login

function dologin(f)
{
  var username = f.user.value;
  var password = f.pass.value;
  if(username == "" || password == "") {
    alert ("You have not entered enough information");
    return false;
  } else {
    var both = username+password;
    var md5 = hex_md5(both);
    f.md5.value = md5;
    var oldlength = f.pass.value.length;
    var mask = "";
    for (i =0; i<oldlength;i++)
    {
      mask = mask+"*";
    }
    f.pass.value = mask;
    return true;
  }
}



// New registration

function newReg(f)
{
  var blank = new Array();
  var invalid = new Array();
  var cnt = 0;
  var cnt1 = 0;
  var orgpattern = /^[^:]+$/;

  // Organisation checks

  if(f.iscompany.value == "1" 
  && f.eumember.options[1].selected
  && f.vatnumber.value == "")
  {
    alert("You will need to contact us on 44 870 0116204 in order to confirm your EU member, non VAT registered status, before you can purchase any domains from us. Once you have done this, we will not charge you tax.");
  }
  if((!f.org.value) && (!f.type.options[0].selected)) {
    invalid[cnt1] = "You must enter a Company/Organisation name";
    cnt1++;
  }
  if((!f.type.options[0].selected)&&(!orgpattern.test(f.org.value))) {
    invalid[cnt1]= "Company/Organisation name invalid";
    cnt1++;
  }
  if((f.org.value) && (f.type.options[0].selected)) {

    invalid[cnt1] = "You must specify a Company/Organisation Type";
    cnt1++;
  }
  if(f.vatnumber.value != "" && !vatNumberChecker(f.vatnumber.value)) {
    invalid[cnt1] = "Vat Number";
    cnt1++;
  }


  // Check required fields are not blank

  if(isBlank(f.fname.value)) {
    blank[cnt] = "First name";
    cnt++;
  }
  if(isBlank(f.sname.value)) {
    blank[cnt] = "Surname";
    cnt++;
  }
  if(isBlank(f.add1.value)) {
    blank[cnt] = "Address";
    cnt++;
  }
  if(isBlank(f.town.value)) {
    blank[cnt] = "Town";
    cnt++;
  }
  if((f.country.options[1].selected || f.country.options[224].selected) && isBlank(f.postcode.value)) {
    blank[cnt] = "Postcode";
    cnt++;
  }
  if(f.country.options[0].selected) {
    blank[cnt] = "Country";
    cnt++;
  }
  if(isBlank(f.tel_d.value) && isBlank(f.tel_e.value) && isBlank(f.tel_m.value)) {
    blank[cnt] = "You must supply at least 1 phone number";
    cnt++;
  }
  if(isBlank(f.email.value)) {
    blank[cnt] = "E-mail address";
    cnt++;
  }
  if(f.hereabout.options[0].selected) {
    blank[cnt] = "Where did you hear about us";
    cnt++;
  }
  if(isBlank(f.username.value)) {
    blank[cnt] = "Username";
    cnt++;
  }
  if(isBlank(f.password.value)) {
    blank[cnt] = "Password";
    cnt++;
  }
  if(isBlank(f.secq.value)) {
    blank[cnt] = "Security question";
    cnt++;
  }
  if(isBlank(f.seca.value)) {
    blank[cnt] = "Security answer";
    cnt++;
  }


  // Check that the data supplied is valid

  if(f.postcode.value != ""
    && (f.country.options[1].selected || f.country.options[224].selected)
    && !checkPostcode(f.postcode.value))
  {
    invalid[cnt1] = "Postcode is invalid - Only the following formats are valid:\n\n\'LN NLL\', \'LNN NLL\', \'LLN NLL\'\n\'LLNN NLL\', \'LNL NLL\', \'LLNL NLL\'\n\'LLL NLL\'\n\nN = Number and L = Letter\n";
    cnt1++;
  }
  if((f.country.options[1].selected || f.country.options[224].selected) && !f.eumember[0].selected) {
    invalid[cnt1] = "The EU membership type must accurately reflect your situation. Currently your choice does not match the country type you have chosen, please correct this.";
    cnt1++;
  }
  if(f.tel_d.value != "" && !telephoneCheck(f.tel_d.value)) {
    invalid[cnt1] = "Daytime phone number is invalid";
    cnt1++;
  }
  if(f.tel_e.value != "" && !telephoneCheck(f.tel_e.value)) {
    invalid[cnt1] = "Evening phone number is invalid";
    cnt1++;
  }
  if(f.tel_m.value != "" && !telephoneCheck(f.tel_m.value)) {
    invalid[cnt1] = "Mobile phone number is invalid";
    cnt1++;
  }
  if(f.smsalert.checked && isBlank(f.tel_m.value)) {
    invalid[cnt1] = "You must provide a mobile number to use the SMS text alerts service";
    cnt1++;
  }
  if(f.email.value != "" && !checkEmail(f.email.value)) {
    invalid[cnt1] = "E-mail address is invalid";
    cnt1++;
  }
  if(f.username.value != "" && (f.username.value.length<5 || f.username.value.length>10)) {
    invalid[cnt1] = "The Username must be between 5 and 10 characters";
    cnt1++;
  }
  if(f.password.value != "" && (f.password.value.length<5 || f.password.value.length>10)) {
    invalid[cnt1] = "The Password must be between 5 and 10 characters";
    cnt1++;
  }
  if(f.password.value != "" && (!(f.password.value == f.rpassword.value))) {
    invalid[cnt1] = "The Passwords did not match";
    cnt1++;
  }
  if(!f.agree.checked) {
    invalid[cnt1] = "You must agree to the telivo terms and conditions";
    cnt1++;
  }



  // Build error message

  var blank_err_msg = "";
  var add_err_msg = "";

  for(cnt=0; cnt<blank.length; cnt++)
  {
    blank_err_msg = blank_err_msg + blank[cnt] + "\n";
  }

  for(cnt=0;cnt<invalid.length;cnt++)
  {
    add_err_msg = add_err_msg + invalid[cnt] + "\n";
  }

  if(blank_err_msg != "") {
    if(add_err_msg != "") {
      alert("The following fields are not filled in:\n\n" + blank_err_msg + "\nYou also have the following errors in your submission:\n\n" + add_err_msg);
      return false;
    }
    else {
      alert("The following fields are not filled in:\n\n" + blank_err_msg);
      return false;
    }
  } else if(add_err_msg != "") {
    alert("You have the following errors in your submission:\n\n" + add_err_msg);
    return false;
  } else {
    return true;
  }
}



// Account home

function hostingInfo(x)
{
  var theURL='';
  if(x==null) {
    theURL='index.cgi';
  } else {
    theURL= x;
  }
  var winName='HostingInfo';
  var features='scrollbars=yes,resizable=yes,width=380,height=360,left=0,top=0,screenX=0,screenY=0';
  if(!window.editwindow) { // window has not yet been defined
    editwindow = window.open(theURL,winName,features);
    editwindow.creator = self;
  } else { // window has been defined
    if(!editwindow.closed) { // window still open
      editwindow.location=(theURL);
      editwindow.focus();
    } else {
      editwindow = window.open(theURL,winName,features);
    }
  }
}  


function checkMenuItem(f)
{
  var choice='';

  for(i=0;i<f.menu.length;i++) {
    if(f.menu.options[i].selected){
      choice = f.menu.options[i].value;
      break;
    }
  }
  if(choice == "promote") {
    window.open("http://uk.bpath.com/telivo_api/hypersubmit/","hypersubmit");
    return false;
  } else {
    return true;
  }
}



// 90 day profile check

function checkDetails(f)
{
  var blank = new Array();
  var invalid = new Array();
  var cnt = 0;
  var cnt1 = 0;
  var orgpattern = /^[^:]+$/;


  // Check required fields are not blank

  if(isBlank(f.fname.value)) {
    blank[cnt] = "First name";
    cnt++;
  }
  if(isBlank(f.sname.value)) {
    blank[cnt] = "Surname";
    cnt++;
  }
  if(isBlank(f.add1.value)) {
    blank[cnt] = "Address";
    cnt++;
  }
  if(isBlank(f.town.value)) {
    blank[cnt] = "Town";
    cnt++;
  }
  if((f.country.options[0].selected || f.country.options[223].selected) && isBlank(f.postcode.value)) {
    blank[cnt] = "Postcode";
    cnt++;
  }
  if(isBlank(f.tel_d.value) && isBlank(f.tel_e.value) && isBlank(f.tel_m.value)) {
    blank[cnt] = "You must supply at least 1 phone number";
    cnt++;
  }
  if(isBlank(f.email.value)) {
    blank[cnt] = "E-mail address";
    cnt++;
  }
  if(isBlank(f.secq.value)) {
    blank[cnt] = "Security question";
    cnt++;
  }
  if(isBlank(f.seca.value)) {
    blank[cnt] = "Security answer";
    cnt++;
  }


  // Check that the data supplied is valid

  if(f.org.value != "" && !orgpattern.test(f.org.value)) {
    invalid[cnt1]= "Company/Organisation name invalid";
    cnt1++;
  }
  if(f.postcode.value != ""
    && (f.country.options[0].selected || f.country.options[223].selected)
    && !checkPostcode(f.postcode.value))
  {
    invalid[cnt1] = "Postcode is invalid - Only the following formats are valid:\n\n\'LN NLL\', \'LNN NLL\', \'LLN NLL\'\n\'LLNN NLL\', \'LNL NLL\', \'LLNL NLL\'\n\'LLL NLL\'\n\nN = Number and L = Letter\n";
    cnt1++;
  }
  if(f.tel_d.value != "" && !telephoneCheck(f.tel_d.value)) {
    invalid[cnt1] = "Daytime phone number is invalid";
    cnt1++;
  }
  if(f.tel_e.value != "" && !telephoneCheck(f.tel_e.value)) {
    invalid[cnt1] = "Evening phone number is invalid";
    cnt1++;
  }
  if(f.tel_m.value != "" && !telephoneCheck(f.tel_m.value)) {
    invalid[cnt1] = "Mobile phone number is invalid";
    cnt1++;
  }
  if(f.smsalert.checked && isBlank(f.tel_m.value)) {
    invalid[cnt1] = "You must provide a mobile number to use the SMS text alerts service";
    cnt1++;
  }
  if(f.email.value != "" && !checkEmail(f.email.value)) {
    invalid[cnt1] = "E-mail address is invalid";
    cnt1++;
  }


  // Build error message

  var blank_err_msg = "";
  var add_err_msg = "";

  for(cnt=0; cnt<blank.length; cnt++)
  {
    blank_err_msg = blank_err_msg + blank[cnt] + "\n";
  }

  for(cnt=0;cnt<invalid.length;cnt++)
  {
    add_err_msg = add_err_msg + invalid[cnt] + "\n";
  }

  if(blank_err_msg != "") {
    if(add_err_msg != "") {
      alert("The following fields are not filled in:\n\n" + blank_err_msg + "\nYou also have the following errors in your submission:\n\n" + add_err_msg);
      return false;
    }
    else {
      alert("The following fields are not filled in:\n\n" + blank_err_msg);
      return false;
    }
  } else if(add_err_msg != "") {
    alert("You have the following errors in your submission:\n\n" + add_err_msg);
    return false;
  } else {
    return true;
  }
}



// Update profile

function updateProfile(f)
{
  var blank = new Array();
  var invalid = new Array();
  var cnt = 0;
  var cnt1 = 0;
  var orgpattern = /^[^:]+$/;

  // Organisation checks

  if(f.iscompany.value == "1" 
  && f.eumember.options[1].selected
  && f.vatnumber.value == "")
  {
    alert("You will need to contact us on 44 870 0116204 in order to confirm your EU member, non VAT registered status, before you can purchase any domains from us. Once you have done this, we will not charge you tax.");
  }
  if((!f.org.value) && (!f.type.options[f.type.options.selectedIndex].value == "IND")) {
    invalid[cnt1] = "You must enter a Company/Organisation name";
    cnt1++;
  }
  if((!f.type.options[0].selected)&&(!orgpattern.test(f.org.value))) {
    invalid[cnt1]= "Company/Organisation name invalid";
    cnt1++;
  }
  if((f.org.value) && (f.type.options[f.type.options.selectedIndex].value == "IND")) {
    invalid[cnt1] = "You must specify a Company/Organisation Type";
    cnt1++;
  }
  if(f.vatnumber.value != "" && !vatNumberChecker(f.vatnumber.value)) {
    invalid[cnt1] = "Vat Number";
    cnt1++;
  }


  // Check required fields are not blank

  if(isBlank(f.fname.value)) {
    blank[cnt] = "First name";
    cnt++;
  }
  if(isBlank(f.sname.value)) {
    blank[cnt] = "Surname";
    cnt++;
  }
  if(isBlank(f.add1.value)) {
    blank[cnt] = "Address";
    cnt++;
  }
  if(isBlank(f.town.value)) {
    blank[cnt] = "Town";
    cnt++;
  }
  if((f.country.options[0].selected || f.country.options[223].selected) && isBlank(f.postcode.value)) {
    blank[cnt] = "Postcode";
    cnt++;
  }
  if(isBlank(f.tel_d.value) && isBlank(f.tel_e.value) && isBlank(f.tel_m.value)) {
    blank[cnt] = "You must supply at least 1 phone number";
    cnt++;
  }
  if(isBlank(f.email.value)) {
    blank[cnt] = "E-mail address";
    cnt++;
  }
  if(isBlank(f.secq.value)) {
    blank[cnt] = "Security question";
    cnt++;
  }
  if(isBlank(f.seca.value)) {
    blank[cnt] = "Security answer";
    cnt++;
  }


  // Check that the data supplied is valid

  if(f.postcode.value != ""
    && (f.country.options[0].selected || f.country.options[223].selected)
    && !checkPostcode(f.postcode.value))
  {
    invalid[cnt1] = "Postcode is invalid - Only the following formats are valid:\n\n\'LN NLL\', \'LNN NLL\', \'LLN NLL\'\n\'LLNN NLL\', \'LNL NLL\', \'LLNL NLL\'\n\'LLL NLL\'\n\nN = Number and L = Letter\n";
    cnt1++;
  }
  if((f.country.options[0].selected || f.country.options[223].selected) && !f.eumember[0].selected) {
    invalid[cnt1] = "The EU membership type must accurately reflect your situation. Currently your choice does not match the country type you have chosen, please correct this.";
    cnt1++;
  }
  if(f.tel_d.value != "" && !telephoneCheck(f.tel_d.value)) {
    invalid[cnt1] = "Daytime phone number is invalid";
    cnt1++;
  }
  if(f.tel_e.value != "" && !telephoneCheck(f.tel_e.value)) {
    invalid[cnt1] = "Evening phone number is invalid";
    cnt1++;
  }
  if(f.tel_m.value != "" && !telephoneCheck(f.tel_m.value)) {
    invalid[cnt1] = "Mobile phone number is invalid";
    cnt1++;
  }
  if(f.smsalert.checked && isBlank(f.tel_m.value)) {
    invalid[cnt1] = "You must provide a mobile number to use the SMS text alerts service";
    cnt1++;
  }
  if(f.email.value != "" && !checkEmail(f.email.value)) {
    invalid[cnt1] = "E-mail address is invalid";
    cnt1++;
  }


  // Build error message

  var blank_err_msg = "";
  var add_err_msg = "";

  for(cnt=0; cnt<blank.length; cnt++)
  {
    blank_err_msg = blank_err_msg + blank[cnt] + "\n";
  }

  for(cnt=0;cnt<invalid.length;cnt++)
  {
    add_err_msg = add_err_msg + invalid[cnt] + "\n";
  }

  if(blank_err_msg != "") {
    if(add_err_msg != "") {
      alert("The following fields are not filled in:\n\n" + blank_err_msg + "\nYou also have the following errors in your submission:\n\n" + add_err_msg);
      return false;
    }
    else {
      alert("The following fields are not filled in:\n\n" + blank_err_msg);
      return false;
    }
  } else if(add_err_msg != "") {
    alert("You have the following errors in your submission:\n\n" + add_err_msg);
    return false;
  } else {
    return true;
  }
}



// Web and email forwarding

function deleteEmailAlias()
{
  if(confirm("Are you sure you want to delete this alias?")) {
    return true;
  }
  else {
    return false;
  }
}  

function changeWebForward()
{
  if(checkURL(document.webforward.web.value)) {
    return true;
  }
  else {
    alert("Invalid web forwarding Address");
    return false;
  }
}

function addAlias(domainname)
{
  var errors = "";
  if(!checkEmail(document.addrow.alias.value + domainname)) {
    errors = errors +"Invalid Address alias\n";
  }

  if(!checkEmail(document.addrow.address.value)) {
    errors = errors + "Invalid Forward To e-mail address\n";
  }

  if(errors == "") {
    return true;
  }
  else {
    alert("The following errors were found:\n\n"+errors);
    return false;
  }
}


// DNS management

function warn(index)
{
  if(confirm("Are you sure you want to delete this record.\n\nThis may affect you domain adversly.")) {
    document.forms[index].submit();
  }
}

function changeA(index, action)
{
  var hostname = document.forms[index].name.value;
  var ip = document.forms[index].data.value;

  if(checkHost(hostname)) {
    if(checkIP(ip)) {
      if(action == "Remove") {
        if(confirm("WARNING: What you are about to do may cause your domain to behave abnormally are you sure you want to do this?")) {
          document.forms[index].action.value=action;
          document.forms[index].submit();
        }
      }
      else {
        document.forms[index].action.value=action;
        document.forms[index].submit();
      }
    }
    else {
      alert(error_msg);
    }
  }
  else {
    alert(error_msg);
  }
}

function changeCNAME(index, action)
{
  var hostname = document.forms[index].name.value;
  var actualhost = document.forms[index].data.value;

  if(checkHost(hostname)) {
    if(checkHost(actualhost)) {
      if(action=="Remove") {
        if(confirm("WARNING: What you are about to do may cause your domain to behave abnormally are you sure you want to do this?")) {
          document.forms[index].action.value=action;
          document.forms[index].submit();
        }
      }
      else {
        document.forms[index].action.value=action;
        document.forms[index].submit();
      }
    }
    else {
      alert(error_msg);
    }
  }
  else {
    alert(error_msg);
  }
}

function changeMX(index, action)
{
  var mailserver = document.forms[index].data.value;
  if(checkName(mailserver)) {
    if(action == "Remove") {
      if(confirm("WARNING: What you are about to do may cause your domain to behave abnormally are you sure you want to do this?")) {
        document.forms[index].action.value=action;
        document.forms[index].submit();
      }
    }   
    else {
      document.forms[index].action.value=action;
      document.forms[index].submit();
    }
  }
  else {
    alert(error_msg);
  }
}

function resetDNS()
{
  if(confirm("Doing this will restore ALL your DNS information to the telivo defaults. Are you sure?")) {
    document.FACTORYDEFAULT.action.value="Reset";
    document.FACTORYDEFAULT.submit();
  }
}



// Update password

function userPassAcpt(f)
{
  var newpass = f.newpass.value;
  var repass = f.repass.value;

  if (newpass == repass) {
    f.pass.value = newpass;
    f.newpass.value = "";
    f.repass.value = "";
    var md5 = hex_md5(f.oldpass.value);
    f.oldpass.value = "";
    f.md5.value = md5;
    return true;
  }
  else {
    alert ("Passwords entered do not match");
    return false;
  }
}


// Change nameservers

function changeNS()
{
  var errarray = new Array();
  var errarray1 = new Array();
  var cnt=0,cnt1=0,nscnt=0,errmes="",errmes1="";

  for(i=0;i<document.nameservers.elements.length;i++) {
    if(document.nameservers["ns" +i]!=null) {
      if(document.nameservers["ns" +i].value) {
        nscnt++;
      }
      if(document.nameservers["ns" + i +"ip"].value && !document.nameservers["ns" +i].value) {
        errarray[cnt] = "Nameserver " + i + " Hostname";
        cnt++;
      }
      if(document.nameservers["ns" +i].value && !checkName(document.nameservers["ns" +i].value)) {
        errarray1[cnt1] = "Nameserver " + i + " is invalid";
        cnt1++;
      }
      if(document.nameservers["ns" +i].value && !document.nameservers["ns" + i + "ip"].value) {
        errarray[cnt] = "Nameserver " + i + " IP address";
        cnt++;
      }
      if(document.nameservers["ns" + i +"ip"].value && !checkIP(document.nameservers["ns" + i + "ip"].value)) {
        errarray1[cnt1] = "The IP address for Nameserver " + i + " is invalid";
        cnt1++;
      }
    }
  }

  if(nscnt<2) {
    alert('You must specify at least 2 Nameservers to change to');
    return false;
  } else {
    for(cnt=0;cnt<errarray.length;cnt++)
    {
      errmes = errmes + errarray[cnt] + "\n";
    }
    for(cnt=0;cnt<errarray1.length;cnt++)
    {
      errmes1 = errmes1 + errarray1[cnt] + "\n";
    }

    if(errmes!="") {
      if(errmes1!="") {
        alert("The following fields are not filled in:\n\n" + errmes + "\nYou also have the following errors in your submission:\n\n" + errmes1);
        return false;
      } else {
        alert("The following fields are not filled in:\n\n" + errmes);
        return false;
      }
    } else if(errmes1!="") {
      alert("You have the following errors in your submission:\n\n" + errmes1);
      return false;
    } else {
      return true;
    }
  }
}


// Tag release

function changeTag()
{
  var tag = document.ips.tag.value;
  var tagchecker = /^[a-zA-Z0-9-_]{2,}$/;

  if(document.ips.tag.value=='') {
    alert("Please enter an IPS Tag");
   return false;
  }
  else if(tagchecker.test(tag)) {
    return true;
  }
  else {
    alert("IPS tag is invalid");
    return false;
  }
}





// Helpers

function isBlank(str)
{
  var pattern = /^\s+$/;
  if((str!=null) && (str!='') && (!pattern.test(str))) {
    return false;
  } else {
    return true;
  }
}


function checkPostcode(str)
{
  var post_pattern = /^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$/;
  if(!post_pattern.test(str)) {
    return false;
  } else {
    return true;
  }
}


function checkEmail(str)
{
  //var email_pattern = /^[\w-]+(\.[\w-]+)*\@([\w-]+\.)+[a-zA-Z]{2,7}$/;
  var email_pattern = /^[\w!#\$%&\'\+\-/=\?\^`\{\|\}~][\w!#\$%&\'\*\+\-/=\?\^`\{\|\}~\.]*\@[a-zA-Z\d][a-zA-Z\d\-]*\.[a-zA-Z\d][a-zA-Z\d\-]*(\.[a-zA-Z\d][a-zA-Z\d\-]*)*$/;
  if(!email_pattern.test(str)) {
    return false;
  } else {
    return true;
  }
}


function selectCountry(f, country)
{
  var len = f.country.options.length;
  for(index = 0; index < len; index++) {
    if(f.country.options[index].value == country) {
      f.country.options[index].selected = true;
      break;
    }
  }
}


function vatNumberChecker(vatnumber)
{
  vatnumber = vatnumber.replace(/\s/g,"");
  var vatpattern = /^(U\d{8}|\d{9}|\d{8}|([\dA-HJ-NP-Z]){2}\d{9}|\d{7}[a-z]|\d[a-z]\d{5}[a-z]|\d{11}|\d{9}B\d{2}|[a-z\d]\d{7}[a-z\d]|\d{10}01)$/;
  var result = vatnumber.match(vatpattern);
  if(result != null) {
    return true;
  } else {
    return false;
  } 
}

function telephoneCheck(number)
{
  var phonePattern = /^(\+\d+|\+\d+\(\d+\)|\+\(\d+\)|\(\+\d+\)){0,1}\s{0,1}([\s\d]{6,})$/;
  var result = number.match(phonePattern);
  if(result != null) {
    var localnumber = result[1];
    if(result[2] != null && result[2] != "") {
      localnumber=result[2];
    }
    var firstchar = localnumber.charAt(0);
    var secndchar = localnumber.charAt(1);
    var firstdigit = firstchar-0;
    var secnddigit = secndchar-0;
    if(firstdigit == secnddigit -1) {
      for(var index=2; index < localnumber.length;index++)
      {
        if(!(localnumber.charAt(index) - index == firstdigit)) {
          return true;
        }
      }
    }
    else {
      if(firstdigit == secnddigit +1) {
        for(var index = 2; index < localnumber.length;index++)
        {
          if(!(localnumber.charAt(index) == firstdigit - index)) {
            return true;
          }
        }
      }
      else {
        if(firstdigit == secnddigit) {
          for(var index = 2; index < localnumber.length;index++)
          {
            if(!(localnumber.charAt(index) == firstdigit)) {
              return true;
            }
          }
        }
	else {
          return true;
        }
      }
    }
  }
  else {
    return false;
  }
}


function typeofcom(f)
{
  if(f.type.options[f.type.options.selectedIndex].value == "IND") {
    f.iscompany.value="0";
  } else {
    f.iscompany.value="1";
  }
}


function getPDF(id)
{
  document.invoices.id.value=id;
  document.invoices.submit();
}


function getCreditPDF(id)
{
  document.credits.creditid.value=id;
  document.credits.submit();
}


function checkURL(url)
{
  var urlTester = /^((http|https|ftp)\:\/\/){0,1}((\d{1,3}\.){3}\d{1,3}|([A-Za-z0-9_-]+\.)+([A-Za-z]{2,7}))(\:\d+){0,1}(\/[A-Za-z0-9+-_\.~@]*){0,}(\/){0,1}(\?.*){0,1}$/;
  if(urlTester.test(url)) {
    return true;
  }
  else {
    return false;
  }
}


function checkIP(ip)
{
   var ipvalidator = new RegExp("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$","g");

  if(ipvalidator.test(ip)) {
    ipvalidator = new RegExp("^(0\.|127\.|10\.|172\.16\.|169\.254\.|192\.168\.254)","g");

    if(ipvalidator.test(ip)) {
      error_msg = "ERROR: the ip address " + ip + " is from a range that is reserved for special use, and as such is un routeable from the internet.";
      return false;
    }
    else {
      return true;
    }
  }
  else {
    error_msg = "ERROR: " + ip + " is not a valid IP address.";
    return false;
  }
}


function checkName(name)
{
  var namevalidator = new RegExp("^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$","g");

  if(namevalidator.test(name)) {
    return true;
  }
  else {
    error_msg = "ERROR: Invalid hostname";
    return false;
  }
}


function checkHost(host)
{
  var namevalidator = new RegExp("^[a-zA-Z0-9][-a-zA-Z0-9]*[a-zA-Z0-9](\.[a-zA-Z0-9][-a-zA-Z0-9]*[a-zA-Z0-9])*$","g");
  if(namevalidator.test(host)) {
    return true;
  }
  else {
    error_msg = "ERROR: Invalid hostname";
    return false;
  }
}


//-->
