/*
	  Copyright (c) 2002 Moonstone Interactive, Inc.
      All Rights Reserved. No portion of this file, including but
      not limited to any associated code, documents or images, may be
      copied, retransmitted, reposted, duplicated or otherwise
      used without the express written permission of Moonstone Interactive, Inc.

*/	

//This file: site-wide Javascript

/* 
** -----------------------------------------------------------------------------------------
** Dynamically source out styles depending on platform. 
*/

//the following requires browsersniff.js
if (is_nav){
	document.write('<link rel=stylesheet type="text/css" href="styles/free_movie_download_ns_2.css">');
} else {
	document.write('<link rel=stylesheet type="text/css" href="styles/free_movie_download_2.css">');	
}

/* 
** -----------------------------------------------------------------------------------------
** Build the Dynamic date line and the date field for the ecard form. 
*/

today = new Date();

dayarray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
montharray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

day = today.getDay();
date = today.getDate();
month = today.getMonth();
year = today.getFullYear();

datefieldtag = "<input type=\"hidden\" name=\"sent_date\" value=\"" + dayarray[day] + " " + montharray[month] + " " + date + "\">";

dateline = "<font class=\"body\"><font class=\"bodyboldblack\">" + dayarray[day] + "</font>" + ", " + montharray[month] + " " + date + "</font>";   


/* 
** -----------------------------------------------------------------------------------------
** Build the header tag - Flash or HTML depending. 
*/

//First - pick a random movie (or gif) number for header
//there are current 6 movies or gifs to choose from
movie_number = Math.ceil(Math.random() * 6);

//next check for flash - requires flascheck.js (note: flashcheck.js requires write_vbscript.js
if ((is_win && (is_ie4up || is_nav4up)) || (is_mac && is_nav4up) || (is_mac && is_ie5)){
//these are the only platforms on which we can reliably sniff Flash

	if (which_version_flash() >= 4){
		//has required version of Flash
		//build Flash header tag
		header_tag = "<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0\" ID=header_movie WIDTH=705 HEIGHT=110> <PARAM NAME=movie VALUE=\"flash_headers/sfd_home_mov_" + movie_number + ".swf\"> <PARAM NAME=quality VALUE=high> <PARAM NAME=scale VALUE=noborder> <PARAM NAME=bgcolor VALUE=#000000> <EMBED src=\"flash_headers/sfd_home_mov_" + movie_number + ".swf\" quality=high scale=noborder bgcolor=#FFFFFF  WIDTH=705 HEIGHT=110 TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED></OBJECT>";
		
	} else {
		//does not have required flash version 
		//give them an HTML header
		//header_tag = "<img src=\"flash_headers/sfd_home_mov_" + movie_number + ".gif\" alt=\"\" border=\"0\" width=\"705\" height=\"110\">";
		header_tag = "<img src=\"flash_headers/sfd_static_header.gif\" alt=\"\" border=\"0\" width=\"705\" height=\"110\">";
	}
} else {
	//possibly unsniffable platform - cannot determine if they have flash 
	//give them an HTML header
	//header_tag = "<img src=\"flash_headers/sfd_home_mov_" + movie_number + ".gif\" alt=\"\" border=\"0\" width=\"705\" height=\"110\">";
	header_tag = "<img src=\"flash_headers/sfd_static_header.gif\" alt=\"\" border=\"0\" width=\"705\" height=\"110\">";
}

		
/*
** -----------------------------------------------------------------------------------------
** msi_copyright.js
** Version: 004 -- 06.22.00
*/

function include_copyright(startyear) {
	var	blob="";
	var msistartyear = 2001;
	var	today=new Date();
	var	thisyear = get_full_year(today);
	if (startyear < thisyear && startyear >= msistartyear) {
		blob += startyear + " - ";
	}
	blob += thisyear;
	blob = "Copyright &copy; " + blob + " <a href=\"http://www.msinteractive.com\" class=\"footersmall\">Moonstone Interactive</a>.";
	return blob;
}
		
function get_full_year(d) { // d is a date object
	yr = d.getYear();
	if (yr < 1000) {
	 	yr+=1900;
	}
	return yr;
}

/* 
** -----------------------------------------------------------------------------------------
** For privacy policy/terms child window
*/


function openPrivacy() {
	var openWin =
	window.open("http://www.getittoday.com/privacy_policy.html","privacy_terms","resizable=0,location=0,status=0,menubar=0,toolbar=0,scrollbars=1,width=450,height=400,left=0,top=0,screenX=0,screenY=0");
	openWin.opener = window;

	openWin.focus();
}

function openTerms() {
	var openWin =
	window.open("http://www.getittoday.com/terms_of_service.html","privacy_terms","resizable=0,location=0,status=0,menubar=0,toolbar=0,scrollbars=1,width=450,height=400,left=0,top=0,screenX=0,screenY=0");
	openWin.opener = window;

	openWin.focus();
}	

/* 
** -----------------------------------------------------------------------------------------
** Preload images (non-navbar. navbar images are loaded seperately.)
*/

function preload_images() {
	var next_image = new Image();
	
	next_image.src = "images/sfd_right_submit_on.gif";
	next_image.src = "images/sfd_right_git_onover.gif";
	next_image.src = "images/sfd_smarrow_on.gif";
	next_image.src = "images/sfd_smarrowdown_on.gif";		
}


/* 
** -----------------------------------------------------------------------------------------
** grab current URL we'll need it for redirection upon newsletter signup
*/
var current_url = document.location;
var form_url_tag = "<input type=\"hidden\" name=\"redirect\" value=\"" + current_url + "\">";


/* 
** -----------------------------------------------------------------------------------------
** Form validation code
*/

function check_form(){

	if (is_ie){
		var email = document.all.signup.email.value;
		var name = document.all.signup.name.value;
	} else {
		var email = document.signup.email.value;
		var name = document.signup.name.value;					
	}
	
	if ((check_email(email)) && (name != null) && (name != "") && (name != " ") && (name != "name")){
		//alert("everything's cool");
	
		newwin = window.open('blank.html','feedback',"height=200,width=350,scrollbars=no,location=no,toolbar=no,directories=no,menubar=no,status=no,resizable=no");
		newwin.opener = window;
		if (document.images) {  // eg if it's js 1.1 (which supports 'focus()')
			newwin.focus();
		}				
		document.signup.submit();
		if (is_ie){
			document.all.signup.email.value = "email address";
			document.all.signup.name.value = "name";
		} else {
			document.signup.email.value = "email address";
			document.signup.name.value = "name";
		}
	} else {	
		//alert("form error");
		
		newwin = window.open('try-again.html','feedback',"height=200,width=350,scrollbars=no,location=no,toolbar=no,directories=no,menubar=no,status=no,resizable=no");
		newwin.opener = window;
		if (document.images) {  // eg if it's js 1.1 (which supports 'focus()')
			newwin.focus();
		}				
	}
}

//Email field check
function check_email(emailStr) {

var checkTLD=0;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

//alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
		//alert("Email address username contains invalid characters.");
		return false;
   }
}

for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
		//alert("Email address domain name contains invalid characters.");
		return false;
   }
}

if (user.match(userPat)==null) {
	//alert("Email address username doesn't seem to be valid.");
	return false;
}


var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {


for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
		//alert("Email Destination IP address is invalid!");
		return false;
   	}
	}
	return true;
}
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
		//alert("The domain name does not seem to be valid.");
		return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	//alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
}

if (len<2) {
	//alert("Email address is missing a hostname!");
	return false;
}
	// If we've gotten this far, everything's valid!
	return true;
}


/* 
** -----------------------------------------------------------------------------------------
** Rotating banner ads
*/


function fRotatingBannerAd() {
var aAd_Link = [["<img src='ads/git_right_medium_fq.GIF' width='468' height='60' alt='try me special!' border='0'>","/launch.aspx?s=sfd.javascript.bc.g.1&lid=719","Gazelle Freestyle - Get it Today"],["<img src='ads/git_right_medium_adt.GIF' width='468' height='60' alt='dont leave your home unprotected.' border='0'>","/launch.aspx?s=sfd.javascript.bc.g.1&lid=677","ADT Home Security System"],["<img src='ads/git_right_medium_msi.GIF' width='468' height='60' alt='Moonstone Interactive' border='0'>","http://www.msinteractive.com/","Moonstone Interactive Online Marketing and Design"],["<img src='ads/git_right_medium_tex.GIF' width='468' height='60' alt='Texas Culinary Academy' border='0'>","/launch.aspx?s=sfd.javascript.bc.g.1&lid=6","Texas Culinary Academy Program Information"],["<img src='ads/git_right_medium_uop.GIF' width='468' height='60' alt='University of Phoenix' border='0'>","http://college-degree.getittoday.com","University of Phoenix Program Information"]];

idx = Math.floor(Math.random()*aAd_Link.length);
var currentBannerAd = "<a href=\"" + aAd_Link[idx][1] + "\" onmouseover=\"window.status='" + aAd_Link[idx][2] + "'; return true;\" onmouseout=\"window.status=''; return true;\">" + aAd_Link[idx][0] + "</a>";
return currentBannerAd
}

function fRotatingSideAd() {
var aAd_Link = [["<img src='ads/101_banner.gif' width='120' height='262' alt='www.online-casino-reviews.info' border='0'>","http://www.online-casino-reviews.info/","http://www.online-casino-reviews.info/"],["<img src='ads/cf_banner.gif' width='120' height='262' alt='www.college-finder.info' border='0'>","http://www.college-finder.info/","http://www.college-finder.info/"],["<img src='ads/git_banner.gif' width='120' height='262' alt='www.getittoday.com' border='0'>","http://www.getittoday.com/","http://www.getittoday.com/"],["<img src='ads/msi_banner.gif' width='120' height='262' alt='www.msinteractive.com' border='0'>","http://www.msinteractive.com/","http://www.msinteractive.com/"]];

idx = Math.floor(Math.random()*aAd_Link.length);
var currentBannerAd = "<a href=\"" + aAd_Link[idx][1] + "\" onmouseover=\"window.status='" + aAd_Link[idx][2] + "'; return true;\" onmouseout=\"window.status=''; return true;\">" + aAd_Link[idx][0] + "</a>";
return currentBannerAd
}

