<!--
function Get_Cookie(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 Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function setupForm(formName) {
	if (userProfile) getValues(userProfile, formName);
}

function getValues(string, formName) {

//    getValue(string,	eval("document.forms[" + formName + "].prefix"),	"select");    
    getValue(string,	document.forms[formName].prefix,	"select");    
    getValue(string,	document.forms[formName].first,   "text");
    getValue(string,	document.forms[formName].mi,   "text");
    getValue(string,	document.forms[formName].last,   "text");
    getValue(string,	document.forms[formName].suffix,	"select");    
    getValue(string,	document.forms[formName].address1,   "text");
    getValue(string,	document.forms[formName].address2,   "text");
    getValue(string,	document.forms[formName].city,   "text");
    getValue(string,	document.forms[formName].county,	"select");    
    getValue(string,	document.forms[formName].state,	"select");    
    getValue(string,	document.forms[formName].zip,   "text");
    getValue(string,	document.forms[formName].zipplus,   "text");
    getValue(string,	document.forms[formName].email,   "text");
    getValue(string,	document.forms[formName].remember, "checkbox");

/*    getValue(string,	document.forms[formName].user,   "text");
//    getValue(string,document.forms[formName].email,  "text");    
    getValue(string,	document.forms[formName].country,	"select");    
    getValue(string,	document.forms[formName].age,    "select");
    getValue(string,	document.forms[formName].sex,    "radio");

    for (var i=0;i<7+1;i++)
        getValue(string,	eval("document.forms[formName].i"+i), "checkbox");
*/
}

function replace(string,text,by) {
// Replaces text with by in string
    var i = string.indexOf(text);
    var newstr = '';
    if ((!i) || (i == -1)) return string;
    newstr += string.substring(0,i) + by;

    if (i+text.length < string.length)
        newstr += replace(string.substring(i+text.length,string.length),text,by);
    
    return newstr;
}

function onCheck(string, compare) { if (string == compare) return true; return false; }

function setSelect( object, value ) {
// Sets the selected index of the Select element to the value. If not, lets it unselected.
	var found = false;
	for (var i = 0; i < object.options.length; i++) {
	if (object.options[i].value == value) {
		found=true; break;
		}
	}
	if (found) { object.selectedIndex = i; }
	else { object.selectedIndex = -1; }

}


function getValue(string, object, elementType) {
// gets value of elementName from string and populates object of elementType
    var startPos = string.indexOf(object.name + "=")
    
    if (startPos > -1) {
        startPos = startPos + object.name.length + 1;
        var endPos = string.indexOf("&",startPos);
        if (endPos == -1) endPos = string.length;

        var elementValue = unescape(string.substring(startPos,endPos));
        if (elementType == "text")     object.value = elementValue;
        if (elementType == "password") object.value = elementValue;
        if (elementType == "select")   setSelect( object, elementValue );
        if (elementType == "checkbox") object.checked = onCheck(object.value, elementValue);
        if (elementType == "radio")    object[elementValue].checked = true;
    }
}

//Check if Browser accepts Cookies
function checkCookieEnabled() {
	var cookieEnabled=(navigator.cookieEnabled)? true : false
	
	//if not IE4+ nor NS6+
	if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
	Set_Cookie("testcookie", "Yes");
	cookieEnabled=(Get_Cookie("testcookie")=="Yes")? true : false
	 //erase dummy value
		Set_Cookie("testcookie", "");
//		Remove_Cookie("testcookie");
	}
	//alert(cookieEnabled);
	return cookieEnabled;
}

function checkRemember (string) {
	var remem_field_name = "remember";
	var remem_value = "";
//	alert ("string = " + string);
	if (string == "" ) {
//	alert ("string before = " + string);
	string = Get_Cookie("userProfile");
//	alert ("string after = " + string);
	}
	if (string != "") {
	//alert ("string = " + string);
		var startPos = string.indexOf(remem_field_name + "=");
		if (startPos > -1) {
			startPos = startPos + remem_field_name.length + 1;
			//alert("startPos = " + startPos);
			var endPos = string.indexOf("&",startPos);
			//alert("endPos = " + endPos);
			if (endPos == -1) endPos = string.length;
			remem_value = unescape(string.substring(startPos,endPos));
//			remem_value = string.substring(startPos,endPos);
//			alert ("remem_value = " + remem_value);
		}					
	}
	else {
		remem_value = "";
	}
	return remem_value;
}

function get_item_value(object, elementType) {
        if (elementType == "text")     return object.value;
        if (elementType == "password") return object.value;
        if (elementType == "select")   return object.options[object.selectedIndex].value;
        if (elementType == "checkbox") {
			if (object.checked) return object.value;
			else return null
		}
        if (elementType == "radio")    return object.value;

}

function store_values(formName, cookieName) {
	var string = "";
//	alert (document.forms[formName].remember.name + "=" + document.forms[formName].remember.checked);
	if (escape(get_item_value(document.forms[formName].remember, "checkbox")) == "yes") {
		string = string + document.forms[formName].prefix.name + "=" + get_item_value(document.forms[formName].prefix, "select");
		string = string + "&" + document.forms[formName].first.name + "=" + get_item_value(document.forms[formName].first, "text");
		string = string + "&" + document.forms[formName].mi.name + "=" + get_item_value(document.forms[formName].mi, "text");
		string = string + "&" + document.forms[formName].last.name + "=" + get_item_value(document.forms[formName].last, "text");
		string = string + "&" + document.forms[formName].suffix.name + "=" + get_item_value(document.forms[formName].suffix, "select");
		string = string + "&" + document.forms[formName].address1.name + "=" + get_item_value(document.forms[formName].address1, "text");
		string = string + "&" + document.forms[formName].address2.name + "=" + escape(get_item_value(document.forms[formName].address2, "text"));
		string = string + "&" + document.forms[formName].city.name + "=" + get_item_value(document.forms[formName].city, "text");
		string = string + "&" + document.forms[formName].county.name + "=" + get_item_value(document.forms[formName].county, "select");
		string = string + "&" + document.forms[formName].state.name + "=" + get_item_value(document.forms[formName].state, "select");
		string = string + "&" + document.forms[formName].zip.name + "=" + get_item_value(document.forms[formName].zip, "text");
		string = string + "&" + document.forms[formName].zipplus.name + "=" + get_item_value(document.forms[formName].zipplus, "text");
		string = string + "&" + document.forms[formName].email.name + "=" + get_item_value(document.forms[formName].email, "text");
		string = string + "&" + document.forms[formName].remember.name + "=" + get_item_value(document.forms[formName].remember, "checkbox");
//		string = string + "&" + document.forms[formName].remember.name + "=" + escape(document.forms[formName].remember.value);
//		alert("string to store = " + string);
//		string = escape(string);
//		alert("post-escape string to store = " + string);
		var today = new Date();
		var expires = new Date(today.getTime() + (365 * 86400000));
		Set_Cookie(cookieName,string,expires,"/",document.domain);
//		Set_Cookie(cookieName,string,expires,"/",".state.nj.us");
//		Set_Cookie(cookieName,string,expires,"/");
//		Set_Cookie(cookieName,string,expires);
	}
	else {
		var today = new Date();
		var expires = new Date(today.getTime() - (365 * 86400000));
		Set_Cookie(cookieName,string,expires,"/",document.domain);
//		Set_Cookie(cookieName,string,expires,"/",".state.nj.us");
//		Remove_Cookie(cookieName);
	}	
//	alert ("string to store = " + string);
//	alert ("cookieName" + cookieName);
//	var expires = new Date(today.getTime() + (56 * 86400000));

}

function form_submit(formName) {
//	if (document.forms[formName].remember.value == "yes") store_values(formName, "userProfile");
	store_values(formName, "userProfile");
//	document.forms['speech_points'].submit();
//	alert(document.forms[formName].name);
//	var object = document.forms[formName];
//	alert(object.name);
//	object.submit();
//	document.forms[formName].submit();
//	document.speech_points.submit();
}
//-->

