// JavaScript Document
var path_home = '';
var path_images = '';
var shared_it = false;

var state = 'none';

function showhide(layer_ref)
{ 
	var sign = '';

	if (document.all) { //IS IE 4 or 5 (or 6 beta) 
		state = eval( "document.all." + layer_ref + ".style.display"); 
	} 
	if (document.layers) { //IS NETSCAPE 4 or below 
		state = document.layers[layer_ref].display; 
	} 
	if (document.getElementById &&!document.all) { 
		hza = document.getElementById(layer_ref); 
		state = hza.style.display; 
	}

	if (state == 'block') { 
		state = 'none'; 
		sign = '+';
	} 
	else { 
		state = 'block'; 
		sign = '-';
	} 
	if (document.all) { //IS IE 4 or 5 (or 6 beta) 
		eval( "document.all." + layer_ref + ".style.display = state"); 
//		eval( "document.all.sign" + layer_ref + ".innerHTML = \'aaaaaaaa\'"); 
	} 
	if (document.layers) { //IS NETSCAPE 4 or below 
		document.layers[layer_ref].display = state; 
	} 
	if (document.getElementById &&!document.all) { 
		hza = document.getElementById(layer_ref); 
		hza.style.display = state; 
	} 
} 


function hide(layer_ref)
{ 
	state = 'none'; 

	if (document.all) { //IS IE 4 or 5 (or 6 beta) 
		eval( "document.all." + layer_ref + ".style.display = state"); 
	} 
	if (document.layers) { //IS NETSCAPE 4 or below 
		document.layers[layer_ref].display = state; 
	} 
	if (document.getElementById &&!document.all) { 
		hza = document.getElementById(layer_ref); 
		hza.style.display = state; 
	} 
}

function show(layer_ref)
{ 
	state = 'block'; 
	
	if (document.all) { //IS IE 4 or 5 (or 6 beta) 
		eval( "document.all." + layer_ref + ".style.display = state");
//		alert(layer_ref);
	}
	if (document.layers) { //IS NETSCAPE 4 or below 
		document.layers[layer_ref].display = state; 
	} 
	if (document.getElementById &&!document.all) { 
		hza = document.getElementById(layer_ref); 
		hza.style.display = state; 
	} 

}

function ShareIt(iditem, itemtype)
{
	if(!shared_it){
		var url = path_home+'modules/common/shareit.php';
		new Ajax.Updater('capaShareIt', url, {evalScripts: true});}
	else{
		$('capaShareIt').innerHTML = '';
		}	
	shared_it=!shared_it;
}


function validate_catpcha()
{
	if($('turing').value == '')
	{
		alert('Incorrect Code');
		reloadCaptcha();
		return false;
	}
	
	var url = path_home+'includes/captcha/captcha_validate.php?turing='+$('turing').value;
	
	new Ajax.Request(url, {
		onSuccess: function(e) {
				var validate = eval("("+e.responseText+")");
				alert(validate);
				if(validate.valida.captcha == 'Yes'){
					$('captcha_valido').value = 1;
					return true;}
				else{
					alert('Incorrect Code');
					reloadCaptcha();
					return false;
					}
				}, 
		method:"get" ,
		evalScripts: true
		});
}

//ES IGUAL AL ANTERIOR SOLO QUE MUESTRA RESULTADO EN CAPA resultado2
function validate_catpcha2()
{
	if($('turing2').value == '')
	{
		alert('Incorrect Code');
		reloadCaptcha2();
		return false;
	}
	
	var url = path_home+'includes/captcha/captcha_validate.php?turing='+$('turing2').value;
	
	new Ajax.Request(url, {
		onSuccess: function(e) {
				var validate = eval("("+e.responseText+")");
				alert(validate);
				if(validate.valida.captcha == 'Yes'){
					$('captcha_valido').value = 1;
					return true;}
				else{
					alert('Incorrect Code');
					reloadCaptcha2();
					return false;
					}
				}, 
		method:"get" ,
		evalScripts: true
		});
}

function reloadCaptcha()
{
	var url = path_home+'includes/captcha.php?home='+path_home;
	$('turing').value = '';
	new Ajax.Updater('capa_captcha', url, {evalScripts: true});
}

function reloadCaptcha2()
{
	var url = path_home+'includes/captcha2.php?home='+path_home;
	$('turing2').value = '';
	new Ajax.Updater('capa_captcha2', url, {evalScripts: true});
}



/*
function validate_catpcha()
{
//	return true;//sacar luego
	if($('turing').value == '')
	{
		alert('Incorrect Code');
		reloadCaptcha();
		return false;
	}
	
	var url = path_home+'includes/captcha/captcha_validate.php?turing='+$('turing').value;
	
	new Ajax.Request(url, {
		onSuccess: function(e) {
				var validate = eval("("+e.responseText+")");
				if(validate.valida.captcha == 'Yes'){
//					$('captcha_valido').value = 1;
					return true;}
				else{
					alert('Incorrect Code');
					reloadCaptcha();
					return false;
					}
				}, 
		method:"get" ,
		evalScripts: true
		});
}

function reloadCaptcha()
{
	var url = path_home+'includes/captcha.php?home='+path_home;
	$('turing').value = '';
	new Ajax.Updater('capa_captcha', url, {evalScripts: true});
}
*/


function textcounter(field, maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
}

function edit_favorite(mod, _user, _item, _itemtype, _action)
{
	var url = path_home+"modules/common/edit_favorite.php?mod="+mod+"&user="+_user+"&item="+_item+"&itemtype="+_itemtype+"&action="+_action;
	new Ajax.Updater('capa_favorite', url, {method: "get", evalScripts:true});
}

function delPlayer(idperson,person,action,idteam,layer,teamtype)
{
	var url = path_home+"modules/person/modif_player_squad.php?idperson="+idperson+"&person="+person+"&idteam="+idteam+"&action="+action+"&teamtype="+teamtype;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function delCompetition(idcompetition,competition,action,idteam,layer,teamtype)
{
	var url = path_home+"modules/team/modif_competition_team.php?idcompetition="+idcompetition+"&competition="+competition+"&idteam="+idteam+"&action="+action+"&teamtype="+teamtype;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function personNationality(idnationality,nationality,action,idperson,layer)
{
	var url = path_home+"modules/person/modif_person_nationality.php?idnationality="+idnationality+"&nationality="+nationality+"&idperson="+idperson+"&action="+action;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function stadiumTeam(idteam,team,action,idstadium,layer)
{
	var url = path_home+"modules/stadium/modif_stadium_team.php?idteam="+idteam+"&team="+team+"&idstadium="+idstadium+"&action="+action;
	alert(url);
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function jobCategory(iditem,stritem,idcategory,action,variable,layer)
{
	var url = path_home+"modules/others/modif_job_category.php?iditem="+iditem+"&stritem="+stritem+"&idcategory="+idcategory+"&action="+action+"&variable="+variable;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function articleCategory(iditem,stritem,idcategory,action,idarticle,layer)
{
	var url = path_home+"modules/article/modif_article_category.php?iditem="+iditem+"&stritem="+stritem+"&idcategory="+idcategory+"&action="+action+"&idarticle="+idarticle;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function delArticle(idarticle,layer)
{
	var url = path_home+"modules/article/del_article.php?idarticle="+idarticle;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function delFriend(iduser,layer)
{
	var url = path_home+"modules/user/del_friend.php?iduser="+iduser;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function videoCategory(iditem,stritem,idcategory,action,idvideo,layer)
{
	var url = path_home+"modules/video/modif_video_category.php?iditem="+iditem+"&stritem="+stritem+"&idcategory="+idcategory+"&action="+action+"&idvideo="+idvideo;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function modifChannel(strchannel,action,idmatch,layer)
{
	var url = path_home+"modules/competition/modif_match_channels.php?strchannel="+strchannel+"&action="+action+"&idmatch="+idmatch+"&layer="+layer;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function competitionMatch(date,idteam1,team1,idteam2,team2,goals1,goals2,idstadium,stadium,action,idcompetition,idmatch,videocode,layer)
{
	var url = path_home+"modules/competition/modif_competition_match.php?date="+date+"&idteam1="+idteam1+"&team1="+team1+"&idteam2="+idteam2+"&team2="+team2+"&goals1="+goals1+"&goals2="+goals2+"&idstadium="+idstadium+"&stadium="+stadium+"&idcompetition="+idcompetition+"&idmatch="+idmatch+"&videocode="+videocode+"&action="+action;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function competitionLiveMatch(date,time,idteam1,team1,idteam2,team2,idstadium,stadium,action,idcompetition,competition,idmatch,layer,layer2)
{
	var url = path_home+"modules/competition/modif_competition_live_match.php?date="+date+"&time="+time+"&idteam1="+idteam1+"&team1="+team1+"&idteam2="+idteam2+"&team2="+team2+"&idstadium="+idstadium+"&stadium="+stadium+"&idcompetition="+idcompetition+"&competition="+competition+"&idmatch="+idmatch+"&action="+action;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
/*
	var url2 = path_home+"modules/competition/show-live-channels-vacio.php";
	new Ajax.Updater(layer2, url2, {method: "get", evalScripts:true});
*/
}

function editMatch(idmatch,action,layer)
{
	var url = path_home+"modules/competition/edit_match.php?idmatch="+idmatch+"&action="+action;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function editLiveMatch(idmatch,action,layer)
{
	var url = path_home+"modules/competition/edit_live_match.php?idmatch="+idmatch+"&action="+action;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function showSubAssoc(idparent,layer)
{
	var url = path_home+"modules/competition/show_subassociations.php?idparent="+idparent;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function teamStadium(idstadium,stadium,action,idteam,layer)
{
	var url = path_home+"modules/team/modif_team_stadium.php?idstadium="+idstadium+"&stadium="+stadium+"&idteam="+idteam+"&action="+action;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function competitionTeam(teamtype,idteam,team,action,idcompetition,layer)
{
	var url = path_home+"modules/competition/modif_competition_team.php?teamtype="+teamtype+"&idteam="+idteam+"&team="+team+"&idcompetition="+idcompetition+"&action="+action;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function matchGoal(minute,idperson,strperson,action,goaltype,layer)
{
	var url = path_home+"modules/competition/modif_match_goals.php?minute="+minute+"&idperson="+idperson+"&strperson="+strperson+"&goaltype="+goaltype+"&action="+action+"&layer="+layer;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function matchCard(minute,idperson,strperson,typecard,action,layer)
{
	var url = path_home+"modules/competition/modif_match_cards.php?minute="+minute+"&typecard="+typecard+"&idperson="+idperson+"&strperson="+strperson+"&action="+action+"&layer="+layer;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function matchLineup(minute,idperson,strperson,lineup,action,layer)
{
	var url = path_home+"modules/competition/modif_match_lineup.php?minute="+minute+"&lineup="+lineup+"&idperson="+idperson+"&strperson="+strperson+"&action="+action+"&layer="+layer;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function matchVideocode(videocode,action,layer)
{
	var url = path_home+"modules/competition/modif_match_videocode.php?videocode="+videocode+"&action="+action;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function submitVote(vote,idmatch,filename,type,layer)
{
	var url = path_home+"modules/schedule/submit_vote.php?vote="+vote+"&idmatch="+idmatch+"&filename="+filename+"&type="+type+"&layer="+layer;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function submitVoteComp(vote,idmatch,filename,type,layer)
{
	var url = path_home+"modules/competition/submit_vote.php?vote="+vote+"&idmatch="+idmatch+"&filename="+filename+"&type="+type+"&layer="+layer;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function submitVoteCompHome(vote,idmatch,filename,type,layer)
{
	var url = path_home+"modules/common/submit_vote.php?vote="+vote+"&idmatch="+idmatch+"&filename="+filename+"&type="+type+"&layer="+layer;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}

function submitVoteMatch(vote,idmatch,layer)
{
	var url = path_home+"modules/competition/submit_vote_match.php?vote="+vote+"&idmatch="+idmatch+"&layer="+layer;
	new Ajax.Updater(layer, url, {method: "get", evalScripts:true});
}


function addReport(mod, _user, _item, _itemtype)
{
	var url = path_home+"modules/report/report.php?mod="+mod+"&user="+_user+"&iditem="+_item+"&itemtype="+_itemtype;
	load_popup_yto(url, 'nada()');
	//new Ajax.Request(url, {method: "get", evalScripts:true});
	//new Ajax.Updater('capa_favorite', url, {method: "get", evalScripts:true});
}

	/*for IE*/
	function getElementsByName_iefix(tag, name, parent) {
		var k;
		if(parent !='' )
		 	k = document.getElementById(parent);
		else
			 k = document;
		
		 var elem = k.getElementsByTagName(tag);
		 var arr = new Array();
		 for(i = 0,iarr = 0; i < elem.length; i++) {
			  att = elem[i].getAttribute("name");
			  if(att == name) {
				   arr[iarr] = elem[i];
				   iarr++;
			  }
		 }
		 
		 return arr;
	}

/*function cmd_favorite(r)
{
	var json = eval("("+r.responseText+")");
	if(json.r.mod!='' && json.r.fav!='' && json.r.fav!='')
	{
		
	}
}*/

function ocultar()
{
	$('cargador').style.visibility = 'hidden';
}

 function EnterForm(e, url)
  {	 
	 if(e.keyCode == 13)
	   Login(url);
	  else if(e.which == 13)
	   Login(url); 
  }

  function Login(url)
  {
	  if($('T2').present() && $('T3').present())
	  {
		  url +='?'+$('frmLogin').serialize();
		  new Ajax.Request(url, {onSuccess: isValidLogin, evalScripts: true});
	  }
	  else
	  {
		  alert('Debe llenar todos los campos.');		  
	  }
  }
  
  function isValidLogin(r)
  {	       
	var json = eval("("+r.responseText+")");
	if(json.valida.error == 'no')
	  {
		   document.location = json.valida.param;		  		  
	  } 	 
	  else
	  {
		 $('error').innerHTML = json.valida.error;
	  }
  }
function person_edit_info()
{
	
	return true;
}

function cargar_modulo(modulo)
{
	if(modulo == 'home')
	{
		location.href = 'index.php';
	}
}
/*
function cargar_modulo_param(url)
{
	location.href = path_home+url;
}
*/

function cargar_modulo_param(module, action, params)
{
	params = params !='' ? '&'+params : '';
	location.href = '?mod='+module+'&action='+action+params;
}

function cargar_wall(item_type, iditem, addedit)
{
	var url = path_home+'modules/wall/wall_ajax.php';
	url += '?item_type='+item_type+'&iditem='+iditem+'&addedit='+addedit;
	new Ajax.Updater('capa_wall', url, {onSuccess: wall_loaded, evalScripts: true});
}

function wall_loaded()
{
	$('msj_sender').value='';
}

function view_rate(item_type, iditem)
{
	var url = path_home+'modules/common/view_rate.php';
	url += '?item_type='+item_type+'&iditem='+iditem;
	new Ajax.Updater('capa_rate', url, {evalScripts: true});
}

function check_availability()
{
	var valid = true;
	
	if($('cuname').value.length < 6 || $('cuname').value.length > 12)
	{
		$('cuname').className = 'invalid';
		alert('the username must be between 6 and 12 characters');
		valid = false;
	}

	if(valid)
	{
		$('cuname').className = '';
		$('layer_availability').className = '';
		$('layer_availability').innerHTML = '';
		var url = path_home+'modules/user/check_availavility.php?username='+$('cuname').value;
		new Ajax.Updater('layer_availability', url, {onLoaded: $('layer_loading').className = 'cl_loading', onComplete: $('layer_loading').className = 'oculta', evalScripts: true});
	}
}

function textCounter(field,cntfield)
{
	cntfield.value = field.value.length;
}


function GetXmlHttpObject(handler){
   var objXMLHttp=null   
   
	if (window.XMLHttpRequest)
	{
   		objXMLHttp=new XMLHttpRequest()
	}   
	else if (window.ActiveXObject)   
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")   
	}   
	
	return objXMLHttp
}

function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")   
{
	document.getElementById("matchess").innerHTML= xmlHttp.responseText;   
}   
else 
{           //alert(xmlHttp.status);   
}
}
// Will populate data based on input

function htmlData(url, qStr){
if (url.length==0)
{
	document.getElementById("matchess").innerHTML="";
	
	return;
}

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert ("Browser does not support HTTP Request");
return;   
}
url=url+"?"+qStr;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}



// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}



/*VIEJAS*/
/*
function valida_form_invite()
{
	var result = false;
	var field_name = document.getElementsByName('name_invite[]');
	var field_email = document.getElementsByName('email_invite[]');
	
	for(var i = 0 ; i < field_name.length ; i++)
	{
		if(field_name[i].value != '' && (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field_email[i].value)))
		{
			result = true;
		}
	}
	
	if($('Turing').value == '' && result)
		result = false;
	
	if(!result)
	{
		document.getElementById('captcha').src = document.getElementById('captcha').src + '?' + (new Date()).getMilliseconds();
	}
	
	return result;
}

function validated_form_registration()
{
	var _form = document.getElementById('form_registration');
	var campos = _form.getElementsByTagName('INPUT');
	var valid = true;
	
	for(var i = 0 ; i < campos.length ; i++)
	{
		if(campos[i].type == 'text' || campos[i].type == 'password')
		{
			if(campos[i].value == '')
			{
				$('img_'+campos[i].name).className = 'invalid';
				valid = false;
			}
			else
			{
				$('img_'+campos[i].name).className = 'valid';
			}
		}
	}
	
	if($('T17').value.length < 6 || $('T17').value.length > 12)
	{
		$('img_T17').className = 'invalid';
		alert('the user name must be between 6 and 12 characters');
		valid = false;
		return false;
	}
	
	if($('T18').value.length < 6 || $('T18').value.length > 12)
	{
		$('img_T18').className = 'invalid';
		$('img_T19').className = 'no_validate';
		alert('the password must be between 6 and 12 characters');
		valid = false;
		return false;
	}
	else if($('T18').value != $('T19').value)
	{
		$('img_T18').className = 'invalid';
		$('img_T19').className = 'invalid';
		alert('password does not match');
		valid = false;
		return false;
	}
	
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('T22').value)))
	{
		$('img_T22').className = 'invalid';
		alert('e-mail incorrect');
		valid = false;
		return false;
	}
	
	if(valid)
	{
		var url = 'modules/user/validate_registration.php?'+$('form_registration').serialize();
		new Ajax.Request(url, {onSuccess: processRegistration, evalScripts: true});
	}
	return false;
}

function processRegistration(respuesta)
{
	//alert(respuesta.responseText)
	var json = eval("("+respuesta.responseText+")");
	if(json.valida.error != 'no')
	{
		document.getElementById('captcha').src = document.getElementById('captcha').src + '?' + (new Date()).getMilliseconds();
		if(json.valida.catpcha != '')
		{
			$('img_Turing').className = 'invalid';
		}
		if(json.valida.username != '')
		{
			$('img_T17').className = 'invalid';
		}
		if(json.valida.password != '')
		{
			$('img_T18').className = 'invalid';
		}
		if(json.valida.confirm_password != '')
		{
			$('img_T19').className = 'invalid';
		}
		if(json.valida.first_name != '')
		{
			$('img_T20').className = 'invalid';
		}
		if(json.valida.last_name != '')
		{
			$('img_T21').className = 'invalid';
		}
		if(json.valida.email != '')
		{
			$('img_T22').className = 'invalid';
		}
		if(json.valida.user_exits != '')
		{
			$('img_T22').className = 'invalid';
		}
	}
	else
	{
		//location.href = 'sign_up.php?user_registered=YES';
		load_popup_yto('modules/user/confirm-registration.php', 'nada()');
	}
}


function join_competion(c, u)
{
	location.href = "modules/user/join_competition.php?id_user="+u+"&id_competition="+c;
}

function recommend_this_site()
{
	var url = 'modules/common/recommended_this_site.php?'+$('frm_recommend_this_site').serialize();
	new Ajax.Request(url, {onLoaded: $('cargador').style.visibility = 'visible', onComplete: finish_recommended, evalScripts: true});
}

function finish_recommended(response)
{
	ocultar();
	document.getElementById('captcha').src = document.getElementById('captcha').src + '?' + (new Date()).getMilliseconds();
	if(response.responseText == '')
	{
	  $('frm_recommend_this_site').reset();
	}
	load_popup_yto('modules/common/recomended_success.php?msj='+response.responseText, 'nada()')
}

function set_fc_competition()
{
	ocultar();
}

function save_competition()
{
	var valid = true;
	var _fc_end = $('txt_end').value.split("-");
	var _fc_start = $('txt_start').value.split("-");
	var _fc_t7 = $('T7').value.split("-");
	var _fc_t8 = $('T8').value.split("-");
	
	
	var fc_start = new Date(_fc_start[2], _fc_start[1], _fc_start[0]);
	var fc_t7 = new Date(_fc_t7[2], _fc_t7[1], _fc_t7[0]);
	var fc_end = new Date(_fc_end[2], _fc_end[1], _fc_end[0]);
	var fc_t8 = new Date(_fc_t8[2], _fc_t8[1], _fc_t8[0]);
	
	if($('T4').value.length < 4)
	{
		//$('img_T17').className = 'invalid';
		alert('name must be at least 4 characters');
		valid = false;
	}
	
	if($('D95').value == -1)
	{
		alert('must select a tournament');
		valid = false;
	}
	
	if(isNaN($('T6').value))
	{
		alert('number of players Invalid');
		valid = false;
	}

	if($('T6').value<=0)
	{
		alert('number of players Invalid');
		valid = false;
	}

	if($('T7').value == '')
	{
		alert('start date Invalid');
		valid = false;		
	}
	else if(compareDate(fc_start, fc_t7) > 0)
	{
		alert('start date Invalid');
		valid = false;		
	}

	if($('T8').value == '')
	{
		alert('end date Invalid');
		valid = false;		
	}
	else if(compareDate(fc_end, fc_t8) < 0)
	{
		alert('end date Invalid');
		valid = false;		
	}

	if(valid)
	{
		$('frm_add_competition').submit();
	}
}

function compareDate(dateA, dateB)
{
   var timeDifference = dateA - dateB;
	
   if (timeDifference > 0)
      return 1;
   else if (timeDifference < 0)
      return -1;
   else
      return 0;
}

function set_arroba()
{
	if($('txt_email').value.indexOf('@') == -1)
	{
		$('txt_email').value += '@';
		$('bt_arroba').disabled = true;
	}
}

function check_arroba()
{
	if($('txt_email').value.indexOf('@') == -1)
	{
		$('bt_arroba').disabled = false;
	}
}

function forget_password()
{
	var valid = true;
	
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('txt_email').value)))
	{
		$('img_email').className = 'invalid';
		alert('e-mail incorrect');
		valid = false;
	}
	if($('Turing').value == '')
	{
		$('img_turing').className = 'invalid';
		alert('Incorrect Code');
		valid = false;
	}
	
	if(valid)
	{
		var url = 'modules/user/forget_password.php?'+$('frm_forget_password').serialize();
		new Ajax.Request(url, {onLoaded: $('layer_loading').className = 'cl_loading', onComplete: process_forget_password, evalScripts: true});
	}
}

function process_forget_password(respuesta)
{
	$('layer_loading').className = 'oculta';
	//$('layer_forget_password').innerHTML = '<h3>proccess your request</h3>';
	var json = eval("("+respuesta.responseText+")");
	
	document.getElementById('captcha').src = document.getElementById('captcha').src + '?' + (new Date()).getMilliseconds();

	if(json.valida.error != 'no')
	{
		$('layer_forget_password').innerHTML = json.valida.catpcha+'<br>'+json.valida.email+'<br>'+json.valida.user_exits;
		if(json.valida.catpcha != '')
		{
			$('img_turing').className = 'invalid';
		}
		if(json.valida.email != '')
		{
			$('img_email').className = 'invalid';
		}
		if(json.valida.user_exits != '')
		{
			$('img_email').className = 'invalid';
		}
	}
	else
	{
		$('capa_frm_forget_password').className = 'oculta';
		location.href = 'login.php';
		//$('layer_forget_password').innerHTML = '<h3>he has sent a message to the email provided you follow the link that there appears to recover your password</h3>';
	}
}

function set_password()
{
	var _form = document.getElementById('frm_reset_password');
	var campos = _form.getElementsByTagName('INPUT');
	
	var valid = true;
	for(var i = 0 ; i < campos.length ; i++)
	{
		if(campos[i].type == 'text')
		{
			if(campos[i].value == '')
			{
				$('img_'+campos[i].name).className = 'invalid';
				valid = false;
			}
			else
			{
				$('img_'+campos[i].name).className = 'valid';
			}
		}
	}
	
	if($('txt_pwd').value.length < 6 || $('txt_pwd').value.length > 12)
	{
		$('img_pwd').className = 'invalid';
		$('img_confirm_pwd').className = 'no_validate';
		alert('the password must be between 6 and 12 characters');
		valid = false;
	}
	else if($('txt_pwd').value != $('txt_confirm_pwd').value)
	{
		$('img_pwd').className = 'invalid';
		$('img_confirm_pwd').className = 'invalid';
		alert('password does not match');
		valid = false;
	}

	if(valid)
	{
		var url = 'modules/user/reset_password.php?'+$('frm_reset_password').serialize();
		new Ajax.Request(url, {onLoaded: $('layer_loading').className = 'cl_loading', onComplete: process_reset_password, evalScripts: true});
	}

}

function process_reset_password(respuesta)
{
	$('layer_loading').className = 'oculta';
	//$('layer_forget_password').innerHTML = '<h3>proccess your request</h3>';
	var json = eval("("+respuesta.responseText+")");
	
	if(json.valida.error != 'no')
	{
		$('layer_reset_password').innerHTML = json.valida.catpcha+'<br>'+json.valida.email+'<br>'+json.valida.user_exits;
		if(json.valida.password != '')
		{
			$('img_pwd').className = 'invalid';
		}
		if(json.valida.confirm_password != '')
		{
			$('img_confirm_pwd').className = 'invalid';
		}
	}
	else
	{
		$('capa_frm_reset_password').className = 'oculta';
	    $('layer_reset_password').innerHTML = '<h3>You can access your account with the new password</h3>';
	}
}

function set_lbl_round(id_round)
{
	url = 'modules/competition/lbl_round.php?id_round='+id_round;
	new Ajax.Updater('capa_lbl_round', url, {onLoaded: $('layer_loading').className = 'cl_loading', onComplete: process_reset_password, evalScripts: true});	
}

function check_date(elEvento)
{
	var evento = window.event || elEvento;
	
	
	if(this.value == 'dd-mm-yyyy' && evento.type == 'focus')
	{
		this.value = '';
	}
	else if(this.value == '' && evento.type == 'blur')
	{
		this.value = 'dd-mm-yyyy';
	}
}

function load_date1_tournament(tournament)
{
	url = 'modules/competition/load_date_tournament.php?id_tournament='+tournament+'&fc=date_1';
	new Ajax.Updater('capa_fc_start', url, {onLoaded: $('cargador').style.visibility = 'visible', onComplete: function(){ocultar(); set_date_competition(1); load_date2_tournament(tournament)}, evalScripts: true});	
}

function load_date2_tournament(tournament)
{
	url = 'modules/competition/load_date_tournament.php?id_tournament='+tournament+'&fc=date_2';
	new Ajax.Updater('capa_fc_end', url, {onLoaded: $('cargador').style.visibility = 'visible', onComplete: function(){ocultar(); set_date_competition(2)}, evalScripts: true});	
}

function set_date_competition(_date)
{
	if($('date_hide_start') != null && $('date_hide_end') != null)
	{
		if(_date == 1)
		{
			for(var i = 0; i < $('T7').options.length; i++)
			{
				if($('T7').options[i].value == $('date_hide_start').value)
				{
					$('T7').selectedIndex = i;
				}
			}
		}
		else
		{
			for(var i = 0; i < $('T8').options.length; i++)
			{
				if($('T8').options[i].value == $('date_hide_end').value)
				{
					$('T8').selectedIndex = i;
				}
			}
		}
	}
}

function delete_competitions(_page)
{
	var cant_comp = 0;
	var _url_string = '';
	var union = '';
	var cmd_comp = document.getElementsByName('C1[]');
	
	for(var i = 0 ; i < cmd_comp.length ; i++)
	{
		if(cmd_comp[i].checked)
		{
			cant_comp++;
			_url_string += union+'id_competition[]='+cmd_comp[i].value;
			union = '&';
		}
	}
	
	if(cant_comp > 0)
	{
		load_popup_yto('modules/competition/alert_delete_competition.php?'+_url_string+'&page_php='+_page);
	}
}

function quit_competitions(_page)
{
	var cant_comp = 0;
	var _url_string = '';
	var union = '';
	var cmd_comp = document.getElementsByName('C1[]');
	
	for(var i = 0 ; i < cmd_comp.length ; i++)
	{
		if(cmd_comp[i].checked)
		{
			cant_comp++;
			_url_string += union+'id_competition[]='+cmd_comp[i].value;
			union = '&';
		}
	}
	
	if(cant_comp > 0)
	{
		load_popup_yto('modules/competition/alert_quit_competition.php?'+_url_string+'&page_php='+_page);
	}
}

function validarFormContact()
{
	if($('fullname').value == '')
	{
		alert('The field can not be empty');
		$('fullname').focus();
		return false;
	}
	if($('f_from').value == '')
	{
		alert('The field can not be empty');
		$('f_from').focus();
		return false;
	}
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('f_from').value)))
	{
		alert('e-mail address incorrectly')
		$('f_from').focus();
		return false;
	}
	if($('msj').value == '')
	{
		alert('The field can not be empty');
		$('msj').focus();
		return false;
	}
	if($('Turing').value == '')
	{
		alert('The field can not be empty');
		$('Turing').focus();
		return false;
	}
	return true;
}*/
