 var obj_HTML;
 var areaCode;
 
	function loadSuppliers(favorites,keyword,screen,phonearea,listingid,categoryid){
		//var param='action=search&type=supplier&keyword='+keyword+'&screen='+screen+'&phonearea='+phonearea;
        var param='action=search&type=supplier&keyword='+keyword+'&screen='+screen;
		if (favorites>0)
			var param=param+"&favorites=1";
			
		if (listingid>0&&listingid!='undefined')
			var param=param+'&id='+listingid;
		if (categoryid>0&&categoryid!="undefined")
			var param=param+'&category_id='+categoryid;

		//Ajax_loadContent('ajax_dualResults.php',param,'supplierResults','supplierResults','HTML','');
        window.location=document.getElementById('host').value+'/dual_results.php?'+param;
	}
	
	function loadDistributors(favorites,keyword,screen,phonearea,listingid,categoryid){
		//var param='action=search&keyword='+keyword+'&type=distributor&screen='+screen+'&phonearea='+phonearea;
        var param='action=search&type=distributor&screen='+screen+'&phonearea='+phonearea;
		if (favorites>0)
			var param=param+"&favorites=1";

		if (listingid>0&&listingid!='undefined')
			var param=param+"&id="+listingid;
			
		if (categoryid>0&&categoryid!='undefined')
			var param=param+"&category_id="+categoryid;
			
		//Ajax_loadContent('ajax_dualResults.php',param,'distributorResults','distributorResults','HTML','');
        document.location.href=document.getElementById('host').value+'/dual_results.php?'+param;
	
	}
    
   
	
	function cleanDistributorArea(){
		document.getElementById('distributorResults').innerHTML="&nbsp;";
	}
	
	
	
	function searchagain(type){
    
		var keyword=document.getElementById('keyword').value;
		if (document.getElementById('phonearea'))
			var phonearea=document.getElementById('phonearea').value;
		else var phonearea=0;
		
		if (phonearea>0&&keyword){
            //loadSuppliers(0,keyword,0,'',0);
            //loadDistributors(0,keyword,0,phonearea,0);
            if(type == 'supplier') {
                param="keyword="+keyword;
                document.location.href=document.getElementById('host').value+'/dual_results.php?type=supplier&'+param; 
            }
			else {
                param="keyword="+keyword+"&phonearea="+phonearea;
                document.location.href=document.getElementById('host').value+'/dual_results.php?type=both&'+param; 
            }
            
		} else {
			if (document.getElementById('distributorResults'))
				cleanDistributorArea();
			loadSuppliers(0,keyword,0,'',0);
		}
       
	
	
	}
	
	
	// CHANGE TITLE
		
	function ajax_loadHTMLDoc(url,phonearea) {
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = ajax_processReqChange;
			req.open("GET", url, true);
			req.send(null);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {
				req.onreadystatechange = ajax_processReqChange;
				req.open("GET", url, true);
				req.send();
			}
		}
	}
	
	function ajax_processReqChange() {
		// only if req shows "complete"
		if (req.readyState == 4) {
			// only if "OK"
			if (req.status == 200) {
				// ...processing statements go here
				response  = req.responseText;
				if(response) {
                    if(obj_HTML == "title") {
                        //Promotional Products Distributors for Area Code $phonearea
                        document.title = "Promotional Products Distributors for Area Code "+areaCode+" "+response;
                        document.getElementById("contact_areacode").innerHTML = "Promotional Products Distributors for Area Code "+areaCode+" "+response;
                    } 
                    else if(obj_HTML == "form") {
                        document.listing.tagtitle.value = "Promotional Products "+response;
                        document.listing.tagheading.value = "Promotional Products "+response;
                        document.listing.tagdescription.value = "Your local distributor for Promotional Products in "+response+" and the surrounding areas, including Logo Pens, T-Shirts, Logo Apparel, Corporate Promotional Items and more";
                    }
				}
                else if(obj_HTML == "form") {
                    document.listing.tagtitle.value = "";
                    document.listing.tagheading.value = "";
                    document.listing.tagdescription.value = "";
                }
                else if(obj_HTML == "title") {
                    document.title = "Promotional Products Distributors for Area Code "+areaCode;
                    document.getElementById("contact_areacode").innerHTML = "Promotional Products Distributors for Area Code "+areaCode;
                }
			} else {
				alert("There was a problem retrieving the XML data:\n" + req.statusText);
			}
		}
	}
	
	function ajax_ChangeTitle(phonearea,obj){
        this.areaCode = phonearea;
        this.obj_HTML = obj;
		var host=document.getElementById('host').value;
		var url=host+'/includes/code/ajax_changeTitle.php?phonearea='+phonearea;
		if(url != '') {
			return (ajax_loadHTMLDoc(url,phonearea,obj));
		}
	}