var ajaxPage=false;

$(document).ready(function(){
	if(ajaxPage) replaceAnchors ('#mainArea');
});
function replaceAnchors(id){
	$(id).find('a').each(function(){
		$(this).bind('click',pageAnchorClick);
	});
}

function pageAnchorClick(event){
	
	event.stopPropagation();
	var link=$(this).context+'';
	var leftNaviAnchors=$('#leftnaviAccordion').find('a');
	leftNaviAnchors.each(function(){
//		jp(this.href.match(/[^?]*id=([^&]*)/)[1]);
		if (link==this.href) {
			AccordionNavi.openPanel($(this).parents('.AccordionPanel')[0]);
			event.preventDefault();

			if (link.substr(link.length-1,1)!='#' && link.substr(link.length-3,3)!='pdf' && link.substr(0,10)!='javascript'){
				$.get(link,{request:1},function(data){
					$("#ajaxContainer").html(data);
				});
			}
		}
	});

}


/************************ b4 jquery **************************************/

function showInfo(id){
	//alert(id);
	AccordionRight.openPanel(document.getElementById('panel'+id));
}
/************************ Search **************************************/

function is_search(){
	if (document.forms[0].search.value=='')return;
	else document.forms[0].submit();
}
/************************ myFutura **************************************/

function openLoginWindow(id) {
 loginpopup = window.open("https://www.myfutura.eu/4build/loginnopopup.phtml?SPRID="+id,"loginpopup","width=440,height=240,left=270,top=240,screenX=270,screenY=240,scrollbars=no,location=no,status=yes,personalbar=no,resizable=no,toolbar=no,menubar=no");
}

function openLoginWindowEn() {
 loginpopup = window.open("https://www.myfutura.eu/4build/loginnopopup.phtml?SPRID="+id,"loginpopup","width=440,height=240,left=270,top=240,screenX=270,screenY=240,scrollbars=no,location=no,status=yes,personalbar=no,resizable=no,toolbar=no,menubar=no");
}

function blurAnchor(obj){
	if (obj.tagName=='A')obj.blur();
}

function decrypt(string){
	key="banana";
	array_alphabet=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","@","-",".",":","_","%");
	var result="";

	for(i=0;i<string.length;i++){
		var j=0;
		while(j<array_alphabet.length&&string.charAt(i)!=array_alphabet[j])j++;
			position_char=j;
			j=0;
			//alert(string.charAt(i));
		while(j<array_alphabet.length&&key.charAt(i%key.length)!=array_alphabet[j])j++;
			position_key=j;
			position=(position_char-position_key)%array_alphabet.length;
			if(position<0)position+=array_alphabet.length;

			//alert(key.charAt(i%key.length));

			result+=array_alphabet[position];
			//alert(array_alphabet[position]);

	}
	document.location.href=decodeURIComponent(result);
}

function DoLogin(lang_id){

	if (!screen){
		l = 100;
		t = 100;
	}else{
		l=screen.width / 2 -200;
		t=screen.height / 2 -110;
	}
	url = "https://www.myfutura.eu/4build_test1/loginnopopup.phtml?SPRID="+lang_id;
	blogin = window.open(url,"blogin","left="+l+",top="+t+",width=430,height=235,menubars=no");
	blogin.focus();
}

/**************************** DEBUGGING *********************************************/

var jsPromptPre = "";

function jp(promptTXT){
	promptTXT +=' ';
	if(document.getElementById('jsPrompt')){
		lines=promptTXT.split("\n");
		for (i=0;i<lines.length;i++){
			var newP = document.createElement("p");
			var newTXT = document.createTextNode(lines[i]);
			newP.appendChild(newTXT);
			document.getElementById('jsPrompt').appendChild(newP);
		}
	} else jsPromptPre+="\n"+promptTXT;
}
function jd(obj){
	var text ='';
	if (typeof(obj)=='object'){
		for(var key in obj) {
			if (key!='channel'){
				if (obj[key]&&(typeof(obj[key])!='function')) text+=key+" => "+obj[key]+"\n";
			}
//			if (obj[key]) text+=key+" => "+obj[key]+"\n";
		}
		jp(text);
	}
}

