//Detect IE5.5+
ieversion = 0;
if (navigator.appVersion.indexOf("MSIE")!= -1) {
    temp=navigator.appVersion.split("MSIE");
    ieversion = parseFloat(temp[1]);
}

function ajax(){
  var r;
  brow=navigator.userAgent.toLowerCase();
  if(brow.indexOf('opera')!= -1){
    r = new XMLHttpRequest();  
  }else if(document.all){
    r = new ActiveXObject("Microsoft.XMLHTTP");
  }else{
    r = new XMLHttpRequest();  
  }
  return r;
}
function loadajax(file){
  var req = new ajax();
  if (req) {
    req.onreadystatechange=function() {
      if (req.readyState==4){
        return false;
      }
    };
    req.open('GET',file);
    req.send(null);
    return true;
  }
}

/* Dynamically include CSS and JS files */
function include_once(script_filename, script_id, randomise) {
  // Inject javascript or css unless one exists with the same id attribute
  var head = document.getElementsByTagName('head').item(0);
  for(var i=0; i<head.childNodes.length; i++) {
    var n = head.childNodes[i];
    var nType = n.nodeName.toLowerCase();
    if ((nType == 'script' || nType == 'link') && script_id != '' && (n.id == script_id)) {
      // duplication
      return;
    }
  }
  
  include_dom(script_filename, script_id, randomise);
}

function include_dom(script_filename, script_id, randomise) {
  // inject a js or css file into the current DOM
  var t = script_filename.substring(script_filename.lastIndexOf('.')+1);
  if (randomise) {
    if (script_filename.lastIndexOf('?') == -1) {
      script_filename += '?rand='+Math.random();
    }
    else {
      script_filename += '&rand='+Math.random();
    }
  }
  var head = document.getElementsByTagName('head').item(0);
  if (t == 'css'){
    // this is a CSS file
    var file = document.createElement('link');
    file.rel = 'stylesheet';
    file.type = 'text/css';
    file.media = 'all';
    if (script_id != "") {
      file.id = script_id;
    }
    file.href = script_filename;
  }
  else {
    // here for file that end in .js, or anything else that we want to execute
    // within a script tags
    var file = document.createElement('script');
    file.language = 'javascript';
    file.type = 'text/javascript';
    if (script_id != '') {
      file.id = script_id;
    }
    file.src = script_filename;
  }
  head.appendChild(file);
  return false;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   
   if (sText.length<6) {
       alert("Sorry, the postal code entered is invalid");
       return false;
   }
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         alert("Sorry, the postal code entered is invalid");
         return false;
      }
   }
   return true;
   
}

function IsNumericCode(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   
   if (sText.length<6) {
       alert("Sorry, the code entered is invalid");
       return false;
   }
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         alert("Sorry, the code entered is invalid");
         return false;
      }
   }
   return true;
   
}

function hasAcceptTerms() {
    canSubmit = false;
    if ($('terms').checked) {
        canSubmit = true;
    } else {
        alert("You have to accept the terms and conditions to submit.");
        canSubmit = false;
    }

    if (canSubmit && $('signup_status') != null) {
        if ($('signup_status').value == "") {
            alert("You have to Accept or Reject the Free First-time installation.");
            canSubmit = false;
        }
        else if ($('signup_status').value == "REJECT") {
            canSubmit = confirm("Are you sure you want to reject the free first time installation?");
        }
    }
    return canSubmit;
}