function focus_fullname() {
   document.form.fullname.focus();
}

function focus_sqrtField() {
   document.sqrtForm.sqrtField.focus();
}

function writeDate() {
   var today=new Date();
	 var formatedDate = today.getMonth()+1+"/"+today.getDate()+"/"+today.getFullYear();
	 document.write("<p>" +formatedDate+ "</p>");
}

function checkForm(fullname) {
   var fullname = document.form.fullname.value;
	 var re = /^[a-zA-Z]+\s+([a-zA-Z]+\s+)*[a-zA-Z]+\s*$/;
	 var valid = re.test(fullname);
	 
	 if (valid==false)
	   {
		  alert("Please Enter Your Full Name, Letters Only.");
			return false;
		 }	
	 else
		{
		 makeCookie(fullname);
		 return true;
		}  		
}

function makeCookie(fullname) {
   document.cookie = "flnm = " +fullname;
	 window.location = "thanks.html";
}

function findCookie(val) {
   var cookie = null;
	 var findVal = val + "=";
	 var dc = document.cookie;
	 if (dc.length > 0){
	    var start = dc.indexOf(findVal);
			if (start >= 0){
			   start += findVal.length;
				 lastVal = dc.indexOf(";", start);
				 if (lastVal == -1){
				    lastVal = dc.length;
				 }
				 cookie = (dc.substring(start, lastVal));				 
			 }else {
			        return cookie; 
			 }     
	 }
	 return cookie;
}	

function writeCookie() {
   fullname = findCookie("flnm");   
   document.write("<p>" +fullname+ "</p>");
}	



function writeSqRt() {
   var x = document.sqrtForm.sqrtField.value;	 
	 var answer = Math.sqrt(x);
	 document.sqrtForm.sqrtAnswer.value = answer;
   	 
}

/**************  JS Rollover Menu Functions *****************/

if (document.images) {
   var ImgOver = new Array();
	 ImgOver[0] = new Image();
	 ImgOver[1] = new Image();
	 ImgOver[2] = new Image();
	 ImgOver[0].src = "images/animation_over.gif";
	 ImgOver[1].src = "images/form_over.gif";
	 ImgOver[2].src = "images/math_over.gif";
	 	 
	 var ImgOut = new Array();
	 ImgOut[0] = new Image();
	 ImgOut[1] = new Image();
	 ImgOut[2] = new Image();
	 ImgOut[0].src = "images/animation.gif";
	 ImgOut[1].src = "images/form.gif";
	 ImgOut[2].src = "images/math.gif";
	 
	 function RollOver(i) {
	    if (document.images) document.images[i].src = ImgOver[i].src;
	 }
	 
	 function RollOut(i) {
	    if (document.images) document.images[i].src = ImgOut[i].src;
	 }
}	



/**************  Animation Functions  *****************/

function xCoord(id) {
     object = document.getElementById(id);
	   xc = parseInt(object.style.left);
	   return xc;
}

function yCoord(id) {
   object = document.getElementById(id);
   yc = parseInt(object.style.top);
   return yc;
}

function placeIt(id, x, y) {
   object = document.getElementById(id);
   object.style.left = x + "px";
   object.style.top = y + "px";
}

function shiftIt(id, dx, dy) {
   object = document.getElementById(id);	
	 object.style.left = xCoord(id) + dx + "px"; 
	 object.style.top = yCoord(id) + dy + "px";
}

function movePicture() {
   var x = xCoord("Picture");
	 if (x <= 900) {
      shiftIt("Picture", 7, -1);	    
      setTimeout("movePicture()", 60);
   }	
}
