//background
var showBackgroundImage=false;
var backgroundImagePath="http://www.loanscompete.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 mainElementQQ;



//debt redrect parameters
//var debtTarget1QQ ="http://q.qouces.com/cgi/r?;n=203;c=462107;s=6751;x=7936;f=200808041134330;u=j;z=TIMESTAMP;"; // billmccoy1 landing page
//var debtTarget2QQ ="http://g.gotmos.com/cgi/r?;n=203;c=462119;s=6752;x=7936;f=200808041140540;u=j;z=TIMESTAMP;"; //billmccoy2 landing page
//var debtTarget3QQ ="http://h.hurrum.com/cgi/r?;n=203;c=462140;s=6753;x=7936;f=200808041151240;u=j;z=TIMESTAMP;"; //billmccoy3 landing page

var debtTarget1QQ="http://www.loanscompete.com/quinstreet/form2/levela.htm";
var debtTarget2QQ="http://www.loanscompete.com/quinstreet/form2/levelb.htm";
var debtTarget3QQ="http://www.loanscompete.com/quinstreet/form2/levelc.htm";

var wasDrawnQQ=false;
var behindValue=["Not behind","1-2 Months","3-4 Months","4 or More months"];
var rateCreditValue=["Excellent","Good","Fair","Needs improvement","Poor"];
var loanTypeValue=["Refinance","Home Equity","Debt Consolidation","Home Purchase"];
var showStartImage=true;
var showStartImagePath="http://loanscompete.com/continue.gif";
var startText="Start saving here";
var showNumber=false;
var target="http://www.loanscompete.com/lcompete/mortgageForms/version4/step2.jsp";

var creditCardText = "Credit card debt";
var creditDebtValues=["0","5000","10000","20000"];


// the text class name is simple3txt


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 drawSimpleForm(elemID){
   initBarbosDHTMLAPI();
   BuildStateArrays();
    var elemQQ=document.getElementById(elemID);
        mainElementQQ=elemQQ; 
        if(elemQQ.style) elemQQ.style.overflow="hidden";

   if(W3C){
            if(showBackgroundImage) {     
                             elemQQ.style.backgroundImage="url('"+backgroundImagePath+"')";
                             elemQQ.style.backgroundRepeat="no-repeat";
                             elemQQ.style.backgroundPosition=""+backgroundImgeLocationX+" "+backgroundImgeLocationY;
                            }
            if(showBackgroundColor) elemQQ.style.backgroundColor=backgroundColor; 
             
           drawElemQQ(elemQQ);
           }

} 
             

function drawElemQQ(elem){
  if(wasDrawnQQ==false){
                            var divContainer=document.createElement("div");
                                divContainer.id="Container1"; 
                                var tableE=document.createElement("table");
                                    tableE.width="100%";
                                    tableE.height="150px";
                                var tbod=document.createElement("tbody");
                                var trE=document.createElement("tr");
                                var tdE=document.createElement("td");
                                var txt=document.createTextNode("State");
                                var sele=createSelect("stateTabQQ","stateTabQQ",State,true,1);
                                var noE;
                                    if(showNumber){
                                                       var tdEE=document.createElement("td");    
                                                           tdEE.width="40px";
                                                       var noI=document.createElement("img");
                                                           noI.src="http://loanscompete.com/jsp/mortgageForms/version4/one.gif";
                                                       tdEE.appendChild(noI);
                                                       tdEE.valign="bottom";
                                                       trE.appendChild(tdEE);
                                                       }     
                                    //tdE.height="60px";
                                    tdE.appendChild(txt);
                                    tdE.className="simple3txt";
                                    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://loanscompete.com/jsp/mortgageForms/version4/two.gif";
                                                       tdEE.appendChild(noI);
                                                       tdEE.valign="bottom";
                                                       trE.appendChild(tdEE);
                                                       } 
                                    txt=document.createTextNode("Are you currently behind in your payments?"); 
                              
                                    tdE.appendChild(txt);
                                    tdE.className="simple3txt";
                                    tdE.appendChild(document.createElement("br"));
                                    sele=createSelect("behindPay","behindPay",behindValue,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://loanscompete.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://loanscompete.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://loanscompete.com/jsp/mortgageForms/version4/five.gif";
                                                       tdEE.appendChild(noI);
                                                       tdEE.valign="bottom";
                                                       trE.appendChild(tdEE);
                                                       } 
                                    txt=document.createTextNode(creditCardText); 
                                    //tdE.height="60px";
                                    tdE.appendChild(txt);
                                    tdE.className="simple3txt";   
                                    tdE.appendChild(document.createElement("br"));
                                    sele=createSelectDebt("creditDebtQQ","creditDebtQQ",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=performActionSS;
                                          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=performActionSS;
                                          divEE.appendChild(inE);
                                          divEE.style.paddingTop="8px";
                                          divContainer.appendChild(divEE);
                                          }  
                                         
                             elem.appendChild(divContainer); 
                             wasDrawnQQ=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 performActionSS(){
var credit="";
var loan="";

var statee="";
var proTT="";
 var t=target;
var debtVal;

var val = document.getElementById("stateTabQQ").value;
    if(val.length<1) {showErrMsgQQ("Select a state");return;}statee=val;
    val= document.getElementById("behindPay").value;
    if(val.length<1) {showErrMsgQQ("Select a behind payment value");return;}proTT=val;
    /*val= document.getElementById("RateCreditTab1").value;
    //if(val.indexOf("Poor")!=-1 || val.indexOf("eds improvement") != -1) t=target1;
    if(val.length<1) {showErrMsgQQ("Select a credit rate");return;}credit=val;
    val= document.getElementById("LoanTypeTab1").value;
    if(val.length<1) {showErrMsgQQ("Select a loan type");return;}loan=val;*/
    debtVal = document.getElementById("creditDebtQQ").value;
    if(debtVal.length<1) {showErrMsgQQ("Select a card debt option");return;}
    
     
      if(debtVal == "5000") {
       t= debtTarget1QQ;
         t+="?SP=US";t+=getAbb(statee);
         t+="&BehindPmts=";
         var indice=document.getElementById("behindPay").selectedIndex;
         if(indice == 1) t+=0;
         else if(indice==2) t+=1;
         else if(indice==3) t+=3;
         else if(indice==4) t+=4;
         t+="&CrediCardDebtAmount=";
         t+=debtVal;
         t+=";"; 
window.location=t;return;}
      else if(debtVal == "10000") {
        t= debtTarget2QQ;
         t+="?SP=US";t+=getAbb(statee);
         t+="&BehindPmts=";
         var indice=document.getElementById("behindPay").selectedIndex;
         if(indice == 1) t+=0;
         else if(indice==2) t+=1;
         else if(indice==3) t+=3;
         else if(indice==4) t+=4;
         t+="&CrediCardDebtAmount=";
         t+=debtVal;
         t+=";";

        window.location=t;return;}
      else if(debtVal == "20000") {
         t= debtTarget3QQ;
         t+="?SP=US";t+=getAbb(statee);
         t+="&BehindPmts=";
         var indice=document.getElementById("behindPay").selectedIndex;
         if(indice == 1) t+=0;
         else if(indice==2) t+=1;
         else if(indice==3) t+=3;
         else if(indice==4) t+=4;
         t+="&CrediCardDebtAmount=";
         t+=debtVal;
         t+=";";

         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 showErrMsgQQ(txt){

var divE=document.createElement("div");
    divE.id="tempDivQQ";
    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;
    mainElementQQ.appendChild(divE); 
    setTimeout("hideErrMsgQQ()",2000);   
}

function hideErrMsgQQ(){
  if(document.getElementById("tempDivQQ")) mainElementQQ.removeChild(document.getElementById("tempDivQQ"));
}
