function ventanaSecundaria (URL,WIDTH,HEIGHT,NOMBRE){ 
	window.open(URL,NOMBRE,"width="+WIDTH+",height="+HEIGHT+",scrollbars=AUTO") 
} 
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}
function ocultar_capa (capa) {
	document.getElementById("datos_personales").style.display="block";
	
}

function display_capas_active (capa,modo) {
	if (modo != '') {
		document.getElementById(capa).style.display=modo;
	} else if (document.getElementById(capa).style.display=="none") {
		document.getElementById(capa).style.display="block";
	} else {
		document.getElementById(capa).style.display="none";
	}
	
}

function categoria_expand (categoria) {
	mcapa='categoria'+categoria;
	capa='subcategoria'+categoria;
	imagen='flechacat'+categoria;
	if (document.getElementById(capa).style.display=="none") {
		document[imagen].src='../skins/2006/imagenes/menu_flecha_on.gif';
		$(document.getElementById(mcapa)).addClass("mainon");
		$(document.getElementById(mcapa)).removeClass("mainoff");
	} else {
		document[imagen].src='../skins/2006/imagenes/menu_flecha_off.gif';
		$(document.getElementById(mcapa)).addClass("mainoff");
		$(document.getElementById(mcapa)).removeClass("mainon");
	}
	datos=display_capas_active (capa,'');
	/* CERRAR LA QUE ESTE ACTIVA */
	
	mcapa2='categoria'+menu_activo;
	capa2='subcategoria'+menu_activo;
	imagen2='flechacat'+menu_activo;
	
	
	
	if (capa2!=capa) {
		document[imagen2].src='../skins/2006/imagenes/menu_flecha_off.gif';
		$(document.getElementById(mcapa2)).addClass("mainoff");
		$(document.getElementById(mcapa2)).removeClass("mainon");
		datos=display_capas_active (capa2,'none');
	}
	
	menu_activo=categoria;
	
}

function expandir_volta (vuelta) {
	mcapa='vuelta'+vuelta;
	imagen='vuelta_img'+vuelta;
	mcapa2='vuelta'+vuelta_activa;
	imagen2='vuelta_img'+vuelta_activa;
	
	if (vuelta_activa!=vuelta) {
		document[imagen].src='../skins/2006/imagenes/btn_menos_02.gif';
		datos=display_capas_active (mcapa,'block');
		document[imagen2].src='../skins/2006/imagenes/btn_mas_02.gif';
		datos=display_capas_active (mcapa2,'none');
	}
	
	vuelta_activa=vuelta;
	
}

function consulta_expand (consulta) {
	capa='respuesta'+consulta;
	imagen='consulta'+consulta;
	if (document.getElementById(capa).style.display=="none") {
		document[imagen].src='../skins/2006/imagenes/btn_menos_02.gif';
	} else {
		document[imagen].src='../skins/2006/imagenes/btn_mas_02.gif';
	}
	datos=display_capas_active (capa,'');
	
}

function cduso_expand () {
	capa='condiciones_uso';
	imagen='condiciones_usoimg';
	if (document.getElementById(capa).style.display=="none") {
		document[imagen].src='../skins/2006/imagenes/btn_menos.gif';
	} else {
		document[imagen].src='../skins/2006/imagenes/btn_mas.gif';
	}
	datos=display_capas_active (capa,'');
	
}

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 "";
}

/* DATA CHECK **************************************************************************************************/
function checkFailed(id,name, color,mensaje) {
	id[name].style.background=(color);
	id[name].focus();
	window.alert(mensaje);
}
function checkFailedDate(id,name, color,mensaje) {
	id[name].style.background=(color);
	id[name].focus();
	window.alert(mensaje);
}

function checkFieldValueNotReq (id,name, mensaje,color) {
	var valor=id[name].value;
	if (valor=='') {
		return 1;
	} else {
		return 0;
	}	
}

function checkFieldValue (id,name, mensaje,color) {
	var valor=id[name].value;
	if (valor=='') {
		check=checkFailed(id,name, color,mensaje)
		return 1;
	} else {
		return 0;
	}	
}

function checkLongitud (id, name,longitud,mode,mensaje,color) {
	//window.alert(cadena+" "+cadena.length+" "+longitud+" "+mode);
	var cadena = id[name].value;
	if (mode=="max") {
		if (cadena.length<longitud) {
			check=checkFailed(id,name, color,mensaje)
			return 1;	
		} else {
			return 0;
		}
	} else if (mode=="min") {
		if (cadena.length>longitud) {
			check=checkFailed(id,name, color,mensaje)
			return 1;	
		} else {
			return 0;
		}
	} else if (mode=="exact") {
		
		if (cadena.length==longitud) {
			return 0;	
		} else {
			check=checkFailed(id,name, color,mensaje)
			return 1;
		}
	}
}

function checkEmail (id, name,mensaje,color) {
	var emailStr = id[name].value;
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		check=checkFailed(id,name, color,mensaje)
		return 1
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
		check=checkFailed(id,name, color,mensaje)
		return 1
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				check=checkFailed(id,name, color,mensaje)
				return 1
			}
		}
		return 0
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		check=checkFailed(id,name, color,mensaje)
		return 1
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
    	domArr[domArr.length-1].length>3) {
		check=checkFailed(id,name, color,mensaje)
   		return 1
	}
	if (len<2) {
		check=checkFailed(id,name, color,mensaje)
	   return 1
	}

	return 0;
}

function checkString (id, name,mensaje,color) {
	var cadena = id[name].value;
	var patron=/[a-zA-Z]/
	var patron2=/[0-9]/
	
	var matchArray=cadena.match(patron)
	if (cadena.lenght<2) {
		check=checkFailed(id,name, color,mensaje)
	   return 1
	}
	if (matchArray==null) {
		check=checkFailed(id,name, color,mensaje)
		return 1
	}
	var matchArray=cadena.match(patron2)
	if (matchArray!==null) {
		check=checkFailed(id,name, color,mensaje)
		return 1
	}
	

	return 0;
}

function checkInt (id,name,mensaje,color) {
	var valor=id[name].value;
	if (isNaN(valor)==true) {
		check=checkFailed(id,name, color,mensaje)
		return 1;
	} else {
		return 0;
	}
}
function checkDate (id,name, color,mensaje){
	var Cadena = id[name+"_dia"].value+"-"+id[name+"_mes"].value+"-"+id[name+"_year"].value;
	var Fecha= new String(Cadena)	// Crea un string
	var RealFecha= new Date()	// Para sacar la fecha de hoy
	
	var mydate=new Date();
	var year=mydate.getYear();
	if (year < 1000)
		year+=1900;
	var day=mydate.getDay();
	var month=mydate.getMonth()+1;
	if (month<10)
		month="0"+month;
	var daym=mydate.getDate();
	if (daym<10)
		daym="0"+daym;
	
	
	
	// Cadena Año
	var Ano= new String(Fecha.substring(Fecha.lastIndexOf("-")+1,Fecha.length))
	// Cadena Mes
	var Mes= new String(Fecha.substring(Fecha.indexOf("-")+1,Fecha.lastIndexOf("-")))
	if (Mes<10)
		Mes="0"+Mes;
	// Cadena Día
	var Dia= new String(Fecha.substring(0,Fecha.indexOf("-")))
	if (Dia<10)
		Dia="0"+Dia;
		
	ahora=year+"-"+month+"-"+daym;
	compare=Ano+"-"+Mes+"-"+Dia;
	if (ahora<compare) {
		check=checkFailed(id,name+"_year", color,mensaje)
		return 1;		
	}
	// Valido el año
	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){
			check=checkFailed(id,name+"_year", color,mensaje)
			return 1
	}
	// Valido el Mes
	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){
		check=checkFailed(id,name+"_mes", color,mensaje)
		return 1
	}
	// Valido el Dia
	if (isNaN(Dia) || parseInt(Dia)<1 || parseInt(Dia)>31){
		check=checkFailed(id,name+"_dia", color,mensaje)
		return 1
	}
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
		if (Mes==2 && Dia > 28 || Dia>30) {
			check=checkFailed(id,name+"_dia", color,mensaje)
			return 1
		}
	}
	
  //para que envie los datos, quitar las  2 lineas siguientes
  //alert("Fecha correcta.")
  return 0;
}
