﻿    var ajax = new sack();
    var bar2;

    function trace(txt)
    {
        document.getElementById('debugTrace').innerHTML +=txt;
     
    }
    
	function searchResult()
	{

	    
	    var search='';
	    
		ajax.requestFile = "result.aspx?advance=1&search=1&record="+ document.getElementById('record').value;
	
		if (document.getElementById('postal').value != "")
		{
			ajax.requestFile += "&amp;postal=" + document.getElementById(listProvince).value;
		}
		
		var ajax = new sack();
		ajax.onCompletion   = showContent;	
		ajax.onLoading      = showWaitMessage;
		ajax.onFail         = showFail;
		ajax.onError        = showError;
		ajax.runAJAX();	
		
		trace("runajax");
		
	}

    function singleSearchPhone()
    {
        var valuePhone = document.getElementById('phone').value
		
		ajax.requestFile	= "result.aspx?search=1&amp;phone="+ valuePhone;
		ajax.onCompletion   = showContent;	
		ajax.onLoading      = showWaitMessage;
		ajax.onFail         = showFail;
		ajax.onError        = showError;
		ajax.runAJAX();	
		window.status+= "Run Ajax Phone Search";
    
    }
    
    function changeState()
    {
        singleSearchResult();
    }
    
	function singleSearchResult()
	{
	    var record = document.getElementById('record').value
	    if ( record[ record.length -1] == ' ' || record.length < 4 )
	    {
	        return;
	    }
	    
	    if( bar2 == undefined)
	    {
	     bar2= createBar(320,15,'white',1,'black','green',85,7,3);
	    }
	    else
	    {
	        bar2.showBar();
	    }
	     
	
		
		var _param  = "";
	
		if (document.getElementById(listProvince).value != "AL")
		{
			_param = "&state=" + document.getElementById(listProvince).value;
		}
		
		if (document.getElementById("city").value != "")
		{
		    _param += "&city=" + document.getElementById("city").value;
		}
        
        if (document.getElementById("phone").value != "")
		{
		    _param += "&phone=" + document.getElementById("phone").value;
		}
		
		callPage =  "result.aspx?search=1&advance=1&record="+ record + _param;
		trace(callPage);
		ajax.requestFile	= callPage;
		
		ajax.onCompletion   = showContent;	
		ajax.onLoading      = showWaitMessage;
		ajax.onFail         = showFail;
		ajax.onError        = showError;
		ajax.runAJAX();	
		window.status= "runajax :" + ajax.requestFile;
		
		
	}



    function showError()
	{
		trace("Error ! "  + ajax.responseStatus[0]);
	}

	function showFail()
	{
		trace("Fail to load");
	}

	function showWaitMessage()
	{
		document.getElementById('statusSearch').innerHTML = " Loading...";
		trace(" showWaitMessage ");
	}
	
	function showContent()
	{
	    bar2.hideBar();
		window.status+= "showContent()";
		contentObj = document.getElementById('contentContainer');
		contentObj.innerHTML = ajax.response;
		document.getElementById('statusSearch').innerHTML ="";

		//alert(ajax.response);
	}

	function createLocation()
	{
		document.forms[1].location.value=  document.getElementById('city').value +",canada";
		showLocation();
	}