var arrTemp = new Array;
var strLoader = '<img src="/Img/ajax-loader.gif" alt="" class="loading" />';

function getHttp(url){
	if(url == ''){return}
	if (window.ActiveXObject){
		httpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		httpReq = new XMLHttpRequest();
	}
	with(httpReq){
		open("GET", url, false);
	
		setRequestHeader("Content-Type", "text/html; charset=utf-8");
/*		setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2001 00:00:00 GMT" );*/
		send(null);
		if (readyState == 4){
			if(status == 200){
				return responseText;
			}else{
				return ''
				//alert("Chyba pri nacitani stanky "+ status +" : "+ statusText);
			}
		}
	}
	
}
function loadInc(url, strId){
//	$.ajax({ url: url, async: true , success: function(data){
//		objGet(strId).innerHTML = data;
//		}
//		});
	objGet(strId).innerHTML = getHttp(url);
}
function loadIncFunction(url, strId){

	$.ajax({ url: url, async: true , success: function(data){
		if(data.indexOf('$$$')>0){
			var arrText = data.split('$$$');
			if(objGet(strId) != null){
			objGet(strId).innerHTML = arrText[0];
			var arrAct = arrText[1].split('|');
			for(var i = 0; i <= arrAct.length-2 && arrAct[i] != '0'; i++){
			  try{
				with(objGet('li_' + arrAct[i])){
					if(className.substr(0,2) == 'pl'){opnLMf('li_' + arrAct[i]);}
					childNodes[0].style.fontWeight='bold';
					childNodes[0].style.color='#00275A';
				}
				}catch(e)
				{
	       // alert(e)
	      }
			}
			}
		}else{
			window.parent.objGet(strId).innerHTML = data;
		}


	}
	});

/* OLD Version - novou zkusim async ajaxem */
/*
	var strText = getHttp(url);
	if(strText.indexOf('$$$')>0){
		var arrText = strText.split('$$$');
		if(objGet(strId) != null){
		objGet(strId).innerHTML = arrText[0];
		var arrAct = arrText[1].split('|');
		for(var i = 0; i <= arrAct.length-2 && arrAct[i] != '0'; i++){
		  try{
			with(objGet('li_' + arrAct[i])){
				if(className.substr(0,2) == 'pl'){opnLMf('li_' + arrAct[i]);}
				childNodes[0].style.fontWeight='bold';
				childNodes[0].style.color='#00275A';
			}
			}catch(e)
			{
       // alert(e)
      }
		}
		}
	}else{
		window.parent.objGet(strId).innerHTML = strText;
	}
	*/
}
function RootHide(intId,nIdGlob){
	if(intId.toString().length > 0 ){loadIncFunction('http://'+ window.location.hostname + gstrLangLink + '/Execute/RootCategoryHide.asp?rootcat='+intId+'&globcat='+nIdGlob+'&langId='+gintLangLink, 'RootCategory'+nIdGlob);}
}
function RootShow(intId,nIdGlob){
	if(intId.toString().length > 0 ){
      loadIncFunction('http://'+ window.location.hostname + gstrLangLink + '/Execute/RootCategoryGet.asp?rootcat='+intId+'&globcat='+nIdGlob+'&langId='+gintLangLink, 'RootCategory'+nIdGlob);
  }  
}
function opnLMf(intId){
	var objParent = objGet(intId);
	replHtml(objGet(intId),objParent);
}
function opnLM(e){
	if(!e)var e = window.event;
	if(e){var srcEl = e.srcElement? e.srcElement : e.target;}
	var objParent = srcEl;
    e.cancelBubble = true;
    replHtml(srcEl,objParent);
}
function replHtml(obj,objPar){
    while (objPar.tagName.toLowerCase() != 'div'){objPar = objPar.parentNode;}
	var intFloor = objPar.id.replace('RootCategory','');
    with(obj){
		if(tagName.toLowerCase() == 'a'){
			SaveCookies("root", parentNode.id.replace('li_' + intFloor + '_','') + '|' + intFloor, null, null, gstrServerAddressRoot);
		}else{
			if(className.substr(0,2) == 'pl'){
				arrTemp[id] = innerHTML;
				innerHTML = arrTemp[id] + strLoader;
				loadInc('http://'+ window.location.hostname + gstrLangLink + '/Execute/CategorySubGet.asp?cat='+id+'&floor='+intFloor+'&langId='+gintLangLink, id);
				innerHTML = arrTemp[id] + innerHTML;
				className = className.replace('pl','mn');
			}else if(className.substr(0,2) == 'mn'){
				if(!arrTemp[id]){
					arrTemp[id] = innerHTML.substring(0,innerHTML.indexOf('</a>') + 4);
				}
				innerHTML = arrTemp[id];
				className = className.replace('mn','pl');
			}
		}
	}
}
function TopProducersShow(){
	loadIncFunction('http://'+ window.location.hostname + gstrLangLink + '/Execute/TopProducersGet.asp', 'TopProducers');
}

function TopProducersHide(){
	loadIncFunction('http://'+ window.location.hostname + gstrLangLink + '/Execute/TopProducersHide.asp', 'TopProducers');
}

function TopCategoryShow(){
	loadIncFunction('http://'+ window.location.hostname + gstrLangLink + '/Execute/TopCategoryGet.asp', 'TopCategory');
}

function TopCategoryHide(){
	loadIncFunction('http://'+ window.location.hostname + gstrLangLink + '/Execute/TopCategoryHide.asp', 'TopCategory');
}

function TopAkMenuShow() {
    loadIncFunction('http://' + window.location.hostname + gstrLangLink + '/Execute/TopAkMenuGet.asp', 'akmenu');
}

function TopAkMenuHide() {
    loadIncFunction('http://' + window.location.hostname + gstrLangLink + '/Execute/TopAkMenuHide.asp', 'akmenu');
}

