// JavaScript Document

/* 
	search for 'isec hx' to find isec specific hacks... 
	mostly needed to fix paths references etc
*/

//ajax-file used for getting articls 
var mm_ajaxfile = 'incs/ajax-resp4.php'; //isec hx


// document on-loaded function
$(document).ready(function() { 


	
	//handlers for scoyo cmd btns
	$(".cmdbtn").click(function() {
				tmp=this.id;
				if(tmp=='btn_cmd2'){
					finit_togglecontent('show','accs');
					finit_togglecontent('show','tabs');
				}
				else if(tmp=='btn_cmd3'){
					finit_togglecontent('hide','accs');
					finit_togglecontent('hide','tabs');
				}
	})
	
	
	//b:handlers for ui btns
	/*
	//var A on-click change  
	$(".abtn").click(function() {
				fshow_content(this.id);
	})
	*/
	
	//var B on-mouseover change
	$(".abtn").mouseover(function(){
     	fshow_content(this.id);
	}).mouseout(function(){
		//
    });
	//e:handlers for ui btns

	//hide teasers
	finit_togglecontent('hide','tabs');
	finit_togglecontent('hide','accs');
	
	/******************************************/
	/* <? scoyo buttons ?> */
	var t	= '';
	$(".sbtn").mouseover(function(){
		$("#" + this.id).removeClass("scoyobtn2a_blue");
		$("#" + this.id).addClass("scoyobtn2a_green");
		$("#" + this.id + "_r").removeClass("scoyobtn2b_blue");
		$("#" + this.id + "_r").addClass("scoyobtn2b_green");
		
    }).mouseout(function(){
		$("#" + this.id).removeClass("scoyobtn2a_green");
		$("#" + this.id).addClass("scoyobtn2a_blue");
		$("#" + this.id + "_r").removeClass("scoyobtn2b_green");
		$("#" + this.id + "_r").addClass("scoyobtn2b_blue");

    });
	
	/*<? //flag code ?>*/
	$(".xflag").mouseover(function(){
		if(this.id.indexOf('cas')>-1){t="La p&aacute;gina en espa&#241;ol";}
		if(this.id.indexOf('cat')>-1){t="La p&agrave;gina en catal&agrave;";}//à
		if(this.id.indexOf('eng')>-1){t="Page in english";}
		if(this.id.indexOf('ale')>-1){t="Seite auf Deutsch";}	
		$("#" + "xflag_fb").removeClass('xhidden');
		$("#" + "xflag_fb").addClass('xshown');		
		$("#" + "xflag_fb").html(t);
    }).mouseout(function(){
		$("#" + "xflag_fb").removeClass('xshown');
		$("#" + "xflag_fb").addClass('xhidden');		
 		$("#" + "xflag_fb").html('');
    });
	
	$(".xflag").click(function() {
		var xval	= 'cas';
		if(this.id.indexOf('cat')>-1){xval='cat';}
		if(this.id.indexOf('eng')>-1){xval='eng';}
		if(this.id.indexOf('ale')>-1){xval='ale';}	
		js_X(xval,'txthd_lang');
	});

	/*<? //login form ?>*/
	t	= "transparent url(li-blue.png) no-repeat";
	$("#xlogin_star").css("background",t);	/*<? //on load... ?>*/
	$("#xlogin_star").mouseover(function(){
		t	= "transparent url(li-green.png) no-repeat";
		$("#xlogin_star").css("background",t);
    }).mouseout(function(){
		t	= "transparent url(li-blue.png) no-repeat";
		$("#xlogin_star").css("background",t);
    });
	
	/*<? //maintain green if in txtbox  ?>*/
	$("#xlogin_form").mouseover(function(){
		t	= "transparent url(li-green.png) no-repeat";
		$("#xlogin_star").css("background",t);
    })
	
	/*<? //--section-tab+acc code ?>*/
	$(".abtn").each(function (i) {
		$('#' + this.id).addClass('xbtn_passive');
	  });
	

	$(".abtn").mouseover(function(){
		/*<? //get type 'tab' or 'acc' ?>*/
		var xtype = "tab"; 
		if(this.id.indexOf('tab')>-1){
			xtype="acc";
		}
		/*<? //reset type to passive ?>*/
		$(".abtn").each(function (i) {
			if(this.id.indexOf(xtype)){
				$('#' + this.id).removeClass('xbtn_active');
				$('#' + this.id).addClass('xbtn_passive');
			}
		});
		/*? //set active ?>*/
		$('#' + this.id).removeClass('xbtn_passive');
		$('#' + this.id).addClass('xbtn_active');

    }).mouseout(function(){
		$('#' + this.id).removeClass('xbtn_passive');
		$('#' + this.id).addClass('xbtn_active');
		
    });
	
	
	/*<? //.scoyobtn clicked ?>*/
	$(".sbtn").click(function() {
		alert('clicked xx=' + this.id);						  
	});
	
	/*<? /*initialize code; 
		set tab1,acc7 active, show teasers , maintable
	?>*/
	$("#acc7").removeClass('xbtn_passive');
	$("#acc7").addClass('xbtn_active');	
	$("#tab1").removeClass('xbtn_passive');
	$("#tab1").addClass('xbtn_active');	
	$("#teaser_acc7").show();
	$("#teaser_tab1").show();
	
	//fly-in
	//if($("#" + 'el_flyin').val().length == 0){
		/*<? //start fly-in ?> */
		//$("#pa").css("visibility","visible");
		//startAp();
		/*<? //only wanted on first load ?> */
		//$("#" + 'el_flyin').val("1"); 
	//}
	
	//loading img
	$("#xloading").hide();

	
});//end doc-ready
function fdbg(p){
	p = p + ', ' + $('#el_fb').html();
	$('#el_fb').html(p);
}
function fshow_content(pid){
	//first hide all the others...
	if(pid.indexOf('acc')>-1){
		finit_togglecontent('hide','accs');
	}else{
		finit_togglecontent('hide','tabs');
	}
	
	//then show the curr one...
	tmp	= '#teaser_' + pid;
	$(tmp).show();
}
function finit_togglecontent(pbshow,pcategory){
	//pcategory is either 'tabs' or 'acc'
	//pbshow is 'show'to show else hides
	
	tmp='';
	for(var i=1;i<8;i++){
		if(pcategory=='accs'){
			tmp	= '#teaser_acc' + i;
			if(pbshow=='show'){$(tmp).show();}
			else{$(tmp).hide();}
		}
		
		if(i<4){
			if(pcategory=='tabs'){
				tmp		='#teaser_tab' + i;
				if(pbshow=='show'){$(tmp).show();}
				else{$(tmp).hide();}
			}
		}
	}
}
function js_X(pval,pelid)
{
	 //sets cookie, submits
	 
	 var c_name	="";
	 var c_val	="";
	 if(pelid=="txthd_lang"){
		 c_val		=pval;
		 c_name		="pl_lang";			//cas||cat||eng||ale
		 
		 //write cookie
		 jsg_setCookie(c_name,c_val,180);
		 //maintain postback act if needed
		 document.getElementById('el_pbact').value="LANGCHANGE";
	 }
	 
	if(document.getElementById(pelid)){
		document.getElementById(pelid).value=pval;
	}
	document.forms[0].submit();
}
function js_qpar( name )
{
  /* get (http://www.netlobo.com/url_query_string_javascript.html) */
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
function jsg_setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function jsg_getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
}

function jsg_checkCookie(c_name)
{
	var xid="";
		
	c_name="pl_lang";
	var x =jsg_getCookie(c_name);
	if (x!=null && x!="")
	  {
			xid="l_" + x;
			var e=document.getElementById(xid);
			e.setAttribute("class", "pl-btn-selected");
			e.setAttribute("className", "pl-btn-selected"); // for IE which does not recognize "class"
	  }
	
	
	c_name="pl_size";
	var x =jsg_getCookie(c_name);
	if (x!=null && x!="")
	  {
			if(x=="12"){
				xid="f_s";
			}
			else{
				xid="f_b";
			}
			var e=document.getElementById(xid);
			e.setAttribute("class", "pl-btn-selected");
			e.setAttribute("className", "pl-btn-selected"); // for IE which does not recognize "class"
		}
	  
	c_name="pl_screen";
	var x =jsg_getCookie(c_name);
	if (x!=null && x!="")
	  {
			if(x=="small"){
				xid="s_s";
			}
			else{
				xid="s_b";
			}
			var e=document.getElementById(xid);
			e.setAttribute("class", "pl-btn-selected");
			e.setAttribute("className", "pl-btn-selected"); // for IE which does not recognize "class"
	  }


	//set an id cookie
	c_name="pl_id";
	var x =jsg_getCookie(c_name);
	if(x==null || x==""){
		var id	= Math.floor(Math.random()*1000000000);
		jsg_setCookie(c_name,"id"+id,180);
	}

}
/**********************/
/**********************/
/* THE AJAX-CALL PROC */
/**********************/
/**********************/
function js_ajaxrequest(pid){
	var sLang	=	"cas";				//default to cast
	var sCurr	=	'';

	if(document.getElementById('txthd_lang')){
		sCurr	=	document.getElementById('txthd_lang').value;
	}
	
	if(sCurr!=""){
		sLang		= sCurr;
	}

	postData	= "content="+pid+"&lang="+sLang;

	//<? //do the ajax call ?>
	var ncase	=	"111";
	var xurl	=	mm_ajaxfile; 
	var data	=	postData;
	
	$("#article_container").html('');
	$("#xloading").show();

	$.ajax({
		url: xurl,	
		type: "GET",		
		data: data,		
		cache: false,
		success: function (html) {
			switch(ncase){
			case("111"):
				//b: isec hx
				//hack to handle change of directory for exmkr samples...
				var nfound=html.indexOf('php6/');
				if (nfound>-1){
					html=html.replace('php6','../php6');
				}
				//e: isec hx

				$("#xloading").hide();
				$("#article_container").html(html);
				break;
			default:
				alert("WARNING unknown command2");
			}
		}
	});
}



