 	var query= new Array();
	var current_target;

    function makeRequest(url,target,runfunc) {
    	   if (http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
    	
    	
        var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function() { 
        	if (runfunc){ update_content(target,http_request,runfunc); }else update_content(target,http_request);
        	
        };
        http_request.open('GET', url, true);
        http_request.send(null);

    }

    function  update_content(target,http_request,runfunc) {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                
                document.getElementById(target).innerHTML = http_request.responseText ;
            if (runfunc) {
            	eval (runfunc);
            }
            
            } else {
                 document.getElementById(target).innerHTML ='There was a problem with the request.';
            }
        }else {
        //	if( document.getElementById('loading')){
        
        //	} else {
        	
			document.getElementById(target).innerHTML = "<img id='loading' src='http://beta.zebra.co.za/images/loading.gif'>Searching Zebra, please wait...";
        	//}
        	
        }

    }
    
    
    function update_main_view(request,value,name,opt){
    	if( document.getElementById(request+"_link")){
    		 if (document.getElementById(request).value != value )
    				{
    			document.getElementById("main_view").removeChild(document.getElementById(request+"_link"));
    			 update_date('0');
    			 //touch_geo();
    			if (opt > 0){
    				 update_main_view(request,value,name,opt);
    			}else{
    				 update_main_view(request,value,name);
    				 
    			}
    	} else {
    		document.getElementById("main_view").removeChild(document.getElementById(request+"_link"));
    		 update_date('0');
    	//	 touch_geo();
    	}
    	
    	
    	} else {
    
    		
    			
var main_view = document.getElementById("main_view");

view_port = document.createElement("li");
view_port.id=request+"_link";
    	if (opt) { 
    	view_port.style.listStyleType = "none";
    	view_port.style.display = "none";
    	} else {
load_port = document.createElement("a");
load_port.href="javascript:search_request('"+request+"','"+value+"','"+name+"');";
load_port.innerHTML = name;
view_port.appendChild(load_port);
    	}
input = document.createElement("input");
input.type = "hidden";
input.id = request;
input.value = value;

view_port.appendChild(input);

main_view.appendChild(view_port);
    	}
    	
 	
    	
    }
    
    function build_request(){
    	var query = '';
    	var main_view = document.getElementById("main_view");
    	    	
    	var linklist = main_view.getElementsByTagName('input');
	for (var i = 0;i < linklist.length;i++){ //linklist.length
		if (linklist.item(i).value != ''){
		var itemtest = "&"+linklist.item(i).id + "=" + linklist.item(i).value;
		
		query = query + itemtest;
		}
	} 
    	
   
    	return query;
    }
    
    

    
    
     function search_request(request,value,name,opt){
	var is_stack=request.indexOf('|');
	if (is_stack > 0){
		var request_stack= new Array();
		 request_stack.push(request.split("|"));
		 request_stack.push(value.split("|"));
		 request_stack.push(name.split("|"));
		  for(var j = 0; j < request_stack[0].length; ++j){
			//check to see if its the same 
		 	if ((  document.getElementById(request_stack[0][j]) && (document.getElementById(request_stack[0][j]).value != request_stack[1][j]) ) | !(document.getElementById(request_stack[0][j]))){
		  	update_main_view(request_stack[0][j],request_stack[1][j],request_stack[2][j]);
		     update_date('0');
		  //	alert('changed');
		 	}else {
		 		//alert('stayed the same');
		  		//check to see if its the same  do nothing if its the same 
		  	}
		  	
   				
		  }
   		
 	 makeRequest('/new_search.php?action=add_result' + build_request(),'theResult' );
 	 
	} else {
	update_main_view(request,value,name,opt);
	makeRequest('/new_search.php?action=add_result' + build_request() ,'theResult');
	}
    
    } 
    
    
    function touchpage(action){
    	var current_page = document.getElementById("page_no").value;
    	
    	if ((current_page > 0 ) | ( action > 0 )){
     		return parseInt(current_page) + parseInt(action);
    	}else { 
 	    	return false; 
    	}
        
    }
    
    
    
      function update_date(pageno,update){
    document.getElementById("page_no").value =  parseInt(pageno);
    if (update > 0){
    makeRequest('/new_search.php?action=add_result' + build_request() ,'theResult');
    }
    return;
    }	
    	
    
function select_dates(target,next_to,target_name){
	
var cal1xx = new CalendarPopup("testdiv1");
cal1xx.setCssPrefix("TEST");
cal1xx.showNavigationDropdowns();
cal1xx.setReturnFunction('update_dates');
	

	if(target){
		
		
		
		current_target = target;
		current_target_name = target_name;
			if(next_to){
	cal1xx.select(document.getElementById(target),next_to,'MM/dd/yyyy');
//	search_request(this.name,this.value,this.options[this.selectedIndex].innerHTML);
	} 
	
	}
}
    
function update_dates(one,two,three){
	//alert( + " " + two + " " + three + " " + four + " " + five);
	search_request(current_target,one+"-"+two+"-"+three,current_target_name+ " " +one+"-"+two+"-"+three);
	//alert(document.getElementById(current_target).value + current_target );
	
}
function select_currency(){
	
}
function touch_geo(obj,runfunc){
	//(request,value,name,opt);
	if(obj){
if (obj.name){
	



	if ((obj.name == "in_country") && document.getElementById("in_province_link") ){
		document.getElementById("main_view").removeChild(document.getElementById("in_province_link"));	
	}
	if (((obj.name == "in_country")  |  (obj.name == "in_province")   |  (obj.name == "in_suburb")  |  (obj.name == "in_area")  | (obj.name == "in_town") ) && document.getElementById("in_region_link")){
		document.getElementById("main_view").removeChild(document.getElementById("in_region_link"));	
	}	
	
	if (((obj.name == "in_country")  |  (obj.name == "in_province")  |  (obj.name == "in_region")  |  (obj.name == "in_suburb")  |  (obj.name == "in_area") ) && document.getElementById("in_town_link") ){
		document.getElementById("main_view").removeChild(document.getElementById("in_town_link"));	
	}
	if (((obj.name == "in_country")  |  (obj.name == "in_province")  | ( obj.name == "in_region")  |  (obj.name == "in_area")  | (obj.name == "in_town"))&& document.getElementById("in_suburb_link") ){
		document.getElementById("main_view").removeChild(document.getElementById("in_suburb_link"));
	}
	if (((obj.name == "in_country")  |  (obj.name == "in_province")  | ( obj.name == "in_region")  |  (obj.name == "in_suburb")  | (obj.name == "in_town"))&& document.getElementById("in_area_link") ){
		document.getElementById("main_view").removeChild(document.getElementById("in_area_link"));
	}			
}	
		
			
	
	}
	
	if (runfunc){
		//update_main_view(obj.name,obj.value,obj.options[obj.selectedIndex].innerHTML);
		search_request(obj.name,obj.value,obj.options[obj.selectedIndex].innerHTML)
		makeRequest('/new_search.php?action=touch_geo' + build_request(),"Geo_select" ); 
	}else makeRequest('/new_search.php?action=touch_geo' + build_request(),"Geo_select" );
	
}

    
    
function clean_geo(name){
	if(name== "in_country") {

	}
	
}



function change_currency(current,target,symbol){
	while (document.getElementById(current)){
	document.getElementById(current).innerHTML = symbol;
	document.getElementById(current).id = target;
	}
	
	document.getElementById('currency_type').value = target;
	currency_value =  target;
	
}
var currency_value ="ZAR"