<!--

// C O O K I E   U T I L I T I E S


/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/
/*
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*//*
function getCookie(name) {
  var dc = document.cookie;
  alert("getCookie name="+name+" dc = " + dc);
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
	alert("getCookie unescape etc " + unescape(dc.substring(begin + prefix.length, end)));
  return unescape(dc.substring(begin + prefix.length, end));
}



/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*//*

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}*/

function getCookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function setCookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function deleteCookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}




// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}



var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function cookieForms() {  
	var mode = cookieForms.arguments[0];

	for(f=1; f<cookieForms.arguments.length; f++) {
		formName = cookieForms.arguments[f];
//alert(formName);
		if(mode == 'open') {	
//alert('open');
//alert('saved_value_'+formName);
			cookieValue = getCookie('saved_value_'+formName);
//alert('saved_name_'+formName);
			nameValue = getCookie('saved_name_'+formName);
//alert(cookieValue);
//alert(nameValue);
			if(cookieValue != null) {
				var cookieArray = cookieValue.split('#cf#');
				var nameArray = nameValue.split('#cf#');
				
				for (i = 1; i < nameArray.length ; i++ ){
				//if(cookieArray.length == document[formName].elements.length) {
					//for(i=0; i<document[formName].elements.length; i++) {
					
					if(cookieArray[i].substring(0,6) == 'select') { 
						document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); 
					}
					else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { 
						eval("document[formName].elements."+nameArray[i]+".checked = true; ");
					}
					else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { 
						eval("document[formName].elements."+nameArray[i]+".checked = false; ");
					}
					else { 
						eval("document[formName].elements."+nameArray[i]+".value = (cookieArray[i]) ? cookieArray[i] : ''; ");
					}
					//}
				}
			}
		}
				
		if(mode == 'save') {	
//alert('save');
			cookieValue = '';
			nameValue = '';
			for(i=1; i<document[formName].elements.length; i++) {
				fieldType = document[formName].elements[i].type;
//alert(fieldType);
				fieldName = document[formName].elements[i].name;
//alert(i+":"+fieldName+":"+fieldType);
				
				if(fieldType == 'password') { passValue = ''; }

				else if(fieldType == 'checkbox') { passValue = 'cb'+document[formName].elements[i].checked; }
				else if(fieldType == 'radio') { passValue = 'rb'+document[formName].elements[i].checked; }
				else if(fieldType == 'select-one') { passValue = 'select'+document[formName].elements[i].options.selectedIndex; }
				else { passValue = document[formName].elements[i].value; }
			
				nameValue = nameValue + escape(fieldName) + '#cf#';
				cookieValue = cookieValue + passValue + '#cf#';
			}
			cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter
//alert(cookieValue);
			setCookie('saved_value_'+formName, cookieValue, exp);		
			nameValue = nameValue.substring(0, nameValue.length-4); // Remove last delimiter
//alert(nameValue);
			setCookie('saved_name_'+formName, nameValue, exp);		
		}	
	}
}

//-->

