function getCookie(name){
    var cname = name + "=";
    var dc = document.cookie;             
    if (dc.length > 0) {              
	begin = dc.indexOf(cname);       
	if (begin != -1) {           
	    begin += cname.length;       
	    end = dc.indexOf(";", begin);
	    if (end == -1) end = dc.length;
	    return unescape(dc.substring(begin, end));
	} 
    }
    return null;
}

function setCookie(name, value, days, path, domain, secure) {
    var expires = (days > 0 ? new Date(new Date().getTime() + 30*86400000) :
		   null);
    document.cookie = name + "=" + escape(value) + 
	((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	((secure == null) ? "" : "; secure");
}

function delCookie (name,path,domain) {
    if (getCookie(name)) {
	document.cookie = name + "=" +
	    ((path == null) ? "" : "; path=" + path) +
	    ((domain == null) ? "" : "; domain=" + domain) +
	    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

// This routine returns an object similar to SSJS's 
// request object. Used to process forms on the client, in a method 
// similar to SSJS. 
// 
// Usage: request=createRequestObject(); 
//        document.writeln("The Name was " + request.name); 
// 
function createRequestObject() 
{ 
    var request   = new Object(); // Creates a new request object. 
    var nameVal   = "";		  // Holds array for a single name-value pair. 
    var inString  = location.search; // Strips query string from URL. 
    var separator = ",";          // Separates multiple values. 

    // If URL contains a query string, grabs it. 
    if (inString.charAt(0) == "?") { 
        // Removes "?" character from query string. 
        inString = inString.substring(1, inString.length); 
        // Separates query string into name-value pairs. 
        keypairs = inString.split("&"); 
        // Loops through name-value pairs. 
        for (var i=0; i < keypairs.length; i++) { 
            // Splits name-value into (nameVal[0]=name, nameVal[1]=value). 
            nameVal = keypairs[i].split("="); 
            // URL decoding
            for (var a in nameVal) { 
		nameVal[a] = nameVal[a].replace(/\+/g, " ");
		nameVal[a] = unescape(nameVal[a]); 
            } 
            // Checks to see if name already exists in request object 
            // (since select lists may contain multiple values). 
            if (request[nameVal[0]]) { 
		request[nameVal[0]] += separator + nameVal[1]; 
            } else { 
		request[nameVal[0]] = nameVal[1]; 
            } 
        } 
    } 
    return request; 
} 

