// loc_search=where~|lat~|lon~|miles~|market_id

var allCookies = document.cookie;
var whereValue = '';
var latValue = '';
var lonValue = '';
var milesValue = '';
var market_idValue = '';
var cookieName = "loc_search";
var splitValue = "~|";

function pop_form() {

    var start=document.cookie.indexOf(cookieName);
    if (start!=-1) {start+=(cookieName.length+1);}
    var end=document.cookie.indexOf(";", start);
    if (end == -1) {end=document.cookie.length;}
    var cookies=unescape(document.cookie.substring(start, end));
    var cookiesArray=cookies.split(splitValue);

    if (start!=-1) { 
        if (cookiesArray[0]) {whereValue    =cookiesArray[0];}
        if (cookiesArray[1]) {latValue      =cookiesArray[1];}
        if (cookiesArray[2]) {lonValue      =cookiesArray[2];}
        if (cookiesArray[3]) {milesValue    =cookiesArray[3];}
        if (cookiesArray[4]) {market_idValue=cookiesArray[4];}

        if (document.ls_top) {
            if (whereValue && document.ls_top.where) {
                document.ls_top.where.value = whereValue;
            }
        }
    
        //marco's hack
        if (document.need_where) {
            if (whereValue && document.need_where.where) {
                document.need_where.where.value = whereValue;
            }
        }
    
        if (document.navigate) {
            if (whereValue && document.navigate.where) {
                document.navigate.where.value = whereValue;
            } 
        }
    
        if (document.ls_top){
            if (latValue && document.ls_top.lat) {
                document.ls_top.lat.value = latValue;
            }
            if (lonValue && document.ls_top.lon) {
                document.ls_top.lon.value = lonValue;
            }
            if (milesValue && document.ls_top.miles) {
                document.ls_top.miles.value = milesValue;
            }
            if (market_idValue && document.ls_top.market_id) {
                document.ls_top.market_id.value = market_idValue;
            }
        }
    }
}

pop_form();

