var site_url = "http://ultimaora.phg.ro/";



function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}
function menu() {
	edit_objs = getElementsByClassName(document, "*", "menu_main");
	for(i=0;i<edit_objs.length;i++) {
		menu_id = edit_objs[i].id ;
		$(menu_id).onclick = function () { 
			//$('middle_container').innerHTML = this.id ;
			ids = this.id.split("menu_main_");
			main_id = ids[1];
			collapsed_divs = getElementsByClassName(document,"*","submenu_toggle");
			for ( i=0;i<collapsed_divs.length;i++) {
				collapsed_id = collapsed_divs[i].id
				if ( $(collapsed_id).style.display == "" && collapsed_id != main_id ) {
					div_id = collapsed_id ;
					new Effect.toggle(collapsed_id,'blind');
				}
			}
			new Effect.toggle('submenu_'+main_id,'blind');
			return false;
		}
	}
}
function toggle_submenu(div_name) {
	the_div = $(div_name);
	if ( the_div.style.display == "none" ) {
		new Effect.BlindDown(div_name,{duration:0.5});
	}
	else {
		new Effect.BlindUp(div_name,{duration:0.5});
	}
}
function show_hide_div(div_name) {
	the_div = $(div_name);
	if ( the_div.style.display == "none" ) {
		new Effect.BlindDown(div_name,{duration:0.5});
	}
	else {
		new Effect.BlindUp(div_name,{duration:0.5});
	}
}
function switch_div(denumire) {
	the_div =  document.getElementById('div_'+denumire);
	arata = the_div.style.display;
	if  ( arata != "none" ) {
		the_div.style.display = "none";
		title_div = document.getElementById('toggle_'+denumire);
		title = title_div.innerHTML;
		title_div.innerHTML = "arata";
	}
	else {
		the_div.style.display = "";
		title_div = document.getElementById('toggle_'+denumire);
		title = title_div.innerHTML;
		title_div.innerHTML = "ascunde";
	}
}
function captcha_reload(id) {
	theImg=document.getElementById(id);
	theImg.src +='?'+ Math.round(Math.random()*100000);
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function toggle_div_2() {
	document.getElementById(this.id).onclick = nimic;
	ids = this.id.split("_");
	the_id = ids[1]+"_"+ids[2];
	toggle_div(the_id,this.id);
	
}
function nimic(){
}
function toggle_div(id,caller) {
		//alert(id +' - '+caller);
		document.getElementById(caller).onclick = nimic;
		if ( document.getElementById(id).style.display == "" )
		{
			new Effect.BlindUp(id,{duration: 0.3,afterFinish: function () { 
			linkurl = document.getElementById(caller) ;
		 	linkurl.onclick = toggle_div_2;
			}
			});
		}
	else 
		{
			new Effect.BlindDown(id,{duration: 0.3,afterFinish: function () { 
			linkurl = document.getElementById(caller) ;
		 	linkurl.onclick = toggle_div_2;
			}
			});
		}
}
function toggle_blinddown(main_id,update_id,img_1,img_2) {
	if ( document.getElementById(main_id).style.display == "" ){
		new Effect.BlindUp(main_id);
		if (update_id  != "" && img_1 != "" && img_2 != "") {
			to_update = document.getElementById(update_id);
			to_update.innerHTML = '<img id="slider_img" src="'+img_1+'" width="120" height="20">';
			the_update = document.getElementById('slider_img');
			the_update.onclick = function() { toggle_blinddown(main_id,update_id,img_1,img_2); }
			the_update.style.cursor = "pointer";
		}
	}
	else {
		new Effect.BlindDown(main_id);
		if (update_id  != "" && img_1 != "" && img_2 != "") {
			to_update = document.getElementById(update_id);
			to_update.innerHTML = '<img id="slider_img" src="'+img_2+'" width="120" height="20">';
			the_update = document.getElementById('slider_img');
			the_update.onclick = function() { toggle_blinddown(main_id,update_id,img_1,img_2); }
			the_update.style.cursor = "pointer";
		}
	}
}

function enable_disable(src,target) {
	if (document.getElementById(src).checked == true )
	{
		document.getElementById(target).removeAttribute("disabled");	
	}
	else {
		document.getElementById(target).setAttribute("disabled","true");	
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function confirm_delete(url,question) {
	test = confirm(question);
	if ( test == true ){
		document.location = url;
		return false;
	}
}
function select_jump(url,param_name,value) {
		document.location = url+'?'+param_name+'='+value;
}
function select_jump_and(url,param_name,value) {
		document.location = url+'&'+param_name+'='+value;
}
var handlerFunc = function(t) {
    alert(t.responseXML);
}
var errFunc = function(t) {
    alert('Error ' + t.status + ' -- ' + t.statusText);
}
var populate_zones = function(t) {
	var selObj = $('station_zone');
	var xmldoc = t.responseXML;
	if (!xmldoc) return false;

	var opts = xmldoc.getElementsByTagName('options')[0];
	if (!opts) {
		selObj.length=0;
		selObj[0]=new Option('--eroare--','-1');
		return false;
	}
	else {
		var elems = opts.getElementsByTagName('option');
		selObj.length=0;
		var val=-1;
		var txt='error';
		var opt;
		for(i=0;i<elems.length;i++) {
			val=elems[i].getAttribute("value");
			txt=elems[i].getAttribute("text");
			if ( txt == "Alege din 0 zone" ) {
				selObj[i]=new Option('Alege zona / regiunea','0',"selected","disabled");
			}
			else {
				selObj[i]=new Option(txt,val);
			}
		}
	}
	selObj.removeAttribute("disabled");
}

function fetch_show_data(show_id) {
	new Ajax.Request("shows_actions.php", {
		method:'post',
		parameters:
		"action=fetch_show_data&show_id="+show_id,
		onSuccess: update_show,
		onFailure: errFunc
	});
}
function build_tip_emisiune(tip) {
	new Ajax.Request("shows_actions.php", {
		method:'post',
		parameters:
		"action=build_tipuri&tip="+tip,
		onSuccess: display_build_tip_emisiune,
		onFailure: errFunc
	});
}
var display_build_tip_emisiune = function(t) {
	$('show_type').innerHTML = '<option value="">Alege tipul</option>'+t.responseText;
}
function update_editor(editorInstance,text){
	var oEditor = FCKeditorAPI.GetInstance(editorInstance);
	oEditor.SetHTML(text);
}
function update_show(t) {
	var xmldoc = t.responseXML;
	if (!xmldoc) return false;

	var opts = xmldoc.getElementsByTagName('options')[0];
	
	var elems = opts.getElementsByTagName('option');
	for ( i=0;i<=elems.length;i++) {
		valoare = elems[i].getAttribute("value") ;
		nume    = elems[i].getAttribute("name") ;
		if ( nume == "tip_emisiune" ) {
			build_tip_emisiune(valoare);
		}
		if ( nume == "descriere" ) {
			update_editor('show_descriere',valoare);
		}
		if ( nume == "poza" ) {
			$('hidden_picture').value = valoare;
			$('pic_placeholder').innerHTML = '<img src="../files/shows/main/thumbs/'+valoare+'" border="0" />';
		}
		if ( cna == "poza" ) {
			alert(valoare);
		}
	}
}
















function do_load() {
	new Effect.toggle('loading','appear',{duration:1});
}
var errFunc = function(t) {
	alert('Error ' + t.status + ' -- ' + t.statusText);
}
var handlerFunc = function(t) {
	alert('Response : '+t.responseText);
}
var open_news = function(cat_id,news_id) {
	if ( $('news_'+cat_id+'_'+news_id).style.display == "none" ) {
		if ( $('news_'+cat_id+'_'+news_id).innerHTML == "" ) {
		new Ajax.Request('news_functions.php',{asynchronous:true,method:'post',parameters:'act=insert_news&ins_news_id='+news_id,onSuccess:function(t) {
				$('news_'+cat_id+'_'+news_id).innerHTML = t.responseText;
				new Effect.BlindDown('news_'+cat_id+'_'+news_id,{duration:0.5});
			}, onFailure:errFunc});
		}
		else {
			new Effect.BlindDown('news_'+cat_id+'_'+news_id,{duration:0.5});
		}
		$('title_'+cat_id+'_'+news_id).style.backgroundColor='#e8eff4';
		$('img_'+cat_id+'_'+news_id).src = site_url+"layout/images/inchide.gif";
		$('titlu_'+cat_id+'_'+news_id).className = "titlu_text_arial";
	}
	else {
		$('title_'+cat_id+'_'+news_id).style.backgroundColor='#FFFFFF';
		$('img_'+cat_id+'_'+news_id).src = site_url+"layout/images/deschide.gif";
		$('titlu_'+cat_id+'_'+news_id).className = "titlu_text_arial";
		new Effect.BlindUp('news_'+cat_id+'_'+news_id,{duration:0.5});
	}
}
var inchide_toate = function(the_main_cat,the_main_news) {
	elemente = getElementsByClassName(document,"*","do_toggle");
	for ( i=0;i<elemente.length;i++ ) {
		img_id =  elemente[i].id;
		values = img_id.split("_");
		cat_id = values[1];
		news_id = values[2];
		if ( news_id != the_main_news && cat_id == the_main_cat ) {
			$('title_'+cat_id+'_'+news_id).style.backgroundColor='#FFFFFF';
			$('img_'+cat_id+'_'+news_id).src = site_url+"layout/images/deschide.gif";
			$('titlu_'+cat_id+'_'+news_id).className = "text_arial";
			new Effect.BlindUp('news_'+cat_id+'_'+news_id,{duration:0.5});
		}
	}
}
var stiri_colapse_expand = function() {
	elemente = getElementsByClassName(document,"*","do_toggle");
	for ( i=0;i<elemente.length;i++ ) {
		img_id =  elemente[i].id;
		img_src = elemente[i].src;
		$(img_id).onclick = function() {
			togg_id = this.id;
			togg_src = this.src;
			cat_id = togg_id.split("_");
			cat_close_id = cat_id[1];
			news_open_id = cat_id[2];
			inchide_toate(cat_close_id,news_open_id);
			open_news(cat_close_id,news_open_id);
		}
	}
}





function sw_divs(div_1,div_2) {
	if ( document.getElementById(div_1).style.display == "" ){
		document.getElementById(div_1).style.display ="none";
		document.getElementById(div_2).style.display ="";
	}
	else {
		document.getElementById(div_2).style.display ="none";
		document.getElementById(div_1).style.display ="";
	}
}




var open_win_video = function(url) {
	window.open(url,'','scrollbars=no,menubar=no,height=420,width=600,resizable=no,toolbar=no,location=no,status=no');
}
var open_win_gallery = function(url) {
	window.open(url,'','scrollbars=no,menubar=no,height=800,width=600,resizable=no,toolbar=no,location=no,status=no');
}
function do_menu(m_id){
	//alert("s-a ales meniul " + m_id); 
	//return false;
}
function do_vote(nota) {
	//alert("s-a votat cu " + nota + " stele" ); 
	//return false;
}
function pic_change(pic_name,src) {
	document.getElementById(pic_name).src = src;
}