// JavaScript Document

if (self==top){document.write("<scr" + "ipt type='text/javascript' language='JavaScript' id='GeniusCode' src='" + location.protocol + '//ibgef.rsvpgenius.com/mgTrack1.js?mgcid=13187Ff' + "'><\/scr" + "ipt>");}

function rewritelinks()
	{
	var templink=""
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) 
		{
		if (links[i].href.substring(links[i].href.length-4)==".pdf") 
			{
			templink=links[i].href;
			templink=templink.substring(0, templink.length-4);
			templink=templink.substring(templink.lastIndexOf("/")+1);
			templink="/register.htm?docrequest="+templink;
			links[i].href = templink;
			}
		}
	}

function checkregistration()
	{
	if (checkforcookie("themisregged")==false)
		{
		document.cookie='themisdest='+location.href+'; path=/';
		var to=setTimeout('window.location = "/register.html";',200);
		}
	}

function setregged()
	{
		setthemiscookie();
		if (checkforcookie("themisdest"))
			{
			var to=setTimeout('window.location = checkforcookie("themisdest");',20);
			}
		else
			{
			var to=setTimeout('window.location = document.URL.substring(0,document.URL.substring(8).indexOf("/")+9)+"prod/downpc.htm";',20);
			}
	}
	
function checkdocredirect()
		{
		var stringtoparse=document.location.search;
		var founddest=false;
		stringtoparse = stringtoparse.substring(1);
		var keypairs = stringtoparse.split("&");
		for (i = 0; i < keypairs.length; i++)
			{
			 var keypair = keypairs[i].split("=");
			 if (keypair[0]=="docrequest")
			 	{
				document.cookie='themisdest='+document.URL.substring(0,document.URL.substring(8).indexOf("/")+9)+'docs/'+keypair[1]+'.pdf; path=/';
				founddest=true;
				}
			}
		if (checkforcookie("themisregged")!=false)
			{
			if (checkforcookie("themisdest")!=false && founddest!=false)
				{
				var to=setTimeout('window.location = checkforcookie("themisdest");',2);
				}
			else
				{
				var to=setTimeout('window.location = document.URL.substring(0,document.URL.substring(8).indexOf("/")+9)+"prod/downpc.htm";',2);
				}
			}
		else
			{
			return false;
			}
		}

function checkforcookie(cookiename)
	{
	if (document.cookie)
		{		
		cookiename=cookiename+"=";
		var cookiearray= document.cookie.split(';');
		for(var i=0; i<cookiearray.length; i++)
			{
			var thiscookie=cookiearray[i];
			while (thiscookie.charAt(0)==' ') thiscookie = thiscookie.substring(1,thiscookie.length);
			
			if (thiscookie.indexOf(cookiename) == 0)
				{
				var cnamelen=cookiename.length;
				var cookievalue=thiscookie.substring(cnamelen);
				return (cookievalue);
				}
			}
		}
	return (false);
	}

function verifyfields()
	{
	errors=false;	
	document.getElementById("firstnameError").innerHTML="";	
	document.getElementById("lastnameError").innerHTML="";	
	document.getElementById("companyError").innerHTML="";	
	document.getElementById("phoneError").innerHTML="";	
	document.getElementById("emailError").innerHTML="";
	document.getElementById("topError").innerHTML="";
	
	if (document.forms.regform.firstname.value=="")
		{
			errors=true;
			document.getElementById("firstnameError").innerHTML="<font color='red'>First Name is a required field</font>";
		}	
	if (document.forms.regform.lastname.value=="" || document.forms.regform.lastname.value.length < 3)
		{
			errors=true;
			document.getElementById("lastnameError").innerHTML="<font color='red'>Last Name is a required field</font>";
		}		
	if (document.forms.regform.company.value=="" || document.forms.regform.company.value.length < 3)
		{
			errors=true;
			document.getElementById("companyError").innerHTML="<font color='red'>Company is a required field</font>";
		}
	if (document.forms.regform.phone.value=="")
		{
			errors=true;
			document.getElementById("phoneError").innerHTML="<font color='red'>Phone Number is a required field</font>";
		}
	else if (isPhone(document.forms.regform.phone.value)==false)
		{
			errors=true;
			document.getElementById("phoneError").innerHTML="<font color='red'>Please enter a valid phone number</font>";
		}	
	if (document.forms.regform.Email.value=="")
		{
			errors=true;
			document.getElementById("emailError").innerHTML="<font color='red'>E-mail Address is a required field</font>";
		}
	else if (isEmail(document.forms.regform.Email.value)==false)
		{
			errors=true;
			document.getElementById("emailError").innerHTML="<font color='red'>Please enter a valid E-mail address</font>";
		}
	if (errors==true)
		{
		document.getElementById("topError").innerHTML="<font color='red'><b>There were problems with your submission</b><br>Please correct the highlighted errors and resubmit.</font>";
		return false;
		}
	setthemiscookie();
	document.forms.regform.destination.value = checkforcookie("themisdest");
	return true;
	}
	
function isPhone(testnumber)
	{
	var valid = 1;
	var goodchars = "0123456789()-+ ";
	var i = 0;
	if (testnumber=="") 
		{
		valid = 0;
		}
	for (i =0; i <= testnumber.length -1; i++) 
		{
		if (goodchars.indexOf(testnumber.charAt(i)) == -1)
			{
			valid = 0;
			}
		}
		return valid;
	}
	
function isEmail(testemail)
	{
	return ((testemail.indexOf(".") > 2) && (testemail.indexOf("@") > 0));
	}
	
function setthemiscookie()
	{
	var days=30;
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "expires="+date.toGMTString();	
	document.cookie='themisregged=true; '+expires+'; path=/';
	}


