// search options

function explodeArray(item,delimiter) {
tempArray=new Array(1);
var Count=0;
var tempString=new String(item);
while (tempString.indexOf(delimiter)>0) {
tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
Count=Count+1
}
tempArray[Count]=tempString;
return tempArray;
}

function searchEventsDate(city){

 var f = document.getElementById("season_from").value;    
 var t = document.getElementById("season_to").value;    

 location.href = geturl() + '/' + city +'/events/' + f + '/' + t;
}

function searchBoxRedirect(listing){                          
var searchbox = document.getElementById("searchbox").value;     
location.href = geturl() + '/' + getCookie2('cityselect') +'/' + listing +'/' + '?page=1&keyword=' + searchbox;
}                                       

function searchSortedBy(){
var url= window.location.href;
var arrayvalexploded = explodeArray(url,'?');

if(document.getElementById("searchbox") !== null){
var searchbox = document.getElementById("searchbox").value; 
 if(searchbox == ''){
 searchbox = 0;
 }
} else{
var searchbox = 0;
}
if(document.getElementById("searchtype") !== null){
var searchtype = document.getElementById("searchtype").value;
 if(searchtype == ''){
 searchtype = 0;
 } 
} else{
var searchtype = 0;
}   
var searchsort = document.getElementById("sort").value;

var the_length = arrayvalexploded[0].length; 
var last_char= arrayvalexploded[0].charAt(the_length-1);
if (last_char == '/'){
var path = '';
} else{
var path = '/';
}

location.href = arrayvalexploded[0] + path + '?page=1&keywords=' + searchbox + '&type=' + searchtype + '&sort=' + searchsort;
}

function replace_date_mode(str) {
    return str.replace('/','-');
}

function searchTypeBoxRedirect(listing){                          
var searchbox = document.getElementById("searchbox").value;   
location.href = geturl() + '/' + getCookie2('cityselect') +'/' + listing +'/' + '?page=1&keyword=' + searchbox;  
}                                       

function searchTypeDropdown(searchtype, city, typecat){

var url= window.location.href;
var arrayvalexploded = explodeArray(url,'?');
var the_length = arrayvalexploded[0].length; 
var last_char= arrayvalexploded[0].charAt(the_length-1);
if (last_char == '/'){
var path = '';
} else{
var path = '/';
} 
location.href = geturl() + '/' + city + '/' + typecat + '/' + searchtype;
}

function searchfromTypeSortedBy(){
var url= window.location.href;
var arrayvalexploded = explodeArray(url,'?');

if(document.getElementById("searchbox") !== null){
var searchbox = document.getElementById("searchbox").value; 
 if(searchbox == ''){
 searchbox = 0;
 }
} else{
var searchbox = 0;
}
if(document.getElementById("searchtype") !== null){
var searchtype = document.getElementById("searchtype").value;
 if(searchtype == ''){
 searchtype = 0;
 } 
} else{
var searchtype = 0;
}   
var searchsort = document.getElementById("sort").value;

var the_length = arrayvalexploded[0].length; 
var last_char= arrayvalexploded[0].charAt(the_length-1);
if (last_char == '/'){
var path = '';
} else{
var path = '/';
}
                                                           /*keyword*/             /*sort*/
location.href = arrayvalexploded[0] + path + '/' + '' + '/' + searchbox + '/' + searchsort;
}

