var showBackgroundImage=false;
var backgroundImagePath="bg.jpg";
var backgroundImgeLocationX = 100;
var backgroundImgeLocationY = 60;
var showBackgroundColor=true;
var backgroundColor="";

var State= new Array();
var Code=new Array();
var isIE = navigator.appName.indexOf("Microsoft Internet Explorer")!= -1 ? true : false;
var target="http://www.4homes.com/homes/moverWizardB";
var asterix="*";

//service type
var showService = true;
var serviceText="Service Type: ";
var serviceTextClassName="txt1";
var serviceValues=["Select","Long Distance Movers","Local Movers","Auto Transport","International Movers","Self Service Moves","Corporate Relocation","Packing Materials","Storage","Special Movers"];
var serviceValuesClassName="txt1";
var serviceAlign="horizontal";
var serviceLocationX=20;
var serviceLocationY=10;
var showServiceAsterix=false;




//moving to state

var showMovingToState=true;
var movingToStateLocationX="20";
var movingToStateLocationY="70";
var movingToStateText="Moving to: ";
var textAlignMovingToState="horizontal";
var showMovingToAsterix=true;
var movingToTextClassName="txt2";
var movingToValueClassName="";



// moving from zip
var showMovingFromZip=true;
var movingFromZipLocationX="20";
var movingFromZipLocationY="40";
var movingFromZipText="From zip: ";
var textAlignMovingFromZip="horizontal";
var fromZipClassName="txt2";
var fromZipShowAsterix=true;


//moving size
var showMoveSize = true;
var moveSizeText="Moving weight: ";
var moveSizeTextClassName="txt2";
var moveSizeValues=["Partial Home, under 2000 lbs","Studio, 2000 lbs","Studio, 2450 lbs","1 Bedroom, 2940 lbs","1 Bedroom, 3850 lbs","2 Bedroom, 4550 lbs","2 Bedroom, 6300 lbs","3 Bedroom, 7700 lbs","3 Bedroom, 8750 lbs","4 Bedroom, 9800 lbs","4 Bedroom, 11200 lbs","Over 11300 lbs"];
var moveSizeValuesClassName="";
var moveSizeAlign="horizontal";
var moveSizeLocationX=20;
var moveSizeLocationY=100;
var showMoveSizeAsterix=false;




// next button
var showImageForNextButton=true;
var imageNextButtonPath="http://www.4homes.com/images/get-quotes.gif";
var nextButtonText="Next >> ";
var nextButtonLocationX="170";
var nextButtonLocationY="130";




//
var data;
var elemWapper;
var formE;

function drawMoverForm(elemID){

var elem1=document.createElement("div");
    elem1.style.position="relative";
    elem1.style.width="100%";
    elem1.style.height="100%";
    elem1.id="panel1";
    elem1.style.overflow="hidden";


BuildStateArrays();

if(document.getElementById){
                           elemWapper=document.getElementById(elemID);
                           if(isIE)formE=document.createElement("<form name='forma'>");
                           else {
                                 formE=document.createElement("form");
                                 formE.name="forma";
                                }
                           if(showBackgroundImage) {     
                             elem1.style.backgroundImage="url('"+backgroundImagePath+"')";
                             elem1.style.backgroundRepeat="no-repeat";
                             elem1.style.backgroundPosition=""+backgroundImgeLocationX+" "+backgroundImgeLocationY;
                            }
                           if(showBackgroundColor) elem1.style.backgroundColor=backgroundColor;

                        

                           
                
                          if(showService)   addSelectToForm(elem1,serviceValues,serviceText,serviceLocationX,serviceLocationY,serviceAlign,"serviceTypeID",serviceTextClassName,serviceValuesClassName,showServiceAsterix,false,"sI");              
                                   


                          if(showMovingToState) addSelectToForm(elem1,State,movingToStateText,movingToStateLocationX,movingToStateLocationY,textAlignMovingToState,"movingToState",movingToTextClassName,movingToValueClassName,showMovingToAsterix,true,"mTI");
                
                           if(showMovingFromZip) addTextFieldToForm(elem1,movingFromZipLocationX,movingFromZipLocationY,movingFromZipText,"fromzip",5,textAlignMovingFromZip,fromZipClassName,fromZipShowAsterix);

                          if(showMoveSize)   addSelectToForm(elem1,moveSizeValues,moveSizeText,moveSizeLocationX,moveSizeLocationY,moveSizeAlign,"moveSizeID",moveSizeTextClassName,moveSizeValuesClassName,showMoveSizeAsterix,true,"mS");              
                          
                          addFromZipFinderLink(elem1,parseInt(movingFromZipLocationX)+150,movingFromZipLocationY); 
                          
                           
                           addNextButtonStep(elem1,nextButtonLocationX,nextButtonLocationY);

                       //if(location.search.indexOf("e=1")!= -1) {showMessage("The zip code you select doesn't exists");}

                            }
//formE.appendChild(elem1);
elemWapper.appendChild(elem1);

}

function addFromZipFinderLink(ele,x,y){
 var spanE=document.createElement("span");
     spanE.style.position="absolute";
     spanE.style.left=x;
     spanE.style.top=y;
var aE=document.createElement("a");
    aE.href="javascript: void showFromZipFinder();"; 
    aE.innerHTML="Zip Finder";
     spanE.appendChild(aE); 
     ele.appendChild(spanE);
}




function showFromZipFinder(){
var w=window.open("http://www.4homes.com/homes/move2/zipFinder.jsp?i=fromzip","","width=520px,height=400px,toolbar=no,scrollbars=yes");
w.moveTo(200,100);
return true;
}



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 addTextFieldToForm(ele,x,y,txt,nam,zis,alig,txtCla,ast){

 var spanE=document.createElement("span");
     spanE.style.textAlign="left";
     spanE.style.position="absolute";
     spanE.style.left=x;
     spanE.style.top=y;
     spanE.id=nam+"con";
var txtElem=document.createElement("span");    
    txtElem.innerHTML=txt;
    if(txtCla.length>1) txtElem.className=txtCla;  
     spanE.appendChild(txtElem);
var  inputE;
     if(isIE) inputE=document.createElement("<input name='"+nam+"' size='"+zis+"'>");
     else {
           inputE=document.createElement("input");
           inputE.name=nam;
           inputE.size=zis;
          }
     inputE.id=nam;
     inputE.type="text";
     if(location.search.indexOf("&fZ=")!= -1){
             var i1=location.search.indexOf("&fZ=")+4;
             inputE.value=location.search.substring(i1,i1+5);
           }
     if(alig=="vertical") spanE.appendChild(document.createElement("br")); 
     spanE.appendChild(inputE);
     if(ast){
            var e=document.createElement("span");
                e.innerHTML=asterix;
                e.className=txtCla;
                spanE.appendChild(e);
           }    
     ele.appendChild(spanE);
}

function createSelect(name,id,val,first,sizes,ind){
  var sel=document.createElement("select");
  var sele=false;
  var index=0;
      if(location.search.indexOf("&"+ind+"=")!= -1){
                                                    sele=true;
                                                   var fi=location.search.indexOf("&"+ind+"=")+2+ind.length;
                                                   var sec=location.search.indexOf("&",fi);
                                                   index=parseInt(location.search.substring(fi,sec));
                                                   } 
                                                        
      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];
                                   if(sele){
                                            var v;
                                            if(first) v=index-1;
                                            else v=index;
                                           if(i==v) op.selected="selected";
                                            } 
                                   sel.appendChild(op);
                               }
      
      
return sel;      
} 


function addSelectToForm(ele,values,title,x,y,alig,SID,txtCla,valCla,ast,fir,selI){

var elemE=document.createElement("span");
    elemE.style.position="absolute";
    elemE.style.left=x;
    elemE.style.top=y;
    elemE.style.textAlign="left";
    elemE.id=SID+"con";
var txtElem=document.createElement("span");
    txtElem.innerHTML=title;
    if(txtCla.length>1) txtElem.className=txtCla; 
    elemE.appendChild(txtElem);
    if(alig=="vertical") elemE.appendChild(document.createElement("br"));
var selectE=createSelect(SID,SID,values,fir,1,selI);
    if(valCla.length>1) selectE.className=valCla;
    elemE.appendChild(selectE);
    if(ast){
            var e=document.createElement("span");
                e.innerHTML=asterix;
                e.className=txtCla;
                elemE.appendChild(e);
           } 
    ele.appendChild(elemE);
} 


function addNextButtonStep(elem,x,y){

var elemE=document.createElement("span");
      elemE.style.position="absolute";
      elemE.style.left=x;
      elemE.style.top=y;
if(showImageForNextButton){
                               
                               var imgEl=document.createElement("img");
                                   imgEl.src=imageNextButtonPath;
                                   imgEl.onclick=actionNextStepPerformed;  
                                   elemE.appendChild(imgEl); 
                                   elemE.style.cursor="pointer";   
                                   elem.appendChild(elemE);

                            }
                            else{
                                 inputE=document.createElement("input");
                                 inputE.type="button";
                                 inputE.value=nextButtonText;
                                 inputE.onclick=actionNextStepPerformed;
                                 elemE.appendChild(inputE); 
                                 elem.appendChild(elemE);
                            }
}

function actionNextStepPerformed(){

var zipFormat=/^\d{5}$/;

var val = document.getElementById("serviceTypeID").value;
    if(val=="Select"){showMessage("Select a service type");return false;}
    val=document.getElementById("fromzip").value;
    if(val.length<1) {showMessage("Enter the depart area zip code");return false;}
    if(!val.match(zipFormat)) {showMessage("Zip code format is XXXXX");return false;}
    val=document.getElementById("movingToState").value;
    if(val.length<1) {showMessage("Select the destination state");return false;}
    val=document.getElementById("moveSizeID").value;
    if(val.length<1) {showMessage("Select a moving size");return false;}
var t=target;
    t+="?fZ="+encodeURIComponent(document.getElementById("fromzip").value); 
    t+="&mTS="+encodeURIComponent(document.getElementById("movingToState").value);
    t+="&mS="+encodeURIComponent(document.getElementById("moveSizeID").value);
    t+="&wizardPart=step1";
    t+="&sT="+encodeURIComponent(document.getElementById("serviceTypeID").value);
    t+="&sTI="+document.getElementById("serviceTypeID").selectedIndex;
    t+="&mTI="+document.getElementById("movingToState").selectedIndex;
    t+="&mSI="+document.getElementById("moveSizeID").selectedIndex;
    location.href=t;
}


function showMessage(txt){
 
var divE=document.createElement("div");
var spanE=document.createElement("span");
    spanE.style.textAlign="center";
    divE.id="tempDiv";
    divE.style.position="absolute";
    divE.style.zIndex="5";
    divE.style.textAlign="center";
    divE.style.width="100%";
    spanE.style.backgroundColor="yellow";
    spanE.style.fontWeight="bold";
    spanE.style.fontStyle="italic";
    var pageL=getPageScroll();
    divE.style.top=parseInt(pageL.top)+10;
    divE.style.left="0px";
    divE.style.fontSize="1.2em";
    spanE.innerHTML=txt;
    divE.appendChild(spanE);
    document.body.appendChild(divE); 
    setTimeout("hideErrMsg()",2000);   
}

function hideErrMsg(){
  if(document.getElementById("tempDiv")) document.body.removeChild(document.getElementById("tempDiv"));

}

function getPageScroll(){
var scroll={left:0,top:0};
    if(document.body && document.body.scrollTop != "undefined") {
          scroll.left+=document.body.scrollLeft;
          scroll.top+=document.body.scrollTop;
          if(document.body.parentNode && document.body.parentNode.scrollTop != "undefined"){
             scroll.left+=document.body.parentNode.scrollLeft;
             scroll.top+=document.body.parentNode.scrollTop;
                                      }
          }
     else if(typeof window.pageXOffset != "undefined"){
           scroll.left+= window.pageXOffset;
           scroll.top+= window.pageYOffset;
         }
return scroll;
}
