var pathak = document.cookie;

function SetCookies(theForm)
{
	var today = new Date();
	var expiry = new Date(today.getTime() +28 * 24 * 60 * 60 * 1000); // plus 28 days
	for(var i=0;i<theForm.elements.length-1;i++)
	{
		if (theForm.elements[i].type=="text")
		{
	      document.cookie=theForm.elements[i].name + "=" + theForm.elements[i].value + ";path=/; expires=" + expiry.toGMTString();
		}
		else if (theForm.elements[i].type=="select-one" && theForm.elements[i].value!="" && theForm.elements[i].value != "SELECT")
		{
			document.cookie = theForm.elements[i].name + "=" + theForm.elements[i].value + ";path=/; expires=" + expiry.toGMTString();
		}
	}
 }

 function fetch_cookies1(theForm)
 { 
	for(var i=0;i<theForm.elements.length-1;i++)
	{
	   var CookiesVal = getCookies(theForm.elements[i].name)
		if (theForm.elements[i].type=="text" ) 
		{
			theForm.elements[i].value= CookiesVal
		}
		if (theForm.elements[i].type=="select-one" && CookiesVal != "")
		{
			theForm.elements[i].value=CookiesVal
		}
	}
 }

 function getCookies(name)
 { 
    // use: getCookie("name");

    var index = pathak.indexOf(name + "=");
    if (index == -1) return '';
    index = pathak.indexOf("=", index) + 1;
    var endstr = pathak.indexOf(";", index);
    if (endstr == -1) endstr = pathak.length;
    return unescape(pathak.substring(index, endstr));
  }