/////////////////////////////////////////////////UTILS///////////////////////////////////////////////////////////////////////

/**
 *
 * @access public
 * @return void
 **/
function str_replace(haystack, needle, replacement) {
	var temp = haystack.split(needle);
	return temp.join(replacement);
}
/**
 *
 * @access public
 * @return void
 **/
function replacer(str){
	var src = ['é', 'É', 'á', 'Á', 'ű', 'Ű', 'ő', 'Ő', 'Ú', 'ú', 'Ó', 'ó', 'Ü', 'ü', 'Ö', 'ö', 'í', 'Í', ' ', '_', '/','?',':','.','|'];
	var dst = ['e', 'e', 'a', 'a', 'u', 'u', 'o', 'o', 'u', 'u', 'o', 'o', 'u', 'u', 'o', 'o', 'i', 'i', '_', '_', '_','_','_','_','_'];
	for(var i=0;i<src.length;i++){
		str=str_replace(str, src[i], dst[i]);
	}
	return str;
}
/////////////////////////////////////////////////UTILS///////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////HÍREK///////////////////////////////////////////////////////////////////////

/**
 *
 * @access public
 * @return void
 **/
function nyitogat(){
	if(document.getElementById('preview').style.display=='none'){
		document.getElementById('preview').style.display='block';
	}else{
		document.getElementById('preview').style.display='none';
	}
}
/**
 *
 * @access public
 * @return void
 **/
function setError(){
	alert('Hiba: ['+document.getElementById('dir').value+'] könyvtár már létezik! Kérlek adj meg másikat nevet!')
	document.getElementById('dir').value='';
}
/**
 *
 * @access public
 * @return void
 **/
function checkDir(strx){
	var s='';
	dir=document.getElementById('long_name').value
	url_name=replacer(dir);
	if(dir.length>0){
		var d=new Date();
		s=d.getFullYear().toString().substr(2,2);
		honap=d.getMonth()+1
		s+=honap.toString().length==1 ? '0'+honap.toString() : honap.toString();
		s+=d.getDate().toString().length==1 ? '0'+d.getDate().toString() : d.getDate().toString();
		dir=s+'_'+replacer(dir);
		Ext.Ajax.request({
			url		: 'savedir.php',
			success : function(responseObject){
							if(responseObject.responseText.length>0){
								alert('Hiba: ez a könyvtár már létezik!')
							}else{
								document.getElementById('submit_btn').disabled=false;
								document.getElementById('work_dir').innerHTML='Munkakönyvtár: <b>'+dir+'</b>';
								document.getElementById('add_image').disabled=false;
								document.getElementById('site_url').innerHTML='URL: <a target=_blank href=http://'+BASE_HREF+strx+'/'+dir.substr(7)+'><b>'+BASE_HREF+strx+'/'+dir.substr(7)+'</b></a>';
								document.getElementById('imagebtn').style.display='none';

							}
						//alert('Sikeres mentés a könyvtár neve: '+dir+'!')
					},
			failure : setError,
			params  : { dir: dir, url_name:url_name}
		});
	}else{
		alert('Kérlek, add meg a könyvtár nevét!')
	}
}
/**
 *
 * @access public
 * @return void
 **/
function setURL(n, mid, sid, page){
	var str=document.form['year_'+n].value.toString()+'-';
	str+=document.form['month_'+n].value.toString()+'-';
	str+=document.form['day_'+n].value.toString()+'_';
	str+=document.form['hour_'+n].value.toString()+':';
	str+=document.form['minit_'+n].value.toString()
	document.location.href='?mid='+mid+'&sid='+sid+'&page='+page+'&date='+str+'&tomodify='+n;
}
/**
 *
 * @access public
 * @return void
 **/
function fckpopup(n){
	myleft=(screen.width)?(screen.width-600)/2:100;
	mytop=(screen.height)?(screen.height-800)/2:100;
	var w=window.open('insert_data.php?id='+n,'popup','width=600, height=800, scrollbars=yes, left='+myleft+', top='+mytop+'');
	w.focus();
}
/**
 *
 * @access public
 * @return void
 **/
function fck_popup_preview(edit,windowWidth,windowHeight){
	myleft=(screen.width)?(screen.width-windowWidth)/2:100;
	mytop=(screen.height)?(screen.height-windowHeight)/2:100;
	var w=window.open('new_preview.php?id='+edit,'popup','width='+windowWidth+', height='+windowHeight+', scrollbars=yes,left='+myleft+', top='+mytop+'');
	w.focus();
}
/**
 *
 * @access public
 * @return void
 **/
function changeNewsDetails(img, long_title, lead_normal, url, id, subsite){

	try{
		var obj=document.getElementById('big_img');
		obj.style.backgroundImage="url("+img+")";
		obj.onclick=function(){
			window.location.href='http://'+BASE_HREF+subsite+'/'+url;
			//document.location.href='http://www.duen.hu/hirek/'+url;
		}
		var obj=document.getElementById('long_title');
		obj.innerHTML=long_title;
		var obj=document.getElementById('lead_normal');
		obj.innerHTML=str_replace(lead_normal, '-------------', '<br>');
		document.getElementById('p_'+id).className='lista_doboz_szoveg_tarolo_cim2'
		//obj.innerHTML=lead_normal;
	}
	catch(e){
		alert(e)
	}
}

temporaly_num=0;
intval='';
function changeNews(){
	if(temporaly_num==5){temporaly_num=0;}
	temporaly_num+=1;
	try{
		var obj=document.getElementById('div_'+temporaly_num);
		if(obj!=undefined){
			obj.onmouseover();
			var szamlalo=0;
			while(szamlalo<5){

				obj2=document.getElementById('div_'+szamlalo);
				if(obj2!= undefined && obj!=obj2){
					obj2.onmouseout();
				}
				szamlalo++;
			}
		}
	}
	catch(e){
		changeNews()
	}
}
/**
 *
 * @access public
 * @return void
 **/

function startfading(){
	try{
		intval=window.setInterval("changeNews()",10000);
	}
	catch(e){}
}
/**
 *
 * @access public
 * @return void
 **/
function stopfading(){

	if(intval!=""){
          window.clearInterval(intval);
          intval="";
    }
    var szamlalo2=0;
	while(szamlalo2<5){
		var obj3=document.getElementById('div_'+szamlalo2)
		if(obj3!= undefined ){
			obj3.onmouseout();
		}

		szamlalo2++
	}
}

/////////////////////////////////////////////////HÍREK///////////////////////////////////////////////////////////////////////
/**
 *
 * @access public
 * @return void
 **/

////////////////////////////////////POPUP///////////////////////////////////////////////
function PopupPic(sPicURL) {
	var screenWidth = screen.availWidth;
	var screenHeight = screen.availHeight;
	var x = (screenWidth/2)-(400/2);
	var y = (screenHeight/2)-(400/2);
	if(BASE_HREF.length>0){
		window.open("http://"+BASE_HREF+"popup.html?"+sPicURL,"","screenX="+x+",left="+x+",screenY="+y+",top="+y+",resizable=false,HEIGHT=200,WIDTH=200");
	}else{
		window.open("popup.html?"+sPicURL,"","screenX="+x+",left="+x+",screenY="+y+",top="+y+",resizable=false,HEIGHT=200,WIDTH=200");
	}
}
////////////////////////////////////POPUP///////////////////////////////////////////////

/**
 *
 * @access public
 * @return void
 **/
function updateList(n){
	Ext.Ajax.request({
			url		: 'listsubdirs.php',
			success : function(responseObject){
							document.form.subcat.length = 0
							if(responseObject.responseText!='ures' && responseObject.responseText!='hiba'){

								arr=responseObject.responseText.split(";")
								for(var i=0;i<arr.length;i++){
									var v=arr[i].split("-----");
									document.form.subcat.options[document.form.subcat.length] = new Option(v[1], v[0]);

								}
							}else{

							}
						//alert('Sikeres mentés a könyvtár neve: '+dir+'!')
					},

			params  : { id: n}
		});
}
/**
 *
 * @access public
 * @return void
 **/
function updateListById(n, id){
	Ext.Ajax.request({
			url		: 'listsubdirs.php',
			success : function(responseObject){
							document.form.subcat.length = 0
							if(responseObject.responseText!='ures' && responseObject.responseText!='hiba'){

								arr=responseObject.responseText.split(";")
								for(var i=0;i<arr.length;i++){
									var v=arr[i].split("-----");
									document.form.subcat.options[document.form.subcat.length] = new Option(v[1], v[0]);
									if(id==v[0]){
										document.form.subcat.selectedIndex=i
									}
								}
							}else{

							}
						//alert('Sikeres mentés a könyvtár neve: '+dir+'!')
					},

			params  : { id: n}
		});
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////BEÁLLÍTÁSOK/////////////////////////////////////////////////////////////////////////////////////////

/**
 *
 * @access public
 * @return void
 **/
function addElements(){

	var sels=new Array();

	right_obj=document.getElementById('elem_list');
	left_obj=document.getElementById('elem_config');
	for(var i=0;i<right_obj.options.length;i++){
		breaked=false
		if(right_obj.options[i].selected){
			for(var j=0;j<left_obj.options.length;j++){
				if(left_obj.options[j].value==right_obj.options[i].value){
					breaked=true
					break;
				}
			}
			if(!breaked){
				var elOptNew = document.createElement('option');
			  	elOptNew.text = right_obj.options[i].value
			  	elOptNew.value = right_obj.options[i].value

				 try {
				    left_obj.add(elOptNew, null) // standards compliant; doesn't work in IE
				  }
				  catch(ex) {
				    left_obj.add(elOptNew); // IE only
				  }
			}
		}
	}

}

/**
 *
 * @access public
 * @return void
 **/
function remElements(){
	 left_obj=document.getElementById('elem_config');
	  var i;
	  for (i = left_obj.options.length - 1; i>=0; i--) {
	    if (left_obj.options[i].selected) {
	      left_obj.remove(i);
	    }
	  }
}


/**
 *
 * @access public
 * @return void
 **/
function sortorder(){
	left_obj=document.getElementById('elem_config');
	for(var j=0;j<left_obj.options.length;j++){
		if(j>0 && left_obj.options[j].selected){

			otext=left_obj.options[(j-1)].text
			ovalue=left_obj.options[(j-1)].value

			left_obj.options[(j-1)].text=left_obj.options[(j)].text
			left_obj.options[(j-1)].value=left_obj.options[(j)].value

			left_obj.options[(j)].text=otext
			left_obj.options[(j)].value=ovalue
		}
	}
}


/**
 *
 * @access public
 * @return void
 **/
function setSel(){
	left_obj=document.getElementById('elem_config');
	for(var j=0;j<left_obj.options.length;j++){
		left_obj.options[j].selected=true
	}
}




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//HÍREK video megjelenítés kapcsoló
function toggler(id,elem){
	var obj=document.getElementById(id)
	if(elem.value=='videók' || elem.value=='videó'){
		obj.style.display='block'
	}else{
		obj.style.display='none'
	}
}




/**
 *
 * @access public
 * @return void
 **/
function showhirkep(a,b,c){

}










