// lazy shortcut
d=document;



if (d.images) {

//preload images for frameset subnav
sections = new Array("register");
for (x=0;x<=sections.length;x++){
var setup = sections[x]+'on = new Image();'+sections[x]+'on.src = "images/register/'+sections[x]+'_on.gif";'+sections[x]+'off = new Image();'+sections[x]+'off.src = "images/register/'+sections[x]+'_off.gif";'
eval(setup)
}

// preload party tips nav
sections = new Array("bring_essentials","landmarks","improvise","beware_guests","whentosaywhen","keep_your_cool","pack_your_supplies","dont_be_sissy","things_could_be_worse","souvenirs","email");
for (x=0;x<=sections.length;x++){
var setup = sections[x]+'on = new Image();'+sections[x]+'on.src = "images/party_tips/nav/'+sections[x]+'_on.jpg";'+sections[x]+'off = new Image();'+sections[x]+'off.src = "images/party_tips/nav/'+sections[x]+'_off.jpg";'
eval(setup)
}

// preload maxim promo buttons
sections = new Array("maximpromo","myspace");
for (x=0;x<=sections.length;x++){
var setup = sections[x]+'on = new Image();'+sections[x]+'on.src = "images/promos/'+sections[x]+'_on.jpg";'+sections[x]+'off = new Image();'+sections[x]+'off.src = "images/promos/'+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');
}

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 ('register.html','register',490,561);
}else{
popwin ('pop.php?which=young','young',490,500);
}
}

function popterms(){
popwin ('pop.php?which=terms','terms',490,500)
}

function popprivacy(){
popwin ('pop.php?which=privacy','privacy',490,500)
}

function popscreening(){
popwin ('pop.php?which=screening','screening',490,500)
}

function popmacaim(){
popscroll ('downloads/aim_icons.html','aim',350,500);
}

function popgame(){
popwin ('pop_game.html','game',500,500);
}

function poppromo(){
popwin ('pop_promo.html','promo',500,350);
}

function popparty(){
popwin ('pop_party.php','partytips',800,620);
}

function poptickets(){
popwin ('pop_tickets.php','tickets',400,270);
}

function popcritics(){
popwin ('pop_critics.html','critics',500,550);
}

function popscreening(film_id,base_url){
popwin ('http://'+base_url+'/screenings/index.php?film_id='+film_id,'screening',490,500)
}


// popgame resizer

function checksize(){
if ((window.width!=420) || (window.height!=380)){
window.resizeTo(500,500);
}}


// 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 checkAge(form){	
	var min_age = 13;
	var month = (parseInt(form.month.options[form.month.selectedIndex].value)-1);
	var day = parseInt(form.day.options[form.day.selectedIndex].value);
	var year = parseInt(form.year.options[form.year.selectedIndex].value);	
	var user = new Date((year+min_age), month, day);
	var today = new Date();	
	if(today.getTime() - user.getTime() < 0){
		return false;
	}else {
		return true;
	}
}

function checkemailsignup(which){
var msg="";	
  if (which.namefirst.value==""){
	msg=msg+"You must enter your first name\n";
  }
  if (which.namelast.value==""){
	msg=msg+"You must enter your last name\n";
  }
  if (which.email.value == ""){
    msg=msg+"Please enter a value for the \"email\" field.\n";
  }
  if (!isEmailAddr(which.email.value)){
    msg=msg+"Please enter a complete email address in the form: yourname@yourdomain.com\n";
  }   
  if (which.email.value.length < 3){
    msg=msg+"Please enter at least 3 characters in the \"email\" field.\n";
  }  
  if (which.city.value==""){
	msg=msg+"You must enter your city\n";
  }
  if (which.state.value=="0"){
	msg=msg+"You must select a state\n";
  }  
  if (which.month.value=="0"){
	msg=msg+"You must select a birth month\n";
  }
  if (which.day.value=="0"){
	msg=msg+"You must select a birth day\n";
  }
  if (which.year.value=="0"){
	msg=msg+"You must select a birth year\n";
  }
  if (which.gender.value=="0"){
	msg=msg+"You must select a gender\n";
  }  
  //if (which.inforeq.checked==false){
	//msg=msg+"You must agree to the TERMS AND CONDITIONS and PRIVACY POLICY\n";
  //}   
  if (msg!=""){  
		alert("the following errors were detected:\n\n" + msg + "\nPlease fix them to proceed.");
		return (false);		
  }else if(!checkAge(which)){  
		SetCookie ('notoldenough', 'that_be_true', exp);
		popsignup();
		self.close();
		return (false); 		
  }else{    
 	 	return (true);		
  }  
}


function checksendfriend(which){
var msg="";	
  if (which.sender_name.value==""){
	msg=msg+"You must enter your name\n";
  }
  if (which.sender_email.value == ""){
    msg=msg+"Please enter a value for your email address.\n";
  }
  if (!isEmailAddr(which.sender_email.value)){
    msg=msg+"Please enter your email address in the form: yourname@yourdomain.com\n";
  }   
  if (which.sender_email.value.length < 3){
    msg=msg+"Please enter at least 3 characters for your email address.\n";
  }  
  if (which.recipient_name.value==""){
	msg=msg+"You must enter your friend's name\n";
  }
  if (which.recipient_email.value == ""){
    msg=msg+"Please enter a value for your friend's email address.\n";
  }
  if (!isEmailAddr(which.recipient_email.value)){
    msg=msg+"Please enter your friend's email address in the form: yourname@yourdomain.com\n";
  }   
  if (which.recipient_email.value.length < 3){
    msg=msg+"Please enter at least 3 characters for your friend's email address.\n";
  }   
  if (msg!=""){  
		alert("the following errors were detected:\n\n" + msg + "\nPlease fix them to proceed.");
		return (false);		
  }else{    
 	 	return (true);		
  }  
}