// lazy shortcut
d=document;

//preload images for frameset subnav

if (d.images) {
sections = new Array("trailer","signup","synopsis","web");
for (x=0;x<=sections.length;x++){
var setup = sections[x]+'on = new Image();'+sections[x]+'on.src = "images/global/nav/'+sections[x]+'_on.jpg";'+sections[x]+'off = new Image();'+sections[x]+'off.src = "images/global/nav/'+sections[x]+'_off.jpg";'
eval(setup)
}
}

// simple rollover/rollout functions

function on(which){if (d.images){document[which].src = eval(which + "on.src");}}
function off(which){if (d.images){document[which].src = eval(which + "off.src");}}


// popwin function

function popwin(url,name,width,height){
var t=(screen.height-height)/2;
var l=(screen.width-width)/2;
window.open(url,name,'width='+width+',height='+height+',top='+t+',left='+l+',location=0,status=0,scrollbars=0,toolbar=0,resizeable=no,noresize');
}

// popscroll function - adds a scrollbar

function popscroll(url,name,width,height){
var t=(screen.height-height)/2;
var l=(screen.width-width)/2;
window.open(url,name,'width='+width+',height='+height+',top='+t+',left='+l+',location=0,status=0,scrollbars=1,toolbar=0,resizeable=no,noresize');
}

// the actual things being opened making use of the above two functions

function popsignup(){
var failtest = GetCookie('notoldenough');
if (failtest==null){
popwin ('signup.html','signup',351,635);
}else{
popwin ('signuptooyoung.html','signuptooyoung',351,375);
}
}

function popsignupthankyou(){
popwin ('signupthankyou.html','signupthankyou',351,408)
}

function popsignuptooyoung(){
popwin ('signuptooyoung.html','signuptooyoung',351,375)
}

function popsynopsis(){
popwin ('synopsis.html','synopsis',385,362)
}

function popterms(){
popscroll ('terms.html','terms',385,362)
}

function popprivacy(){
popscroll ('privacy.html','privacy',385,362)
}

function popsite(){
popwin ('sniffer.html','site',750,590)
}

// cookie script

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

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 DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}



// email format checker for signup page

function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}
function checkemailsignup(which){
  if (which.email.value == ""){
    alert("Please enter a value for the \"email\" field.");
    which.email.focus();
    return (false);
  }
  if (!isEmailAddr(which.email.value)){
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    which.email.focus();
    return (false);
  }   
  if (which.email.value.length < 3){
    alert("Please enter at least 3 characters in the \"email\" field.");
    which.email.focus();
    return (false);
  }  
  if (which.age_group.value=="0"){
  alert("You must select an age group");
  which.age_group.focus();
  return (false);
  }
  if ((which.age_group.value=="1")||(which.age_group.value=="2")){
  SetCookie ('notoldenough', 'that_be_true', exp);
  popsignuptooyoung();
  self.close();
  return (false);    
  }
  return (true);
}
