function changeService() {
 var obj = document.forms[0];
 if (!obj) {
  alert('cannot locate form');
  return false;
 }

 obj.step.value = 2;
 obj.submit();
}

var markedAction = "";
function markAction(newValue) {
 markedAction = newValue;
}

function fixAction() {
 var obj = document.forms[0];
 if (!obj) {
  alert('cannot locate form');
  return false;
 }

 if (markedAction == '') {
  markedAction = 'basic';
 }

 obj.rtype.value = markedAction;

 var strReturn = "";

 var strHref = obj.action;
 var strNewHref = "";
 if ( strHref.indexOf("?") > -1 ){
  var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
  strNewHref = strHref.substr(0, strHref.indexOf("?"));

  var aQueryString = strQueryString.split("&");
  for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
   if (aQueryString[iParam].indexOf("type" + "=") > -1 ){
    var aParam = aQueryString[iParam].split("=");
    strNewHref += aParam[0];
    strNewHref += "=";
    strNewHref += markedAction;
   } else {
    strNewHref += aQueryString[iParam];
    strNewHref += "&";
   }
  }
 }

 obj.action = strNewHref;

 return true;
}


function validateForm()
{
 var form = document.forms["Contact"];
 if (form) {
  var nameErr = "Please enter your name";
  var companyErr = "Please enter your company name";
  var emailErr = "Please supply an email address";
  var phoneErr = "Please supply a phone number";
 
  if (form.Name)
  {
   if (form.Name.value == "")
   {
    alert(nameErr);
    return false;
   }
  }
  if (form.Company)
  {
   if (form.Company.value == "")
   {
    alert(companyErr);
    return false;
   }
  }
  if (form.PhoneNumber)
  {
   if (form.PhoneNumber.value == "")
   {
    alert(phoneErr);
    return false;
   }
  }
  if (form.Email)
  {
   if (form.Email.value == "" || !check_email('emailaddress', true))
   {
    alert(emailErr);
    return false;
   }
  }

 }
 else
 {
  // No form has been found
 }
}

function check_email(id, inline)
{
 var obj = document.getElementById(id);
 if (!obj) { /* console.debug('id cannot be found');*/ return false; }
 var input = obj.value;
 if (input && window.RegExp)
 {
  var no_ws_ctl = "[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]";
  var alpha = "[\\x41-\\x5a\\x61-\\x7a]";
  var digit = "[\\x30-\\x39]";
  var cr = "\\x0d";
  var lf = "\\x0a";
  var crlf = "(" + cr + lf + ")";

  var obs_char = "[\\x00-\\x09\\x0b\\x0c\\x0e-\\x7f]";
  var obs_text = "("+lf+"*"+cr+"*("+obs_char+lf+"*"+cr+"*)*)";
  var text = "([\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f]|"+obs_text+")";
  var obs_qp = "(\\x5c[\\x00-\\x7f])";
  var quoted_pair = "(\\x5c"+text+"|"+obs_qp+")";

  var wsp = "[\\x20\\x09]";
  var obs_fws = "("+wsp+"+("+crlf+wsp+"+)*)";
  var fws = "((("+wsp+"*"+crlf+")?"+wsp+"+)|"+obs_fws+")";
  var ctext = "("+no_ws_ctl+"|[\\x21-\\x27\\x2A-\\x5b\\x5d-\\x7e])";
  var ccontent = "("+ctext+"|"+quoted_pair+")";
  var comment = "(\\x28("+fws+"?"+ccontent+")*"+fws+"?\\x29)";
  var cfws = "(("+fws+"?"+comment+")*("+fws+"?"+comment+"|"+fws+"))";
  var cfws = fws+"*";

  var atext = "("+alpha+"|"+digit+"|[\\x21\\x23-\\x27\\x2a\\x2b\\x2d\\x2e\\x3d\\x3f\\x5e\\x5f\\x60\\x7b-\\x7e])";
  var atom = "("+cfws+"?"+atext+"+"+cfws+"?)";

  var qtext = "("+no_ws_ctl+"|[\\x21\\x23-\\x5b\\x5d-\\x7e])";
  var qcontent = "("+qtext+"|"+quoted_pair+")";
  var quoted_string = "("+cfws+"?\\x22("+fws+"?"+qcontent+")*"+fws+"?\\x22"+cfws+"?)";
  var word = "("+atom+"|"+quoted_string+")";

  var obs_local_part = "("+word+"(\\x2e"+word+")*)";
  var obs_domain = "("+atom+"(\\x2e"+atom+")*)";

  var dot_atom_text = "("+atext+"+(\\x2e"+atext+"+)*)";
  var dot_atom = "("+cfws+"?"+dot_atom_text+cfws+"?)";

  var dtext = "("+no_ws_ctl+"|[\\x21-\\x5a\\x5e-\\x7e])";
  var dcontent = "("+dtext+"|"+quoted_pair+")";
  var domain_literal = "("+cfws+"?\\x5b("+fws+"?"+dcontent+")*"+fws+"?\\x5d"+cfws+"?)";

  var local_part = "("+dot_atom+"|"+quoted_string+"|"+obs_local_part+")";
  var domain = "("+dot_atom+"|"+domain_literal+"|"+obs_domain+")";
  var addr_spec = "("+local_part+"\\x40"+domain+")";

  var reg1 = inline ? new RegExp(addr_spec, 'i') : new RegExp('^'+addr_spec+'$', 'i');
  return reg1.test(input) ? true : false;
 }
 return false;
}

function popup(w,h,ref,title) {
 nw=window.open(ref,title,"scrollbars=1,top=130,left=170,width="+w+",height="+h);
 nw.focus;
}


function noEnter(e){
 var characterCode
 if(e && e.which) {
  e = e
  characterCode = e.which
 }
 else {
  e = event
  characterCode = e.keyCode
 }

 if(characterCode == 13) {
  return false
 }
 else{
  return true
 }
}

/* Function that determines whether a credit card number is valid
   Please note that a valid credit card number is not essentially a
   credit card in good standing. */
function isValidCreditCard(number) {
 var total = 0;
 var flag = 0;
 for (var i=(number.length - 1);i>=0; i--) {
  if (flag == 1) {
   var digits = number.charAt(i) * 2;
   if (digits > 9) digits -= 9;
   total += digits;
   flag = 0;
  } else {
   total = total + parseInt(number.charAt(i));
   flag = 1;
  }
 }
 if ((total%10) == 0) {
  return true;
 } else {
  return false;
 }
}

 function validateCC()
 {
  var obj = document.getElementById('creditCard');
  var invalid = false;
  if (obj.value == "") {
   invalid = true;
  }

  if(false == isValidCreditCard(obj.value)) {
   invalid = true;
  }
  
  if (invalid) {
   alert("You must provide a valid credit card number");
   return false;
  }

  var objNameonCard = document.getElementById('nameonCard');
  if (objNameonCard.value == '') {
   alert("You must provide the name of the bearer of the credit card");
   return false;
  }

  return true;
 }

function splitOptions(splittingString, selectedOption) {
    var arrayString = splittingString.split("~");
    var arrayLength = arrayString.length;
    if (arrayString[arrayLength - 1] == "") {
        arrayLength--;
    }
    var i = 0;
    while (i < arrayLength) {
        document.write("<option value=\"" + arrayString[i] + "\"" + (selectedOption == arrayString[i] ? " selected" : "") + ">" + arrayString[i + 1]);
        i = i + 2;
    }
}


