function advAJAX() {

    var obj = new Object();

    obj.url = window.location.href;
    obj.method = "GET";
    obj.parameters = new Object();
    obj.jsonParameters = new Object();
    obj.headers = new Object();
    obj.async = true;
    obj.mimeType = "text/xml";
    obj.username = null;
    obj.password = null;
    obj.form = null;
    obj.disableForm = true;

    obj.unique = true;
    obj.uniqueParameter = "_uniqid";

    obj.requestDone = false;
    obj.queryString = "";
    obj.responseText = null;
    obj.responseXML = null;
    obj.status = null;
    obj.statusText = null;
    obj.aborted = false;
    obj.timeout = 0;
    obj.retryCount = 0;
    obj.retryDelay = 1000;
    obj.tag = null;
    obj.group = null;
    obj.progressTimerInterval = 50;

    obj.xmlHttpRequest = null;

    obj.onInitialization = null;
    obj.onFinalization = null;
    obj.onReadyStateChange = null;
    obj.onLoading = null;
    obj.onLoaded = null;
    obj.onInteractive = null;
    obj.onComplete = null;
    obj.onProgress = null;
    obj.onSuccess = null;
    obj.onFatalError = null;
    obj.onError = null;
    obj.onTimeout = null;
    obj.onRetryDelay = null;
    obj.onRetry = null;
    obj.onGroupEnter = null;
    obj.onGroupLeave = null;

    obj.createXmlHttpRequest = function() {

        if (typeof XMLHttpRequest != "undefined")
            return new XMLHttpRequest();
        var xhrVersion = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
                "MSXML2.XMLHttp","Microsoft.XMLHttp" ];
        for (var i = 0; i < xhrVersion.length; i++) {
            try {
                var xhrObj = new ActiveXObject(xhrVersion[i]);
                return xhrObj;
            } catch (e) { }
        }
        obj.raiseEvent("FatalError");
        return null;
    };

    obj._oldResponseLength = null;
    obj._progressTimer = null;
    obj._progressStarted = navigator.userAgent.indexOf('Opera') == -1;
    obj._onProgress = function() {

        if (typeof obj.onProgress == "function" &&
            typeof obj.xmlHttpRequest.getResponseHeader == "function") {
            var contentLength = obj.xmlHttpRequest.getResponseHeader("Content-length");
            if (contentLength != null && contentLength != '') {
                var responseLength = obj.xmlHttpRequest.responseText.length;
                if (responseLength != obj._oldResponseLength) {
                    obj.raiseEvent("Progress", obj, responseLength, contentLength);
                    obj._oldResponseLength = obj.xmlHttpRequest.responseText.length;
                }
            }
        }
        if (obj._progressStarted) return;
        obj._progressStarted = true;
        var _obj = this;
        this.__onProgress = function() {
            obj._onProgress();
            obj._progressTimer = window.setTimeout(_obj.__onProgress, obj.progressTimerInterval);
        }
        _obj.__onProgress();
    }

    obj._onInitializationHandled = false;
    obj._initObject = function() {

        if (obj.xmlHttpRequest != null) {
            delete obj.xmlHttpRequest["onreadystatechange"];
            obj.xmlHttpRequest = null;
        }
        if ((obj.xmlHttpRequest = obj.createXmlHttpRequest()) == null)
            return null;
        if (typeof obj.xmlHttpRequest.overrideMimeType != "undefined")
            obj.xmlHttpRequest.overrideMimeType(obj.mimeType);
        obj.xmlHttpRequest.onreadystatechange = function() {

            if (obj == null || obj.xmlHttpRequest == null)
                return;
            obj.raiseEvent("ReadyStateChange", obj, obj.xmlHttpRequest.readyState);
            obj._onProgress();
            switch (obj.xmlHttpRequest.readyState) {
                case 1: obj._onLoading(); break;
                case 2: obj._onLoaded(); break;
                case 3: obj._onInteractive(); break;
                case 4: obj._onComplete(); break;
            }
        };
        obj._onLoadingHandled =
            obj._onLoadedHandled =
            obj._onInteractiveHandled =
            obj._onCompleteHandled = false;
    };

    obj._onLoading = function() {

        if (obj._onLoadingHandled)
            return;
        if (!obj._retry && obj.group != null) {
            if (typeof advAJAX._groupData[obj.group] == "undefined")
                advAJAX._groupData[obj.group] = 0;
            advAJAX._groupData[obj.group]++;
            if (typeof obj.onGroupEnter == "function" && advAJAX._groupData[obj.group] == 1)
                obj.onGroupEnter(obj);
        }
        obj.raiseEvent("Loading", obj);
        obj._onLoadingHandled = true;
    };
    obj._onLoaded = function() {

        if (obj._onLoadedHandled)
            return;
        obj.raiseEvent("Loaded", obj);
        obj._onLoadedHandled = true;
    };
    obj._onInteractive = function() {

        if (obj._onInteractiveHandled)
            return;
        obj.raiseEvent("Interactive", obj);
        obj._onInteractiveHandled = true;
        if (!obj._progressStarted)
            obj._onProgress();
    };
    obj._onComplete = function() {

        if (obj._onCompleteHandled || obj.aborted)
            return;
        if (obj._progressStarted) {
            window.clearInterval(obj._progressTimer);
            obj._progressStarted = false;
        }
        obj.requestDone = true;
        with (obj.xmlHttpRequest) {
            obj.responseText = responseText;
            obj.responseXML = responseXML;
            if (typeof status != "undefined")
                obj.status = status;
            if (typeof statusText != "undefined")
                obj.statusText = statusText;
        }
        obj.raiseEvent("Complete", obj);
        obj._onCompleteHandled = true;
        if (obj.status == 200)
            obj.raiseEvent("Success", obj); else
            obj.raiseEvent("Error", obj);
        //delete obj.xmlHttpRequest['onreadystatechange'];
        obj.xmlHttpRequest = null;
        if (obj.disableForm)
            obj.switchForm(true);
        obj._groupLeave();
        obj.raiseEvent("Finalization", obj);
    };

    obj._groupLeave = function() {

        if (obj.group != null) {
            advAJAX._groupData[obj.group]--;
            if (advAJAX._groupData[obj.group] == 0)
                obj.raiseEvent("GroupLeave", obj);
        }
    };

    obj._retry = false;
    obj._retryNo = 0;
    obj._onTimeout = function() {

        if (obj == null || obj.xmlHttpRequest == null || obj._onCompleteHandled)
            return;
        obj.aborted = true;
        obj.xmlHttpRequest.abort();
        obj.raiseEvent("Timeout", obj);
        obj._retry = true;
        if (obj._retryNo != obj.retryCount) {
            obj._initObject();
            if (obj.retryDelay > 0) {
                obj.raiseEvent("RetryDelay", obj);
                startTime = new Date().getTime();
                while (new Date().getTime() - startTime < obj.retryDelay);
            }
            obj._retryNo++;
            obj.raiseEvent("Retry", obj, obj._retryNo);
            obj.run();
        } else {
            delete obj.xmlHttpRequest["onreadystatechange"];
            obj.xmlHttpRequest = null;
            if (obj.disableForm)
                obj.switchForm(true);
            obj._groupLeave();
            obj.raiseEvent("Finalization", obj);
        }
    };

    obj.run = function() {

        obj._initObject();
        if (obj.xmlHttpRequest == null)
            return false;
        obj.aborted = false;
        if (!obj._onInitializationHandled) {
            obj.raiseEvent("Initialization", obj);
            obj._onInitializationHandled = true;
        }
        if (obj.method == "GET" && obj.unique)
            obj.parameters[encodeURIComponent(obj.uniqueParameter)] =
            new Date().getTime().toString().substr(5) + Math.floor(Math.random() * 100).toString();
        if (!obj._retry) {
            for (var a in obj.parameters) {
                if (obj.queryString.length > 0)
                    obj.queryString += "&";
                if (typeof obj.parameters[a] != "object")
                    obj.queryString += encodeURIComponent(a) + "=" + encodeURIComponent(obj.parameters[a]); else {
                    for (var i = 0; i < obj.parameters[a].length; i++)
                        obj.queryString += encodeURIComponent(a) + "=" + encodeURIComponent(obj.parameters[a][i]) + "&";
                    obj.queryString = obj.queryString.slice(0, -1);
                }
            }
            for (var a in obj.jsonParameters) {
                var useJson = typeof [].toJSONString == 'function';
                if (obj.queryString.length > 0)
                    obj.queryString += "&";
                obj.queryString += encodeURIComponent(a) + "=";
                if (useJson)
                    obj.queryString += encodeURIComponent(obj.jsonParameters[a].toJSONString()); else
                    obj.queryString += encodeURIComponent(obj.jsonParameters[a]);
            }
            if (obj.method == "GET" && obj.queryString.length > 0)
                obj.url += (obj.url.indexOf("?") != -1 ? "&" : "?") + obj.queryString;
        }
        if (obj.disableForm)
            obj.switchForm(false);
        try {
            obj.xmlHttpRequest.open(obj.method, obj.url, obj.async, obj.username || '', obj.password || '');
        } catch (e) {
            obj.raiseEvent("FatalError", obj, e);
            return;
        }
        if (obj.timeout > 0)
            setTimeout(obj._onTimeout, obj.timeout);
        if (typeof obj.xmlHttpRequest.setRequestHeader != "undefined")
            for (var a in obj.headers)
                obj.xmlHttpRequest.setRequestHeader(encodeURIComponent(a), encodeURIComponent(obj.headers[a]));
        if (obj.method == "POST" && typeof obj.xmlHttpRequest.setRequestHeader != "undefined") {
            obj.xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            obj.xmlHttpRequest.send(obj.queryString);
        } else if (obj.method == "GET")
            obj.xmlHttpRequest.send('');
    };

    obj.handleArguments = function(args) {

        if (typeof args.form == "object" && args.form != null) {
            obj.form = args.form;
            obj.appendForm();
        }
        for (a in args) {
            if (typeof obj[a] == "undefined")
                obj.parameters[a] = args[a]; else {
                if (a != "parameters" && a != "headers")
                    obj[a] = args[a]; else
                    for (b in args[a])
                        obj[a][b] = args[a][b];
            }
        }
        obj.method = obj.method.toUpperCase();
    };

    obj.switchForm = function(enable) {

        if (typeof obj.form != "object" || obj.form == null)
            return;
        with (obj.form)
            for (var nr = 0; nr < elements.length; nr++)
                if (!enable) {
                    if (elements[nr]["disabled"])
                        elements[nr]["_disabled"] = true; else
                        elements[nr]["disabled"] = "disabled";
                } else
                    if (typeof elements[nr]["_disabled"] == "undefined")
                        elements[nr].removeAttribute("disabled");
    };

    obj.appendForm = function() {

        with (obj.form) {
            obj.method = getAttribute("method").toUpperCase();
            obj.url = getAttribute("action");
            for (var nr = 0; nr < elements.length; nr++) {
                var e = elements[nr];
                if (e.disabled)
                    continue;
                switch (e.type) {
                    case "text":
                    case "password":
                    case "hidden":
                    case "textarea":
                        obj.addParameter(e.name, e.value);
                        break;
                    case "select-one":
                        if (e.selectedIndex >= 0)
                            obj.addParameter(e.name, e.options[e.selectedIndex].value);
                        break;
                    case "select-multiple":
                        for (var nr2 = 0; nr2 < e.options.length; nr2++)
                            if (e.options[nr2].selected)
                                obj.addParameter(e.name, e.options[nr2].value);
                        break;
                    case "checkbox":
                    case "radio":
                        if (e.checked)
                            obj.addParameter(e.name, e.value);
                        break;
                }
            }
        }
    };

    obj.addParameter = function(name, value) {
        if (typeof obj.parameters[name] == "undefined")
            obj.parameters[name] = value; else
        if (typeof obj.parameters[name] != "object")
            obj.parameters[name] = [ obj.parameters[name], value ]; else
        obj.parameters[name][obj.parameters[name].length] = value;
    };
    obj.delParameter = function(name) {

        delete obj.parameters[name];
    };
    obj.raiseEvent = function(name) {
        var args = [];
        for (var i = 1; i < arguments.length; i++)
            args.push(arguments[i]);
        if (typeof obj["on" + name] == "function")
            obj["on" + name].apply(null, args);
        if (name == "FatalError")
            obj.raiseEvent("Finalization", obj);
    }

    if (typeof advAJAX._defaultParameters != "undefined")
        obj.handleArguments(advAJAX._defaultParameters);
    return obj;
}

advAJAX.get = function(args) {

    return advAJAX.handleRequest("GET", args);
};

advAJAX.post = function(args) {

    return advAJAX.handleRequest("POST", args);
};

advAJAX.head = function(args) {

    return advAJAX.handleRequest("HEAD", args);
};

advAJAX.submit = function(form, args) {

    if (typeof args == "undefined" || args == null)
        return -1;
    if (typeof form != "object" || form == null)
        return -2;
    var request = new advAJAX();
    args["form"] = form;
    request.handleArguments(args);
    return request.run();
};

advAJAX.assign = function(form, args) {

    if (typeof args == "undefined" || args == null)
        return -1;
    if (typeof form != "object" || form == null)
        return -2;
    if (typeof form["onsubmit"] == "function")
        form["_onsubmit"] = form["onsubmit"];
    form["advajax_args"] = args;
    form["onsubmit"] = function() {
        if (typeof this["_onsubmit"] != "undefined" && this["_onsubmit"]() === false)
            return false;
        if (advAJAX.submit(this, this["advajax_args"]) == false)
            return true;
        return false;
    }
    return true;
};

advAJAX.download = function(targetObj, url) {

    if (typeof targetObj == "string")
        targetObj = document.getElementById(targetObj);
    if (!targetObj)
        return -1;
    advAJAX.get({
        url: url,
        onSuccess : function(obj) {
            targetObj.innerHTML = obj.responseText;
        }
    });
};

advAJAX.scan = function() {

    var obj = document.getElementsByTagName("a");
    for (var i = 0; i < obj.length;) {
        if (obj[i].getAttribute("rel") == "advancedajax" && obj[i].getAttribute("href") !== null) {
            var url = obj[i].getAttribute("href");
            var div = document.createElement("div");
            div.innerHTML = obj[i].innerHTML;
            div.className = obj[i].className;
            var parent = obj[i].parentNode;
            parent.insertBefore(div, obj[i]);
            parent.removeChild(obj[i]);
            advAJAX.download(div, url);
        } else i++;
    }
};

advAJAX.handleRequest = function(requestType, args) {

    if (typeof args == "undefined" || args == null)
        return -1;
    var request = new advAJAX();
    window.advajax_obj = request;
    request.method = requestType;
    request.handleArguments(args);
    return request.run();
};

advAJAX._defaultParameters = new Object();
advAJAX.setDefaultParameters = function(args) {

    advAJAX._defaultParameters = new Object();
    for (a in args)
        advAJAX._defaultParameters[a] = args[a];
};

advAJAX._groupData = new Object();

function load_categories(selected){
	var selected_category = selected;
	advAJAX.setDefaultParameters({
	onInitialization : function(obj) { 
		disable_search_from(true);
		document.forms.search_form.search_products_categories.options.length=0;
		document.forms.search_form.search_products_categories.options[0]=new Option("pobieranie danych...", "pobieranie danych...", false, false);
	},
	onLoading : function(obj) { 
		disable_search_from(true);
	},
	onSuccess : function(obj) {
		eval(obj.responseText);
		document.forms.search_form.search_products_categories.options.length=0;
		for (i=0; i<subcategories_id.length; i++){
			if(selected==subcategories_id[i]){
				document.forms.search_form.search_products_categories.options[i]=new Option(subcategories[i], subcategories_id[i], false, true);
			}
			else{
				document.forms.search_form.search_products_categories.options[i]=new Option(subcategories[i], subcategories_id[i], false, false);
			}
		}
		
		disable_search_from(false);
	},
	onError : function(obj) { 
		alert("Brak danych...");
	}
	});
	advAJAX.get({ url: "/ajax?type=search_categories"});
	advAJAX.setDefaultParameters({});
}
function load_subcategories(cid, selected){
	advAJAX.setDefaultParameters({
	onInitialization : function(obj) { 
		disable_search_from(true);
		document.forms.search_form.search_products_subcategories.options.length=0;
		document.forms.search_form.search_products_subcategories.options[0]=new Option("pobieranie danych...", "pobieranie danych...", false, false);
	},
	onLoading : function(obj) { 
		disable_search_from(true);
	},
	onSuccess : function(obj) {
		eval(obj.responseText);
		document.forms.search_form.search_products_subcategories.options.length=0;
		for (i=0; i<subcategories_id.length; i++){
			if(selected==subcategories_id[i]){
				document.forms.search_form.search_products_subcategories.options[i]=new Option(subcategories[i], subcategories_id[i], false, true);
			}
			else{
				document.forms.search_form.search_products_subcategories.options[i]=new Option(subcategories[i], subcategories_id[i], false, false);
			}
		}
		
		disable_search_from(false);
	},
	onError : function(obj) { 
		alert("Brak danych...");
	}
	});
	advAJAX.get({ url: "/ajax?type=search_subcategories&cid="+cid});
	advAJAX.setDefaultParameters({});
}
function load_manufactures(cid, selected){
	advAJAX.setDefaultParameters({
	onInitialization : function(obj) { 
		disable_search_from(true);
		document.forms.search_form.search_products_manufactures.options.length=0;
		document.forms.search_form.search_products_manufactures.options[0]=new Option("pobieranie danych...", "pobieranie danych...", false, false);
	},
	onLoading : function(obj) { 
		disable_search_from(true);
	},
	onSuccess : function(obj) {
		eval(obj.responseText);
		document.forms.search_form.search_products_manufactures.options.length=0;
		for (i=0; i<manufactures_id.length; i++){
			if(selected==manufactures_id[i]){
				document.forms.search_form.search_products_manufactures.options[i]=new Option(manufactures[i], manufactures_id[i], false, true);
			}
			else{
				document.forms.search_form.search_products_manufactures.options[i]=new Option(manufactures[i], manufactures_id[i], false, false);
			}
		}
		
		disable_search_from(false);
	},
	onError : function(obj) { 
		alert("Brak danych...");
	}
	});
	advAJAX.get({ url: "/ajax?type=search_manufactures&cid="+cid});
	advAJAX.setDefaultParameters({});
}
function select_category(cid, selected){
	if(cid){
		var selected_category = cid;
	}
	else{
		var selected_category = document.forms.search_form.search_products_categories.options[document.forms.search_form.search_products_categories.selectedIndex].value;
	}
	advAJAX.setDefaultParameters({
	onInitialization : function(obj) { 
		disable_search_from(true);
		document.forms.search_form.search_products_subcategories.options.length=0;
		document.forms.search_form.search_products_subcategories.options[0]=new Option("pobieranie danych...", "pobieranie danych...", false, false);
	},
	onLoading : function(obj) { 
		disable_search_from(true);
	},
	onSuccess : function(obj) { 
		eval(obj.responseText);
		document.forms.search_form.search_products_subcategories.options.length=0;
		for (i=0; i<subcategories_id.length; i++){
			if(selected==subcategories_id[i]){
				document.forms.search_form.search_products_subcategories.options[i]=new Option(subcategories[i], subcategories_id[i], false, true);
			}
			else{
				document.forms.search_form.search_products_subcategories.options[i]=new Option(subcategories[i], subcategories_id[i], false, false);
			}
		}
		
		disable_search_from(false);
		if(subcategories_id[0]==""){
			if(selected!=-1){
				select_manufacture(selected_category);
			}
		}
		else{
			if(!selected){
				select_manufacture(selected_category);
			}
		}
	},
	onError : function(obj) { 
		alert("Brak danych...");
	}
	});
	advAJAX.get({ url: "/ajax?type=search_subcategories&cid="+selected_category});
	advAJAX.setDefaultParameters({});
}

function select_manufacture(cid, selected){
	if(cid){
		var selected_subcategory = cid;
	}
	else{
		var selected_subcategory = document.forms.search_form.search_products_subcategories.options[document.forms.search_form.search_products_subcategories.selectedIndex].value;
	}
	advAJAX.setDefaultParameters({
	onInitialization : function(obj) { 
		disable_search_from(true);
		document.forms.search_form.search_products_manufactures.options.length=0;
		document.forms.search_form.search_products_manufactures.options[0]=new Option("pobieranie danych...", "pobieranie danych...", false, false);
	},
	onLoading : function(obj) { 
		disable_search_from(true);
	},
	onSuccess : function(obj) {
		eval(obj.responseText);
		document.forms.search_form.search_products_manufactures.options.length=0;
		for (i=0; i<manufactures_id.length; i++){
			if(selected==manufactures_id[i]){
				document.forms.search_form.search_products_manufactures.options[i]=new Option(manufactures[i], manufactures_id[i], false, true);
			}
			else{
				document.forms.search_form.search_products_manufactures.options[i]=new Option(manufactures[i], manufactures_id[i], false, false);
			}
		}
		
		disable_search_from(false);
	},
	onError : function(obj) { 
		alert("Brak danych...");
	}
	});
	advAJAX.get({ url: "/ajax?type=search_manufactures&cid="+selected_subcategory});
	advAJAX.setDefaultParameters({});
}
function disable_search_from(state){
	if(state){
		document.forms.search_form.search_products_manufactures.disabled=true;
		document.forms.search_form.search_products_description.disabled=true;
		document.getElementById("bt_search").disabled=true;
		//document.getElementById("bt_search").style.visibility="hidden";
	}
	else{
		document.forms.search_form.search_products_manufactures.disabled=false;
		document.forms.search_form.search_products_description.disabled=false;
		document.getElementById("bt_search").disabled=false;
		//document.getElementById("bt_search").style.visibility="visible";
	}
	
}
function order_product(product_id, product_title, product_index){
	var quantity  = document.getElementById("quantity_"+product_id).value;
	advAJAX.setDefaultParameters({
	onInitialization : function(obj) { 
		document.getElementById("quantity_"+product_id).disabled=true;
	},
	onLoading : function(obj) { 
		
	},
	onSuccess : function(obj) {
		if(obj.responseText!="false"){
			eval(obj.responseText);
			document.getElementById("quantity_"+product_id).disabled=false;
			document.getElementById("quantity_"+product_id).value=0;
			try {
           		document.getElementById("product_in_order_"+product_id).innerHTML = "<img src=\"/images/checked.gif\" width=\"17\" height=\"17\" alt=\"Produkt znajduje się już w zamówieniu.\">";
        	} catch (e) {
			document.getElementById("quantity_"+product_id).value=quantity;
			}
			$.cartbox.load();
		}
	},
	onError : function(obj) { 
		document.getElementById("quantity_"+product_id).disabled=true;
		document.getElementById("quantity_"+product_id).value=document.getElementById("quantity_min_"+product_id).value;
	}
	});
	advAJAX.get({ url: "/ajax_orders?products_id="+product_id+"&quantity="+quantity});
	advAJAX.setDefaultParameters({});
}
function add_product_to_wishlist(product_id, product_title, product_index){
	var quantity  = document.getElementById("quantity_"+product_id).value;
	advAJAX.setDefaultParameters({
	onInitialization : function(obj) { 
	},
	onLoading : function(obj) { 
		
	},
	onSuccess : function(obj) {
		if(obj.responseText!="false"){
			$.wishlistbox.load();
		}
	},
	onError : function(obj) { 
		document.getElementById("quantity_"+product_id).disabled=true;
		document.getElementById("quantity_"+product_id).value=document.getElementById("quantity_min_"+product_id).value;
	}
	});
	advAJAX.get({ url: "/wishlist.php?products_id="+product_id});
	advAJAX.setDefaultParameters({});
}
var isloaded=0;
function load_searchengine_delay(delay)
{
	if(location.href.search(/product_info/)>-1 || location.href.search(/search/)>-1){
		var t=setTimeout("load_searchengine()",delay);
	}
	else{
		if(isloaded==0){
			var t=setTimeout("load_searchengine()",delay);
			isloaded=1;
		}
	}
}
function load_catalog_delay(delay)
{
	var c=setTimeout("load_catalog()",delay);
}
function load_catalog(){
	document.getElementById("catalog").style.display="block";
	if(document.getElementById("search_products_description").value != "Kod, nazwa lub opis produktu"){
		document.getElementById("search_products_description").style.color="#4A4A4A";
	}
}
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   submitSearch();
   return false;
   }
else
   return true;
}
function open_help(help_file) {
	width=780;
	height=585;
	var Win = window.open(help_file,"help",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no, menubar=no,left='+((screen.width-850)/2)+',top='+((screen.height-600)/2)+',location=no,directories=no,status=no,toolbar=no' );
}

function focusLogin(){
	if(document.getElementById("login").value=="Twój login"){
		document.getElementById("login").value="";
	}
}					
function blurLogin(){
	sText = document.getElementById("login").value;
	sText = sText.replace(/\s/g,'');
	if(sText==""){
		document.getElementById("login").value="Twój login";
	}
}
function focusPasswd(){
	//if(document.getElementById("password").value=="Hasło"){
		document.getElementById("password").value="";
	//}
}					
function blurPasswd(){
	sText = document.getElementById("password").value;
	sText = sText.replace(/\s/g,'');
	if(sText==""){
		document.getElementById("password").value="Hasło";
	}
}
function focusSearch(){
	if(document.getElementById("search_products_description").value=="Kod, nazwa lub opis produktu"){
		document.getElementById("search_products_description").value="";
	}
}					
function blurSearch(){
	searchText = document.getElementById("search_products_description").value;
	searchText = searchText.replace(/\s/g,'');
	if(searchText==""){
		document.getElementById("search_products_description").value="Kod, nazwa lub opis produktu";
	}
}
function submitSearch(){
	manufacturesText = document.getElementById("search_products_manufactures").value;
	searchText = document.getElementById("search_products_description").value;
	searchText = searchText.replace(/\s/g,'');
	if((searchText=="" || searchText=="Kod,nazwalubopisproduktu") && manufacturesText=="all"){
		alert("Proszę wpisać kod, nazwę, opis produktu lub wybrać producenta, aby przeprowadzić wyszukiwanie!");
	}
	else{
		if((searchText=="" || searchText=="Kod,nazwalubopisproduktu") && manufacturesText!="all"){
			document.getElementById("search_products_description").value = "all";	
		}
		else{
			document.getElementById("search_products_description").value = document.getElementById("search_products_description").value;
		}
		document.search_form.submit();
	}	
}
function toggleMenu(el, over)
{
    if (over) {
		$(el).addClass("over");
    }
    else {
        $(el).removeClass("over");
    }
}
function microtime(get_as_float) {

    var now = new Date().getTime() / 1000;
    var s = parseInt(now);

    return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s;
}

$(document).ready(function() {
	//load_catalog();
	/*menu*/
	$("#my_account_bt").mouseover(function(){
		var offset = $(this).offset();
		$("#usersubmenu").css({left:offset.left-24,top:offset.top+55});
		$("#usersubmenu").show();
	   });
	$('#usersubmenu').bind('mouseleave', function() {
		$(this).hide();
	});
});

;(function($){
	$.cartbox = {
	    init : function(id) {
			showOrHide = false;
			$('.cart-box-actions-button').click(function() {
				if ( showOrHide == false ) {
					clearTimeout($.cartbox.t);
				    $.cartbox.show();
					showOrHide = true;
				} else if ( showOrHide == true ) {
				  	$.cartbox.hide();
				  	showOrHide = false;
				}
			});

			$(".cart-box-products").css("height", ($(window).height()-109));
			
			$(window).resize(function() {  
				$.cartbox.resize();
			});
			
			$.cartbox.load('stop');		
			/*
			var loc = window.location.toString();
			if (loc.indexOf("/account") > -1) {
				$.cartbox.t = setTimeout($.cartbox.show, 2000);
				$.cartbox.t = setTimeout($.cartbox.hide, 4000);
			}
			*/
	    },
	    load : function(opt) {
			$.cartbox.ajax = $.ajax({
				url: '/cart.php?' + microtime(),
				beforeSend: function() {
					$(".cart-box-actions").html("Pobieranie danych.");
			    	clearTimeout($.cartbox.t);
					if(opt!='stop'){
						$.cartbox.show();
					}
				},
				success: function(data) {
					var products = jQuery.parseJSON(data);
					var productLength = products.length;
	                if(productLength > 0){
						var data = '<ul class="cart-box-products-items">';		
						for (var i = 0; i < (productLength-1); i++){				
							data += '<li><div class="cart-box-item"><div class="cart-box-item-image"><a href="/edit_order?order_id='+products[i]['customers_basket_id']+'"><img src="'+products[i]['image']+'"/></a></div><div class="cart-box-item-index">'+products[i]['products_index']+'</div></div><div class="cart-box-item-price">'+products[i]['products_price']+' ('+products[i]['customers_basket_quantity']+' '+products[i]['quantity_type_name']+')</div><div class="cart-box-item-actions"><a onClick="$.cartbox.remove('+products[i]['customers_basket_id']+');">Usuń</a>&nbsp;&nbsp;<a href="/edit_order?order_id='+products[i]['customers_basket_id']+'">Zmień ilość</a></div></li>';
						}
						data += '</ul>';
	                    $(".cart-box-products").html(data);
						$("#total_products").html(products[productLength-1]['total_products']);

						var cartSummary = '';
						cartSummary += '<ul>';
						cartSummary += '<li>Liczba produktów w koszyku: '+products[productLength-1]['total_products']+'</li>';
						cartSummary += '<li>Wartość netto: '+products[productLength-1]['total_netto']+'</li>';
						cartSummary += '<li>Wartość brutto: '+products[productLength-1]['total_brutto']+'</li>';
						if(productLength > 1){
							cartSummary += '<li><a href="/new_orders" title="Złóż zamówienie">Złóż zamówienie</a> | <a onClick="$.cartbox.remove(\'all\');" title="Usuń wszystkie produkty z koszyka">Usuń wszystkie</a></li>';
						}
						else{
							cartSummary += '<li><a href="/login">Zaloguj się, aby dodać produkty</a></li>';
						}
						cartSummary += '</ul>';
						$(".cart-box-actions").html(cartSummary);
						$('.cart-box-products').scrollbar();
					}
					else{
						$(".cart-box-products").html('Brak produktów w koszyku.');
					}
					if(opt!='stop'){
						$.cartbox.t = setTimeout($.cartbox.hide, 2000);
					}
				},
				error: function() {
					$.cartbox.reportError();
				},
			});
		},
	    remove : function(id) {
			$.cartbox.ajax = $.ajax({
				url: '/cart.php?delete='+id,
				beforeSend: function() {
					$(".cart-box-actions").html("Usuwanie produktów.");
				},
				success: function(data) {
					$.cartbox.load();
				},
				error: function() {
					$.cartbox.reportError();
				},
			});
	    },
	    show : function(id) {
			$('#cart-box').stop(true, false).animate({right: 0}, {duration: 'slow', easing: 'easeOutExpo'});
	    },
	    hide : function(id) {
			$('#cart-box').stop(true, false).animate({right: -202}, {duration: 'slow', easing: 'easeOutExpo'});
	    },
	    resize : function(id) {
			$(".cart-box-products").css("height", ($(window).height()-109));
			$.cartbox.load();
	    },
	    reportError : function(response) {
	        $(".cart-box-products").html('Nie pobrano informacji o produktach!');
	    }
	};
})(jQuery);

$(document).ready(function() {
	$.cartbox.init();
});

/*wishlist*/

;(function($){
	$.wishlistbox = {
	    init : function(id) {
			showOrHideWishlist = false;
			$('.wishlist-box-actions-button').click(function() {
				if ( showOrHideWishlist == false ) {
					clearTimeout($.wishlistbox.t);
				    $.wishlistbox.show();
					showOrHideWishlist = true;
				} else if ( showOrHideWishlist == true ) {
				  	$.wishlistbox.hide();
				  	showOrHideWishlist = false;
				}
			});
			
			$(".wishlist-box-products").css("height", ($(window).height()-109));
			
			$(window).resize(function() {  
				$.wishlistbox.resize();
			});
			$.wishlistbox.load('stop');		
			/*
			var loc = window.location.toString();
			if (loc.indexOf("/account") > -1) {
				$.wishlistbox.t = setTimeout($.wishlistbox.show, 4000);
				$.wishlistbox.t = setTimeout($.wishlistbox.hide, 6000);
			}
			*/
	    },
	    load : function(opt) {
			$.wishlistbox.ajax = $.ajax({
				url: '/wishlist.php?' + microtime(),
				beforeSend: function() {
					
					$(".wishlist-box-actions").html("Wczytywanie danych.");
			    	clearTimeout($.wishlistbox.t);
					if(opt!='stop'){
						$.wishlistbox.show();
					}
				},
				success: function(data) {
					var products = jQuery.parseJSON(data);
					var productLength = products.length;
	                if(productLength > 0){
						var data = '<ul class="wishlist-box-products-items">';		
						for (var i = 0; i < (productLength-1); i++){				
							data += '<li><div class="cart-box-item"><div class="cart-box-item-image"><a href="/product_info/'+products[i]['products_id']+'/"><img src="'+products[i]['image']+'"/></a></div><div class="cart-box-item-index">'+products[i]['products_index']+'</div></div><div class="cart-box-item-price">'+products[i]['products_price']+'</div><div class="cart-box-item-actions"><a onClick="$.wishlistbox.remove('+products[i]['customers_wishlist_id']+');">Usuń</a>&nbsp;&nbsp;<a onClick="$.wishlistbox.copyToCart('+products[i]['products_id']+');">Kopiuj do koszyka</a></div></li>';
						}
						data += '</ul>';
	                    $(".wishlist-box-products").html(data);
						var wishlistSummary = '';
						wishlistSummary += '<ul>';
						wishlistSummary += '<li>Liczba produktów w schowku: '+products[productLength-1]['total_products']+'</li>';
						wishlistSummary += '<li>Wartość netto: '+products[productLength-1]['total_netto']+'</li>';
						wishlistSummary += '<li>Wartość brutto: '+products[productLength-1]['total_brutto']+'</li>';
						if(productLength > 1){
							wishlistSummary += '<li><a onClick="$.wishlistbox.remove(\'all\');"  title="Usuń wszystkie produkty ze schowka">Usuń wszystkie</a> | <a onClick="$.wishlistbox.copyToCart(\'all\');" title="Kopiuj wszystkie produkty do koszyka">Kopiuj do koszyka</a></li>';
						}
						else{
							wishlistSummary += '<li><a href="/login">Zaloguj się, aby użyć schowka</a></li>';
						}
						wishlistSummary += '</ul>';
						$(".wishlist-box-actions").html(wishlistSummary);
						$('.wishlist-box-products').scrollbar();
					}
					else{
						$(".wishlist-box-products").html('Brak produktów w schowku.');
					}
					if(opt!='stop'){
						$.wishlistbox.t = setTimeout($.wishlistbox.hide, 2000);
					}
				},
				error: function() {
					$.wishlistbox.reportError();
				},
			});
		},
	    remove : function(id) {
			$.wishlistbox.ajax = $.ajax({
				url: '/wishlist.php?delete='+id,
				beforeSend: function() {
					$(".wishlist-box-actions").html("Usuwanie produktów.");
				},
				success: function(data) {
					$.wishlistbox.load();
				},
				error: function() {
					$.wishlistbox.reportError();
				},
			});
	    },
		copyToCart : function(id) {
			$.wishlistbox.ajax = $.ajax({
				url: '/wishlist.php?copyToCart='+id,
				beforeSend: function() {
					$(".cart-box-actions").html("Pobieranie danych.");
			    	clearTimeout($.cartbox.t);
					$.cartbox.show();
				},
				success: function(data) {
					$.cartbox.load();
				},
				error: function() {
					$.wishlistbox.reportError();
				},
			});
	    },
	    show : function(id) {
			$('#wishlist-box').stop(true, false).animate({left: 0}, {duration: 'slow', easing: 'easeOutExpo'});
	    },
	    hide : function(id) {
			$('#wishlist-box').stop(true, false).animate({left: -202}, {duration: 'slow', easing: 'easeOutExpo'});
	    },
	    resize : function(id) {
			$(".wishlist-box-products").css("height", ($(window).height()-109));
			$.wishlistbox.load();
	    },
	    reportError : function(response) {
	        $(".wishlist-box-products").html('Nie pobrano informacji o produktach!');
	    }
	};
})(jQuery);

$(document).ready(function() {
	$.wishlistbox.init();
});

/*myaccount*/
/*
;(function($){
	$.myaccount = {
	    init : function(id) {
			$("#my-account").css("display", "block");
			$('#my-account').mouseover(function() {
				clearTimeout($.myaccount.t);
			    $.myaccount.show();
			});
			$('#my-account').mouseleave(function() {
			    $.myaccount.hide();
			});
			var loc = window.location.toString();
			if (loc.indexOf("/account") > -1) {
				$.myaccount.t = setTimeout($.myaccount.show, 0);
				$.myaccount.t = setTimeout($.myaccount.hide, 2000);
			}
	    },
	    show : function(id) {
			$('#my-account').stop(true, false).animate({top: 0}, {duration: 'slow', easing: 'easeOutExpo'});
	    },
	    hide : function(id) {
			$('#my-account').stop(true, false).animate({top: -150}, {duration: 'slow', easing: 'easeOutExpo'});
	    }
	};
})(jQuery);

$(document).ready(function() {
	if(logged){
		$.myaccount.init();
	}
});
*/
/*animation*/

;(function($){
	$.mainanimation = {
	    init : function(id) {
			this.scene = 2;
			$('.s1').click(function() {
				$.mainanimation.show(1);
			});
			$('.s2').click(function() {
				$.mainanimation.show(2);
			});
			$('.s3').click(function() {
				$.mainanimation.show(3);
			});
			$('.s1').mouseover(function() {
				clearTimeout($.mainanimation.t);
				$('.s1').fadeTo('fast', 0.5, function() {});
			});
			$('.s2').mouseover(function() {
				clearTimeout($.mainanimation.t);
				$('.s2').fadeTo('fast', 0.5, function() {});
			});
			$('.s3').mouseover(function() {
				clearTimeout($.mainanimation.t);
				$('.s3').fadeTo('fast', 0.5, function() {});
			});
			$('.s1').mouseleave(function() {
				clearTimeout($.mainanimation.t);
			    $.mainanimation.t = setTimeout($.mainanimation.play, 5000);
				$('.s1').fadeTo('fast', 1, function() {});
			});
			$('.s2').mouseleave(function() {
				clearTimeout($.mainanimation.t);
			    $.mainanimation.t = setTimeout($.mainanimation.play, 5000);
			   $('.s2').fadeTo('fast', 1, function() {});
			});
			$('.s3').mouseleave(function() {
				clearTimeout($.mainanimation.t);
			    $.mainanimation.t = setTimeout($.mainanimation.play, 5000);
				$('.s3').fadeTo('fast', 1, function() {});
			});
			$.mainanimation.t = setTimeout($.mainanimation.play, 5000);
			
	    },
	    show : function(scene) {
			if(scene == 1){
				$('.animation-main-big-scenes').stop(true, false).animate({left: 0}, {duration: 'slow', easing: 'easeOutExpo'});
				$.mainanimation.scene = 2;
			}
			if(scene == 2){
				$('.animation-main-big-scenes').stop(true, false).animate({left: -632}, {duration: 'slow', easing: 'easeOutExpo'});
				$.mainanimation.scene = 3;
			}
			if(scene == 3){
				$('.animation-main-big-scenes').stop(true, false).animate({left: -1264}, {duration: 'slow', easing: 'easeOutExpo'});
				$.mainanimation.scene = 1;
			}
	    },
	    play : function() {
			clearTimeout($.mainanimation.t);
			$('.s'+$.mainanimation.scene).fadeTo('fast', 0.2, function() {
				$(this).fadeTo('fast', 1, function() {})
			});

			if($.mainanimation.scene == 1){
				$('.animation-main-big-scenes').stop(true, false).animate({left: 0}, {duration: 'slow', easing: 'easeOutExpo'});
			}
			if($.mainanimation.scene == 2){
				$('.animation-main-big-scenes').stop(true, false).animate({left: -632}, {duration: 'slow', easing: 'easeOutExpo'});
			}
			if($.mainanimation.scene == 3){
				$('.animation-main-big-scenes').stop(true, false).animate({left: -1264}, {duration: 'slow', easing: 'easeOutExpo'});
			}
			if($.mainanimation.scene == 3){
				$.mainanimation.scene = 1;
			}
			else{
				$.mainanimation.scene++;
			}
			$.mainanimation.t = setTimeout($.mainanimation.play, 5000);
	    }
	};
})(jQuery);

$(document).ready(function() {
	try {
         $.mainanimation.init();
    } catch (e) {}
	$('.f1').mouseover(function() {
		$('.f1').fadeTo('fast', 0.5, function() {});
		$('#promodiv').css('position','absolute');
		$('#promodiv').fadeTo('fast', 1, function() {});
	});
	$('.f2').mouseover(function() {
		$('.f2').fadeTo('fast', 0.5, function() {});
	});
	$('.f3').mouseover(function() {
		$('.f3').fadeTo('fast', 0.5, function() {});
	});
	$('.f1').mouseleave(function() {
		$('.f1').fadeTo('fast', 1, function() {});
		$('#promodiv').css('display','none');
		$('#promodiv').fadeTo('fast', 0, function() {
			$('#promodiv').css('display','none');
		});
	});
	$('.f2').mouseleave(function() {
	   $('.f2').fadeTo('fast', 1, function() {});
	});
	$('.f3').mouseleave(function() {
		$('.f3').fadeTo('fast', 1, function() {});
	});
});

