
//FUNCIONES ADMINISTRADOR
function acceso_login(){	
	if (document.forms['formulario_acceso'].elements['username'].value == '') {alert("Por favor, inserta el campo username.");return false;}
	if (document.forms['formulario_acceso'].elements['password'].value == '') {alert("Por favor, inserta el campo password.");return false;}
}

function validar_categorias(accion){	
	if (document.forms['categorias'].elements['categoria'].value == '') {alert("Por favor, inserta el campo categoria.");return false;}
	if (document.forms['categorias'].elements['orden'].value == '') {alert("Por favor, inserta el campo orden.");return false;}
	if (accion == "add"){
		if (document.forms['categorias'].elements['userfile'].value == '') {alert("Por favor, selecciona una imagen.");return false;}
	}
}

function validar_jugadores(accion){
	if (accion == "add"){
		if (document.forms['jugadores'].elements['nombre'].value == '') {alert("Por favor, inserta el campo Nombre.");return false;}
		if (document.forms['jugadores'].elements['apellido'].value == '') {alert("Por favor, inserta el campo Apellido.");return false;}
		//if (document.forms['jugadores'].elements['apodo'].value == '') {alert("Por favor, inserta el campo Apodo.");return false;}
		//if (document.forms['jugadores'].elements['edad'].value == '') {alert("Por favor, inserta el campo Edad.");return false;}
		//if (document.forms['jugadores'].elements['descripcion'].value == '') {alert("Por favor, inserta el campo Descripcion.");return false;}
		if (document.forms['jugadores'].elements['numero'].value == '') {alert("Por favor, inserta el campo Numero.");return false;}
		if (document.forms['jugadores'].elements['temporada'].value == '') {alert("Por favor, inserta el campo Temporadas.");return false;}	
		//if (document.forms['jugadores'].elements['userfile'].value == '') {alert("Por favor, selecciona una imagen.");return false;}
		if (document.forms['jugadores'].elements['tipo'].value == '') {alert("Por favor, selecciona una tipo.");return false;}
	}
	if (accion == "edit"){
		num = document.forms['jugadores'].elements['num'].value;
		valor = 0;
		for (var x=0; x < num; x++) {
			if(document.forms['jugadores'].elements["nombre["+x+"]"].value == ''){valor++;}
			if(document.forms['jugadores'].elements["apellido["+x+"]"].value == ''){valor++;}
			//if(document.forms['jugadores'].elements["apodo["+x+"]"].value == ''){valor++;}
			//if(document.forms['jugadores'].elements["edad["+x+"]"].value == ''){valor++;}
			//if(document.forms['jugadores'].elements["descripcion["+x+"]"].value == ''){valor++;}
			if(document.forms['jugadores'].elements["numero["+x+"]"].value == ''){valor++;}
			if(document.forms['jugadores'].elements["temporada["+x+"]"].value == ''){valor++;}
		}//for
		if (valor != 0){
			alert("Por favor, rellena todos los campos de Nombre, Apellido, Numero, Temporada");return false;
		}
	}
}

function validar_fases(op){
	if(op == "add"){
		if (document.forms['fases'].elements['selectfase'].value == '') {alert("Por favor, selecciona una clase.");return false;}
		if (document.forms['fases'].elements['categorias'].value == '') {alert("Por favor, selecciona una categoria.");return false;}
		if (document.forms['fases'].elements['fase'].value == '') {alert("Por favor, inserta el campo Fase.");return false;}
	}
	if(op == "edit"){
		num = document.forms['fases'].elements['num'].value;
		valor = 0;
		for (var x=0; x < num; x++) {
			if(document.forms['fases'].elements["fase["+x+"]"].value == '' || document.forms['fases'].elements["selectfase["+x+"]"].value == '' || document.forms['fases'].elements["categorias["+x+"]"].value == '' ){valor++;}
		}//for
		if (valor != 0){
			alert("Por favor, inserta el campo fase y selecciona una categoria");return false;
		}
	}//
}

function validar_noticias(){
	if (document.forms['noticias'].elements['titulo'].value == '') {alert("Por favor, inserta el campo Titulo Noticia.");return false;}
	if (document.forms['noticias'].elements['noticia'].value == '') {alert("Por favor, insert el campo Noticia.");return false;}
}

function validar_cronicas(){
	if (document.forms['cronicas'].elements['categorias'].value == '') {alert("Por favor, selecciona una categoría.");return false;}
	if (document.forms['cronicas'].elements['titulo'].value == '') {alert("Por favor, inserta el campo Partido.");return false;}
	if (document.forms['cronicas'].elements['cronica'].value == '') {alert("Por favor, inserta el campo Cronica.");return false;}
	if (document.forms['cronicas'].elements['autor'].value == '') {alert("Por favor, selecciona el autor.");return false;}
}

function validar_comentarios(){
	if (document.forms['comentarios'].elements['titulo'].value == '') {alert("Por favor, inserta el campo T´tulo.");return false;}
	if (document.forms['comentarios'].elements['comentario'].value == '') {alert("Por favor, inserta el campo Comentario.");return false;}
}

function validar_usuarios(op){
	if(op == "add"){
		if (document.forms['usuarios'].elements['usuario'].value == '') {alert("Por favor, inserta el campo Usuario.");return false;}
		if (document.forms['usuarios'].elements['password'].value == '') {alert("Por favor, inserta el campo Password.");return false;}
		if (document.forms['usuarios'].elements['permisos'].value == '') {alert("Por favor, inserta el campo Permisos.");return false;}
	}
	if(op == "edit"){
		num = document.forms['fases'].elements['num'].value;
		valor = 0;
		for (var x=0; x < num; x++) {
			if(document.forms['fases'].elements["fase["+x+"]"].value == ''){valor++;}
		}//for
		if (valor != 0){
			alert("Por favor, inserta el campo fase");return false;
		}
	}//
}

function validar_equipos(op){
	if(op == "add")if (document.forms['equipos'].elements['equipo'].value == '') {alert("Por favor, inserta el campo Equipo.");return false;}
	if(op == "edit"){
		num = document.forms['equipos'].elements['num'].value;
		valor = 0;
		for (var x=0; x < num; x++) {
			if(document.forms['equipos'].elements["equipo["+x+"]"].value == ''){valor++;}
		}//for
		if (valor != 0){
			alert("Por favor, inserta el campo Equipo");return false;
		}
	}//
}

function validar_catpar(op){
	if(op == "add")if (document.forms['catpar'].elements['fase'].value == '') {alert("Por favor, inserta el campo fase.");return false;}
	if(op == "edit"){
		num = document.forms['catpar'].elements['num'].value;
		valor = 0;
		for (var x=0; x < num; x++) {
			if(document.forms['catpar'].elements["fase["+x+"]"].value == ''){valor++;}
		}//for
		if (valor != 0){
			alert("Por favor, inserta el campo fase");return false;
		}
	}//
}

function validar_estpar(op){
	if(op == "add")if (document.forms['estpar'].elements['estado'].value == '') {alert("Por favor, inserta el campo Estado.");return false;}
	if(op == "edit"){
		num = document.forms['estpar'].elements['num'].value;
		valor = 0;
		for (var x=0; x < num; x++) {
			if(document.forms['estpar'].elements["estado["+x+"]"].value == ''){valor++;}
		}//for
		if (valor != 0){
			alert("Por favor, inserta el campo Estado");return false;
		}
	}//
}

function validar_partidos(op){
		num = document.forms['partidos'].elements['num'].value;
		valor = 0;
		for (var x=0; x < num; x++) {
			if((document.forms['partidos'].elements["local["+x+"]"].value == '') || (document.forms['partidos'].elements["visitante["+x+"]"].value == '')){valor++;}
		}//for
		if (valor != 0){
			alert("Por favor, selecciona todos los equipos");return false;
		}
}

////FUNCIONES SELECTS MULTIPLES
function move(fbox,tbox,bpress) {
	cadena = "";
	cont = true;
	for(var i=0; i<fbox.options.length; i++) {
		if(fbox.options[i].selected && fbox.options[i].value != "") {
			var no = new Option();
			no.value = fbox.options[i].value;
			no.text = fbox.options[i].text;
			cadena+=no.value+",";
			tbox.options[tbox.options.length] = no;
			fbox.options[i].value = "";
			fbox.options[i].text = "";
			cont = false;
		}
	}
	if(cont == false)BumpUp(fbox);
	cadena = cadena.substring(0,cadena.length-1)
	id_categorias = catequip.id_categorias.value;
	id_tipos_partidos = catequip.id_tipos_partidos.value;
	if (cadena != ""){
		document.location.href("catequip.php?id_categorias="+id_categorias+"&id_tipos_partidos="+id_tipos_partidos+"&valores="+cadena+"&accion="+bpress+"");
	}else{
		alert("Debes seleccionar algun equipo");
	}
}

function BumpUp(box)  {
	for(var i=0; i<box.options.length; i++) {
		if(box.options[i].value == "")  {
			for(var j=i; j<box.options.length-1; j++)  {
				box.options[j].value = box.options[j+1].value;
				box.options[j].text = box.options[j+1].text;
			}
			var ln = i;
			break;
		}
	}
	if(ln < box.options.length)  {
		box.options.length -= 1;
		BumpUp(box);
	}
}
////FIN FUNCIONES SELECTS MULTIPLES

function soloNumeros(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 44)) {
        return false;
    }
    return true;
}

function crear_carpeta(formulario){
	if(formulario.elements['nombre'].value == ''){alert("Por favor, inserte el campo nombre");return false;}
}

function subir_imagen(formulario){
	if(formulario.elements['carpeta'].value == ''){alert("Por favor, seleccione o cree una carpeta");return false;}
	if(formulario.elements['userfile'].value == ''){alert("Por favor, seleccione una imagen");return false;}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}//function MM_jumpMenu

var popUpWin=0;
function popUpWindow(left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  address = "subimg.php";
  popUpWin = open(address, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
 
if (parseInt(navigator.appVersion) >= 4) popUpWin.moveTo((screen.width/2)-(left/2+395),(screen.height/2)-(top/2+250));
 
}
//FIN FUNCIONES ADMNISTRADOR

function new_freecap(){
	// loads new freecap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("freecap").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent caching
		document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*10000);
	} else {
		alert("Lo siento, ha sido imposible cargar otra palabra, recarge la página para generar otro código");
	}
}

function validar_sugerencias(){	
	if (document.forms['sugerencias'].elements['nombre'].value == '') {alert("Por favor, indica tú nombre.");return false;}
	if (document.forms['sugerencias'].elements['email'].value == '') {alert("Por favor, indica tú email.");return false;}
	if (document.sugerencias.email.value.indexOf('@') =='-1'){alert("El e-mail no es correcto");return false;}
	if (document.forms['sugerencias'].elements['asunto'].value == '') {alert("Por favor, indica el asunto.");return false;}
	if (document.forms['sugerencias'].elements['mensaje'].value == '') {alert("Por favor, indica el mensaje.");return false;}
	if (document.forms['sugerencias'].elements['word'].value == '') {alert("Por favor, inserta el código de seguridad.");return false;}
}

function cambiar(accion,num){
		var valor = document.getElementById("valoracion["+num+"]").value;
		
		if(accion == "suma")cantidad = parseFloat(document.getElementById("valoracion["+num+"]").value) + 0.5;
		if(accion == "resta"){
			if(document.getElementById("valoracion["+num+"]").value > 0)cantidad = parseFloat(document.getElementById("valoracion["+num+"]").value) - 0.5;
		}
		
		document.getElementById("valoracion["+num+"]").value = cantidad;
} // function




