var closeyourself = false;
var exitPopupNeeded = false;

// exitpopup for ie only
function leave(page,width,height,scrollbar) {
  if ( !exitPopupNeeded ) return true;
  if ( width==0 ) { //787
    width = 750;
    height = 410;
  }
  if(document.all) 
    showModalDialog(page,window,'dialogWidth=' + width + 'px;dialogHeight=' + height + 'px;status:0;help:0;scroll:' + scrollbar);
}

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

// this checks the newsletter form and alerts if smthing was not filled correctly
function check_newsletter_form(id,moveon,closeyourself){
  str = 'newsletterform' + id;
  frm=document.forms[str];
  if (!frm.firstname.value) {
    alert ("Please include your first name");
    frm.firstname.focus();
    return false;
  } else if (!frm.lastname.value) {
    alert ("Please include your last name");
    frm.lastname.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;
  }
  
  exitPopupNeeded=false;
  if (closeyourself) {self.close();}
  if (moveon) { document.location.href='main.html'; }
  return true;
}

// this checks the refer form and alerts if smthing was not filled correctly
function check_refer_form() {

  frm = document.forms[0];
  
  if (!frm.firstname.value) {
    alert ("Please include your first name");
    frm.firstname.focus();
    return false;
  } else if (!frm.lastname.value) {
    alert ("Please include your last name");
    frm.lastname.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;
  }

  // friend1
  if (!frm.f1_firstname.value) {
    alert ("Please include your friend's firstname!");
    frm.f1_firstname.focus();
    return false;
  }
  if (!frm.f1_lastname.value) {
    alert ("Please include your friend's lastname!");
    frm.f1_lastname.focus();
    return false;
  }
  if ( !frm.f1_email.value || !em_chk(frm.f1_email.value) ) {
    alert ("Please check your friend's email address");
    frm.f1_email.focus();
    return false;
  }

  // friend2
  if (!frm.f2_firstname.value) {
    alert ("Please include your friend's firstname!");
    frm.f2_firstname.focus();
    return false;
  }
  if (!frm.f2_lastname.value) {
    alert ("Please include your friend's lastname!");
    frm.f2_lastname.focus();
    return false;
  }
  if ( !frm.f2_email.value || !em_chk(frm.f2_email.value) ) {
    alert ("Please check your friend's email address");
    frm.f2_email.focus();
    return false;
  }
  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;
  }
  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. \r\nPlease make sure the name and email address of the people being referred are not the same as yours.');
    return false;
  } 
  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;
  }

  exitPopupNeeded=false;
  return true;
} 

// to open the privacy window
function oppwin ( loc ) {
  var pWidth = 500;
  var pHeight = 480;
  var xPos = (screen.width/2)-(pWidth/2);
  var yPos = (screen.height/2)-(pHeight/2);
  var ppWin = "";
  //Opera most likely in tabbed mode, so calculate from the win size instead of screen size
  if (navigator.appName=="Opera") 
  yPos = (window.innerHeight/2)-(pHeight/2);
  
  ppWin = window.open ("","ppWin","width=" + pWidth + ",height=" + pHeight + ",status=0,menubar=0,location=0,resizable=1,titlebar=0,scrollbars=1,left=" + xPos + ",top=" + yPos );
  ppWin.location.href = loc;
} 


// cookie functions
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" : "");
}

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;
  }
}

function popup(wURL,wWidth,wHeight) {
    var wName = 'popup';
    if ( !wWidth )  wWidth  = 475;
    if ( !wHeight ) 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);
}
