/* Call the function only if in ZERO RESULTS*/

function checkURLZERO_2() {
/* URL PARAMETERS / QUERY STRING */
	
	// URL parameter object
	// Case insensitive version without decodeURLcomponent 11-01-2010
	// Based on implementation by Andy E: http://stackoverflow.com/questions/901115/get-querystring-values-with-jquery/2880929#2880929
	querystringSEC = {
		_q: decodeURI(window.location.search.substring(1)), // holds the original querystring, decoded if in greek characters	
		// URL decoding
		_d: function (s) { s+=''; return s.replace(/\+/g, ' '); },
		// Regex for extracting key-value pairs
		_r: /([^&;=]+)=?([^&;]*)/g,
	
		// Get specific value from the original querystring
		get: function(key) {
			return this._map[key.toLowerCase()];
		},			
	
		// Populate the query map and reset the internal querystring
		init: function() {
			var e, key, value;
			while (e = this._r.exec(this._q)) {
				key = e[1].toLowerCase();						
				value = this._d(e[2]);							
				$('#LinksZeroResult007').append("<span id=Re_"+key+">"+value+"</span>");						
			}			
		}	
			
	};
	
	function searchParametersToURL(params, values) {
		// Force array input
		if (!isArray(params)) {
			params = [params]; values = [values];
		}
	
		var resultURL = null;
		var lower_params = new Array();
		var paramString = '';
		for (var i = 0; i < params.length; i++) {
			lower_params[i] = params[i].toLowerCase();	
			// Special case: If you set articletype=0 (both auction and buy now) for a C&B search,
			// it will fail because it is too general, so in this case, we need to change it to articletype=3
			if (qxlVars.is_cars && (lower_params[i] == 'articletype') && (values[i] == 0)) values[i] = 3;	
			paramString += '&' + params[i] + '=' + values[i];
		}
	
		if (qxlVars.is_search) {
			// We are already on a search/search.asp or CarsAndBikes/Search.aspx listing
			// So we can just change the parameter(s) and keep the rest
			resultURL = querystringSEC.buildURL(params, values);
		}
	}
	
	
	function Checker() {
	var urlC = window.location.host;	
			// Setup click handlers for the tabs
			$('#LinksZeroResult007').each(function() {
					$(this).find('span').each(function(i) {
			if ($(this).is("#Re_txtsearch,#Re_articletype,#Re_catg,#Re_itemcondition,#Re_listingtype,#Re_memberclass,#Re_areanr,#Re_txtprixmin,#Re_txtprixmax,#Re_zip")) {				
							// Check to see which Category the search is done
				var myID = $("#CategoryAndLevel option:selected").text();
						   $('#Re_catg').text(myID);
						
				var checkAType = $('#Re_catg').text();
			
				switch(checkAType)
					{
						case "Όλες οι κατηγορίες":
						$('#Re_catg').hide();
						break;				
					}
				
				if (($('#it_noResult_div').length)==0) {
						//Send to DIV MESSAGEPOINT txtSearch, Cat, Country
						var passer = $('#Re_txtsearch').text();	
						var checkAType2 = $('#Re_catg').text();
						var stripWhite = checkAType2.replace(/^\s/g,""); //strip white spaces
						var passer3 = $("#Region option:selected").text();
									
						$('#MessagePoint').html('<span>'+passer+'</span><span class="CatType"><span style="font-size:12px"> ></span> '+stripWhite+'</span><span class="Area"><span style="font-size:12px"> ></span> '+passer3+'</span>');			
						$('#Re_catg').hide(); //hide from URL remover
						$('#Re_txtsearch').hide(); //hide from URL remover
						$('#Re_areanr').hide(); //hide from URL remover
						
						switch(passer3)
						{
							case "Όλοι οι νομοί και χώρες":
							$('.Area').hide();
							break;				
						}
										
						switch(checkAType2)
						{
							case "Όλες οι κατηγορίες":					
							$('.CatType').hide();
							break;			
						}			
						} else {								
								$('#Re_txtsearch').show();
								$('#MessagePoint').remove();
							}
				
				//check to see if counter is ON, if NOT PLACE BACK IN 
				if(($('#n_ActiveUrl').length) == 0){
					var CountArt = $('.n_ListBottomLeft b:eq(1)').text();
					$('#pathCats').append('<span id="n_ActiveUrl"> > <b>'+CountArt+'</b> αποτελέσματα βρέθηκαν για <b>'+passer+'</b></span>');
			}			
			
			//Check to see which ARTICLETYPE it is
			var checkAType = $('#Re_articletype').text();
			switch(checkAType)
			{
				case "0":
				$('#Re_articletype').hide();
				break;
				
				case "1":
				$('#Re_articletype').text("Δημοπρασίες");
				break;	
				
				case "2":
				$('#Re_articletype').text("Σταθερή τιμή");
				break;			
			}
			
			//Check to see which AREA it is
			var areaInfo = $("#Region option:selected").text();
			$('#Re_areanr').text(areaInfo);
			
			//Check to see what type of MEMBER they are 
			var checkAType = $('#Re_memberclass').text();
			switch(checkAType)
			{
				case "0":
				$('#Re_memberclass').hide();
				break;
				
				case "1":
				$('#Re_memberclass').text("Μόνο Ιδιώτες");
				break;	
				
				case "4":
				$('#Re_memberclass').text("Μόνο Επαγγελματίες");
				break;			
			}			
			
			//Check to see what the ITEM CONDITION is 
			var checkICon = $('#Re_itemcondition').text();
			switch(checkICon)
			{
				case "2":
				$('#Re_itemcondition').text("Ελαφρώς μεταχειρισμένο");
				break;
				
				case "3":
				$('#Re_itemcondition').text("Μεταχειρισμένο");
				break;
				
				case "4":
				$('#Re_itemcondition').text("Παλιό");
				break;
				
				case "5":
				$('#Re_itemcondition').text("Ελαττωματικό");
				break;		
				
				case "7":
				$('#Re_itemcondition').text("Καινούρια");
				break;
				
				case "8":
				$('#Re_itemcondition').text("Μεταχειρισμένα");
				break;	
				
				case "0":
				$('#Re_itemcondition').text("Καινούριο");
				break;
				
				case "1":
				$('#Re_itemcondition').text("Καινούριο με συσκευασία");
				break;
				
				case "-1":
				$('#Re_itemcondition').hide();
				break;
						
			}
			
			//Check to see which ArticleType it is
			var checkAType = $('#Re_listingtype').text();
			switch(checkAType)
			{
				case "3":
				$('#Re_listingtype').text("Από 1€");
				break;	
			}
			
			//Check to see PRICE RANGE			
			
			$('#Re_txtprixmin').click(function(event){					
							var currentLink = document.location.href.toLowerCase();	
							var finalRes= currentLink.replace(/&txtprixmin=\d*/," ");						
							window.location.href = finalRes;																			
							$(this).hide("slow");
			});				
						
			$('#Re_txtprixmax').click(function(event){					
							var currentLink = document.location.href.toLowerCase();	
							var finalRes= currentLink.replace(/&txtprixmax=\d*/," ");						
							window.location.href = finalRes;																			
							$(this).hide("slow");	
			});	
			
			$('#Re_zip').click(function(event){					
							var currentLink = document.location.href.toLowerCase();	
							var finalRes= currentLink.replace(/&zip=\d*/,"");						
							window.location.href = finalRes;																			
							$(this).hide("slow");
			});
								
			//Check to see if Article type BID and change to ALL!	
				$('#Re_articletype').click(function(event){
					var Compare = $('#Re_articletype').text();
						if ( Compare =='Δημοπρασίες'){				
							var currentLink = document.location.href.toLowerCase();	
							var sendNew =currentLink.replace("articletype=1", "articletype=0");  //go to ALL products 
							window.location.href = sendNew;																						
						} 
						if ( Compare =='Σταθερή τιμή'){				
							var currentLink = document.location.href.toLowerCase();	
							var sendNew =currentLink.replace("articletype=2", "articletype=0");	 //go to ALL products 
							window.location.href = sendNew;																						
					}
					
					else{ 				
						$(this).hide("slow");									
						}
			});					
			
			//Check to see if MEMBER type changed 	
				$('#Re_memberclass').click(function(event){
					var Compare = $('#Re_memberclass').text();
						if ( Compare =='Μόνο Ιδιώτες'){				
							var currentLink = document.location.href.toLowerCase();	
							var sendNew =currentLink.replace("memberclass=1", "memberclass=0");  //go to ALL products 
							window.location.href = sendNew;																						
						} 
						if ( Compare =='Μόνο Επαγγελματίες'){				
							var currentLink = document.location.href.toLowerCase();	
							var sendNew =currentLink.replace("memberclass=4", "memberclass=0");	 //go to ALL products 
							window.location.href = sendNew;																					
						}					
					else{ 				
						$(this).hide("slow");									
						}
			});		
			
			//Check to see if COUNTRY type changed 	
			var ch = $('#Re_areanr').text();
			switch(ch)
				{
					case "Όλοι οι νομοί και χώρες":					
					$('#Re_areanr').hide();
					break;	
					
					case "Όλοι οι νομοί":					
					$('#Re_areanr').hide();
					break;		
				}		
			
				$('#Re_areanr').click(function(event){					
							var currentLink = document.location.href.toLowerCase();	
							var finalRes= currentLink.replace(/areanr=.../i,"areanr=-1");							
							window.location.href = finalRes;																			
							$(this).hide("slow");
			});						
			
			//Check to see if MEMBER type changed 	
				$('#Re_memberclass').click(function(event){
					var Compare = $('#Re_memberclass').text();
						if ( Compare =='Ιδιώτες'){				
							var currentLink = document.location.href.toLowerCase();	
							var sendNew =currentLink.replace("memberclass=1", "memberclass=0");  //go to ALL products 
							window.location.href = sendNew;																						
						} 
						if ( Compare =='Μόνο Επαγγελματίες'){				
							var currentLink = document.location.href.toLowerCase();	
							var sendNew =currentLink.replace("memberclass=4", "memberclass=0");	 //go to ALL products 
							window.location.href = sendNew;																						
					}
					
					else{ 				
						$(this).hide("slow");									
						}
			});		
			
			//check to see if litingtype is empty, if so hide it
				if (!$.trim($('#Re_itemcondition').text()))
				$('#Re_itemcondition').hide();
				//Check to see for Item Condition and switch!		
					$('#Re_itemcondition').click(function(event){
						var Compare = $('#Re_itemcondition').text();
						if ( Compare =='Μεταχειρισμένα'){						
						var currentLink = document.location.href.toLowerCase();;	
						var sendNew =currentLink.replace("itemcondition=8", "");
						window.location.href = sendNew;	
						$(this).hide("slow");																					
						} 
						
						if ( Compare =='Ελαττωματικό'){						
						var currentLink = document.location.href.toLowerCase();;	
						var sendNew =currentLink.replace("itemcondition=5", "");
						window.location.href = sendNew;	
						$(this).hide("slow");																					
						} 
						
						if ( Compare =='Παλιό'){						
						var currentLink = document.location.href.toLowerCase();;	
						var sendNew =currentLink.replace("itemcondition=4", "");
						window.location.href = sendNew;	
						$(this).hide("slow");																					
						} 
						
						if ( Compare =='Μεταχειρισμένο'){						
						var currentLink = document.location.href.toLowerCase();;	
						var sendNew =currentLink.replace("itemcondition=3", "");
						window.location.href = sendNew;	
						$(this).hide("slow");																					
						} 	
						
						if ( Compare =='Ελαφρώς μεταχειρισμένο'){						
						var currentLink = document.location.href.toLowerCase();;	
						var sendNew =currentLink.replace("itemcondition=2", "");
						window.location.href = sendNew;	
						$(this).hide("slow");																					
						} 	
						
						if ( Compare =='Καινούριο'){						
						var currentLink = document.location.href.toLowerCase();;	
						var sendNew =currentLink.replace("itemcondition=0", "");
						window.location.href = sendNew;	
						$(this).hide("slow");																					
						} 	
						
						if ( Compare =='Καινούριο με συσκευασία'){						
						var currentLink = document.location.href.toLowerCase();;	
						var sendNew =currentLink.replace("itemcondition=1", "");
						window.location.href = sendNew;	
						$(this).hide("slow");																					
						} 	
						
						if ( Compare =='Καινούρια'){						
						var currentLink = document.location.href.toLowerCase();;	
						var sendNew =currentLink.replace("itemcondition=7", "");
						window.location.href = sendNew;		
						$(this).hide("slow");	
																									
					} else{ 				
						return false;										
						}
				});		
				
				//check to see if litingtype is empty, if so hide it
				if (!$.trim($('#Re_listingtype').text()))
				$('#Re_listingtype').hide();
					   
				//if from 1 Euro GO TO ALL				
				$('#Re_listingtype').click(function(event){
					var Compare = $('#Re_listingtype').text();
						if ( Compare =='Από 1€'){				
							var currentLink = document.location.href.toLowerCase();	
							var sendNew =currentLink.replace("listingtype=3", "listingtype=");  //go to ALL products 
							window.location.href = sendNew;		
							$(this).hide("slow");																				
						} 			
					else{ 				
						$(this).hide("slow");									
						}
			});		
											
				
				//Place the x image if txtsearch in category!
				var currentLink = document.location.href.toLowerCase();	
						var finalT = /(txtSearch=[A-Za-z])/i;
						if (currentLink.match(finalT)) {   //if their is a txtSearch inside then do the replacing 				
							$('#Re_catg').css({'background-image':'url("/imgweb/14/V4/misc/remove.png")','cursor':'pointer'});
						 }				 
							
				//when in a specific category and clicked to remove search that word GLOBALLY!
				$('#Re_catg').click(function(event){
						var currentLink = document.location.href.toLowerCase();	
						var finalT = /(txtSearch=[A-Za-z])/i;
						if (currentLink.match(finalT)) {   //if their is a txtSearch inside then do the replacing 					
							var finalRes= currentLink.replace(/catg=...../i,"catg=1");
							window.location.href = finalRes;
							$(this).hide("slow");
						 }
						else{								
						return false;
						}
				});		
						} 			
	else {					
				$(this).hide();						
		 };
		});
		});				
	} 
	
	function persPage() {
		 var urlcheck = window.location.host
		 var secondLevelLocation = pathArray[1];
		 if (urlcheck=='info.ricardo.gr'){
			 if ($('#it_noResult_div').length) {
				 $('#InfoBox').html('<div>Δεν βρέθηκαν προϊόντα για το χρήστη: '+secondLevelLocation+'</div>')
				 $('#MessageTitle').remove();
				 $('.n_ThNailDescTitle').remove();
				 $('.n_ListTableC').remove();
				 $('#WraperResults').remove();
			 }
		 }
		}
	
	// Initialize
	querystringSEC.init();	
	Checker();	
	persPage();
	
	/* Change TEXT on price RANGE */
	var checkAType = $('#Re_txtprixmin').text();
	var newC = checkAType; 
	if (newC =='' ){
		$('#Re_txtprixmin').hide();
		} else {$('#Re_txtprixmin').html('από '+newC);}
			
	var checkAType2 = $('#Re_txtprixmax').text();
	var newC2 = checkAType2; 
		if (newC2 ==''){
			$('#Re_txtprixmax').hide();
		} else {$('#Re_txtprixmax').html('έως '+newC2);	}
		
	/* Change ZIP code */
	var checkAType = $('#Re_zip').text();
	var newD = checkAType; 
	if (newD ==''){
		$('#Re_zip').hide();
		} else {$('#Re_zip').html('Τ.Κ. '+newD);}
	
	//Place the Interesting articles after date PUBLISHED FOR ZERO RESULTS
	$('#WraperResults').insertBefore('#LastUpdate');	
	
	//check to see if all the items in zero results are HIDDEN, so that you can push DIV up
	$("#LinksZeroResult007").each(function(){
       if($(this).children().is(':visible'))
         { return; }
		 else {$(this).remove()}
     });	 
	 		
	  //If nothing is in the selected remove 
	 if ($('#Re_txtsearch').is(':empty')) {$('#Re_txtsearch').hide()};
	 
	 $('.SubTitle').remove(); // remove the subtitle form the extended search, on the EXTENDED SEARCH	 
	 if ($('#listHeader').is(':visible')) { $('#Re_itemcondition').hide(); $('#Re_listingtype').hide(); $('#Re_articletype').hide();  } else{return;} ; //if it finds the search TABS dont show it twice
		
	 //check to see if the απο and έως is empty 	
	var checkAType = $('#Re_txtprixmin').text();
	var newC = checkAType; 
	if (newC =='' || newC=='από  ' ){
		$('#Re_txtprixmin').hide();
		} 
		
	var checkAType = $('#Re_txtprixmax').text();
	var newC = checkAType; 
	if (newC =='' || newC=='έως  ' || newC=='έως 0' ){
		$('#Re_txtprixmax').hide();
		} 		

} 


