jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

window.onload = function()
{
    if (navigator.product=="Gecko" && navigator.userAgent.indexOf("rv:1.7")>=-1)
    { // blad w Gecko 1.7
	var s=document.body.style;
	s.display="none";
	s.display="";
    }
/*    $("#CP").hide();
    $("#CP").css("position","absolute");
    $("#CP").css("top","0px");
    $("#CP").css("left","0px");
    $("#CP").attr("src","img/clipboard.gif");
    if(CC){
    $("#CP").fadeIn();
    }*/
}

function showSubmenu(nazwa)
{
    if(document.getElementById(nazwa))
    {
	if(document.getElementById(nazwa).style.display == 'block')
    	    document.getElementById(nazwa).style.display="none";
	else
	    document.getElementById(nazwa).style.display="block";
    }

}

function Clipboard(a){
    $.post("ajax.php",{func:"C",I:a},
     function(data){
        if(data){
	$("#"+a).html("oferta w schowku <img src='img/clipboard.gif' height='20' border='0' title='Pokaż schowek' />");
	$("#"+a).attr("href","index2.php?nieruchomosci=schowek");
	$("#"+a).attr("onclick","SA()");
	$("#schowekL").html(" pokaż schowek ("+data+" ofert)<img src='img/clipboard.gif' height='20' border='0' title='Pokaż schowek' style='text-decoration:none;'/>");
      //  alert("Ilość ofert w schowku: "+data);
	
        }
     }
    );
}

function SA(){

    $.cookie("par",window.location.href);

}


function SLA(){
    if(window.location.href.indexOf("user") == -1)
        $.cookie("parL",window.location.href);

}


function LoginPlease(){

    alert("Musisz być zalogowany by móc obejrzeć pełną treść ogłoszenia");
    return false;
}


function GetModels(M,Class_){

	$("#moC").html("<select class='"+Class_+"' style='background:url(img/ajax-loading.gif) no-repeat center;'><option ></option></select>");	
	$.get("/moto/ajax.php",{akcja:"getModels",id:M,klasa:Class_}, function(data){
	    $("#moC").html(data);
	});
    }

function GetMarks(M,Class_)
{

	$("#maC").html("<select class='"+Class_+"' style='background:url(img/ajax-loading.gif) no-repeat center;'><option ></option></select>");	
	$("#moC").html("<select class='"+Class_+"' style='background:url(img/ajax-loading.gif) no-repeat center;'><option ></option></select>");	
	$.get("/moto/ajax.php",{akcja:"getMarks",id:M,klasa:Class_}, function(data){
	    $("#maC").html(data);
	    $("#moC").html("<select name='mo'  class='"+Class_+"'  id='mo'><option value='0'>--</option></select>");	
	});


}



function GetModels2(M,Class_){

	$("#moC1").html("<select class='"+Class_+"' style='background:url(img/ajax-loading.gif) no-repeat center;'><option ></option></select>");	
	$.get("/moto/ajax.php",{akcja:"getModels",id:M,klasa:Class_,xtra:'2'}, function(data){
	    $("#moC1").html(data);
	});
    }

function GetMarks2(M,Class_)
{

	$("#maC1").html("<select class='"+Class_+"' style='background:url(img/ajax-loading.gif) no-repeat center;'><option ></option></select>");	
	$("#moC1").html("<select class='"+Class_+"' style='background:url(img/ajax-loading.gif) no-repeat center;'><option ></option></select>");	
	$.get("/moto/ajax.php",{akcja:"getMarks",id:M,klasa:Class_,xtra:'2'}, function(data){
	    $("#maC1").html(data);
	    $("#moC1").html("<select name='mo' class='"+Class_+"'  id='mo'><option value='0'>--</option></select>");	
	});


}


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"), "");
		    }