// JavaScript Document

function _Mostrar(n){
	
var campos = new Array();

campos[0] = "categorias";
campos[1] = "nombre";
campos[2] = "apellidos";
campos[3] = "empresa";
campos[4] = "email";
campos[5] = "url";
campos[6] = "titulo";
campos[7] = "descripcion";
campos[8] = "claves";



var z = campos.length;

	document.getElementById("bg-ayuda").style.visibility = "visible";
	document.getElementById("ic-ayuda").style.visibility = "visible";
	//document.getElementById("ayudatxt").style.visibility = "visible";	
	
	for(i=0; i!=z; i++){	

		if(document.getElementById(campos[i]).style.visibility == "visible"){
			document.getElementById(campos[i]).style.visibility = "hidden";
			document.getElementById(campos[i]+"txt").style.visibility = "hidden";
		}//end if
	}//end for

	document.getElementById(campos[n]).style.visibility = "visible";
	document.getElementById(campos[n]+"txt").style.visibility = "visible";
	document.getElementById("derecho").style.height = "700px";	


}//end function _Mostrar

function _Mostrarimg(n){
	
var campos = new Array();

campos[0] = "imagen";

var z = campos.length;

	document.getElementById("bg-ayuda").style.visibility = "visible";
	document.getElementById("ic-ayuda").style.visibility = "visible";
	//document.getElementById("ayudatxt").style.visibility = "visible";	
	
	for(i=0; i!=z; i++){	

		if(document.getElementById(campos[i]).style.visibility == "visible"){
			document.getElementById(campos[i]).style.visibility = "hidden";
			document.getElementById(campos[i]+"txt").style.visibility = "hidden";
		}//end if
	}//end for

	document.getElementById(campos[n]).style.visibility = "visible";
	document.getElementById(campos[n]+"txt").style.visibility = "visible";
	document.getElementById("derecho").style.height = "700px";	


}//end function _Mostrarimg

function _Inscripcion(nombre, apellidos, empresa, email, url, titulo, descripcion, claves){
	

	//comrueba las cantidad de palabras clave,  error 5
	
	var vclaves = _Claves(claves);
	if(vclaves == 1){
		var error5 = 0;
	}else{
		document.getElementById('status').innerHTML='Escribe como m&aacute;ximo 3 palabras claves';
	}	

	//comprueba selectedindex, error 4	
	var indice = document.forms.inscripcion.categoria.selectedIndex; 
	//valor del indice escogido
    var valor = document.forms.inscripcion.categoria.options[indice].value; 
	
	if(valor != "none"){
		var error4 = 0;
	}else{
		document.getElementById('status').innerHTML='Selecciona una opci&oacute;n de la lista.';
	}
	
	//comrueba la formato de la url,  error 3
	
	var curl = _Url(url);
	if(curl == 1){
		var error3 = 0;
	}else{
		document.getElementById('status').innerHTML='La direcci&oacute;n URL no es una direcci&oacute;n v&aacute;lida.';
	}	
	
//comprueba email, error 2
	var cemail = _eMail(email);
	
	if(cemail == 1){
		var error2 = 0;
	}else{
		document.getElementById('status').innerHTML='Escribe una direcci&oacute;n de e-Mail correcta.';		
	}
	
//comprueba campos vacios, error 1

	var vemail = _Vacio(email);
	var vurl = _Vacio(url);
	var vtitulo = _Vacio(titulo);
	var vdescripcion = _Vacio(descripcion);
	var vclaves = _Vacio(claves);	
	if(vemail == 1 && vurl == 1 && vtitulo == 1 && vdescripcion == 1 && vclaves == 1){
		
		var error1 = 0;
		
	}else{
		document.getElementById('status').innerHTML='Rellena los campos obligatorios.';
	}
	
//comprueba el formato de la url, error de url
//comprueba el las palabras clave separadas por coma, error de pclaves

	//si todo errores 0, submit
	if(error1 == 0 && error2 == 0 && error3 == 0 && error4 == 0 && error5 == 0){
		document.forms.inscripcion.submit();			
	}//end if errorx	

}//end function _Inscripcion


function _Claves(claves){
	
	var ok = 1;
	var arclaves = new Array();	
	var temp = "";
	var claves2 = "";

	z = claves.length;

	for(i=0; i<=z; i++){
		temp = claves.charAt(i);
		claves2 = claves2 + temp.replace(/ /, "");
	}

	//alert(claves2);
	arclaves = claves2.split(/,/);

	var num = arclaves.length;	
	//alert(num);
	
	if(num <= 3){
		return ok;
	}

	
}//end function _Claves


function _Url(url){
	
	var ok = 1;
	var ptos = -1;
	var www = url.lastIndexOf("www."); 
	var ptoini = url.indexOf(".");
	var ptofin = url.lastIndexOf(".");

	if(ptoini < ptofin){
		ptos = 1; 	
	}

	if(www != -1 && ptos != -1){
		return ok;
	}

	
}//end function _Url


function _Vacio(campo){

	var ok = 1;	
	if (campo != "" && campo != "undefined") {
		return ok;
	}
	
}//end function _Vacio

function _eMail(email){

	var ok = 1; 
	var arr = email.lastIndexOf("@"); 
	var pto = email.lastIndexOf(".");

	if(arr != -1 && pto != -1){
		return ok;
		//error = 2;
		//url = _Url();
		//document.location.assign(url+'?error='+error);	
	}
	
}//end function _eMail

function _Imagen(){
var picture;
var desiredWidth = 190;
var desiredHeight = 126;
picture = document.getElementById('upload');
	if ( (picture.width >= desiredWidth ) && (picture.height >= desiredHeight) ){
		document.getElementById('status_IMG').innerHTML='Imagen enviada correctamente';
	} else {
		document.getElementById('status_IMG').innerHTML='Imagen con resolución insuficiente.<br />';
	}

}//end function _Imagen
