		//need to change this url to mimic the current server
//	var this_url = "http://192.168.100.26/usedprice/";
//	var this_sslurl = "http://192.168.100.26/usedprice/";
	//var this_url = "http://209.62.0.164/";
	//var this_sslurl = "https://209.62.0.164/";
//	var this_url = "http://www.usedprice.com/";
//	var this_sslurl = "https://www.usedprice.com/";
	var this_url = "http://www.usedprice.com.cluster/";
	var this_sslurl = "https://www.usedprice.com.cluster/";

	function ClipBoard(divname) {
		textRange =document.getElementById(divname).value;
		//textRange.execCommand("Copy");
		window.clipboardData.setData('text',textRange);

	}

	
function copy_clip(divname)
{
	var browser=navigator.appName;
	if (browser == "Netscape" || browser == "Opera") {
		alert('The copy function does not work in your browser. Please click on the text to highlight and then copy the text by pressing Control-C');
	}
	meintext = document.getElementById(divname).value;
 if (window.clipboardData) 
   {
   
   // the IE-manier
   window.clipboardData.setData("Text", meintext);
   
   // waarschijnlijk niet de beste manier om Moz/NS te detecteren;
   // het is mij echter onbekend vanaf welke versie dit precies werkt:
   }
   else if (window.netscape) 
   { 
   
   // dit is belangrijk maar staat nergens duidelijk vermeld:
   // you have to sign the code to enable this, or see notes below 
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   
   // maak een interface naar het clipboard
   var clip = Components.classes['@mozilla.org/widget/clipboard;1']
                 .createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;
   
   // maak een transferable
   var trans = Components.classes['@mozilla.org/widget/transferable;1']
                  .createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;
   
   // specificeer wat voor soort data we op willen halen; text in dit geval
   trans.addDataFlavor('text/unicode');
   
   // om de data uit de transferable te halen hebben we 2 nieuwe objecten 
   // nodig om het in op te slaan
   var str = new Object();
   var len = new Object();
   
   var str = Components.classes["@mozilla.org/supports-string;1"]
                .createInstance(Components.interfaces.nsISupportsString);
   
   var copytext=meintext;
   
   str.data=copytext;
   
   trans.setTransferData("text/unicode",str,copytext.length*2);
   
   var clipid=Components.interfaces.nsIClipboard;
   
   if (!clip) return false;
   
   clip.setData(trans,null,clipid.kGlobalClipboard);
   
   }
   alert("Following info was copied to your clipboard:\n\n" + meintext);
   return false;
}

	
	
	function clearButtons(buttonGroup){ 
	   for (i=0; i < buttonGroup.length; i++) { 
		
	    if (buttonGroup[i].checked == true) { 
	    buttonGroup[i].checked = false 
	    }
	
	   } 
	
	} 	
				
	function exceed_maxlength(varname, len) {
		var var_cnt = varname.length;
		if (var_cnt >= len) {
			return false;	
		}
	}
	function  get_yearmo() {
		var now = new Date();
		var mo = now.getMonth();
		var year        = now.getYear();
		if (mo == 1) mo = "01";
		if (mo == 2) mo = "02";
		if (mo == 3) mo = "03";
		if (mo == 4) mo = "04";
		if (mo == 5) mo = "05";
		if (mo == 6) mo = "06";
		if (mo == 7) mo = "07";
		if (mo == 8) mo = "08";
		if (mo == 9) mo = "09";
		var this_yearmo = year + mo;
		return this_yearmo;
	}

	function changeRule(theNumber, hide) {	
		var theRules = new Array();	
		if (document.styleSheets[0].cssRules) {		
			theRules = document.styleSheets[0].cssRules;	
		} 
		else if (document.styleSheets[0].rules) {		
			theRules = document.styleSheets[0].rules;	
		}	
		if (hide == "y") theRules[theNumber].style.display = 'none';
		else  theRules[theNumber].style.display = 'none';
	}

	function trim(str, chars) {   
	    return ltrim(rtrim(str, chars), chars);   
	}   
	  
	function ltrim(str, chars) {   
	    chars = chars || "\\s";   
	    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");   
	}   
	  
	function rtrim(str, chars) {   
	    chars = chars || "\\s";   
	    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");   
	} 	

	//the functions below will be used to connect the search using ajax
    function xml_connect() {
        var httpRequest;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
               //This causes a damn error when data returned isn't XML
                httpRequest.overrideMimeType('text/xml');
                // See note below about this line
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) {
                           try {
                                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                               } 
                             catch (e) {}
                          }
                                       }

        if (!httpRequest) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
		return httpRequest;
    }

	function explodeArray(item,delimiter) {
		tempArray=new Array(1);
		var Count=0;
		var tempString=new String(item);
		while (tempString.indexOf(delimiter)>0) {
			tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
			tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
			Count=Count+1
		}
		tempArray[Count]=tempString;
		return tempArray;
	}
	
	function entsub(this_func) {
  		if (window.event && window.event.keyCode == 13){
	  		if (this_func == "query_search_go") {
		  		toggle_searchsubmit();
		  		//toggle_searchbutton();
	  		}
	  		else if (this_func == "email_profform") {
		  		send_profile();
	  		}
	  		else if (this_func == "send_message") {
		  		submit_send();
	  		}	  	
	  		else if (this_func == "prof_directions") {
		  		var dirid = document.getElementById("prof_id").value;
		  		find_directions(dirid);	
	  		}	
	  		//else if (this_func == "dir_search") dir_search('','');
	  		else if (this_func == "login_sess") login_sess();
		}
  		else
    		return true;
    }
    	
	function textCounter(field,cntfield,maxlimit) {
		if (field.value.length > maxlimit) // if too long...trim it!
			field.value = field.value.substring(0, maxlimit);
			// otherwise, update 'characters left' counter
		else
			cntfield.value = maxlimit - field.value.length;
	}
	function filter_urlstr(this_str) {
		this_str = this_str.replace(/\n/g,"<br>");
		//this_str = this_str.replace(/\r/g,"<br>");
		this_str = this_str.replace(/\&/g,"%26");
		this_str = this_str.replace(/\=/g,"%3D");
		this_str = this_str.replace(/\#/g,"%23");
		this_str = this_str.replace(/\+/g,"%2B");
		this_str = this_str.replace(/\?/g,"%40");
		
		return this_str;
	}
	//hi&cmd=show_account&
	/*MY ACCOUNT FUNCTIONS*/
	function hide_accounttabs() {
		document.getElementById("display_accounttabs").style.display = "none";
	}
	function display_accounttabs(last_dirtab, show_boa) {	
		document.getElementById("display_accounttabs").style.display = "block";		
		//var last_dirtab = document.getElementById("last_clicked_dirtab").value;
		//alert(last_dirtab);
		if (show_boa)
		    document.getElementById('tabboa').style.display='';
		if (last_dirtab == "show_myaccount") {
			document.getElementById("display_accounttabs").style.display = "block";
			document.getElementById("tabdir").className = "topTabsOn";
			document.getElementById("tabedit").className = "topTabs";
			document.getElementById("tabrecent").className = "topTabs";		    			
			document.getElementById("tabdirreport").className = "topTabs";		    			
			document.getElementById("tabmessage").className = "topTabs";		    			
			document.getElementById("tabboa").className = "topTabs";

			document.getElementById("tabdirimg").innerHTML = "<img src='images/tab_Directory.gif' border=0>";
			document.getElementById("tabeditimg").innerHTML = "<img src='images/tab_MyAccountOff.gif' border=0>";
			document.getElementById("tabrecentimg").innerHTML = "<img src='images/tab_RecentOff.gif' border=0>";
			document.getElementById("tabdirreportimg").innerHTML = "<img src='images/tab_ReportsOff.gif' border=0>";
			document.getElementById("tabmessageimg").innerHTML = "<img src='images/tab_MessagesOff.gif' border=0>";
			document.getElementById("tabboaimg").innerHTML = "<img src='images/tab_BOAOff.gif' border=0>";
			
			location.href = "#myaccount";
		}
		else if (last_dirtab == "show_account") {
			document.getElementById("tabdir").className = "topTabs";
			document.getElementById("tabedit").className = "topTabsOn";
			document.getElementById("tabrecent").className = "topTabs";		    			
			document.getElementById("tabdirreport").className = "topTabs";		    			
			document.getElementById("tabmessage").className = "topTabs";
			document.getElementById("tabboa").className = "topTabs";
										
			document.getElementById("tabdirimg").innerHTML = "<img  src='images/tab_DirectoryOff.gif' border=0>";
			document.getElementById("tabeditimg").innerHTML = "<img src='images/tab_MyAccount.gif' border=0>";
			document.getElementById("tabrecentimg").innerHTML = "<img src='images/tab_RecentOff.gif' border=0>";
			document.getElementById("tabdirreportimg").innerHTML = "<img src='images/tab_ReportsOff.gif' border=0>";
			document.getElementById("tabmessageimg").innerHTML = "<img src='images/tab_MessagesOff.gif' border=0>";
			document.getElementById("tabboaimg").innerHTML = "<img src='images/tab_BOAOff.gif' border=0>";
			location.href = "#account";
		}
		else if (last_dirtab == "show_recents") {
			document.getElementById("tabdir").className = "topTabs";
			document.getElementById("tabedit").className = "topTabs";
			document.getElementById("tabrecent").className = "topTabsOn";		    			
			document.getElementById("tabdirreport").className = "topTabs";		    			
			document.getElementById("tabmessage").className = "topTabs";
			document.getElementById("tabboa").className = "topTabs";
			
			document.getElementById("tabdirimg").innerHTML = "<img  src='images/tab_DirectoryOff.gif' border=0>";
			document.getElementById("tabeditimg").innerHTML = "<img src='images/tab_MyAccountOff.gif' border=0>";
			document.getElementById("tabrecentimg").innerHTML = "<img src='images/tab_Recent.gif' border=0>";
			document.getElementById("tabdirreportimg").innerHTML = "<img src='images/tab_ReportsOff.gif' border=0>";
			document.getElementById("tabmessageimg").innerHTML = "<img src='images/tab_MessagesOff.gif' border=0>";
			document.getElementById("tabboaimg").innerHTML = "<img src='images/tab_BOAOff.gif' border=0>";
			location.href = "#recent";
		}	
		else if (last_dirtab == "show_report") {
			document.getElementById("tabdir").className = "topTabs";
			document.getElementById("tabedit").className = "topTabs";
			document.getElementById("tabrecent").className = "topTabs";		    			
			document.getElementById("tabdirreport").className = "topTabsOn";		    			
			document.getElementById("tabmessage").className = "topTabs";
			document.getElementById("tabboa").className = "topTabs";
			
			document.getElementById("tabdirimg").innerHTML = "<img  src='images/tab_DirectoryOff.gif' border=0>";
			document.getElementById("tabeditimg").innerHTML = "<img src='images/tab_MyAccountOff.gif' border=0>";
			document.getElementById("tabrecentimg").innerHTML = "<img src='images/tab_RecentOff.gif' border=0>";
			document.getElementById("tabdirreportimg").innerHTML = "<img src='images/tab_Reports.gif' border=0>";
			document.getElementById("tabmessageimg").innerHTML = "<img src='images/tab_MessagesOff.gif' border=0>";
			document.getElementById("tabboaimg").innerHTML = "<img src='images/tab_BOAOff.gif' border=0>";
			location.href = "#report";
		}	
		else if (last_dirtab == "show_messages") {
			document.getElementById("tabdir").className = "topTabs";
			document.getElementById("tabedit").className = "topTabs";
			document.getElementById("tabrecent").className = "topTabs";		    			
			document.getElementById("tabdirreport").className = "topTabs";		    			
			document.getElementById("tabmessage").className = "topTabsOn";
			document.getElementById("tabboa").className = "topTabs";
			
			document.getElementById("tabdirimg").innerHTML = "<img  src='images/tab_DirectoryOff.gif' border=0>";
			document.getElementById("tabeditimg").innerHTML = "<img src='images/tab_MyAccountOff.gif' border=0>";
			document.getElementById("tabrecentimg").innerHTML = "<img src='images/tab_RecentOff.gif' border=0>";
			document.getElementById("tabdirreportimg").innerHTML = "<img src='images/tab_ReportsOff.gif' border=0>";
			document.getElementById("tabmessageimg").innerHTML = "<img src='images/tab_Messages.gif' border=0>";
			document.getElementById("tabboaimg").innerHTML = "<img src='images/tab_BOAOff.gif' border=0>";
			location.href = "#message";
		}			
		else if (last_dirtab == "show_boa") {
			document.getElementById("tabdir").className = "topTabs";
			document.getElementById("tabedit").className = "topTabs";
			document.getElementById("tabrecent").className = "topTabs";		    			
			document.getElementById("tabdirreport").className = "topTabs";		    			
			document.getElementById("tabmessage").className = "topTabs";
			document.getElementById("tabboa").className = "topTabsOn";
			
			document.getElementById("tabdirimg").innerHTML = "<img  src='images/tab_DirectoryOff.gif' border=0>";
			document.getElementById("tabeditimg").innerHTML = "<img src='images/tab_MyAccountOff.gif' border=0>";
			document.getElementById("tabrecentimg").innerHTML = "<img src='images/tab_RecentOff.gif' border=0>";
			document.getElementById("tabdirreportimg").innerHTML = "<img src='images/tab_ReportsOff.gif' border=0>";
			document.getElementById("tabmessageimg").innerHTML = "<img src='images/tab_MessagesOff.gif' border=0>";
			document.getElementById("tabboaimg").innerHTML = "<img src='images/tab_BOA.gif' border=0>";
			location.href = "#upload";
		}
	}
	function display_showrecents_tab() {
			document.getElementById("tabdir").className = "topTabs";
			document.getElementById("tabedit").className = "topTabs";
			document.getElementById("tabrecent").className = "topTabsOn";
			document.getElementById("tabdirreport").className = "topTabs";		    			
			document.getElementById("tabmessage").className = "topTabs";					    			
			document.getElementById("tabboa").className = "topTabs";
					
			document.getElementById("tabdirimg").innerHTML = "<img src='images/tab_DirectoryOff.gif' border=0>";
			document.getElementById("tabeditimg").innerHTML = "<img src='images/tab_MyAccountOff.gif' border=0>";
			document.getElementById("tabrecentimg").innerHTML = "<img src='images/tab_Recent.gif' border=0>";
			document.getElementById("tabdirreportimg").innerHTML = "<img src='images/tab_ReportsOff.gif' border=0>";
			document.getElementById("tabmessageimg").innerHTML = "<img src='images/tab_MessagesOff.gif' border=0>";			
			document.getElementById("tabboaimg").innerHTML = "<img src='images/tab_BOAOff.gif' border=0>";
			location.href = "#recent";		
	}
	function display_showmessage_tab() {
			document.getElementById("tabdir").className = "topTabs";
			document.getElementById("tabedit").className = "topTabs";
			document.getElementById("tabrecent").className = "topTabs";
			document.getElementById("tabdirreport").className = "topTabs";		    			
			document.getElementById("tabmessage").className = "topTabsOn";					    			
			document.getElementById("tabboa").className = "topTabs";
					
			document.getElementById("tabdirimg").innerHTML = "<img  src='images/tab_DirectoryOff.gif' border=0>";
			document.getElementById("tabeditimg").innerHTML = "<img src='images/tab_MyAccountOff.gif' border=0>";
			document.getElementById("tabrecentimg").innerHTML = "<img src='images/tab_RecentOff.gif' border=0>";
			document.getElementById("tabdirreportimg").innerHTML = "<img src='images/tab_ReportsOff.gif' border=0>";
			document.getElementById("tabmessageimg").innerHTML = "<img src='images/tab_Messages.gif' border=0>";			
			document.getElementById("tabboaimg").innerHTML = "<img src='images/tab_BOAOff.gif' border=0>";
			location.href = "#account";		
	}	
	function display_showmyaccount_tab() {
			document.getElementById("tabdir").className = "topTabs";
			document.getElementById("tabedit").className = "topTabsOn";
			document.getElementById("tabrecent").className = "topTabs";
			document.getElementById("tabdirreport").className = "topTabs";		    			
			document.getElementById("tabmessage").className = "topTabs";					    			
			document.getElementById("tabboa").className = "topTabs";
					
			document.getElementById("tabdirimg").innerHTML = "<img  src='images/tab_DirectoryOff.gif' border=0>";
			document.getElementById("tabeditimg").innerHTML = "<img src='images/tab_MyAccount.gif' border=0>";
			document.getElementById("tabrecentimg").innerHTML = "<img src='images/tab_RecentOff.gif' border=0>";
			document.getElementById("tabdirreportimg").innerHTML = "<img src='images/tab_ReportsOff.gif' border=0>";
			document.getElementById("tabmessageimg").innerHTML = "<img src='images/tab_MessagesOff.gif' border=0>";			
			document.getElementById("tabboaimg").innerHTML = "<img src='images/tab_BOAOff.gif' border=0>";
			location.href = "#account";		
	}		
	function display_showdirreport_tab(){
			document.getElementById("tabdir").className = "topTabs";
			document.getElementById("tabedit").className = "topTabs";
			document.getElementById("tabrecent").className = "topTabs";
			document.getElementById("tabdirreport").className = "topTabsOn";		    			
			document.getElementById("tabmessage").className = "topTabs";					    			
			document.getElementById("tabboa").className = "topTabs";
					
			document.getElementById("tabdirimg").innerHTML = "<img  src='images/tab_DirectoryOff.gif' border=0>";
			document.getElementById("tabeditimg").innerHTML = "<img src='images/tab_MyAccountOff.gif' border=0>";
			document.getElementById("tabrecentimg").innerHTML = "<img src='images/tab_RecentOff.gif' border=0>";
			document.getElementById("tabdirreportimg").innerHTML = "<img src='images/tab_Reports.gif' border=0>";
			document.getElementById("tabmessageimg").innerHTML = "<img src='images/tab_MessagesOff.gif' border=0>";			
			document.getElementById("tabboaimg").innerHTML = "<img src='images/tab_BOAOff.gif' border=0>";
			location.href = "#report";			
	}
	
	function display_showupload_tab(){
			document.getElementById("tabdir").className = "topTabs";
			document.getElementById("tabedit").className = "topTabs";
			document.getElementById("tabrecent").className = "topTabs";
			document.getElementById("tabdirreport").className = "topTabs";		    			
			document.getElementById("tabmessage").className = "topTabs";					    			
			document.getElementById("tabboa").className = "topTabsOn";
					
			document.getElementById("tabdirimg").innerHTML = "<img  src='images/tab_DirectoryOff.gif' border=0>";
			document.getElementById("tabeditimg").innerHTML = "<img src='images/tab_MyAccountOff.gif' border=0>";
			document.getElementById("tabrecentimg").innerHTML = "<img src='images/tab_RecentOff.gif' border=0>";
			document.getElementById("tabdirreportimg").innerHTML = "<img src='images/tab_Reports.gif' border=0>";
			document.getElementById("tabmessageimg").innerHTML = "<img src='images/tab_MessagesOff.gif' border=0>";			
			document.getElementById("tabboaimg").innerHTML = "<img src='images/tab_BOA.gif' border=0>";
			location.href = "#upload";
	}
		
	function show_dir_button() {
		document.getElementById("submit_buy_dir").style.display = "block";
		document.getElementById("checkout_loader").innerHTML = "";
	}	
	function delete_option(optid, price) {
		
		var payment_plan = document.getElementById("payment_plan").value;
		var payment_arr = explodeArray(payment_plan,",");
		var i;
		var payment_new = removeItems(payment_arr, optid);
		var last_el = payment_new.length - 1;
		var payment_string = "";
		for (i = 0; i < payment_new.length; i++) {
			if (payment_new[i] != "" & payment_new[i] != "undefined") {
				//alert(payment_new[i]);
				if (i != last_el) payment_string += payment_new[i] + ",";
				else payment_string += payment_new[i];
			}
		}
		//alert(payment_string);
		document.getElementById("payment_plan").value = payment_string;
		var optrow = "optrow_" + optid;
		document.getElementById(optrow).style.display = 'none'; 
		var tot_opt = document.getElementById("tot_opt").value;
		//var new_tot = parseInt(tot_opt) - parseInt(price);
		var new_tot = tot_opt - price;
		var result = Math.round(new_tot*100)/100;
		result=result.toFixed(2);
		document.getElementById("tot_opt").value = result;
		document.getElementById("total_options").innerHTML = result;
		if (result <= 0) {
			document.getElementById("show_cc_num").innerHTML = "<span class='errorred'>NO CARD NECESSARY!</span>";
			document.getElementById("free_prod_toggle").value = "y";	
			//document.getElementById("show_cc_num").style.display = "none";
			document.getElementById("buy_dir_expmo").disabled = true;
			document.getElementById("buy_dir_expyr").disabled = true;
			document.getElementById("buy_dir_cvv").disabled = true;
		}
	}
	function removeItems(array, item) {
		var i = 0;
		while (i < array.length) {
			if (array[i] == item) {
				array.splice(i, 1);
			} 
			else {
				i++;
			}
		}
		return array;
	}	
	var checkflag = "false";
	function check(field) {
		if (checkflag == "false") {
			for (i = 0; i < field.length; i++) {
				field[i].checked = true;
			}
			checkflag = "true";
			return "all"; 
		}
		else {
			for (i = 0; i < field.length; i++) {
				field[i].checked = false; 
			}
			checkflag = "false";
			return "all"; 
		}
	}
	function select_all_pricechk(){
		if (document.getElementById("select_category_all").checked == true) {
			var cnt_selcat = document.getElementById("selcat_cnt").value;
	        //alert('cnt_selcat: ' + cnt_selcat);
			//var chkbox = document.getElementById("emcam_chk"); //radio field
	        var select_category = "";
	        var this_chkbox;
	        var i;
	        for (i = 0; i < cnt_selcat; i++) {
		        this_chkbox = "select_category_" + i;
		        //alert(this_chkbox);
		        var this_selcat = document.getElementById(this_chkbox);
	            if (this_selcat.parentNode.id!=('bundle'+i))
    	            this_selcat.checked = true;
	        }	
    	}
	}
	function show_couponentry() {
		document.getElementById("enter_couponinput").style.display = "block";	
		document.getElementById("enter_couponsubmit").style.display = "block";	
		document.getElementById("coupon_toggle").style.display = "none";	
	}
	function validate_sel_options() {
		
		var i;
        var select_clicks = "";
        var click_count=0;
        while(document.getElementById("select_clicks" + click_count))
            if (document.getElementById("select_clicks" + click_count++).checked)
                select_clicks=1;
		
        var cnt_selcat = document.getElementById("selcat_cnt").value;
        var select_category = "";
        var this_chkbox;
        var i;
        for (i = 0; i < cnt_selcat; i++) {
	        this_chkbox = "select_category_" + i;
	        //alert(this_chkbox);
	        var this_selcat = document.getElementById(this_chkbox);
            if (this_selcat.checked == true) {
	            //alert('this_selcat: ' + this_selcat.value);
	            select_category += this_selcat.value + "|";
            }
        }		
		document.getElementById("select_category").value = select_category;
        //alert('select_category: ' + document.getElementById("select_category").value);        
        
        var coupon_optids = document.getElementById("coupon_optids").value;
        var status = true;
        
		if (select_clicks == "" & select_category == "" & coupon_optids == "") {
			alert('You must select an option to proceed.');
			status = false;
			//show_dir_button();
			return status;
		}
		//else document.getElementById("sel_options_table").style.backgroundColor = 'white';
		
		if (status == true) {
			document.getElementById('select_options').submit();		
		}
	}

	function clear_option(optname) {
		var buttonGroup = document.getElementsByName(optname);
		for (i=0; i < buttonGroup.length; i++) { 
			if (buttonGroup[i].checked == true) { 
	    		buttonGroup[i].checked = false 
			}
		} 		
	}	

	function validate_ban(){
		var status = true;
		var banname = document.getElementById("ban_name").value;
		var banurl = document.getElementById("ban_url").value;
		//var affcity = document.getElementById("payee_cit").value;
		if (document.getElementById("image_banstore")) var image_ban = document.getElementById("image_banstore").value;
		else var image_ban = "1";
		
		
		if (document.getElementById("ban_old")) var banold = document.getElementById("ban_old").value;
		else var banold = "";
		//alert("|"+image_ban+"|..|"+ban_old+"|");
		if (image_ban == "" & banold == "") {
			alert('You must click the "Load Image" button after you are done Browsing an image.');
			document.getElementById("ban_iframe").style.backgroundColor = 'red';
			//document.getElementById("ban_iframe").focus();
			status = false;
			return status;			
		}
		else {
			if (document.getElementById("ban_iframe")) document.getElementById("ban_iframe").style.backgroundColor = 'white';
		}
					
		if (banold == "") {
		
			if (banname == "") {
				alert('You must enter the name of this banner.');
				document.getElementById("ban_name").style.backgroundColor = 'red';
				document.getElementById("ban_name").focus();
				status = false;
				return status;			
			}
			else {
				document.getElementById("ban_name").style.backgroundColor = 'white';
			}
						
			var chkurl = checkUrl(banurl);
			if (banurl == "" || chkurl == false) {
				alert('You must enter the VALID url of the Website that will be using this .');
				document.getElementById("ban_url").style.backgroundColor = 'red';
				document.getElementById("ban_url").focus();
				status = false;
				return status;			
			}
			else {
				document.getElementById("ban_url").style.backgroundColor = 'white';
			}
		}
		else {
			if (banold == "no") {
				alert('You must select a banner to continue.');
				/*document.getElementById("ban_name").style.backgroundColor = 'red';
				document.getElementById("ban_name").focus();
				status = false;*/
				return status;			
			}
			else {
				//document.getElementById("ban_name").style.backgroundColor = 'white';
			}			
		}
				
		if(!document.getElementById("ban_bypasscat")) {
			var ban_cats = document.getElementById("ban_cats");
			var bancatIndex = ban_cats.selectedIndex;		
			if (ban_cats.options[bancatIndex].value == "def" | ban_cats.options[bancatIndex].value == "") {
				alert('You must select a category.');
				document.getElementById("ban_cats").style.backgroundColor = 'red';
				document.getElementById("ban_cats").focus();
				status = false;
				return status;			
			}
			else {
				var ban_catsind = ban_cats.options[bancatIndex].value;
				document.getElementById("ban_cats").style.backgroundColor = 'white';
			}	
		}

						
		if (status == true) {
			document.getElementById('upload_banner').submit();	
		}				
		
	}
	function validate_txt(){
		var status = true;
		var banname = document.getElementById("ban_txtname").value;
		var banurl = document.getElementById("ban_txturl").value;
		var banheader = document.getElementById("ban_txtheader").value;
		var banl1 = document.getElementById("ban_txtl1").value;
		var banl2 = document.getElementById("ban_txtl2").value;
		if (document.getElementById("txt_old")) var txtold = document.getElementById("txt_old").value;
		else var txtold = "";
		//var affcity = document.getElementById("payee_cit").value;
		
		if (txtold == "") {
			if (banname == "") {
				alert('You must enter the name of this banner.');
				document.getElementById("ban_txtname").style.backgroundColor = 'red';
				document.getElementById("ban_txtname").focus();
				status = false;
				return status;			
			}
			else {
				document.getElementById("ban_txtname").style.backgroundColor = 'white';
			}
					
			if (banheader == "") {
				alert('You must enter the header for this banner.');
				document.getElementById("ban_txtheader").style.backgroundColor = 'red';
				document.getElementById("ban_txtheader").focus();
				status = false;
				return status;			
			}
			else {
				document.getElementById("ban_txtheader").style.backgroundColor = 'white';
			}
			
			if (banl1 == "") {
				alert('You must enter the first line of text for this banner.');
				document.getElementById("ban_txtl1").style.backgroundColor = 'red';
				document.getElementById("ban_txtl1").focus();
				status = false;
				return status;			
			}
			else {
				document.getElementById("ban_txtl1").style.backgroundColor = 'white';
			}
			
			var chkurl = checkUrl(banurl);
			if (banurl == "" || chkurl == false) {
				alert('You must enter the VALID url of the Website that will be using this .');
				document.getElementById("ban_txturl").style.backgroundColor = 'red';
				document.getElementById("ban_txturl").focus();
				status = false;
				return status;			
			}
			else {
				document.getElementById("ban_txturl").style.backgroundColor = 'white';
			}
		}
		else {
			if (txtold == "no") {
				alert('You must select a text ad to continue.');
				/*document.getElementById("ban_name").style.backgroundColor = 'red';
				document.getElementById("ban_name").focus();
				status = false;*/
				return status;			
			}
			else {
				//document.getElementById("ban_name").style.backgroundColor = 'white';
			}			
		}
		if(!document.getElementById("ban_bypasscat")) {		
			var ban_cats = document.getElementById("ban_cats");
			var bancatIndex = ban_cats.selectedIndex;		
			if (ban_cats.options[bancatIndex].value == "def" | ban_cats.options[bancatIndex].value == "") {
				alert('You must select a category.');
				document.getElementById("ban_cats").style.backgroundColor = 'red';
				document.getElementById("ban_cats").focus();
				status = false;
				return status;			
			}
			else {
				var ban_catsind = ban_cats.options[bancatIndex].value;
				document.getElementById("ban_cats").style.backgroundColor = 'white';
			}	
		}

						
		if (status == true) {
			document.getElementById('upload_textban').submit();	
		}	
				
		
	}
	function validate_affiliate() {
		var status = true;
		var affname = document.getElementById("payee_name").value;
		var affurl = document.getElementById("payee_url").value;
		var affcity = document.getElementById("payee_cit").value;
		var affzip = document.getElementById("payee_zip").value;
		var affad1 = document.getElementById("payee_address1").value;
		var aff_country = document.getElementById("payee_country"); //select field
		var aff_state = document.getElementById("payee_state"); //select field
		
		if (affname == "") {
			alert('You must enter the name of the person who will be receiving the affiliate payout checks.');
			document.getElementById("payee_name").style.backgroundColor = 'red';
			document.getElementById("payee_name").focus();
			status = false;
			return status;			
		}
		else {
			document.getElementById("payee_name").style.backgroundColor = 'white';
		}
				
		var chkurl = checkUrl(affurl);
		if (affurl == "" || chkurl == false) {
			alert('You must enter the VALID url of the Website that will be using this .');
			document.getElementById("payee_url").style.backgroundColor = 'red';
			document.getElementById("payee_url").focus();
			status = false;
			return status;			
		}
		else {
			document.getElementById("payee_url").style.backgroundColor = 'white';
		}
		if (affad1 == "") {
			alert('You must enter the first address line of the person who will be receiving the affiliate payout checks.');
			document.getElementById("payee_address1").style.backgroundColor = 'red';
			document.getElementById("payee_address1").focus();
			status = false;
			return status;			
		}
		else {
			document.getElementById("payee_address1").style.backgroundColor = 'white';
		}
		
		var countryIndex = aff_country.selectedIndex;		
		if (aff_country.options[countryIndex].value == "def" | aff_country.options[countryIndex].value == "") {
			alert('You must select a country.');
			document.getElementById("affcountry_display").style.backgroundColor = 'red';
			document.getElementById("payee_country").focus();
			status = false;
			return status;			
		}
		else {
			var aff_country = aff_country.options[countryIndex].value;
			document.getElementById("affcountry_display").style.backgroundColor = 'white';
		}	
		if (affzip == "") {
			alert('You must enter the zip code of the person who will be receiving the affiliate payout checks.');
			document.getElementById("payee_zip").style.backgroundColor = 'red';
			document.getElementById("payee_zip").focus();
			status = false;
			return status;			
		}
		else {
			document.getElementById("payee_zip").style.backgroundColor = 'white';
		}
		
		var stateIndex = aff_state.selectedIndex;		
		if (aff_state.options[stateIndex].value == "def" | aff_state.options[stateIndex].value == "") {
			alert('You must select a state.');
			document.getElementById("affstates_display").style.backgroundColor = 'red';
			document.getElementById("payee_state").focus();
			status = false;
			return status;			
		}
		else {
			var aff_state = aff_state.options[stateIndex].value;
			document.getElementById("affstates_display").style.backgroundColor = 'white';
		}								
		
		if (trim(affcity) == "") {
			alert('You must enter the city of the person who will be receiving the affiliate payout checks.');
			document.getElementById("payee_cit").style.backgroundColor = 'red';
			document.getElementById("payee_cit").focus();
			status = false;
			return status;			
		}
		else {
			document.getElementById("payee_cit").style.backgroundColor = 'white';
		}
		var check_tos = document.getElementById("aff_tos_check");
		if (check_tos.checked == false) {
			alert('You must agree to the Terms of Service to create an account');
			document.getElementById("aff_tos_check").style.backgroundColor = 'red';
			//document.getElementById("tos_text").style.backgroundColor = 'red';
			status = false;
			return status;
		}
		else {
			document.getElementById("aff_tos_check").style.backgroundColor = 'white';
			//document.getElementById("tos_text").style.backgroundColor = 'white';
		}
						
		if (status == true) {
			document.getElementById('setup_aff').submit();	
		}		
		
	}
			
	function validate_contact() {
		var bus_reason = document.getElementById("error_type");
		var reasonIndex = bus_reason.selectedIndex;		
		var contact_comment = trim(document.getElementById("my_comment").value);
		var status = true;
		var email = document.getElementById("my_email").value;
		if (bus_reason.options[reasonIndex].value == "Please choose.." | bus_reason.options[reasonIndex].value == "") {
			alert('You must select a subject for this communication.');
			document.getElementById("error_type").style.backgroundColor = 'red';
			document.getElementById("error_type").focus();
			status = false;
			return status;			
		}
		else {
			var bus_reason = bus_reason.options[reasonIndex].value;
			document.getElementById("error_type").style.backgroundColor = 'white';
		}	
		var email_format = checkEmail(email);
		if (email_format == false) {
			alert('You must enter a VALID e-mail address');
			document.getElementById("my_email").style.backgroundColor = 'red';
			document.getElementById("my_email").focus();
			status = false;
			return status;			
		}
		else {
			document.getElementById("my_email").style.backgroundColor = 'white';
		}
			
		if (contact_comment == "") {
			alert('You must enter some comment.');
			document.getElementById("my_comment").style.backgroundColor = 'red';
			document.getElementById("my_comment").focus();
			status = false;
			return status;
		}
		else document.getElementById("my_comment").style.backgroundColor = 'white';						
		
		if (status == true) {
			document.getElementById('my_contact').submit();	
		}		
		
	}
	function buy_dir_submit	() {
		
		document.getElementById("submit_buy_dir").style.display = "none";
		document.getElementById('checkout_loader').style.visibility='visible';
        //IE compatible code - so it displays the animation
        if (navigator && navigator.appVersion.indexOf("MSIE")!=-1)
            setTimeout("document.getElementById('checkout_loader').src = 'images/ajax_loader_clear.gif';", 100);
		var itemid = document.getElementById("store_pid").value;
		var status = true;
		var bus_name = document.getElementById("buy_dir_name").value;
		var bus_ad1 = document.getElementById("buy_dir_ad1").value;
		var bus_ad2 = document.getElementById("buy_dir_ad2").value; //select field
		var bus_country = document.getElementById("buy_dir_country"); //select field
		var bus_state = document.getElementById("buy_dir_state"); //select field
		var bus_city = document.getElementById("buy_dir_city").value;
		var bus_zip = document.getElementById("buy_dir_zip").value;
		var req_fields = document.getElementById("req_checkout").value;
		
		if (document.getElementById("tosban_check")) {
			var check_tos = document.getElementById("tosban_check");
			if (check_tos.checked == false) {
				alert('You must agree to the Advertising policies to purchase an ad');
				document.getElementById("tosban_check").style.backgroundColor = 'red';
				//document.getElementById("tos_text").style.backgroundColor = 'red';
				show_dir_button();
				status = false;
				return status;
			}
			else {
				document.getElementById("tosban_check").style.backgroundColor = 'white';
				//document.getElementById("tos_text").style.backgroundColor = 'white';
			}
		}
					
        var payment_plan = document.getElementById("payment_plan").value;
   		if (payment_plan == '') { //the payment optionid is HARDCODED here, we will want to make this dynamic
			alert('You did not select a payment option. \n\n Please try again.');
			document.getElementById("buy_dir_name").style.backgroundColor = 'red';
			document.getElementById("buy_dir_name").focus();
			status = false;
			show_dir_button();
			return status;
		}
		else document.getElementById("buy_dir_name").style.backgroundColor = 'white';

		if (payment_plan == '194' & itemid == "" ) { //the payment optionid is HARDCODED here, we will want to make this dynamic
			alert('There has been an error processing your order. You have selected the individual item valuation, but we were unable to find an itemid. \n\n Please try again.');
			document.getElementById("buy_dir_name").style.backgroundColor = 'red';
			document.getElementById("buy_dir_name").focus();
			status = false;
			show_dir_button();
			return status;
		}
		else document.getElementById("buy_dir_name").style.backgroundColor = 'white';
		        
        var free_prod_toggle = document.getElementById("free_prod_toggle").value;
        
		if (document.getElementById("show_savecc")) { //we will use the cc num that already exists in the db
			if (document.getElementById("show_savecc").checked == true) {
				var show_savecc	= "1";
			}
			else var show_savecc = "0";
		}
		else var show_savecc = "0";
        
		if (free_prod_toggle == "y" || show_savecc == "1") {
			var bus_ccnum = "0";
			var bus_cvv = "-1";
			var bus_expmo = "0"; //select field
			var bus_expyr = "0"; //select field	        
	        var expmo = "0";
	        var expyr = "0";
        }
        else {
			var bus_ccnum = document.getElementById("buy_dir_ccnum").value;
			var bus_cvv = document.getElementById("buy_dir_cvv").value;
			var bus_expmo = document.getElementById("buy_dir_expmo"); //select field
			var bus_expyr = document.getElementById("buy_dir_expyr"); //select field	        
			if (bus_ccnum == "" & document.getElementById("buy_dir_ccnum").disabled != true) {
				alert('You must enter a credit card number to complete this transaction.');
				document.getElementById("buy_dir_ccnum").style.backgroundColor = 'red';
				document.getElementById("buy_dir_ccnum").focus();
				status = false;
				show_dir_button();
				return status;
			}
			else document.getElementById("buy_dir_ccnum").style.backgroundColor = 'white';
			
			if (bus_cvv == "") {
				alert('You must enter the security code located on the back of your credit card to complete this transaction.');
				document.getElementById("buy_dir_cvv").style.backgroundColor = 'red';
				document.getElementById("buy_dir_cvv").focus();
				status = false;
				show_dir_button();
				return status;
			}
			else document.getElementById("buy_dir_cvv").style.backgroundColor = 'white';
			
			var expmoIndex = bus_expmo.selectedIndex;			
			var expyrIndex = bus_expyr.selectedIndex;		
			var yearmo = get_yearmo();
			var exp_yearmo =  bus_expyr.options[expyrIndex].value +  bus_expmo.options[expmoIndex].value;
			if (exp_yearmo < yearmo) {
				alert('You must enter a expiration date that is current.');
				document.getElementById("buy_expmo_display").style.backgroundColor = 'red';
				document.getElementById("buy_expyr_display").style.backgroundColor = 'red';
				status = false;
				show_dir_button();
				return status;			
			}
			else 	{
				if (bus_expmo.options[expmoIndex].value == "def" | bus_expmo.options[expmoIndex].value == "") {
					alert('You must select the month of the credit card\'s expiration.');
					document.getElementById("buy_expmo_display").style.backgroundColor = 'red';
					document.getElementById("buy_dir_expmo").focus();
					status = false;
					show_dir_button();
					return status;			
				}
				else {
					var expmo = bus_expmo.options[expmoIndex].value;
					document.getElementById("buy_expmo_display").style.backgroundColor = 'white';
				}	
		
				if (bus_expyr.options[expyrIndex].value == "def" | bus_expyr.options[expyrIndex].value == "") {
					alert('You must select the year of the credit card\'s expiration.');
					document.getElementById("buy_expyr_display").style.backgroundColor = 'red';
					document.getElementById("buy_dir_expyr").focus();
					status = false;
					show_dir_button();
					return status;			
				}
				else {
					var expyr = bus_expyr.options[expyrIndex].value;
					document.getElementById("buy_expyr_display").style.backgroundColor = 'white';
				}	
			}
		}				
		if (bus_name == "" && req_fields == 1) {
			alert('You must enter a name.');
			document.getElementById("buy_dir_name").style.backgroundColor = 'red';
			document.getElementById("buy_dir_name").focus();
			status = false;
			show_dir_button();
			return status;
		}
		else document.getElementById("buy_dir_name").style.backgroundColor = 'white';
		if (bus_city == "" && req_fields == 1) {
			alert('You must enter a city.');
			document.getElementById("buy_dir_city").style.backgroundColor = 'red';
			document.getElementById("buy_dir_city").focus();
			status = false;
			show_dir_button();
			return status;
		}
		else document.getElementById("buy_dir_city").style.backgroundColor = 'white';

		if (bus_zip == "" && req_fields == 1) {
			alert('You must enter a zip code.');
			document.getElementById("buy_dir_zip").style.backgroundColor = 'red';
			document.getElementById("buy_dir_zip").focus();
			status = false;
			show_dir_button();
			return status;
		}
		else document.getElementById("buy_dir_zip").style.backgroundColor = 'white';
		
		if (bus_ad1 == "" && req_fields == 1) {
			alert('You must enter the first line of the address associated with this card.');
			document.getElementById("buy_dir_ad1").style.backgroundColor = 'red';
			document.getElementById("buy_dir_ad1").focus();
			status = false;
			show_dir_button();
			return status;
		}
		else document.getElementById("buy_dir_ad1").style.backgroundColor = 'white';

		var countryIndex = bus_country.selectedIndex;		
		
		if ((bus_country.options[countryIndex].value == "def" | bus_country.options[countryIndex].value == "") && req_fields == 1) {
			alert('You must select a country.');
			document.getElementById("buy_countrydisplay").style.backgroundColor = 'red';
			document.getElementById("buy_dir_country").focus();
			status = false;
			show_dir_button();
			return status;			
		}
		else {
			var bus_country = bus_country.options[countryIndex].value;
			document.getElementById("buy_countrydisplay").style.backgroundColor = 'white';
		}	
		var stateIndex = bus_state.selectedIndex;		
		var bus_state = bus_state.options[stateIndex].value;

		if (status == true) {
		}	
	}
	function validate_buy_ccnum() {
							
	}
	function process_signup2(r)	{
		try
		{
			if (r.readyState==4)
				if (r.status==200)
				{
					var i;
        			var radios = document.getElementsByName("payment_plan");
			        var payment_plan = "";

        			for (i = 0; i < radios.length; i++) {
            			if (radios[i].checked) payment_plan = radios[i].value;
        			}
					var chk_val =r.responseText;
					var response_arr = new Array();
					var response_arr = explodeArray(chk_val,",");
					var res_id = response_arr[0];
					var res_text = response_arr[1];
					var itemid = document.getElementById("store_pid").value;
					if (itemid != "" & itemid != "na") var item_ins = "- Return to <a href='"+this_url+"dropdown.php?item_id="+itemid+"'>Item Detail</a><br>";
					else var item_ins = "";
					var passcode_redir = document.getElementById("passcode_redir").value;
					//alert("RES_ID: " + res_id);
					//alert("response: " + r);
    				if (res_id == 16) {
	    				if (passcode_redir == "yes") {
		    				var status_bar = "<table><tr>"+
		    					"<td><img src=\"images/barCreate.gif\" width=79 height=15 hspace=2></td>"+
								"<td><img src=\"images/barVerify.gif\"hspace=2></td>"+
								"<td><img src=\"images/bar_choose.gif\" width=84 height=15 hspace=2></td>"+
								"<td><img src=\"images/bar_checkout.gif\" width=51 height=15 hspace=2></td>"+
								"<td><img src=\"images/barDirectoryOn.gif\" hspace=2></td>";
								"</tr></table>";
	    				}
	    				else {
		    				var status_bar = "<table><tr>"+
		    					"<td><img src=\"images/barCreate.gif\" width=79 height=15 hspace=2></td>"+
		    					"<td><img src=\"images/barVerify.gif\"hspace=2></td>"+
								"<td><img src=\"images/bar_choose.gif\" width=84 height=15 hspace=2></td>"+
								"<td><img src=\"images/bar_checkout.gif\" width=51 height=15 hspace=2></td>";

	    				}
	    				//alert("itemid: " + itemid);
	    				if (itemid != "" & itemid != "na") {
		    				status_bar += "<td><img src=\"images/barViewOn.gif\" hspace=2></td>"+
								"</tr></table>";
		    				document.getElementById("checkout_final").innerHTML = status_bar;	
		    				load_ind(itemid, 'display_checkout');
	    				}
	    				else {
		    				status_bar += "<td><img src=\"images/barDirectoryOn.gif\" hspace=2></td>"+
								"</tr></table>";
		    				document.getElementById("checkout_final").innerHTML = status_bar;	
		    				goto_directory();
	    				}
	    				
	    				
					}		
					else if (res_id == 18) {
	    				if (passcode_redir == "yes") {
		    				var status_bar = "<table><tr>"+
		    					"<td><img src=\"images/barCreate.gif\" width=79 height=15 hspace=2></td>"+
								"<td><img src=\"images/barVerify.gif\"hspace=2></td>"+
								"<td><img src=\"images/bar_choose.gif\" width=84 height=15 hspace=2></td>"+
								"<td><img src=\"images/bar_checkout.gif\" width=51 height=15 hspace=2></td>"+
								"<td><img src=\"images/barViewOn.gif\" hspace=2></td>"+
								"</tr></table>";
	    				}
	    				else {
		    				var status_bar = "<table><tr>"+
		    					"<td><img src=\"images/barCreate.gif\" width=79 height=15 hspace=2></td>"+
								"<td><img src=\"images/barVerify.gif\"hspace=2></td>"+		    					
								"<td><img src=\"images/bar_choose.gif\" width=84 height=15 hspace=2></td>"+
								"<td><img src=\"images/bar_checkout.gif\" width=51 height=15 hspace=2></td>"+
								"<td><img src=\"images/barViewOn.gif\" hspace=2></td>"+
								"</tr></table>";
	    				}
	    				document.getElementById("checkout_final").innerHTML = status_bar;
	    				load_ind(itemid, 'display_checkout');
					}
					else if (res_id == 17) { //need to take them back to order page, with all "TOP" info populated
						alert('There was an error with your credit card. Your transaction was NOT processed. Please try this transaction again later.');
						show_dir_button();
						var old_html = document.getElementById("checkout_cc").innerHTML;
						document.getElementById("checkout_cc").innerHTML = "There was an error with this transaction. Error message: " + res_text + "<br>"+old_html;
					}						
					else if (res_id < 16 & res_id > 11) { //need to take them back to "blank" order page
						show_dir_button();
						var old_html = document.getElementById("checkout_cc").innerHTML;
						document.getElementById("checkout_cc").innerHTML = "DB entry error. Your transaction was NOT processed. Please try this transaction again later. Error message: " + res_text + "<br>"+old_html;
					}
					else if (res_id < 11 & res_id > 1) { //need to take them back to order page, with all "TOP" info populated
						show_dir_button();
						var old_html = document.getElementById("checkout_cc").innerHTML;
						document.getElementById("checkout_cc").innerHTML = "There was an error with your credit card. Your transaction was NOT processed. Please try this transaction again later.Error message: " + res_text + "<br>"+old_html;
						// now redirect to checkout.php?cmd=buy_directory&optid=$optid
					}
					else { //need to take them to "contact us" page
						//cc was charged but data did not insert, have them call us
						alert('Your transaction was processed but there was an error creating your account. Please contact our customer service department.');						
						show_dir_button();
						//document.getElementById("checkout_cc").innerHTML = this_html;
						var old_html = document.getElementById("checkout_cc").innerHTML;
						document.getElementById("checkout_cc").innerHTML = "Your transaction was processed but there was an error creating your account. Please contact our customer service department at <a href='mailto:support@usedprice.com'>support@usedprice.com</a>." + old_html;
						// now redirect to checkout.php?cmd=buy_directory&optid=$optid
					}
	    		}
		}
		catch (e) {	}
	}
		
	function zip_to_state(statediv, stateinput, zipstring) {
		stateinput = filter_urlstr(stateinput);
		zipstring = filter_urlstr(zipstring);
		var m = xml_connect();
		if (m)
		{	
			m.onreadystatechange=function() { change_results(m, statediv); };
			m.open("GET", "myaccount.php?ajax=yes&cmd=pull_states&stateinput="+stateinput+"&zipstring="+zipstring, true); //+"&h="+h+"&t="+t
			m.setRequestHeader("Content-Type", "application/xml");
			m.setRequestHeader("Cache-Control", "no-cache"); 
			m.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}		
		
	}
	function check_for_city(zipstring, changediv, countryid) {
		zipstring = filter_urlstr(zipstring);
		var selectList = document.getElementById(countryid);
		var selectIndex = selectList.selectedIndex;
		var this_country = selectList[selectIndex].value;
		if (this_country == "USA") { //autopopulate will ONLY work for US zips
			var citytext;
			var statediv;
			var stateinput;
			if (changediv == "dir_bus_city") {
				citytext = "dir_bus_city";
				statediv = "show_states";
				stateinput = "dir_bus_state";
			}
			else if (changediv == "zip_city") {
				citytext = "buy_dir_city";	
				statediv = "show_states_buy";		
				stateinput = "buy_dir_state";
			}
			else if (changediv == "payee_zipcity") {
				citytext = "payee_cit";	
				statediv = "show_states_payee";		
				stateinput = "payee_state";
			}
			
			if (document.getElementById(citytext).value == "") { //only work if the city has NOT been typed yet
				if (zipstring.length >= 5) {
					if (changediv=="dir_bus_city") //For new directory signup layout, don't use the old crappy code
					{
    					var funct=function(response, boxname) { document.getElementById(boxname).value=response; };
    					AJAXRequest("myaccount.php?ajax=yes&cmd=pull_city&changediv="+changediv+"&zipstring="+zipstring, funct, changediv);
       					zip_to_state(statediv, stateinput, zipstring);						
					}
					else
					{
    					var r = xml_connect();
					    if (r)
    					{		
	    					r.onreadystatechange=function() { change_results(r, changediv); };
		    				r.open("GET", "myaccount.php?ajax=yes&cmd=pull_city&changediv="+changediv+"&zipstring="+zipstring, true); //+"&h="+h+"&t="+t
    	        			r.setRequestHeader("Content-Type", "application/xml");
					    	r.setRequestHeader("Cache-Control", "no-cache"); 
						    r.send(null);
	    					zip_to_state(statediv, stateinput, zipstring);						
		    			}		
			    		else {
				    		alert('not added');
    						//document.getElementById("searchform").submit();
	    				}	
    				}
					
				}
			}
		}
	}
	function edit_myaccount() {
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
			r.open("GET", "myaccount.php?cmd=edit_account&ajax=yes", true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}		
	}
	function edit_mycampaigns(){
		var cnt_emcam = document.getElementById("emcamacc_cnt").value;
		//var chkbox = document.getElementById("emcam_chk"); //radio field
        var select_chkbox = "";
        var this_chkbox;
        
        for (i = 0; i < cnt_emcam; i++) {
	        this_chkbox = "emcamacc_" + i;
	        var this_emcam = document.getElementById(this_chkbox);
            if (this_emcam.checked == false) select_chkbox += this_emcam.value + "|";
        }		
        //alert(select_chkbox);
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'display_status'); };
			r.open("GET", "myaccount.php?cmd=edit_campaigns&ajax=yes&select_chkbox="+select_chkbox, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
		
		
	}
	function check_account_pw() {
		var old_pw = document.getElementById("account_oldpw").value;	
		old_pw = filter_urlstr(old_pw);	
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { validate_pw(r); };
			r.open("GET", "myaccount.php?ajax=yes&cmd=chk_pw&old_pw="+old_pw, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}		
	//connects to signup.php
	function validate_pw(r)	{
		try
		{
			if (r.readyState==4)
				if (r.status==200)
				{
					var resp =r.responseText;
					val_arr = new Array();
					val_arr = explodeArray(resp,"<");
					var chk_val = val_arr[0];
    				if (chk_val == 0) {
						alert('The password you entered is not correct. Please try again, or use the \'Forgot Password\'.');
						document.getElementById("account_oldpw").style.backgroundColor = 'red';
						document.getElementById("account_oldpw").focus();
					}		
					else {
						update_account_pw();
						document.getElementById("account_oldpw").style.backgroundColor = 'white';							
					}
	    		}
		}
		catch (e) {	}
	}		
	function update_account_pw() {
		var status = true;
		var old_pw = document.getElementById("account_oldpw").value;
		var password = document.getElementById("account_newpw").value;
		var passwordverify = document.getElementById("account_pwconfirm").value;
		
		if (password != passwordverify) {
			alert('The password you enter MUST match the verified password');
			document.getElementById("account_newpw").style.backgroundColor = 'red';
			document.getElementById("account_pwconfirm").style.backgroundColor = 'red';
			document.getElementById("account_newpw").focus();
			status = false;
			return status;
		}
		else {
			document.getElementById("account_newpw").style.backgroundColor = 'white';
			document.getElementById("account_pwconfirm").style.backgroundColor = 'white';
		}
		if (password.length < 6 | password.length > 15) {
			alert('Your password verification must be between 6 and 15 characters');
			document.getElementById("account_newpw").style.backgroundColor = 'red';
			document.getElementById("account_newpw").focus();
			status = false;
			return status;
		}
		else document.getElementById("account_newpw").style.backgroundColor = 'white';

		if (passwordverify.length < 6 | passwordverify.length > 15) {
			alert('Your password verification must be between 6 and 15 characters');
			document.getElementById("account_pwconfirm").style.backgroundColor = 'red';
			document.getElementById("account_pwconfirm").focus();
			status = false;
			return status;
		}
		else document.getElementById("account_pwconfirm").style.backgroundColor = 'white';
		password = filter_urlstr(password);
		if(status == true) {
			var r = xml_connect();
			if (r)
			{		
				r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
				r.open("GET", "myaccount.php?ajax=yes&update_pw=yes&newpw="+password, true); //+"&h="+h+"&t="+t
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);
			}		
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}				
		}
	}
	function update_account_info() {
		var status = true;
		var fname = filter_urlstr(document.getElementById("account_fname").value);
		var mname = filter_urlstr(document.getElementById("account_mname").value);
		var lname = filter_urlstr(document.getElementById("account_lname").value);
		var company = filter_urlstr(document.getElementById("account_company").value);
		var email = filter_urlstr(document.getElementById("account_email").value);
		var phone = filter_urlstr(document.getElementById("account_phone").value);
		

		if (checkEmail(email) == false) {
			alert('You must enter a valid email.');
			document.getElementById("account_email").style.backgroundColor = 'red';
			document.getElementById("account_email").focus();
			status = false;
			return status;
		}
		else document.getElementById("account_email").style.backgroundColor = 'white';
		if (status == true) {
			document.getElementById("update_myaccount").submit();
			/*var r = xml_connect();
			if (r)
			{		
				r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
				r.open("GET", "myaccount.php?ajax=yes&update_account=yes&fname="+fname+"&mname="+mname+"&lname="+lname+"&phone="+phone+"&email="+email+"&company="+company, true); //+"&h="+h+"&t="+t
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);
			}		
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}*/				
		}
	}
	
	function validate_account_dupemail() {
		
		var email = document.getElementById("account_email").value;
		email = filter_urlstr(email);
		var r = xml_connect();
		r.onreadystatechange=function() { validate_account2(r, 'email_dup'); };
		r.open("GET", "myaccount.php?ajax=yes&cmd=chk_dup_email&email="+email, true);
		r.setRequestHeader("Content-Type", "application/xml");
		r.setRequestHeader("Cache-Control", "no-cache"); 
		r.send(null);
		
	}
	//this validates the email and captcha
	//connects to signup.php
	function validate_account2(r)	{
		try
		{
			if (r.readyState==4)
				if (r.status==200)
				{
					var resp =r.responseText;
					val_arr = new Array();
					val_arr = explodeArray(resp,"<");
					var chk_val = val_arr[0];
    				if (chk_val > 0) {
						alert('This email address already exists in our database.');
						document.getElementById("account_email").style.backgroundColor = 'red';
						document.getElementById("account_email").focus();
					}		
					else {
						document.getElementById("account_email").style.backgroundColor = 'white';							
						update_account_info();						
					}
	    		}
		}
		catch (e) {	}
	}	
		
	function show_myaccount() {
		document.getElementById("last_clicked_dirtab").value = "show_myaccount";
		display_accounttabs();
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
			r.open("GET", "myaccount.php?cmd=display&ajax=yes", true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
			
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}
		repop_rightdir();					 
	}
	var last_ltid;
	function show_contacts(ltid){
		document.getElementById("hard_contactlist").innerHTML = "";
		if (document.getElementById('contact_list') && document.getElementById('contact_list').style.display=='block' && ltid==last_ltid)
		{
    		document.getElementById('contact_list').style.display='none';
    		return;
		}
		last_ltid=ltid;
		var m = xml_connect();
		if (m)
		{		
			m.onreadystatechange=function() { change_results(m, 'contact_list'); };
			m.open("GET", "rightnav.php?ajax=yes&contact_dd=yes&ltid="+ltid, true); //+"&h="+h+"&t="+t
			m.setRequestHeader("Content-Type", "application/xml");
			m.setRequestHeader("Cache-Control", "no-cache"); 
			m.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	/*function changecss(theClass,element,value) {
	//documentation for this script at http://www.shawnolson.net/a/503/
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    document.styleSheets[S][cssRules][R].style[element] = value;
	   }
	  }
	 }	
	}*/
	// Pass a class name, style property name and value to set
	/*function changeStyle(cName, spName, newValue)
	{
		alert('inside changestyle');
		// Get the style sheets collection
		var sSheets = document.styleSheets;
		
		// Exit if no style sheets collection
		if (!sSheets || !sSheets.length) return;
		
		// Work out which rule accessor name is needed
		var raName = (sSheets[0].cssRules)? 'cssRules' :
		(sSheets[0].rules)? 'rules' : null;
		
		// Exit if haven't found a model we like
		if (!raName || 'object' != typeof sSheets[0][raName]) return;
		
		// Setup some variables
		var sRule, sRules;
		
		// Setup a RegExp to test class names with
		// selectorText allowed to have '.' or '*' as leading character
		// browser dependent (old IE uses '*')
		var re = new RegExp('^[.*]' + cName + '$');
		
		// Go thru style sheets & get rules
		for(var i=0, m=sSheets.length; i<m; ++i){
			sRules = sSheets[i][raName];
			
			// Look for rule & modify it
			for (var j=0, n=sRules.length; j<n; ++j){
				sRule = sRules[j];
				if (re.test(sRule.selectorText)){
					sRule.style[spName] = newValue;
				}
			}
		}
	}*/
	function changecss(theclass,element,value) { 
		//documentation for this script at http://www.shawnolson.net/a/503/ 
		var cssrules; 
		if (document.all) { 
		cssrules = 'rules'; 
		} 
		else if (document.getElementById) { 
		cssrules = 'cssrules'; 
		} 
		for (var S = 0; S < document.styleSheets.length; S++){ 
		for (var R = 0; R < document.styleSheets[S][cssrules].length; R++) { 
		if (document.styleSheets[S][cssrules][R].selectorText == theclass) { 
		document.styleSheets[S][cssrules][R].style[element] = value; 
		} 
		} 
		} 
	} 
	function show_code(div) {
		var this_div = 'aff_code_' + div;
		var this_show = 'aff_view_' + div;
		if (document.getElementById(this_div).style.display == 'none') {
			document.getElementById(this_div).style.display = 'block';
			document.getElementById(this_show).innerHTML = 'Hide Code';
		}
		else {
			document.getElementById(this_div).style.display = 'none';			
			document.getElementById(this_show).innerHTML = 'View Code';
		}
	}
	function show_aff_mo(mo) {
		var mo_str = document.getElementById("store_mo").value;
		var mo_arr = new Array();
		mo_arr = explodeArray(mo_str, "|");
		var i;
		var this_row;
		var oParent = this.parent;
		var this_sales;
		var this_comm;
		for(i = 0; i < mo_arr.length; i++) {
			this_row = "aff_" + mo_arr[i];
			this_comm = "affco_" + mo_arr[i];
			this_sales = "affsa_" + mo_arr[i];
			//alert(document.getElementById(this_sales).value);
			//alert(document.getElementById(this_comm).value);
			this
			//alert(this_row);
			if (mo_arr[i] == mo) {
				//alert('show: ' + this_row);
				//changeRule(this_row, "n");
				//changecss(this_row,"style","display:block");
				//changeStyle(this_row, 'display', 'block');
				//changecss(this_row, 'display', 'block');
				//this_row.setProperty('display', 'block');
				document.getElementById("aff_sales").innerHTML = document.getElementById(this_sales).value;
				document.getElementById("aff_comm").innerHTML = document.getElementById(this_comm).value;
				document.getElementById(this_row).style.display = "block";
				document.getElementById("aff_all").style.display = "none";
			}
			else {
				//alert('hide: ' + this_row);
				//changeRule(this_row, "y");
				//changecss(this_row,"style","display:none")
				//changeStyle(this_row, 'display', 'none');
				//changecss(this_row, 'display', 'none');
				//this_row.setProperty('display', 'none');
				document.getElementById(this_row).style.display = "none";				
			}
		}
		if (mo == "aff_all") {
			document.getElementById("aff_sales").innerHTML= document.getElementById("affsa_all").value;
			document.getElementById("aff_comm").innerHTML = document.getElementById("affco_all").value;
			document.getElementById("aff_all").style.display = "block";
		}
	}
	function show_prevban() {
		var atid = document.getElementById("ban_atid").value;
		var hide_old = "approved_" + atid;
		if(document.getElementById(hide_old)) document.getElementById(hide_old).style.display = "none";
		var this_dim = document.getElementById("ban_dim").value;
		document.getElementById("ban_old").value = "";
		var arr_dim = new Array();
		arr_dim = explodeArray(this_dim, "x");
		var this_h = arr_dim[1];
		var this_w = arr_dim[0];
		
		var previmg = "file:///" + filter_urlstr(document.getElementById("image_ban").value);
		
		previmg = previmg.replace("\\","/");
		previmg = previmg.replace(/\ /g,"%20");
		location.href = "#prev_ban";
		var prev_ban = "banad_0_" + atid;
		if (document.getElementById(prev_ban)) document.getElementById(prev_ban).innerHTML = "<img src='"+previmg+"' height='"+this_h+"' width='"+this_w+"' alt='N/A in Firefox'><br><br>"; // 
		else document.getElementById("prev_banner_ad").innerHTML = "<img src='"+previmg+"' height='"+this_h+"' width='"+this_w+"' alt='N/A in Firefox'><br><br>"; // 
		//else document.getElementById("prev_banner_ad").src = previmg; // 
	}
	function hide_banolds(this_id, typeid) {
		var this_atid = document.getElementById("ban_atid").value;
		if (this_atid == "") this_atid = document.getElementById("txt_adtypeid").value;
		if (document.getElementById("newcamp_2")) document.getElementById("newcamp_2").style.display = "none";
		if (document.getElementById("newcamp_3")) document.getElementById("newcamp_3").style.display = "none";
		if (this_atid != typeid) document.getElementById("prev_banner_ad").innerHTML = "";
		document.getElementById("prev_txt_ad").style.display = "none";
		if (document.getElementById("toggle_newtab")) document.getElementById("toggle_newtab").style.display = "none";
		if (document.getElementById("ban_typecnt")) {
			var ban_cnt = document.getElementById("ban_typecnt").value;
			var i;
			var at_span;
			for(i = 1; i <= ban_cnt; i++) {
				at_span = "approved_" + i;		
				document.getElementById(at_span).style.display = "none";
			}
		}
	}
	function renew_display() {
		var this_atid = document.getElementById("ban_atid").value;
		if (this_atid == "") this_atid = document.getElementById("txt_adtypeid").value;		
		if (this_atid == 1) {
			
			document.getElementById("create_txtad").style.display = "block";
			document.getElementById("txt_adtab").style.display = "none";
			var bantype = "txt";
		}
		else {
			document.getElementById("create_imgad").style.display = "block";
			document.getElementById("ban_adtab").style.display = "none";
			var bantype = "ban";
		}		
		
	}
	function show_app_ads() {
		var this_atid = document.getElementById("ban_atid").value;
		if (this_atid == "") this_atid = document.getElementById("txt_adtypeid").value;
		//alert(this_atid);
		var oldcnt = "banold_cnt_" + this_atid;
		var this_cnt = document.getElementById(oldcnt).value;
		//alert(this_cnt);
		if (this_cnt > 0) {
			var at_span = "approved_" + this_atid;
			var bantype;
			//alert(this_atid);
			if (this_atid == 1) {
				document.getElementById("txt_adtab").style.display = "none";
				var bantype = "txt";
			}
			else {
				document.getElementById("ban_adtab").style.display = "none";
				var bantype = "ban";
			}
			var bantypediv;
			var banolddiv;
			banolddiv = bantype + "_old";
			if (document.getElementById("toggle_newtab").style.display == "none") {

				document.getElementById(banolddiv).value = "no";	
								
				document.getElementById(at_span).style.display = "block";
				document.getElementById("toggle_newtab").style.display = "block"
				document.getElementById("toggle_existtab").style.display = "none"
			}
			else {
				document.getElementById(at_span).style.display = "none";			
				bantypediv = bantype +"_adtab";
				//alert(document.getElementByID(bantypediv).innerHTML);
				document.getElementById(bantypediv).style.display = "block";
				document.getElementById(banolddiv).value = "";			
							
				document.getElementById("toggle_newtab").style.display = "none"
				document.getElementById("toggle_existtab").style.display = "block"
			}	
		}
		else {
			alert('You have no ads approved for this ad type.');	
		}	
	}
	function change_banimg(atid, adid){
		var this_div = "approved_"+ atid + "_" + adid;
		var show_div = "showim_" + adid;
		if (document.getElementById(this_div).style.display == "none"){
			document.getElementById(this_div).style.display = "block";
		}
		else {
			document.getElementById(this_div).style.display = "none";
		}
		//document.getElementById(this_div). = "block";	

	}
	function load_banad(im_loc, imdiv, imid){
		document.getElementById("ban_url").value = "";
		//document.upload_banner.image_ban.value = "HEHE";
		//document.getElementsByTagName('image_ban')[0].value="HEHE";
		//document.getElementById("image_ban").value = "HEHE";	
		//alert(document.getElementsByTagName('image_ban')[0].value);
		var this_atid = document.getElementById("ban_atid").value;
		if (this_atid == "") this_atid = document.getElementById("txt_adtypeid").value;
		var at_span = "banold_cnt_" + this_atid;
		if (this_atid > 1) document.getElementById("ban_old").value = imid;
		else document.getElementById("txt_old").value = imid;
		var this_imdiv = "banold_" + imdiv;
		var banold_cnt = document.getElementById(at_span).value;
		var i = 0;
		document.getElementById(this_imdiv).style.backgroundColor = "red";	
		for(i = 0; i < banold_cnt; i++) {
			var mydiv = "banold_" + i;
			if (imdiv != i) {
				document.getElementById(mydiv).style.backgroundColor = "#f0f0f0";	
			}
		}
		
	}
	function show_adcreate(this_type, rad_val, asid, slotid) {
		hide_banolds('', this_type);
		var appr_types = document.getElementById("approved_adtypes").value;
		var type_arr = new Array();
		type_arr = explodeArray(appr_types,"|");
		var len = type_arr.length;
		var chk_appr = 0;
		for ( var x = 0 ; x < len ; x++ ) {
			if ( type_arr[x] == this_type) {
				chk_appr = 1;
			}
		}
		if (chk_appr == 0) { //no approved ads for this type, so we hide the 'use existing ad' part
			if(document.getElementById("toggle_existtab")) {
				document.getElementById("toggle_existtab").style.display = "none";
				//document.getElementById("toggle_newtab").style.display = "none";			
			}
		}
		else {
			if(document.getElementById("toggle_existtab")) {
				document.getElementById("toggle_existtab").style.display = "block";
				//document.getElementById("toggle_newtab").style.display = "block";			
			}
		}
		document.getElementById("image_banstore").value = "";
		var ifr;
		var max_iframe = document.getElementById("max_iframe").value;
		for (ifr = 1; ifr <= max_iframe; ifr++) {
			//alert(ifr);
			var loop_if = "modify_file" + ifr;
			if (document.getElementById(loop_if)) document.getElementById(loop_if).style.display = "none";
		}
		var this_if  = "modify_file" + this_type;
		if (document.getElementById(this_if)) document.getElementById(this_if).style.display = "block";
		if (document.getElementById("newcamp_2")) document.getElementById("newcamp_2").style.display = "block";		
		if (document.getElementById("newcamp_3")) document.getElementById("newcamp_3").style.display = "block";		
		//if(document.getElementById("toggle_existtab") & chk_appr > 0) document.getElementById("toggle_existtab").style.display = "block";
		var dim_arr = new Array();
		dim_arr = explodeArray(rad_val,"|");
		var this_catid = dim_arr[0];
		var this_dim = dim_arr[1];
		//var this_type = dim_arr[1];
		document.getElementById("ban_dim").value = this_dim;
		document.getElementById("ban_atid").value = this_type;
		if (this_type > 1) {
			
			document.getElementById("ban_adtab").style.display = "block";
			document.getElementById("txt_adtab").style.display = "none";
			document.getElementById("create_txtad").style.display = "none";
			document.getElementById("create_imgad").style.display = "block";
			document.getElementById("ban_adtype").value = this_type;
			document.getElementById("asid_ban").value = asid;
			document.getElementById("aslotid_ban").value = slotid;
			
		}
		else {
			document.getElementById("ban_adtab").style.display = "none";
			document.getElementById("txt_adtab").style.display = "block";
			
			document.getElementById("create_imgad").style.display = "none";
			document.getElementById("create_txtad").style.display = "block";
			document.getElementById("txt_adtypeid").value = this_type;
			document.getElementById("asid_txt").value = asid;
			document.getElementById("aslotid_txt").value = slotid;
			//document.getElementById("create_imgad").style.display = "block";
		}	
	}
	function show_adnew(rad_val) {
		var dim_arr = new Array();
		dim_arr = explodeArray(rad_val,"|");
		var this_type = dim_arr[0];
		var this_dim = dim_arr[1];
		hide_banolds('', this_type);		
		//var this_type = dim_arr[1];
		document.getElementById("ban_dim").value = this_dim;
		document.getElementById("ban_atid").value = this_type;
		if (rad_val == "def") {
			document.getElementById("create_imgad").style.display = "none";
			document.getElementById("create_txtad").style.display = "none";
		}
		else {
			if (this_type > 1) {
				document.getElementById("create_txtad").style.display = "none";
				document.getElementById("create_imgad").style.display = "block";
				document.getElementById("ban_adtype").value = this_type;
				//document.getElementById("asid_ban").value = asid;
				//document.getElementById("aslotid_ban").value = slotid;
				
			}
			else {
				document.getElementById("create_imgad").style.display = "none";
				document.getElementById("create_txtad").style.display = "block";
				document.getElementById("txt_adtypeid").value = this_type;
				//document.getElementById("asid_txt").value = asid;
				//document.getElementById("aslotid_txt").value = slotid;
				//document.getElementById("create_imgad").style.display = "block";
			}	
		}
		
		var ifr;
		var max_iframe = document.getElementById("max_iframe").value;
		for (ifr = 1; ifr <= max_iframe; ifr++) {
			//alert(ifr);
			var loop_if = "modify_file" + ifr;
			if (document.getElementById(loop_if)) document.getElementById(loop_if).style.display = "none";
		}
		var this_if  = "modify_file" + this_type;
		if (document.getElementById(this_if)) document.getElementById(this_if).style.display = "block";
				
	}	
	function show_ban_cat(mo) {
		hide_banolds('', '');
		if (document.getElementById("newcamp_2")) document.getElementById("newcamp_2").style.display = "block";
		show_banners(mo);
		if (document.getElementById("toggle_existtab"))	document.getElementById("toggle_existtab").style.display = "none";
		if (document.getElementById("toggle_newtab")) document.getElementById("toggle_newtab").style.display = "none";	
		var cid_str = document.getElementById("store_cid").value;
		var cid_arr = new Array();
		cid_arr = explodeArray(cid_str, "|");
		var i;
		var this_row;
		var oParent = this.parent;
				
		document.getElementById("create_imgad").style.display = "none";
		document.getElementById("create_txtad").style.display = "none";
		for(i = 0; i < cid_arr.length; i++) {
			this_row = "bancat_" + cid_arr[i];
		
			var this_rad = "adtype_" + cid_arr[i];
			var clear_rad = document.getElementsByName(this_rad);
			clearButtons(clear_rad);			
			//alert(this_row);
			if (cid_arr[i] == mo) {
				document.getElementById(this_row).style.display = "block";
			}
			else {
				document.getElementById(this_row).style.display = "none";				
			}
		}
		/*if (mo == "aff_all") {
			document.getElementById("aff_sales").html = document.getElementById("affsa_all").value;
			document.getElementById("aff_comm").html = document.getElementById("affco_all").value;
			document.getElementById("aff_all").style.display = "block";
		}*/
	}

	
		
	function display_dirreport(listingid, datepart) {
		var yearpart = datepart.substring(0, 4);
		
		var mopart = datepart.substring(4);
		//alert('year: ' + yearpart + ' month: ' + mopart);
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
			r.open("GET", "myaccount.php?cmd=display_dirreport&ajax=yes&mopart="+mopart+"&yearpart="+yearpart+"&listingid="+listingid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}
		
		
	}
	function highlight_help(rowname) {
		var myurl = new Array('impression_help', 'click_help', 'webhits_help', 'timesmapped_help');
		var j = 0;
		var cnt = myurl.length;
		for (j = 0; j < cnt; j++) {
			if (rowname == myurl[j])
				document.getElementById(rowname).style.backgroundColor = "yellow";	
			else 
				document.getElementById(myurl[j]).style.backgroundColor = "#ffffff";	
		}
	}
	function show_messages(){
		document.getElementById("display_myaccount").innerHTML = "<img src='images/ajax_loader.gif'>";
		document.getElementById("last_clicked_dirtab").value = "show_messages";
		display_accounttabs();		
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
			r.open("GET", "myaccount.php?cmd=show_messages&ajax=yes", true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
		
		
	}
	/*function show_recents() {
		document.getElementById("display_myaccount").innerHTML = "<img src='images/ajax_loader.gif'>";
		document.getElementById("last_clicked_dirtab").value = "show_recents";
		display_accounttabs();
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
			r.open("GET", "myaccount.php?cmd=show_recents&ajax=yes", true); //+"&h="+h+"&t="+t
			
			//r.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" ); 
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			 
	 }	 */
	function show_report() {
		document.getElementById("display_myaccount").innerHTML = "<img src='images/ajax_loader.gif'>";
		document.getElementById("last_clicked_dirtab").value = "show_report";
		display_accounttabs();
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
			r.open("GET", "myaccount.php?cmd=display_dirreport&ajax=yes", true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			 
	 }	 	 
	 function show_account() {
		document.getElementById("last_clicked_dirtab").value = "show_account";
		display_accounttabs();
		var r = xml_connect();
		if (r) {
			r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
			r.open("GET", "myaccount.php?cmd=show_account&ajax=yes", true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}					 
	 }
	 function create_directory(profilePage) {
		 document.getElementById("display_myaccount").innerHTML = "<img src='images/ajax_loader.gif'>";
		 display_accounttabs();
		var r = xml_connect();
		//alert(this_url);
		if (r)
		{		
			if (profilePage==3) //Load images part directly
			    r.onreadystatechange=function() { change_results(r, 'display_myaccount_images'); };
			else
			    r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
			r.open("GET", "myaccount.php?cmd=create_directory&ajax=yes", true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			 
	}
	function toggle_checksign() {
        var radios = document.getElementsByName("checkout_account");
        var default_log = "";
		var i;
        for (i = 0; i < radios.length; i++) {
            if (radios[i].checked) {
	            default_log = radios[i].value;
	            if (default_log == 0) {
		            document.getElementById("checkout_loginform").style.display = "block";
		            document.getElementById("checkout_signupform").style.display = "none";
		            /*
		            document.getElementById("login_checkout").style.display = "block";
		            document.getElementById("signup_in_checkout").style.display = "none";
		            document.getElementById("submit_cc").style.display = "none";
		            document.getElementById("ccform").style.display = "none";
		            */
	            }
	            else if (default_log == 1) {
   		            document.getElementById("checkout_loginform").style.display = "none";
		            document.getElementById("checkout_signupform").style.display = "block";

		            /*
		            document.getElementById("signup_in_checkout").style.display = "block";
		            document.getElementById("ccform").style.display = "block";
		            document.getElementById("submit_cc").style.display = "block";
		            document.getElementById("login_checkout").style.display = "none";
		            */
	            }
            }
            else radios[i].checked = false;
        }		
	}
	 function goto_directory() {
		 document.getElementById("display_checkout").innerHTML = "<img src='images/ajax_loader.gif'>";
		 display_accounttabs();
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'display_checkout'); };
			r.open("GET", "myaccount.php?cmd=create_directory&ajax=yes", true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			 
	}	
	function approve_comment(commentid) {
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
			r.open("GET", "myaccount.php?ajax=yes&comment_approve=yes&commentid="+commentid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	function delete_comment(commentid) {
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
			r.open("GET", "myaccount.php?ajax=yes&comment_delete=yes&commentid="+commentid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	function delete_mycomment(commentid) {
		var this_row = "commentrow"+commentid;
		document.getElementById(this_row).style.display = "none";
		var r = xml_connect();
		if (r)
		{		
			r.open("GET", "myaccount.php?ajax=yes&comment_delete=yes&commentid="+commentid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}	
	function change_catdd(catnum) {
		var r = xml_connect();
		if (r)
		{		
			var stored_cat1 = document.getElementById("stored_cat1").value;
			var stored_cat2 = document.getElementById("stored_cat2").value;
			var stored_cat3 = document.getElementById("stored_cat3").value;
			document.getElementById("current_cat").value = catnum;
			document.getElementById("catnum").innerHTML = catnum;
			var current_cat = document.getElementById("current_cat").value;
			var this_catspan = "cat_display" + catnum;
			var i;
			var display_catspan;
			var display_mfrspan;
			var display_typespan;
			for (i = 1; i <=3; i++) {
				
				display_catspan = "cat_display"+i;
				display_mfrspan = "catmfr_"+i;
				display_typespan = "cattype_"+i;
				if (i == catnum) {
					//alert('showing ' + display_catspan);
					document.getElementById(display_catspan).style.display = 'block';
					document.getElementById(display_mfrspan).style.display = 'block';
					document.getElementById(display_typespan).style.display = 'block';
				}
				else {
					//alert('hiding ' + display_catspan);
					document.getElementById(display_catspan).style.display = 'none';
					document.getElementById(display_mfrspan).style.display = 'none';
					document.getElementById(display_typespan).style.display = 'none';
				}
			}
			r.onreadystatechange=function() { change_results(r, this_catspan); };
			r.open("GET", "myaccount.php?ajax=yes&cmd=repopulate_catdd&stored_cat1="+stored_cat1+"&stored_cat2="+stored_cat2+"&stored_cat3="+stored_cat3+"&this_cat="+catnum, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}		
	}
	function show_mfrtypes(catname) {
		if (document.getElementById("mfrtype_search").style.display == "none") {
			document.getElementById("mfrtype_search").style.display = "block";
		}
		else {
			document.getElementById("mfrtype_search").style.display = "none";			
		}
		//var mfrsearch = catname + "_mfr_search";
		//document.getElementById("mfr_search").focus();
		
	}
	function pop_dir_mfr(this_catid) {
		var current_cat = document.getElementById("current_cat").value;
		var cat_mfrval = "catmfr_"+ current_cat;	
		var m = xml_connect();
		if (m)
		{		
			var j;
			for (j = 1; j <= 3; j++) {
				hide_span = "catmfr_" + j;
					document.getElementById(hide_span).style.display = "none";
			}
			m.onreadystatechange=function() { change_results(m, cat_mfrval); };
			m.open("GET", "myaccount.php?ajax=yes&cmd=repopulate_catmfr&this_catid="+this_catid+"&this_catnum="+current_cat, true); //+"&h="+h+"&t="+t
			m.setRequestHeader("Content-Type", "application/xml");
			m.setRequestHeader("Cache-Control", "no-cache"); 
			m.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	function pop_dir_type(this_catid) {
		var current_cat = document.getElementById("current_cat").value;
		var cat_typeval = "cattype_"+ current_cat;			
		var r = xml_connect();
		if (r)
		{		
			var i;
			var hide_span;
			for (i = 1; i <= 3; i++) {
				hide_span = "cattype_" + i;
				document.getElementById(hide_span).style.display = "none";
			}
			r.onreadystatechange=function() { change_results(r, cat_typeval); };
			r.open("GET", "myaccount.php?ajax=yes&cmd=repopulate_cattype&this_catid="+this_catid+"&this_catnum="+current_cat, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}		
		
	}
	function store_thiscat(this_catid) {
		var current_cat = document.getElementById("current_cat").value;
		var cat_val = "stored_cat" + current_cat;
		document.getElementById(cat_val).value = this_catid;
		if (this_catid != 'def') {
			var cat_typeval = "cattype_"+ current_cat;
			var cat_mfrval = "catmfr_"+ current_cat;
			pop_dir_mfr(this_catid);			
			pop_dir_type(this_catid);			
		}
	}
	function populate_states(country, state_div, state_span) {
		//alert('country: ' + country + ' state_div: ' + state_div + ' state_span: ' + state_span);
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, state_span); };
			r.open("GET", "myaccount.php?ajax=yes&cmd=populate_states&country="+country+"&state_div="+state_div, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	function display_upload(this_photo) {
		var i;
		var hide_span;
		var highlight_span;
		for (i = 1; i <=6; i++) {
			hide_span = "modify_file" + i;
			highlight_span = "userimg" + i;
			if (i == this_photo) {
				document.getElementById(hide_span).style.display = 'block';	
				document.getElementById(highlight_span).style.backgroundColor = 'red';
			}
			else {
				document.getElementById(highlight_span).style.backgroundColor = 'white';
				document.getElementById(hide_span).style.display = 'none';	
			}
		}
	}
	var singleSelect = true;  // Allows an item to be selected once only
	var sortSelect = true;  // Only effective if above flag set to true
	var sortPick = true;  // Will order the picklist in sort sequence
	
	function initIt(left_select, right_select) {
	
	  var selectList = document.getElementById(left_select);
	
	  var pickList = document.getElementById(right_select);
	
	  var pickOptions = pickList.options;
	
	  pickOptions[0] = null;  // Remove initial entry from picklist (was only used to set default width)
	
	  selectList.focus();  // Set focus on the selectlist
	
	}
	
	function add_bustype(left_select, right_select) {
		if (document.getElementById(right_select).length >= 3) {
			alert('You have already selected 3 business types. Please remove one to add another.');	
		}		
		else {
	  	  
	  	  var selectList = document.getElementById(left_select);
		      
		  var selectIndex = selectList.selectedIndex;
		
		  var selectOptions = selectList.options;
		
		  var pickList = document.getElementById(right_select);
		
		  var pickOptions = pickList.options;
		
		  var pickOLength = pickOptions.length;
		
		  // An item must be selected
		
		  if (selectIndex > -1) {
		
		    pickOptions[pickOLength] = new Option(selectList[selectIndex].text);
		
		    pickOptions[pickOLength].value = selectList[selectIndex].value;
		
    	    // If single selection, remove the item from the select list
		
		    if (singleSelect) {
		
		      selectOptions[selectIndex] = null;
		
		    }
		
		    if (sortPick) {
		
		      var tempText;
		
		      var tempValue;
		
		      // Sort the pick list
		
		      while (pickOLength > 0 && pickOptions[pickOLength].value < pickOptions[pickOLength-1].value) {
		
		        tempText = pickOptions[pickOLength-1].text;
		
		        tempValue = pickOptions[pickOLength-1].value;
		
		        pickOptions[pickOLength-1].text = pickOptions[pickOLength].text;
		
		        pickOptions[pickOLength-1].value = pickOptions[pickOLength].value;
		
		        pickOptions[pickOLength].text = tempText;
		
		        pickOptions[pickOLength].value = tempValue;
		
		        pickOLength = pickOLength - 1;
		
		      }
		
		    }
		
		  }
		}
		
	}
	function remove_bustype(left_select, right_select) {
		  var selectList = document.getElementById(left_select);
		
		  var selectOptions = selectList.options;
		
		  var selectOLength = selectOptions.length;
		
		  var pickList = document.getElementById(right_select);
		
		  var pickIndex = pickList.selectedIndex;
		
		  var pickOptions = pickList.options;
		
		  if (pickIndex > -1) {
		
		    // If single selection, replace the item in the select list
		
		    if (singleSelect) {
		
		      selectOptions[selectOLength] = new Option(pickList[pickIndex].text);
		
		      selectOptions[selectOLength].value = pickList[pickIndex].value;
		
		    }
		
		    pickOptions[pickIndex] = null;
		
		    if (singleSelect && sortSelect) {
		
		      var tempText;
		
		      var tempValue;
		
		      // Re-sort the select list
		
		      while (selectOLength > 0 && selectOptions[selectOLength].value < selectOptions[selectOLength-1].value) {
		
		        tempText = selectOptions[selectOLength-1].text;
		
		        tempValue = selectOptions[selectOLength-1].value;
		
		        selectOptions[selectOLength-1].text = selectOptions[selectOLength].text;
		
		        selectOptions[selectOLength-1].value = selectOptions[selectOLength].value;
		
		        selectOptions[selectOLength].text = tempText;
		
		        selectOptions[selectOLength].value = tempValue;
		
		        selectOLength = selectOLength - 1;
		
		      }
		
		    }
		
		  }		
		
		
		
	}
	function add_showpub() {
		document.getElementById("dir_show_public").checked = true;		
	}
	function remove_showndir() {
		document.getElementById("dir_showndir").checked = false;
	}
	function submit_directory_add(this_type) {
		validate_dir_add(this_type);
	}

	function validate_dir_dd(this_select) {
		var b;
		var thistype_arr = "";
		var optlength = this_select.options.length;
		var maxlength; 
		if (optlength < 3) maxlength = optlength;
		else maxlength = 3;
		for (b = 0; b < maxlength; b++) {
			if (this_select.options[b]){ //&& this_select.options[b].value != "undefined"
				//alert(this_select.options[b].text);
				thistype_arr += this_select.options[b].value + "|";
			}
		}
		return thistype_arr;
	}
	function default_photo() {
		var i;
        var radios = document.getElementsByName("image_default");
        var default_img = "";

        for (i = 0; i < radios.length; i++) {
            if (radios[i].checked) {
	            default_img = radios[i].value;
	            var this_default = i;
	            var this_img = "image" + default_img + "_url";
	            var imgurl = document.getElementById(this_img).value;
	            
            }
        }		
        if (imgurl == "") {
	    	alert('You must upload an image before you can select it as your default.'); 
	    	radios[this_default].checked = false;
		}
        else {
			var r = xml_connect();
			if (r)
			{		
				r.open("GET", "index_action.php?command=myaccount&cmd=update_default&imgurl="+imgurl, true); //+"&h="+h+"&t="+t
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);
			}		
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}		        
        }
        
	}
	//Doesn't really validate anymore, validation is elsewhere
	//Kept the name because I'm just not going to fix this crap right now
	function validate_dir_add(this_type)
	{
    	var listingtype=-1;
    	for (i=1;i<5;i++)
    	{
        	var dirtype=document.getElementById('dirtype' + i);
        	if (dirtype && dirtype.checked)
        	    listingtype=i;
	    }
		var bus_name = filter_urlstr(document.getElementById("dir_bus_name").value);
		var bus_phone = filter_urlstr(document.getElementById("dir_bus_phone").value);
		var countrybox=document.getElementById("dir_bus_country");
		var bus_country = countrybox.options[countrybox.selectedIndex].value;
		var bus_zip = filter_urlstr(document.getElementById("dir_bus_zip").value);
		var statebox=document.getElementById("dir_bus_state");
		var bus_state="";
		if (statebox)
		    bus_state = statebox.options[statebox.selectedIndex].value;
		var bus_city = filter_urlstr(document.getElementById("dir_bus_city").value);
		var bus_add1 = filter_urlstr(document.getElementById("dir_bus_add1").value);
		var bus_add2 = filter_urlstr(document.getElementById("dir_bus_add2").value);
		var bus_email = filter_urlstr(document.getElementById("dir_bus_email").value);
		var bus_website = filter_urlstr(document.getElementById("dir_bus_website").value);
		var bus_typeselect = document.getElementById("dir_bus_typeselect"); //select field
		var bus_promoline = filter_urlstr(document.getElementById("dir_bus_promoline").value);
		var bus_desc = filter_urlstr(document.getElementById("dir_bus_desc").value);
		var show_public=0;
		if (document.getElementById("dir_show_public").checked == true) 
		    show_public=1;
		var showndir=0
		if (document.getElementById("dir_showndir").checked == true)
		    showndir=1;

		var bustype_arr = "";
		var cat_array="";
		var cat_string="";
		var cat_count=0;
		for (i=0;i<3;i++)
		{
			//Business types selected
			if (bus_typeselect.options[i] && bus_typeselect.options[i].value != "undefined")
				bustype_arr+=bus_typeselect.options[i].value + ",";

		    //Check if category exists
		    var catdiv=document.getElementById('categorydiv' + i);
   		    var catid=document.getElementById('bus_catid' + i);
		    if (catdiv && catid)
		    {
    		    cat_count++;
    		    cat_array+=catid.value + ",";
    		    var type_string="", mfr_string="";
    		    var type_select=document.getElementById('dir_bus_typeselect' + i);
    		    var mfr_select=document.getElementById('dir_bus_mfrselect' + i);
    		    if (type_select && mfr_select)
    		    {
        		    //Go through each type and mfr for this category, add them to submit string
        		    for (x=0;x<3;x++)
        		    {
            		    if (type_select.options[x] && type_select.options[x].value!="undefined")
            		        type_string+=type_select.options[x].value + ",";
            		    if (mfr_select.options[x] && mfr_select.options[x].value!="undefined")
            		        mfr_string+=mfr_select.options[x].value + ",";
        		    }
        		    if (type_string!="")
        		        cat_string+="&cattype" + cat_count + "=" + type_string;
        		    if (mfr_string!="")
        		        cat_string+="&catmfr" + cat_count + "=" + mfr_string;
    		    }
		    }
		}
//		document.getElementById("display_myaccount").innerHTML = ""; //??????
		location.href = "#myaccount";
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, "myaccount_refresh"); };
			r.open("GET", "myaccount.php?modify_directory=yes&ajax=yes&update_type="+this_type+"&listing_type="+listingtype+"&bus_name="+bus_name+"&bus_phone="+bus_phone+"&bus_country="+bus_country+"&bus_zip="+bus_zip+"&bus_state="+bus_state+"&bus_city="+bus_city+"&bus_add1="+bus_add1+"&bus_add2="+bus_add2+"&bus_email="+bus_email+"&bus_website="+bus_website+"&bustype_arr="+bustype_arr+"&show_public="+show_public+"&showndir="+showndir+"&bus_promoline="+bus_promoline+"&bus_desc="+bus_desc+"&categories="+cat_array+cat_string, true); 
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else
			alert('not added');
	}	
	
	/*PROFILE FUNCTIONS*/
	function inc_webhits(dirid) {
		var r = xml_connect();
		if (r)	{		
			r.open("GET", "profilebox.php?inc_webhits=yes&ajax=yes&listingid="+dirid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	function inc_banhits(campid,adid) {
		var r = xml_connect();
		if (r)	{		
			r.open("GET", "profilebox.php?inc_banhits=yes&ajax=yes&adid="+adid+"&adcampid="+campid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	function show_text() {
		if(document.getElementById("txtad_0_1")) document.getElementById("txtad_0_1").style.display = "none";
		document.getElementById("prev_txt_ad").style.display = "block";
		document.getElementById("prev_txthead").innerHTML = document.getElementById("ban_txtheader").value;
		document.getElementById("prev_txtl1").innerHTML = document.getElementById("ban_txtl1").value;
		document.getElementById("prev_txtl2").innerHTML = document.getElementById("ban_txtl2").value;
		document.getElementById("prev_txturl").innerHTML = document.getElementById("ban_txtdispurl").value;
	}
	function show_banners(this_catid) {
		//var this_catid = document.getElementById("store_cid").value;
		//alert(this_catid);
		if (this_catid == "def") {
			document.getElementById("prev_other_ads").innerHTML = "";
			document.getElementById("prev_othertxt_ads").innerHTML = "";
		}
		else {
			var r = xml_connect();
			if (r)	{		
				r.onreadystatechange=function() { change_results(r, "prev_other_ads"); };
				r.open("GET", "profilebox.php?populate_banners=yes&ajax=yes&this_catid="+this_catid, true); //+"&h="+h+"&t="+t
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);
			}		
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}		
			var m = xml_connect();
			if (m)	{		
				m.onreadystatechange=function() { change_results(m, "prev_othertxt_ads"); };
				m.open("GET", "profilebox.php?populate_txtbans=yes&ajax=yes&this_catid="+this_catid, true); //+"&h="+h+"&t="+t
				m.setRequestHeader("Content-Type", "application/xml");
				m.setRequestHeader("Cache-Control", "no-cache"); 
				m.send(null);
			}		
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}		
		}		
	}	
		
	function inc_mapit(dirid) {
		var r = xml_connect();
		if (r)	{		
			r.open("GET", "profilebox.php?inc_mapit=yes&ajax=yes&listingid="+dirid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	
	function find_directions(dirid) {
		var my_dir = document.getElementById("mapit_directions").value;
		if (my_dir == "Type your address here") my_dir = "";
		my_dir = filter_urlstr(my_dir);
		
		var your_dir = document.getElementById("prof_address").value;
		your_dir = filter_urlstr(your_dir);
		if (my_dir == "") var map_url = "http://maps.yahoo.com/#mvt=m&q1="+your_dir;
		else var map_url = "http://maps.yahoo.com/#mvt=m&q2="+your_dir+"&q1="+my_dir;
		
		window.open (map_url,"mywindow","resizable=1,status=1,scrollbars=1,toolbar=1,location=1"); //,width=350,height=250
		var r = xml_connect();
		if (r)	{		
			r.open("GET", "profilebox.php?inc_mapit=yes&ajax=yes&listingid="+dirid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}	
	function goto_search(cat, mfrid, typeid) {
		document.getElementById("last_div_clicked").value = "goto_search";
		document.getElementById("last_clicked_mfr").value = mfrid;
		document.getElementById("last_clicked_catid").value = cat;
		document.getElementById("last_clicked_type").value = typeid;
		show_dd(cat, 'yes');
	}
	function focus_on_query() {

		if (document.getElementById("Email_Login") && document.getElementById("query")) {
			if (document.getElementById("Email_Login").value == "") {
				document.getElementById("query").focus();	
			}
		}
	}
	function chk_res(){
		var wi = screen.width;
		var he = screen.height;
		if (wi < "1024") {
			alert('This site was designed to be viewed at 1024x768 resolution. Your monitor is currently set for '+w+'x'+h+'. \n\nPlease see the FAQ page for more information on adjusting your screen resolution.');	
		}		
	}
	function focus_on_mfrlet(catname) {
		//var mfrlet = catname + "_mfr_search";
		//if (document.getElementById(mfrlet)) var this_mfrlet = document.getElementById(mfrlet).focus(); 
		if (document.getElementById("query")) var this_mfrlet = document.getElementById("query").focus(); 
	}	
	function show_readmore(this_div) {
		var show_div = "long_" + this_div;
		var hide_div = "short_" + this_div;
		document.getElementById(show_div).style.display = 'block';	
		document.getElementById(hide_div).style.display = 'none';	
	}
	function show_dir_table(table_num)
	{
		window.location.hash='top';
		var table_cnt = document.getElementById("searchdir_rowcnt").value;
		var num_rows = parseInt(document.getElementById("num_rows").value);
		var total_cnt = parseInt(document.getElementById("searchdir_totcnt").value);
		var dir_select = document.getElementById("change_dirpage");
		dir_select.selectedIndex = table_num;

		var dir_select1 = document.getElementById("change_dirpage1");
		dir_select1.selectedIndex = table_num;
		
		var i;
		var page_html = "";
		var tab_num = parseInt(table_num);
		
		if (table_cnt == table_num) {
			//alert('last ' + tab_num + '..' + table_cnt);
			var res_start = (num_rows * tab_num) + 1;
			var results = "Search results " + res_start + " - " + total_cnt + " of " + total_cnt;
			
			var pg_next = "<span class='fText'>next &gt;</span>";
			var prev_tab = tab_num - 1;
			var pg_prev = "<span class='fText'><a href='#' onclick='show_dir_table(\""+prev_tab+"\");'>&lt; prev</span>";
		}
		else if (tab_num == 0) {
			var results = "Search results " + "1 - " + num_rows + " of " + total_cnt;
			//alert('first ' + tab_num + '..' + table_cnt);
			var pg_prev = "<span class='fText'>&lt; prev</span>";
			var next_tab = tab_num + 1;
			var pg_next = "<span class='fText'><a href='#' onclick='show_dir_table(\""+next_tab+"\");'>next &gt;</span>";
		}
		else {
			//alert('neither ' + tab_num + '..' + table_cnt);
			var next_tab = tab_num + 1;
			var pg_next = "<span class='fText'><a href='#' onclick='show_dir_table(\""+next_tab+"\");'>next &gt;</span>";
			var prev_tab = tab_num - 1;
			var res_start = (num_rows * tab_num) + 1;
			var res_end  = res_start + num_rows - 1;
			var results = "Search results " + res_start + " - " + res_end + " of " + total_cnt

			var pg_prev = "<span class='fText'><a href='#' onclick='show_dir_table(\""+prev_tab+"\");'>&lt; prev</span>";
		}
		for (i = 0; i <= table_cnt; i++) {
			var this_page = i + 1;
			var table_id  = "dir_display"+i;
			if (i == tab_num) { //show this table
				document.getElementById(table_id).style.display = 'block';
			}
			else { //hide this table
				document.getElementById(table_id).style.display = 'none';
			}
		}
		document.getElementById("dirlist_prev").innerHTML = "";
		document.getElementById("dirlist_next").innerHTML = "";
		document.getElementById("dirlist_prev").innerHTML = pg_prev;
		document.getElementById("dirlist_next").innerHTML = pg_next;
		document.getElementById("dir_searchres").innerHTML = results;
		document.getElementById("dir_searchres1").innerHTML = results;

		document.getElementById("dirlist_prev1").innerHTML = "";
		document.getElementById("dirlist_next1").innerHTML = "";
		document.getElementById("dirlist_prev1").innerHTML = pg_prev;
		document.getElementById("dirlist_next1").innerHTML = pg_next;
	}
	
	function show_msg_table(table_num) {
		window.location.hash='top';
		var table_cnt = document.getElementById("searchmsg_rowcnt").value;
		var num_rows = parseInt(document.getElementById("msg_num_rows").value);
		var total_cnt = parseInt(document.getElementById("searchmsg_totcnt").value);
		var dir_select = document.getElementById("change_msgpage");
		dir_select.selectedIndex = table_num;

		var i;
		var page_html = "";
		var tab_num = parseInt(table_num);
		
		if (table_cnt == table_num) {
			//alert('last ' + tab_num + '..' + table_cnt);
			var res_start = (num_rows * tab_num) + 1;
			var results = "Search results " + res_start + " - " + total_cnt + " of " + total_cnt;
			
			var pg_next = "<span class='fText'>next &gt;</span>";
			var prev_tab = tab_num - 1;
			var pg_prev = "<span class='fText'><a href='#' onclick='show_msg_table(\""+prev_tab+"\");'>&lt; prev</span>";
		}
		else if (tab_num == 0) {
			var results = "Search results " + "1 - " + num_rows + " of " + total_cnt;
			//alert('first ' + tab_num + '..' + table_cnt);
			var pg_prev = "<span class='fText'>&lt; prev</span>";
			var next_tab = tab_num + 1;
			var pg_next = "<span class='fText'><a href='#' onclick='show_msg_table(\""+next_tab+"\");'>next &gt;</span>";
		}
		else {
			//alert('neither ' + tab_num + '..' + table_cnt);
			var next_tab = tab_num + 1;
			var pg_next = "<span class='fText'><a href='#' onclick='show_msg_table(\""+next_tab+"\");'>next &gt;</span>";
			var prev_tab = tab_num - 1;
			var res_start = (num_rows * tab_num) + 1;
			var res_end  = res_start + num_rows - 1;
			var results = "Search results " + res_start + " - " + res_end + " of " + total_cnt

			var pg_prev = "<span class='fText'><a href='#' onclick='show_msg_table(\""+prev_tab+"\");'>&lt; prev</span>";
		}
		for (i = 0; i <= table_cnt; i++) {
			var this_page = i + 1;
			var table_id  = "msg_display"+i;
			if (i == tab_num) { //show this table
				document.getElementById(table_id).style.display = 'block';
			}
			else { //hide this table
				document.getElementById(table_id).style.display = 'none';
			}
		}
		document.getElementById("msglist_prev").innerHTML = "";
		document.getElementById("msglist_next").innerHTML = "";
		document.getElementById("msglist_prev").innerHTML = pg_prev;
		document.getElementById("msglist_next").innerHTML = pg_next;
		document.getElementById("msg_searchres").innerHTML = results;
	}

	
		
	function delete_contact(cid) {
		var r = xml_connect();
		if (r)
		{	
			r.onreadystatechange=function() { change_results(r, 'add_remove'); dir_tools_state(r, 'add_remove', '', 'none'); };
			r.open("GET", "profilebox.php?ajax=yes&delete_contact=yes&cid="+cid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}		
	}
	function delete_contact_right(cid) {
		var this_cidrow = "table_contacts_" + cid;
		document.getElementById(this_cidrow).style.display = 'none';
		var r = xml_connect();
		if (r)
		{	
			r.onreadystatechange=function() { change_results(r, 'add_remove_right'); };
			r.open("GET", "profilebox.php?ajax=yes&delete_contact=yes&cid="+cid+"&rightnav=yes", true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}		
	}

		
	function hide_contactlist() {
		if (document.getElementById("table_contacts"))
			document.getElementById("table_contacts").style.display = 'none';
		
	}
	function repop_rightdir() {
		var m = xml_connect();
		if (m)
		{		
			m.onreadystatechange=function() { change_results(m, 'show_mycontacts'); };
			m.open("GET", "rightnav.php?ajax=yes&cmd=account_right_col&refresh=yes", true); //+"&h="+h+"&t="+t
			m.setRequestHeader("Content-Type", "application/xml");
			m.setRequestHeader("Cache-Control", "no-cache"); 
			m.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	function block_contact(cid) {
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'add_remove'); dir_tools_state(r, 'block_unblock', 'none', ''); };
			r.open("GET", "profilebox.php?ajax=yes&block_contact=yes&cid="+cid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}	
	}
	function block_contact_msg(cid) {
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'add_remove_msg'); };
			r.open("GET", "profilebox.php?ajax=yes&block_contact=yes&cid="+cid+"&from_msgs=y", true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}	
	}
		
	function unblock_contact(cid) {
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'add_remove'); dir_tools_state(r, 'block_unblock', '', 'none'); };
			r.open("GET", "profilebox.php?ajax=yes&unblock_contact=yes&cid="+cid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}	
	}	
	function unblock_contact_msg(cid) {
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'add_remove_msg'); };
			r.open("GET", "profilebox.php?ajax=yes&unblock_contact=yes&cid="+cid+"&from_msgs=y", true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}	
	}	
		
	function add_contact(cid) {
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'add_remove'); dir_tools_state(r, 'add_remove', 'none', ''); };
			r.open("GET", "profilebox.php?ajax=yes&add_contact=yes&cid="+cid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}		
	}

	
	//This function was made because the site structure changed quite a bit and I don't have time to recode all the ajax return functions
	function dir_tools_state(r, state, first_state, second_state)
	{
		if (r.readyState==4)
		    if (r.status==200)
		    {
    		    if (state=='block_unblock')
    		    {
          	        document.getElementById('addremove_contacts').style.display=first_state;
          	        document.getElementById('blockunblock_contacts').style.display='';
          	        document.getElementById('block_contact_link').style.display=first_state;
          	        document.getElementById('unblock_contact_link').style.display=second_state;
    		    }
    		    if (state=='add_remove')
    		    {
          	        document.getElementById('blockunblock_contacts').style.display=first_state;
          	        document.getElementById('addremove_contacts').style.display='';
          	        document.getElementById('add_contact_link').style.display=first_state;
          	        document.getElementById('delete_contact_link').style.display=second_state;
    		    }
		    }
	}

		
	function dir_email_profile()
	{
		var dir_main=document.getElementById('dir_tools_main');
		var dir_title=document.getElementById('dir_tools_title');
		var dir_refer=document.getElementById("dir_tools_refer");
		var dir_body=document.getElementById("dir_tools_body");

		if (dir_main && dir_title && dir_refer && dir_body)
		{
    		dir_body.innerHTML=dir_refer.innerHTML;
    		dir_title.innerHTML='Email Profile';
    		dir_main.style.display='';
		}
		
//		document.getElementById("profile_email").innerHTML = "<table class='fText1' align='center'><tr><td><span class='fText1'>Enter the e-mail address of the person <br>you would like to refer to this profile.</span></td><td><input type='text' class='input' id='email_thisprofile' name='email_thisprofile' onkeypress='return entsub(\"email_profform\")'></td><td><a href='#emailprofile' onclick='send_profile();'><img src='images/button_submit.gif' border=0></td></tr></table><br>";
//		document.getElementById("email_thisprofile").focus();
	}
	function dir_send_message()
	{
		var dir_main=document.getElementById('dir_tools_main');
		var dir_title=document.getElementById('dir_tools_title');
		var dir_msg=document.getElementById("dir_tools_msg");
		var dir_body=document.getElementById("dir_tools_body");

		if (dir_main && dir_title && dir_msg && dir_body)
		{
    		dir_body.innerHTML=dir_msg.innerHTML;
    		dir_title.innerHTML='Send Message';
    		dir_main.style.display='';
		}
		
	}
	function send_profile() {
		var cid = document.getElementById("email_thisprofid").value;
		var send_email = filter_urlstr(document.getElementById("email_thisprofile").value);
		if (checkEmail(send_email) == false) {
			alert('You must enter a valid email address.');
			document.getElementById("email_thisprofile").style.backgroundColor = 'red';
			document.getElementById("email_thisprofile").focus();
			status = false;
			return status;
		}
		else {
			document.getElementById("email_thisprofile").style.backgroundColor = 'white';
			var r = xml_connect();
			if (r)
			{		
				r.onreadystatechange=function() { change_results(r, 'dir_tools_body'); };
				r.open("GET", "profilebox.php?ajax=yes&cmd=send_thisprofile&cid="+cid+"&send_email="+send_email, true); //+"&h="+h+"&t="+t
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);
			}		
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}		
		}
	}
	function submit_send() {
		var cid = document.getElementById("sendmsg_thisprofid").value;
		var this_msg = document.getElementById("send_msg").value;
		
		new_msg = filter_urlstr(this_msg);
		//alert(this_msg);
		//alert(new_msg);		
		var this_subject = document.getElementById("send_subject").value;
		new_subject = filter_urlstr(this_subject);
		
		if (this_msg == "") {
			alert('You must enter text for the message.');
			document.getElementById("send_msg").style.backgroundColor = 'red';
			document.getElementById("send_msg").focus();
			status = false;
			return status;
		}
		else {
			document.getElementById("send_msg").style.backgroundColor = 'white';
			var r = xml_connect();
			if (r)
			{		
				r.onreadystatechange=function() { change_results(r, 'dir_tools_body'); };
				r.open("GET", "profilebox.php?ajax=yes&cmd=send_thismsg&cid="+cid+"&send_msg="+new_msg+"&send_subject="+new_subject, true); //+"&h="+h+"&t="+t
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);
			}		
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}		
		}
	}	
	function submit_reply() {
		var cid = document.getElementById("reply_dirid").value;
		var this_msg = document.getElementById("reply_msg").value;
		this_msg = filter_urlstr(this_msg);
		var this_subject = document.getElementById("reply_subject").value;
		this_subject = filter_urlstr(this_subject);
		if (this_msg == "") {
			alert('You must enter text for the message.');
			document.getElementById("reply_msg").style.backgroundColor = 'red';
			document.getElementById("reply_msg").focus();
			status = false;
			return status;
		}
		else {
			document.getElementById("reply_msg").style.backgroundColor = 'white';
			var r = xml_connect();
			if (r)
			{		
				document.getElementById("reply_button").innerHTML = "";
				r.onreadystatechange=function() { change_results(r, 'reply_content'); };
				r.open("GET", "myaccount.php?ajax=yes&cmd=send_thisreply&cid="+cid+"&send_msg="+this_msg+"&send_subject="+this_subject, true); //+"&h="+h+"&t="+t
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);
			}		
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}		
		}
	}		
	function delete_msgs() {
		var del_msg = document.getElementsByName("delete_message");
		//delete_message	
		var del_ids = "";
		for(var i = 0; i < del_msg.length; i++) {
			if(del_msg[i].checked == true){
				//alert(del_msg[i].value);	
				if (del_msg[i].value != "all")	del_ids += del_msg[i].value + "|";
			}
		}
		if (del_ids != "") {
			var r = xml_connect();
			if (r)
			{		
				r.onreadystatechange=function() { change_results(r, 'display_myaccount'); };
				r.open("GET", "myaccount.php?cmd=show_messages&ajax=yes&del_msgs="+del_ids, true); //+"&h="+h+"&t="+t
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);
			}		
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}				
		}
	}
	function report_member(cid){
		//alert('reporting user');
		
		var answer = confirm("Are you sure you want to report this user? \n\nReasons to report a user include: inappropriate content, leaving vulgar comments, misuse of UsedPrice.com, etc.")
		if (answer){ //send e-mail (add to table) to report a user
			var r = xml_connect();
			if (r)
			{		
				//r.onreadystatechange=function() { change_results(r, 'profile_email'); };
				r.open("GET", "profilebox.php?ajax=yes&cmd=report_user&cid="+cid, true); //+"&h="+h+"&t="+t
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);
			}		
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}	
		}
		else{
		}
		
	}
	function thisimg_big(iid) {
		document.getElementById("last_clicked_pimg").value = iid;
		var r = xml_connect();
		if (r)
		{		
			document.getElementById("bigimg_display").style.display = "block";
			r.onreadystatechange=function() { change_results(r, 'bigimg_display'); };
			r.open("GET", "profilebox.php?ajax=yes&cmd=show_big&iid="+iid, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	function thisimg_item(iid, item_id, catname) {
		var r = xml_connect();
		if (r)
		{		
			document.getElementById("itemimg_display").style.display = "block";
			r.onreadystatechange=function() { change_results(r, 'itemimg_display'); };
			r.open("GET", "lookupbox.php?ajax=yes&cmd=show_item&iid="+iid+"&item_id="+item_id+"&catname="+catname, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
		
	function hide_bigimg() {
		document.getElementById("bigimg_display").style.display = "none";
	}
	function new_comment(com_type) {
		if (com_type == "general") {
			document.getElementById("post_commenttext_gen").value = "";
			document.getElementById("add_comment_gen").style.display = "block";
			location.href = "#comment_post_gen";
			document.getElementById("post_commenttext_gen").focus();
		}
		else if (com_type == "photo") {
			document.getElementById("post_commenttext_photo").value = "";
			document.getElementById("add_comment_photo").style.display = "block";
			location.href = "#comment_post_photo";
			document.getElementById("post_commenttext_photo").focus();
		}
		else if (com_type == "item") {
			var r = xml_connect();
			if (r)
			{		
				var itemid = document.getElementById("last_clicked_itemid").value;
				//alert(itemid);
				r.onreadystatechange=function() { change_results(r, 'post_commenttext_item'); };
				r.open("GET", "lookupbox.php?ajax=yes&cmd=update_item_comment&com_itemid="+itemid, true); //+"&h="+h+"&t="+t
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);
			}		
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}				
			document.getElementById("post_commenttext_item").value = "";
			document.getElementById("add_comment_item").style.display = "block";
			document.getElementById("add_comment_item_submit").style.display = "block";
			location.href = "#comment_post_item";
			document.getElementById("post_commenttext_item").focus();
		}		
		 
	}
	function collapse_review() {
		document.getElementById("add_comment_item_submit").style.display = "none";
		document.getElementById("add_comment_item").style.display = "none";
	}
	function post_comment(com_type) {
		var this_text;
		var msg_span;
		var msg_row;
		var this_source;
		if (com_type == "general") {
			this_text = filter_urlstr(document.getElementById("post_commenttext_gen").value);
			msg_span = "msg_comment_gen";
			msg_row = "add_comment_gen";
			this_source = document.getElementById("last_clicked_listing").value;
		}
		else if (com_type == "photo") {
			this_text = filter_urlstr(document.getElementById("post_commenttext_photo").value);
			msg_span = "msg_comment_photo";
			msg_row = "add_comment_photo";
			this_source = document.getElementById("last_clicked_pimg").value;
		}
		else if (com_type == "item") {
			this_text = filter_urlstr(document.getElementById("post_commenttext_item").value);
			msg_span = "msg_comment_item";
			msg_row = "add_comment_item";
			document.getElementById("add_comment_item_submit").style.display = "none";
			this_source = document.getElementById("last_clicked_itemid").value;
			var rating1 = document.getElementById("rating1").value;
			var rating2 = document.getElementById("rating2").value;
			var rating3 = document.getElementById("rating3").value;
			var rating4 = document.getElementById("rating4").value;
			if (rating1 > 0 | rating2 > 0 | rating3 > 0 | rating4 > 0) {
				var add_rating = 1;		
			}	
			//alert('add rating ' + add_rating);
		}		
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, msg_span); };
			if (add_rating == 1) r.open("GET", "profilebox.php?ajax=yes&insert_comment=yes&type="+com_type+"&text="+this_text+"&source="+this_source+"&add_rating=yes&rating1="+rating1+"&rating2="+rating2+"&rating3="+rating3+"&rating4="+rating4, true); //+"&h="+h+"&t="+t
			else r.open("GET", "profilebox.php?ajax=yes&insert_comment=yes&type="+com_type+"&text="+this_text+"&source="+this_source, true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			document.getElementById(msg_row).style.display = "none";
			r.send(null);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	/*LOGIN FUNCTIONS*/
	function login_sess() {
		var r = xml_connect();
		if (r)
		{		
			var email = filter_urlstr(document.getElementById("Email_Login").value);
			var password = filter_urlstr(document.getElementById("Password_Login").value);
			r.onreadystatechange=function() { change_results(r, 'show_login'); };
			var params = "Email="+email+"&Password="+password+"&command=login&submit=yes"; //&submit="+submit1+"
			r.open("POST", "index_action.php", true); //+"&h="+h+"&t="+t
			
			r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			r.setRequestHeader("Content-length", params.length);
			r.setRequestHeader("Connection", "close");
			r.send(params);

		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}
	function logout_sess() {
		var r = xml_connect();
		if (r)
		{		
			r.onreadystatechange=function() { change_results(r, 'show_login'); };
			var params = "command=login&logout=true";
			r.open("POST", "index_action.php", true); //+"&h="+h+"&t="+t
			r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			r.setRequestHeader("Content-length", params.length);
			r.setRequestHeader("Connection", "close");
			r.send(params);
		}		
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}			
	}	
	function forgot_password(this_form) {
		if (this_form == "non_valid") {
			email = document.getElementById("nonvalid_email").value;			
		}
		else eval("var email = document."+this_form+".Email_Login.value;");	
		email = email.replace(/^\s*|\s*$/g,'');
		email = email.replace(/^\s*/g,'');
		email = email.replace(/\s*$/g,'');
		//email = filter_urlstr(email);
		if (document.getElementById("nonval_pid")) var store_pid = document.getElementById("nonval_pid").value;
		else var store_pid  = "";
		if 	(checkEmail(email) == false) {
			alert('You must enter a valid e-mail address. We will send the password to that address');			
		}
		else { //begin function to email the password
			var r = xml_connect();
			if (r)
			{
				r.onreadystatechange=function() { change_results(r, 'login_message'); };
				r.open("GET", "signup.php?ajax=yes&cmd=forgot_pw&email="+email+"&store_pid="+store_pid, true);
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);			
			}
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}	
		}			
	}	

	
	/*SIGNUP FUNCTIONS*/

	function change_numbers() {
		if (document.getElementById("toggle_phone").value == "us") {
			document.getElementById("us_phone").style.display = "none";
			document.getElementById("nonus_phone").style.display = "block";
			document.getElementById("toggle_phone").value = "non_us";
			document.getElementById("togglephone_text").innerHTML = "US phone?";
			document.getElementById("nonus_phonenumber").focus();		
		}
		else {
			document.getElementById("us_phone").style.display = "block";
			document.getElementById("nonus_phone").style.display = "none";
			document.getElementById("toggle_phone").value = "us";
			document.getElementById("togglephone_text").innerHTML = "Non-US phone?";
			document.getElementById("at").focus();		
		}	
	}
	function clear_signup1()	 {
		document.getElementById("FName").value = "";
		document.getElementById("LName").value = "";
		document.getElementById("Company").value = "";
		document.getElementById("Email").value = "";
		document.getElementById("EmailVerify").value = "";
		document.getElementById("Password").value = "";
		document.getElementById("PasswordVerify").value = "";
		document.getElementById("at").value = "";
		document.getElementById("e").value = "";
		document.getElementById("n").value = "";
		document.getElementById("EmailVerify").style.backgroundColor = 'white';
		document.getElementById("Email").style.backgroundColor = 'white';
		document.getElementById("Password").style.backgroundColor = 'white';
		document.getElementById("PasswordVerify").style.backgroundColor = 'white';
		
	}
	function validate_signup_dupemail(captcha_val) {
		if (captcha_val == "valid") {
			captcha_val = filter_urlstr(captcha_val);
			var email = document.getElementById("Email").value;
			email = filter_urlstr(email);
			var r = xml_connect();
			r.onreadystatechange=function() { validate_signup2(r, 'email_dup', captcha_val); };
			r.open("GET", "signup.php?ajax=yes&cmd=chk_email_dup&email="+email, true);
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}
		else validate_signup1(captcha_val);
		
	}
	//this validates the email and captcha
	//connects to signup.php
	function validate_signup2(r, field, captcha_val)	{
		try
		{
			if (r.readyState==4)
				if (r.status==200)
				{
					var chk_val =r.responseText;
					if (field == "email_dup") {
	    				if (chk_val > 0) {
							alert('This email address already exists in our database. Please use the \'Forgot My Password\' link and we will send you your password.');
							document.getElementById("Email").style.backgroundColor = 'red';
							document.getElementById("Email").focus();
						}		
						else {
							document.getElementById("Email").style.backgroundColor = 'white';							
							validate_signup1(captcha_val);
						}
					}
	    		}
		}
		catch (e) {	}
	}	
	
	function checkEmail(email) {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))	return (true)
		else return (false)
	}	
	function checkUrl(theurl) {
	    var v = new RegExp(); 
	    v.compile("[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
	    if (!v.test(theurl)) { 
	        return false; 
	    } 
	}
	function URL( url, name ) {
		this.url = url;
		this.name = name;
	}
	function validate_signup1(captcha_val) {
		var send_to_checkout = document.getElementById("send_to_checkout").value;
		var fname = filter_urlstr(document.getElementById("FName").value);
		var lname = filter_urlstr(document.getElementById("LName").value);
		if (document.getElementById("toggle_phone").value == "us") {
			var phone = document.getElementById("at").value  + document.getElementById("e").value + document.getElementById("n").value;		}
		else {
			var phone = document.getElementById("nonus_phonenumber").value;		
		}
		phone = filter_urlstr(phone);
		var company = filter_urlstr(document.getElementById("Company").value);
        
		var cnt_emcam = document.getElementById("emcam_cnt").value;
		//var chkbox = document.getElementById("emcam_chk"); //radio field
        var select_chkbox = "";
        var this_chkbox;
        
        for (i = 0; i < cnt_emcam; i++) {
	        this_chkbox = "emcam_" + i;
	        var this_emcam = document.getElementById(this_chkbox);
            if (this_emcam.checked == false) select_chkbox += this_emcam.value + "|";
        }		
        document.getElementById("sel_chkbox").value = select_chkbox;
		//alert(select_chkbox);
        				
		var email = filter_urlstr(document.getElementById("Email").value);
		var emailverify = filter_urlstr(document.getElementById("EmailVerify").value);
		var password = filter_urlstr(document.getElementById("Password").value);
		var h = document.getElementById("h").value;
		var t = document.getElementById("t").value;
		var passwordverify = filter_urlstr(document.getElementById("PasswordVerify").value);
		var status = true;

		var check_tos = document.getElementById("tos_check");
		if (captcha_val == "valid") {
			if (check_tos.checked == false) {
				alert('You must agree to the Terms of Service to create an account');
				document.getElementById("tos_check").style.backgroundColor = 'red';
				//document.getElementById("tos_text").style.backgroundColor = 'red';
				status = false;
				return status;
			}
			else {
				document.getElementById("tos_check").style.backgroundColor = 'white';
				//document.getElementById("tos_text").style.backgroundColor = 'white';
			}
			if (t == "") {
				alert('You must enter the information from the image.');
				document.getElementById("t").style.backgroundColor = 'red';
				document.getElementById("t").focus();
				status = false;
				return status;
			}
			else {
				document.getElementById("t").style.backgroundColor = 'white';
			}
			//now check if this email already exists in the db
			//we will also want to verify that an e-mail address is an actual e-mail address (check for "@", domain extension, etc)
			if (email == "") {
				alert('You must enter an e-mail address');
				document.getElementById("Email").style.backgroundColor = 'red';
				document.getElementById("Email").focus();
				status = false;
				return status;
			}
			else document.getElementById("Email").style.backgroundColor = 'white';
			if (emailverify == "") {
				alert('You must verify your e-mail address');
				document.getElementById("EmailVerify").style.backgroundColor = 'red';
				document.getElementById("EmailVerify").focus();
				status = false;
				return status;
			}
			else document.getElementById("EmailVerify").style.backgroundColor = 'white';
			
			if (email != emailverify) {
				alert('The email address you enter MUST match the verified e-mail address');
				document.getElementById("Email").style.backgroundColor = 'red';
				document.getElementById("EmailVerify").style.backgroundColor = 'red';
				document.getElementById("Email").focus();
				status = false;
				return status;
			}
			else {
				document.getElementById("Email").style.backgroundColor = 'white';
				document.getElementById("EmailVerify").style.backgroundColor = 'white';
			}
			
			if (password.length < 6 | password.length > 15) {
				alert('You must enter a password that is between 6 and 15 characters');
				document.getElementById("Password").style.backgroundColor = 'red';
				document.getElementById("Password").focus();
				status = false;
				return status;
			}
			else document.getElementById("Password").style.backgroundColor = 'white';
	
			if (password == "") {
				alert('You must enter a password');
				document.getElementById("Password").style.backgroundColor = 'red';
				document.getElementById("Password").focus();
				status = false;
				return status;
			}
			else document.getElementById("Password").style.backgroundColor = 'white';
			if (passwordverify == "") {
				alert('You must verify your password');
				document.getElementById("PasswordVerify").style.backgroundColor = 'red';
				document.getElementById("PasswordVerify").focus();
				status = false;
				return status;
			}
			else document.getElementById("PasswordVerify").style.backgroundColor = 'white';
			
			if (password != passwordverify) {
				alert('The password you enter MUST match the verified password');
				document.getElementById("Password").style.backgroundColor = 'red';
				document.getElementById("PasswordVerify").style.backgroundColor = 'red';
				document.getElementById("Password").focus();
				status = false;
				return status;
			}
			else {
				document.getElementById("Password").style.backgroundColor = 'white';
				document.getElementById("PasswordVerify").style.backgroundColor = 'white';
			}
			if (passwordverify.length < 6 | passwordverify.length > 15) {
				alert('Your password verification must be between 6 and 15 characters');
				document.getElementById("PasswordVerify").style.backgroundColor = 'red';
				document.getElementById("PasswordVerify").focus();
				status = false;
				return status;
			}
			else document.getElementById("PasswordVerify").style.backgroundColor = 'white';
			var email_format = checkEmail(email);
			if (email_format == false) {
				alert('You must enter a VALID e-mail address');
				document.getElementById("Email").style.backgroundColor = 'red';
				document.getElementById("Email").focus();
				status = false;
				return status;			
			}
			else {
				document.getElementById("Email").style.backgroundColor = 'white';
			}
		}		
		else {
			document.getElementById("send_to_checkout").value = 0;	
		}
		if (status == true) {
    			if (captcha_val=="invalid")
    			{
               		captcha_t=document.createElement("input");
   		            captcha_t.name="t";
   		            captcha_t.type="hidden";
   		            captcha_t.value="";
   		            document.getElementById("create_user").appendChild(captcha_t);
			    }
    			document.getElementById("create_user").submit();		
			
			/*var r = xml_connect();
			if (r)
			{
				var goto_purchase = document.getElementById("goto_purchase").value;
				var store_pid = document.getElementById("store_pid").value;
				
				if (captcha_val == "invalid") t = "";
				r.onreadystatechange=function() { change_results(r, 'display_signup'); };
				r.open("GET", "signup.php?select_chkbox="+select_chkbox+"&send_to_checkout="+send_to_checkout+"&ajax=yes&cmd=process_form&fname="+fname+"&lname="+lname+"&company="+company+"&email="+email+"&password="+password+"&phone="+phone+"&h="+h+"&t="+t+"&goto_purchase="+goto_purchase+"&store_pid="+store_pid+"&captcha_val="+captcha_val, true); //+"&h="+h+"&t="+t
				r.setRequestHeader("Content-Type", "application/xml");
				r.setRequestHeader("Cache-Control", "no-cache"); 
				r.send(null);
	
			}
			else {
				alert('not added');
				//document.getElementById("searchform").submit();
			}	*/
		}
	}
	function submit_signup1(captcha_val)	 {
		
		document.getElementById("signup_msg").innerHTML = "";
		var fname = document.getElementById("FName").value;
		var lname = document.getElementById("LName").value;
		if (document.getElementById("toggle_phone").value == "us") {
			var phone = document.getElementById("at").value  + document.getElementById("e").value + document.getElementById("n").value;		}
		else {
			var phone = document.getElementById("nonus_phonenumber").value;		
		}
	
		var company = document.getElementById("Company").value;
		var email = document.getElementById("Email").value;
		var emailverify = document.getElementById("EmailVerify").value;
		var password = document.getElementById("Password").value;
		var passwordverify = document.getElementById("PasswordVerify").value;

		validate_signup_dupemail(captcha_val);
		
	}
		
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	//This is broken in firefox(not firefox 3 though.. still broken in opera)
	function autoTab(input,len, e) {
		var keyCode = (isNN) ? e.which : e.keyCode;
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		if(input.value.length >= len && !containsElement(filter,keyCode)) {
			input.value = input.value.slice(0, len);
			input.form[(getIndex(input)+1) % input.form.length].focus();
		}
		
		function containsElement(arr, ele) {
			var found = false, index = 0;
			while(!found && index < arr.length)
			if(arr[index] == ele)
			found = true;
			else
			index++;
			return found;
		}
		
		
		function getIndex(input) {
			var index = -1, i = 0, found = false;
			while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
			return index;
		}
		return true;
	}
	
	/*PRODUCT FUNCTION*/
	function nav_prodtabs(tabname){
		if (tabname == "price") {
			document.getElementById("prodtab_price").innerHTML = '<img src="images/tabPricing.gif" hspace=2 border="0">';
			document.getElementById("show_prodtab_price").style.display = "block";
			document.getElementById("show_prodtab_specs").style.display = "none";
			document.getElementById("show_prodtab_desc").style.display = "none";
			document.getElementById("prodtab_specs").innerHTML = '<img src="images/tabSpecsOff.gif" hspace=2 border="0">';
			document.getElementById("prodtab_desc").innerHTML = '<img src="images/tabDescOff.gif" hspace=2 border="0">';			
		}
		else if (tabname == "specs") {
			document.getElementById("prodtab_specs").innerHTML = '<img src="images/tabSpecs.gif" hspace=2 border="0">';
			document.getElementById("show_prodtab_specs").style.display = "block";
			document.getElementById("show_prodtab_price").style.display = "none";
			document.getElementById("show_prodtab_desc").style.display = "none";
			document.getElementById("prodtab_price").innerHTML = '<img src="images/tabPricingOff.gif" hspace=2 border="0">';
			document.getElementById("prodtab_desc").innerHTML = '<img src="images/tabDescOff.gif" hspace=2 border="0">';
		}
		else if (tabname == "desc") {
			document.getElementById("prodtab_desc").innerHTML = '<img src="images/tabDesc.gif" hspace=2 border="0">';
			document.getElementById("show_prodtab_desc").style.display = "block";
			document.getElementById("show_prodtab_price").style.display = "none";
			document.getElementById("show_prodtab_specs").style.display = "none";
			document.getElementById("prodtab_price").innerHTML = '<img src="images/tabPricingOff.gif" hspace=2 border="0">';
			document.getElementById("prodtab_specs").innerHTML = '<img src="images/tabSpecsOff.gif" hspace=2 border="0">';
		}	
	}
	function add_boaprice(itemid) {
		var boa_price = filter_urlstr(document.getElementById("boa_price").value);
		var r = xml_connect();
		if (r)
		{
			r.onreadystatechange=function() { change_results(r, 'boa_ins'); };
			r.open("GET", "lookupbox.php?ajax=yes&cmd=add_boaprice&itemid="+itemid+"&boa_price="+boa_price, true);
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}				
	}	
	function update_boaprice(itemid) {
		var boa_price = filter_urlstr(document.getElementById("boa_price").value);
		var public_price_id = document.getElementById("public_price_id").value;
		var r = xml_connect();
		if (r)
		{
			r.onreadystatechange=function() { change_results(r, 'boa_ins'); };
			r.open("GET", "lookupbox.php?ajax=yes&cmd=update_boaprice&itemid="+itemid+"&boa_price="+boa_price+"&public_price_id="+public_price_id, true);
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}				
	}		
	function show_pricing_info(itemid, gawid) {
		document.getElementById("show_thisprice").style.display = "block";
		document.getElementById("show_thisprice").innerHTML = "<img src='images/ajax_loader.gif'>";
		if (document.getElementById("show_thisaccess")) document.getElementById("show_thisaccess").style.display = "none";
		var r = xml_connect();
		if (r)
		{
			r.onreadystatechange=function() { change_results(r, 'show_thisprice'); };
			r.open("GET", "lookupbox.php?ajax=yes&cmd=useclick&itemid="+itemid+"&gawid="+gawid, true);
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}	
	}
	function select_rating(tableid, rating) {
		var this_table = "item_rating" + tableid;
		var this_var = "rating" + tableid;
		var rating_num;
		if (rating == "one") rating_num = 1;
		else if (rating == "two") rating_num = 2;
		else if (rating == "three") rating_num = 3;
		else if (rating == "four") rating_num = 4;
		else if (rating == "five") rating_num = 5;
		document.getElementById(this_var).value = rating_num;
		var rating_img = "images/rating/select_"+rating+".gif";
		var mytable = document.getElementById(this_table);
		//mytable.setAttribute("background", rating_img);
		mytable.style.backgroundImage='url(' + rating_img + ')';
	}
	
	function no_search() {
		alert('You must enter some text for this query before you can perform a search.');
		return false;	
		document.getElementById("query").focus();
	}
	function inc_cat(catid) {
		var r = xml_connect();
		if (r)
		{
			r.onreadystatechange=function() { change_results(r, 'show_thisprice'); };
			r.open("GET", "dropdown.php?ajax=yes&cmd=inc_cat&this_catid="+catid, true);
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}		
		
		
	}
	function toggle_searchbutton(){
		//alert('inside toggle_searchbutton');
		var this_query = document.getElementById("query")
		var search_button=document.getElementById('search_button');
		if (this_query && search_button)
		    search_button.innerHTML = "<img src='images/ajax_loader.gif'>";
		/*if (this_query == "") {
			alert('You must enter some texttttt for this query before you can perform a search.');
			exit;
		}
		else {*/
			/*document.getElementById("search_button").innerHTML = '<param name="allowScriptAccess" value="sameDomain" />'+
					'<param name="movie" value="images/searching.swf" />'+
					'<param name="quality" value="high" />'+
					'<param name="bgcolor" value="#fbd87c" />'+
					'<embed src="images/searching.swf" quality="high" bgcolor="#fbd87c" width="120" height="20" name="searching" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
			*/	
				//'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" width="120" height="20" id="searching" align="middle">'+ 
				//'</object>';
		//}
	}
	function toggle_searchsubmit(search_type)
	{
		if (!search_type)
		    search_type='';
		document.getElementById(search_type + 'search_wait_img').style.visibility='visible';
 		document.getElementById(search_type + 'search_img').style.visibility='hidden';
        //IE compatible code - so it displays the animation
        if (navigator && navigator.appVersion.indexOf("MSIE")!=-1)
            setTimeout("document.getElementById('" + search_type + "search_wait_img').src = 'images/ajax_loader_clear.gif';", 100);
		if (search_type!='')
    		document.getElementById(search_type + "query").name='query';
		document.getElementById(search_type + "search_query").focus();
		document.getElementById(search_type + "search_query").submit(); //changed by Josh on 06/28/07
	}

	function hide_imghelp() {
		if (document.getElementById("img_help").style.display == "block") {
			document.getElementById("img_help").style.display = "none";			
			document.getElementById("img_help_f").innerHTML = "<a href='#img_help_a' onclick='hide_imghelp();'>Show Help</a>";
		}
		else {
			document.getElementById("img_help").style.display = "block";			
			document.getElementById("img_help_f").innerHTML = "<a href='#img_help_a' onclick='hide_imghelp();'>Hide Help</a>";
		}
	}
	
	//this is the general search return function, it will work based on the stored values shown below
	function changePage(pnum, object, mfr_id, type_id, cat_id, query, extra, pl)
	{
		//query = changePage(query);
		//document.getElementById('query').focus();
		//document.getElementById('display_ind').innerHTML = "";
		document.getElementById('search_loader').innerHTML = "<img src='images/ajax_loader_clear.gif'>";
		document.getElementById('display_searchres').style.display = 'block';
		//window.location.hash='top';
	    if (!pl)
	        pl = '50';
		var r = xml_connect();	
		if (r)
		{			
			var value=null;
			r.onreadystatechange=function() { change_results(r, 'display_searchres'); };
			r.open("GET", "searchdisplay.php?ajax=yes&q=" + query + "&t="+type_id+"&m=" + mfr_id +"&c="+cat_id+"&pl="+pl+"&ob="+object+"&pn=" + pnum+"&command=searchdisplay"+extra, true);	
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
		}
		else
		    document.getElementById("searchform").submit();				

	}	
	//we will hide the search results if the query is blank and either the mfr_id or type_id is blank
	function check_search_parameters() { 
		var mfr_id = document.getElementById("last_clicked_mfr").value;
		var type_id = document.getElementById("last_clicked_type").value;
		var query = document.getElementById("query_search").value;
		if ((mfr_id == "" | type_id == "") & query == "") hide_all_results();  		
		
	}
	function revise_mfr() {
		var cat_name = document.getElementById("last_clicked_cat").value;
		var mfr_store = cat_name + "_mfr_store";
		var store_mfr = document.getElementById(mfr_store).value;
		
	}
	//load an individual product
				function mouseOver()
				{
					document.b1.src ='images/profileImage.gif';
				}
				function mouseOut()
				{
					document.b1.src ='images/rating/".$ov_img."';
				}			
				
				
				function showtip2(current,e,text){  
					var tooltip2=document.getElementById('tooltip2');
					
				    tooltip2.innerHTML=text;
					tooltip2.style.left=e.clientX+document.body.scrollLeft+60;
					tooltip2.style.top=e.clientY+document.body.scrollTop-150;
					tooltip2.style.visibility='visible';
					/*if (document.all && document.readyState=='complete'){ 
						document.all.tooltip2.innerHTML=text;
						document.all.tooltip2.style.pixelLeft=event.clientX+document.body.scrollLeft+40;
						document.all.tooltip2.style.pixelTop=event.clientY+document.body.scrollTop-150;
						document.all.tooltip2.style.visibility='visible';
					} 
					else if (document.layers){ 
						document.tooltip2.document.nstip.document.write('+text+');
						document.tooltip2.document.nstip.document.close();
						document.tooltip2.document.nstip.left=0;
						currentscroll=setInterval('scrolltip()',100);
						document.tooltip2.left=e.pageX+10;
						document.tooltip2.top=e.pageY+10;
						document.tooltip2.visibility='show';
					}*/ 
				} 
				function hidetip2(){ 
					var tooltip2=document.getElementById('tooltip2')
					tooltip2.style.visibility='hidden';
					/*if (document.all) document.all.tooltip2.style.visibility='hidden';
					else if (document.layers){ 
						clearInterval(currentscroll);
						document.tooltip2.visibility='hidden';
					}*/
				}			
	function store_item(item) {
		document.getElementById("save_item").value = item;	
	}
	function print_ind(item_id) {
		window.open ("print_item.php?item_id="+item_id+"&ajax=yes","mywindow","resizable=1,status=1,scrollbars=1"); //,width=350,height=250
	}
	function print_recents(uid) {
		var order_by = document.getElementById("stored_recent_orderby").value;
		var order_dir = document.getElementById("stored_recent_orderdir").value;
		window.open ("print_recents.php?uid="+uid+"&ajax=yes&orderby="+order_by+"&order_dir="+order_dir,"mywindow","resizable=1,status=1,scrollbars=1"); //,width=350,height=250
	}	
	function load_ind(item, divname){
		if (divname == "display_ind") document.getElementById("display_ind").innerHTML = "<img src='images/ajax_loader.gif'>";
		if (divname == "display_checkout") var hide_x = "y";
		else var hide_x = "n";
		var r = xml_connect();
		if (r)
		{
			r.onreadystatechange=function() { change_results(r, divname); };
			r.open("GET", "lookupbox.php?ajax=yes&id="+item+"&cmd=show_ind&hide_x="+hide_x, true);
			r.setRequestHeader("Content-Type", "application/xml");
			r.setRequestHeader("Cache-Control", "no-cache"); 
			r.send(null);
			
		}
		else {
			alert('not added');
			//document.getElementById("searchform").submit();
		}
		document.getElementById("display_ind").style.display = "block";
	}			
	//hide the individual product
	function hide_hidden() {

		if (document.getElementById("hide_ind").value == "no") {
			document.getElementById("hide_ind").value = "yes";
			
			document.getElementById("show_indx").style.display = "block";
			document.getElementById("display_ind").style.display = "none";
		}	
		else {
			document.getElementById("hide_ind").value = "no";
			document.getElementById("show_indx").style.display = "none";
			document.getElementById("display_ind").style.display = "block";
		}
	}

	function letter_mfr(typeid, catname) {
		//if (window.event.keyCode == "40" && document.getElementById("load_mfr")) {
		//	alert('1');
		//	document.getElementById("load_mfr").focus();
		//}
		//else {
			alert('2');
			var r = xml_connect();	
			var mfrsearch = catname + "_mfr_search";
			var mfr_div = "manufacturer_" + catname;
			var mfr_html = document.getElementById(mfr_div).innerHTML;
			var mfr_let = document.getElementById(mfrsearch).value;
	
			
			if (mfr_let.length > 0 | typeid == "S") {
				var send_to_ajax = 0;
					
				/*if(document.getElementById("search_firstlet")) {
					
					var mfr_first = mfr_let.substring(0, 1);
					//alert('mfr_first: ' + mfr_first +"..search_firstlet: " + document.getElementById("search_firstlet").value);
					mfr_first = mfr_first.toLowerCase();
					if (mfr_first == document.getElementById("search_firstlet").value) {
						send_to_ajax = 1;
					}
					else {
						document.getElementById("mfr_shortlist").value = "";
						document.getElementById("mfr_stored").value = "";
					}
				}*/				
				document.getElementById(mfr_div).innerHTML = "<img src='images/ajax_loader.gif'>";
				/*if ((mfr_let.length == 1 | document.getElementById("mfr_shortlist").value == "" | typeid == "S") & send_to_ajax == 0) {
					var mfr_div = "manufacturer_" + catname;
					var mfr_html = document.getElementById(mfr_div).innerHTML;
					mfr_html = document.getElementById(mfr_div).innerHTML;
					var query = document.getElementById("query").value;
					
					if (typeid != "") var send_ins = "sender=ind&";
					else var send_ins = "";
							
					//var stored_type = document.getElementById("this_stored_type").value;
					
					mfr_let = filter_urlstr(mfr_let);
					query = filter_urlstr(query);
					var m = xml_connect();	
					if (m)
					{			
						var value=null;
						m.onreadystatechange=function() { change_results(m, mfr_div); };
						m.open("GET", "dropdown.php?"+send_ins+"search=mfr&query_ajax="+query+"&cmd=mfr_letter_search&ajax=yes&typeid="+typeid+"&catname="+catname+"&search_letter="+mfr_let, true);	
						m.setRequestHeader("Content-Type", "application/xml");
						m.setRequestHeader("Cache-Control", "no-cache"); 
						m.send(null);
					}
					else  alert('not added');	
			    }
			    else {*/
				    //alert('going to letter_mfr_ajax');
				    letter_mfr_ajax(typeid, catname);
			    //}
		    }	  
    	//}
	}
	function change_mfr(mfrid, catname, query) {
		document.getElementById("typeid_mfr").value = "";
		document.getElementById("mfrid_mfr").value = mfrid;
		document.getElementById("query_browse").value = query;
		document.getElementById("catname_mfr").value = catname;
		document.getElementById("selected_mfr").submit();
	}
	function change_type(typeid, catname, mfrid) {
		document.getElementById("typeid_mfr").value = typeid;
		document.getElementById("mfrid_mfr").value = mfrid;
		document.getElementById("catname_mfr").value = catname;
		document.getElementById("selected_mfr").submit();
	}
	function letter_mfr_ajax(typeid, catname) {
		var mfr_div = "manufacturer_" + catname;
		var mfr_html = document.getElementById(mfr_div).innerHTML;
		document.getElementById("mfr_ajax_loader").style.display = "block";
		document.getElementById(mfr_div).innerHTML = "";
		var mfrsearch = catname + "_mfr_search";
		var mfr_let = document.getElementById(mfrsearch).value;
		
		var m_slist = document.getElementById("mfr_shortlist").value;
		//alert(document.getElementById("mfr_stored").value);
		//alert(document.getElementById("mfr_shortlist").value);
		if (mfr_let.length > 0) {
			//alert('1m_slist: ' + m_slist);
			//alert('heeey');
			//var kc = event.keyCode;
			//alert(kc);
			if (m_slist == ''){ //event.keyCode == '8' || event.keyCode == '46' || 
				//alert('first');
				var mfr_stored = document.getElementById("mfr_stored").value;
			}
			else {
				//alert('2nd');
				var mfr_stored = document.getElementById("mfr_shortlist").value;
			}
			//var mfr_stored = document.getElementById("mfr_stored").value;
			var mfr_stored = document.getElementById("mfr_shortlist").value;
			mfr_html = document.getElementById(mfr_div).innerHTML;
			var query = document.getElementById("query").value;
			//alert(mfr_stored);
			var mfr_arr = new Array();
			mfr_arr = explodeArray(mfr_stored,"|");
			var i;
			mfr_let = filter_urlstr(mfr_let);
			query = filter_urlstr(query);
			var mfr_arrcnt = mfr_arr.length - 1;
			var chk_result = 0;
			document.getElementById(mfr_div).innerHTML = "";
			if (mfr_arrcnt < 20) var mult_size = mfr_arrcnt;
			else var mult_size = 20;
			
			//alert(mult_size);			
			var get_query = document.getElementById("query").value;
			//alert(get_query);
			var new_html = "<select multiple id='load_mfr' size='"+mult_size+"' class='input' onchange='change_mfr(this.value, \""+catname+"\", \""+get_query+"\");'>";
			for (i = 0; i < mfr_arrcnt; i++) {
				
				var mfr_el = new Array();
				mfr_el = explodeArray(mfr_arr[i], "~");
				var mfr_stid = mfr_el[0];
				var mfr_stname = mfr_el[1];
				var cmp_len = mfr_let.length;
				var mfr_small = mfr_stname.substring(0,cmp_len);
				mfr_small = mfr_small.toLowerCase();
				mfr_letlower = mfr_let.toLowerCase();
				if (mfr_letlower == mfr_small) {
					chk_result = 1;
					//will need to make the url below dynamic, ssl or not
					//new_html += "\n<a href='dropdown.php?catname="+catname+"&sender=ind&mfrid="+mfr_stid+"&typeid=&query="+query+"&increment=mfr' class='fText1' onclick='toggle_searchbutton();'>"+ mfr_stname + "</a><br>";
					new_html += "\n<option value='"+mfr_stid+"'>"+ mfr_stname + "</option>";
					//document.getElementById(mfr_div).innerHTML += mfr_stname + "<br>";
					
				}
				//document.getElementById("mfr_shortlist").value += mfr_arr[i] + "|";
			}		
			new_html += "</select>";
			document.getElementById(mfr_div).innerHTML = new_html;
			//alert(mfr_let);
			if (chk_result == 0 & m_slist.length > 0) document.getElementById(mfr_div).innerHTML = "<span class='errorred'>No results found. Please delete some letters and try again.</span>";
			//var t = setTimeout("no_mfr_found('"+mfr_div+"')", 1000);
			document.getElementById("mfr_ajax_loader").style.display = "none";
		}
	}
	function hide_mfrsearch(catname) {
		var mfr_searchhide = catname + "_mfr_search";
		if (document.getElementById(mfr_searchhide)) {
			document.getElementById(mfr_searchhide).disabled = true;
			document.getElementById(mfr_searchhide).style.backgroundColor = '#cccccc';		
		}
	}
	function toggle_mfrsearch() {
		cat_name = document.getElementById("last_clicked_cat").value;
		mfr_id = document.getElementById("last_clicked_mfr").value;
		var mfr_searchhide = cat_name + "_mfr_search";
		if (mfr_id != "") {
			document.getElementById(mfr_searchhide).disabled = true;
			document.getElementById(mfr_searchhide).style.backgroundColor = '#cccccc';			
		}
		else {
			document.getElementById(mfr_searchhide).disabled = false;
			document.getElementById(mfr_searchhide).style.backgroundColor = '#ffffff';	
		}
		
	}
		
	function letter_type(mfrid, catname) {
		//var hide_result = catname + "_type_top10";
		//document.getElementById(hide_result).style.display = "none";
		
		var r = xml_connect();	
		var typesearch = catname + "_type_search";
		var type_div = catname + "_type";
		var type_html = document.getElementById(type_div).innerHTML;
		document.getElementById(type_div).innerHTML = "<img src='images/ajax_loader.gif'>";
		type_html = document.getElementById(type_div).innerHTML;
		var query = document.getElementById("query").value;
		
		if (mfrid != "") var send_ins = "sender=ind&";
		else var send_ins = "";
		var type_let = document.getElementById(typesearch).value;
		type_let = filter_urlstr(type_let);
		query = filter_urlstr(query);
		var m = xml_connect();	
		if (m)
		{			
			var value=null;
			m.onreadystatechange=function() { change_results(m, type_div); };
			m.open("GET", "dropdown.php?"+send_ins+"search=type&query_ajax="+query+"&cmd=type_letter_search&ajax=yes&mfrid="+mfrid+"&catname="+catname+"&search_letter="+type_let, true);	
			m.setRequestHeader("Content-Type", "application/xml");
			m.setRequestHeader("Cache-Control", "no-cache"); 
			m.send(null);
		}
		else
		    alert('not added');		  
	}
	function hide_typesearch(catname) {
		var type_searchhide = catname + "_type_search";
		if (document.getElementById(type_searchhide)) {
			document.getElementById(type_searchhide).disabled = true;
			document.getElementById(type_searchhide).style.backgroundColor = '#cccccc';		
		}
	}
	function toggle_typesearch() {
		cat_name = document.getElementById("last_clicked_cat").value;
		type_id = document.getElementById("last_clicked_type").value;
		var type_searchhide = cat_name + "_type_search";
		if (type_id != "") {
			document.getElementById(type_searchhide).disabled = true;
			document.getElementById(type_searchhide).style.backgroundColor = '#cccccc';			
		}
		else {
			document.getElementById(type_searchhide).disabled = false;
			document.getElementById(type_searchhide).style.backgroundColor = '#ffffff';	
		}
		
	}
	function hide_ccnum() {
		if (document.getElementById("buy_dir_ccnum").disabled == true)		{
			document.getElementById("buy_dir_ccnum").disabled = false;
			document.getElementById("buy_dir_ccnum").value = "";
			document.getElementById("buy_dir_expmo").style.display = 'block';
			document.getElementById("buy_dir_expyr").style.display = 'block';
			document.getElementById("buy_dir_cvv").style.display = 'block';
		}
		else {
			document.getElementById("buy_dir_ccnum").disabled = true;
			document.getElementById("buy_dir_expmo").style.display = 'none';
			document.getElementById("buy_dir_expyr").style.display = 'none';
			document.getElementById("buy_dir_cvv").style.display = 'none';
			var m = xml_connect();	
			if (m)
			{			
				var value=null;
				m.onreadystatechange=function() { change_results(m, "buy_dir_ccnum"); };
				m.open("GET", "checkout.php?ajax=yes&cmd=show_cclast4", true);	
				//alert('checkout.php?ajax=yes&cmd=show_cclast4');
				m.setRequestHeader("Content-Type", "application/xml");
				m.setRequestHeader("Cache-Control", "no-cache"); 
				m.send(null);
			}
			else
			    alert('not added');			
		}
	}

	//this function will update an individual search, either the type or manufacturer, in the left nav
	
	//this updates the search results for type or manufacturer based on the other  
	
	//this updates the results in the main content area
	//connects to search_display.php OR lookup.php
	function change_results(r, divname)	{
		try
		{
			//alert('readystate: ' + r.readyState);
			if (r.readyState==4)
				if (r.status==200)
				{
	    			//Skip this ajax html crap for saving account info
	    			if (divname=="myaccount_refresh")
	    			{
    	    			window.location.assign(this_url + "myaccount.php?cmd=display");
    	    			return;
	    			}
	    			//Go straight to images page
	    			if (divname=="display_myaccount_images")
	    			    var i=document.getElementById("display_myaccount");
	    			else
    					var i=document.getElementById(divname);					
	    			var this_html = r.responseText;
	    			i.style.display="block";
	    			if (divname == "display_signup") {

		    			captcha_arr = explodeArray(this_html,"|~~~~~|");
		    			var captcha_cnt = captcha_arr.length;
		    			if (captcha_cnt > 1){
			    			var myemail = captcha_arr[0];
							var signup_html = captcha_arr[1].replace("~~~~~|","");
							i.innerHTML=signup_html;				    			
							var domain_arr = new Array();
							domain_arr = explodeArray(myemail,"@");
			
							var myurl = new Array('yahoo.com', 'msn.net', 'msn.com', 'hotmail.com', 'go.com', 'gmail.com');
							var j;
							var domainname;
							var cnt = myurl.length;
							for (j = 0; j < cnt; j++) {
								//alert('domain_arr: ' + domain_arr[1] + ' myurl: ' + myurl[j]);
								if (domain_arr[1] == myurl[j]) {
									if (domain_arr[1] == "yahoo.com") domainname = "mail.yahoo.com";
									else if (domain_arr[1] == "msn.com" | domain_arr[1] == "msn.net" | domain_arr[1] == "hotmail.com") domainname = "hotmail.com";
									else if (domain_arr[1] == "gmail.com") domainname = "gmail.com";
									else if (domain_arr[1] == "go.com") domainname = "mail.go.com";
									var show_domain = "http://" + domainname;
									//here we will add the logic to open a popup directly to the mail domain
									window.open (show_domain,"mywindow","location=1,status=1,scrollbars=1,resizable=1,width=500,height=400"); 
									mywindow.moveTo(0,0);					
								}
							}	
							
		    			}
		    			else {
			    			i.innerHTML=r.responseText;	
		    			}
	    			}
	    			else if (divname == "buy_dir_ccnum") {
		    			i.value=r.responseText;
		    			
	    			}
	    			/*else if (divname == "display_myaccount") {
		    			
		    			alert(this_html);
		    			
	    			}*/
	    			else if (divname == "post_commenttext_item") {
		    			i.value=r.responseText;
	    			}
	    			else if (divname == "login_message") {

	    				if(document.getElementById("nonvalid_email")) {
			    			if (r.responseText != "E-mail not found.") {
			    				alert('Your validation code has been sent to the e-mail address that you entered. Please allow up to 30 minutes for email to be received.');
		    				}		    				
			    			if (document.getElementById("login_message1")) document.getElementById("login_message1").innerHTML = 	"Validation sent";
			    			document.getElementById("login_message").innerHTML = "Validation sent";
	    				}
	    				else {
			    			if (r.responseText != "E-mail not found.") {
			    				alert('Your password has been sent to the e-mail address that you entered. Please allow up to 30 minutes for email to be received.');
		    				}		    				
			    			if (document.getElementById("login_message1")) document.getElementById("login_message1").innerHTML = 	r.responseText;
			    			document.getElementById("login_message").innerHTML = 	r.responseText;
		    			}
	    			}
	    			else if (divname.substring(0, 12) == "manufacturer") {
		    			alert('heyyy\n' + this_html);
						var mfr_arr = new Array();
						mfr_arr = explodeArray(this_html,"|");
						var i;
						var mfr_arrcnt = mfr_arr.length;
						var catname = divname.replace(/manufacturer_/, "");
						//var catname = catname_arr[0];
						//alert(divname +".."+catname);
						//divname.innerHTML = "";
						var mfrsearch = catname + "_mfr_search";
						var mfr_let = document.getElementById(mfrsearch).value;						
						//var old_html = document.getElementById(divname).innerHTML;
						//alert(old_html);
						if (mfr_arrcnt < 20) var mult_size = mfr_arrcnt;
						else var mult_size = 20;
						var get_query = document.getElementById("query").value;
						alert(get_query);
						//alert(mult_size);
						var html_rows = "<select multiple id='load_mfr' size='"+mult_size+"' class='input' onchange='change_mfr(this.value, \""+catname+"\", \""+get_query+"\");'>";
						//document.getElementById(divname).innerHTML = this_html;
						//alert('mfr search div almost there ' + divname);	
						document.getElementById("mfr_shortlist").value = "";
						if (mfr_arrcnt > 0) {
							for (i = 0; i < mfr_arrcnt; i++) {
								if (trim(mfr_arr[0]) != "") {
									var mfr_el = new Array();
									mfr_el = explodeArray(mfr_arr[i], "~");
									var mfr_stid = mfr_el[0];
									var mfr_stname = mfr_el[1];
									//will need to make the url below dynamic, ssl or not
									//divname.innerHTML += "\n<a href='dropdown.php?catname="+catname+"&sender=ind&mfrid="+mfr_stid+"&typeid=&query="+query+"&increment=mfr' class='fText1' onclick='toggle_searchbutton();'>"+ mfr_stname + "</a><br>";
									var cmp_len = mfr_let.length;
									var mfr_small = mfr_stname.substring(0,cmp_len);
									mfr_small = mfr_small.toLowerCase();
									mfr_letlower = mfr_let.toLowerCase();
									if (mfr_letlower == mfr_small) {								
										//html_rows += "\n<a href='dropdown.php?catname="+catname+"&sender=ind&mfrid="+mfr_stid+"&typeid=&query=&increment=mfr' class='fText1' onclick='toggle_searchbutton();'>"+ mfr_stname + "</a><br>";
										html_rows += "\n<option value='"+mfr_stid+"'>"+ mfr_stname + "</option>";
									}
									//document.getElementById(mfr_div).innerHTML += mfr_stname + "<br>";
									document.getElementById("mfr_shortlist").value += mfr_arr[i] + "|";
								}
							}	
							html_rows += "</select>";	
						}
						else {
							html_rows = "";
						}
						//html_rows += this_html;
						//alert(document.getElementById("mfr_shortlist").value);
						if (trim(mfr_arr[0]) == ""	& i <= 1) {
							html_rows = "";	
						}
						else {
						}
						if (mfr_let) {
							var this_mfrsmall = mfr_let.toLowerCase();
							this_mfrsmall = this_mfrsmall.substring(0, 1);
							//alert('mfr_small ' + this_mfrsmall);
							//alert('assigning first letter');
							document.getElementById("search_firstlet").value = this_mfrsmall;
						}
						document.getElementById(divname).innerHTML = html_rows; 
						//document.getElementById(divname).innerHTML += this_html; 
						
						//if (document.getElementById("mfr_shortlist").value == "") {
						if (mfr_arrcnt == 0 | trim(html_rows) == "") {
							var mfr_div = "manufacturer_" + catname;
							document.getElementById(mfr_div).innerHTML = "<span class='errorred'>No results found. Please delete some letters and try again.</span>";
						}						
	    			}
	    			else {	    
		    			var thsinner = i.innerHTML;
		    			//var resp = 	r.responseText;
		    			//alert(thsinner + "---" + this_html);	
		    			//document.getElementById("audio_manufacturer").innerHTML = divname + "..audio_manufacturer";
		    			i.innerHTML = this_html;
		    			//alert(divname);
						//thsinner="";
		    			if (divname == "show_login") {
			    			document.loginform.submit();	
			    			
		    			}
		    			if (divname == "display_searchres") {
			    			check_search_parameters();
			    			document.getElementById("search_loader").innerHTML = "";
		    			}
		    			//if (divname == "display_ind") document.getElementById("hidden_ind").style.display = "block";
		    			if (divname == "contact_list") {
			    			
		    			}
						
		    			if (divname == "add_remove" || divname == "add_remove_right") {
			    			
			    			repop_rightdir();
		    			}
		    			if (divname == "add_remove_msg") {
			    			
			    			repop_msgblock();
		    			}
		    			if (divname == "display_directory" || divname == "display_dir_search") {
			    			repop_rightdir();
		    			}

		    			if (divname=="display_myaccount_images")
		    			    setActiveProfilePage(3);
					}
			    }
			else {
					return;
					var i=document.getElementById(divname);					
	    			var this_html = r.responseText;
	    			i.style.display="block";
	    			i.innerHTML=r.responseText;				
			}
		}
		catch (e) {	}
	}
	
	
	
	
	
	//Displays a popup 'dropdown' style box for a textbox
	function dropdownShow(boxname)
	{
    	var dropdownBox=document.getElementById(boxname+"_search");
    	var dropdownDiv=document.getElementById(boxname+"_dropdown");
   	    var dropdownSel=dropdownDiv.getElementsByTagName("select")[0];
    	
   	    if (dropdownDiv)
      	{
           	dropdownDiv.style.left=calculateOffset("offsetLeft", dropdownBox)+"px";
            dropdownDiv.style.top=calculateOffset("offsetTop", dropdownBox)+(dropdownBox.offsetHeight - 1)+"px";
           	dropdownDiv.style.zIndex="1";
            if (dropdownSel.offsetWidth<dropdownBox.offsetWidth)
            {
                dropdownDiv.style.width=dropdownBox.offsetWidth;
                dropdownSel.style.width=dropdownDiv.style.width;
            }
            dropdownDiv.style.visibility="visible";
    	}
	}
	
	//Handles changed text and fetches new search results for the 'dropdown' box
	//ddState is defined globally with the corresponding dropdown boxes
	function dropdownTyping(boxname, e, query, mfrid, typeid, categoryID)
	{
    	var dropdownBox=document.getElementById(boxname+"_search");
    	var dropdownDiv=document.getElementById(boxname+"_dropdown");
    	var dropdownSel=dropdownDiv.getElementsByTagName("select")[0];
    	
    	if (e.type=="focus")
    	    dropdownBox.select();
    	
    	var showall=(ddState[boxname+'count']>0 && ddState[boxname+'count']<26);
    	if ((dropdownBox.value && ddState[boxname+"letter"]!=dropdownBox.value.substr(0, 1).toLowerCase() && !showall) || (showall && (ddState[boxname+'loaded']==0 || ddState[boxname+"letter"]!='')))
    	{
        	clearTimeout(ddState.reqtimer);
        	ddState[boxname+"loaded"]=1;
        	dropdownDiv.innerHTML="<select class='input' style='' onKeyDown=\"if (event.keyCode==13) return keyHandler('"+boxname+"', event);\" onMouseOver='ddState.hover=1' onMouseOut='ddState.hover=0' onBlur=\"document.getElementById('"+boxname+"_dropdown').style.visibility='hidden';\" size=10><option value=-1 style=\"font-style: italic; font-weight: bold; color: #777777;\">Searching...</option></select>";
       	    dropdownShow(boxname);
        	if (ddState[boxname+'count'] && ddState[boxname+'count']<26)
        	    ddState.reqtimer=setTimeout("AJAXRequest('mfrtypelist.php?firstletter=&query="+query+"&mfrID="+mfrid+"&typeID="+typeid+"&catID="+categoryID+"', loadBox, '"+boxname+"')", ddState.timerlen);
        	else
        	    ddState.reqtimer=setTimeout("AJAXRequest('mfrtypelist.php?firstletter="+dropdownBox.value.substr(0, 1)+"&query="+query+"&mfrID="+mfrid+"&typeID="+typeid+"&catID="+categoryID+"', loadBox, '"+boxname+"')", ddState.timerlen);
        	ddState.timerlen=700;
       	}
       	else if (ddState[boxname+"loaded"]==2)
       	{
        	if (!dropdownBox.value && !showall)
                dropdownDiv.style.visibility='hidden';
            else if (!(e.keyCode==13 || e.keyCode==38 || e.keyCode==40))
            {
                dropdownShow(boxname);
                dropdownSelect(boxname);
            }
       	}
	}
	
	//Highlights the selection closest to what's in the text box(but doesn't select if a letter doesn't match)
	function dropdownSelect(boxname)
	{
    	var dropdownBox=document.getElementById(boxname+"_search");
    	var dropdownDiv=document.getElementById(boxname+"_dropdown");
    	
    	var divSelect=dropdownDiv.getElementsByTagName("select")[0]
    	var divOptions=divSelect.options;
    	if (dropdownBox.value)
    	{
        	var currMatch=0, lastMatch=0, currLen=1, currSearch='';
        	var searchStr=dropdownBox.value.toLowerCase(), selectVal=-1;
    	    for (i=0;i<divOptions.length && selectVal==-1;i++)
    	    {
        	    currSearch=divOptions[i].innerHTML.toLowerCase();
        	    currLen=1;
        	    while(currLen<=searchStr.length && currSearch.substr(0, currLen)==searchStr.substr(0, currLen))
        	    {
            	    currMatch++;
            	    currLen++;
        	    }
        	    if (currLen-1==searchStr.length)
            	    selectVal=i;
        	    else if (lastMatch>currMatch)
            	    selectVal=-1;//i-1;
        	    else
        	        lastMatch=currMatch;
        	}
        	divSelect.selectedIndex=selectVal;
    	}
    	else
    	{
    	    divSelect.selectedIndex=-1;
	    }
	}
	

	//Handles leaving the boxes, automatically selects highlighted item
	function leaveHandler(boxname)
	{
    	var dropdownBox=document.getElementById(boxname+"_search");
    	var dropdownSel=document.getElementById(boxname+"_dropdown").getElementsByTagName("select")[0];
   		if (dropdownSel.selectedIndex==-1 || dropdownSel.options[dropdownSel.selectedIndex].value==-1 || ddState.changed==0)
   		{
       		dropdownBox.value=ddState[boxname+'prev'];
   		    return false;
        }
   		document.getElementById(boxname+"id").value=dropdownSel.options[dropdownSel.selectedIndex].value
   		increment=document.createElement("input");
   		increment.name="increment";
   		increment.type="hidden";
   		increment.value=boxname;
   		document.getElementById("search_query").appendChild(increment);
   		document.getElementById("search_query").submit();
	}
	
	//Handles keypresses other than text input
	function keyHandler(boxname, e)
	{
    	var dropdownBox=document.getElementById(boxname+"_search");
    	var dropdownSel=document.getElementById(boxname+"_dropdown").getElementsByTagName("select")[0];
    	if (e.keyCode==13 || e.keyCode==9)
    	{
    		if (dropdownSel.selectedIndex==-1)
    		{
	       		dropdownBox.value=ddState[boxname+'prev'];
                document.getElementById(boxname+'_dropdown').style.visibility='hidden';
    		    return false;
		    }
    		document.getElementById(boxname+"id").value=dropdownSel.options[dropdownSel.selectedIndex].value
    		increment=document.createElement("input");
    		increment.name="increment";
    		increment.type="hidden";
    		increment.value=boxname;
    		document.getElementById("search_query").appendChild(increment);
    		document.getElementById("search_query").submit();
    	    return false;
	    }
    	ddState.changed=1;
    	if (e.keyCode==38)
    	{
    	    if (dropdownSel.selectedIndex>0)
    	        dropdownSel.selectedIndex--;
    	    return false;
        }
    	else if (e.keyCode==40)
    	{
    	    if (dropdownSel.selectedIndex<dropdownSel.options.length - 1)
    	        dropdownSel.selectedIndex++;    	     
    	    return false;
        }
	}
	
	//Handles mouse input, specifically clicking an item to select it
	function mouseHandler(boxname, e)
	{
       	if (e.target)
      	{
    		if (e.target.value==-1)
    		    return false;
       	    document.getElementById(boxname+"id").value=e.target.value;
   	    }
       	else 
       	{
    		if (e.srcElement.value==-1)
    		    return false;
       	    document.getElementById(boxname+"id").value=e.srcElement.value;
   	    }
   		increment=document.createElement("input");
   		increment.name="increment";
   		increment.type="hidden";
   		increment.value=boxname;
   		document.getElementById("search_query").appendChild(increment);
  		document.getElementById("search_query").submit();
	}
	
	//Loads the list of items into specificed box
	//ddState is defined globally with the corresponding dropdown boxes
	function loadBox(list, boxname)
	{
        var dropdownBox=document.getElementById(boxname+"_search");
        var dropdownDiv=document.getElementById(boxname+"_dropdown");

        ddState.timerlen=0;
        ddState[boxname+"loaded"]=2;
        if (dropdownBox.value && ddState[boxname+'count']>25)
            ddState[boxname+'letter']=dropdownBox.value.substr(0, 1).toLowerCase();
        else
            ddState[boxname+'letter']='';
        
        htmllist=list.replace(/\/\//g, "<option value=");
        htmllist=htmllist.replace(/\\\\/g, "</option>");
        htmllist="<select class='input' style='' onClick=\"mouseHandler('"+boxname+"', event);\" onKeyDown=\"if (event.keyCode==13) keyHandler('"+boxname+"', event);\" onMouseOver='ddState.hover=1' onMouseOut='ddState.hover=0' onBlur=\"document.getElementById('"+boxname+"_dropdown').style.visibility='hidden';\" size=10>"+htmllist+"</select>";
        dropdownDiv.innerHTML=htmllist;
        if (dropdownDiv.style.visibility!='hidden')
        {
            dropdownShow(boxname);
            dropdownSelect(boxname);
        }
	}
	
	//Calculates the offset of the object
	function calculateOffset(offsetName, object)
	{
        var offset=0;
        while(object)
        {
            offset+=object[offsetName];
            object=object.offsetParent;
        }
        return offset;
	} 
	
	//Calculates the width of the object
	function calculateWidth(object)
	{
    	if(navigator && navigator.userAgent.toLowerCase().indexOf("msie")==-1)
    	{
        	return object.offsetWidth; //(minus border..)
        } else {
            return object.offsetWidth;
        }
    }
    
    //Function to send an AJAX request
    function AJAXRequest(requeststr, funct, boxname, parameters)
    {
        var httpRequest;

        if (window.XMLHttpRequest) // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
        else if (window.ActiveXObject) // IE
        {
            try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } 
            catch (e)
            {
                try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } 
                catch (e) {}
            }
        }

        if (httpRequest)
		{	
			httpRequest.onreadystatechange=function()
			{
    			if (httpRequest.readyState==4 && httpRequest.status==200)
    			    if (funct)
    			        funct(httpRequest.responseText, boxname);
		    }
	
			if (parameters) //Parameters were sent, this is a POST request
			{
                httpRequest.open('POST', requeststr, true);
			    httpRequest.setRequestHeader("Cache-Control", "no-cache"); 
                httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                httpRequest.setRequestHeader("Content-length", parameters.length);
                httpRequest.setRequestHeader("Connection", "close");
                httpRequest.send(parameters);
			}
			else
			{
    			httpRequest.open("GET", requeststr, true);
			    httpRequest.setRequestHeader("Cache-Control", "no-cache"); 
			    httpRequest.send(null);
		    }
		}		
		else 
		    alert ('Failed to load XMLHttpRequest object.');
    }
    
    //Validates that the user agrees to the API TOS
    function validateAPIRequest()
    {
        apidiv=document.getElementById('api_accept_div');
        apichk=document.getElementById('api_accept_tou');
        if (!(apichk.checked))
        {
            alert("You must agree to the terms of use before receiving your User API Code.");
            apidiv.style.border='1px solid red';
            return false;
        }
        return true;
    }
    
    //Handles display of images in item image gallery, and switching between them
    function viewImage(num)
    {
        var currImg=document.getElementById('img'+num);
        var fullImg=document.getElementById('fullimg');
        var flagUrl=document.getElementById('flagurl');
        var currImgVal=document.getElementById('currimgval');
        if (currImg)
        {
            currImg.style.border='3px solid #FAC745';
            if (fullImg)
                fullImg.src=currImg.src.replace("_tn.", "_real.");
            if (flagUrl) //Change the 'flag image' id
            {
                flagUrl.href=flagUrl.href.substring(0, flagUrl.href.indexOf('report_id') + 10);
                flagUrl.href=flagUrl.href + currImg.name;
            }
            if (currImgVal) //Change the 'approve/deny' id
                currImgVal.value=currImg.name;
        }
        var newnum=-1;
        do
        {
            newnum=newnum+1;
            currImg=document.getElementById('img'+newnum);
            if (currImg && newnum!=num)
                currImg.style.border='3px solid white';
        } while(currImg);
    }

    function submit_imageGallery()
    {
        document.getElementById('agreetext').style.border='';
        document.getElementById('fname').style.border='';
        if (document.getElementById('imagetos').checked==false)
        {
            document.getElementById('agreetext').style.border='1px solid red';
            alert('You must agree to the terms of service before uploading an item image.');
        }
        else if (document.getElementById('fname').value.length<1)
        {
            document.getElementById('fname').style.border='1px solid red';
            alert('You must select a file to upload.');
        }
        else
        {
		    document.getElementById('upload_wait_img').style.visibility='visible';
 		    document.getElementById('upload_img').style.visibility='hidden';
            //IE compatible code - so it displays the animation
            if (navigator && navigator.appVersion.indexOf("MSIE")!=-1)
                setTimeout("document.getElementById('upload_wait_img').src = 'images/ajax_loader_clear.gif';", 100);
            try
            {
                document.getElementById('image_gallery_upload').submit();
            }
            catch(e)
            {
                alert("Please use the browse button to select a valid file.");
      		    document.getElementById('upload_wait_img').style.visibility='hidden';
     		    document.getElementById('upload_img').style.visibility='visible';
            }
        }
    }
    
    function submit_imageReport()
    {
        document.getElementById('flag_type').style.border='';
        document.getElementById('flag_description').style.border='';
        if (document.getElementById('flag_type').selectedIndex==0)
        {
            document.getElementById('flag_type').style.border='1px solid red';
            alert('Please choose a reason for reporting this image.');
        }
        else if (document.getElementById('flag_description').value.length<1)
        {
            document.getElementById('flag_description').style.border='1px solid red';
            alert('Please provide a description of the problem with this image.');
        }
        else
            document.getElementById('report_img').submit();
    }
    
    function submit_screenUserImage(approve)
    {
        var doSubmit=true;
        if (!approve)
        {
            doSubmit=confirm("Denying this image will delete it permanently from the server!\n\nDo you want to continue?");
            document.getElementById('image_action').value='deny';
        }
        else
            document.getElementById('image_action').value='approve';
            
        if (doSubmit)
            document.getElementById('approve_img').submit();
    }
    
    //Used to get the absolute position of an element
    function getElementPos(objname)
    {
	    obj=document.getElementById(objname);
	    var curleft = curtop = 0;
	    if (obj)
	    {
		    do
		    {
			    curleft += obj.offsetLeft;
    			curtop += obj.offsetTop;
	    	} while (obj = obj.offsetParent);
	    }
	    return [curleft,curtop];
    }
    
    function submit_profileGallery()
    {
        document.getElementById('fname').style.border='';
        if (document.getElementById('fname').value.length<1)
        {
            document.getElementById('fname').style.border='1px solid red';
            alert('You must select a file to upload.');
        }
        else
        {
		    document.getElementById('upload_wait_img').style.visibility='visible';
 		    document.getElementById('upload_img').style.visibility='hidden';
            //IE compatible code - so it displays the animation
            if (navigator && navigator.appVersion.indexOf("MSIE")!=-1)
                setTimeout("document.getElementById('upload_wait_img').src = 'images/ajax_loader_clear.gif';", 100);
            try
            {
                document.getElementById('profile_gallery_upload').submit();
            }
            catch(e)
            {
                alert("Please use the browse button to select a valid file.");
      		    document.getElementById('upload_wait_img').style.visibility='hidden';
     		    document.getElementById('upload_img').style.visibility='visible';
            }
        }
    }
    
	function textCounterDiv(field, cntfield, maxlimit)
	{
		if (field.value.length > maxlimit) // if too long...trim it!
			field.value = field.value.substring(0, maxlimit);
		else if (cntfield)// otherwise, update 'characters left' counter
			cntfield.innerHTML = maxlimit - field.value.length;
	}

	function numericValidate(e)
    {
        if(e.which!=undefined)
	        key=e.which;
        else if (e.keyCode!=undefined)
	        key=e.keyCode;
        numcheck = /[!-\/:-~ ]/;
        return !numcheck.test(String.fromCharCode(key));
    }
    
    function addProfileCategory()
    {
        cat_dropdown=document.getElementById('dir_add_category');
        if (cat_dropdown && cat_dropdown.selectedIndex!=undefined)
        {
            var nextdiv=0;
            for (var i=0;i<4;i++)
                if (document.getElementById("cattitlediv" + i))
                    nextdiv++;
                else
                    break;

            if (nextdiv<3)
            {
                button=document.getElementById('dir_add_category_btn');
                button.disabled=true;
                button.value='Loading..';
                AJAXRequest('myaccount.php?cmd=load_mfrtype&catID=' + cat_dropdown.options[cat_dropdown.selectedIndex].value, loadProfileMfrType, nextdiv);
            }
        }
    }
    
    function loadProfileMfrType(response, divnum)
    {
        var divcontainer=document.getElementById('category_main');
        
        var divhtml=document.getElementById('category_div_default').innerHTML;

        button=document.getElementById('dir_add_category_btn');
        button.disabled=false;
        button.value='Add';
        
        var addbox=document.getElementById('dir_add_category');
        addbox.remove(addbox.selectedIndex);

        if (divcontainer && divhtml)
        {
            catid=response.substr(0, response.indexOf("//"));
            response=response.substring(response.indexOf("//") + 2);
            catname=response.substr(0, response.indexOf("//"));
        	response=response.replace(/\/\//g, "<option value=");
        	response=response.replace(/\\\\/g, "</option>");
            //Parse mfrs from response, and prepare as html
            mfrs=response.substring(response.indexOf("<"));
        	mfrs=mfrs.substring(0, mfrs.indexOf("__next__"));
        	//Parse types from response, and prepare as html
            types=response.substr(response.indexOf("__next__") + 8);

            //Load category divs
           	divhtml=divhtml.replace(/\_\_num\_\_/g, divnum);
           	divhtml=divhtml.replace(/\_\_num1\_\_/g, (divnum + 1));
           	divhtml=divhtml.replace(/\_\_catname\_\_/g, catname);
           	divhtml=divhtml.replace(/\_\_catid\_\_/g, catid);
           	divhtml=divhtml.replace(/<!--typeselhtml-->/g, "");
           	divhtml=divhtml.replace(/<!--mfrselhtml-->/g, "");
           	divhtml=divhtml.replace(/display\: block/g, "display: none");

            var newdiv=document.createElement('div');
           	newdiv.id='categorydiv' + divnum;
           	newdiv.innerHTML=divhtml;

           	//Add types to select box
           	//Have to find the select and replace the whole thing, because IE won't fix their bugs
           	var spans=newdiv.getElementsByTagName('span');
           	for (i=0;i<spans.length;i++)
           	{
               	if (spans[i].getAttribute('title')=='typehtmlspan')
                   	spans[i].innerHTML=spans[i].innerHTML.replace(/\<\/select\>/i, types + "</select>");
                else if (spans[i].getAttribute('title')=='mfrhtmlspan')
                   	spans[i].innerHTML=spans[i].innerHTML.replace(/\<\/select\>/i, mfrs + "</select>");
           	}

           	divcontainer.insertBefore(newdiv, document.getElementById('cattitleadd'));
           	changeProfileCategory(divnum);
           	//Update div numbers
           	setProfileCategoryNumbers();
        }
    }
    
    function changeProfileCategory(divnum)
    {
        var divcount=0;
        var changed=false;
        for (var i=0;i<3;i++)
        {
            var divcontainer=document.getElementById('category_main');
            var categoryedit=document.getElementById('cateditdiv' + i);
            var categorytext=document.getElementById('cattextdiv' + i);
            var categorylink=document.getElementById('editcategory' + i);
            var categorylink2=document.getElementById('closecategory' + i);
            if (divcontainer && categorytext && categoryedit && categorylink && categorylink2 && divnum!=i)
            {
                divcount++;
                if (categorytext.innerHTML.indexOf("__typeselhtml__")>-1)
                {
                    //If this is new and hasn't been saved, add back into dropdown
                    var catid=document.getElementById('bus_catid' + i).value;
                    var catname=document.getElementById('catTitle' + i).parentNode.innerHTML;
                    catname=catname.substr(catname.search(/<\/span> /i) + 8);
                    addOptionSorted('dir_add_category', catname, catid, true);
                    
                    //Also remove this category div
                    divcontainer.removeChild(document.getElementById('categorydiv' + i));
                    
                    changed=true;
                    divcount--;
                    setProfileCategoryNumbers();
                }
                else
                {
                    categoryedit.style.display='none';
                    categorytext.style.display='block';
                    categorylink.style.display='';
                    categorylink2.style.display='none';
                }
            }
            else if (divcontainer && categoryedit && categorytext && categorylink)
            {
                divcount++;
                categoryedit.style.display='block';
                categorytext.style.display='none';
                categorylink.style.display='none';
                categorylink2.style.display='';
            }
        }
        var divaddtitle=document.getElementById('cattitleadd');
        var divaddmain=document.getElementById('catadd');
        if (divaddtitle && divaddmain)
        {
            if (divcount==3)
            {
                divaddtitle.style.display='none';
                divaddmain.style.display='none';
            }
            else if (divcount<3 && divaddtitle.style.display=='none')
            {
                divaddtitle.style.display='block';
                divaddmain.style.display='block';
            }
        }
    }
    
    function saveProfileCategory(divnum)
    {
        var mfrs=document.getElementById('dir_bus_mfrselect' + divnum);
        var types=document.getElementById('dir_bus_typeselect' + divnum);
        var textdiv=document.getElementById('cattextdiv' + divnum);
        if (mfrs && types && textdiv)
        {
            var mfrsHTML="";            
            var typesHTML="";
            for (i=0;i<types.length;i++)
                typesHTML=typesHTML + "<p style='padding-left: 15px;'>" + types.options[i].innerHTML + "</p>";
            for (i=0;i<mfrs.length;i++)
                mfrsHTML=mfrsHTML + "<p style='padding-left: 15px;'>" + mfrs.options[i].innerHTML + "</p>";
            if (mfrsHTML=="")
                mfrsHTML="<p style='padding-left: 15px;'>None</p>";
            if (typesHTML=="")
                typesHTML="<p style='padding-left: 15px;'>None</p>";
            
            textdiv.getElementsByTagName('div')[2].innerHTML=typesHTML;
            textdiv.getElementsByTagName('div')[5].innerHTML=mfrsHTML;
        }
    }
    
    function closeProfileCategory(divnum)
    {
        var categorylink=document.getElementById('editcategory' + divnum);
        var categorylink2=document.getElementById('closecategory' + divnum);
        var categorytext=document.getElementById('cattextdiv' + divnum);
        document.getElementById('cateditdiv' + divnum).style.display='none';
        document.getElementById('cattextdiv' + divnum).style.display='block';
        if (categorylink && categorylink2 && categorytext)
        {
            categorylink.style.display='';
            categorylink2.style.display='none';
            if (categorytext.innerHTML.indexOf("__typeselhtml__")>-1)
                removeProfileCategory(divnum);
        }
    }
        
    function removeProfileCategory(divnum)
    {
        var divcontainer=document.getElementById('category_main');
        var divaddtitle=document.getElementById('cattitleadd');
        var divaddmain=document.getElementById('catadd');
        if (divcontainer)
        {
            var catid=document.getElementById('bus_catid' + divnum).value;
            var catname=document.getElementById('catTitle' + divnum).parentNode.innerHTML;
            catname=catname.substr(catname.search(/<\/span> /i) + 8);
            addOptionSorted('dir_add_category', catname, catid, true);

            divcontainer.removeChild(document.getElementById('categorydiv' + divnum));
            setProfileCategoryNumbers();
        }
        if (divaddtitle && divaddmain)
        {
            if (divaddtitle.style.display=='none')
            {
                divaddtitle.style.display='block';
                divaddmain.style.display='block';
            }
        }        
    }
    
    //Updates the 'category 1', 'category 2' text for each div
    function setProfileCategoryNumbers()
    {
        var divcontainer=document.getElementById('category_main');
        var divlist=divcontainer.getElementsByTagName('span');
        var divcount=1;
        if (divcontainer && divlist)
        {
            for (i=0;i<divlist.length;i++)
            {
                if (divlist[i].id && divlist[i].id.indexOf('catTitle')>-1)
                    divlist[i].innerHTML='Category ' + divcount++ + ':';
            }
        }
    }
    
    function setProfileType(typenum)
    {
        var detailsmain=document.getElementById('profileDetailsMain');
        var detailsalt=document.getElementById('profileDetailsAlt');
        //Display the main div if it's still hidden
        if (detailsmain && detailsmain.style.display=='none')
        {
            detailsmain.style.display='block';
            detailsalt.style.display='none';
        }
        var bustypelist=document.getElementById('dir_bus_type');
        var bustypeselected=document.getElementById('dir_bus_typeselect');
        //Handle the business type selector
        if (bustypelist && bustypeselected)
        {
            for (;bustypeselected.length>0;)
            {
                bustypeselected.selectedIndex=0;
                remove_bustype('dir_bus_type', 'dir_bus_typeselect');
            }
            if (typenum==1)
            {
                for (i=0;i<bustypelist.length;i++)
                {
                    if (bustypelist.options[i].innerHTML=='Personal Use')
                    {
                        bustypelist.selectedIndex=i;
                        add_bustype('dir_bus_type', 'dir_bus_typeselect')
                        document.getElementById('bustypespan').style.display='none';
                        break;
                    }
                }
            }
            else
                document.getElementById('bustypespan').style.display='';
        }
        var requiredspans=detailsmain.getElementsByTagName('span');
        //Handle all the '*' required marks
        if (requiredspans)
        {
            for (i=0;i<requiredspans.length;i++)
            {
                if (requiredspans[i].className=='required' && requiredspans[i].id)
                {
                    if (requiredspans[i].id=='reqemail' || requiredspans[i].id=='reqwebsite')
                    {
                        if (typenum==2 || typenum==4)
                            requiredspans[i].style.display='';
                        else
                            requiredspans[i].style.display='none';
                    }
                    else if (typenum==3 || typenum==4)
                        requiredspans[i].style.display='';
                    else
                        requiredspans[i].style.display='none';
                }
            }
        }
        //Handle text changes
        var promolbl=document.getElementById('lbl_bus_promoline');
        var namelbl=document.getElementById('lbl_bus_name');
        var phonelbl=document.getElementById('lbl_bus_phone');
        var desclbl=document.getElementById('lbl_bus_desc');
        if (promolbl && namelbl && phonelbl && desclbl)
        {
            if (typenum==1)
            {
                promolbl.innerHTML='Display name:';
                namelbl.innerHTML="<span class='required'>*</span>Name:";
                phonelbl.innerHTML='Phone:';
                desclbl.innerHTML='Describe yourself:';
            }
            else
            {
                promolbl.innerHTML='Profile headline:';
                namelbl.innerHTML="<span class='required'>*</span>Business name:";
                phonelbl.innerHTML='Business phone:';
                desclbl.innerHTML='Describe your business:';
            }
        }
        
        //If in an error state, clear it
        var typediv=document.getElementById('profileTypeDiv');
        if (typediv && typediv.style && (typediv.style.borderColor.indexOf('red')>-1 || typediv.style.borderColor=='#ff0000'))
            typediv.style.border='';
    }
    
    function setActiveProfilePage(pagenum)
    {
        if (document.getElementById('profileTopLink1').style.backgroundPosition=="0px 0px" && !validateProfilePage(pagenum))
            return;
        var linkwidths=new Array(0, -41, -61, -37);
        var divlist=new Array("", "createDir_details", "createDir_categories", "createDir_images");
        var showlist=new Array("", ",2,", ",1,2,", ",1,3,");
        var linkadd=new Array(0, -1, 1);
        
        for (i=1;i<4;i++)
        {
            var toplink=document.getElementById('profileTopLink' + i);
            var currdiv=document.getElementById(divlist[i]);
            var bottomlink=document.getElementById('profileBottomLink' + i);
            if (toplink && currdiv && bottomlink)
            {
                if (i==pagenum)
                {
                    toplink.style.backgroundPosition="0px 0px";
                    currdiv.style.display='block';
                }
                else
                {
                    toplink.style.backgroundPosition="" + linkwidths[i] + "px 0px";
                    currdiv.style.display='none';
                }
                if (showlist[pagenum].indexOf(',' + i + ',')>-1)
                {
                    bottomlink.style.display='';
                    if (i<3)
                        bottomlink.onclick=new Function("setActiveProfilePage(" + (pagenum + linkadd[i]) + "); window.scroll(0, 230); return false;");
               }
                else
                    bottomlink.style.display='none';
            } 
        }
    }
    
    function validateProfilePage(pagenum)
    {
        var profiletype=0;
        var valid=false;
        
        for (i=1;i<5;i++)
            if (document.getElementById('dirtype' + i).checked)
                profiletype=i;
        //Clear previous errors
        var detailsNodes=document.getElementById('profileDetailsMain').getElementsByTagName('div')[0].childNodes;
        for (i=0;i<detailsNodes.length;i++)
            if (detailsNodes[i].style && (detailsNodes[i].style.borderColor.indexOf('red')>-1 || detailsNodes[i].style.borderColor=='#ff0000'))
                detailsNodes[i].style.border='1px solid #787878';
        //Special exception for state - it's in an enclosing span
        var statebox=document.getElementById('dir_bus_state');
        if (statebox && statebox.style && (statebox.style.borderColor.indexOf('red')>-1 || statebox.style.borderColor=='#ff0000'))
            statebox.style.border='1px solid #787878';
            
        if (profiletype==0)
            badField('profileTypeDiv', 'Please select a profile type.');
        else
        {
            //All types must have name
            var namebox=document.getElementById('dir_bus_name');
            if (namebox && trim(namebox.value).length<=0)
            {
                badField('dir_bus_name', 'Please provide a valid name.');
                return false;
            }
            //Personal - no validation
            if (profiletype==1)
                valid=true;
            //Web-based business validation
            if (profiletype==2 || profiletype==4)
            {
                var emailbox=document.getElementById('dir_bus_email');
                var websitebox=document.getElementById('dir_bus_website');
                var bustypebox=document.getElementById('dir_bus_typeselect');
                if (emailbox && checkEmail(emailbox.value)==false)
                    badField('dir_bus_email', 'Please provide a valid e-mail address.');
                else if (websitebox && checkUrl(websitebox.value)==false)
                    badField('dir_bus_website', 'Please provide a valid website.');
                else if (bustypebox && bustypebox.length==0)
                {
                    if (navigator.userAgent.indexOf("MSIE")>-1) //IE doesn't support borders on select boxes
                        badField('ieTypeselectFix', 'Please choose at least one business type.');                
                    else
                        badField('dir_bus_typeselect', 'Please choose at least one business type.');
                }
                else
                    valid=true;
            }          
            if (profiletype==3 || (profiletype==4 && valid==true)) //Physical business validation
            {
                valid=false;
                var countrybox=document.getElementById('dir_bus_country');
                var countrysel;
                if (countrybox)
                    countrysel=countrybox.options[countrybox.selectedIndex].value;
                var zipbox=document.getElementById('dir_bus_zip');
                var statesel;
                if (statebox)
                    statesel=statebox.options[statebox.selectedIndex].value;
                var citybox=document.getElementById('dir_bus_city');
                var addybox=document.getElementById('dir_bus_add1');
                var bustypebox=document.getElementById('dir_bus_typeselect');
                if (countrybox && countrysel && (countrysel=="def" || trim(countrysel).length<=0))
                    badField('dir_bus_country', 'Please choose a country.');
                else if (zipbox && trim(zipbox.value).length<=0)
                    badField('dir_bus_zip', 'Please enter a valid zip code.');
                else if (statebox && statesel && (statesel=="def" || trim(statesel).length<=0))
                    badField('dir_bus_state', 'Please choose a state.');
                else if (citybox && trim(citybox.value).length<=0)
                    badField('dir_bus_city', 'Please enter a city.');
                else if (addybox && trim(addybox.value).length<=0)
                    badField('dir_bus_add1', 'Please enter an address.');
                else if (bustypebox && bustypebox.length==0)
                {
                    if (navigator.userAgent.indexOf("MSIE")>-1) //IE doesn't support borders on select boxes
                        badField('ieTypeselectFix', 'Please choose at least one business type.');                
                    else
                        badField('dir_bus_typeselect', 'Please choose at least one business type.');
                }
                else
                    valid=true;
            }
        }
            
        return valid;
    }
    
    //General error handling function, alerts and then highlights bad cell
    function badField(element, msg)
    {
        alert(msg);
        document.getElementById(element).style.border='1px solid red';
    }
    
    //Adds an option to a select box, preserving sort order
    function addOptionSorted(selectName, optionText, optionValue, nameSort)
    {
        var insertPos;
        var selectBox=document.getElementById(selectName);
        if (selectBox)
        {
            for (insertPos=0;insertPos<selectBox.length;insertPos++)
            {
                if (nameSort)
                {
                    if (selectBox.options[insertPos].text.toLowerCase()>optionText.toLowerCase())
                    {
                        break;
                    }
                }
                else
                {
                    if (selectBox.options[insertPos].value>optionValue)
                        break;
                }
            }
            var newopt=document.createElement('option');
            newopt.text=optionText;
            newopt.value=optionValue;
            try { selectBox.add(newopt, selectBox.options[insertPos]); } //W3C standards compliant method
            catch (ex) { selectBox.add(newopt, insertPos); } //IE 'super sucky lame' method
        }
    }
    
    //Moves an option from one select box to another, preserving sort order
    function moveOptionSorted(selectNameSrc, selectNameDest, nameSort, limit)
    {
        var selectBoxSrc=document.getElementById(selectNameSrc);
        var selectBoxDest=document.getElementById(selectNameDest);
        if (selectBoxSrc && selectBoxSrc.selectedIndex>-1 && selectBoxDest)
        {
            if (limit && selectBoxDest.length>=limit)
            {
                alert('You can only add ' + limit + ' items to this box.');
                return;
            }
            var moveopt=selectBoxSrc.options[selectBoxSrc.selectedIndex];
            if (nameSort)
                addOptionSorted(selectNameDest, moveopt.text, moveopt.value, nameSort);
            else
                addOptionSorted(selectNameDest, moveopt.text, moveopt.value);
            selectBoxSrc.remove(selectBoxSrc.selectedIndex);
        }
    }
    
    //Handle adding a business type, and de-highlighting any error states for the business type box
    function addBusinessType(mainname, addname)
    {
        var addbox=document.getElementById(addname);
        if (navigator.userAgent.indexOf("MSIE")>-1) //IE doesn't support borders on select boxes, so use the span instead
            document.getElementById('ieTypeselectFix').style.border='';
        else //Clear error state from validation (non-IE)
            if (addbox && addbox.style && (addbox.style.borderColor.indexOf('red')>-1 || addbox.style.borderColor=='#ff0000'))
	            addbox.style.border='';
	    moveOptionSorted(mainname, addname, true, 3);
    }
    
    //Adds an image to the image display
    function addProfileImage(imgsrc, imgcaption, imgwidth, imgheight)
    {
        var divnum=-1, divcount=0;
        var noimages=document.getElementById('noimagesdiv');
        if (noimages && noimages.style.display=='block')
            noimages.style.display='none';
        for (i=0;i<8;i++)
        {
            if (document.getElementById('imagediv' + i))
                divcount++;
            else if (divnum==-1)
                divnum=i;
        }
        if (divnum>-1)
        {
            var divcontainer=document.getElementById('images_main');
        
            var divhtml=document.getElementById('image_div_default').innerHTML;

            if (divcontainer && divhtml)
            {
                //Load image divs
               	divhtml=divhtml.replace(/\_\_num\_\_/g, divnum);
               	divhtml=divhtml.replace(/imagereplace/g, imgsrc);
               	divhtml=divhtml.replace(/\_\_caption\_\_/g, wordWrap(imgcaption, 14, ' '));
               	divhtml=divhtml.replace(/\_\_width\_\_/g, imgwidth);
               	divhtml=divhtml.replace(/\_\_height\_\_/g, imgheight);

                var newdiv=document.createElement('div');
               	newdiv.id='imagediv' + divnum;
               	newdiv.innerHTML=divhtml;
               	//Hide 'default' image if this is not the only image
               	if (divcount!=0)
               	    newdiv.getElementsByTagName('img')[0].style.display='none';

               	divcontainer.insertBefore(newdiv, document.getElementById('image_div_default'));
           	}
        }
    }
    
    //Deletes an image from user's profile
    function deleteProfileImg(imgnum)
    {
        var delConfirm;
        var imageUI=document.getElementById('profileImage' + imgnum);
        delConfirm=confirm("Are you sure you want to delete this image?");
        if (delConfirm && imageUI)
        {
    		imageUI=imageUI.src;
    		imageUI=imageUI.substr(imageUI.lastIndexOf('/') + 1);
    		imageUI=imageUI.replace(/(\_tn)|(ProfileImages\/)/, "");
    		AJAXRequest("profileimage_upload.php?deleteimg=" + imageUI + "&imgnum=" + imgnum, removeProfileImg);
		}
    }
    
    //Removes an image from the display
    function removeProfileImg(imgnum)
    {
        if (imgnum==-1)
            alert("There was an error deleting your image. Please try deleting this image again.\n\nIf the problem continues, you can contact us using the 'Contact' link near the top.");
        else
        {
            var divcontainer=document.getElementById('images_main');
            var imagediv=document.getElementById('imagediv' + imgnum);
            var defaultdiv=document.getElementById('profileImageDefault' + imgnum);
            var isdefault=0;
            if (divcontainer && imagediv && defaultdiv)
            {
                if (!defaultdiv.style.display || (defaultdiv.style.display && defaultdiv.style.display.toLowerCase()!='none'))
                    isdefault=1;
                divcontainer.removeChild(imagediv);
                //This is required to refresh an Opera display bug that doesn't refresh the layout
                divcontainer.style.display='none';
                divcontainer.style.display='block';
                
                var divcount=0;
                //Check if that was the last image
                for (i=0;i<8;i++)
                {
                    if (document.getElementById('imagediv' + i))
                    {
                        divcount++;
                        //They deleted the default image, so set the next one to default
                        if (isdefault==1)
                        {
                            setDefaultProfileImg(i);
                            isdefault==0;
                        }
                    }
                }
                //If last image, show the 'no images' text
                if (divcount==0)
                {
                    var noimages=document.getElementById('noimagesdiv');
                    noimages.style.display='block';
                }
            }
        }
    }
    
    //Shows a preview of the full image
    function showProfileImg(e, imgnum, imgwidth, imgheight)
    {
        var imagefulldiv=document.getElementById('imagefulldiv');
        var image=document.getElementById('profileImage' + imgnum);
	    var imgpos=getElementPos('images_main');

	    imagefulldiv.style.display='block';
        imagefulldiv.getElementsByTagName('span')[1].innerHTML='<img src="' + image.src.replace(/_tn/, "_real") + '">';

	    var windowWidth=0;
	    var leftpos=0, toppos=0;

        if (self.innerWidth)
		    windowWidth=self.innerWidth;
	    else if (document.documentElement && document.documentElement.clientWidth)
		    windowWidth=document.documentElement.clientWidth;
	    else if (document.body)
		    windowWidth=document.body.clientWidth;
		//Set image in middle of window
	    leftpos=(windowWidth  - imgwidth) / 2;
	    if (leftpos>0)
		    imagefulldiv.style.left=leftpos + "px";
		    
        imagefulldiv.style.top=(imgpos[1] - 20) + "px";
    }
    
    //Changes which image is the default in the database, and display
    function setDefaultProfileImg(imgnum)
    {
        var imageUI=document.getElementById('profileImage' + imgnum);
        if (imageUI)
        {
    		imageUI=imageUI.src;
    		imageUI=imageUI.substr(imageUI.lastIndexOf('/') + 1);
    		imageUI=imageUI.replace(/(\_tn)|(ProfileImages\/)/, "");
    		AJAXRequest("profileimage_upload.php?defaultimg=" + imageUI + "&imgnum=" + imgnum);

            for (i=0;i<8;i++)
            {
                defaultimg=document.getElementById('profileImageDefault' + i)
                if (defaultimg)
                {
                    if (i==imgnum)
                       defaultimg.style.display='block';
                    else
                       defaultimg.style.display='none';
                }
            }
        }   
    }
    
    //Swaps two different elements, making one visible and the other hidden
    function swapElementDisplay(name1, name2)
    {
        var element1=document.getElementById(name1);
        var element2=document.getElementById(name2);
        if (element1 && element2)
        {
            element1.style.display='block';
            element2.style.display='none';
        }
    }
    
    //Wraps a string so it's only a certain amount of characters wide
    //Only considers spaces as word breaks
    function wordWrap(text, textwidth, breakstr)
    {
        var lettercount=0;
        for (i=0;i<text.length;i++)
        {
           lettercount++;
            if (text.charAt(i)==" ")
                lettercount=0;
            if (lettercount==textwidth)
	        {
                text=text.substr(0, i) + breakstr + text.substr(i);
                lettercount=0;
	        }
        }
        return text;
    }
    
    function changeProfileSearch(pagenum, args)
    {
        var search_wait_img1=document.getElementById('profile_page_wait1');
        var search_wait_img2=document.getElementById('profile_page_wait2');
        if (search_wait_img1 && search_wait_img2)
        {
            document.getElementById('profile_page_wait_div1').style.display='';
            search_wait_img1.style.visibility='visible';
            search_wait_img2.style.visibility='visible';
            if (navigator && navigator.appVersion.indexOf("MSIE")!=-1) //IE SUCKS, won't animate unless src is changed
            {
                setTimeout("document.getElementById('profile_page_wait1').src = 'images/ajax_loader_clear.gif';", 100);
                setTimeout("document.getElementById('profile_page_wait2').src = 'images/ajax_loader_clear.gif';", 100);
            }
        }
        AJAXRequest("profilebox.php?search_cmd=show_results&ajax=yes&pnum=" + pagenum + "&" + args, updateProfileSearch, "search_div_full");
    }
    
    function updateProfileSearch(text, boxname)
    {
        boxelement=document.getElementById(boxname);
        if (boxelement)
            boxelement.innerHTML=text;
    }
    
    function shiftProfileImages(direction)
    {
        var image_container=document.getElementById('image_container');
        if (image_container)
        {
            if (direction==1)
            {
                var image_holder=image_container.removeChild(image_container.firstChild);
                image_container.appendChild(image_holder);
            }
            else if (direction==-1)
            {
                var image_holder=image_container.removeChild(image_container.lastChild);
                image_container.insertBefore(image_holder, image_container.firstChild);
            }
            
        }
    }
    
    //Expands the advanced search div, and selects a tab if provided
    function expandAdvancedSearch(tabID)
    {
        document.getElementById('attrib_search').style.visibility='visible';
        selectTab(tabID);
    }
    
    //Selects a given tab, fires when a tab is clicked on
    function selectTab(tabID)
    {
        var tab_data;
        var prev_tab_data=document.getElementById('attrib_tab_data' + tabState.selected);
        var tab_controls=document.getElementById('attribSearchTabDiv');
        if (tab_controls && tabState)
        {
            //If no previous selection, then initialize tabs
            if (tabState.selected=="")
            {
                if (tabID==0)
                    tabState.selected=tab_controls.getElementsByTagName('div')[0].id.replace(/attrib_tab/g, "");
                tabState.firstTab=tab_controls.getElementsByTagName('div')[0].id.replace(/attrib_tab/g, "");
                initTabs(tab_controls);
                if (tabID==0) //No tab selected, revert to default
                {
                    curr_tab=document.getElementById('attrib_tab' + tabState.selected);
                    tab_data=document.getElementById('attrib_tab_data' + tabState.selected);
                }
                else //Select provided tab
                {
                    tabState.selected=tabID;
                    curr_tab=document.getElementById('attrib_tab' + tabID);
                    tab_data=document.getElementById('attrib_tab_data' + tabID);
                }
                curr_tab.getElementsByTagName('div')[0].style.backgroundImage='url(images/attrib_tab_gradient.gif)';
                curr_tab.getElementsByTagName('div')[0].style.top='0';
            }
            else //Previous selection is present, disable previous and enable new tab
            {
                var prev_tab=document.getElementById('attrib_tab' + tabState.selected);

                if (tabID==0)
                {
                    curr_tab=document.getElementById('attrib_tab' + tabState.firstTab);
                    tab_data=document.getElementById('attrib_tab_data' + tabState.firstTab)
                    tabState.selected=tabState.firstTab;
                }
                else
                {
                    curr_tab=document.getElementById('attrib_tab' + tabID);
                    tab_data=document.getElementById('attrib_tab_data' + tabID);
                    tabState.selected=tabID;
                }
                
                prev_tab.getElementsByTagName('div')[0].style.backgroundImage='url(images/attrib_tab_background.gif)';
                prev_tab.getElementsByTagName('div')[0].style.top='2'

                curr_tab.getElementsByTagName('div')[0].style.backgroundImage='url(images/attrib_tab_gradient.gif)';
                curr_tab.getElementsByTagName('div')[0].style.top='0'
            }
            if (prev_tab_data)
                prev_tab_data.style.display='none';
            tab_data.style.display='';
        }
    }
    
    //Adds an attribute filter selection to the generated url
    function attribItemSelect(sel_type, sel_value, sel_group)
    {
        if (sel_type==1) //Listitem
            tabState.filter_l=toggleFilterValue(tabState.filter_l, sel_value, document.getElementById('chkl_' + sel_value));
        else if (sel_type==2) //Group 
            tabState.filter_g=toggleFilterValue(tabState.filter_g, sel_value, document.getElementById('chkg_' + sel_value));
        else if (sel_type==3) //Range
            tabState.filter_r=toggleFilterValue(tabState.filter_r, sel_value, document.getElementById('chkr_' + sel_value));
        else if (sel_type==4) //Group listitem
        {
            var group_item=document.getElementById('chkg_' + sel_group + 'l_' + sel_value);
            var normal_item=document.getElementById('chkl_' + sel_value);
            //Check/uncheck the group list item, if unchecked then uncheck the normal list item as well
            tabState.filter_l=toggleFilterValue(tabState.filter_l, sel_value, group_item);
            if (normal_item && group_item.checked==false)
                normal_item.checked=false;
            
            var group_div_items=document.getElementById('div_' + sel_group).getElementsByTagName('input');
            var group_box=document.getElementById('chkg_' + sel_group);
            var group_item_value;
            if (group_div_items && group_box)
            {
                //If the group is checked
                if (group_box.checked)
                {
                    //Set each individual item that's checked, since group will not be selected anymore
                    for (i=0;i<group_div_items.length;i++)
                    {
                        if (group_div_items[i].checked)
                        {
                            group_item_value=group_div_items[i].id.substr(group_div_items[i].id.indexOf('l_') + 2);
                            tabState.filter_l=toggleFilterValue(tabState.filter_l, group_item_value, group_div_items[i]);
                        }
                    }
                    //Uncheck group and remove from list
                    group_box.checked=false;
                    tabState.filter_g=toggleFilterValue(tabState.filter_g, sel_group, group_box);
                }
                else //If the group is not checked
                {
                    var all_checked=true;
                    //Loop through each item, determine if all items are checked
                    for (i=0;i<group_div_items.length;i++)
                    {
                        if (group_div_items[i].checked==false)
                        {
                            all_checked=false;
                            break;
                        }
                    }
                    //If all items are checked, re-check the group and add it to the list
                    if (all_checked)
                    {
                        group_box.checked=true;
                        tabState.filter_g=toggleFilterValue(tabState.filter_g, sel_group, group_box);
                        //Remove items from the list since group is selected now
                        for (i=0;i<group_div_items.length;i++)
                        {
                            group_item_value=group_div_items[i].id.substr(group_div_items[i].id.indexOf('l_') + 2);
                            tabState.filter_l=toggleFilterValue(tabState.filter_l, group_item_value, group_div_items[i], true);
                        }
                    }
                }
                
            }
        }
        else if (sel_type==5) //Year listitem
            tabState.filter_y=toggleFilterValue(tabState.filter_y, sel_value, document.getElementById('chky_' + sel_value));
        else if (sel_type==6) //Test group 'anthony method'
            tabState.filter_g=toggleFilterValue(tabState.filter_g, sel_value, document.getElementById('chkg_' + sel_value));
            
    }
    
    //Adds/removes an item from a filter, clear parameter is used by group items to clear their listitems
    function toggleFilterValue(filter_var, sel_value, box, clear)
    {
        //If box is checked, and group isn't clearing items
        if (box && box.checked && !clear)
        {
            if ((('-' + filter_var + '-').indexOf('-' + sel_value + '-')==-1))
            {
                if (filter_var!="")
                    filter_var+='-';
                filter_var +=sel_value;
            }
        }
        else if (box) //If box is unchecked, or group is clearing items
        {
            filter_var=('-' + filter_var + '-').replace('-' + sel_value + '-', '-');
            if (filter_var=="-")
                filter_var="";
            if (filter_var!="")
                filter_var=filter_var.substr(1, filter_var.length - 2)
        }
        return filter_var;
    }
    
    //Selects group items when a group is selected
    function attribGroupSelect(group_id)
    {
        var group_div_items=document.getElementById('div_' + group_id).getElementsByTagName('input');
        var group_checkbox=document.getElementById('chkg_' + group_id);
        var sel_value, normal_item;
        for (i=0;i<group_div_items.length;i++)
        {
            if (group_checkbox.checked)
                group_div_items[i].checked=true;
            else
            {
                group_div_items[i].checked=false;
                normal_item=document.getElementById('chkl_' + sel_value);
                if (normal_item)
                    normal_item.checked=false;
            }
            sel_value=group_div_items[i].id.substr(group_div_items[i].id.indexOf('l_') + 2);
            tabState.filter_l=toggleFilterValue(tabState.filter_l, sel_value, group_div_items[i], true);
        }
    }
    
    //Shows/hides group items
    function attribGroupToggleItems(group_id)
    {
        var group_div=document.getElementById('div_' + group_id);
        var group_link=document.getElementById('link_' + group_id);
        
        if (group_div.style.display=='none')
        {
            group_div.style.display='';
            if (group_link)
                group_link.innerHTML='(hide)'
        }
        else
        {
            group_div.style.display='none';
            if (group_link)
                group_link.innerHTML='(show all)'
        }
    }
    
    //Submits the current filters, directs to the newly generated URL
    function attribSearchSubmit()
    {
        var newURL=tabState.URL_start;
        if (tabState.filter_l!="")
            newURL += '&filter_l=' + tabState.filter_l;
        if (tabState.filter_g!="")
            newURL += '&filter_g=' + tabState.filter_g;
        if (tabState.filter_r!="")
            newURL += '&filter_r=' + tabState.filter_r;
        if (tabState.filter_y!="")
            newURL += '&filter_y=' + tabState.filter_y;
            
        var attrib_tabs=document.getElementById('attribSearchTabDiv').childNodes;
        var tab_id, tab_controls, selected_box;
        //Build the attr_sel string by going through each tab and seeing if any boxes were checked
        for (i=0;i<attrib_tabs.length;i++)
        {
            if (!attrib_tabs[i].innerHTML || attrib_tabs[i].id=='attrib_tabyear')
                continue;
            tab_id=attrib_tabs[i].id.replace(/attrib_tab/g, "");
            tab_controls=document.getElementById('attrib_tab_data' + tab_id).getElementsByTagName('input');
            selected_box=false;
            //Go through each checkbox in this tab
            for (x=0;x<tab_controls.length;x++)
            {
                if (tab_controls[x].type=='checkbox' && tab_controls[x].checked)
                {
                    selected_box=true;
                    break;
                }
            }
            if (selected_box) //Checkbox was selected, add to attr_sel filter
            {
                if ((('-' + tabState.filter_as + '-').indexOf('-' + tab_id + '-')==-1))
                {
                    if (tabState.filter_as!="")
                        tabState.filter_as+='-';
                    tabState.filter_as+=tab_id;
                }
            }
            else //Checkbox was not selected, remove from attr_sel filter
            {
                if ((('-' + tabState.filter_as + '-').indexOf('-' + tab_id + '-')>-1))
                {
                    tabState.filter_as=('-' + tabState.filter_as + '-').replace('-' + tabState.filter_as + '-', '-');
                    if (tabState.filter_as=="-")
                        tabState.filter_as="";
                    if (tabState.filter_as!="")
                        tabState.filter_as=tabState.filter_as.substr(1, tabState.filter_as.length - 2)
                }
            }
        }
        if (tabState.filter_as!="")
            newURL += '&attr_sel=' + tabState.filter_as;
        
        year1=document.getElementById('year1box');
        if (year1)
            newURL += '&year1=' + year1.value;
        else if (document.getElementById('year1_val'))
            newURL += '&year1='
            
        year_specific=document.getElementById('year_specific');
        year2=document.getElementById('year2box');
        if (year1 && year1.value!='' && ((year_specific && year_specific.checked) || (year2 && year2.value==year1.value)))
            newURL += 's'
        else
        {
            if (year2 && (!year1 || year2.value!=year1.value))
                newURL += '&year2=' + year2.value;
            else if (document.getElementById('year2 _val'))
                newURL += '&year2='
        }
        if (year1 && year2 && year1.value && year2.value && year1.value>year2.value)
        {
            alert("Starting year must be earlier than ending year!");
            return false;
        }
        document.location.href=newURL;
    }
    
    //Initializes attribute search tab order
    function initTabs(tab_controls)
    {
        var tabNodes=tab_controls.childNodes;
        var rows=new Array(), prev_row_width=0, curr_row_width=0, curr_row_height=-1;
        //Loop through each div and calculate the length of each row of tabs
        for (i=0;i<tabNodes.length;i++)
        {
            if (tabNodes[i].innerHTML)
            {
                if (curr_row_height==-1)
                    curr_row_height=tabNodes[i].offsetTop
                else if (tabNodes[i].offsetTop>curr_row_height)
                {
                     prev_row_width=curr_row_width;
                     curr_row_width=0;
                     curr_row_height=tabNodes[i].offsetTop;
                     rows[rows.length]=tabNodes[i].id;
                }
                curr_row_width+=tabNodes[i].offsetWidth;
            }
        }
        if (rows.length>0) //If there's more than one row, reposition tabs
        {
            //Add in a spacer tab if the last row is smaller than the previous
            if (prev_row_width>curr_row_width + 5)
            {
                var spacer_div=document.createElement("div");
                spacer_div.style.width=(prev_row_width - curr_row_width - 5) + "px";
                spacer_div.style.height="21px";
                spacer_div.style.cssFloat="left";
                spacer_div.id="spacer_div";
                tab_controls.appendChild(spacer_div);
            }
                        
            var temp_tab;
            //Loop through each row, position the tabs in backwards row order
            //I.E. second row is stacked on top of the first row, third row is stacked on top of the second
            for (i=0, curr_row=0, curr_pos=-1;i<tabNodes.length;i++)
            {
                if (tabNodes[i].innerHTML || tabNodes[i].id=="spacer_div")
                {
                    if (tabNodes[i].id==rows[curr_row])
                    {
                        curr_row++;
                        curr_pos=-1;
                    }
                    if (curr_row>0)
                    {
                        temp_tab=tab_controls.removeChild(tabNodes[i]);
                        temp_tab.style.zIndex=(5 - curr_row);
                        temp_tab.style.top=(4 * curr_row);
                        temp_tab.style.position='relative';
                        if (curr_pos==-1)
                            tab_controls.insertBefore(temp_tab, tabNodes[0]);
                        else
                            tab_controls.insertBefore(temp_tab, curr_pos.nextSibling);
                       curr_pos=temp_tab;
                    }
                }
            }
        }
    }
