var OrangeFile="orange-";
var TrainFile="training-";
var AnalysisFile="analysis-";
var today=new Date();

window.onload = function(){
	
	today.setFullYear(today.getFullYear()+1); //ie the user preference will last a year
	
	var cookie=new String(document.cookie);
	
	if (cookie.search(/mov/) >= 0)
		ChangeToMOV();
	else if (cookie.search(/avi/) >= 0)
		ChangeToAVI();
	else
		ChangeToWMV();
}
function ChangeToWMV(){
	document.cookie="wmv; expires="+today.toGMTString();
	hashI=GetMovieExtButtons();
	hashI["wmv"].setAttribute('src','wmv_yes.gif');
	hashI["avi"].setAttribute('src','avi_no.gif');
	hashI["mov"].setAttribute('src','mov_no.gif');
	hashI[OrangeFile].setAttribute('href',OrangeFile+"wmv.php");
	hashI[TrainFile].setAttribute('href',TrainFile+"wmv.php");
	hashI[AnalysisFile].setAttribute('href',AnalysisFile+"wmv.php");
}
function ChangeToAVI(){
	document.cookie="avi; expires="+today.toGMTString();
	hashI=GetMovieExtButtons();
	hashI["wmv"].setAttribute('src','wmv_no.gif');
	hashI["avi"].setAttribute('src','avi_yes.gif');
	hashI["mov"].setAttribute('src','mov_no.gif');
	hashI[OrangeFile].setAttribute('href',OrangeFile+"avi.php");
	hashI[TrainFile].setAttribute('href',TrainFile+"avi.php");
	hashI[AnalysisFile].setAttribute('href',AnalysisFile+"avi.php");
}
function ChangeToMOV(){
	document.cookie="mov; expires="+today.toGMTString();
	hashI=GetMovieExtButtons();
	hashI["wmv"].setAttribute('src','wmv_no.gif');
	hashI["avi"].setAttribute('src','avi_no.gif');
	hashI["mov"].setAttribute('src','mov_yes.gif');
	hashI[OrangeFile].setAttribute('href',OrangeFile+"mov.php");
	hashI[TrainFile].setAttribute('href',TrainFile+"mov.php");
	hashI[AnalysisFile].setAttribute('href',AnalysisFile+"mov.php");
}
function GetMovieExtButtons(){
	var hashI=new Object();
	hashI["wmv"]=document.getElementById("wmv_img");
	hashI["avi"]=document.getElementById("avi_img");
	hashI["mov"]=document.getElementById("mov_img");
	hashI[OrangeFile]=document.getElementById("OrangeGrove");
	hashI[TrainFile]=document.getElementById("Training");
	hashI[AnalysisFile]=document.getElementById("Analysis");
	return hashI;
}
function SubmitForm(form){
	error='';
	if (!form.agree[0].checked)
		error+='You must agree to the license. ';
	if (form.fullname.value == '')
		error+='You must enter your name. ';
	var email=form.email.value;
	if (email == '')
		error+='You must enter your email address. ';
	if (!checkEmail(email))
		error+='You must enter a valid email address. ';
	if (form.inst.value == '')
		error+='You must enter your institution or company name. ';
	if (form.usecase.value == '')
		error+='You must tell us your intended use. ';	
	if (error != '')
		alert(error);
	else
		form.submit();
}
function checkEmail(email) {
	if (window.RegExp) {
		var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
		var reg1 = new RegExp(reg1str);
		var reg2 = new RegExp(reg2str);
		if (!reg1.test(email) && reg2.test(email)) {
			return true;
		}
		return false;
	} else {
		if(email.indexOf("@") >= 0)
			return true;
		return false;
	}
}