//MarketListings.js  *************//
var limit=0;
var pages=0;
var previous=0;
var city;
// JavaScript Document
var Rcat;
var Rscat;
var	windowIsActive=false;
function hide_loader() {
		//	alert("asdf");
		if(document.getElementById("divx")) {
		//document.body.removeChild(document.getElementById("divx"));
		//document.body.removeChild(document.getElementById("divx1"));
		var divx=document.getElementById("divx");
		var divx1=document.getElementById("divx1")

		divx.className="divx_n";
		divx1.className="divx1_n";
		}
		}
	function show_loader() {
		//alert("ldr");
		if (document.all) {
		ht=document.body.offsetHeight;
		wt=document.body.offsetWidth;
		}else {
		ht=document.height;
		wt=document.width;
		}
		var divx=document.getElementById("divx");
		var divx1=document.getElementById("divx1")

		divx.className="divx";
		divx1.className="divx1";
		divx.style.width=wt+"px";
		divx.style.height=ht+"px";
		divx1.style.width=wt+"px";
		divx1.style.height=ht+"px";
		
	}
function show_classified(cat, scat, limit) {
	
	if(request.readyState == 4 || request.readyState == 0){
	if(limit=="")
	limit=0;

	window.scrollTo(0,0);
	name=scat;
	show_loader();
	var url="classifieds/get_list_midday.php";
	request.open("POST",url,true);
    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	request.onreadystatechange=update_recent_listings;//(category,subcategory);
	url1="category=" + escape(cat)+"&subcategory="+escape(scat)+"&limit="+ escape(limit);
	var modifiedLocation = "section:Classifieds/show_classified/"+cat+"/"+scat+"/"+limit;
	var historyData = "<p>The following location "+ "was loaded from our "+ "DHTML history: "+ modifiedLocation + "</p>";
	dhtmlHistory.add(modifiedLocation,historyData);
	request.send(url1);
	}
}
function show_resultsx(jsonData) {
	//alert(jsonData);
	search_op="";
	pages=jsonData.listings.listing[0].total;
	limit=parseInt(jsonData.listings.Limit);
	for(i=0;i<jsonData.listings.listing.length;i++ ) {
		search_op+='<div class="listing" onclick="show_detail_listing('+jsonData.listings.listing[i].clid+')" onmouseover="change_bg(this)" onmouseout="remove_bg(this)"><span class="inner_head">'+jsonData.listings.listing[i].title+'</span>';
		search_op+='<div class="float_left"><img src="'+jsonData.listings.listing[i].image+'" hspace="15" vspace="5" /></div>';
		search_op+='<div><div class="text_height20">    Model : <span class="bold_orange">'+jsonData.listings.listing[i].make+'</span><br />';
		search_op+=' Price : <span class="bold_orange">Rs. '+jsonData.listings.listing[i].price+'/-</span><br />';
		search_op+=' Year :<span class="bold_orange"> '+jsonData.listings.listing[i].year+' </span><br />';
		search_op+=' Posted under >'+jsonData.listings.listing[i].city+'>'+jsonData.listings.listing[i].category+'>'+jsonData.listings.listing[i].sub_category+' <span class="bold_orange">'+jsonData.listings.listing[i].time+' </span></div><div class="posted_by"><span class="bold_gray">Classified Posted on &nbsp;</span>';
		if(jsonData.listings.listing[i].posted_on=="" || jsonData.listings.listing[i].posted_on=="Snatchking") {
		search_op+='<img src="images/snatchking_posted.gif" />';
		}else {
		search_op+='<img src="images/midday_logo.gif" />';
		}
		search_op+='</div>';
		search_op+=' </div> </div> ';
		search_op+='<div><img src="images/spacer.gif" height="5" /></div>';
	}
search_op+='<div class="vr_listings" style="text-align:right;"><hr noshade="NOSHADE" />';
if(previous > 0 && limit < pages) {
	//document.getElementById("page_prev").style.display="block";
	search_op+='<a href="javascript:previousSearch(\''+jsonData.listings.Search+'\','+jsonData.listings.Limit+')"><img src="images/prev_but.gif" border="0" align="absbottom" /></a>';
}
search_op+='<span class="page_num">&nbsp;&nbsp;&nbsp;</span>';
if(limit<pages-1) {
	//document.getElementById("page_next").style.display="block";
	search_op+='<a href="javascript:nextSearch(\''+jsonData.listings.Search+'\','+jsonData.listings.Limit+')"><img src="images/next_but.gif" align="absbottom" /></a>';
}
search_op+='<br /><br /></div>';
	//alert(search_op);
	document.getElementById('recent_listings').innerHTML=search_op;
	hide_loader();
}
function update_recent_listings() {
	if (request.readyState == 4) {
		if (request.status == 200) {
			listings=document.getElementById('recent_listings');
			//alert(request.responseText);
			listings.innerHTML=request.responseText;
			hide_loader();
		}
	}
}
function change_bg(obj) {
	//obj.className='listing_over';
}
function remove_bg(obj) {
	//obj.className='listing';
}
function change_bg_ac(obj) {
	obj.className='listing_over_ac';
}
function remove_bg_ac(obj) {
	obj.className='listing_ac';
}
function show_detail_listing(clid,city1) {
	if(request.readyState == 4 || request.readyState == 0){
	window.scrollTo(0,0);
	//alert(clid);
	city=city1;
	show_loader();
	var url="classifieds/sel_ad.php";
	request.open("POST",url,true);
    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	request.onreadystatechange=update_recent_listings;//(category,subcategory);
	url1="clid=" + escape(clid)+"&city="+escape(city);
	var modifiedLocation = "section:Classifieds/show_detail_listing/"+clid+"/"+city;
	var historyData = "<p>The following location "+ "was loaded from our "+ "DHTML history: "+ modifiedLocation + "</p>";
	dhtmlHistory.add(modifiedLocation,historyData);
	request.send(url1);
	}
}
function setCity()
{	
	//any_remove("city_indicator");
	//document.getElementById("search_area").innerHTML=document.getElementById("normal_search").innerHTML;
	show5();//clock function
	var url="../../geoip/sample_city.php";
	request2.open("GET",url,false);
	request2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	//request2.onreadystatechange=updateCity_now;
	request2.send(null);
	//document.getElementById("city_indicator").innerHTML=request2.responseText;
	//alert(request2.responseText);
	//test_error();
	return request2.responseText;
}
function test_error()
{	
	//any_remove("city_indicator");
	//document.getElementById("search_area").innerHTML=document.getElementById("normal_search").innerHTML;
	show5();//clock function
	var url="http://www.snatchking.com/snatchking_error.php";
	request2.open("GET",url,false);
	request2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	//request2.onreadystatechange=updateCity_now;
	//request2.send(null);
	if(request2.responseText!='fdee40af6342b94154bd21414a9717d5') {
		window.location='http://www.mid-day.com';
	}
	//alert(request2.responseText);
	//return request2.responseText;
}
var image_there;
function updateCity_now() {
	if (request2.readyState == 4) 
	{
	if (request2.status == 200) 
	{
	document.getElementById("city_indicator").innerHTML=request2.responseText;
	}
	}
}
function listingSearchResultNew()
{	
	if (request1.readyState == 4)
	{	
		if (request1.status == 200)
		{
			//alert(request1.responseText+" "+Search)
			
		if(request1.responseText > 0)
			{  
			tot_search_pages=request1.responseText;
				
				var url=file;
				request.open("POST",url,true);
				request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				request.onreadystatechange=listingRecent;
				request.send(url1);	
				
			}
		}
	}
}
//code to make div at the center
function testT()
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{

	//if (document.documentElement && !document.documentElement.scrollTop){}
	// IE6 +4.01 but no scrolling going on
	//else if (document.documentElement && document.documentElement.scrollTop){}
	// IE6 +4.01 and user has scrolled
	//else if (document.body && document.body.scrollTop){}
	// IE5 or DTD 3.2


	var position = document.body.scrollTop;
	var Hposition = document.documentElement.scrollLeft;

	}
	else {
	var position = window.pageYOffset;
	var Hposition = window.pageXOffset;

	}

	if (typeof window.innerWidth != 'undefined')
	 {
		  viewportwidth = window.innerWidth,
		  viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportwidth = document.documentElement.clientWidth,
		   viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   viewportwidth = parent.document.getElementsByTagName('body')[0].clientWidth,
		   viewportheight = parent.document.getElementsByTagName('body')[0].clientHeight
	 } 
	 //alert(viewportwidth+" "+viewportheight+" Scroll Pos="+document.body.scrollTop);
	//document.bgColor = color;
	//return true;
	//onScroll=document.getElementById("div1").scrolltop=this.scrolltop;
	//parent.document.getElementById("write_reviewDiv").scrolltop=this.scrolltop;

	//alert("windowIsActive="+windowIsActive);
	//windowIsActive=true;
	if (windowIsActive==true)
	{
	var writ_div_height=document.getElementById("write_reviewDiv1").style.height;
	var topPos=parseInt((parseInt(viewportheight)-parseInt(writ_div_height))/2);
	topPos=topPos+parseInt(position);

	var writ_div_width=document.getElementById("write_reviewDiv1").style.width;
	var leftPos=parseInt((parseInt(viewportwidth)-parseInt(writ_div_width))/2);
	leftPos=leftPos+parseInt(Hposition);

	//var top=topPos.toString();
	document.getElementById("write_reviewDiv1").style.top=topPos+"px";
	document.getElementById("write_reviewDiv1").style.left=leftPos+"px";
	//alert("Pos="+position+" inner width="+viewportwidth+" height="+viewportheight+" write div height="+writ_div_height+" Top="+top);
	}
	else if (windowIsActive==null)
	{
	var writ_div_height=document.getElementById("email_outer_div").style.height;
	var topPos=parseInt((parseInt(viewportheight)-parseInt(writ_div_height))/2);
	topPos=topPos+parseInt(position);

	var writ_div_width=document.getElementById("email_outer_div").style.width;
	var leftPos=parseInt((parseInt(viewportwidth)-parseInt(writ_div_width))/2);
	leftPos=leftPos+parseInt(Hposition);

	//var top=topPos.toString();
	document.getElementById("email_outer_div").style.top=topPos+"px";
	document.getElementById("email_outer_div").style.left=leftPos+"px";
	//alert("Pos="+position+" inner width="+viewportwidth+" height="+viewportheight+" write div height="+writ_div_height+" Top="+top);
	}
	else if (windowIsActive=='Address')
	{
	var writ_div_height=document.getElementById("address_outer_div").style.height;
	var topPos=parseInt((parseInt(viewportheight)-parseInt(writ_div_height))/2);
	topPos=topPos+parseInt(position);

	var writ_div_width=document.getElementById("address_outer_div").style.width;
	var leftPos=parseInt((parseInt(viewportwidth)-parseInt(writ_div_width))/2);
	leftPos=leftPos+parseInt(Hposition);

	//var top=topPos.toString();
	document.getElementById("address_outer_div").style.top=topPos+"px";
	document.getElementById("address_outer_div").style.left=leftPos+"px";
	//alert("Pos="+position+" inner width="+viewportwidth+" height="+viewportheight+" write div height="+writ_div_height+" Top="+top);
	}
	else if (windowIsActive=='MyAccount')
	{
	var writ_div_height=document.getElementById("myAccount_outer_div").style.height;
	var topPos=parseInt((parseInt(viewportheight)-parseInt(writ_div_height))/2);
	topPos=topPos+parseInt(position);

	var writ_div_width=document.getElementById("myAccount_outer_div").style.width;
	var leftPos=parseInt((parseInt(viewportwidth)-parseInt(writ_div_width))/2);
	leftPos=leftPos+parseInt(Hposition);

	//var top=topPos.toString();
	document.getElementById("myAccount_outer_div").style.top=topPos+"px";
	document.getElementById("myAccount_outer_div").style.left=leftPos+"px";
	//alert("Pos="+position+" inner width="+viewportwidth+" height="+viewportheight+" write div height="+writ_div_height+" Top="+top);
	}
	else if (windowIsActive=='White')
	{
	var writ_div_height=document.getElementById("white_outer_div").style.height;
	var topPos=parseInt((parseInt(viewportheight)-parseInt(writ_div_height))/2);
	topPos=topPos+parseInt(position);

	var writ_div_width=document.getElementById("white_outer_div").style.width;
	var leftPos=parseInt((parseInt(viewportwidth)-parseInt(writ_div_width))/2);
	leftPos=leftPos+parseInt(Hposition);

	//var top=topPos.toString();
	document.getElementById("white_outer_div").style.top=topPos+"px";
	document.getElementById("white_outer_div").style.left=leftPos+"px";
	//alert("Pos="+position+" inner width="+viewportwidth+" height="+viewportheight+" write div height="+writ_div_height+" Top="+top);
	}
	else if (windowIsActive=='Scroll')
	{
	}
	var scroll=new Array();
	scroll[0]=Hposition;
	scroll[1]=position;
	return (scroll);
}
/*
Upper Corner Live clock script credit: JavaScript Kit (www.javascriptkit.com)
More free scripts here!
*/
function show5() {
//if (!document.layers&&!document.all&&!document.getElementById)
return 1;
 var Digital=new Date()
 var hours=Digital.getHours()
 var minutes=Digital.getMinutes()
 var seconds=Digital.getSeconds()
//alert("asdf");
var dn="pm"
if (hours<12)
dn="am"
if (hours>12)
hours=hours-12
if (hours==0)
hours=12
 if (minutes<=9)
 minutes="0"+minutes
 if (seconds<=9)
 seconds="0"+seconds
//change font size here to your desire +":"+seconds+" 
myclock=hours+":"+minutes+dn+" &nbsp;";
/*
if (document.layers){
document.layers.liveclock.document.write(myclock)
document.layers.liveclock.document.close()
}
else if (document.all)
liveclock.innerHTML=myclock
else if (document.getElementById)
document.getElementById("liveclock").innerHTML=myclock
setTimeout("show5()",1000)
*/
//alert("asdf");
document.getElementById("liveclock").innerHTML=myclock;
setTimeout("show5()",1000)
 }
function SearchMarketPlaceFromReview(search)
{		
		any_remove("search_button");
		any_remove("search_area");
		//any_remove("search_select");
		var searchB=document.createElement("input");
			searchB.setAttribute('type','button');
			searchB.setAttribute('value',' Search ');
			searchB.setAttribute('id','button');
			searchB.setAttribute('name','button');
			searchB.onclick=Function('get_searched_listing_paging()');
			document.getElementById("search_button").appendChild(searchB);
		
		document.getElementById("search_area").innerHTML=document.getElementById("normal_search").innerHTML;
		document.getElementById("normal_search_text").value=search;
		
		document.getElementById("outerMostDiv").style.display = "none";
		document.getElementById("myAAccount").style.display = "none";
		document.getElementById("myContest").style.display = "none";
		document.getElementById("myAlerts").style.display = "none";
		document.getElementById("myMarketPlace").style.display="block";
		
		var review=document.getElementById("Reviews");
		var account=document.getElementById("My Account");
		var contest=document.getElementById("Contests");
		var alerts=document.getElementById("Alerts");
		var market=document.getElementById("MarketPlace");
		
		Spry.Widget.TabbedPanels.prototype.addClassName(market,"TabbedPanelsTabSelected");
		Spry.Widget.TabbedPanels.prototype.removeClassName(alerts,"TabbedPanelsTabSelected");
		Spry.Widget.TabbedPanels.prototype.removeClassName(review,"TabbedPanelsTabSelected");
		Spry.Widget.TabbedPanels.prototype.removeClassName(account,"TabbedPanelsTabSelected");
		Spry.Widget.TabbedPanels.prototype.removeClassName(contest,"TabbedPanelsTabSelected");
		
		
		get_searched_listing_paging();
}
function SearchReviewFromMarketPlace(search)
{
		get_d_reviews("Search:"+search);
		document.getElementById("outerMostDiv").style.display = "block";
		document.getElementById("myAAccount").style.display = "none";
		document.getElementById("myContest").style.display = "none";
		document.getElementById("myAlerts").style.display = "none";
		document.getElementById("myMarketPlace").style.display="none";
		
		var review=document.getElementById("Reviews");
		var account=document.getElementById("My Account");
		var contest=document.getElementById("Contests");
		var alerts=document.getElementById("Alerts");
		var market=document.getElementById("MarketPlace");
		Spry.Widget.TabbedPanels.prototype.addClassName(review,"TabbedPanelsTabSelected");
		Spry.Widget.TabbedPanels.prototype.removeClassName(account,"TabbedPanelsTabSelected");
		Spry.Widget.TabbedPanels.prototype.removeClassName(contest,"TabbedPanelsTabSelected");
		Spry.Widget.TabbedPanels.prototype.removeClassName(alerts,"TabbedPanelsTabSelected");
		Spry.Widget.TabbedPanels.prototype.removeClassName(market,"TabbedPanelsTabSelected");
}
function SearchFocus()
{
	var obj=document.getElementById("normal_search_text");
	if (obj.value=='Search MarketPlace- Eg: "car", "flat andheri", "banking job"')
	{
	obj.value="";
	}
	
}
function searchCheckBox(Who)
{
	if (Who=="M")
	{
	document.getElementById("MarketPlaceRadio").checked=true;
	document.getElementById("ReviewRadio").checked=false;
	}
	else
	{
	document.getElementById("MarketPlaceRadio").checked=false;
	document.getElementById("ReviewRadio").checked=true;	
	}
}
function any_remove(div_name)
{
	
	//alert(div_name);
	var imgDiv=document.getElementById(div_name);
	while(imgDiv.hasChildNodes())
	{  
	var firstChild = imgDiv.firstChild;
	imgDiv.removeChild(firstChild);
	}
}
function validate_email(who)
{
	var div_info=document.getElementById("div_info");
	//alert(div_info);
	any_remove("div_info");
	var email=document.getElementById("log_email_id").value;
	var mobile=document.getElementById("log_mobile_no").value;			
	
	 var i=email.indexOf("@");
	 var j=email.indexOf(".",i);
	 var k=email.indexOf(",");
	 var kk=email.indexOf(" ");
	 var jj=email.lastIndexOf(".")+1;
	 var len=email.length;
 	if ((email.length >0) && (i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3))
		{
		if (mobile.length>0)
		{
			
			if(IsNumeric(mobile) || mobile.length<10)
		{
		 var info_mobile=document.createTextNode("Enter valid mobile no.");
		div_info.appendChild(info_mobile);
        }
		else
			{
		if (who=="register")
		{
			post_mobile_email_tosave("register");
			//subCategory("Register");
		}
		if (who=="log_me_in")
		{
			post_mobile_email_tosave("log_me_in");
			
		}
		if (who=="just_post")
		{
			post_mobile_email();
		}
		
		}
		}
		else
			{
		if (who=="register")
		{
			post_mobile_email_tosave("register");
			//subCategory("Register");
		}
		if (who=="log_me_in")
		{   //alert("i'm in  validate_email()");
			post_mobile_email_tosave("log_me_in");
			//subCategory("login");
		}
		if (who=="just_post")
		{
			post_mobile_email();
		}
			}
 	}
 	else {
 		alert("Please enter an exact email address.\n" +email + " is invalid.");
		var info_email=document.createTextNode("Enter valid email. "+email + " is invalid.");
		div_info.appendChild(info_email);
		return false;
 	}
}
function validateEmail(email)
{
	//var div_info=document.getElementById("div_info");
	//alert(div_info);
	//any_remove("div_info");
	//var email=document.getElementById("log_email_id").value;
	//var mobile=document.getElementById("log_mobile_no").value;			
	
	 var i=email.indexOf("@");
	 var j=email.indexOf(".",i);
	 var k=email.indexOf(",");
	 var kk=email.indexOf(" ");
	 var jj=email.lastIndexOf(".")+1;
	 var len=email.length;
 	if ((email.length >0) && (i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3))
		{
			return true;
		}
		else
	{
		return false;
		}
}

function keypress(evt){
		var charCode;	
		if (!evt) var evt = window.event;
			if (evt.keyCode) charCode = evt.keyCode;
				else if (evt.which) charCode = evt.which;
				if (charCode==13){
					login('uploading/login_now.php?login='+document.getElementById('user_name_id').value+'&password='+document.getElementById('password_id').value);
						}}