//background
var showBackgroundImage=false;
var backgroundImagePath="http://www.loanall.com/jsp/mortgageForms/version4/formbackground.gif";
var backgroundImgeLocationX = 0;
var backgroundImgeLocationY = 0;
var showBackgroundColor=false;
var backgroundColor="#D6D6D6";




var W3C,IE4,IE6CSS,NN4,isCSS,IE;

var State = new Array();
var Code = new Array();

var mainElement;


// redirect parameters
var redirectCreditValue1="Excellent";//Excellent
var redirectLoanValue1="Refinance";
var redirectTarget1="http://y.yupils.com/cgi/r?;n=203;c=462126;s=6754;x=7936;f=200808041146490;u=j;z=TIMESTAMP;";

var redirectCreditValue2="Good";//Good
var redirectLoanValue2="Refinance";
var redirectTarget2="http://y.yupils.com/cgi/r?;n=203;c=462126;s=6754;x=7936;f=200808041146490;u=j;z=TIMESTAMP;";

var redirectCreditValue3="Fair";//Fair
var redirectLoanValue3="Refinance";
var redirectTarget3="http://y.yupils.com/cgi/r?;n=203;c=462126;s=6754;x=7936;f=200808041146490;u=j;z=TIMESTAMP;";

//debt redrect parameters
var debtTarget1 ="http://www.loanall.com/jsp/newform/levela.htm?"; // billmccoy1 landing page
var debtTarget2 ="http://www.loanall.com/jsp/newform/levelb.htm?"; //billmccoy2 landing page
var debtTarget3 ="http://www.loanall.com/jsp/newform/levelc.htm?"; //billmccoy3 landing page



var wasDrawn=false;
var proTypeValue=["Primary - Single Family","Primary - Condo","Manufactured","2-4 Plex","2nd Home","Mobile","Other"];
var rateCreditValue=["Excellent","Good","Fair","Needs improvement","Poor"];
var loanTypeValue=["Refinance","Home Equity","Debt Consolidation","Home Purchase"];
var showStartImage=true;
var showStartImagePath="http://loanall.com/jsp/mortgageForms/version4/start-Tab1.gif";
var startText="Start saving here";
var showNumber=false;
var target="http://www.loanall.com/allloans/mortgageForms/version4/step2.jsp";
var target1="https://www.loanall.com/allloans/tab1Page2Debt.jsp";

var creditCardText = "Credit card debt";
var creditDebtValues=["0","5000","10000","20000"];





function initBarbosDHTMLAPI(){
 if(document.images){
                     isCSS=(document.body && document.body.style) ? true : false;
                     W3C=(isCSS && document.getElementById) ? true : false;
                     IE4=(isCSS && document.all) ? true : false;
                     NN4=(document.layers) ? true : false;
                     IE6CSS=(document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
                     IE= navigator.appName.indexOf("Internet Explorer")!= -1 ? true : false;
                    }
} 




function drawForm(elemID){
   initBarbosDHTMLAPI();
   BuildStateArrays();
    var elem=document.getElementById(elemID);
        mainElement=elem; 
        if(elem.style) elem.style.overflow="hidden";

   if(W3C){
            if(showBackgroundImage) {     
                             elem.style.backgroundImage="url('"+backgroundImagePath+"')";
                             elem.style.backgroundRepeat="no-repeat";
                             elem.style.backgroundPosition=""+backgroundImgeLocationX+" "+backgroundImgeLocationY;
                            }
            if(showBackgroundColor) elem.style.backgroundColor=backgroundColor; 
             
           drawElem(elem);
           }

} 
             

function drawElem(elem){
  if(wasDrawn==false){
                            var divContainer=document.createElement("div");
                                divContainer.id="Container1"; 
                                var tableE=document.createElement("table");
                                    tableE.width="100%";
                                    tableE.height="250px";
                                var tbod=document.createElement("tbody");
                                var trE=document.createElement("tr");
                                var tdE=document.createElement("td");
                                var txt=document.createTextNode("State");
                                var sele=createSelect("stateTab1","stateTab1",State,true,1);
                                var noE;
                                    if(showNumber){
                                                       var tdEE=document.createElement("td");    
                                                           tdEE.width="40px";
                                                       var noI=document.createElement("img");
                                                           noI.src="http://loanall.com/jsp/mortgageForms/version4/one.gif";
                                                       tdEE.appendChild(noI);
                                                       tdEE.valign="bottom";
                                                       trE.appendChild(tdEE);
                                                       }     
                                    tdE.appendChild(txt);
                                    tdE.appendChild(document.createElement("br"));
                                    tdE.appendChild(sele);
                                    trE.appendChild(tdE);
                                    tbod.appendChild(trE);
                                    trE=document.createElement("tr"); 
                                    tdE=document.createElement("td");
                                    if(showNumber){
                                                       var tdEE=document.createElement("td");    
                                                           tdEE.width="40px";
                                                       var noI=document.createElement("img");
                                                           noI.src="http://loanall.com/jsp/mortgageForms/version4/two.gif";
                                                       tdEE.appendChild(noI);
                                                       tdEE.valign="bottom";
                                                       trE.appendChild(tdEE);
                                                       } 
                                    txt=document.createTextNode("Property type"); 
                                    tdE.appendChild(txt);
                                    tdE.appendChild(document.createElement("br"));
                                    sele=createSelect("ProTypeTab1","ProTypeTab1",proTypeValue,true,1);
                                    tdE.appendChild(sele);
                                    trE.appendChild(tdE);
                                    tbod.appendChild(trE);
                                    trE=document.createElement("tr");
                                    tdE=document.createElement("td");
                                    if(showNumber){
                                                       var tdEE=document.createElement("td");    
                                                           tdEE.width="40px";
                                                       var noI=document.createElement("img");
                                                           noI.src="http://loanall.com/jsp/mortgageForms/version4/three.gif";
                                                       tdEE.appendChild(noI);
                                                       trE.appendChild(tdEE);
                                                       }    
                                    txt=document.createTextNode("Rate your credit"); 
                                    tdE.appendChild(txt);
                                    tdE.appendChild(document.createElement("br"));
                                    sele=createSelect("RateCreditTab1","RateCreditTab1",rateCreditValue,true,1);
                                    tdE.appendChild(sele);
                                    trE.appendChild(tdE);
                                    tbod.appendChild(trE);
                                    trE=document.createElement("tr");
                                    tdE=document.createElement("td");
                                    if(showNumber){
                                                       var tdEE=document.createElement("td");    
                                                           tdEE.width="40px";
                                                       var noI=document.createElement("img");
                                                           noI.src="http://loanall.com/jsp/mortgageForms/version4/four.gif";
                                                       tdEE.appendChild(noI);
                                                       tdEE.valign="bottom";
                                                       trE.appendChild(tdEE);
                                                       } 
                                    txt=document.createTextNode("Loan type"); 
                                    tdE.appendChild(txt);
                                    tdE.appendChild(document.createElement("br"));
                                    sele=createSelect("LoanTypeTab1","LoanTypeTab1",loanTypeValue,true,1);
                                    tdE.appendChild(sele);
                                    trE.appendChild(tdE);
                                    tbod.appendChild(trE);
                                    trE=document.createElement("tr");
                                    tdE=document.createElement("td");
                                    if(showNumber){
                                                       var tdEE=document.createElement("td");    
                                                           tdEE.width="40px";
                                                       var noI=document.createElement("img");
                                                           noI.src="http://loanall.com/jsp/mortgageForms/version4/five.gif";
                                                       tdEE.appendChild(noI);
                                                       tdEE.valign="bottom";
                                                       trE.appendChild(tdEE);
                                                       } 
                                    txt=document.createTextNode(creditCardText); 
                                    tdE.appendChild(txt);
                                    tdE.appendChild(document.createElement("br"));
                                    sele=createSelectDebt("creditDebt","creditDebt",creditDebtValues,true,1);
                                    tdE.appendChild(sele);
                                    trE.appendChild(tdE);
                                    tbod.appendChild(trE);
                                    tableE.appendChild(tbod);
                             divContainer.appendChild(tableE);
                              if(showStartImage){
                                                      var divEE=document.createElement("div");
                                                      divEE.style.position="relative";
                                                      divEE.style.textAlign="center";
                                          var inE=document.createElement("span");
                                          var imgE=document.createElement("img");   
                                              imgE.src=showStartImagePath;
                                              inE.appendChild(imgE);
                                          divEE.appendChild(inE);
                                          imgE.onclick=performAction;
                                          divEE.style.paddingTop="0px";
                                          divEE.style.cursor="pointer";
                                          divContainer.appendChild(divEE);

                                                          }
                                    else {
                                          var divEE=document.createElement("div");
                                              divEE.style.position="relative";
                                              divEE.style.textAlign="center";
                                          var inE=document.createElement("input");
                                              inE.type="button";
                                              inE.value=startText;
                                              inE.onclick=performAction;
                                          divEE.appendChild(inE);
                                          divEE.style.paddingTop="8px";
                                          divContainer.appendChild(divEE);
                                          }  
                                         
                             elem.appendChild(divContainer); 
                             wasDrawn=true;
                            }
 else{
      document.getElementById("Container1").style.zIndex=3;
      document.getElementById("Container1").style.display="block";
     }
     
}











function BuildStateArrays()
{
 State[0] = "Alabama";         Code[0] = "AL";
 State[1] = "Alaska";          Code[1] = "AK";
 State[2] = "Arizona";         Code[2] = "AZ";
 State[3] = "Arkansas";        Code[3] = "AR";
 State[4] = "California";      Code[4] = "CA";
 State[5] = "Colorado";        Code[5] = "CO";
 State[6] = "Connecticut";     Code[6] = "CT";
 State[7] = "Delaware";        Code[7] = "DE";
 State[8] = "Florida";         Code[8] = "FL";
 State[9] = "Georgia";         Code[9] = "GA";
State[10] = "Hawaii";         Code[10] = "HI";
State[11] = "Idaho";          Code[11] = "ID";
State[12] = "Illinois";       Code[12] = "IL";
State[13] = "Indiana";        Code[13] = "IN";
State[14] = "Iowa";           Code[14] = "IA";
State[15] = "Kansas";         Code[15] = "KS";
State[16] = "Kentucky";       Code[16] = "KY";
State[17] = "Louisiana";      Code[17] = "LA";
State[18] = "Maine";          Code[18] = "ME";
State[19] = "Maryland";       Code[19] = "MD";
State[20] = "Massachusetts";  Code[20] = "MA";
State[21] = "Michigan";       Code[21] = "MI";
State[22] = "Minnesota";      Code[22] = "MN";
State[23] = "Mississippi";    Code[23] = "MS";
State[24] = "Missouri";       Code[24] = "MO";
State[25] = "Montana";        Code[25] = "MT";
State[26] = "Nebraska";       Code[26] = "NE";
State[27] = "Nevada";         Code[27] = "NV";
State[28] = "New Hampshire";  Code[28] = "NH";
State[29] = "New Jersey";     Code[29] = "NJ";
State[30] = "New Mexico";     Code[30] = "NM";
State[31] = "New York";       Code[31] = "NY";
State[32] = "North Carolina"; Code[32] = "NC";
State[33] = "North Dakota";   Code[33] = "ND";
State[34] = "Ohio";           Code[34] = "OH";
State[35] = "Oklahoma";       Code[35] = "OK";
State[36] = "Oregon";         Code[36] = "OR";
State[37] = "Pennsylvania";   Code[37] = "PA";
State[38] = "Rhode Island";   Code[38] = "RI";
State[39] = "South Carolina"; Code[39] = "SC";
State[40] = "South Dakota";   Code[40] = "SD";
State[41] = "Tennessee";      Code[41] = "TN";
State[42] = "Texas";          Code[42] = "TX";
State[43] = "Utah";           Code[43] = "UT";
State[44] = "Vermont";        Code[44] = "VT";
State[45] = "Virginia";       Code[45] = "VA";
State[46] = "Washington";     Code[46] = "WA";
State[47] = "West Virginia";  Code[47] = "WV";
State[48] = "Wisconsin";      Code[48] = "WI";
State[49] = "Wyoming";        Code[49] = "WY";
}  

function createSelect(name,id,val,first,sizes){
  var sel=document.createElement("select");
      if(IE) sel=document.createElement("<select name='"+name+"' size='"+sizes+"'>");
      sel.name=name;
      sel.id=id;
      if(!IE)sel.size=sizes;
      if(first) {
                 var op=document.createElement("option");
                                   op.value="";
                                   op.innerHTML="Select";
                                   sel.appendChild(op); 
                }
      for(i=0;i<val.length;i++){
                               var op=document.createElement("option");
                                   op.value=val[i];
                                   op.innerHTML=val[i];
                                   sel.appendChild(op);
                               }
      
      
return sel;      
}  

function createSelectInterval(name,id,val,first,sizes,increment){
  var sel=document.createElement("select");
      if(IE) sel=document.createElement("<select name='"+name+"' size='"+sizes+"'>");
      sel.name=name;
      sel.id=id;
      if(!IE)sel.size=sizes;
      if(first) {
                 var op=document.createElement("option");
                                   op.value="";
                                   op.innerHTML="Select";
                                   sel.appendChild(op); 
                }
      for(i=0;i<val.length;i++){
                               var op=document.createElement("option");
                                   op.value=val[i]-increment;
                                   if(val[i]<=10000 )op.innerHTML="$"+(val[i]-increment)+" - $"+(val[i]-1);
                                   else op.innerHTML="$"+(val[i]-2*increment)+" - $"+(val[i]-1);
                                   sel.appendChild(op);
                               }
      
      
return sel;      
}  


function createSelectDebt(name,id,val,first,sizes,increment){
  var sel=document.createElement("select");
      if(IE) sel=document.createElement("<select name='"+name+"' size='"+sizes+"'>");
      sel.name=name;
      sel.id=id;
      if(!IE)sel.size=sizes;
      if(first) {
                 var op=document.createElement("option");
                                   op.value="";
                                   op.innerHTML="Select";
                                   sel.appendChild(op); 
                }
      for(i=0;i<val.length;i++){
                               var op=document.createElement("option");
                                   op.value=val[i];
                                   if(val[i]==0) op.innerHTML="0$ - 5000$";
                                   else if(val[i]==5000) op.innerHTML="5000$ - 10000$";
                                   else if(i == (val.length-1) ) op.innerHTML=""+val[i]+"$ +";
                                   else op.innerHTML=""+val[i]+"$ - "+(parseInt(val[i])+10000)+"$";
                                   sel.appendChild(op);
                               }
      
      
return sel;      
}  



function performAction(){
var credit="";
var loan="";

var statee="";
var proTT="";
 var t=target;
var debtVal;

var val = document.getElementById("stateTab1").value;
    if(val.length<1) {showErrMsg("Select a state");return;}statee=val;
    val= document.getElementById("ProTypeTab1").value;
    if(val.length<1) {showErrMsg("Select a property type");return;}proTT=val;
    val= document.getElementById("RateCreditTab1").value;
    //if(val.indexOf("Poor")!=-1 || val.indexOf("eds improvement") != -1) t=target1;
    if(val.length<1) {showErrMsg("Select a credit rate");return;}credit=val;
    val= document.getElementById("LoanTypeTab1").value;
    if(val.length<1) {showErrMsg("Select a loan type");return;}loan=val;
    debtVal = document.getElementById("creditDebt").value;
    if(credit == "Needs improvement" || credit == "Poor"){//alert(debtVal);return;
     
      if(debtVal == "5000") {t= debtTarget1;t+="st=US"+getAbb(statee);t+="&db="+debtVal;window.location=t;return;}
      else if(debtVal == "10000") {t= debtTarget2;t+="st=US"+getAbb(statee);t+="&db="+debtVal;window.location=t;return;}
      else if(debtVal == "20000") {t= debtTarget3;t+="st=US"+getAbb(statee);t+="&db="+debtVal;window.location=t;return;}
      
    }

   if(credit == "Excellent" || credit == "Good" || credit == "Fair") {
     t=redirectTarget1;
     t+=";propertyStateCode="+getAbb(statee);
     t+=";CRTID=20074784";  
     t+=";PortalServiceCode=";
     if(loan =="Refinance") t+="REFI";
     else if(loan =="Home Equity") t+="HOMEEQ";
     else if(loan =="Debt Consolidation") t+="DEBTCON";
     else if(loan =="Home Purchase") t+="NEWHOME";
     t+=";PropertyType=";
     if(proTT =="Primary - Single Family") t+="Single";
     else if(proTT =="Primary - Condo") t+="Condo";
     else if(proTT =="2-4 Plex") t+="Multi";
     else if(proTT =="Mobile") t+="Mobile";
     else if(proTT =="Manufactured") t+="Manufactured";
     t+=";CreditRating="+credit;
     window.location=t;
      return;
     }     
  


   
    t+="?st="+encodeURIComponent(document.getElementById("stateTab1").value);
    t+="&proT="+encodeURIComponent(document.getElementById("ProTypeTab1").value);
    t+="&rateC="+encodeURIComponent(document.getElementById("RateCreditTab1").value);
    t+="&loanT="+encodeURIComponent(document.getElementById("LoanTypeTab1").value);
    window.location=t;
}

function getAbb(stat){
 for(var i=0;i<50;i++) {
                       if(State[i] == stat) return Code[i];
                       }
 
}



function showErrMsg(txt){

var divE=document.createElement("div");
    divE.id="tempDiv";
    divE.style.position="absolute";
    divE.style.zIndex="5";
    divE.style.textAlign="center";
    divE.style.backgroundColor="yellow";
    divE.style.fontWeight="bold";
    divE.style.fontStyle="italic";
    divE.style.top="3px";
    divE.style.left="60px";
    divE.style.fontSize="1.2em";
    divE.innerHTML=txt;
    mainElement.appendChild(divE); 
    setTimeout("hideErrMsg()",2000);   
}

function hideErrMsg(){
  if(document.getElementById("tempDiv")) mainElement.removeChild(document.getElementById("tempDiv"));
}