var xmlDoc,categ,subcateg,zip,ozip,q,page,sort,total_items,property_type,price,year_built,search_cnt,search_opt_cnt,distance,range,fcity,fstate,fzip,model,make,keyword,sort_by,lot_size,bedrooms,bathrooms,square_footage,bestmatch=0,salary,region;
fcity='';fstate='';fzip='';make='';model='';salary='';
var d = new Date();
var today=d.getTime();
var one_day=86400000;
range=50;
distance=""
year_built=""
price="";bathrooms='';square_footage='';
property_type="";
region='';
sort_by="Distance";
sort='';
var states = new Array("Alabama", "Alaska", "Arizona","Arkansas", "California", "Colorado", "Connecticut",
"Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii", "Idaho","Illinois", "Indiana", "Iowa",
"Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts","Michigan", "Minnesota", "Mississippi",
"Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York",
"North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina",
"South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Washington", "Virginia", "West Virginia",
"Wisconsin", "Wyoming");

var abbr = new Array("AL", "AK", "AZ","AR", "CA", "CO", "CT",
"DE","DC","FL","GA","HI", "ID","IL", "IN", "IA",
"KS", "KY", "LA", "ME", "MD", "MA","MI", "MN", "MS",
"MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY",
"NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC",
"SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV",
"WY", "WY");

var ranges = new Array("5", "10", "25", "50", "200" );

function loadXML(arg1,arg2,arg4,arg5,arg6,arg7,arg8,arg9) {
 if(make=='') make=omake;
 document.getElementById("listings").innerHTML="<span style='padding-left:10px;'>loading info...Please wait</span>";
 categ=arg1;subcateg=arg2;q=arg4;page=arg5;sort=arg6;fcity=arg7;fstate=arg8;
 keyword=removeSpaces(arg9);
 if(sort=='') {
       	bestmatch=1;
	sort_by='';
 }
 if(categ=='service') range=200;
 var parameters = "categ="+arg1+"&subcateg="+subcateg+"&keywords="+keyword+"&q="+arg4+"&page="+arg5+"&range="+range+"&sort="+sort+"&fcity="+fcity+"&fstate="+fstate;

 var url="http://www.etownguide.com/getattributes.php?"+parameters;
//prompt("The Message :", url);
 if (window.ActiveXObject) {
	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async=false;
	xmlDoc.load(url);
	getXML();
 } else if (document.implementation && document.implementation.createDocument) {
	xmlDoc=document.implementation.createDocument("","",null);
	xmlDoc.load(url);
	xmlDoc.onload=getXML;
 } else alert('Your browser cannot handle this script');
 }

function getXML() {
 var l,research,categs,categs_nr,categs_hrefs,categ_title,scategs,categ_value,domain,stitle,links,order_links;
 x=xmlDoc.documentElement.childNodes;
 if(categ=='real_estate') s_title='Real Estate';
 if(categ=='cars') s_title='Car Rentals';
 if(categ=='service') s_title='Sevices';
 if(categ=='rentals') s_title='Rentals';
 if(categ=='jobs') s_title='Jobs';
 if(categ=='vacation_rentals') s_title='Vacation Rentals';
 research="<div class='wend'></div><a href='javascript:resetSearch()' >Reset search</a>";
 research+="<form name='f' onsubmit='return Search(this)' action='' class='sform'>";
  research+="<table> <tr><td width='25%'>";
// if(categ!='rentals'){
research+="<div class='title'><b>Change Distace:</b></div>"
research+="</td>" ;
research+="<td> <select name='range' id='rangesel' onchange='changeRange()' class='inpt'>";
research+="<option value='city'>City</option>"
for (var i=0; (i < ranges.length); i++) {
     research+="<option value='"+ranges[i]+"' ";
     if(ranges[i]==range){
          research+= "selected";
     }
     research+=">"+ranges[i]+" miles</option>";
}
research+="</select>";
research+="</td> </tr>";
// }
 research+="<tr> <td width='25%'>" ;
 research+="<div class='title'><b>Change City:</b></div>";
 research+="</td> " ;
 research+="<td width='15%' align='left'>";
 research+="<input type='text' name='fcity' class='inpt' value='"+fcity+"'>";
 research+="</td> <td width='23%'>";
 research+="<b>Change State: </b></td><td> <select name='fstate' class='inpt' value=''>";
 research+="<option value=''>Select one</option>";
 for (var i=0; (i < states.length); i++) {
     research+="<option value='"+abbr[i]+"' ";
     if(abbr[i]==fstate){
        research+= "selected";
     } 
     research+=">"+states[i]+"</option>";
 }
 research+="</select>";
 research+="</td><td align='left'><input type='submit' value='search' style='float:left' class='button'>";
 research+="</td> </tr>";
 research+="<tr> <td>";
 research+="<div class='title'><b>Keywords: </b></div>";
 research+="</td>";
 research+="<td> <input name='keywords' type='text'  value='"+removeCommas(keyword)+"' class='inpt' /><div class='wend'></div>";
 research+="</td><td width='20%' align='left'><input type='submit' value='search' style='float:left' class='button'>";
 research+="</td> </tr></table>";
// if(categ=='jobs'){
//	 research+="<div class='title'>Search Other Jobs</div>";
//	 research+="<div class='is'>";
//	 research+="Keyword: <input type='text' name='njob' class='inpt' value=''><div class='wend'></div>";
//	 research+="<input type='submit' value='search' style='float:right' class='button' >";
//	 research+="</div>";
// }

research+="</form>"

 links ="";
 for(i=0;i<x.length;i++){
	links+="<div class='wend'></div>";
	if(x[i].nodeName=='entry'){
		categs=x[i].childNodes;
		for(c=0;c<categs.length;c++){
			if(categs[c].nodeName=='title') {
				categ_title=categs[c].firstChild.nodeValue
			       	if(categ_title=='Price'||categ_title=='Category'||categ_title=='Year Built'||categ_title=='Property type'||categ_title=='Make'||categ_title=='Model'||categ_title=='Activities'||categ_title=='Location'||categ_title=='Destination'||categ_title=='Bedrooms'|| categ_title=='Bathrooms'|| categ_title=='Lot Size'||categ_title=='Square Footage' || categ_title=='Salary' || categ_title=='Region'){
					links+="<B><div class='title'>"+categ_title+"<hr></div></B> "

				}
			}
			if(categs[c].nodeName=='v:attribute'){
				if(categ_title=='Price'||categ_title=='Category'||categ_title=='Year Built'||categ_title=='Property type'||categ_title=='Make'||categ_title=='Model'||categ_title=='Activities'||categ_title=='Location'||categ_title=='Destination' || categ_title=='Bedrooms'|| categ_title=='Bathrooms'|| categ_title=='Lot Size'||categ_title=='Square Footage' || categ_title=='Salary' || categ_title=='Region'){
					scategs=categs[c].childNodes;
					for(sc=0;sc<scategs.length;sc++){
						if(scategs[sc].nodeName=='v:value'){
							categ_value=scategs[sc].firstChild.nodeValue;
							if(categ_title=='Category') {
								categ_values=categ_value.split("/")
                                                                categ_value=categ_values[1];
							}
							links+="<a href='";
                                                        if(categ_title=='Category')links+="javascript:changeSubcategory(\""+categ_value+"\")"
							if(categ_title=='Property type'||categ_title=='Activities')links+="javascript:changePropertyType(\""+scategs[sc].getAttribute('id')+"\")"
							if(categ_title=='Price') links+="javascript:changePrice(\""+scategs[sc].getAttribute('id')+"\")";
							if(categ_title=='Year Built') links+="javascript:changeYear(\""+scategs[sc].getAttribute('id')+"\")";
							if(categ_title=='Location') links+="javascript:changeLocation(\""+categ_value+"\")";
							if(categ_title=='Destination') links+="javascript:changeLocation2(\""+categ_value+"\")";
							if(categ_title=='Make') links+="javascript:changeMake(\""+scategs[sc].getAttribute('id')+"\")";
							if(categ_title=='Model') links+="javascript:changeModel(\""+scategs[sc].getAttribute('id')+"\")";
                                                                                          if(categ_title=='Bedrooms') links+="javascript:changeToBedRoom(\""+scategs[sc].getAttribute('id')+"\")";
                                                                                          if(categ_title=='Bathrooms') links+="javascript:changeToBathRoom(\""+scategs[sc].getAttribute('id')+"\")";
                                                                                          if(categ_title=='Lot Size') links+="javascript:changeToLotsize(\""+scategs[sc].getAttribute('id')+"\")";
                                                                                          if(categ_title=='Square Footage') links+="javascript:changeToSquareFootage(\""+scategs[sc].getAttribute('id')+"\")";
							if(categ_title=='Salary') links+="javascript:changeSalary(\""+scategs[sc].getAttribute('id')+"\")";
							if(categ_title=='Region') links+="javascript:changeRegion(\""+scategs[sc].getAttribute('id')+"\")";
                                                                                          links+="'>"+categ_value+"&nbsp <span class='grey'>("+scategs[sc].getAttribute('count')+")</span></a><br>";

						}
					}                                  
				}
			}
		}
		links+="<br/>"
	}
 }
 document.getElementById("research").innerHTML=research;
 document.getElementById("links").innerHTML=links;
 loadListing();
}

function loadSortingLinks(){
	
	order_links="";
	order_links+="<table width='100%'><tr><td width='17%' align='left'><div class='title'><b>Sorted by:</b></div></td><td align='left'>";
	if(bestmatch==1){
		order_links+="Best match | " ;
	}else{	
		order_links+="<a href='javascript:matchAll()'>Best match</a> | " ;		
	}
	order_links+="<a href='javascript:changeSort(\"Distance\")'><img src='http://www.etownguide.com/img/none.gif' border='0' width='10px' id='imgdistance'>Distance</a> | " ;
	
	order_links+="<a href='javascript:changeSort(\"Date\")'><img src='http://www.etownguide.com/img/none.gif' border='0' width='10px' id='imgdate'>Date</a> | " ;
	
	if(categ=='jobs'){
		order_links+="<a href='javascript:changeSort(\"Salary\")'><img src='http://www.etownguide.com/img/none.gif' border='0' width='10px' id='imgprice'>Salary</a>";
    		order_links+="<img src='http://www.etownguide.com/img/none.gif'  border='0' width='10px' id='imgmileage'>" ;
  		
	}else if(categ=='vacation_rentals'){
    		order_links+="<a href='javascript:changeSort(\"NightlyRate\")'><img src='http://www.etownguide.com/img/none.gif' border='0' width='10px' id='imgprice'>NightlyRate</a>";
    		order_links+="<img src='http://www.etownguide.com/img/none.gif'  border='0' width='10px' id='imgmileage'>" ;
	}else{
    		order_links+="<a href='javascript:changeSort(\"Price\")'><img src='http://www.etownguide.com/img/none.gif' border='0' width='10px' id='imgprice'>Price</a>";

	}
	
	if(categ =='cars'){
		 	order_links+=" | ";
       		   	order_links+="<a href='javascript:changeSort(\"Mileage\")'><img src='http://www.etownguide.com/img/none.gif' border='0' width='10px' id='imgmileage'>Mileage</a>" ;
  		}else{
       		   	order_links+="<img src='http://www.etownguide.com/img/none.gif' border='0' width='10px' id='imgmileage'>" ;
  		}
	order_links+="</td></tr><table>";
	document.getElementById("reorder").innerHTML=order_links;
	changeSortImg();
}

function changeSortImg(){
	
             if(bestmatch!=1){
		if(sort==3) {
			document.getElementById("imgdistance").src="http://www.etownguide.com/img/up.gif";
		} else if(sort==4) {
			document.getElementById("imgdistance").src="http://www.etownguide.com/img/down.gif";
		} else if(sort==1) {
			document.getElementById("imgprice").src="http://www.etownguide.com/img/up.gif";
		} else if(sort==2) {
			document.getElementById("imgprice").src="http://www.etownguide.com/img/down.gif";
		} else if(sort==7) {
			document.getElementById("imgdate").src="http://www.etownguide.com/img/up.gif";
		}else if(sort==8) {
			document.getElementById("imgdate").src="http://www.etownguide.com/img/down.gif";
		}else if(sort==5) {
			document.getElementById("imgmileage").src="http://www.etownguide.com/img/up.gif";
		}else if(sort==6) {
			document.getElementById("imgmileage").src="http://www.etownguide.com/img/down.gif";
		} 
	}else{
		document.getElementById("imgdistance").src="http://www.etownguide.com/img/none.gif";
   		document.getElementById("imgprice").src="http://www.etownguide.com/img/none.gif";
   		document.getElementById("imgdate").src="http://www.etownguide.com/img/none.gif";
   		document.getElementById("imgmileage").src="http://www.etownguide.com/img/none.gif";
	}  
}

function loadListing(){
	
            	loadSortingLinks();
	if(page==1){
		document.getElementById("listings").innerHTML="<span style='padding-left:10px;'>loading info...Please wait</span>";
		document.getElementById("pages").innerHTML="";
		document.getElementById("pages2").innerHTML="";		
	}
	             
   	var url2;
	if(bestmatch == 1){
               	bestmatch = 0;
		document.getElementById("imgmileage").src="http://www.etownguide.com/img/none.gif";
	 	url2="http://www.etownguide.com/getlistings.php?categ="+categ+"&subcateg="+subcateg+"&zip="+zip+
		  	"&keywords="+keyword+"&q="+q+"&page="+page+"&property_type="+property_type+
		  	"&price="+price+"&year_built="+year_built+"&range="+range+"&fcity="+fcity+"&fstate="+fstate+
		  	"&make="+make+"&model="+model+"&square_footage="+square_footage+"&lot_size="+lot_size+
		  	"&bathrooms="+bathrooms+"&bedrooms="+bedrooms+"&salary="+salary+"&region="+escape(region);
	 	sort=3;
		  
 	}else{
                 
   		url2="http://www.etownguide.com/getlistings.php?categ="+categ+"&subcateg="+subcateg+"&zip="+zip+
		     "&keywords="+keyword+"&q="+q+"&page="+page+"&sort="+sort+"&property_type="+property_type+
		     "&price="+price+"&year_built="+year_built+"&range="+range+"&fcity="+fcity+"&fstate="+fstate+
	   	     "&make="+make+"&model="+model+"&square_footage="+square_footage+"&lot_size="+lot_size+
		     "&bathrooms="+bathrooms+"&bedrooms="+bedrooms+"&salary="+salary+"&region="+escape(region);
 	}
	//prompt("The Message for SMS:", url2);
        	//document.getElementById("trace").innerHTML="<p style='width:300px;font-size:10px;'>"+url2+"</p>";
	 if (window.ActiveXObject) {	
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.load(url2);
		getXML2();
	 } else if (document.implementation && document.implementation.createDocument) {
		xmlDoc=document.implementation.createDocument("","",null);
		xmlDoc.load(url2);
		xmlDoc.onload=getXML2;
 	} else alert('Your browser cannot handle this script');
	
	
}


function getXML2() {
 var l,pages_cnt,pages,fpos,lpos,lpage,nextpage,prevpage,location,c_entry,list_cnt,published,item_date,title,price,content,item_link_type,item_link,cc,cd,itemhasimage,nl,content_item,description,domain,item_city,item_zip,item_title,itemimg,item_make,item_model,item_mileage,item_year,item_vin,item_dupcount,item_color,item_engine,item_transmision,item_fuel,item_amenities,item_activities,item_details,statei,item_descr,item_salary,item_company,item_experience,item_education,item_skills,has_img;
 item_title="";list_cnt="";page=page*1;nextpage=page+1;prevpage=page-1;pages_cnt="";item_date="";item_amenities="";item_activities="";item_salary="";item_company="";item_experience="";item_education="";item_skills="";
 item_make="";item_model="";item_mileage="";item_year="";item_vin="";item_dupcount="";item_color="";item_engine="";item_transmision="";item_fuel="";statei="";item_descr="";
 item_details="";
 if(sort == 5 ){
	sort_by = 'Mileage';
 }
 search_opt_cnt="<br><b>Search Options:</b>"+"&nbsp;<br> <b>Category:</b>&nbsp; "+categ;
 if(subcateg!="")search_opt_cnt+=","+subcateg;
 search_opt_cnt+="<br><b>Keywords:</b>&nbsp; "+removeCommas(keyword);
 if(property_type!="")search_opt_cnt+="<br><b>Property Type:</b>&nbsp; "+property_type;
 if(year_built!="") search_opt_cnt+="<br><b>Year Built:</b>&nbsp; "+year_built;
 if(range!="") search_opt_cnt+="<br><b>Distance:</b>&nbsp; "+range;
 if(fcity!="") search_opt_cnt+="<br><b>City:</b>&nbsp; "+fcity+", &nbsp; "+fstate;
 if(sort!="") search_opt_cnt+="<br><b>Sorted by:</b>&nbsp; "+sort_by;
 search_opt_cnt=search_opt_cnt.replace ("_", " ");
 search_opt_cnt+="";
 document.getElementById("search_opt").innerHTML=search_opt_cnt;
 x2=xmlDoc.documentElement.childNodes;
 nl=0;
 for(n=0;n<x2.length;n++){
	if(x2[n].nodeName=='o:totalResults'){
		total_items=x2[n].firstChild.nodeValue;

		pages=total_items/10;
		lpage=pages-1;

		if(page>20) {
			fpos=page-10;
	                lpos=page+10;
		}else {
	                fpos=0;
	                lpos=21;
		}
		if(page>1) pages_cnt+=" <a href='javascript:changePage(\""+prevpage+"\")'>Prev</a>";
		for(p=0;p<pages;p++){
			if(p>fpos && p<lpos){
	                        if(p==page){
	                            pages_cnt+=" <b>"+p+"</b> ";
	                        } else {
	                            pages_cnt+=" <a href='javascript:changePage(\""+p+"\")' >"+p+"</a> ";
	                        }
			}

		}
		if(page<lpage) pages_cnt+=" <a href='javascript:changePage(\""+nextpage+"\")'>Next</a>";
 		document.getElementById("pages").innerHTML=pages_cnt;
 		document.getElementById("pages2").innerHTML=pages_cnt;
	}
	if(x2[n].nodeName=='entry'){
		content_item="";
                		location="";
		itemimg='';
		has_img='';
		c_entry=x2[n].childNodes;
		for(entryl=0;entryl<c_entry.length;entryl++){
			if(c_entry[entryl].nodeName=="title") title=c_entry[entryl].firstChild.nodeValue;
			if(c_entry[entryl].nodeName=="v:image_url") {
				//itemimg=c_entry[entryl].firstChild.nodeValue;
				item_imgs=c_entry[entryl].childNodes;
				itemimg=c_entry[entryl].childNodes.length;
                                o=c_entry[entryl].childNodes[0];
				if (o!=undefined) {
					itemimg=o.nodeValue;
				}
			}
			if(c_entry[entryl].nodeName=="v:hasimage") {
				//itemimg=c_entry[entryl].firstChild.nodeValue;
				has_img=c_entry[entryl].childNodes.length;
                                			o=c_entry[entryl].childNodes[0];
				if (o!=undefined) {
					has_img=o.nodeValue;
				}
			}
			if(c_entry[entryl].nodeName=="link"){
				item_link_type=c_entry[entryl].getAttribute('rel');
				if(item_link_type=='via') item_link=c_entry[entryl].getAttribute('href');
			}
			if(c_entry[entryl].nodeName=="published") {
				published=c_entry[entryl].firstChild.nodeValue;
				published=published.split("T")
				itemd=published[0];
				year=itemd.substring(0,4)
				month=itemd.substring(5,7)
				if(month[0]==0)month=month[1];
				month--;
				day=itemd.substring(8,10);
				if(day[1]==0)day=day[1];
				item_date=Date.UTC(year,month,day);
				item_date=today-item_date;
				item_date=item_date/one_day;
				item_date=Math.floor(item_date);
				if(item_date==0)item_date="today"; else item_date+=" days ago";
			}
                	if(categ!='vacation_rentals'&&c_entry[entryl].nodeName=="v:price") {
				prices=""
				price=c_entry[entryl].getAttribute('value');
                                pos3=price.length;
				pos2=pos3-3;
				pos1=pos3-6;
				prices=price.substring(0,pos1)
				if(pos3>6) prices+=","
				prices+=price.substring(pos1,pos2)
				if(pos3>3)prices+=","
				prices+=price.substring(pos2,pos3);
				if(prices.length>1)prices="<b>$"+prices+"</b>";
			}
                	if(categ!='cars') if(c_entry[entryl].nodeName=="v:description") description=c_entry[entryl].firstChild.nodeValue;
			if(c_entry[entryl].nodeName=="v:location"){
				cc=c_entry[entryl].childNodes;
				for(cd=0;cd<cc.length;cd++){
    					if(cc[cd].nodeName=="v:zip") {
						o=cc[cd].childNodes[0];
						if (o!=undefined) location=o.nodeValue;
					}
    					if(cc[cd].nodeName=="v:city") {
						cityi='';
						o=cc[cd].childNodes[0];
						if (o!=undefined) {
							if (location!='') location+=', ';
							cityi+=o.nodeValue;
						}
					}
    					if(cc[cd].nodeName=="v:state") {
						statei='';
						o=cc[cd].childNodes[0];
						if (o!=undefined) {
							statei+=o.nodeValue;
						}
					}
    					if(categ!='cars')if(cc[cd].nodeName=="v:distance") {
						o=cc[cd].childNodes[0];
						if (o!=undefined) {
							distance=o.nodeValue;
						}
					}
				}
			}
			if(categ=='cars'){
				description='';
	                        if(c_entry[entryl].nodeName=="v:make") item_make=c_entry[entryl].firstChild.nodeValue;
	                         if(c_entry[entryl].nodeName=="v:model"){ 
			item_model="-";
			o=c_entry[entryl].childNodes[0];
			if (o!=undefined){
				item_model=o.nodeValue;
			}
		      }
	                        if(c_entry[entryl].nodeName=="v:mileage") {
						item_mileage="-";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_mileage=o.nodeValue;
						}
					}
	                        if(c_entry[entryl].nodeName=="v:year")  {
						item_year="-";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_year=o.nodeValue;
						}
					}
	                        //if(c_entry[entryl].nodeName=="v:vin") item_vin=c_entry[entryl].firstChild.nodeValue;
	                        if(c_entry[entryl].nodeName=="v:dupcount") item_dupcount=c_entry[entryl].firstChild.nodeValue;
	                        if(c_entry[entryl].nodeName=="v:color") item_color=c_entry[entryl].firstChild.nodeValue;
	                        if(c_entry[entryl].nodeName=="v:engine") {
						item_engine="-";
					item_engine=c_entry[entryl].firstChild.nodeValue;
				}
	                        if(c_entry[entryl].nodeName=="v:transmission")  {
						item_transmision="-";
						item_transmision=c_entry[entryl].firstChild.nodeValue;
					}
	                        if(c_entry[entryl].nodeName=="v:details") {
					item_details=" ";
					item_details=c_entry[entryl].firstChild.nodeValue;
				}


			}
			if(categ=='vacation_rentals'){
	                        if(c_entry[entryl].nodeName=="v:amenities") {
					item_amenities=" ";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_amenities=o.nodeValue;
						}
				}
	                        if(c_entry[entryl].nodeName=="v:activities") {
					item_activities=" ";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_activities=o.nodeValue;
						}
				}
	                        if(c_entry[entryl].nodeName=="v:proptype") {
					item_proptype=" ";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_proptype=o.nodeValue;
						}
				}
	                        if(c_entry[entryl].nodeName=="v:bedrooms") {
					item_bedrooms="-";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_bedrooms=o.nodeValue;
						}
				}
	                        if(c_entry[entryl].nodeName=="v:bathrooms") {
					item_bathrooms="-";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_bathrooms=o.nodeValue;
						}
				}
	                        if(c_entry[entryl].nodeName=="v:sleeps") {
					item_sleeps="-";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_sleeps=o.nodeValue;
						}
				}
	                        if(c_entry[entryl].nodeName=="v:ratelow") {
					item_lowrate="-";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_lowrate=o.nodeValue;
						}
				}
	                        if(c_entry[entryl].nodeName=="v:ratehigh") {
					item_highrate="-";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_highrate=o.nodeValue;
						}
				}
	                        if(c_entry[entryl].nodeName=="v:description") {
					item_descr="";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_descr=o.nodeValue;
						}
				}

			}
			if(categ=='jobs'){
	                        if(c_entry[entryl].nodeName=="v:details") {
					item_details="";
					item_details=c_entry[entryl].firstChild.nodeValue;
				}
	                        if(c_entry[entryl].nodeName=="v:salary") {
					item_salary="";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
						item_salary=o.nodeValue;
						}
					//item_salary=c_entry[entryl].firstChild.nodeValue;
				}
	                        if(c_entry[entryl].nodeName=="v:company") {
					item_company="";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
						item_company=o.nodeValue;
						}
				}
	                        if(c_entry[entryl].nodeName=="v:experience") {
					item_experience="";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_experience=o.nodeValue;
							if(item_experience=='1') item_experience+=" year"; else item_experience+=" years";
						}
				}
	                        if(c_entry[entryl].nodeName=="v:education") {
					item_education="";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_education=o.nodeValue;
						}
				}
	                        if(c_entry[entryl].nodeName=="v:skills") {
					item_skills="";
						o=c_entry[entryl].childNodes[0];
						if (o!=undefined) {
							item_skills=o.nodeValue;
						}
				}


			}


			if(c_entry[entryl].nodeName=="v:domain_name") domain=c_entry[entryl].firstChild.nodeValue;
		}
		nl++;
		list_cnt+="<div class='item'><br/>";
		list_cnt+="<table ><tr><td>";

		if(categ!='jobs')list_cnt+="<div class='leftimage'>";
		list_cnt+="<a href='"+item_link+"' target='_blank'></a>";		
		if(has_img == 'yes'){
			list_cnt+="<td valign='top'><a href='"+item_link+"' target='_blank'>";
			list_cnt+="<img src='"+itemimg+"' border='0' width='128px'></a></td>";
		}
		list_cnt+="<td valign='top'><h4><a href='"+item_link+"' target='_blank'>"+ title +"</a></h4>" ;
		list_cnt+="<a href='"+item_link+"' target='_blank'>View Listing</a>&nbsp;";
		if(categ!='jobs')list_cnt+="</div><div class='item_details'>";
		list_cnt+="<b>Published</b> "+item_date+" on "+"<a href='http://"+domain+"' target='_blank' style='display:inline !important;color:#000000; margin-left:0px;float:left'>"+domain+"</a><br>"
		if(categ!='vacation_rentals'&&categ!='jobs')if(prices!='')list_cnt+="<br><br><b>Price: </b>"+prices +"<br>"
	       	if(categ=='vacation_rentals'||categ=='jobs')list_cnt+="<br>"

 	       	if(categ=='vacation_rentals')list_cnt+="<br><b>Distance: </b>"+distance+"&nbsp;";
	       	list_cnt+="<b>City:</b>&nbsp;"+cityi+",&nbsp;"+statei+"  ";
		if(categ=='cars'){
			description=" ";
			list_cnt+="<b>Model:</b>&nbsp;"+convertUpper(item_make)+","+convertUpper(item_model);
			list_cnt+="<br><b>Details:</b>";
			if(item_mileage != ''){
			     list_cnt+="<br><i>Mileage: </i>&nbsp; "+item_mileage;
			}
			if(item_year != ''){
				list_cnt+="&nbsp; &nbsp; <i>Year: </i>"+item_year;
			}
			if(item_vin != ''){
				list_cnt+="&nbsp; &nbsp; <i>VIN: </i>&nbsp; "+item_vin;
			}
			if(item_dupcount != ''){
				list_cnt+="&nbsp; &nbsp; <i>Dupcount:</i>&nbsp; "+item_dupcount;
			}
			if(item_color != ''){
				list_cnt+="<br><i>Color:</i>&nbsp; "+item_color;
			}
			if(item_engine != ''){
				list_cnt+="&nbsp; &nbsp; <i>Engine:</i>&nbsp; "+item_engine;
			}
			if(item_transmision != ''){
				list_cnt+="<br><i>Transmision:</i>&nbsp; "+item_transmision;
			}
			if(item_details != ''){
				list_cnt+="<br><i>Detail:</i>&nbsp; "+item_details;	
			}		
		}
		if(categ=='vacation_rentals'){
		       	list_cnt+="<br><b>Type:</b>&nbsp;"+item_proptype;
			list_cnt+="<br><b>Price:</b>&nbsp;"+"<i>Low Rate</i>&nbsp; "+item_lowrate+"&nbsp; &nbsp;<i>High Rate</i>&nbsp; "+item_highrate;
		       	list_cnt+="<br><b>Details:</b>&nbsp;"+"<i>Bedrooms</i>&nbsp; "+item_bedrooms+"&nbsp; &nbsp;<i>Bathrooms</i>&nbsp; "+item_sleeps+"&nbsp &nbsp;<i>Sleeps</i>&nbsp; "+item_sleeps;
		       	list_cnt+="<br><br><b>Amenities:</b>&nbsp;"+item_amenities;
		       	list_cnt+="<br><b>Activities:</b>&nbsp;"+item_activities;

		}
		if(categ=='vacation_rentals') {
				if(item_descr!='undefined'&&item_descr!=''&&item_descr!=null)description=item_descr; else description=" - ";
		}
		if(categ=='jobs') {
				if(item_details!='undefined'&&item_details!=''&&item_details!=null)description=item_details; else description=" - ";
				if(item_salary != ''){
					list_cnt+="<br><b>Salary:</b>&nbsp;"+item_salary;
				}
				if(item_experience != ''){
					list_cnt+="<br><b>Company:</b>&nbsp;"+item_company; 
				}
				if(item_experience != ''){
					list_cnt+="<br><b>Experience:</b>&nbsp;"+item_experience;
				}
				if(item_education != ''){
					list_cnt+="<br><b>Education:</b>&nbsp;"+item_education;
				}
				if(item_skills != ''){
					list_cnt+="<br><b>Skills:</b>&nbsp;"+item_skills;
				}

		}

		if(categ!='cars') list_cnt+="<br><b>Description:</b>&nbsp;"+description;
		if(categ!='jobs')list_cnt+="</div>";
		list_cnt+="<div class='w_end2'></div></div>";
                list_cnt+="</td></tr></table><hr>";    
	}

 }
	document.getElementById("listings").innerHTML=list_cnt;
	if(nl==0) document.getElementById("listings").innerHTML="No results found.";
}

function changePage(arg){
	page=arg;
	loadListing();
}

function changeSubcategory(arg){
	subcateg=arg;
	page=1;
	loadListing()
}

function changePropertyType(arg){
	property_type=arg;
	page=1;
	loadListing();
}

function changePrice(arg){
	price=arg;
	if(price=='unknown')price="";
	page=1;
	loadListing();
}

function changeModel(arg){
	model=arg;
	if(model=='unknown')model="";
	page=1;
	loadListing();
}

function changeMake(arg){
	make=arg;
	if(make=='unknown')make="";
	page=1;
	loadListing();
}

function changeSalary(arg){
	salary=arg;
	if(salary=='unknown')salary="";
	page=1;
	loadListing();
}

function changeYear(arg){
	year_built=arg;
	page=1;
	loadListing();
}

function changeToBedRoom(arg){
   bedrooms=arg;
   page=1;
   loadListing();
}

function changeToBathRoom(arg){
   bathrooms=arg;
   page=1;
   loadListing();
}

function changeRegion(arg){
   region=arg;
   page=1;
   loadListing();
}

function changeToLotsize(arg){
   lot_size=arg;
   page=1;
   loadListing();
}

function changeToSquareFootage(arg){
   square_footage=arg;
   page=1;
   loadListing();
}

function matchAll(){
   bestmatch = 1; 
   loadListing();
}

function changeSort(arg){
	sort_by=arg;

	if(arg=='Distance') {
		if(sort==3) {
			sort=4;
		} else {
			sort=3;
		}
	} else  if(arg=='Price' || arg=='NightlyRate' || arg == 'Salary'){
		if(sort==1) {
			sort=2;
		}else {
			sort=1;
		}
		document.getElementById("imgdistance").src="http://www.etownguide.com/img/none.gif";
		document.getElementById("imgdate").src="http://www.etownguide.com/img/none.gif";
		document.getElementById("imgmileage").src="http://www.etownguide.com/img/none.gif";
	} else if(arg == 'Date') {
		if(sort==7) {
			sort=8;
		}else {
			sort=7;
		}
		document.getElementById("imgprice").src="http://www.etownguide.com/img/none.gif";
		document.getElementById("imgdistance").src="http://www.etownguide.com/img/none.gif";
		document.getElementById("imgmileage").src="http://www.etownguide.com/img/none.gif";
	} else {
		if(sort==5) {
			sort=6;
		}else {
			sort=5;
		}
		document.getElementById("imgprice").src="http://www.etownguide.com/img/none.gif";
		document.getElementById("imgdistance").src="http://www.etownguide.com/img/none.gif";
		document.getElementById("imgdate").src="http://www.etownguide.com/img/none.gif";
	}
	
	page=1;        
	loadListing();        
        
}

function resetSearch(){
	document.getElementById("search_opt").innerHTML="";
	subcateg="";
	page=1;
	sort=3;
	property_type="";
	price="";
	year_built="";
	zip=ozip;
	fcity=ocity;
	fstate=ostate;
	fzip='';
	loadXML(categ,subcateg,'','1','3',ocity,ostate,'');

}

function changeRange(){
	range=document.f.range.value;
	page=1;
	loadListing();
}

function Search(arg){
	var njobs;
	njobs="";
     	//if(categ=='jobs') njobs=document.f.njob.value;
	fstate=document.f.fstate.value;
	fcity=document.f.fcity.value;
	fkeyword=document.f.keywords.value;
	fcity=convertUpper(fcity);
	fcity=trim(fcity);
	fkeyword=trim(fkeyword);
	if(fcity!=''&&fstate=='') alert('State is required');
	if(fcity=="")fcity=ocity;
        	if(fstate=="")fstate=ostate;
	document.f.fcity.value =fcity;
	//if(categ=='jobs') loadXML(categ,subcateg,njobs,'1',sort,fcity,fstate,fkeyword); else loadXML(categ,subcateg,'','1',sort,fcity,fstate,fkeyword);
	 loadXML(categ,subcateg,'','1',sort,fcity,fstate,fkeyword);
	return false;
}

function changeLocation(arg){
	var loc_values,lcity,lstate,lzip;
        lcity='';lstate='';lzip='';
	loc_values=arg.split(",");
        fcity=loc_values[0];
	fcity=trim(fcity)
	fstate=loc_values[1];
	fstate=trim(fstate);
	loadXML(categ,subcateg,'','1',sort,fcity,fstate,keyword);
}
function changeLocation2(arg){
	var loc_values,lcity,lstate,lzip,lcityv;
        lcity='';lstate='';lzip='';
	loc_values=arg.split("-");
        lcity=loc_values[1];
	lcityv=lcity.split("Area");
	fcity=lcityv[0];
	fcity=trim(fcity);
	fstate=loc_values[0];
	fstate=trim(fstate);
	loadListing();
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function convertUpper(str) {
        return str.toLowerCase().replace(/\b[a-z]/g, cnvrt);
        function cnvrt() {
            return arguments[0].toUpperCase();
        }
}

function removeSpaces(str){
	var key = '';
	var temp = new Array();
	temp = str.split(' ');
	for (var i=0; (i < temp.length); i++) {
     		if(i == temp.length-1){
			key+=temp[i];
     		}else{
			key+=temp[i]+',';
     		}
	}
	return key;
}

function replaceCharacter(str,matchWith,replaceWith){
	var key = '';
	var temp = new Array();
	temp = str.split(matchWith);
	for (var i=0; (i < temp.length); i++) {
     		if(i == temp.length-1){
			key+=temp[i];
     		}else{
			key+=temp[i]+replaceWith;
     		}
	}
	return key;
}

function removeCommas(str){
	var key = '';
	var temp = new Array();
	temp = str.split(',');
	for (var i=0; (i < temp.length); i++) {
     		if(i == temp.length-1){
			key+=temp[i];
     		}else{
			key+=temp[i]+' ';
     		}
	}
	return key;
}


        var contents;
	function loadHTML(urlParam) { 
          var url = urlParam;  
	  var callback = processResponse;
	  execute(callback, url);
          document.getElementById("pages").innerHTML = "loading.....";    
	}
	
	function execute(callback, url) {
	  // branch for native XMLHttpRequest object
	  if (typeof XMLHttpRequest != "undefined") {
		    req = new XMLHttpRequest();
	  } else if (window.ActiveXObject) {
		     req = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	   if (req) {	
	      req.onreadystatechange = callback;
	      req.open("GET", "http://www.etownguide.com/getContent.jsp?url="+url, true);
	      req.send(null);
	    }
	}
	
		function processResponse() {
	  // only if req shows "loaded"
	  if (req.readyState == 4) {
	    if (req.status == 200) {
	        allText = req.responseText; // get conts from site
	          var searchString = "<a href=\"";
              var foundPosition = allText.indexOf(searchString);
              var match = "pediapro" ; 	
              var copy="";
                            while (foundPosition != -1){
                                copy += allText.substr(0,foundPosition + searchString.length);
                                allText = allText.substr(foundPosition+searchString.length,allText.length)
                                found = allText.match("\"");
                                var endPosition = allText.indexOf(found);
                                var suburl = allText.substr(0,endPosition);
                                if(suburl.match(match)){
                                  copy += "javascript:loadHTML('" + suburl + "')";
                                  allText = allText.replace(suburl, "");
                                }
                                if(suburl.charAt(0) == '/'){
                                  copy += "javascript:loadHTML('http://www.pediapro.com" + suburl + "')";
                                  allText = allText.replace(suburl, "");
                                }
                               	foundPosition = allText.indexOf( searchString );
			      }  

                            
                           copy += allText;
                           copy = copy.replace('<form action="/etownguide/index.php/Special:Search" id="searchform">','<form name="searchform" id="searchform" method="post" onSubmit="return callLoadHTML()">');
                           //copy = copy.replace('</form>',''); 
                           //copy = copy.replace('<input name="go" id="searchGoButton" value="Search" type="submit">','<input name="go" id="searchGoButton" value="Search" type="button" onclick="callLoadHTML();">'); 			   
                           document.getElementById("pages").innerHTML = ""; 
	                   document.getElementById("pages").innerHTML = copy;
	    } else {
               
	      alert("There was a problem while retrieving the data:\n Refresh the page and try again" + req.statusText);
	    }
	  }
  }	

  function callLoadHTML(){        
    var element = document.getElementById("searchInput");    
    var url="http://www.pediapro.com/etownguide/index.php/Special:Search?search="+replaceCharacter(element.value,' ','_');
    loadHTML(url);    
    return false;
  }

// for flicker

  function loadFlicker(urlParam) {
	  
          var url = urlParam;  
	  var callbackFlicker = processResponseFlicker;
	  executeFlicker(callbackFlicker, url);
	}
	
	function executeFlicker(callbackFlicker, url) {
	  // branch for native XMLHttpRequest object
	  if (typeof XMLHttpRequest != "undefined") {
		    req = new XMLHttpRequest();
	  } else if (window.ActiveXObject) {
		     req = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	   if (req) {	
	      req.onreadystatechange = callbackFlicker;
	      req.open("GET", "http://www.etownguide.com/getContent.jsp?url="+url, true);
	      req.send(null);
	    }
	}
	
	function processResponseFlicker() {
	  // only if req shows "loaded"
	  if (req.readyState == 4) {
	    if (req.status == 200) {
	        allText = req.responseText; // get conts from site
                document.getElementById("flicker").innerHTML = allText;
	    } else {
	      alert("There was a problem while retrieving the data:\n Refresh the page and try again" + req.statusText);
	    }
	  }
       }
         
     //=========================Ebay=====================
 function loadEbay(urlParam) {
          var url = urlParam;
	  var call = process;
	  callUrl(call, url);
          document.getElementById("ebaypages").innerHTML = "loading.....";
	}

	function callUrl(call, url) {
	  if (typeof XMLHttpRequest != "undefined") {
		    req = new XMLHttpRequest();
	  } else if (window.ActiveXObject) {
		     req = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	   if (req) {	
	      req.onreadystatechange = call;
	      req.open("GET", "http://www.etownguide.com/getContent.jsp?url="+url, true);
	      req.send(null);
	    }
	}
	
	function process() {

	  if (req.readyState == 4) {
	    if (req.status == 200) {
	        allText = req.responseText; 
	        var finalData = searchAndReplace(allText);
	          document.getElementById('ebaypages').innerHTML = finalData;
                                                  
	    } else {

	      alert("There was a problem while retrieving the data:\n Refresh the page and try again" + req.statusText);
	    }
 	}
      }

     function searchAndReplace(allText){


        var searchKey = "<a href=\"";
       var foundPosition = allText.indexOf(searchKey);
       var copy="";
       var suburl ="";
       while (foundPosition != -1){
          copy += allText.substr(0,foundPosition + searchKey.length-1);
          allText = allText.substr(foundPosition+searchKey.length,allText.length)
          found = allText.match("\"");
          var endPosition = allText.indexOf(found);
           suburl = allText.substr(0,endPosition);

            var pos = suburl.indexOf('javascript');
            if(pos == -1){
                copy += "javascript:loadEbay('" + suburl + "')" ;
             }else{
                copy +=  suburl ;
             }
            suburl = allText.substr(0,endPosition+1);
            allText = allText.replace(suburl, "");
            foundPosition = allText.indexOf( searchKey );

      }
      copy += allText;
      allText =copy;
      copy="";
      var searchKey = "<a href=";
      foundPosition = allText.indexOf(searchKey);
       var s=0;
      while (foundPosition != -1){
          copy += allText.substr(0,foundPosition + searchKey.length);
          allText = allText.substr(foundPosition+searchKey.length,allText.length)
         
          
          found = allText.match(" ");
          var endPosition = allText.indexOf(found);
           suburl = allText.substr(0,endPosition);

            var pos = suburl.indexOf('javascript');
            if(pos == -1){
                copy += "javascript:loadEbay('" + suburl + "')" ;
             }else{
                copy +=  suburl ;
             }

            allText = allText.replace(suburl, "");
            foundPosition = allText.indexOf( searchKey );

      }
      copy += allText;
      allText =copy;
      copy="";
      var searchKey = "<form action=\"";
      foundPosition = allText.indexOf(searchKey);
       var s=0;
      while (foundPosition != -1){
          copy += allText.substr(0,foundPosition + searchKey.length);
          allText = allText.substr(foundPosition+searchKey.length,allText.length)

          found = allText.match("\"");
          var endPosition = allText.indexOf(found);
           suburl = allText.substr(0,endPosition);

            var pos1 = suburl.indexOf('javascript');
            if(pos1 == -1){
                copy += "javascript:loadEbay('" + suburl + "')" ;
             }else{
                copy +=  suburl ;
             }

            allText = allText.replace(suburl, "");
            foundPosition = allText.indexOf( searchKey );

      }

       copy += allText;
       var str = 'target="_blank"';
       var foundPosition = copy.indexOf(str);
        while (foundPosition != -1){
          copy = copy.replace('target="_blank"',"");
            foundPosition = copy.indexOf(str);
      }
      /* var copy1 ="";
      copy1+= copy;
      copy= copy1; */
       var changeSubmit ='<input name="searchit" value="search" type= button onclick="newSearch();">';
      var existing = '<input name="searchit" value="search" type="submit">';
       var foundPosition = copy.indexOf(existing);
       var i=1;
        while (foundPosition != -1){
          if(i==1){
          copy = copy.replace(existing,changeSubmit);
          }
            foundPosition = copy.indexOf(existing);
        }  i++;
      return copy;
  }










