// <!--
// Global JavaScript Functions

function preLoadNav() {
	var navimages = new Array();
	for (z=0; z<preLoadNav.arguments.length; z++){
		navimages[z] = new Image();
		navimages[z].src = preLoadNav.arguments[z];
	}
}

function popup_window(url,width,height,source) 
{
	theWindow = window.open(url, source, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+width+',height='+height);
	theWindow.focus();
}

function article_image_popup(url,width,height,cacheBuster)
{
	newURL = "/actions/popup.php?"+url;
	imgWin = window.open(newURL, cacheBuster, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+width+',height='+height);
	imgWin.focus();
}

function email_page(data, site)
{
	emailWindow = window.open('/actions/emailArticle.php?' + data + '&site=' + site, 'email_window', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=400');
}

function print_page(iid, site)
{
	rootDir = site == 'studiodaily' ? 'main' : site;
	printWindow = window.open('/' + rootDir + '/print/' + iid, 'print_window', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=465,height=450');
}

function request_permission(site)
{
	printWindow = window.open('/actions/request.php?site=' + site, 'request_window', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=465,height=450');
}

function checkEmailForm(theForm)
{
	var TO		= theForm.TO.value;
	var FROM	= theForm.FROM.value;
	var BCC		= theForm.BCC.value;
//	var regExp	= /[^@]+@[^\.]+\..+/; // email validator
	var regExp	= /[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})/; // email validator
//		"^.+@.+\..+$"
//		"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$"
	
	toValid =	TO.search(regExp);
	fromValid =	FROM.search(regExp);
	bccValid =	BCC.search(regExp);
	
	if (TO == "") {
		theForm.TO.focus();
		alert("You must first enter the email address of the person \rto whom you would like to send this article.");
		return false;
	} else if (toValid == -1) {
		theForm.TO.focus();
		alert("You must first enter a valid email address in the \"To\" field.");
		return false;
	} else if (FROM == "") {
		theForm.FROM.focus();
		alert("You must first enter your email address in the \"Your Email Address\" field.");
		return false;
	} else if (fromValid == -1) {
		theForm.FROM.focus();
		alert("You must first enter a valid email address in the \"Your Email Address\" field.");
		return false;
	} else if (BCC != "" && bccValid == -1) {
		theForm.BCC.focus();
		alert("You must first enter a valid email address in the \"Bcc\" field.");
		return false;
	}
	
}

function video_window(src,width,height) 
{
	var adjHeight = (height < 340 ? 340 : height)+35+47; // add for template header and footer
	var adjWidth = width+176; // add for sponsorship ad + 6 px gutter
	var rexp = /^ai2/;
	var serverRef = src.search(rexp) != -1 ? 'aimediaserver2' : 'aimediaserver' ;
	videoWindow = window.open('http://'+serverRef+'.com/studiodaily/videoplayer/?src='+src+'&width='+width+'&height='+height, 'video', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+adjWidth+',height='+adjHeight);
	videoWindow.moveTo(30,30);
	videoWindow.focus();
}

// -->


