$(function(){
    $("#change_lan a").click(function(){
        var getParams = "";
        var searchParams = window.location.getSearchParams();
        for(var key in searchParams){
            if(getParams!="") getParams+="&";
            getParams+=key+"="+searchParams[key];
        }
        if(getParams!="") getParams="?"+getParams;
        window.location.href = "http://"+window.location.hostname+"/"+($(this).attr("lang")=="ENG"?"ENG":"")+getParams;
        return false;
    });
    $("#header_fla").live("click",function(){
        window.location.href = "http://"+window.location.hostname+"/"+($("#change_lan a.active").attr("lang")=="ENG"?"ENG":"");
    });
});


function include( filename,id ) {	// The include() statement includes and evaluates the specified file.
	var js = document.createElement('script');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', filename);
	js.setAttribute('defer', 'defer');
	if(id!==undefined) js.setAttribute('id', id);
	if($('HEAD').find('#'+id).length){
	   $('HEAD').find('#'+id).remove();
	}
	//if(document.getElementsByTagName('HEAD').lenght>0){
	    document.getElementsByTagName('HEAD')[0].appendChild(js);
	//}

	// save include state for reference by include_once
	var cur_file = {};
	cur_file[window.location.href] = 1;

	if (!window.php_js) window.php_js = {};
	if (!window.php_js.includes) window.php_js.includes = cur_file;
	if (!window.php_js.includes[filename]) {
		window.php_js.includes[filename] = 1;
	} else {
		window.php_js.includes[filename]++;
	}

	return window.php_js.includes[filename];
}

function screenSize() {
      var w, h; 
      w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
      h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
      return {w:w, h:h};
}

window.location.getSearchParams = function() {
    var params = {};
    var getParamsStringArray = this.search.replace("?", "").replace("#", "").split("&");
    for (var i = 0; i < getParamsStringArray.length; i++) {
        if (getParamsStringArray[i])
            params[getParamsStringArray[i].split("=")[0]] = getParamsStringArray[i].indexOf("=") >= 0 ? getParamsStringArray[i].split("=")[1] : "";
    }
    return params;
};


