
    myColors=Array()
    myColors[1]="99cccc";
    myColors[2]="33cccc";
    myColors[3]="669999";
    myColors[4]="336666";
    myColors[5]="3399cc";
    myColors[6]="003366";
    myColors[7]="333399";
    myColors[8]="6666cc";
    myColors[9]="cc9933";
    myColors[10]="ff9900";
    myColors[11]="ffcc66";
    myColors[12]="669933";
    myColors[13]="336600";
    myColors[14]="66cc00";
    myColors[15]="006633";
    myColors[16]="cc99cc";
    myColors[17]="ff3399";
    myColors[18]="990066";
    myColors[19]="663366";
    myColors[20]="660033";
    myColors[21]="ff3333";
    myColors[22]="cc0033";
    myColors[23]="993333";
    myColors[24]="993366";
    myColors[25]="330033";
    myColors[26]="cc6633";
    myColors[27]="993300";
    myColors[28]="cc9966";
    myColors[29]="996600";
    myColors[30]="336600";

    $(document).ready(function(){
    
        // test
        //$("#body").prepend('<div id="test" style="position:absolute;top:0;right:0;width:220px;font-size:11px;z-index:100;border:solid 1px #ccc;">hello</div>');
    	
        // popoup
        
        $("#ringme").click(function(e){
            
            e.preventDefault();

            var url="http://www.ringcentral.com/ringme/?uc=DD3372EC7F6C4A8ABFB425C90E62120D616857906559,0,&s=no&v=2";
            var w=375;
            var h=390;

            var winl = (screen.width - w) / 2;
            var wint = (screen.height - h) / 2;
            
            winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,resizable=no' 
            win = window.open(url, 'pop', winprops);	
            win.window.focus();            

        });
        
        // search by input
        
        $("#search-state-button").click(function(e){
            //getAjaxResult()
            e.preventDefault();            
            searchByInput();
         
        });
        
        // search by keypress
        
        $(document).keypress(function(event) {
                
            if (event.keyCode == '13') {
			
				if( $(".search-state-button-go-home").length==0 ){ 
					//getAjaxResult();
					event.preventDefault();
					searchByInput();
			
				}else{ 	
					goHomeAndSearch();

				}	
			}
            
        });
        
        randomFigure();        
        randomColor();
			
		$(".search-state-button-go-home").click(function(e){
		
			goHomeAndSearch();
		
		});		
    
    });    
	
	// go home
	
	function goHomeAndSearch(){
		
		var zipCode=$("#search-state-code").attr("value");
		
		if(zipCode!==""){
			//if(Number(zipCode)){
				window.location = "index.php?zipcode="+zipCode;
			/*}else{
				alert("Error!\nThis is not a number: "+zipCode);
			}*/
		}
		if(zipCode=="00000"){
			window.location = "services.php?lId=template";
		}
	
	}
        
    // do search by input
    
    function searchByInput(){    
        var dbSearch=false;
        var zipCode=$("#search-state-code").attr("value");
        
        if(zipCode!=="" && zipCode!="00000"){

           //if(Number(zipCode)){
                dbSearch="true";    
            /*}else{
                alert("Error!\nThis is not a number: "+zipCode);
            }*/ 

        }
        
        if(zipCode=="00000"){
			window.location = "services.php?lId=template";
		}
        
        
        if(dbSearch && zipCode!="00000"){
        
            //searchPhoneNumber("zipCode", zipCode);
            window.location = "index.php?zipcode="+zipCode;
        }
        
    }    
   
    // search, or call from flash direct
    
    function searchPhoneNumber(type, data){
           
        // $("#test").append("<br>type/data: "+type+"/"+data);
        
        $("#state-name").html("Searching ...");
 
        $("#state-name").delay(800).fadeIn();
        $("#locksmithspan").delay(800).fadeIn();
        $("#state-name-home").delay(800).fadeOut(function(){
        
            // call flash, reset map                   
            var myFlashMovie = document.getElementById("flashMap");
            myFlashMovie.callResetMap();                 
        
        });
        
        if(type=="zipCode"){
        
            $.get("php/search.php", { zipCode: data},    
                function(searchData){                
                                  
                    // $("#test").append("<br>1. searchData: "+searchData);

                    // $("#search-state-code").attr("value", "");
                    
                    var myd=searchData.split("+");
                    var phoneNum=myd[0];
                    var stateName=myd[1];
                    var stateCode=myd[2];
                    var imageCode=myd[3];
                    
                    // $("#test").append("<br>phoneNum: "+phoneNum+"<br>stateName: "+stateName+"<br>stateCode: "+stateCode);
                    
                    // phone num
                    var phoneNums=myd[0].split("|");
                    $(".phoneNumber").delay(800).html(phoneNums[0]);

                    if(phoneNums[1]!=undefined) {
                        $(".phoneNumberSub").delay(800).html(phoneNums[1]);
                    }else{
                        $(".phoneNumberSub").delay(800).html("");                    
                    }
                    
                    // state name
                    $("#state-name").delay(800).html(stateName);                    
                    
                    $("#flashMapOver img").attr("src", "img/pic_main-state-"+imageCode+".jpg");
                    $("#flashMapOver").delay(800).fadeIn();
                    
                    $(".pBottomHome #home").click(function(e){
                        
                        e.preventDefault();

						$("#search-state-code").attr("value", "");
						
                        $(".phoneNumber").html("1-800-248-LOCK");
                        $(".phoneNumberSub").html("5625");
                        
                        $("#flashMapOver").fadeOut();
                        $("#state-name").fadeOut();
                        $("#locksmithspan").fadeOut();
                        $("#state-name-home").fadeIn();
                    
                    });
                    
                });
            
        }else{

            $.get("php/search.php", { cityName: data },    
                function(searchData){
                
                    // $("#test").append("<br>2. searchData: "+searchData);
                    
                    // $("#search-state-code").attr("value", "");
                    
                    var myd=searchData.split("+");
                    var phoneNum=myd[0];
                    var stateName=myd[1]
                    var stateCode=myd[2];
                    var imageCode=myd[3];
                    
                    // phone num
                    var phoneNums=myd[0].split("|");
                    $(".phoneNumber").delay(800).html(phoneNums[0]);

                    if(phoneNums[1]!=undefined) {
                        $(".phoneNumberSub").delay(800).html(phoneNums[1]);
                    }else{
                        $(".phoneNumberSub").delay(800).html("");                    
                    }

                    // state name
                    $("#state-name").delay(800).html(stateName);                    
                    
                    $("#flashMapOver img").attr("src", "img/pic_main-state-"+imageCode+".jpg");
                    $("#flashMapOver").delay(800).fadeIn();
                    
                    $(".pBottomHome #home").click(function(e){
                        
                        e.preventDefault();
                       
					   $("#search-state-code").attr("value", "");
					   
                        $(".phoneNumber").html("1-800-248-LOCK");
                        $(".phoneNumberSub").html("5625");
                        
                        $("#flashMapOver").fadeOut();
                        $("#state-name").fadeOut();
                        $("#locksmithspan").fadeOut();
                        $("#state-name-home").fadeIn();
                    
                    });                    

                });
                
                $.get('new/data.php', 'state='+data, function(ret) { $('#lock_data').html(ret); } );

        }
        
        randomColor();
        randomFigure();
        amreicaFigure();
        
    }
    
    function randomColor(){
    
        var mynum=Math.floor(Math.random()*30)+1;
        var newcolor="#"+myColors[mynum];
        
        $("#state-name").css("color", newcolor);
        $("#locksmithspan").css("color", newcolor);
  
    } 
    
    function randomFigure(){
    
        var num=Math.floor(Math.random()*17)+1;
        
        $("#figure").attr("src", "img/pic_figure_"+num+".jpg");
    
    }
    
    function amreicaFigure(){
    
        //var num=Math.floor(Math.random()*17)+1;
        
        $("#figure2").attr("src", "img/amrica_flag.jpg");
    
    }
