function showtop(id1,id2,poza) {
	link1 = id1+'-link';
	link2 = id2+'-link';
	
	if($(id1).style.display='none')	{
		$(id1).style.display = 'block';
		$(id2).style.display = 'none';									
		$(link2).className = 'menuList';
		$(link1).className = 'selected menuList';								
		$('topbg').src = self_location + 'images/right_'+poza+'_1.jpg'								
	}						
}

function pch_blurpass(state) {
	if (state=='load'){
		if (document.getElementById('pass_focus').value!=''){
			document.getElementById('pass').style.display='block';}	
	}
	else if (state=='over'){
		if(document.getElementById('pass').style.display==''){
			document.getElementById('pass').style.display='none';}	
	}
	else{
	if (document.getElementById('password').value==''){
			if (document.getElementById('pass_focus').value!='true'){
				document.getElementById('pass').style.display='';
			}
		}
	}
}

function show_soon(id,id2) {
	if($(id).style.display=='none') {
		$(id).style.display = 'block';
		if($(id2))
			$(id2).style.display = 'none'
		
		
	}
	else {
		$(id).style.display = 'none'
		if($(id2))
			$(id2).style.display = 'block'
	}
	
}

function select_state(id) {	
	if(id=='US')
		document.getElementById('state').style.display='block'
	else
		document.getElementById('state').style.display='none'
}

function error_field(form_name,field) {
	
	var inputs = new Array('u_fname','u_lname','u_email','user_login','user_pass');
	
	for(var i=0;i<inputs.lenght;i++) {
		if(field==inputs[i]) {
			document[form_name][field].focus();
			document[form_name][field].style.backgroundColor = '#DFB9B6';			
		}
		else
			document[form_name][field].style.backgroundColor = '#FFF';
				
		alert(document[form_name][i].value);
	}		
}


function checkUser() {
	if($('u_login').value!='') {	
		var url = self_location + 'checkUserName.php';
		var params = 'user_login=' + $('u_login').value;
		var target = 'results';
			
		var ajax = new Ajax.Updater(
						target,url, {method: 'get', parameters: params, onFailure: reportError}
					);
	}	
}

function reportError(request) {
	$('results').innerHTML = "Error";
}

function getVote(id,type,user,user_vote) {
	if(parseInt(user_vote)>10) {
		return false;
	}
	//$('x_thanks').innerHTML = 'Thanks for your vote';
	//$('x_thanks').style.backgroundColor = '#CC0000';
	document.getElementById('vote_overlay').style.display = 'block';	
	var url = self_location + 'setUserVote.php';
	var params = 'content_id=' + id +'&type=' + type +'&user_id=' + user +'&rating=' + user_vote;
	var target = 'x_thanks';
	
	
	var ajax = new Ajax.Updater(
					target,url, {method: 'get', parameters: params, onFailure: reportError}
				);
	
	$('x_thanks').style.display = 'block';
	
}
function sign_in() {
	document.getElementById('vote_overlay').style.display = 'block';
	$('x_thanks').style.display = 'block';
}

strings = '';
function handleArrowKeys(evt) {		
	evt = (evt) ? evt : ((window.event) ? event : null);	
	if (evt) {
		
		if($j('#header_login_form').length>0) {
			username = document.header_login_form.username.value;
			password = document.header_login_form.password.value;
			
			if(evt.keyCode=='13' && username!='Utilizator' && password!='Parola') {
				
				document.header_login_form.submit();			
				return false;
			}
		}
		
		
		switch (evt.keyCode) {
			case 27:delfun();break;
			case 13:test_concurs(strings);break;
			default: strings = strings + evt.keyCode;
		 }
	
	}
}

function test_concurs(thestring) 
{
	new Ajax.Request('/concurs_razer.php?string='+thestring,{
					 method:'get',
					 onSuccess:function(req){							
							if(req.responseText.isJSON()){
								var results = req.responseText.evalJSON(true);
								if(results)
									verify(results)
								return;
							}							
							else {
								if(req.responseText!='')
									alert(req.responseText);							
							}
						}});	
	strings ='';
}

function verify(results) 
{	
	if(results[0]=='play')
		playFunGame();
	else {		
		window.location = self_location + results[0];
		return true;		
	}
}


function delfun() {
	if($('test_flash_game')) {
		$('test_flash_game').style.display = 'none';
		$('site-content').removeChild(divs);
	}
		
}

function playFunGame() 
{
	
	if (!$('test_flash_game')) {	
	new Ajax.Request('/ajax_flash_game.php?fgame_category=1',{
					 method:'get',
					 onSuccess:function(req){							
							if(req.responseText.isJSON()){
								var results = req.responseText.evalJSON(true);
								if(results)
									displayFunGame(results);
								return;
							}							
							else
								alert(req.responseText+ ' EROARE');							
						}});	
	}
}

function displayFunGame(l) {
	
	divs = document.createElement('div');
	divs.id = 'test_flash_game';
	divs.style.position = 'absolute';
	divs.style.top = '10px';
	divs.style.left = '100px';
	divs.style.zIndex = '1000';
	divs.style.width = '650px';
	divs.style.height = '500px';	
	divs.style.display = 'block';
	
	//divs.innerHTML = l['fgame_title'];
	
	$('site-content').appendChild(divs);
	
	playThisFlashGame('test_flash_game',l['fgame_id'],l['fgame_ext'])
	
	
}
function playThisFlashGame(id_content,flash_id,ext) {
	$(id_content).innerHTML = '<embed src="http://s1.gamextv.ro/game_x_media/mochi/'+flash_id+'.'+ext+'" menu="false" quality="high" width="550" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
}

document.onkeyup = handleArrowKeys;	


function BrowseImages(game_id,picture_id)
{
	if(!picture_id)
		picture_id = 0;
	url = self_location+'gamegallery_'+game_id+'_'+picture_id+'.html';
		
	PopupCenter(url,1180,700);
}

function BrowseNews(news_id,picture_id)
{
	if(!picture_id)
		picture_id = 0;
	url = self_location+'newsgallery_'+news_id+'_'+picture_id+'.html';
	
	PopupCenter(url,1180,700);
}

function PopupCenter(pageURL,w,h) {
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	var targetWin = window.open (pageURL, 'popup', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

function browseGame(search_string)
{
	removeSearchResults($('find_game'), 'fav_game_select');
	if(search_string && search_string.length >3){
		new Ajax.Request('/browse_game.php?ss='+escape(search_string),{
						 method:'get',
						 onSuccess:function(req){
								if(req.responseText.isJSON()){
									var results = req.responseText.evalJSON(true);
									if(results)
										updateSearchResults($('find_game'),'gaming_related_info[fav_game]','fav_game_select',results);
									return;
								}
							}});
	}
}

function emptyList( box ) {
	if($(box) != null && box.options.length>0){
		while ( box.options.length ) 
			box.options[0] = null;
	}
}

function updateSearchResults(parent, box_name, box_id, l)
{
	emptyList(box_id);
	if(!$(box_id)){
		var newSel  = document.createElement("select");
	    newSel.name = box_name;
	    newSel.id   = box_id;
	    parent.appendChild(newSel);
	}
	else
		var newSel  = $(box_id);
	
	for (i=0; i < l.length; i++) {
		option = new Option( l[i]['title'], l[i]['id'] );
		newSel.options[newSel.length] = option;
	}
	newSel.style.display = 'block';
}

function removeSearchResults(parent, box_id)
{
	if($(box_id != null)){
		for(;parent.childNodes.length;){
			parent.removeChild(parent.childNodes[0]);
		}
	}
}

function addToFriends(profile_id, element_id)
{
	if(profile_id && element_id){
		new Ajax.Request('/add_friend/'+profile_id,{method:'get',onSuccess:function(req){
				/*
				var parent = $(element_id).parentNode;
				parent.removeChild($(element_id));			
				parent.innerHTML = 'Request sent';
				*/
				var parent = $(element_id).parentNode;
				$(element_id).onclick = function () {return false;}
				$(element_id).innerHTML = 'Friend Request sent';
							
			}});
	}
}

function acceptFriendRequest(rel_id, element_id)
{
	if(rel_id && element_id){
		
		new Ajax.Request('/accept_friend/'+rel_id,{method:'get',onSuccess:function(req){
			var parent = $('bloq_'+rel_id).parentNode;
			parent.removeChild($('bloq_'+rel_id));
			}});
		
		
	}
}

function declineFriendRequest(rel_id, element_id)
{
	if(rel_id && element_id){
		new Ajax.Request('/deny_friend/'+rel_id,{method:'get',onSuccess:function(req){
				var parent = $('bloq_'+rel_id).parentNode;
				parent.removeChild($('bloq_'+rel_id));
			}});
	}
}



function sendMessage(profile_id)
{
	if(profile_id){
		PopupCenter('/send_message/'+profile_id,640,480);
	}
}

/*
var captureKeys = function (e) {
	var evt = e || window.event;
	if(evt.keyCode){
		if(evt.ctrlKey)
			alert('keyCode is '+evt.keyCode+' charCode is '+evt.charCode+' +Control');
		else if(evt.metaKey)
			alert('keyCode is '+evt.keyCode+' charCode is '+evt.charCode+' +MetaKey');
		else
			alert('keyCode is '+evt.keyCode+' charCode is '+evt.charCode);
	//}
	return true;
}
*/

function right_friends(id) {
	if($(id).style.display=='none')
		$(id).style.display='block'
	else
		$(id).style.display='none';
}

function addloading() {	
	loading();	
	anchors = getElementsByClassName('loading');
	for(i=0; i<anchors.length; i++) {				
		var anchor = anchors[i];		
		anchor.onclick = function() {onclickme(anchor.innerHTML);}; 		
	}	
}

function onclickme(text) {	
	document.getElementById('loading_page').style.display='block'	
}

function loading() {
	if($('loading_page').style.display=='none') {
		$('loading_page').style.display='block';
		$('loading_page').style.top='0px';
	}
	else {		
		$('loading_page').style.top='-50px';
		$('loading_page').style.display='none';
	}
}

function getElementsByClassName(classname, node) {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("a");
    for(var i=0,j=els.length; i<j; i++)
    if(re.test(els[i].className))a.push(els[i]);
     return a;
}

function WriteAndHide(id,text,sec) {
	if(!sec) sec = 5000;
	$(id).innerHTML = text;	
	var t=setTimeout(function sh() {$(id).innerHTML = '';$(id).style.display='none'},sec);
}

function changeClass(content_id,id,nr) {
	for(i=1;i<nr;i++)
		$(content_id+'_'+i).className = '';
	
	$(content_id+'_'+id).className = 'selected';
}

function switch_class(class1,extra,elem) 
{
	$(elem).className = extra+class1;
}

function showHideElements(content_id,id,nr) 
{
	for(i=1;i<nr;i++)
		$(content_id+'_'+i).style.display = 'none';
	
	$(content_id+'_'+id).style.display = 'block';
}

function tba_content(id_class,id_div,id,nr)  {
	changeClass(id_class,id,nr);
	showHideElements(id_div,id,nr) ;
}

function DivsHover(classname,node) {
    if(!node) node = document.getElementsByTagName("body")[0];
    var divs = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("div");
    for(var i=0,j=els.length; i<j; i++) {
		if(re.test(els[i].className)) {
			els[i].id = 'comm_'+i;
			els[i].onmouseover = function() { this.style.backgroundColor='#434343'};
			els[i].onmouseout = function() { this.style.backgroundColor='#232323'};
			
		}
	}
    //return divs;
}


function get_radio_value()
{		
	for (var i=0; i < document.form_pool.poll.length; i++)
	{
		if (document.form_pool.poll[i].checked)
		  {
		  var input_value = document.form_pool.poll[i].value;
		  }
	}
	
	return input_value;
}


function getPoolVote(pool_id,user_id) 
{		
	q_id = get_radio_value();		
	q_id = parseInt(q_id);
	pool_id = parseInt(pool_id);
	user_id = parseInt(user_id);
	
	new Ajax.Request('/setPoolVote.php?pool_id='+pool_id+'&q_id='+q_id+'&user_id='+user_id,{
						 method:'get',
						 onSuccess:function(req){
								if(req.responseText.isJSON()){
									var results = req.responseText.evalJSON(true);
									if(results)
										update_newsx_pool(results);
									return;
								}
								else {
									/*$('thanks').innerHTML = results;
									text = $('thanks').innerHTML;
									*/
									WriteAndHide('thanks',req.responseText)
								}
									
							}});
		
}

function update_newsx_pool(results)
{	
	$('setuservote').innerHTML = results[0];	
	WriteAndHide('thanks',results[1]);
	
}

function newsxVideo(page,section)
{
	page = parseInt(page);
	
	if(!segment_id)
		segment_id = 0;
	
	var url = '/return_newsx.php?rank='+page+'&segment_id='+segment_id;
	if(section)
		url = url+'&section='+section;
	
	
	new Ajax.Request(url,{
						 method:'get',
						 onSuccess:function(req){
								if(req.responseText.isJSON()){
									var results = req.responseText.evalJSON(true);
									if(results)
										update_newsx(results);
									return;
								}
							}});	
}

function update_newsx(l) 
{
	$('newsx_test').innerHTML = l[0];
	$('newsx_pagination').innerHTML = l[1];
}

function switch_comm() 
{
	$('add-comment').toggle();
	
	if($('img_comm').className=='firstComm') {
		$('img_comm').className='secondComm';
		$('addcomm').className='selected';
		$('addcommdiv').className='';
		$('listcomm').className='';
	}
	else {
		$('listcomm').className='selected';
		$('addcomm').className='';
		$('addcommdiv').className='selected';
		$('img_comm').className='firstComm';
	}
}

/* changed by lucian Mar 2010 - added func for the new voteaza page */
function switch_comm_vot(vtab)
{
	if(vtab==2) {
    $('add-comment').show();
		$('imgcom').className='comm2';
		$('addcomm').className='selected';
		$('listcomm').className='';
	}
	else {
    $('add-comment').hide();
		$('imgcom').className='comm1';
		$('listcomm').className='selected';
		$('addcomm').className='';
	}
}
/* end changed by lucian Mar 2010 */

function switch_price(id) 
{
	for(i=1;i<4;i++)
		$('btn_'+i).className = 'btn_'+i;			
		
	$('btn_'+id).className = 'btn_'+id+' selected';
	$('premiu_img').src = '/images/shows/concurs/es_concurs_premiu_'+id+'.png'	
}
