var server="buysale.ro"
var LUNGIME_MIN_CHEI=3;
var CHEI_DEFAULT="Cauta text, id sau telefon";

$(document).ready (function(){
    var bgColorOdd="#FFFFBB",bgColorHover="#CFCDFF";
    $("#list .row").mouseleave(function(){
        $(this).css("border-left"," thin dotted #FFFFEB");
        $(this).css("border-right"," thin dotted #FFFFEB");
    });
    $("#list .row").mouseover(function(){
        $(this).css("border-left"," thin dotted #336699");
        $(this).css("border-right"," thin dotted #336699");
    });
    $("#list .row:odd").css("background-color",bgColorOdd);

    $("#list .row .anunt").click(function(){
        $("#list .row").preventDefault();
    });
    $(".companieImg").simpletip({
        content:"Anunt dat de companie",
        fixed:false
    });
    $("#chei").click (function () {
        this.value='';
    });
    $('#chei').blur(function () {
        if (this.value.length<=2) this.value=CHEI_DEFAULT;
    });

});


function loadinparent(url, closeSelf){
    location.href = url;
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}



function noenter(e) {
    evt = e || window.event;
    var keyPressed = evt.which || evt.keyCode;
    return !(keyPressed == 13);
}

//    return !(window.event && window.event.keyCode == 13); }

function row_highlight (d){
    div=d;
    div.style.backgroundColor="#FFFFBB";
}


function page_highlight(obj){
    obj.style.backgroundImage='/images/pag.png';
}

function page_clean(obj) {
    obj.style.backgroundImage= '';
}

function setHomepage()
{
    if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage('http://'+server);
 
    }
    else if (window.sidebar)
    {
        if(window.netscape)
        {
            try
            {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch(e)
            {
                alert("Aceasta actiune a fost blocata de browser. Poti adauga manual adresa noastra ca pagina implicita pentru browserul tau.");
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage','http://www.asp.net/130.aspx');
    }
}

function row_clean(d) {
    div=d;
    div.style.backgroundColor="transparent";
}



//            function resetAndSubmitForm() {
//                document.form_filtru.chei.value='';
//                document.form_filtru.id='';
//                document.form_filtru.idCat.selectedIndex=0;
//                document.form_filtru.idJudet.selectedIndex=document.form_filtru.idJudet.options.length-1;
//                document.form_filtru.submit();
//            }


function clearFiltruPret(sel) {
    if (isNaN(sel.value)) sel.value='';
}

function fillFIltruPret(sel) {
    if (isNaN(sel.value) || sel.value==null || sel.value=='') if(sel.name=='pret_min') sel.value='De la'; else sel.value='Pana la';
}
function getSearchKey() {
    return ((document.form_filtru.chei.value.length>=LUNGIME_MIN_CHEI && document.form_filtru.chei.value!=CHEI_DEFAULT)?("cauta/"+document.form_filtru.chei.value.replace(/ /g, "-")+"/"):'');
}

function getURLCategorie(reset) {
    parinte='';
    selObj=document.getElementById("idCat");
    if(reset) return '';//(selObj.options[0].text + "/").toLowerCase();
    if(selObj.selectedIndex>1 && !selObj.options[selObj.selectedIndex].text.match(/^ +/) ){
        index=selObj.selectedIndex;
        if(!selObj.options[index].text.match(/^\s+/)) {
            for( i =index;i>=1;i-- ) {
                if(selObj.options[i].text.match(/^\s+/) && index!=i ) {
                    parinte= trim(selObj.options[i].text,"\\s").replace(/ /g, "-")+"/";
                    break;
                }
            }
        }
    }
    if(selObj.selectedIndex==0) return '';
    return (parinte +trim(selObj.options[selObj.selectedIndex].text,"\\s").replace(/ /g, "-") + "/").toLowerCase() ;
}

function getURLJudet(reset) {
    selObj=document.getElementById("idJudet");
    if(reset) return "index.html";
    if(selObj.selectedIndex==0) return 'index.html';
    return selObj.options[selObj.selectedIndex].text.toLowerCase() + ".html";
}


function categorieJump(targ,restore){ //v3.0
    eval(targ+".location='/anunturi/" + getURLCategorie(false) + getSearchKey()+((  document.getElementById('idLocalitate').selectedIndex>0)?getURLJudet(false):getURLJudet(true)) + "'");
    if (restore) selObj.selectedIndex=0;
}

function judetJump(targ,selObj,restore){ //v3.0
    if(selObj.options[selObj.selectedIndex].text.toLowerCase()=="bucuresti") eval(targ+".location='http://bucuresti." + server + "/anunturi/" + getURLCategorie(false) + getSearchKey()+getURLJudet(false)+"'");
    else  eval(targ+".location='http://" + server + "/anunturi/" + getURLCategorie(false) + getSearchKey()+getURLJudet(false)+"'");
    if (restore) selObj.selectedIndex=0;
} 

function localitateJump(targ,selObj,restore){ //v3.0 
    if(selObj.options[selObj.selectedIndex].value==0 ) {
        judetJump(targ, document.getElementById("idJudet"), restore);
    }else {
        eval(targ +".location='http://" + selObj.options[selObj.selectedIndex].text.replace(/ /g, "-")+"."+ server + "/anunturi/"+ getURLCategorie() + getSearchKey()+ getURLJudet()+"'");
    }
    if (restore) selObj.selectedIndex=0;
}
 
function debug(msg) {
    div=document.getElementById("debug");
    div.innerHTML=msg;
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}