function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function check(pass)
{
	var ans = 0;
	//ans = validateEmail();
	//alert("ans: "+ans);
	if(ans == 0)
	{
		//alert("Valid Form");
	
		var password = readCookie('formCookie');
		var myPass = String(pass.passText.value);
		if(password == myPass)
		{
			//alert("The text, "+myPass+", matches the generated code, "+password);
			return true;
		}
		else
		{
			alert("The text, "+myPass+", did not match the generated code, "+password);
		}
		return false;
	}
	else
	{
		//alert("Invalid Form");
		return false;
	}	
}


function myDrawFunctionDiv(id, xp, yp)
{
	//alert("myDrawFunctionDiv");
	var jg2 = new jsGraphics(id);
	
	//This is the starting X position.
	var x = xp;
	
	//This is the starting Y position.
	var y = yp;
	
	//This sets the width and height.
	w = 100;
	h = 50;
		
	jg2.setColor("white");
	jg2.fillRect(x,y,w,h);
	
	//This should contain the path to the background image.
	//Set the path from the file that is calling this function.
	jg2.drawImage("images/backgroundSm.jpg", x, y, w, h);
	
	jg2.setColor("#999999");
	
	jg2.setFont("Futura Lt BT","20px",Font.BOLD);
	
	//Below is the section that generates the random code and sets it into the cookie.
	smallLetters=new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
	bigLetters=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

	var text = "";
	
	for (i=0;i<=4;i++) 
	{
		var num = Math.floor(Math.random()*2);
		if(num == 0)
		{
			var letterNumber=Math.floor(Math.random()*26);//Used to get a letter of the alphabet.
			if(Math.floor(Math.random()*2)==0)
			{
				text += smallLetters[letterNumber];
			}
			else
			{
				text += bigLetters[letterNumber];
			}			
		}
		else
		{
			var randomNumber=Math.floor(Math.random()*10);//Used to get a number 0-9.
			text += String(randomNumber);
		}
	}

	createCookie('formCookie',text,1);
	
	jg2.drawString(text,x+20,y+15);
	jg2.paint();
  
}


function myDrawFunction(xp,yp,wp,hp)
{
	var browserName=navigator.appName;
	
	var x = xp;
	var y = yp;
	var w = wp;
	var h = hp;
	
	var bW = 0;//sets custom browser width.
	var bH = 0;//sets custom browser height.
	
	//This looks to see what browser is running and will adjust the position of the
	//image accordingly.
	var OSName;
	if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
	
	if (browserName=="Netscape")
	{
		if (OSName != "MacOS")
		{
			x = x - 2;
			y = y - 10;
		}
		else
		{
			y = y - 30;
		}
	} 
	if (browserName=="Microsoft Internet Explorer")
	{
		//Do nothing.
	}
		
	jg.setColor("white");
	jg.fillRect(x,y,w,h);
	
	jg.drawImage("../images/backgroundSm.jpg", x, y, w, h);
	
	jg.setColor("#999999");
	
	jg.setFont("Futura Lt BT","20px",Font.BOLD);
	
	smallLetters=new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
	bigLetters=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

	var text = "";
	
	for (i=0;i<=4;i++) 
	{
		var num = Math.floor(Math.random()*2);
		if(num == 0)
		{
			var letterNumber=Math.floor(Math.random()*26);//Used to get a letter of the alphabet.
			if(Math.floor(Math.random()*2)==0)
			{
				text += smallLetters[letterNumber];
			}
			else
			{
				text += bigLetters[letterNumber];
			}			
		}
		else
		{
			var randomNumber=Math.floor(Math.random()*10);//Used to get a number 0-9.
			text += String(randomNumber);
		}
	}

	createCookie('formCookie',text,1);
	
	jg.drawString(text,x+20,y+15);
	jg.paint();
  
}