var mp3_files = new Array();
var current_tab = 'none';
var myTabHandlers = {
		onCreate: function(){
			Element.show('systemWorking');
			Element.hide('tabcontainer');
		},

		onComplete: function() {
			if(Ajax.activeRequestCount == 0){
				Element.hide('systemWorking');
				Element.show('tabcontainer');
			}
		}
};

function changeTabContainer(t) {
	var url = 'http://localhost/ce/ajaxResponder.php';
	var pars = 'account=ajax&request_type=get_tab&current_tab=' + t;

	Ajax.Responders.unregister(myTabHandlers);
	Ajax.Responders.register(myTabHandlers);
	var myAjax = new Ajax.Updater(
					{success: 'tabcontainer'}, 
					url, 
					{
						method: 'get', 
						parameters: pars
					});

	if (!null($("tab_"+current_tab))) {
		$("tab_"+current_tab).className = '';
		$("href_"+current_tab).className = '';
	}
	$("tab_"+t).className = 'current';
	$("href_"+t).className = 'current';

	current_tab = t;
	return false;
}

function checkSupplyBox(t) {
	if (document.getElementById('props').value == '' || document.getElementById('contact').value == '') {
		alert(t);
		return false;
	} else {
		return true;
	}
}

function setWhat(i, frm) {
    document.forms[frm].elements['what'].value=i;
}

function setAction(a, frm) {
    document.forms[frm].elements['action'].value=a;
    if (a=='del'||a=='del_sch') return confirm('Biztosan törölni akarod?');
    else return true;
}

function doSubmit(frm) {
    document.forms[frm].submit();
}

function setValues(i,a,f) {
    setWhat(i, f);
    if (setAction(a, f)) doSubmit(f);
}

function showModalDlg(url, name, features, forcewindowopen) {
  wheight = 400;
  wwidth = 660;
  wleft = (screen.width - wwidth) / 2;
  wtop = (screen.height - wheight) / 2;
  wcenter = 'no';
  wlocation = 'no';
  wmenubar = 'no';
  wresizable = 'no';
  wscrollbars = 'yes';
  wstatus = 'no';
  wtoolbar = 'no';
  // ez a sor kell debugolashoz:
  //forcewindowopen = 1;
  if (forcewindowopen != 1)
    forcewindowopen = 0;
  featurelist = features.split(';');
  for (i=0;i<featurelist.length;i++) {
    data = featurelist[i].split('=');
    switch (data[0]) {
      case "height": wheight = data[1]; break;
      case "width": wwidth = data[1]; break;
      case "top": if (wcenter != 1) { wtop = data[1]; } break;
      case "left": if (wcenter != 1) { wleft = data[1]; } break;
      case "scrollbar": wscrollbars = data[1]; break;
      case "centered": wcenter = 'yes'; break;
      case "locationbar": wlocation = 'yes'; break;
      case "menubar": wmenubar = 'yes'; break;
      case "statusbar": wstatus = 'yes'; break;
      case "toolbar": wtoolbar = 'yes'; break;
      case "resizable": wresizable = 'yes'; break;
    }
  }
  if (wcenter = 1) {
    wleft = (screen.width - wwidth) / 2;
    wtop = (screen.height - wheight) / 2;
  }
  if ((forcewindowopen == 0) && (window.showModalDialog)) {
    fl = 'dialogHeight: ' + wheight + 'px;dialogWidth=' + wwidth + 'px;dialogLeft=' + wleft + 'px;dialogTop=' + wtop +
         'px;scroll=' + wscrollbars + ';status=' + wstatus + ';resizable=' + wresizable;
    window.showModalDialog(url, '', fl);
  }
  else {
    fl = 'height=' + wheight + ',width=' + wwidth + ',left=' + wleft + ',top=' + wtop +
         ',location=' + wlocation + ',scrollbars=' + wscrollbars + ',menubar=' + wmenubar +
         ',status=' + wstatus + ',toolbar=' + wtoolbar + ',resizable=' + wresizable;
    window.open(url, '', fl);
  }
}

function getElByID(idVal, numofparents) {
   // igy mar elirhatom a fuggveny nevet
   return getElById(idVal, numofparent);
}

function getElById(idVal, numofparents)
  {
  p = '';
  for (i=0;i<numofparents;i++)
    p = p + 'parent.';
  if (document.getElementById != null)
    return eval(p + 'document.getElementById(idVal)');
  if (document.all != null)
    return eval(p + 'document.all[idVal]');

  alert("Hiba! A böngésző nem támogatja: getElById()")
  return null
  }

function PageLoaded() {
  var s=0;
  try {
//    if (getCookie('STOP_STREAM')) ply.sendEvent("STOP");
    if (getCookie('MUTE_STREAM')) ply.sendEvent("MUTE");
  } catch(e){};
  return 0;
/*  
  $('footer_div').style.position = 'absolute';
  $('comment_div').style.position = 'absolute';
  try {
      if ($('toc_frame').clientHeight > $('hotpotatoe_container').clientHeight) {
        if ($('toc_frame').clientHeight > $('body_txt').clientHeight) {
          $('comment_div').style.top = $('body_txt').offsetTop + $('body_txt').clientHeight + 160;
          $('footer_div').style.top = $('toc_frame').clientHeight + 100;
        } else {
//          $('comment_div').style.top = $('body_txt').clientHeight + 100;
          $('footer_div').style.top = $('body_txt').clientHeight + $('comment_div').clientHeight+ 170;
        }
      } else {
        $('comment_div').style.top = $('hotpotatoe_container').offsetTop + $('hotpotatoe_container').clientHeight + 20;
        $('footer_div').style.top = $('hotpotatoe_container').clientHeight + $('comment_div').clientHeight + 200;
      }
      s = 1;
//      $('comment_div').style.top = $('body_txt').offsetTop + $('body_txt').clientHeight + 130;
      $('player1').addViewListener('LINK','stopMovie');
  } catch (e) {
//        $('comment_div').style.top = $('toc_frame').offsetTop + $('toc_frame').clientHeight + 450;
//        $('comment_div').style.top = $('body_txt').offsetTop + $('body_txt').clientHeight + 10;
//        $('footer_div').style.top = $('body_txt').offsetTop + $('body_txt').clientHeight + $('comment_div').clientHeight + 100;
        if (s==0) $('footer_div').style.top = $('comment_div').offsetTop + $('comment_div').clientHeight + 180;
  }
*/
}

function stopMovie() {
//  $('ply').sendEvent('STOP', true);
}

function startCountDown(min) {
  window.setTimeout('timeoutReminder()', (min - 5) * 60 * 1000);
}

function timeoutReminder() {
  alert('Kérem frissítse az oldalt, különben a kapcsolat a kiszolgálóval 3 perc múlva megszakad, és újra be kell jelentkeznie!');
}

function changeDivVisibility(n) {
	_div = getElById(n+'_selector');
	if (_div.style.display == 'none') _div.style.display = 'block';
	else _div.style.display = 'none';
}

function doLoader(w,h,what,l,tp) {
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;

    return window.open("modLoader.php?loadwhat="+what+"&tp="+tp,"load"+l,"toolbar=no,scrollbars=yes,width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition);
} 

function openFrame(w,h,tp,tl) {
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;

	URL = "frame.php?tp="+tp;

	globalHTML="<html><head><title>"+tl+"</title></head>"
	+"<frameset rows='100%,*'><frame src='"+URL+"'></frame>"
	+"</frameset></html>";
	return window.open("javascript:opener.globalHTML", "load","toolbar=no,scrollbars=yes,width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition);
} 

function fNull() {
}

function showSendWindow(c,i,t) {
	s = prompt(t);
}

function changeStyles(c) { 
	var s = new String($('myStyles').href).replace('style'+$('font_size').value+'.css', 'style'+c+'.css');
	var url = 'http://server.civic-edu.eu/ycr-e/ajaxResponder.php';
	var pars = 'account=ajax&request_type=set_font&font_size=' + c;
	
	try	{
			Ajax.Responders.unregister(myDetailHandlers);
			Ajax.Responders.unregister(myAppDetailHandlers);
	}
	catch (e) {null;}
	var myAjax = new Ajax.Updater(
					{success: 'tmp'}, 
					url, 
					{
						method: 'get', 
						parameters: pars
					});

	$('font_size').value = c;
	$('myStyles').href = s; 
	return false;
}

function startMP3(t) {
    if (mp3_files.indexOf(t) == -1) {
	var p = document.getElementById("audio_"+t);
//	var p = $("audio_"+t);
	var my_div = document.createElement('<div>');
	my_div.setAttribute('id','audio_content_'+t);
	my_div.setAttribute('name','audio_content_'+t);
	my_div.innerHTML = '<object id=\"ply_'+t+'\" type=\"application/x-shockwave-flash\" data=\"__js__/player_mp3_maxi.swf\" width=\"1\" height=\"1\"><param name=\"movie\" value=\"__js__/player_mp3_maxi.swf\" /><param name=\"FlashVars\" value=\"mp3=/ycr-e/admin/spaw2/uploads/audio/'+t+'&amp;showslider=0&amp;autoplay=1&amp;width=1\" /></object>';
	p.appendChild(my_div); 
	mp3_files.push(t);    
    } else {
	removePanel(t);
    }
}

function removePanel(t) {
    try {
	$('ply_'+t).setVariable('player:jsStop', '');
    } catch(e) {null;}
    var p = document.getElementById("audio_"+t);
    //$('audio_'+t).removeChild($('audio_content_'+t)); 
    p.removeChild($('audio_content_'+t)); 
    mp3_files.splice(mp3_files.indexOf(t), 1);
}  
    
function 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 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 "";
}