/*
 * Querystring functionality
*/
//
// Define querystring function
function QueryString(key) {
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
		if (QueryString.keys[i]==key) {
			value = QueryString.values[i];
			break;
		}
	return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();
//
// Parse querystring for keys and values
function QueryString_Parse() {
	var query = unescape(window.location.search.substring(1) );
	var pairs = query.split("&");
	for (var i=0;i<pairs.length;i++) {
		var pos = pairs[i].indexOf('=');
		if (pos >= 0) {
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}
}

//

function gateCheck(theForm, ageGate){

	ageGateFailMsg = "You must be over the age of 17 to enter this website.\nThis site may contain material which may be unsuitable for you.";
	ageGateFailURL = "underage.html";
	ageGateOKURL = "main.html?cid=" . cid;

	// check if user has hit Submit already
	if (submitClicked == 1){
		alert('Please only click Submit once.');
		return false;
	}

	// check if their month/date combo is acceptable
	var daysInMonth = new Array(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	selectedMonth = theForm.Birth_Month[theForm.Birth_Month.selectedIndex].value;
	selectedDay = theForm.Birth_Day[theForm.Birth_Day.selectedIndex].value;
	selectedYear = theForm.Birth_Year[theForm.Birth_Year.selectedIndex].value;
	if ((selectedMonth != "MM") && (selectedDay != "DD")){
		if ((selectedDay > daysInMonth[selectedMonth]) || ((selectedMonth == 2) && (selectedDay == 29) && (selectedYear % 4 != 0))){
			alert("The birthdate you provided is not valid.\nPlease enter your birthdate and try submitting again.");
			return false;
		}
	}

	var ageCookie = 0;
	var sysDate = new Date(); 
	sysDate.setYear(sysDate.getFullYear() - ageGate);
	var age = true;

	if (ageCookie != 1){
		if ( (theForm.Birth_Month[theForm.Birth_Month.selectedIndex].value == "") || (theForm.Birth_Day[theForm.Birth_Day.selectedIndex].value == "") || (theForm.Birth_Year[theForm.Birth_Year.selectedIndex].value == "" ) ) { 
			alert("Please enter your birth date."); 
			return false;
		}
		if (age == true){ 
			submittedDate = new Date();
			submittedDate.setDate( theForm.Birth_Day[theForm.Birth_Day.selectedIndex].value ); 
			submittedDate.setMonth( theForm.Birth_Month[theForm.Birth_Month.selectedIndex].value - 1 ); 
			submittedDate.setYear( theForm.Birth_Year[theForm.Birth_Year.selectedIndex].value ); 

			var today = new Date(); 
			var expireTimeOnFail = new Date(today.getTime() + 30 * 60 * 1000 ); // plus 30 min
			var expireTimeOnPass = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000 ); // plus 24 hrs
			if (sysDate.valueOf() < submittedDate.valueOf()) {
				document.cookie = "ageGate=fail;expires=" + expireTimeOnFail.toGMTString() + ";" 
				age=false; 
				window.location=ageGateFailURL;
				return false; 
			} else { 
				document.cookie = "ageGate=pass;expires=" + expireTimeOnPass.toGMTString() + ";" 
				submitClicked = 1;		//stop user from submitting 2x 
				window.location=ageGateOKURL;
				return true; 
			} 
		} else { 
			alert(ageGateFailMsg);
			return false; 
		}
	} else {
		return false;
	}
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/*
 * Querystring functionality
*/
//
// Define querystring function

function params(qp) { 
	try{r=unescape(location.search.match(new RegExp(qp+"=+([^&]*)"))[1]);}
	catch(e){r='';} 
	return r; 
}


/*
 * Video Embedding functionality
*/
//
// Embed Quicktime
function embedQuicktime(movieAddress, width, height) {
	height += 16; //remember to add 16 vertical pixels for the nav bar
	document.write('<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="'+width+'" HEIGHT="'+height+'" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0">');
	document.write('<PARAM NAME="controller" VALUE="TRUE">');
	document.write('<PARAM NAME="type" VALUE="video/quicktime">');
	document.write('<PARAM NAME="autoplay" VALUE="true">');
	document.write('<PARAM NAME="target" VALUE="myself">');
	document.write('<PARAM NAME="src" VALUE="'+movieAddress+'">');
	document.write('<PARAM NAME="pluginspage" VALUE="http://www.apple.com/quicktime/download/indext.html">');
	document.write('<EMBED WIDTH="'+width+'" HEIGHT="'+height+'" CONTROLLER="TRUE" TARGET="myself" SRC="'+movieAddress+'" type="video/quicktime" BGCOLOR="#000000" BORDER="0" PLUGINSPAGE="http://www.apple.com/quicktime/download/indext.html"></EMBED>');
	document.write('</OBJECT>');
}
//
// Embeed Windows Media
function embedWindowsMedia(movieAddress, width, height) {
	height += 46;  //remember to add 46 vertical pixels for the nav bar
	document.write('<OBJECT ID="MediaPlayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"  standby="Loading Microsoft Windows Media Player components..." TYPE="application/x-oleobject" width="'+width+'" height="'+height+'"><PARAM NAME="FileName" VALUE="'+movieAddress+'" width="'+width+'" height="'+height+'"><EMBED TYPE="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows95/downloads/contents/wurecommended/s_wufeatured/mediaplayer/default.asp" SRC="'+movieAddress+'" Name=MediaPlayer ShowControls=1 ShowDisplay=0 ShowStatusBar=0 width='+width+' height='+height+' AUTOPLAY="true"></EMBED></OBJECT>');
}
/*
 * Popup functions
*/
//
function openTrailer6PopWithOptions(){
	width = 751;
	height = 534;
	newWindow = window.open('vid/video13.html','video','width=' + width + ',height=' + height + ',top=100,left=100,resize=no,scrollbars=no' + '');
	newWindow.focus();
	return;
	
}
// AIM Icon download window
function openAIM() { 	
	width = 750;
	height = 532;
	newWindow = window.open('downloads/aim/aim.html','AIM_Icons','width=' + width + ',height=' + height + ',top=100,left=100,resize=no,scrollbars=no' + '');
	newWindow.focus();
	return;
}
//
// Wallpaper download window
function openWallpaper(size, name) { 
	width = 800;
	height = 500;
	newWindow = window.open('downloads/wallpaper.html?size=' + size + '&name=' + name + '','Desktops','width=' + width + ',height=' + height + ',top=100,left=100,scrollbars=1' + '');
	newWindow.focus();
	return;
} 
//
// Screensaver download window
function openFanKit() { 
	width = 400;
	height = 200;
	newWindow = window.open('downloads/fankit/fankit.html','FanKit','width=' + width + ',height=' + height + ',top=100,left=100' + '');
	newWindow.focus();
	return;
} 
//
// Get Flash (popup)
function popWindow( theURL, winName, features ) { 
	window.open( theURL, winName, features ); 
} 
//
// Other offsite links
function getFlash() { 
	newWindow = window.open('http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;promoid=BIOW' + ',getFlash' + ',top=100,left=100' + ''); 
	newWindow.focus();
} 
/*
 * autodownload and autoclose for screensaver popup window
*/
//
// autodownload
function initiateDownload(file) {
	window.location.href = file;
}
//
// autoclose
function closeMe() {
	window.close();
}
function openClip1Pop(){
	width = 751;
	height = 534;
	newWindow = window.open('vid/video1.html','video','width=' + width + ',height=' + height + ',top=100,left=100,resize=no,scrollbars=no' + '');
	newWindow.focus();
	return;
	
}
function openClip2Pop(){
	width = 751;
	height = 534;
	newWindow = window.open('vid/video3.html','video','width=' + width + ',height=' + height + ',top=100,left=100,resize=no,scrollbars=no' + '');
	newWindow.focus();
	return;
	
}
function openClip3Pop(){
	width = 751;
	height = 534;
	newWindow = window.open('vid/video5.html','video','width=' + width + ',height=' + height + ',top=100,left=100,resize=no,scrollbars=no' + '');
	newWindow.focus();
	return;
	
}
function openClip4Pop(){
	width = 751;
	height = 534;
	newWindow = window.open('vid/video7.html','video','width=' + width + ',height=' + height + ',top=100,left=100,resize=no,scrollbars=no' + '');
	newWindow.focus();
	return;
	
}
function openClip5Pop(){
	width = 751;
	height = 534;
	newWindow = window.open('vid/video9.html','video','width=' + width + ',height=' + height + ',top=100,left=100,resize=no,scrollbars=no' + '');
	newWindow.focus();
	return;
	
}
function openClip6Pop(){
	width = 751;
	height = 534;
	newWindow = window.open('vid/video11.html','video','width=' + width + ',height=' + height + ',top=100,left=100,resize=no,scrollbars=no' + '');
	newWindow.focus();
	return;
	
}
//
function openTonySays(){
	width = 750;
	height = 532;
	newWindow = window.open('tonySays.html','video','width=' + width + ',height=' + height + ',top=100,left=100,resize=no,scrollbars=no' + '');
	newWindow.focus();
	return;
	
}
