//Build a PHP like $_GET Array
var $_GET = {};

document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
    function decode(s) {
        return decodeURIComponent(s.split("+").join(" "));
    }

    $_GET[decode(arguments[1])] = decode(arguments[2]);
});


function prealert(input_array) {
	var x = "";
	for (key in input_array) {
		x += key+" = "+input_array[key]+"\n";
	}
	alert(x);
}

$(function(){
	$("a").click(function(){
		$(this).blur();
	});
	$("a").focus(function(){
		$(this).blur();
	});
	
	
	/** Korrekturen für MSIE 6 **/
	if ($.browser.msie==true && $.browser.version=="6.0") {
		/** PNG FIX **/
		 
		/** TOPMENU FIX **/
			$('#topnav .level1').mouseover(function(){
				$("ul.submenu", this).show();
			}).mouseout(function(){
				$("ul.submenu", this).hide();
			});
			
			//$('#page').css("margin-top", "120px");
			$('#header').css("position", "absolute").css("z-index", "9999999").css("top", "0px").css("left", "0px");
			
		/** Startseite Overlay Fix**/
			$('#dot_map .dot').mouseover(function(){
				$("a", this).show();
			}).mouseout(function(){
				$("a", this).hide();
			});
			
			/* IE6 Hinweis */
			$('#header').after("<div id='ie6Msg'>Unsere Seiten sind für aktuelle Browser programmiert. Um den vollen Umfang nutzen zu können, führen Sie bitte ein<br /> Browserupdate aus. Dies wird auch zu Ihrer eigenen Internet-Sicherheit dringend empfohlen.</div>");
			
	}
	
});

if(SERVER_HTTP_HOST().indexOf("stadtreklame") > -1 || SERVER_HTTP_HOST().indexOf("p122198") > -1){
	//p122198 ist der online Testserver
    var ENV = "production";
    var baseUrl = SERVER_HTTP_HOST() + "/ci_admin/";
    var baseUrlFileadmin = baseUrl.replace(/ci_admin\//i, "");
}else{
    var ENV = "local";
    var baseUrl = SERVER_HTTP_HOST() + "/KUNDEN/stadtreklameT3/ci_admin/";
    
}

function SERVER_HTTP_HOST(){
	var url = window.location.href;
	url = url.replace("http://", "");

	var urlExplode = url.split("/");
	var serverName = urlExplode[0];

	serverName = 'http://'+serverName;
	return serverName;
}




/** 
 * Zeigt ein Web2.0 LoadingOverlay mit LoadingIndicator an.
 * Skaliert ausserdem automatisch auf die Dimensionen von "object" oder des gesamten Fensters!!
 **/
function showOverlay(object, loadingDiv_ID){
	if (loadingDiv_ID=="" || typeof(loadingDiv_ID)=="undefined" || typeof(loadingDiv_ID)==undefined) {
		loadingDiv_ID = "#divLoading";
	}
	
	try {
		var offset = $(object).offset();
		var newHeight = $(object).outerHeight();
		var newWidth = $(object).outerWidth();
		var pos_x = offset.left;
		var pos_y = offset.top;
	}
	catch (e) {
		var newHeight = $(document).outerHeight();
		var newWidth = "100%";
		var pos_x = 0;
		var pos_y = 0;		
	}
	/*
	var av_height = screen.availHeight;
	var center = (av_height/2) + scrolltop;
	var offset_from_center = center - (tab_height*2);
	*/
	$(loadingDiv_ID).height(newHeight);
	$(loadingDiv_ID).css("width", newWidth);
	$(loadingDiv_ID).css("top", pos_y);
	$(loadingDiv_ID).css("left", pos_x);
	if (newWidth==0 || newHeight==0) {
		return;
	}
	else {
		$(loadingDiv_ID).show();
	}
	// alert("newWidth "+newWidth+"  newHeight"+newHeight);
}


// Versteckt das Overlay wieder
function hideOverlay(){
	$(loadingDiv_ID).hide();
}


//MERKLISTE
function merklisteAddItem(id, type){
    $.ajax({
        type: "POST",
        url: baseUrl + "merkliste/merklisteAddItem/",
        cache: false,
        data: "&id=" + id + "&type=" + type,
        async: true,
        success: function(data) {
            alert("Zur Merkliste hinzugefügt");
        }
    });
    return false;
}

function merklisteRemoveItem(id, type, idObjHide){
    $.ajax({
        type: "POST",
        url: baseUrl + "merkliste/merklisteRemoveItem/",
        cache: false,
        data: "&id=" + id + "&type=" + type,
        async: true,
        success: function(data) {
            if(idObjHide != ""){
                 $('#' + idObjHide).addClass('toBeFadedOut');
                $('#' + idObjHide).fadeOut('slow');
            }
        }
    });
    return false;
}

 /** Größe des Anzeigebereichs "#page" automatisch einstellen **/
function resize_page_height() {
    var current_height = $('#page').height();
    var new_height = current_height;
    var offet = $('#page').offset();
    var availHeight = $(document).height();
    var minusHeight = $('#footer').height();

    if ( (current_height+offet.top-minusHeight) < availHeight) new_height = current_height+offet.top-minusHeight;
    $('#page').height(new_height);
}