var _site_url = "http://www.ministerul-funny.ro/";
var _functProcess = "process";
var _functAct = "php";

function ministerul_funny(){}
function ministerulfunny(){}
	
var errFunc = function(t) {
	alert('Error ' + t.status + ' -- ' + t.statusText);
}
	
function xbaddplay(id){
	new Ajax.Request(
		_site_url+"add_playlist."+_functAct, { 
				method:'post', 
				parameters: "action=addtolist&id="+id, 
				onSuccess: update_list, 
				onFailure: errFunc 
		}
	);
}

function xbaddplaya(id){
	new Ajax.Request(
		_site_url+"add_playlist_a."+_functAct, { 
				method:'post', 
				parameters: "action=addtolist&id="+id, 
				onSuccess: update_list_a, 
				onFailure: errFunc 
		}
	);
}

function xbremplay(id, tid){
	var nume_buton = 'adauga_buton_' + tid;
	new Ajax.Request(
		_site_url+"add_playlist."+_functAct, {
			method:'post',
			parameters: "action=delfromlist&id="+id,
			onSuccess: function(){
				update_list();
				$(id).className = 'invisible_pl';
			},
			onFailure: errFunc
		}
	);
	if($(nume_buton) != null){
		$(nume_buton).src='/images/add_off.gif';
		$(nume_buton).blur();
	}

}

function xbremfavs(id, add){
	new Ajax.Request(
		_site_url+"add_favorites."+_functAct, {
			method:'post',
			parameters: "d=t&name="+id,
			onSuccess: update_favs(t.responseText),
			onFailure: errFunc
		}
	);
}

function xbremplay_a(id, tid){
	var nume_buton = 'adauga_buton_' + tid;
	new Ajax.Request(
		_site_url+"add_playlist_a."+_functAct, {
			method:'post',
			parameters: "action=delfromlist&id="+id,
			onSuccess: update_list_a,
			onFailure: errFunc
		}
	);
	if($(nume_buton) != null){
		$(nume_buton).src='/images/add_off.gif';
		$(nume_buton).blur();
	}
}

function update_list(var1){
	var s = 'n=a';

	if(var1 == 'l'){
	var myAjax = new Ajax.Updater(
		{ success: "playlist_l" },
		_site_url+"load_playlist."+_functAct,
		{ method: 'post', parameters: s, evalScripts: true }
	);
	}else{
	var myAjax = new Ajax.Updater(
		{ success: "playlist" },
		_site_url+"load_playlist."+_functAct,
		{ method: 'post', parameters: s, evalScripts: true }
	);
	}
	var t = 'nr=nr&n=a';
	var myAjax = new Ajax.Updater(
		{ success: "playlist_nr" },
		_site_url+"load_playlist."+_functAct,
		{ method: 'post', parameters: t, evalScripts: true }
	);
}

function update_favs(m){
	var u = 'name='+m+'&d=s';
	var t = 'nr=nr&n=a';
			new Ajax.Updater( { success: 'save_fav' }, _site_url+'add_favorites.'+_functAct, { method: 'post', parameters: u, evalScripts: true } );
			new Ajax.Updater( { success: 'favorite_nr' }, _site_url+'load_favorite_nr.'+_functAct, { method: 'post', parameters: t, evalScripts: true } );
//			update_favs_l(n);			
}


function update_favs_g(g){
	var u = 'name='+g+'&d=s';
	var t = 'nr=nr&n=a';
			new Ajax.Updater( { success: 'save_fav' }, _site_url+'add_favorites_g.'+_functAct, { method: 'post', parameters: u, evalScripts: true } );
			new Ajax.Updater( { success: 'favorite_nr' }, _site_url+'load_favorite_nr_g.'+_functAct, { method: 'post', parameters: t, evalScripts: true } );
//			update_favs_l(n);			
}

function update_favs_a(a){
	var u = 'name='+a+'&d=s';
	var t = 'nr=nr&n=a';
			new Ajax.Updater( { success: 'save_fav' }, _site_url+'add_favorites_a.'+_functAct, { method: 'post', parameters: u, evalScripts: true } );
			new Ajax.Updater( { success: 'favorite_nr' }, _site_url+'load_favorite_nr_a.'+_functAct, { method: 'post', parameters: t, evalScripts: true } );
//			update_favs_l(n);			
}

function update_favs_l(var1){
	var t = 'add_opt='+var1;
			new Ajax.Updater( { success: 'XBfavs' }, _site_url+"load_favorites."+_functAct, { method: 'post', parameters: t, evalScripts: true } );
}


function _XBA_savepl(var1) {
	if(var1 == "") {
		alert("Introduce-ti un nume pentru playlist!");
	} else {
	new Ajax.Request(_site_url+"save/thisa/"+var1, {
		method: 'post',
		parameters: 'save='+var1,
		onSuccess: function(){
				the_div2 = 'XB_save';
				new Effect.BlindUp(the_div2,{duration:0.5});
				update_mov_tab('playlist_disp', 'playlist_dispa');
			},
		onFailure: errFunc
	});
	}
}


function _hide_div_plsave() {
	the_div1 = 'after_save_pl';
	the_div2 = 'XB_save';
	the_div1.style.display = "block";
	new Effect.BlindUp(the_div2,{duration:0.5});
	setTimeout('new Effect.BlindUp(the_div1,{duration:0.5})', 3000);
}


function update_list_a(){
	var s = 'n=a';
	var myAjax = new Ajax.Updater(
		{ success: "playlist" },
		_site_url+"load_playlist_a."+_functAct,
		{ method: 'post', parameters: s }
	);
	
	var t = 'nr=nr&n=a';
	var myAjax = new Ajax.Updater(
		{ success: "playlist_nr" },
		_site_url+"load_playlist_a."+_functAct,
		{ method: 'post', parameters: t }
	);
}

var i=0;
function create_new_uppic(value) {
	var place 	= document.getElementById('to_insert');
	var the_content = document.createElement('input');
	the_content.setAttribute('type','file');
	the_content.setAttribute('name','new_picture[]');
	the_content.setAttribute('id','phg_' + i);
	
	if(value == 'adauga'){
			if(i >= '14'){
				alert('Nu poti adauga mai mult de 15 poze');
			}else{
				place.appendChild(the_content);	i++;
			}
		}
	else if(value == 'sterge'){
		if(i>0){
			j = i-1; place.removeChild(document.getElementById('phg_' + j)); i--;
		}
	}
	
}

function MenuFlash(var1){
	alert("sa ales meniul " + var1); 
}
function XBVote(var1, var2){
	var t = 'v='+var1+'&n='+var2+'&ale=0';
	new Ajax.Updater( { success: 'vote' }, _site_url+'display_vote.'+_functAct, { method: 'post', parameters: t } );
	Effect.Appear('vote', { duration: 3.0 });
	new Ajax.Request(_site_url+'vote.'+_functAct, {
		method:'post',

		parameters: 'action=vote&name='+var2+'&nota='+var1,
		onSuccess: ministerul_funny,
		onFailure: errFunc
	});
	var u = 'v='+var1+'&n='+var2+'&ale=1';
	new Ajax.Updater( { success: 'votep' }, _site_url+'display_vote.'+_functAct, { method: 'post', parameters: u } );
}

function getNext(){
	setTimeout('window.location.reload()', 2000);
}
function goHome(){
	window.location='/';
}

function goARG(var1){
	window.location='/'+var1;
}
function goNOW(var1){
	window.location=var1;
}
function goNOW_NL(var1){
	window.open(var1);
}

function update_mov_tab(var1, var2, var3, var4){
	var t = 'inner='+var2+'&add='+var3+'&extra='+var4;
	new Ajax.Updater( { success: var1 }, _site_url+'inner_html.'+_functAct, { method: 'post', parameters: t, evalScripts: true, onComplete:function() { 
		if(var2 == 'movies_options'){																											 
		update_favs(var4);
		} 
	}} );
}

function _writeflash_g(xb){ 
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="80%" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+_site_url+'play_game_'+xb+'.html" />');
	document.write('<param name="quality" value="high" />');
//	document.write('<param name="bgcolor" value="#FFFFFF" />');
//	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="'+_site_url+'play_game_'+xb+'.html" width="100%" height="80%" align="middle" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function _writeflash(xb,get_autoplay,width,height){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+_site_url+_site_act+'?flv='+xb+'&flv_get_play='+get_autoplay+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#333333" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="'+_site_url+_site_act+'?xb='+xb+'&flv_get_play='+get_autoplay+'" wmode="transparent" width="'+width+'" height="'+height+'" align="middle" quality="high" bgcolor="#333333" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

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 _XB_save_fav(name){
	var t = 'name='+name+'&d=d';
	new Ajax.Updater( { success: 'save_fav' }, _site_url+'add_favorites.'+_functAct, { method: 'post', parameters: t } );	
}
function _XBG_save_fav(name){
	var t = 'name='+name+'&d=d';
	new Ajax.Updater( { success: 'save_fav' }, _site_url+'add_favorites_g.'+_functAct, { method: 'post', parameters: t } );	
}
function _XBP_save_fav(name){
	var t = 'name='+name+'&d=d';
	new Ajax.Updater( { success: 'save_fav' }, _site_url+'add_favorites_p.'+_functAct, { method: 'post', parameters: t } );	
}

function _XBA_save_fav(name){
	var t = 'name='+name+'&d=d';
	new Ajax.Updater( { success: 'save_fav' }, _site_url+'add_favorites_a.'+_functAct, { method: 'post', parameters: t } );	
}

function _XB_del_fav(name){
	new Ajax.Request(
		_site_url+"add_favorites."+_functAct, {
			method:'post',
			parameters: 'name='+name+'&d=n',
			onSuccess: _XB_rem(name),
			onFailure: errFunc
		}
	);
}

function _XBP_del_fav(name){
	new Ajax.Request(
		_site_url+"add_favorites_p."+_functAct, {
			method:'post',
			parameters: 'name='+name+'&d=n',
			onSuccess: _XBP_rem(name),
			onFailure: errFunc
		}
	);
}

function _XBA_del_fav(name){
	new Ajax.Request(
		_site_url+"add_favorites_a."+_functAct, {
			method:'post',
			parameters: 'name='+name+'&d=n',
			onSuccess: _XBA_rem(name),
			onFailure: errFunc
		}
	);
}


function _XB_rem(name){
	$(name).style.display = "none";
}

function _XBP_rem(name){
	$(name).style.display = "none";
}

function _XBA_rem(name){
	$(name).style.display = "none";
}

function stars_over(id,nota) {
	var old_srcs = new Array();
	for (i=1;i<=nota;i++) {
		tipul = id.split("_");
		former_src = $('star_'+tipul[1]+'_'+i).src;
		old_srcs[i] = former_src;
		$('star_'+tipul[1]+'_'+i).src = _site_url+"images/stea/over.png";
		
		Event.observe('star_'+tipul[1]+'_'+i, 'mouseout', 
		
			function(e){
				numar = id.split("_");
				for ( j=1;j<=numar[2];j++ ) {
					$('star_'+numar[1]+'_'+j).src = old_srcs[j] ;
				}
			}
		);
				
	}
}
	
function picset_vote(id,nota){
	var t = 'name='+id+'&nota='+nota;
	new Ajax.Updater( { success: 'vote' }, _site_url+'votep.'+_functAct, { method: 'post', parameters: t } );
}

function audio_vote(id,nota){
	var t = 'name='+id+'&nota='+nota;
	new Ajax.Updater( { success: 'vote' }, _site_url+'votea.'+_functAct, { method: 'post', parameters: t } );
}

function MM_preloadimage() { 
	var d=document; if(d.image){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadimage.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_swapImgRestore() { 
	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_findObj(n, d) { 
	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() { 
	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 MM_preloadimage() { 
	var d=document; if(d.image){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadimage.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 icoana_playlist(video, rand) {
	var nume_buton = 'adauga_buton_' + video;
	
	if (document.getElementById(nume_buton).src.match('end')){
		document.getElementById(nume_buton).blur();
	}else{
		xbaddplay(rand);
		document.getElementById(nume_buton).src='/images/add_end.gif';
		document.getElementById(nume_buton).blur();
	}
}

function icoana_playlista(audio, rand) {
	var nume_buton = 'adauga_buton_' + audio;
	
	if (document.getElementById(nume_buton).src.match('end')){
		document.getElementById(nume_buton).blur();
	}else{
		xbaddplaya(rand);
		document.getElementById(nume_buton).src='/images/add_end.gif';
		document.getElementById(nume_buton).blur();
	}
}

function mo_adauga(video) {
	var nume_buton = 'adauga_buton_' + video;
	if (document.getElementById(nume_buton).src.match('end')){
		document.getElementById(nume_buton).src='/images/add_end.gif';
	}
	else {
		document.getElementById(nume_buton).src='/images/add_on.gif';
	}			
}

function mo_adauga_o(video) {
	var nume_buton = 'adauga_buton_' + video;
	if (document.getElementById(nume_buton).src.match('end')){
		document.getElementById(nume_buton).src='/images/add_end.gif';
	}
	else {
		document.getElementById(nume_buton).src='/images/add_off.gif';
	}			
}

function update_pic_tab(var1, var2, var3, var4){
	var t = 'inner='+var2+'&add='+var3+'&extra='+var4;
	new Ajax.Updater( { success: var1 }, _site_url+'inner_html.'+_functAct, { method: 'post', parameters: t, evalScripts: true, onComplete:function() { 
		if(var2 == 'pic_options'){																											 
		update_favs_p(var4);
		} 
	}} );
}


function doPreload(image, size1, size2){
	var imagine = new Image(size1, size2);
	imagine.src = image;
	return imagine;
}



function update_main_pic(pic, size, size2){
	//var the_image = doPreload(_site_url+'pictures/'+pic+'/2',size,size2);
	if(size != size2){
		$('updater_main_pic').innerHTML = '<a id="thumb1" href="'+_site_url+'pictures/'+pic+'/2" class="highslide" onclick="return hs.expand(this, {captionId: \'caption1\'})"><img src="'+_site_url+'pictures/'+pic+'/2" width="'+size+'" alt="" title="Click pentru a mari" /></a>';
	} else {
		$('updater_main_pic').innerHTML = '<a href="javascript:ministerul_funny();" onclick="javascript:ministerul_funny();"><img src="'+_site_url+'pictures/'+pic+'/2" width="'+size+'" alt="" border="0" /></a>';
	}
		$('down_mov').width = size;
}


function update_main_pic_old(pic, size, size2){
	//var the_image = doPreload(_site_url+'pictures/'+pic+'/2',size,size2);
	if(size != size2){
		$('updater_main_pic').innerHTML = '<a href="javascript:ministerul_funny();" onclick="javascript:pop_img(\''+_site_url+'pictures/'+pic+'/2\', \''+size+'\');"><img src="'+_site_url+'pictures/'+pic+'/2" width="'+size+'" alt="" border="0" /></a>';
	} else {
		$('updater_main_pic').innerHTML = '<a href="javascript:ministerul_funny();" onclick="javascript:ministerul_funny();"><img src="'+_site_url+'pictures/'+pic+'/2" width="'+size+'" alt="" border="0" /></a>';
	}
		$('down_mov').width = size;
}

function pop_img(URL, size) {
	$('updater_main_pic').className = 'float_pic_a';
	$('back_img').className = 'float_pic_b';
	$('updater_main_pic').innerHTML = '<a href="#" onclick="javascript:hide_pic_a(\''+URL+'\',\''+size+'\');"><img src="'+URL+'" alt="" border="0" /></a>';
}

function hide_pic_a(URL,size){
	$('updater_main_pic').className = '';
	$('back_img').className = 'float_pic_c';
	$('updater_main_pic').innerHTML = '<a href="javascript:ministerul_funny();" onclick="javascript:pop_img(\''+URL+'\',\''+size+'\');"><img src="'+URL+'" width="'+size+'" alt="" border="0" /></a>';
	//$('updater_main_pic').style.display = "none";
}

function update_favs_p(p){
	var u = 'name='+p+'&d=s';
	var t = 'nr=nr&n=a';
//	alert(p);
			new Ajax.Updater( { success: 'save_fav' }, _site_url+'add_favorites_p.'+_functAct, { method: 'post', parameters: u, evalScripts: true } );
			new Ajax.Updater( { success: 'favorite_nr' }, _site_url+'load_favorite_nr_p.'+_functAct, { method: 'post', parameters: t, evalScripts: true } );
//			update_favs_l(n);			
}

function _this_game_resize(){
	$('the_game').className = "new_resize";
	$('text_resize').className = "text_resize";
	$('game_bg').style.display = "block";
	$('text_resize').innerHTML = '<a href="javascript:ministerul_funny();" onClick="javascript:_this_game_resize_more();">Mareste mai mult</a> | <a href="javascript:ministerul_funny();" onClick="javascript:_this_game_back();">Micsoreaza</a>';
}

function _this_game_resize_more(){
	$('the_game').className = "new_resize_2";
	$('text_resize').className = "text_resize";
	$('game_bg').style.display = "block";
	$('text_resize').innerHTML = '<a href="javascript:ministerul_funny();" onClick="javascript:_this_game_back();">Micsoreaza</a>';
}

function _this_game_back(){
	$('game_bg').style.display = "none";
	$('text_resize').className = "text_resize";
	$('the_game').className = "normal_size";
	$('text_resize').innerHTML = '<a href="javascript:ministerul_funny();" onClick="javascript:_this_game_resize();">Mareste</a>';
	
}

function update_gam_tab(var1, var2, var3, var4){
	var t = 'inner='+var2+'&add='+var3+'&extra='+var4;
	new Ajax.Updater( { success: var1 }, _site_url+'inner_html.'+_functAct, { method: 'post', parameters: t, evalScripts: true, onComplete:function() { 
		if(var2 == 'games_options'){																											 
		update_favs_g(var4);
		}
	}} );
}

function update_blog_tab(var1, var2, var3, var4){
	var t = 'inner='+var2+'&add='+var3+'&extra='+var4;
	new Ajax.Updater( { success: var1 }, _site_url+'inner_html.'+_functAct, { method: 'post', parameters: t, evalScripts: true, onComplete:function() { }} );
}

function update_pl_tab(var1, var2){
	var t = 'inner='+var2;
	new Ajax.Updater( { success: var1 }, _site_url+'inner_html.'+_functAct, { method: 'post', parameters: t, evalScripts: true, onComplete:function() { 
	}} );
}

function playlist_divs(strTag,strClass,strNewClass) {
	for (i=0;i<document.getElementsByTagName(strTag).length; i++) {
		if (document.getElementsByTagName(strTag).item(i).className == strClass) {
			document.getElementsByTagName(strTag).item(i).className = strNewClass;
		}
	}
}

function update_watch_list(var1){
	_the_div_sl = var1;
	_the_div_s2 = 'video_now_'+_the_div_sl;
	playlist_divs('div', 'fix_playlist_now', 'fix_playlist_last');
	playlist_divs('div', 'visible_pl', 'invisible_pl');
	if(($(_the_div_sl) != null) && ($(_the_div_s2) != null)){
		$(_the_div_sl).className = "fix_playlist_now";
		$(_the_div_s2).className = "visible_pl";
	}
	window.location.href = '#pl'+_the_div_sl;
}


function unpack_playlist_a(id){
	new Ajax.Request(
		_site_url+"fetch_playlist_a."+_functAct, {
			method:'post',
			parameters: "action=remake&id="+id,
			onSuccess: package_loaded_a(id),
			onFailure: errFunc
		}
	);
}


function package_loaded_a(id){
	the_pk = "pl_no_"+id;
	playlist_divs('div', 'visible_pl', 'invisible_pl');
	Effect.Appear(the_pk, { duration: 1.0 });
	$(the_pk).className = "visible_pl";
	setTimeout('update_list_a()', 500);
}





function unpack_playlist(id){
	new Ajax.Request(
		_site_url+"fetch_playlist."+_functAct, {
			method:'post',
			parameters: "action=remake&id="+id,
			onSuccess: package_loaded(id),
			onFailure: errFunc
		}
	);
}

function package_loaded(id){
	the_pk = "pl_no_"+id;
	playlist_divs('div', 'visible_pl', 'invisible_pl');
	Effect.Appear(the_pk, { duration: 1.0 });
	$(the_pk).className = "visible_pl";
}

function del_playlist(id){
	var pls_confirm=confirm("Esti sigur ca vrei sa stergi acest playlist?");
	var tr_id = 'pl_tr_'+id;
	var tr_id2 = 'pl_tr2_'+id;
	if (pls_confirm==true){
	new Ajax.Request(
		_site_url+"fetch_playlist."+_functAct, {
			method:'post',
			parameters: "action=del&id="+id,
			onSuccess: function (){
					$(tr_id).className = 'invisible_pl';
					$(tr_id2).className = 'invisible_pl';
			},
			onFailure: errFunc
		}
	);
	}
}



function del_playlist_a(id){
	var pls_confirm=confirm("Esti sigur ca vrei sa stergi acest playlist?");
	var tr_id = 'pl_tr_'+id;
	var tr_id2 = 'pl_tr2_'+id;
	if (pls_confirm==true){
	new Ajax.Request(
		_site_url+"fetch_playlist_a."+_functAct, {
			method:'post',
			parameters: "action=del&id="+id,
			onSuccess: function (){
					$(tr_id).className = 'invisible_pl';
					$(tr_id2).className = 'invisible_pl';
			},
			onFailure: errFunc
		}
	);
	}
}


function destroy_package(id){
	the_pk = "pl_tr_"+id;
	$(the_pk).className = "invisible_pl";
}

function _XB_savepl(var1) {
	if(var1 == "") {
		alert("Introduce-ti un nume pentru playlist!");
	} else {
	new Ajax.Request(_site_url+"save/this/"+var1, {
		method: 'post',
		parameters: 'save='+var1,
		onSuccess: function(){
				the_div2 = 'XB_save';
				new Effect.BlindUp(the_div2,{duration:0.5});
				update_mov_tab('playlist_disp', 'playlist_disp');
			},
		onFailure: errFunc
	});
	}
}

function update_aud_tab(var1, var2, var3, var4){
	var t = 'inner='+var2+'&add='+var3+'&extra='+var4;
	new Ajax.Updater( { success: var1 }, _site_url+'inner_html.'+_functAct, { method: 'post', parameters: t, evalScripts: true, onComplete:function() { 
		if(var2 == 'audio_options'){																											 
		update_favs_a(var4);
		} 
	}} );
}


function reg_user(var1, var2, var3){
	the_div = var1;
	var c = var1+'='+var2+'&nd='+var3;
	//alert(var1+','+var2+','+var3);
	new Ajax.Request(
		_site_url+"user_functions."+_functAct, {
			method:'post',
			parameters: c,
			onSuccess: function(t){
					$(the_div).innerHTML = t.responseText;
					Effect.Appear(the_div, { duration: 2.0 });
					new Effect.Highlight(the_div,{startcolor:'#EEEEEE',endcolor:'#FFFFFF'});
			},
			onFailure: errFunc
		}
	);
}

function try_register(vars){
	the_div_err = 'errors';
	var c = 'try=ok&'+vars;
	new Ajax.Request(
		_site_url+"user_functions."+_functAct, {
			method:'post',
			parameters: c,
			onSuccess: function(t){
				var str = t.responseText;
				if(str.substring(0, 6) == "corect"){
						$('reguser').className = "invisible_pl";
						$(the_div_err).innerHTML = str.substring(6);
						Effect.Appear(the_div_err, { duration: 2.0 });

				} else {
						$(the_div_err).innerHTML = str.substring(6);
						Effect.Appear(the_div_err, { duration: 2.0 });
				}
			},
			onFailure: errFunc
		}
	);	
}

function add_comment(vars, hash){
	var c = vars;
	new Ajax.Request(
		_site_url+"comments."+_functAct, {
			method:'post',
			parameters: c,
			onSuccess: function(t){
				var str = t.responseText;
				if(str.substring(0, 6) == "corect"){
				update_mov_tab('movies_comments', 'movies_comments', add_opt, hash);
				update_gam_tab('games_comments', 'games_comments', add_opt, hash);
				update_aud_tab('audio_comments', 'audio_comments', add_opt, hash);
				update_blog_tab('blog_comments', 'blog_comments', 0, add_opt);
				} else {
				alert(str);
				}
			},
			onFailure: errFunc
		}
	);	
}

function menu_top(var1, var2){
	if(var2 == "on"){
		$(var1).className = 'menu_top_on';
	} else {
		$(var1).className = 'menu_top';
	}
}

function add_emoticon(var1, textarea){
	var emoticon;
	switch(var1){
		case "1": emoticon = "[XD]"; break;
		case "2": emoticon = "[:D]"; break;
		case "3": emoticon = "[^D]"; break;
		case "4": emoticon = "[:)]"; break;
		case "5": emoticon = "[:O]"; break;
		case "6": emoticon = "[:P]"; break;
		case "7": emoticon = "[:(]"; break;
		case "8": emoticon = "[^}]"; break;
		case "9": emoticon = "[;D]"; break;
		default: emoticon = "[:)]";
	}
	if(textarea == 1){
		var comentariu = document.post_c.com;
	}else if(textarea == 2){
		var comentariu = document.inbox_compose.message;
	}
	if (document.selection){
        comentariu.focus();
        var sel = document.selection.createRange();
        sel.text = emoticon;
    } else if (comentariu.selectionStart || comentariu.selectionStart == '0') {
        var start = comentariu.selectionStart;
        var end = comentariu.selectionEnd;
        comentariu.value = comentariu.value.substring(0, start) + emoticon + comentariu.value.substring(end, comentariu.value.length);
    } else {
        comentariu.value = comentariu.value + emoticon;
    }
	
	comentariu.focus();
}

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){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}




function show_overlay(){
	var arrayPageSize = getPageSize();
	$('overlay_background').style.height = arrayPageSize[1]+"px" ;
	$('overlay_background').style.display = "block";
}
function hide_overlay(){
	$('overlay_background').style.display = "none";
}


function close_popwin(){
	window.parent.location = _site_url+'index.php?r=1';
}


function site_navi(var1){
	var c = var1+'=true';
	Windows.closeAll();
	if(var1 == 'contact'){
		new Ajax.Request(
			_site_url+"site_navi."+_functAct, {
				method:'post',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					var win = new Window({className: "alphacube", title:"Contact echipa Ministerul FUNNY",  width:400, height:200, top: 10, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
				},
				onFailure: errFunc
			}
		);	
	
	} else if(var1 == 'faq'){
		new Ajax.Request(
			_site_url+"site_navi."+_functAct, {
				method:'post',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					var win = new Window({className: "alphacube", title:"Intrebari frecvente",  width:500, height:600, top: 10, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
				},
				onFailure: errFunc
			}
		);	
	
	} else if(var1 == 'politica'){
		new Ajax.Request(
			_site_url+"site_navi."+_functAct, {
				method:'post',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					var win = new Window({className: "alphacube", title:"Politica de confidentialitate",  width:500, height:600, top: 10, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
				},
				onFailure: errFunc
			}
		);	
	
	} else if(var1 == 'parteneri'){
		new Ajax.Request(
			_site_url+"site_navi."+_functAct, {
				method:'post',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					var win = new Window({className: "alphacube", title:"Parteneri",  width:400, height:300, top: 10, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
				},
				onFailure: errFunc
			}
		);	
	
	} else if(var1 == 'sitemap'){
		new Ajax.Request(
			_site_url+"site_navi."+_functAct, {
				method:'post',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					var win = new Window({className: "alphacube", title:"Sitemap",  width:500, height:600, top: 10, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
				},
				onFailure: errFunc
			}
		);	
	
	} 
}




function user_settings(var1){
	var c = var1+'=true';
	Windows.closeAll();
	if(var1 == 'settings'){
		new Ajax.Request(
			_site_url+"user_settings."+_functAct, {
				method:'post',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					var win = new Window({className: "alphacube", title:"Modifica profil",  width:610, height:665, top: 10, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
				},
				onFailure: errFunc
			}
		);	
	
	} else if (var1 == 'pwd') {
		new Ajax.Request(
			_site_url+"user_settings."+_functAct, {
				method:'post',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					//show_overlay();
					var win = new Window({className: "alphacube", title:"Schimba parola",  width:550, height:300, top: 150, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
				},
				onFailure: errFunc
			}
		);	
	} else if (var1 == 'ajutor'){
		new Ajax.Request(
			_site_url+"html/help."+_functAct, {
				method:'get',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					//show_overlay();
					var win = new Window({className: "alphacube", title:"Ministerul Funny FAQ",  width:550, height:470, top: 150, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
				},
				onFailure: errFunc
			}
		);
	} else if (var1 == 'login'){
		new Ajax.Request(
			_site_url+"html/login."+_functAct, {
				method:'get',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					//show_overlay();
					var win = new Window({className: "alphacube", title:"Login User",  width:350, height:200, top: 150, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
				},
				onFailure: errFunc
			}
		);
	} else if (var1 == 'register'){
		new Ajax.Request(
			_site_url+"reg_user."+_functAct, {
				method:'get',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					//show_overlay();
					var win = new Window({className: "alphacube", title:"Inregistrare",  width:550, height:370, top: 150, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
				},
				onFailure: errFunc
			}
		);
	} else if(var1 == 'lostpwd'){
		new Ajax.Request(
			_site_url+"user_settings."+_functAct, {
				method:'post',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					var win = new Window({className: "alphacube", title:"Recuperare parola",  width:550, height:300, top: 10, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
				},
				onFailure: errFunc
			}
		);	
	
	}
}

function user_verify(var1, var2, var3, var4, var5){
	var c = 'm='+var1+'&u='+var2+'&p='+var3+'&x='+var4;	
	var u = var5;
		new Ajax.Request(
			_site_url+"user_verify."+_functAct, {
				method:'post',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					if (str.substring(0, 6) == 'succes') {
						alert('Parola dumneavoastra a fost actualizata!');
						Windows.closeAll();
						hide_overlay();
					} else {
					$(u).innerHTML = str;
					}
				},
				onFailure: errFunc
			}
		);	
}

function change_ava(var1){
	var img_loc = _site_url+'images/avatare/'+var1;
	$('img_src').src = img_loc;
}

function settings(var1, var2){
	if(var2 == 'over'){
		$(var1).style.background = '#D1E2F9';
	}else{
		$(var1).style.background = '#FFFFFF';
	}
}

function uset(var1, var2){
	//var2 = var2.replace('%', '[ls]', var2);
	if(var1 == 'all'){
		var c = var2+'&t='+var1;
	} else {
		var c = 't='+var1+'&v='+var2;
	}
	if(var2 != ''){
			new Ajax.Request(
			_site_url+"user_setu."+_functAct, {
				method:'post',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					if(str == 'boo'){
						alert('Nu esti autentificat!');
						window.location.reload();
					} else if (str.substring(0, 6) == 'succes') {
						alert('Profilul dumneavoastra a fost actualizat!');
						Windows.closeAll();
						hide_overlay();
					} else {
						$(var1+'_v').innerHTML = str;
					}
				},
				onFailure: errFunc
			}
		);
	} else {
		$(var1+'_v').innerHTML = '';
	}
}

function noLS(e){
        var forbiddenKeys = new Array('v');
        var key;
        var isCtrl;
		var unicode = e.charCode ? e.charCode : e.keyCode;
        if(window.event){
                key = window.event.keyCode;
                if(window.event.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        } else {
                key = e.which;
                if(e.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }
        if(isCtrl){
                for(i=0; i<forbiddenKeys.length; i++) {
                        if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase()){ return false; }
                }
        } else {
			if (unicode == 37){ return false; }
		}
        return true;
}



function browser(){
	if (navigator.appName == 'Microsoft Internet Explorer'){
		clickIE()
	}
	if (navigator.appName == 'Netscape'){
		clickNS
	}else{
		clickNS
	}
	var message="";
	function clickIE() {
		if (document.all){
			(message); return false;
		}
	}
	function clickNS(e){
		if(document.layers||(document.getElementById&&!document.all)){
			if (e.which==2||e.which==3){
				(message);return false;
			}
		}
	}
	if(document.layers){
		document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;
	}else{
		document.onmouseup=clickNS;document.oncontextmenu=clickIE;
	}
	document.oncontextmenu=new Function("return false")
}

function reenable(){
	var message="";
	function clickIE(){
		if (document.all){
			(message); return true;
		}
	}

function clickNS(e){
	if(document.layers||(document.getElementById&&!document.all)){
		if (e.which==2||e.which==3){
			(message);return true;}
		}
	}
	if (document.layers){
		document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;
	}else{
		document.onmouseup=clickNS;document.oncontextmenu=clickIE;
	}
	document.oncontextmenu=new Function("return true")
}

function get_tag(tag){
	document.search.cauta.value = tag;
	document.search.submit();
}

function upload(var1){
	Windows.closeAll();
	var win = new Window({className: "alphacube", title:"Adauga continut",  width:620, height:500, top: 150, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
	win.setURL(_site_url+'upload/');
	win.setZIndex('202');
	win.show();
	win.showCenter();
}

function upload_nlog(var1){
	Windows.closeAll();
	var win = new Window({className: "alphacube", title:"",  width:300, height:150, top: 100, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
	win.setURL(_site_url+'upload/');
	win.setZIndex('202');
	win.show();
	win.showCenter();
}

function useu(var1, var2){
	var c = 't='+var1+'&v='+var2;
	if(var2 != ''){
			new Ajax.Request(
			_site_url+"user_upload."+_functAct, {
				method:'post',
				parameters: c,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					if(str == 'boo'){
						alert('Nu esti autentificat!');
						window.location.href = '/';
					} else {
						$(var1+'_v').innerHTML = str;
					}
				},
				onFailure: errFunc
			}
		);
	} else {
		$(var1+'_v').innerHTML = '';
	}
}

function useua(var1, var2, var3){
	var c = 'n='+var1+'&c='+var2+'&a='+var3+'&f=f';
	var magic;
	var ret;
	new Ajax.Request(
		_site_url+"user_upload."+_functAct, {
			method:'post',
			parameters: c,
			evalScripts: true,
			onSuccess: function(t){
				var str = t.responseText;
				if(str == 'boo'){
					alert('Nu esti autentificat!');
					window.location.reload();
				} else if (str.substring(0, 6) == 'succes') {
					document.incarca.pickaboo.value = 'da';
					document.incarca.submit.click();
				} else {
					$('error').innerHTML = str;
					document.incarca.pickaboo.value = 'nu';
				}
			},
			onFailure: errFunc
		}
	);

	if(document.incarca.pickaboo.value == 'da'){
		return true;
	} else {
		return false;
	}
}

function chk_checkbox(form){
	if(form.checked == true){
		return 'on';
	} else {
		return 'off';
	}
}

function voteaza(hash, nota, ce){
	var c = 'h='+hash+'&n='+nota+'&ce='+ce;
	new Ajax.Request(
		_site_url+"user_vote."+_functAct, {
			method:'post',
			parameters: c,
			evalScripts: true,
			onSuccess: function(t){
				var str = t.responseText;
				if(str == 'boo'){
					alert('Nu esti autentificat!');
					//window.location.reload();
				} else {
					alert(str);
					//$('vote_v').innerHTML = str;
				}
			},
			onFailure: errFunc
		}
	);
}

function voteaza2(hash, nota, ce){
	var c = 'h='+hash+'&n='+nota+'&ce='+ce;
	new Ajax.Request(
		_site_url+"user_vote."+_functAct, {
			method:'post',
			parameters: c,
			evalScripts: true,
			onSuccess: function(t){
				var str = t.responseText;
				if(str == 'boo'){
				} else {
					alert(str);
				}
			},
			onFailure: errFunc
		}
	);
}

function progress_bar(){
	$('the_form').style.display = "none";
	$('progress_bar').style.display = "block";
}

function replaceHtml(el, html) {
        var oldEl = (typeof el === "string" ? document.getElementById(el) : el);
        var newEl = document.createElement(oldEl.nodeName);
        newEl.id = oldEl.id;
        newEl.className = oldEl.className;
        newEl.innerHTML = html;
        oldEl.parentNode.replaceChild(newEl, oldEl);
        return newEl;
};

function change_url(var1){
	document.the_url.urlp.value = _site_url+'xb_p='+var1;
}

function footer(var1){
	Windows.closeAll();
	if(var1 == 'credite'){
		new Ajax.Request(
			_site_url+"footer_display."+_functAct, {
				method:'post',
				parameters: 'show='+var1,
				evalScripts: true,
				onSuccess: function(t){
					var str = t.responseText;
					var win = new Window({className: "alphacube", title:"Credite",  width:610, height:465, top: 100, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
					win.getContent().innerHTML = str;
					win.setZIndex('202');
					win.show();
					win.showCenter();
					new Effect.ScrollTo('menu_top',{offset: -50});
				},
				onFailure: errFunc
			}
		);	
	
	}else{
		Windows.closeAll();
	}
}

function check_email(){
	var c = 'string_type=node';
	new Ajax.Request(
		_site_url+"user_email."+_functAct, {
			method:'post',
			parameters: c,
			evalScripts: true,
			onSuccess: function(t){
				var str = t.responseText;
				if(str == 'you_got_mail'){
							new Ajax.Request(
								_site_url+"html/"+str+"."+_functAct, {
									method:'get',
									evalScripts: true,
									onSuccess: function(t){
										var str = t.responseText;
										var win = new Window({className: "alphacube", title:"Aveti mesaje necitite!",  width:350, height:200, top: 150, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
										win.getContent().innerHTML = str;
										win.setZIndex('202');
										win.show();
										win.showCenter();
									},
									onFailure: errFunc
								}
							);
				} else {
					ministerul_funny();
				}
			},
			onFailure: errFunc
		}
	);
}

function show_email(){
	Windows.closeAll();
	var win = new Window({className: "alphacube", title:"Casuta postala",  width:800, height:500, top: 100, left: 100, destroyOnClose: true, recenterAuto:false, minimizable:false, maximizable:false, resizable:false, wiredDrag: true, showProgress: true});
	win.setURL(_site_url+'email/?inbox=1');
	win.setZIndex('202');
	win.show();
}

function hide_email_window(){
	var c = 'string_type=chain';
	new Ajax.Request(
		_site_url+"user_email."+_functAct, {
			method:'post',
			parameters: c,
			evalScripts: true,
			onSuccess: ministerul_funny,
			onFailure: errFunc
		}
	);
}

function email_down(id){
	$(id).style.background = "#CFCFCF";
}
function email_up(id, color){
	$(id).style.background = color;
}

function selectAll(form, checked) {
  for(var i=0; i<form.length; i++) {
    form.elements[i].checked = checked;
  }
}

function req_mk_d(var1){
	var c = 'n='+var1+'&string_type=rail';
		new Ajax.Request(
		_site_url+"user_email."+_functAct, {
			method:'post',
			parameters: c,
			evalScripts: true,
			onSuccess: function(t){
				var str = t.responseText;
				if(str == 'boo'){
					alert('Numele folderului trebuie sa aiba maxim 10 caractere!');
				} else if (str == 'boo2') {
					alert('Numele folderului trebuie sa aiba un nume!');
				} else {
					goNOW(_site_url+'email/?inbox=1');
				}
			},
			onFailure: errFunc
		}
	);
}

function update_info(var1){
	playlist_divs('a', 'needle', 'email_normal');
	$('folder_'+var1).className = 'email_selected';
}


function read_mail(id, ida){
	window.location = _site_url+'email/?citeste=1&ga='+ida+'&id='+id;
}


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});
	}
}

var erori_com = function(t) {
	rasp = t.responseText;
	div_name = 'comment_div';
	if ( rasp == "success" ) {
		new Effect.BlindUp(div_name,{duration:0.5});
		document.location.reload(1);
	} else if ( rasp.substr(6,13) == "greseli" ) {
		document.location = window.document.URL;
	} else {
		$('erori').innerHTML = rasp;
		new Effect.Appear('erori');
	}
}
