var SiteConfig = {};

function echo(sMessage) {
    var a = getUrlVars();    
    if (a['dev'] || Cookie.read('dev')) alert(sMessage);
}

if (!console) {
	var console = {
        info: function() {},
        debug: function() {},
        error: function() {},
        warn: function() {},
        dir: function() {},
        dirxml: function() {},
        time: function() {},
        timeEnd: function() {},
        trace: function() {},
        profile: function() {},
        profileEnd: function() {},
        group: function() {},
        groupEnd: function() {}
    };
}

var _Browser = {
	ie: Browser.Engine.trident,
	ie6: Browser.Engine.trident4,
	ie7: Browser.Engine.trident5
};


/* zwraca obiekt zawierajacy zmienne z url'a */
function getUrlVars() {
    var vars = {}, hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        if (vars[hash[0]]) continue;
        vars[hash[0]] = hash[1];
    }
    var i = 0;
    for (var x in vars) i++;
    vars.length = i;
    return vars;
}

// uzywac tych z mootools
function addClassName(oEl, sClassName) {
    if (!oEl.className.match(new RegExp("" + sClassName + "", "i")))
        oEl.className += (oEl.className ? " " : "") + sClassName;
}

function isClassName(oEl, sClassName) {
    if (oEl.className.match(new RegExp("" + sClassName + "", "i")))
        return true;
    else
        return false;
}

function removeClassName(oEl, sClassName) {
    oEl.className = oEl.className.replace(new RegExp(" \\b" + sClassName + "\\b|\\b" + sClassName + "\\b ?", "gi"), "");
}

// uzywac tej z mootools
function getStyle(oEl, sProperty) {
    if (oEl.style[sProperty]) {
        return oEl.style[sProperty];
    } else if (oEl.currentStyle) {
        return oEl.currentStyle[sProperty];
    } else if (document.defaultView && document.defaultView.getComputedStyle) {
        var style = document.defaultView.getComputedStyle(oEl, null)
        return style.getsPropertyValue(sProperty);
    } else {
        return null;
    }
}

function openUrl(new_url) {
  window.location=new_url;
}

/*
    reload POSTEM formularz step5
    uzywana w bookingvalidator i na step5
*/
function autoSubmitBookForm(form_name) {
  document.getElementById(form_name).action = '';
  document.getElementById(form_name).submit();
}


/**
    Obiekt do tworzenia, usuwania, przechwytywania Eventow. 
    Ujednolica nazewnictwo wiekszosci wlasciwosci Eventu (jezeli chodzi o Mozille i IE)
    przypisz do zmiennej 'e' metode 'getEvent' w funkcji/metodzie obslugujacej event aby uzyskac ten efekt.
    autor: pio
    le: 10:04 2008-08-11 by pio
*/
var pioEvent = {  
    addEvent: function (obj, type, fn) {
    	if (obj.addEventListener)
    		obj.addEventListener(type, fn, false);
    	else if (obj.attachEvent) {
    		obj["e"+type+fn] = fn;
    		obj[type+fn] = function() { obj["e"+type+fn](window.event); }
    		obj.attachEvent("on"+type, obj[type+fn]);
    	}
        return fn;
    },

    removeEvent: function (obj, type, fn) {
    	if (obj.removeEventListener)
    		obj.removeEventListener(type, fn, false);
    	else if (obj.detachEvent) {
    		obj.detachEvent("on"+type, obj[type+fn]);
    		obj[type+fn] = null;
    		obj["e"+type+fn] = null;
    	}
    },
    
    getEvent: function () {
    	if (window.event) {
    		return this._formatEvent(window.event);
    	} else {
    		return pioEvent.getEvent.caller.arguments[0];
    	}
    },
    
    _ie: function() {
    	return (document.all && !window.opera);
    },
    
    _formatEvent: function(e) {
        if (this._ie() == true) {
        	e.charCode = (e.type == "keypress") ? e.keyCode : 0;
            e.eventPhase = 2;
            e.isChar = (e.charCode > 0);
            e.pageX = e.clientX + document.body.scrollLeft;
            e.pageY = e.clientY + document.body.scrollTop;
            e.target = e.srcElement;
            e.preventDefault = function () { this.returnValue = false; };
            e.stopPropagation = function () { this.cancelBubble = true; };
            e.timeStamp = (new Date).getTime();
            if (e.type == "mouseout") {
            	e.relatedTarget = e.toElement;
            } else if (e.type == "mouseover") {
                e.relatedTarget = e.fromElement;
            }
        }
        return e;
    }
};

var pioCookie = {  
    set: function(name, val, sec) {
        if (val) {
            document.cookie = name + "=" + escape (val) +
                ((sec) ? "; expires=" + this._time(sec): "");
        } else if (this.get(name)) {
            document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
        }
    },
    get: function(name) {
        var arg = name + "=";
        var aLen = arg.length;
        var cLen = document.cookie.length;
        var i = 0;
        while (i < cLen) {
            var j = i + aLen;
            if (document.cookie.substring(i, j) == arg) {
                return this._getValue(j);
            }
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break; 
        }
        return null;   	
    },
    _time: function(i) {
        if(!i) var i = 0;
        else i = i*1000;
    	var expDate = (new Date).getTime();
        expDate = expDate + i;
        var newDate = new Date(expDate);
        return newDate.toGMTString();
    },
    
    _getValue: function(offset) {
        var end = document.cookie.indexOf (";", offset);
        if (end == -1) {
            end = document.cookie.length;
        }
        return unescape(document.cookie.substring(offset, end));
    }    
};

var Position = {
	size: function(el) {
        return this._create(el.offsetWidth, el.offsetHeight)
	},

	offset: function(el) {
		return this._create(el.offsetLeft, el.offsetTop)
	},      
    
    /**
        * pozycja absolutan
    */
	topLeftOffset : function(el) {
        var y = 0, x = 0;
        while (el != null ) {
            y += el.offsetTop;
            x += el.offsetLeft;
            el = el.offsetParent;
        }
        return this._create(x, y);
	},

	bottomRightOffset: function(el) {
		var topleft = this.topLeftOffset(el);
        return this._plus(this.size(el), topleft);
	},
    
    /**
        * Przegladarka 
    */
	scrollOffset: function() {
		if (window.pageXOffset) {
			return this._create(window.pageXOffset, window.pageYOffset);
		} else if (document.documentElement) {
			return this._create(
                document.body.scrollLeft + document.documentElement.scrollLeft, 
                document.body.scrollTop + document.documentElement.scrollTop);
		} else if (document.body.scrollLeft >= 0) {
			return this._create(document.body.scrollLeft, document.body.scrollTop);
		} else {
			return this._create(0, 0);
		}
	},

	clientSize: function() {
		if (window.innerHeight >= 0) {
			return this._create(window.innerWidth, window.innerHeight);
		} else if (document.documentElement) {
			return this._create(document.documentElement.clientWidth,
					document.documentElement.clientHeight);
		} else if (document.body.clientHeight >= 0) {
			return this._create(document.body.clientWidth,
					document.body.clientHeight);
		} else {
			return this._create(0, 0);
		}
	},
    
    _create : function(a, b) {
		return {x: a, y: b};
	},
    
    _plus: function(o1, o2) {
	    var a = o1.x + o2.x;
        var b = o1.y + o2.y;
        return this._create(a, b);
    }    
};



