function SelCityZip(li) {
   if ((li.extra != null) && (li.extra != '')) {
      $('#zip_id').val(li.extra[0]);      
      if($('#cat').val() == '') {
         $('#cat').focus();
      }
   }
}

function file_exists(url) { 
	// Returns true if filename exists

	var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	if (!req) {throw new Error('XMLHttpRequest not supported');}
	// HEAD Results are usually shorter (faster) than GET
	req.open('HEAD', url, false);
	req.send(null);
	if (req.status == 200){ 
		return 1;
	}
	return 0;
}
function urldecode (str) {

    var hash_map = {}, ret = str.toString(), unicodeStr='', hexEscStr='';
    
    var replacer = function (search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The hash_map is identical to the one in urlencode.
    hash_map["'"]   = '%27';
    hash_map['(']   = '%28';
    hash_map[')']   = '%29';
    hash_map['*']   = '%2A';
    hash_map['~']   = '%7E';
    hash_map['!']   = '%21';
    hash_map['%20'] = '+';
    hash_map['\u00DC'] = '%DC';
    hash_map['\u00FC'] = '%FC';
    hash_map['\u00C4'] = '%D4';
    hash_map['\u00E4'] = '%E4';
    hash_map['\u00D6'] = '%D6';
    hash_map['\u00F6'] = '%F6';
    hash_map['\u00DF'] = '%DF';
    hash_map['\u20AC'] = '%80';
    hash_map['\u0081'] = '%81';
    hash_map['\u201A'] = '%82';
    hash_map['\u0192'] = '%83';
    hash_map['\u201E'] = '%84';
    hash_map['\u2026'] = '%85';
    hash_map['\u2020'] = '%86';
    hash_map['\u2021'] = '%87';
    hash_map['\u02C6'] = '%88';
    hash_map['\u2030'] = '%89';
    hash_map['\u0160'] = '%8A';
    hash_map['\u2039'] = '%8B';
    hash_map['\u0152'] = '%8C';
    hash_map['\u008D'] = '%8D';
    hash_map['\u017D'] = '%8E';
    hash_map['\u008F'] = '%8F';
    hash_map['\u0090'] = '%90';
    hash_map['\u2018'] = '%91';
    hash_map['\u2019'] = '%92';
    hash_map['\u201C'] = '%93';
    hash_map['\u201D'] = '%94';
    hash_map['\u2022'] = '%95';
    hash_map['\u2013'] = '%96';
    hash_map['\u2014'] = '%97';
    hash_map['\u02DC'] = '%98';
    hash_map['\u2122'] = '%99';
    hash_map['\u0161'] = '%9A';
    hash_map['\u203A'] = '%9B';
    hash_map['\u0153'] = '%9C';
    hash_map['\u009D'] = '%9D';
    hash_map['\u017E'] = '%9E';
    hash_map['\u0178'] = '%9F';
    hash_map['\u00C6'] = '%C3%86';
    hash_map['\u00D8'] = '%C3%98';
    hash_map['\u00C5'] = '%C3%85';
 
    for (unicodeStr in hash_map) {
        hexEscStr = hash_map[unicodeStr]; // Switch order when decoding
        ret = replacer(hexEscStr, unicodeStr, ret); // Custom replace. No regexing
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}
function urlencode (str) {
 
    var hexStr = function (dec) {
        return '%' + dec.toString(16).toUpperCase();
    };
 
    var ret = '',
            unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
    str = (str+'').toString();
 
    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            // Reserved assumed to be in UTF-8, as in PHP
            if (code === 32) {
                ret += '+'; // %20 in rawurlencode
            }
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048 && code < 65536) { // 3 bytes
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 65536) { // 4 bytes
                ret += hexStr((code >> 18) | 0xF0);
                ret += hexStr(((code >> 12) & 0x3F) | 0x80);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;
}

function SelCategory(li) {
   if ((li.extra != null) && (li.extra != '')) {      
      
   }
   if($('#zcity').val() == '') {
      $('#zcity').focus();
   }
}

function formatItem(row) {
	return "<b>" + row[0] +"</b>";
}





function cjsearch() {
	$.ajax({
	  url: baseurl + '/cj/?cat=' + $('#cat').val(),
	  cache: false,
	  success: function(data){
		  if(data) {
			$("#right_body_content").html(data);
		  } else {
			  data = '<a href="http://www.kqzyfj.com/click-3463003-10495435"><img src="http://www.lduhtrp.net/image-3463003-10495435" width="200" height="250" alt="" border="0"/></a><br><a href="http://www.jdoqocy.com/click-3463003-10649734"><img src="http://www.lduhtrp.net/image-3463003-10649734" width="200" height="250" alt="" border="0"/></a><br>';
			  $("#right_body_content").html(data);
		  }
	  }
	});
}

function searchdata(idvalue) {
			
	 if ($("input[@name='find_listing']:checked").val() == 'bus') { 
		$('#cat').val($(idvalue).attr('id'));//return false;
	} else if  ($("input[@name='find_listing']:checked").val() == 'class') {
		$('#classified_cat').val($(idvalue).attr('id'));//return false;
	}
	
	$('#ajax_busy').show();
	if ($("input[@name='find_listing']:checked").val() == 'bus') {
		if (($('#zcity').val() == '') || ($('#cat').val() == '') || ($("#zcity").val() == 'Enter Location') || ($("#cat").val() == 'Enter Category')) {
			$('#ajax_busy').hide();
			alert('Enter search criteria.');
			return false;
		}
		pageingsearchType = 'business';
		pageingsortby	= 'distance';
		pageingperpage = 20;
		var hash = '#page1';
		hash = hash.replace(/^.*#/, '');
		$.history.load(hash);
		//businessSearchlist (1, perpage, 'distance');
	} else if  ($("input[@name='find_listing']:checked").val() == 'class') {
		if (($('#zcity').val() == '') || ($('#classified_cat').val() == '') || ($("#zcity").val() == 'Enter Location') || ($("#classified_cat").val() == 'Enter Category')) {
			$('#ajax_busy').hide();
			alert('Enter search criteria.');
			return false;
		}
		homechildcategoryid = '';
		pageingsearchType = 'classified';
		pageingsortby	= 'ad_posted';
		pageingperpage = 20;
		var hash = '#page1';
		hash = hash.replace(/^.*#/, '');
		$.history.load(hash);
		//viewAllClassified ('classified', 1, perpage, 'ad_posted');
	}

}
function pageload(hash) {
	//if hash value exists, run the ajax
	if (hash) {
		pageingcurretntPageNumber = hash.split('page');
		$("#searchresultandcategory").show();
		$("#resultcontentdiv").hide();
		$("#pagination").show();
		$("#showing").show();
		paginator(pageingsearchType, pageingcurretntPageNumber[1], pageingperpage, pageingsortby);
	} else {
			if (indexpage == 1) {
				 $.ajax({
				  url: baseurl+'/index/backurl/',
				  cache: false,
				  success: function(data){
					$("#cat").val('Enter Category');
					$("#classified_cat").val('Enter Category'); 
					$("#zcity").val('Enter Location');
				  }
				});
			}
		$("#searchresultandcategory").hide();
		$("#pagination").hide();
		$("#showing").hide();
		$("#resultcontentdiv").show();
	}
}

function paginator(searchType, curretntPageNumber, perpage, sortby) { 
	if (searchType == 'business') { 
		businessSearchlist (curretntPageNumber, perpage, sortby); 
	} else if (searchType == 'viweall') {
		viewAllClassified ('viweall', curretntPageNumber, perpage, sortby); 
	} else if (searchType == 'classified') {
		viewAllClassified ('classified', curretntPageNumber, perpage, sortby);
	}
}
$(document).ready(function(){
	 $.history.init(pageload);	
	 $("#shopsearchform").submit(function() {
		return false;
    });
	
	$('#sl_submit').click(function(){
		if ($("input[@name='find_listing']:checked").val() == 'bus') {

			if (($('#zcity').val() == '') && ($('#cat').val() == '')) {
				$('#ajax_busy').hide();
				alert('Enter the Location & Category');
				return false;
			}
			if (($("#zcity").val() == 'Enter Location') && ($("#cat").val() == 'Enter Category')) {
				$('#ajax_busy').hide();
				alert('Enter the Location & Category');
				return false;
			}
			if (($('#cat').val() == '') || ($("#cat").val() == 'Enter Category')) {
				$('#ajax_busy').hide();
				alert('Enter Category');
				return false;
			}
			if (($('#zcity').val() == '') || ($("#zcity").val() == 'Enter Location')) {
				$('#ajax_busy').hide();
				alert('Enter Location');
				return false;
			}
			//businessSearchlist (1, perpage, 'distance');
			pageingsearchType = 'business';
			pageingsortby	= 'distance';
			pageingperpage = 20;
			var hash = '#page1';
			hash = hash.replace(/^.*#/, '');
			$.history.load(hash);
			
		} else if  ($("input[@name='find_listing']:checked").val() == 'class') {

			if (($('#zcity').val() == '') && ($('#classified_cat').val() == '')) {
				$('#ajax_busy').hide();
				alert('Enter the Location & Category');
				return false;
			}
			if (($("#zcity").val() == 'Enter Location') && ($("#classified_cat").val() == 'Enter Category')) {
				$('#ajax_busy').hide();
				alert('Enter the Location & Category');
				return false;
			}
			if (($('#classified_cat').val() == '') || ($("#classified_cat").val() == 'Enter Category')) {
				$('#ajax_busy').hide();
				alert('Enter Category');
				return false;
			}
			if (($('#zcity').val() == '') || ($("#zcity").val() == 'Enter Location')) {
				$('#ajax_busy').hide();
				alert('Enter Location');
				return false;
			}
			homechildcategoryid = '';
			pageingsearchType = 'classified';
			pageingsortby	= 'ad_posted';
			pageingperpage = 20;
			var hash = '#page1';
			hash = hash.replace(/^.*#/, '');
			$.history.load(hash);
			//viewAllClassified ('classified', 1, perpage, 'ad_posted');
		}
	
   });

	// JSON code to get the User Location classifieds
	$('#view_all').click(function(){ 
								  //viewAllClassified ('viweall', 1, perpage, 'ad_posted');
								 	pageingsearchType = 'viweall';
									pageingsortby	= 'ad_posted';
									pageingperpage = 20;
									var hash = '#page1';
									hash = hash.replace(/^.*#/, '');
									$.history.load(hash);
								  return false; });

});
function businessSearchlistsort() { 
	businessSearchlist (1, perpage, $('#businessSearchlistsortby').val());
}

function businessSearchlist (curretntPageNumber, perpage, sortby) {

	$('.ac_results').hide();
	$('#ajax_busy').show();
	$('#searchresultandcategory').html('');
	$('#business-premium-plus').html('');
	//$('#showing').html('<div id="ajax_busy" style="display:block"><img src="./images/ajax_loading.gif"></div>');

	$.getJSON(baseurl + '/search/?curretntPageNumber=' + curretntPageNumber + '&perpage=' + perpage + '&sortby=' + sortby + '&businessCategory=' + urlencode($('#cat').val()) + '&city=' + urlencode($('#zcity').val()) + '&searchType=business',function(data){

		$('#ajax_busy').hide();

		$('#business-premium-plus').html('');
		$("#business-premium-plus").removeClass("feature");
		$("#business-premium-plus").addClass("recommend");

		$('#pagination').html('');
		status =  "1";
		var result = '<h3><span>Sort By :&nbsp;&nbsp;<select name="businessSearchlistsortby" id="businessSearchlistsortby" class="dropdown" onchange="businessSearchlistsort();" ><option value="create_date">Posted date</option><option value="name">Title</option><option value="distance">Distance</option></select></span>Recommended Listing</h3><div class="clr"></div>';
		var pp_result	=	'';
		var p_result	=	'';
		var ef_result	=	'';
		var i =0;
		var total_plus = 0;
		var premimum_plus_total = 0;
		var premium_plus_result_total_plus = 0;
		var plusbusiness_name	=	'';

		/*-- JSON loop to show the Premium Plus records Starts --*/
		$.each(data.set.plus, function(i,plus){

			if(plus.empty) {
				$('#business-premium-plus').html('');
				result	=	'';
				return false;
			}

			premimum_plus_total = plus.total;
			if(plus.name != ""){

				if((plus.burl == '') || (plus.burl == 'http://'))	{
					plusbusiness_name	=	plus.name;
				} else	{
					plusbusiness_name	=	'<a href="' + plus.burl + '" target="_blank">' + plus.name + '</a>';
				}

				pp_result += '<div class="box1"><b>' + plusbusiness_name + ' - ' + plus.city + ', ' + plus.state + '</b><div>' + plus.address + '</div><div>' + plus.phone + ' ' + plus.ad_posted + '</div></div>';
				i++;
			}
			total_plus = i;
		});
		var initial_pp_result	=	result + pp_result;
		$('#business-premium-plus').show();
		$('#business-premium-plus').html(initial_pp_result);
		/*-- JSON loop to show the Premium Plus records Ends --*/

		premium_plus_result_total_plus = total_plus;
		p_result += '<div class="clr"></div>';

		var z = 0;
		var premimum_total = 0;
		var prembusiness_name	=	'';
		total_plus = 0;

		/*-- JSON loop to show the Premium records Starts --*/
		$.each(data.set.premium, function(i,prem){

			if(prem.empty) {
				return false;
			}

			premimum_total = prem.total;
			z++;

			if((prem.burl == '') || (prem.burl == 'http://'))	{
				prembusiness_name	=	prem.name;
			} else	{
				prembusiness_name	=	'<a href="http://' + prem.burl + '" target="_blank">' + prem.name + '</a>';
			}

			p_result += '<div class="result-premium"><span class="rslt-p1"><b>' + prembusiness_name + '</b><div>' + prem.address + ' ' + prem.city + ' &raquo; <a class="map-iframe" href="' + baseurl + '/index/gmap/name/' + prem.name + '/address/' + prem.address + '/city/' + prem.city + '/latitude/' + prem.latitude + '/longitude/' + prem.longitude + '" class="map-link">Map</a></div><span>Category: ' + prem.category + '</span></span><span class="rslt-p2">' + prem.phone + '</span><span class="rslt-p3">' + prem.rating + '</span><span class="rslt-p4">' + prem.ad_posted + '</span></div><script type="text/javascript">$(".map-iframe").colorbox({width:"530px", height:"650px", iframe:true});</script>';

			total_plus = z;
		});
		/*-- JSON loop to show the Premium records Ends --*/

		var	premium_result_total_plus = 0;
		premium_result_total_plus = total_plus;

		var total = ''  ;
		var y = 0;
		var selectedsortby = '';
		var business_name	=	'';

		if (curretntPageNumber != 1) 
			y = (curretntPageNumber-1)*perpage;

		var classname = '';
		total_plus = 0;

		/*-- JSON loop to show the Economy/Normal records Starts --*/
		$.each(data.set.normal, function(i, norm){

			if(norm.empty) {
				return false;
			}
			y++;

			total = norm.total;
			selectedsortby = norm.sortby;

			if(i % 2 == 0)	{
				classname = 'result-row1';
			} else {
				classname = 'result-row2';
			}
			if (norm.flag == 'Economy Plus') {
				classname = 'result-row3';
			}

			if((norm.burl == '') || (norm.burl == 'http://'))	{
				business_name	=	norm.name;
			} else	{
				business_name	=	'<a href="http://' + norm.burl + '" target="_blank">' + norm.name + '</a>';
			}

			ef_result += '<div class="' + classname + '"><span class="rslt-p1">' + y + ' <b>' + business_name + '</b><div>' + norm.address + ' ' + norm.city + ' &raquo; <a class="map-iframe map-link" href="' + baseurl + '/index/gmap/name/' + norm.name + '/address/' + norm.address + '/city/' + norm.city + '/latitude/' + norm.latitude + '/longitude/' + norm.longitude + '" class="map-link">Map</a></div><span>Category: ' + norm.category + '</span></span><span class="rslt-p2">' + norm.phone + '</span><span class="rslt-p3">' + norm.rating + '</span><span class="rslt-p4">' + norm.ad_posted + '</span></div><script type="text/javascript">$(".map-iframe").colorbox({width:"530px", height:"650px", iframe:true});</script>';

			total_plus = y;

		});

		var b_result	=	p_result + ef_result;
		$('#business-left-div').show();
		$('#business-left-div').html(b_result);
		/*-- JSON loop to show the Economy/Normal records Ends --*/

		//$('#searchresultandcategory').html(result);
		$("#businessSearchlistsortby").find('option').each(function(){

			if($(this).val() == selectedsortby) {
				$(this).attr("selected",true);
			}

	   });

		if(premimum_plus_total > 0 || premimum_total > 0 || total > 0) {
			total_record = Math.max(premimum_plus_total,premimum_total, total);
			
			if (premimum_plus_total > total || premimum_total > total) {
				if (premimum_plus_total > premimum_total) {
					perpage = 6;
					lastnumber = premium_plus_result_total_plus;  
				} else	{
					perpage = 5;
					lastnumber = premium_result_total_plus;
				}
			} else {
				lastnumber = total_plus;
			}
			var startnumber = 0;

			if (curretntPageNumber != 1) 
				startnumber = (curretntPageNumber - 1) * perpage;

			var showing = 'Showing ' + (startnumber + 1) + ' - ' + lastnumber + ' of ' + total_record;

			$("#pagination").load(baseurl + '/index/pagination/searchType/business/total/' + total_record + '/curretntPageNumber/' + curretntPageNumber + '/perpage/' + perpage + '/sortby/' + sortby, null, function() { });
			$('#showing').html(showing);
			$('#business-right-div').show();

		 } else	{

			var topresult = '';
			$('#pagination').html('');
			$('#showing').html('');

			if(data.set.top != undefined)	{

				topresult += 'We found 0 results for your search but we found these Top categories.';

				 $.each(data.set.top, function(i,top){

				   topresult += '<li style="padding-left:10px;list-style-type:none;"><a href="#" onclick="searchdata(this); return false;" class="linksuggest" id="' + top.name + '">' + top.name + '</a></li>';

				});

			} else	{
			   topresult += 'We found 0 results for your search!';
			}

			$('#searchresultandcategory').html(topresult);
			$('#business-right-div').hide();
		}

		//cjsearch();
	});
	$('.ac_results').hide();
}


function viewAllClassifiedsort(searchType, curretntPageNumber, perpage) { 
	viewAllClassified (searchType, 1, perpage, $('#viewallclassifiedsortby').val());
}

var tooltipi	=	0;
var totladivdetails = 0;

function viewAllClassified (searchType, curretntPageNumber, perpage, sortby) {

	$('.ac_results').hide();
	$('#ajax_busy').show();

	$('#business-premium-plus').hide();
	$('#business-left-div').hide();
	$('#business-right-div').hide();

	$('#searchresultandcategory').html('');
	$('#showing').html('');
	$("#pagination").html('');

	if($('#view_cl_img').attr("checked"))
		var show_img = $('#view_cl_img').val();
	else
		var show_img = "0";

	$.getJSON(baseurl + '/search/?show_img=' + show_img + '&curretntPageNumber=' + curretntPageNumber + '&perpage=' + perpage + '&sortby=' + sortby + '&searchType=' + searchType + '&classifiedCategory=' + urlencode($('#classified_cat').val()) + '&city=' + urlencode($('#zcity').val()) + '&chaildcatid=' + homechildcategoryid,function(data)	{

		$('#ajax_busy').hide();
		$('#searchresultandcategory').html('');
		$("#searchresultandcategory").removeClass("feature");
		$("#searchresultandcategory").addClass("recommend");
		$('#pagination').html('');

		var status =  "1";
		var result = '<h3><div id="suggest_span" style="display: block;">Sort By :&nbsp;&nbsp;<select name="viewallclassifiedsortby" id="viewallclassifiedsortby" onchange="viewAllClassifiedsort(\'' + searchType + '\', ' + curretntPageNumber + ', ' + perpage + ');" ><option value="ad_posted">Posted date</option><option value="ad_title">Title</option><option value="distance">Distance</option></select></div>Recommended Listing</h3><div class="clr"></div>';

		var i =0;
		var y = 0;
		var total = '';
		var feedtotal = 0;
		var feedtotal_plus = 0;
		var dbtotal = 0;
		var dbtotal_plus = 0;
		var classname = '';
		var topresult = '';

		if (curretntPageNumber != 1) 
			y = (curretntPageNumber-1)*perpage;

		var showing = 'Showing ' + (y + 1) + ' - ';
		var selectedsortby = '';
		perpage = 5;

		$.each(data.set.normal, function(i, norm)	{
			if(norm.empty) {
				return false;
			}
			y++;
			dbtotal = norm.total;
			selectedsortby = norm.sortby;

			if(i % 2 == 0)	{
				classname = 'result-row1';
			} else {
				classname = 'result-row2';
			}

			var tooptipvariable = '';
			if(norm.ad_images != '')	{

				if(file_exists(img_baseurl + "/images/uploaded/" + norm.state + "/" + norm.ad_images) == 0)
					//var img = '<img alt="" src="images/no-image.jpg" height="90" width="90">';
					var	img = '';
				else {
					var img = '<img id="thumb' + i + '" alt="" src="' + img_baseurl + '/images/uploaded/' + norm.state + '/' + norm.ad_images + '" height="90" width="90">';
					tooptipvariable += '$("#thumb' + i + '").tooltip({delay: 0,showURL: false,bodyHandler: function() {return $("<img/>").attr("src", "' + img_baseurl + '/images/uploaded/big/' + norm.state + '/' + norm.ad_images + '");}});';
				}

			} else	{
				//var img = '<img alt="" src="images/no-image.jpg" height="90" width="90">';
				var	img = '';
			}

			var imagegallerycount = 0;
			var imageGalleryCollection = '';

			$.each(norm.imagegallery, function(imagegallerycount, imagegallery)	{

					imageGalleryCollection += '<img height="90" border="0" width="90" id="tooltip' + tooltipi + imagegallerycount + '" src="' + img_baseurl + '/images/uploaded/' + imagegallery.state_code.toLowerCase() + '/' + imagegallery.image_file + '"/>';
					tooptipvariable += '$("#tooltip' + tooltipi + imagegallerycount + '").tooltip({delay: 0,showURL: false,bodyHandler: function() {return $("<img/>").attr("src", "' + img_baseurl + '/images/uploaded/big/' + imagegallery.state_code.toLowerCase() + '/' + imagegallery.image_file + '");}});';
					tooltipi++;

				}
			);

			var dyn_price = '';
			if(norm.rating != "")
				dyn_price	=	"<div>" + norm.rating + "</div>";

			if(norm.url != "")
				var dyn_url	=	'<a href="http://api.addthis.com/oexchange/0.8/offer?url=' + norm.url + '" target="_blank"><img src="http://s7.addthis.com/static/btn/lg-share-en.gif" width="125" height="16" border="0" alt="Share" /></a>';
			else
				var dyn_url	=	'<a href="http://api.addthis.com/oexchange/0.8/offer?url=http://www.shopzipcode.com" target="_blank"><img src="http://s7.addthis.com/static/btn/lg-share-en.gif" width="125" height="16" border="0" alt="Share" /></a>';

			result += '<div class="' + classname + '"><div class="crslt-p1"><div class="s-no">' + y + '</div><div id="cname' + y + '" onclick="displaydetails(' + y + ');" class="c-name" style="float: left; width: 610px;"><a class="business-name">' + norm.name + '</a></div>' + dyn_price + '<div id="shortdetail' + y + '" style="clear: left;"><div class="class-img"><a href="#" onClick="return false;">' + img + '</a></div><div class="classifieds-result-con"><div class="class-city">' + norm.city + ' &raquo; <a class="map-iframe map-link" href="' + baseurl + '/index/gmap/city/' + norm.city + '/latitude/' + norm.latitude + '/longitude/' + norm.longitude + '">Map</a><div class="business-address">' + norm.desc + '<br />' + norm.dynamic_value + '</div></div><div class="class-cat">Category: ' + norm.category + '</div></div></div></div><div class="posted-date">' + norm.ad_posted + '</div></div><div id="longdetail' + y + '" class="classi-description"><div class="classi-shape"></div><h5><a href="#" id="detailclose' + y + '" onclick="closedetails(' + y + '); return false;" class="classi-close"></a>' + norm.name + '</h5><div class="classi-img-row">' + imageGalleryCollection + '</div><div>' + norm.city + ' &raquo; <a class="map-iframe map-link" href="' + baseurl + '/index/gmap/city/' + norm.city + '/latitude/' + norm.latitude + '/longitude/' + norm.longitude + '">Map</a></div>' + norm.descfull + '<br /><br />' + norm.dynamic_value + '<br /><span>Category: ' + norm.category + '</span><div class="clr"></div><div class="reply">' + dyn_url + '&nbsp;&nbsp;|&nbsp;&nbsp;<a href="' + baseurl + '/addclassifieds/view/id/' + norm.list_id + '/stateCode/' + norm.state + '/" class="search-result">Reply</a></div></div><script type="text/javascript">$(".map-iframe").colorbox({width:"530px", height:"650px", iframe:true});$(".search-result").colorbox({width:"730px", height:"650px", iframe:true});' + tooptipvariable + '</script>';

			img = '';

			dbtotal_plus	=	y;
			totladivdetails	=	y;

		});

		$.each(data.set.feed, function(i, feed)	{
			if(feed.empty) {
				return false;
			}

			feedtotal = feed.total;
			if(i % 2 == 0)	{
				classname = 'result-row1';
			} else	{
				classname = 'result-row2';
			}

			var feedCategory = '';
			var pic = '';

			if (feed.category == 1)	{
				perpage = 10;
				feedCategory = '<a target="_blank" href="http://indeed.com" title="indeed.com">indeed.com</a></div>';
				var description	=	feed.desc;
				var feed_add	=	feed.source;
			}
			else if (feed.category == 2)	{
				perpage = 10;
				feedCategory = '<a target="_blank" href="http://ebay.com" title="ebay.com">ebay.com</a></div>';
				pic = '<div class="class-img"><a target="_blank" href="'+feed.flink+'"><img src="'+feed.pic+'"></div>';
				var description	=	feed.desc;
				var feed_add	=	feed.source;
			}
			else if (feed.category == 3)	{
				perpage = 10;
				feedCategory = '<a target="_blank" href="http://foreclosurelistings.com" title="foreclosurelistings.com">foreclosurelistings.com</a></div>';
				pic = '';
				var description	=	feed.desc + ' &raquo; <a class="map-iframe map-link" href="' + baseurl + '/index/gmap/city/' + feed.city + '/latitude/' + feed.latitude + '/longitude/' + feed.longitude + '">Map</a><script type="text/javascript">$(".map-iframe").colorbox({width:"530px", height:"650px", iframe:true});</script>';
				var feed_add	=	'Price: ' + feed.source;
			}
			else if (feed.category == 4)	{
				perpage = 20;
				feedCategory = '<a target="_blank" href="http://oodle.com" title="oodle.com">oodle.com</a></div>';
				pic = '<div class="class-img"><a target="_blank" href="'+feed.flink+'"><img src="'+feed.pic+'" height="75" alt=""></div>';
				var description	=	feed.desc + ' &raquo; <a class="map-iframe map-link" href="' + baseurl + '/index/gmap/city/' + feed.city + '/latitude/' + feed.latitude + '/longitude/' + feed.longitude + '">Map</a><script type="text/javascript">$(".map-iframe").colorbox({width:"530px", height:"650px", iframe:true});</script>';
				var feed_add	=	feed.source;
			}
			else if (feed.category == 5)	{
				perpage = 10;
				feedCategory = '<a target="_blank" href="http://ebay.com" title="ebay.com">ebay.com</a></div>';
				pic = '<div class="class-img"><a target="_blank" href="'+feed.flink+'"><img src="'+feed.pic+'"></div>';
				var description	=	feed.desc;
				var feed_add	=	feed.source;
			}
			else if (feed.category == 11)	{
				perpage = 10;
				var bath_bed	=	'';
				if(feed.bedrooms != '' && feed.bathrooms != '')
					var bath_bed	=	'Bedrooms: ' + feed.bedrooms + ' Bathrooms: ' + feed.bathrooms +' ';
				feedCategory = 'Google</div><div style="float: left; padding-top: 5px;">' + bath_bed + feed.broker + '</div>';

				pic = '<div class="class-img"><img src="'+feed.pic+'" alt="" width="75" /></div>';
				var description	=	feed.desc;
				var mls			=	'';
				if(feed.mls_name != '' && feed.mls_listing_id != '')
					mls			=	' MLS Name : ' + feed.mls_name + ' MLS ID : ' + feed.mls_listing_id
				var feed_add	=	feed.source + mls;
			}

			y++;
			feedtotal_plus++;

			result += '<div class="' + classname + '"><div class="crslt-p1"><div class="s-no">' + y + '</div>' + pic + '<div class="classifieds-result-con"><div class="c-name"><a class="business-name" target="_blank" href="' + feed.flink + '">' + feed.name + '</a></div><div class="class-city">' + feed_add + '<div class="business-address">' + description + '</div></div><div class="class-cat">Source: ' + feedCategory + '</div></div><div class="posted-date">' + feed.published + '</div></div>';

		});

		$('#searchresultandcategory').html(result);
		if(feedtotal)	{
			$('#suggest_span').hide();
			//$('#suggest_span').html('');
		}
		$("#viewallclassifiedsortby").find('option').each(function(){

			if($(this).val() == selectedsortby) {
				$(this).attr("selected",true);
			}

		});

		if(dbtotal_plus > 0 || feedtotal_plus > 0) {
			$('#boxes').hide();
			$("#affiliate_container").hide();
			$('#left_body').show();

			if (dbtotal < feedtotal) {

				total = feedtotal;
				//showing +=	parseInt(dbtotal_plus+feedtotal_plus)+' of '+parseInt(parseInt(total)+parseInt(dbtotal_plus));
				showing +=	parseInt(y) + ' of ' + parseInt(parseInt(total)+parseInt(dbtotal_plus));

			} else  {

				total = dbtotal;
				showing +=	parseInt(dbtotal_plus+feedtotal_plus)+' of '+parseInt(parseInt(total)+parseInt(feedtotal_plus));

			}

	      	$("#pagination").load(baseurl+'/index/pagination/searchType/'+searchType+'/total/'+total+'/curretntPageNumber/'+curretntPageNumber+'/perpage/'+perpage+'/sortby/'+sortby, null, function() { });
			 $('#showing').html(showing);
			 dbtotal_plus = 0;
			 feedtotal_plus = 0;

         } else	{

            $('#boxes').hide();
            $("#affiliate_container").hide();
            $('#left_body').show();
			$('#showing').html('');
			$("#pagination").html('');

			if(searchType == 'classified')	{

				if(data.set.top != undefined)	{

					topresult += 'We found 0 results for your search but we found these Top key words.</center><table>';	

					 $.each(data.set.top, function(i,top)	{
					   topresult += '<tr><td width=40></td><td><b><a href="#" onclick="searchdata(this); return false;" class="linksuggest" id="' + top.name + '">' + top.name + '</a></b></td></tr>';
					});

				} else	{
				   topresult += 'We found 0 results for your search!</center><table>';
				}

				topresult += '</table>';

				if(show_img)	{
					if(show_img != '0')
						topresult += 'Refine your search without images';
				}
				$('#searchresultandcategory').html(topresult);
			} else {

				if(show_img != '0')
					topresult += 'We found 0 results for your search! Refine your search without images';
				else
					topresult += 'We found 0 results for your search!';
	
				$('#searchresultandcategory').html(topresult);

			}
         }
		 $('#ajax_busy').hide();
		 $('.ac_results').hide();
	});
}

function displaydetails(divid) { 
  if ($("#longdetail"+divid).is(":visible")) {
		$("#longdetail"+divid).hide();
		$('#shortdetail'+divid).show();
	} else {
		for (divcount = 0; divcount <= totladivdetails; divcount++) {
			if (divid == divcount) { 
				$('#shortdetail'+divcount).hide();			  
				$('#longdetail'+divcount).show();
			} else {
				$('#shortdetail'+divcount).show();			  
				$('#longdetail'+divcount).hide(); 
			}
		}
	}
}

function closedetails(divid) {
	$('#shortdetail'+divid).show();			  
	$('#longdetail'+divid).hide();
	return false;
}