//this is the cookie expiry by default

var expDays = 100;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

// popup needed by def - controls beforeyougo popups
var popupneeded=1;

//survey location win sizes / scrollbar
var slwidth  = 730;
var slheight = 570;
var sscroll  = 1;

//online-more-info win sizes / scrollbar
var omiwidth  = 700;
var omiheight = 500;
var omiscroll = 1;

//fax-mail-more-info win sizes / scrollbar
var fmiwidth  = 787;
var fmiheight = 600;
var fmiscroll = 1;

//this is used in the check_form : from popups, it closes itself.
closeyourself = 0;

// exitpopup with modal dialog
function leave(page,width,height,scrollbar){
  if(document.all) 
    showModalDialog(page,window,'dialogWidth=' + width + 'px;dialogHeight=' + height + 'px;status:0;help:0;scroll:' + scrollbar);
}


//radio on and off - hides/shows elements on the page
function radioOn(target) {
    obj=document.getElementById(target);
    obj.style.display='inline';
}

function radioOff(target) {
    obj=document.getElementById(target);
    obj.style.display='none';
}

/* surveyformcheck - don't send if no radio was checked!*/
function surveyformcheck () {

  // changes: no form check needed atm
  setTimeout ('self.close()',1000);
  return true;

  var cango = 0;
  frm=document.forms[0];
  if ( frm.survey_option1.checked ) {
    cango = 1;
  } else if ( frm.survey_option2.checked ) { 
     if ( ! frm.o21.checked && ! frm.o22.checked && !frm.o23.checked && !frm.o24.checked && !frm.o25.checked && !frm.o26.checked && !frm.o28.checked && !frm.o29.checked && !frm.o30.checked && !frm.o99.checked) {
      alert ('Please select one from the list of search engines!');
      return false;
    } else 
     cango = 1;
  } else if ( frm.survey_option3.checked ) {
    if ( !frm.option3.value ) {
      alert ('Please enter the website address!');
      return false;
    } else 
      cango = 1;
  } else if ( frm.survey_option4.checked ) {
    if ( !frm.option4.value ) {
      alert ('Please tell us in the box, how did you find out about us!');
      return false;
    } else
 	    cango = 1;
  } else {
    alert ('Oops...You must have forgotten to select an option!\nNo problem, click on the option you want first, and THEN send it.');
    return false;
  }
  if (cango) {
    setTimeout ('self.close()',500);
    return true;
  }
}

/* deselecting other radios */
function RadioDesel () {
  frm=document.forms[0];
  frm.cc1.checked=false;
  frm.cc2.checked=false;
  frm.cc3.checked=false;
  frm.cc4.checked=false;
  frm.cc5.checked=false;
  frm.cc6.checked=false;
}

/* admin form checque details show/hide */
function ShowChqDetails () {
  document.getElementById("chk").style.display = 'block';
}
function HideChqDetails () {
  document.getElementById("chk").style.display = 'none';
}


function OnunloadPopup () {
    if (!popupneeded)

      return true;
    var wName = 'popupou';
    var wWidth = 787;
    var wHeight = 410;
    var wURL = "beforeyougo.html";
    var wOptions = "left=0,top=0,height=" + wHeight + ",width=" + wWidth +",scrollbars=1,status=1,menubar=1,toolbar=1,location=1,resizable=1"; 
    var iHandle = window.open(wURL,wName,wOptions);
}

function popupsecure() {
    var wName = 'posecure';
    var wWidth = 475;
    var wHeight = 430;
    //var wURL = 'secure-information.html';
    var wURL = 'secure-information.html';
    var wOptions = "titlebar=0,left=0,top=0,height=" + wHeight + ",width=" + wWidth +",scrollbars=0,status=0,menubar=0,toolbar=0,location=0,resizable=0"; 
    var iHandle = window.open(wURL,wName,wOptions);
}

function popup(wURL,wWidth,wHeight) {
    var wName = 'popup';
    //var wWidth = 475;
    //var wHeight = 410;
    var wOptions = "left=100,top=50,height=" + wHeight + ",width=" + wWidth +",scrollbars=1,status=0,menubar=0,toolbar=0,location=0,resizable=1"; 
    window.open(wURL,wName,wOptions);
}

function check_form () {
  
  frm=document.forms[0];
  if (!frm.first_name.value) {
    alert ("Please include your first name");
    frm.first_name.focus();
    return false;
  } else if (!frm.last_name.value) {
    alert ("Please include your last name");
    frm.last_name.focus();
    return false;
  } else if (!frm.email.value) {
    alert ("Please include your email address");
    frm.email.focus();
    return false;
  } else if ( !em_chk(frm.email.value) ) {
    alert ("Please check your email address");
    frm.email.focus();
    return false;
  } else if ( !frm.country.selectedIndex ) {
    alert ("To help provide you with specific Internet Marketing Secrets & Tips\nrelated to your *Geographical Location*, please select the Country you reside in \nfrom the pulldown menu provided.");
    frm.country.focus();
    return false;
  }
  
  
  popupneeded=0;
  if (closeyourself) {self.close();}
  return true;
}

function checkContactForm () {
  frm=document.forms[0];
  if (!frm.first_name.value) {
    alert ("Please include your first name");
    frm.first_name.focus();
    return false;
  } else if (!frm.last_name.value) {
    alert ("Please include your last name");
    frm.last_name.focus();
    return false;
  } else if (!frm.email.value) {
    alert ("Please include your email address");
    frm.email.focus();
    return false;
  } else if ( !em_chk(frm.email.value) ) {
    alert ("Please check your email address");
    frm.email.focus();
    return false;
  } else if (!frm.comments.value) {
    alert ("Please include a comment or question before sending");
    frm.comments.focus();
    return false;
  }
  //country select
  if ( !frm.country.selectedIndex ) {
    alert ("Please select your country");
    frm.country.focus();
    return false;
  }
  
  //phone contact check
  /*
  if ( !frm.contactmethod[0].checked ) {
    if ( frm.contactmethod[1].checked ) {
      if ( !frm.preferrednum.value ) {
        alert ("Please enter your preferred contact number");
        frm.preferrednum.focus();
        return false;
      }
      if ( !frm.contacttime[0].checked && !frm.contacttime[1].checked && !frm.contacttime[2].checked ) {
        alert ("Please select a suitable time to call you");
        return false;
      }
    } else {
      alert ("Please select your preferred contact method");
      return false;
    }
  }
  */
  popupneeded=0;
  return true;
}

function check_referral_form() {
  frm=document.forms[0]
  
  // ********  the person  *********
  if ( ! frm.firstname.value ) {
    alert('Please include your first name');
    frm.first_name.focus()
    return false;
  } else if ( ! frm.lastname.value ) {
    alert('Please include your last name');
    frm.last_name.focus()
    return false;
  } else if ( ! frm.email.value || ! em_chk(frm.email.value) ) {
    alert('Please check your email address');
    frm.email.focus()
    return false;
  } else if ( ! frm.f1_firstname.value ) { // ******  f1  ***********
    alert('Please include the first name of the 1st referred person');
    frm.f1_firstname.focus()
    return false;
  } else if ( ! frm.f1_lastname.value ) {
    alert('Please include the last name of the 1st referred person');
    frm.f1_lastname.focus()
    return false;
  } else if ( frm.f1_email.value && !em_chk(frm.f1_email.value) ) {
    alert('Please check the email address of the 1st referred person');
    frm.f1_email.focus()
    return false;
  } else if ( frm.f2_email.value && !em_chk(frm.f2_email.value) ) { // ******  f2  ***********
    alert('Please check the email address of the 2nd referred person');
    frm.f2_email.focus()
    return false;
  } else if ( ! frm.confirmation.checked  ) {
    alert ('Please tick the box "I confirm I know the above people" to indicate you truly know the people being referred');
    return false;
  } else if ( frm.email.value == frm.f1_email.value || frm.email.value == frm.f2_email.value ) {
    alert ('The referring person cannot be the same as the REFERRED person. \nPlease make sure the name and email address of the people being referred are not the same as yours.');
    return false;
  } else if ( frm.f2_email.value && (frm.f2_email.value == frm.f1_email.value) ) {
    alert ('It seems the email addresses of the referred people are the same. Please change one of the email addresses and try again!');
    return false;
  } else {
    showPopup=false; 
    frm.submit();
    return true;
  }
}   

var warned = false;
function Secure_form_validate(data) {
  var err = false;
  if ( !data.name.value ) { 
    alert('Please fill in your First Name.'); data.name.focus();
  } else if (data.surname.value=='') {
    alert('Please fill in your Last Name.');data.surname.focus();
  }  else if ( (!warned) && (data.email.value=='') ) {
    err= true; data.email.focus();
  } else if ( data.email.value && !em_chk(data.email.value)) {
    if ( !warned ) {
      err=true; data.email.focus();
    } else {
      alert ('Please check your email address');data.email.focus()
    }
  } else if (data.email.value!=data.email_confirm.value) {
    alert('It seems that the \'Email Address\' field and the \'Email Address Confirmed\' field don\'t contain the same email addresses. Please check them both to ensure that your email address is correct.');data.email_confirm.focus();
  } else if(data.phone.value=='' && data.mobile.value=='') {
    alert('Please provide at least one contact number - just in case we are not able to reach you by email.'); data.phone.focus();
  } else if(data.CC[0].checked==false && data.CC[1].checked==false && data.CC[2].checked==false && data.CC[3].checked==false && data.CC[4].checked==false && data.CC[5].checked==false) {
    alert('Please select your Credit Card.');
  } else if (data.CCNUM.value=='') {
    alert('Please fill in your Credit Card Number.');
  } else if(data.CCNUM.value.length<15) {
    alert('Please complete your Credit Card Number\nPlease do not include any spaces or seperators.');
      //  This has been deleted to ensure that dashes or spaces don't generate an error message unnecessarily
      //} else if (!NbChk(data.CCNUM.value)) {
      //  alert('Please do not include letters in your Credit Card Number.');
  } else if(data.month.options[data.month.selectedIndex].value=='') {
    alert('Please select a Month');
  } else if(data.year.options[data.year.selectedIndex].value=='') {
    alert('Please select a Year');
  } else {
    return true;
  }
  if ( err ) {
    alert ('Please check your email address.\n\nIt\'s important to include an email address to ensure the delivery of important information. \n\nIf however you DON\'T have an email address no problem, just leave the \'Email Address\' field empty to continue on with your registration.');
    warned = true;
  }
  return false;
}

function BeforePrinting(data) {
  if ( !data.name.value ) { 
    alert('Please fill in your First Name.'); data.name.focus();
  } else if (data.surname.value=='') {
    alert('Please fill in your Last Name.');data.surname.focus();
  }  else if (data.email.value=='') {
    alert('Please fill in your Email Address.');data.email.focus();
  } else if (!em_chk(data.email.value)) {
    alert('Please check your Email Address.'); data.email.focus();
  } else if (data.email.value!=data.email_confirm.value) {
    alert('It seems that the \"Email Address\" field and the \"Email Address Confirmed\" field don\'t contain the same email addresses. Please check them both to ensure that your email address is correct.');data.email_confirm.focus();
  } else if(data.phone.value=='' && data.mobile.value=='') {
    alert('Please provide at least one contact number - just in case we are not able to reach you by email.'); data.phone.focus();
  } else {
    self.print();
  showPopup=false;
  return true;
  }
}

function SeoReqest_form_validate(data) {
  if ( !data.name.value ) { 
    alert('Please fill in your First Name.'); data.name.focus();
  } else if (data.surname.value=='') {
    alert('Please fill in your Last Name.');data.surname.focus();
  }  else if (data.email.value=='') {
    alert('Please fill in your Email Address.');data.email.focus();
  } else if (!em_chk(data.email.value)) {
    alert('Please check your Email Address.'); data.email.focus();
  } else if (data.email.value!=data.email_confirm.value) {
    alert('It seems that the \"Email Address\" field and the \"Email Address Confirmed\" field don\'t contain the same email addresses. Please check them both to ensure that your email address is correct.');data.email_confirm.focus();
  } else if(data.phone.value=='' && data.mobile.value=='') {
    alert('Please provide at least one contact number - just in case we are not able to reach you by email.'); data.phone.focus();
  } else {
  return true;
  }
  return false;
}


function em_chk(str){
  if(!str.match(/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,6}$/i)) {
    return false;
  } else {
    return true
  }
}

function NbChk(n) {
  if ( n!='' ) {
    if ( !isNaN(n) )  {
      return true;
    } 
  } 
  return false;
}

function getCookieVal (offset) {  
  var endstr = document.cookie.indexOf (";", offset);  
  if (endstr == -1) { endstr = document.cookie.length; }
  return unescape(document.cookie.substring(offset, endstr));
}


function GetCookie (name) {  
  var arg = name + "=";  
  var alen = arg.length;  
  var clen = document.cookie.length;  
  var i = 0;  
  while (i < clen) {    
    var j = i + alen;    
    if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    
    i = document.cookie.indexOf(" ", i) + 1;    
    if (i == 0) break;   
  }  
  return null;
}



function SetCookie (name, value) {  
  var argv = SetCookie.arguments;  
  var argc = SetCookie.arguments.length;  
  var expires = (argc > 2) ? argv[2] : null;  
  var path = (argc > 3) ? argv[3] : null;  
  var domain = (argc > 4) ? argv[4] : null;  
  var secure = (argc > 5) ? argv[5] : false;  
  document.cookie = name + "=" + escape (value) + 
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
  ((path == null) ? "" : ("; path=" + path)) +  
  ((domain == null) ? "" : ("; domain=" + domain)) +    
  ((secure == true) ? "; secure" : "");
}



/** cookieForms saves form content of a page.
* use the following code to call it:
*  <body onLoad="cookieForms('open', 'form_1', 'form_2', 'form_n')" onUnLoad="cookieForms('save', 'form_1', 'form_2', 'form_n')">
* It works on text fields and dropdowns in IE 5+
* It only works on text fields in Netscape 4.5
**/
function cookieForms() {  
  var mode = cookieForms.arguments[0];
  for(f=1; f<cookieForms.arguments.length; f++) {
    formName = cookieForms.arguments[f];
    if(mode == 'open') {  
      cookieValue = GetCookie('saved_'+formName);
      if(cookieValue != null) {
        var cookieArray = cookieValue.split('#cf#');
        if(cookieArray.length == document[formName].elements.length) {
          for(i=0; i<document[formName].elements.length; i++) {
            if(cookieArray[i].substring(0,6) == 'select') { document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); }
            else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { document[formName].elements[i].checked = true; }
            else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[formName].elements[i].checked = false; }
            else { document[formName].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }
          }
        }
      }
    }
        
    if(mode == 'save') {  
      cookieValue = '';
      for(i=0; i<document[formName].elements.length; i++) {
        fieldType = document[formName].elements[i].type;
        if(fieldType == 'password') { passValue = ''; }
        else if(fieldType == 'checkbox') { passValue = 'cb'+document[formName].elements[i].checked; }
        else if(fieldType == 'radio') { passValue = 'rb'+document[formName].elements[i].checked; }
        else if(fieldType == 'select-one') { passValue = 'select'+document[formName].elements[i].options.selectedIndex; }
        else { passValue = document[formName].elements[i].value; }
        cookieValue = cookieValue + passValue + '#cf#';
      }
      cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter
      SetCookie('saved_'+formName, cookieValue, exp);    
    }  
  }
}