﻿// JScript File
function nameDefined(ckie, name)
{
   var splitValues;
   var i;
    
   for (i=0; i<ckie.length; i++)
   {
      splitValues = ckie[i].split("=");
      if(splitValues[0] == name)
      {
        return true;
      }     
   }
   return false;
}

function delBlanks(strng)
{
   var result="";
   var i;
   var chrn;
   
   for (i=0;i<strng.length;++i) 
   {
      chrn=strng.charAt(i);
      if(chrn != " ")
        result += chrn;
   }
   return result;
}

function getCookieValue(ckie, name)
{
   var splitValues;
   var i;
   
   for(i=0; i<ckie.length; i++)
   {
      splitValues = ckie[i].split("=");
      if(splitValues[0] == name)
        return splitValues[1];
   }
   return "";
}

// Tests to see if the cookie with the name and value 
// are on the client computer
function testCookie(cname, cvalue) 
{  
   var cookie = document.cookie;
   var chkdCookie = delBlanks(cookie);
   var nvpair = chkdCookie.split(";");
   var tvalue;

   //See if the name is in any pair
   if(nameDefined(nvpair,cname))  
   {   
      tvalue = getCookieValue(nvpair,cname)  //Gets the value of the cookie
      if(tvalue == cvalue)
        return true;
	  else
	    return false;
   }

   return false;
}

// Adds a new cookie with the ckieText text that will
// expire in the future, after lifeSpan number of milliseconds
function addCookie(ckieText, lifeSpan) 
{
      var futdate = new Date();
      var expdate = futdate.getTime();
      
      expdate += lifeSpan;
      futdate.setTime(expdate);
      
      var newCookie = ckieText;
      newCookie += " expires=" + futdate.toGMTString();
      window.document.cookie = newCookie;
}