var showBackgroundImage=true;
var backgroundImagePath="/images/leadagentbg.gif";
var backgroundImgeLocationX = 1;
var backgroundImgeLocationY = 1;
var showBackgroundColor=false;
var backgroundColor="#DBEADB";
var target="http://www.smartquote.com/smarthome/saveCustomerInfoS";

var State= new Array();
var Code=new Array();
var isIE = navigator.appName.indexOf("Microsoft Internet Explorer")!= -1 ? true : false;
var textClassName1="";
var textClassName2="";

var showTitleText=true;
var titleTextClassName="";
var titleTextLocationY="20";
var titleTextLocationX="15";
var titleText=" <b>Lower your marketing costs now! </b>";

// search button
var showImageForButton=true;
var imageButtonPath="/images/largesubmit.gif";
var buttonText="Search price";
var buttonLocationX="30";
var buttonLocationY="250";


var fieldsLeft=30;
var fieldsTop=58;


//your full name

var showFullName=true;
var fullNameText="Your full name : ";


//company
var showCompany=true;
var companyText="Company";

//streetaddress

var showAddress=false;
var addressText="Street Address:";

//streetaddress

var showCity=false;
var cityText="City:";


//state

var showState=true;
var stateText="State:";
var stateType="text";

//zip

var showZip=false;
var zipText="Zip:";

//phone

var showPhone=true;
var phoneText="Phone:";

//email

var showEmail=true;
var emailText="Email:";

//email confirm

var showEmailConf=false;
var emailConfText="Email (confirm):";

//web site
var showWebSite=true;
var webSiteText="Website:";

//type of business
var showTypeBusinness=false;
var typeBusinnesText="Business:";
var business=["mortgage","insurance","debt","loan modification"];


var elemContainer;

function drawContactForm(elemID){
var elemWapper;
var elem=document.createElement("div");
    elem.style.position="relative";
    elem.style.width="100%";
    elem.style.height="100%";
    elem.style.overflow="hidden";
    elemContainer=elem;
BuildStateArrays();

if(document.getElementById){
                           elemWapper=document.getElementById(elemID);
                           var formaE;
                           if(isIE) formaE=document.createElement("<form method='post' name='forma'>");
                           else {
                                  formaE=document.createElement("form");
                                  formaE.name="forma";
                                  formaE.method="post";
                                }
                          
                           if(showBackgroundImage) {     
                             elem.style.backgroundImage="url('"+backgroundImagePath+"')";
                             elem.style.backgroundRepeat="no-repeat";
                             elem.style.backgroundPosition=""+backgroundImgeLocationX+" "+backgroundImgeLocationY;
                            }
                           if(showBackgroundColor) elem.style.backgroundColor=backgroundColor;

                           if(showTitleText) addTextToForm(elem,titleTextClassName,titleTextLocationX,titleTextLocationY,titleText,textClassName1,"fullname");
                           
                           var spanE=document.createElement("span");
                               spanE.style.position="absolute";
                               spanE.style.top=fieldsTop
                               spanE.style.left=fieldsLeft;
                           var tableE=document.createElement("table");
                           var tbodyE=document.createElement("tbody");
                               tableE.width="100%";
                               //tableE.height="100%"; 
                           
                           if(showFullName) addTextInputToFormTableSimple(tbodyE,fullNameText,textClassName1,"fullname");

                           if(showCompany) addTextInputToFormTableSimple(tbodyE,companyText,textClassName1,"company");
                           if(showAddress) addTextInputToFormTableSimple(tbodyE,addressText,textClassName1,"address");
                           if(showCity) addTextInputToFormTableSimple(tbodyE,cityText,textClassName1,"city");
                           if(showState && stateType=="select") addTextSelectToFormTableSimple(tbodyE,stateText,State,textClassName1,"user_state");
                           if(showState && stateType!="select") addTextInputToFormTableSimple(tbodyE,stateText,textClassName1,"user_state");
                           if(showZip) addTextInputToFormTableSimple(tbodyE,zipText,textClassName1,"zip");
                           if(showPhone) addTextInputToFormTableSimple(tbodyE,phoneText,textClassName1,"phone");
                           if(showEmail) addTextInputToFormTableSimple(tbodyE,emailText,textClassName1,"email");
                           if(showEmailConf) addTextInputToFormTableSimple(tbodyE,emailConfText,textClassName1,"emailconf");
                           if(showWebSite) addTextInputToFormTableSimple(tbodyE,webSiteText,textClassName1,"website");
                           if(showTypeBusinness) addTextSelectToFormTableSimple(tbodyE,typeBusinnesText,business,textClassName1,"businness");
                           tableE.appendChild(tbodyE);  
                           spanE.appendChild(tableE);                          
                           elem.appendChild(spanE);
                           var buttonE=document.createElement("span");
                               buttonE.style.position="absolute";
                               buttonE.style.left=buttonLocationX;
                               buttonE.style.top= buttonLocationY; 
                           if(showImageForButton){
                               var imgEl=document.createElement("img");
                                   imgEl.src=imageButtonPath;
                                   imgEl.onclick=checkForm;  
                                   buttonE.appendChild(imgEl); 
                                   buttonE.style.cursor="pointer";  

                            }
                            else{
                                 inputE=document.createElement("input");
                                 inputE.type="button";
                                 inputE.value=buttonText;
                                 inputE.onclick=checkForm;
                                 buttonE.appendChild(inputE);
                            }
                            elem.appendChild(buttonE);
                            formaE.appendChild(elem);
                           }

elemWapper.appendChild(formaE);

}


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 addTextToForm(ele,sty,x,y,txt){

 var spanE=document.createElement("span");
     spanE.className=sty;
     spanE.style.position="absolute";
     spanE.style.left=x;
     spanE.style.top=y;
     spanE.innerHTML=txt; 
     ele.appendChild(spanE);
}

function createSelect(name,id,val,first,sizes){
  var sel=document.createElement("select");
      if(isIE) sel=document.createElement("<select name='"+name+"' size='"+sizes+"'>");
      sel.name=name;
      sel.id=id;
      if(!isIE)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 addSelectToForm(ele,values,title,x,y,alig,SID){

var elemE=document.createElement("span");
    elemE.style.position="absolute";
    elemE.style.left=x;
    elemE.style.top=y;
var bold=document.createElement("b");    
    bold.appendChild(document.createTextNode(title));
    elemE.appendChild(bold);
    if(alig=="vertical") elemE.appendChild(document.createElement("br"));
var selectE=createSelect(SID,SID,values,true,1);
    elemE.appendChild(selectE);
     
    ele.appendChild(elemE);
} 

function addTextInputToFormTableSimple(ele,txt,sty,nam){
 var trE=document.createElement("tr");
  var tdE=document.createElement("td");  
       
      tdE.className=sty;
      tdE.align="left";
      tdE.innerHTML=txt; 
      trE.appendChild(tdE);
       tdE=document.createElement("td");
      var inputE;
      if(isIE) inputE=document.createElement("<input name='"+nam+"'>");
      else {
            inputE=document.createElement("input");
            inputE.name=nam;
           }  
     tdE.appendChild(inputE);
     trE.appendChild(tdE);  
     ele.appendChild(trE);
}

function addTextSelectToFormTableSimple(ele,txt,val,sty,nam){
 var trE=document.createElement("tr");
  var tdE=document.createElement("td");  
       
      tdE.className=sty;
      tdE.align="left";
      tdE.innerHTML=txt; 
      trE.appendChild(tdE);
       tdE=document.createElement("td");
      var inputE=createSelect(nam,nam,val,true,1);
     tdE.appendChild(inputE);
     trE.appendChild(tdE);  
     ele.appendChild(trE);
}

function checkForm(){
var zipFormat=/^\d{5}$/;
var phoneFormat=/^\d{3}-\d{3}-\d{4}$/;
var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

   if(document.forma.fullname.value.length<1) {showErrMsg("You must enter your full name",40);return false;}
   //if(document.forma.address.value.length<1) {showErrMsg("You must enter your addess",50);return false;}
  // if(document.forma.city.value.length<1) {showErrMsg("You must enter your city",50);return false;}
   if(document.forma.user_state.value.length<1) {showErrMsg("You must enter your state",40);return false;}
   //if(document.forma.zip.value.length<1) {showErrMsg("You must enter your zip area code",40);return false;}
   //else if(!document.forma.zip.value.match(zipFormat)){showErrMsg("The zip code format has to be XXXXX",40);return false;} 
   if(document.forma.phone.value.length<1) {showErrMsg("You must enter your phone number",40);return false;}
   else if(!document.forma.phone.value.match(phoneFormat)){showErrMsg("The phone format is XXX-XXX-XXXX",40);return false;} 
   if(document.forma.email.value.length<1) {showErrMsg("You must enter your email address",40);return false;}
   else if(!document.forma.email.value.match(emailFilter)){showErrMsg("The format of your email address is wrong",40);return false;} 
   //if(document.forma.email.value != document.forma.emailconf.value) {showErrMsg("The email addresses does not match",40);return false;} 
   //if(document.forma.businness.value.length<1) {showErrMsg(" Select a businness",70);return false;}

   document.forma.action=target;
   document.forma.submit();
}

function showErrMsg(txt,left){
var pos=getContainerPosition();
var divE=document.createElement("div");
    divE.id="tempDiv";
    divE.style.position="absolute";
    divE.style.zIndex="50";
    divE.style.textAlign="center";
    divE.style.backgroundColor="yellow";
    divE.style.fontWeight="bold";
    divE.style.fontStyle="italic";
    divE.style.top=pos.top+10+"px";
    divE.style.left=pos.left+left+"px";
    divE.style.fontSize="1.2em";
    divE.innerHTML=txt;
    document.body.appendChild(divE); 
    setTimeout("hideErrMsg()",2000);   
}

function hideErrMsg(){
  if(document.getElementById("tempDiv")) document.body.removeChild(document.getElementById("tempDiv"));
}

function getContainerPosition(){
var parent= elemContainer;
var leftt=0;
var topp=0;
while(parent){
                    leftt+=parent.offsetLeft;
					topp+=parent.offsetTop;
					parent=parent.offsetParent;
			}
if(navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined"){
                    topp+=document.body.topMargin;
					leftt+=document.body.leftMargin;
					} 			
return {left:leftt,top:topp}
}
