// JavaScript Document <!--
var submitwhere;
submitwhere = "http://cgi.hsh.com/htmlform/htmlform.fxp";
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=/" : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function setupForm() {
    if (userProfile) getValues(userProfile);
	if (document.forms[0].hshdata.value<1){
			document.forms[0].hshdata.value = 1;
		}else{
			document.forms[0].hshdata.value = eval(document.forms[0].hshdata.value) + eval(1);
		}
}

function getValues(string) {
    getValue(string,"NAME",   document.forms[0].NAME,   "text");
    getValue(string,"PHONE_HOME",    document.forms[0].PHONE_HOME,    "text");
    getValue(string,"PHONE_BIZ",    document.forms[0].PHONE_BIZ,    "text");
    getValue(string,"EMAIL_ADDR",    document.forms[0].EMAIL_ADDR,    "text");
    getValue(string,"LOANPURPOS",    document.forms[0].LOANPURPOS,    "select");
    getValue(string,"PROP_LOC",    document.forms[0].PROP_LOC,    "select");
    getValue(string,"ANNINC_TXT",    document.forms[0].ANNINC_TXT,    "text");
    getValue(string,"LOANAMT_T",    document.forms[0].LOANAMT_T,    "text");
    getValue(string,"PROP_VAL",    document.forms[0].PROP_VAL,    "text");	
    getValue(string,"LOAN_TYPE",    document.forms[0]['LOAN_TYPE'],    "select");
	getValue(string,"COMMENTS1",    document.forms[0].COMMENTS1,    "text");
	getValue(string,"hshdata",    document.forms[0].hshdata,    "text");

}

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) { 
if (string != "on"){
 return false;
 }
return true; 
}
function onSelect(elementValue,object){
for (i=0; i<object.length; i++) { 
	if (object.options[i].value==elementValue)
		return i;
	} 
return 0;
}

function getValue(string,elementName,object,elementType) {
// gets value of elementName from string and populates object of elementType

    var startPos = string.indexOf(elementName + "=")
    
    if (startPos > -1) {
        startPos = startPos + elementName.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")   object.selectedIndex = onSelect(elementValue,object);
        if (elementType == "checkbox") object.checked = onCheck(elementValue);
        if (elementType == "radio")    object[elementValue].checked = true;
    }
}
function infoCheck(){
if(document.forms[0].saveinfo.checked){
document.forms[0].action=""
document.forms[0].method="get";
}else{
document.forms[0].action=submitwhere
document.forms[0].method="post";
}
}


function build_cookie(){
	
var newval;
newval = "";
newval = newval + "NAME=" + document.forms[0].NAME.value + "&";
newval = newval + "ADDRESS1=" + document.forms[0].ADDRESS1.value + "&";
newval = newval + "CITY=" + document.forms[0].CITY.value + "&";
newval = newval + "STATE=" + document.forms[0].STATE.value + "&";
newval = newval + "ZIP=" + document.forms[0].ZIP.value + "&";
newval = newval + "PHONE_HOME=" + document.forms[0].PHONE_HOME.value + "&";
newval = newval + "PHONE_BIZ=" + document.forms[0].PHONE_BIZ.value + "&";
newval = newval + "EMAIL_ADDR=" + document.forms[0].EMAIL_ADDR.value + "&";
newval = newval + "CALLWHEN=" + document.forms[0].CALLWHEN.value + "&";
newval = newval + "LOANPURPOS=" + document.forms[0].LOANPURPOS[document.forms[0].LOANPURPOS.selectedIndex].value + "&";
newval = newval + "PROP_LOC=" + document.forms[0].PROP_LOC.value + "&";
newval = newval + "ANNINC_TXT=" + document.forms[0].ANNINC_TXT.value + "&";
newval = newval + "LOANAMT_T=" + document.forms[0].LOANAMT_T.value + "&";
newval = newval + "PROP_VAL=" + document.forms[0].PROP_VAL.value + "&";
newval = newval + "WHEN_NEED=" + document.forms[0]['WHEN_NEED'][document.forms[0]['WHEN_NEED'].selectedIndex].value + "&";
newval = newval + "LOAN_TYPE=" + document.forms[0]['LOAN_TYPE'][document.forms[0]['LOAN_TYPE'].selectedIndex].value + "&";

if (document.forms[0].LTJUMBO.checked)
newval = newval + "LTJUMBO=" + document.forms[0].LTJUMBO.value + "&";
if (document.forms[0].LTNOFEE.checked)
newval = newval + "LTNOFEE=" + document.forms[0].LTNOFEE.value + "&";
if (document.forms[0]['No-Point'].checked)
newval = newval + "No-Point=" + document.forms[0]['No-Point'].value + "&";
if (document.forms[0].LT100PCT.checked)
newval = newval + "LT100PCT=" + document.forms[0].LT100PCT.value + "&";
if (document.forms[0].LTOTHER.checked)
newval = newval + "LTOTHER=" + document.forms[0].LTOTHER.value + "&";

newval = newval + "COMMENTS1=" + document.forms[0].COMMENTS1.value + "&";
newval = newval + "hshdata=" + document.forms[0].hshdata.value;

return newval;

}

function submitit(){
	var today = new Date();
	var expires = new Date(today.getTime() + (4*3600000));//(0.25 * 86400000));
	var searchString = build_cookie();
	if (searchString.length > 0){ 
		Set_Cookie("userProfile",searchString,expires,"/");
	}
	document.forms[0]['submit coupon'].disabled = true;
	document.forms[0].submit();
return true;
}

var userProfile = Get_Cookie("userProfile");



if (!userProfile) {
    document.write("<div align='center'><TABLE border='0'><TR><TD><SMALL> Want information from more than one lender? You will have the ability to save your <BR>information  so that you don\'t have to retype it on the next coupon.</SMALL></TD></TR></TABLE></DIV>");
 }

if (userProfile){
document.write('Your information has been saved previously, <input type="button" name="Setup" value="Click Here to Load Your Information" onclick="setupForm()">');
}

//-->