

  function getCookie(name)
 	{ 
	var DC = document.cookie;
    var index = DC.indexOf(name + "=");
    if (index == -1) return null;
    index = DC.indexOf("=", index) + 1;
    var endstr = DC.indexOf(";", index);
    if (endstr == -1) endstr = DC.length;
    return unescape(DC.substring(index, endstr));
  	}
  
  // Function setCookie sets the cookie for the site. This cookie is set for  160 days.
  
  function setCookie(name, value)
   { 
   	var DC = document.cookie;
	var today = new Date();
  	var expiry = new Date(today.getTime() + 160 * 24 * 60 * 60 * 1000); // plus 160 days

	var path = "/";

    if (value != null && value != "")
    {  
		document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=" + path  
		DC = document.cookie; 
	}
  }

// Function Check() is wtitten is called from the load event of the body. This function sets the value of all the fields.

function Check()
{
	var isNS6 = (navigator.userAgent.indexOf("Gecko") > 0) ? 1 : 0;
	if (isNS6 == 0) 	
	{	
	var str = getCookie("VALSET");
	//if(str != null)
	//{
		GetAllValuesOnForm();
	//}
	}
	
}

// Function SetAllValInCookies() will be called when any form is being submitted. This function sets the cookie for the site.

function SetAllValInCookies(myForm)
{	
	
	var isNS6 = (navigator.userAgent.indexOf("Gecko") > 0) ? 1 : 0;
	if (isNS6 == 0) 
	{
	var str = getCookie("VALSET")
	var intStoreCookies = 0;
	if(str != null)
	{
		intStoreCookies = 1;
	}
	else
	{
		if (confirm("Is it OK to keep this information for later download requests? (If NOT 'Cancel'.)")) 
		{
			intStoreCookies = 1 ;
		}
	}
	if (intStoreCookies==1)
	{	
	setCookie("VALSET","true");

	var intCtr=0;
	for (intCtr=0;intCtr < myForm.elements.length - 1;intCtr++)
	{
		if (myForm.elements[intCtr].type == "text")
		{
			setCookie(myForm.elements[intCtr].name, myForm.elements[intCtr].value);
		}
		if (myForm.elements[intCtr].type == "textarea")
		{
			setCookie(myForm.elements[intCtr].name, myForm.elements[intCtr].value);
		}
		if (myForm.elements[intCtr].type == "select-one")
		{
			setCookie(myForm.elements[intCtr].name, myForm.elements[intCtr].value);
		}
		if (myForm.elements[intCtr].type == "select")
		{
			setCookie(myForm.elements[intCtr].name, myForm.elements[intCtr].value);
		}
	}
	
	}
	}
	
	return true;
}

function GetAllValuesOnForm()
{
	var intFormCount = 0;

	for (intFormCount=0; intFormCount < document.forms.length; intFormCount++)
	{
		var intCtr=0;
		for (intCtr=0;intCtr< document.forms[intFormCount].elements.length - 1;intCtr++)
		{
	
		//	if (document.forms[intFormCount].elements[intCtr].type == "text")
		//	{
		
			var cookievalue = ParseCookie(document.forms[intFormCount].elements[intCtr].name)
		
		if (cookievalue != "NULL")
		{
				document.forms[intFormCount].elements[intCtr].value = ParseCookie(document.forms[intFormCount].elements[intCtr].name)
		}
	    	//}
		}
	}
}

function ParseCookie(name)
{
	var RetVal = getCookie(name)
	if(RetVal == null)
	{
		RetVal = "NULL";
	}	
	return RetVal;
	
}

