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
	document.cookie="CurrentPageURL=" + window.location + ";path=/; expires=" + expiry.toGMTString();
	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
		}
		try
		{
			if (theForm.elements[i].type=="select-one" && CookiesVal != "")
			{
				if (IsNumeric(CookiesVal) == false)
				{
					theForm.elements[i].value=CookiesVal
				}
			}
		}
		catch(e)
		{
			alert("Error Occurs");
		}
	}
 }

 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));
  }

// To check Weather value is Numeric or Not-- Code is For NCP only

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
   if (strString.length > 2) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
    {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
    }
   return blnResult;
   }
