function saltodetema(url,opcion,id){
	auxid="";
	if (id!=0){
		auxid=id;
	}
	auxzona="";
	if (url=="areas.asp"){
		auxzona=document.formarea.zona.value;
	}
	document.location.href=url+"?opcion="+opcion+"&id="+auxid+"&zona="+auxzona;
}

function abrir(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function flvFPW1(){// v1.3
// Copyright 2002, Marja Ribbers-de Vroed, FlevOOware (www.flevooware.nl/dreamweaver/)
var v1=arguments,v2=v1[2].split(","),v3=(v1.length>3)?v1[3]:false,v4=(v1.length>4)?parseInt(v1[4]):0,v5=(v1.length>5)?parseInt(v1[5]):0,v6,v7=0,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18;if (v4>1){v10=screen.width;for (v6=0;v6<v2.length;v6++){v18=v2[v6].split("=");if (v18[0]=="width"){v8=parseInt(v18[1]);}if (v18[0]=="left"){v9=parseInt(v18[1]);v11=v6;}}if (v4==2){v7=(v10-v8)/2;v11=v2.length;}else if (v4==3){v7=v10-v8-v9;}v2[v11]="left="+v7;}if (v5>1){v14=screen.height;for (v6=0;v6<v2.length;v6++){v18=v2[v6].split("=");if (v18[0]=="height"){v12=parseInt(v18[1]);}if (v18[0]=="top"){v13=parseInt(v18[1]);v15=v6;}}if (v5==2){v7=(v14-v12)/2;v15=v2.length;}else if (v5==3){v7=v14-v12-v13;}v2[v15]="top="+v7;}v16=v2.join(",");v17=window.open(v1[0],v1[1],v16);if (v3){v17.focus();}document.MM_returnValue=false;
}

/************************************************************************
FUNCIONES DE VALIDACION DE FORMULARIOS
**************************************************************************/
msje="Por favor, revise los errores en los siguientes campos:\n\n";
equivoc=0;
function emilio(contcorreo,nombrecampo){
        //compruebo el emilio
                var correo=contcorreo;
                var fallo_correo = 0;
                var pos = correo.indexOf("@");
                
                if (pos == -1){
                        equivoc=1;
                        fallo_correo = 1;
                }
        
        //compruebo q tenga al menos 1 carácter antes y después de le arroba y el punto
                if ((pos == 0)||(pos == correo.length-1)) {
                        equivoc=1;
                        fallo_correo = 1;
                }
                
                var pos2 = correo.lastIndexOf(".");
                if((pos2 < pos+1)||(pos2 == correo.length-1)){
                        equivoc=1;
                        fallo_correo = 1;        
                }

				if(correo.length>5){
					for (i=0; i<correo.length; i++){
							if (correo.charAt(i)==" ") {
							equivoc=1;
							fallo_correo = 1;
							}
					}
				}
                
                if (fallo_correo==1){
					var aux_nc=replaceChars(nombrecampo,'c_','');
					aux_nc=replaceChars(aux_nc,'_',' ');
                    msje+="· El campo '"+aux_nc+"' requiere una dirección de correo válida.\n";
                }
}

function validar_fecha(field){
	//compruebo la fecha mientras la mete el usuario; la función se la asigno directamente al campo
	//llamada a la funcion: onBlur="validar_fecha(caducidad)" el nombre del campo, sin comillas
	var checkstr = "0123456789";
	var DateField = field;
	var Datevalue = "";
	var DateTemp = "";
	var seperator = "/";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;
	err = 0;
	DateValue = DateField.value;
	/* borra todos los caracteres excepto 0..9 */
	for (i = 0; i < DateValue.length; i++) {
		  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
			 DateTemp = DateTemp + DateValue.substr(i,1);
		  }
	}
	DateValue = DateTemp;
   	/* Siempre cambio la fecha a 8 dígitos - cadena */
	/* si el año tiene 2 digitos/ se asume 20xx */
	if (DateValue.length == 6) {
		DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2);
	}
	if (DateValue.length != 8) {
		err = 19;
	}
	/* año incorrecto si es = 0000 */
	year = DateValue.substr(4,4);
	if (year == 0) {
		err = 20;
	}
	/* valido mes*/
	month = DateValue.substr(2,2);
	if ((month < 1) || (month > 12)) {
		err = 21;
	}
	/* valido día*/
	day = DateValue.substr(0,2);
	if (day < 1) {
		err = 22;
	}
	/* validación de año bisiesto */
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
		leap = 1;
	}
	if ((month == 2) && (leap == 1) && (day > 29)) {
		err = 23;
	}
	if ((month == 2) && (leap != 1) && (day > 28)) {
		err = 24;
	}
	/* validacion de otros meses */
	if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
		err = 25;
	}
	if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
		err = 26;
	}
	/* Si se mete 00, directamente borro */
	if ((day == 0) && (month == 0) && (year == 00)) {
		err = 0; day = ""; month = ""; year = ""; seperator = "";
	}
	/* si no hay error, lo meto en el campo */
	if (err == 0) {
		DateField.value = day + seperator + month + seperator + year;
	}
	/* Si el error es != 0 , mensaje */
	else {
		alert("La fecha es incorrecta");
		DateField.select();
		DateField.focus();
	}
}

function replaceChars(cadena,quito,pongo) {
	out = quito;
	add = pongo;
	temp = "" + cadena;
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function checkeacampo(tipo,campo,form){
	/*
	validacion de campos; "tipo" nos dice si es cadena, numero, fecha, dni,... Con "campo" le paso dos
	cosas: el nombre del campo y  si es o no obligatorio. por eso lo primero que hago es esplitear cada
	valor en la matriz "obligatorio"; la cadena que llega es así: "campo_n!1". 1 es obligatorio y 0, no. 
	Y finalmente, "form" es el nombre del formulario.
	*/
	var obligatorio=new Array();
	obligatorio=campo.split("!");
	var aux_cadena=eval("document."+form+"."+obligatorio[0]+".value");
	var nombrecampo=replaceChars(obligatorio[0],'c_','');
	nombrecampo=replaceChars(nombrecampo,'_',' ');
	//alert(nombrecampo);
	switch (tipo) {
		case 1:
		//numero
			if (isNaN(aux_cadena)) {
					equivoc=1;
					msje+="· El campo '"+nombrecampo+"' debe ser un número.\n";
			}
			if ( (aux_cadena=="") && (obligatorio[1]==1) ) {
					equivoc=1;
					msje+="· El campo '"+nombrecampo+"' es obligatorio.\n";
			}
		break;
		case 21:
		//numero DNI; quito la validacion de numero porque se flipa
			/*if (isNaN(eval("document."+form+"."+obligatorio[0]+".value"))) {
					equivoc=1;
					msje+="· El campo '"+obligatorio[0]+"' debe ser un número.\n";
			}*/
			if ( (aux_cadena=="") && (obligatorio[1]==1) ) {
					equivoc=1;
					msje+="· El campo '"+nombrecampo+"' es obligatorio.\n";
			}
		break;
		case 4:
		//fecha corta
			if ( (aux_cadena=="") && (obligatorio[1]==1) ) {
					equivoc=1;
					msje+="· El campo '"+nombrecampo+"' es obligatorio.\n";
			}
		break;
		case 20:
			//correo
			if (obligatorio[1]==1) {
					emilio("'"+aux_cadena+"'","'"+obligatorio[0]+"'");
			}else if (aux_cadena!=""){
					emilio("'"+aux_cadena+"'","'"+obligatorio[0]+"'");
			}
		break;
		case 12:
		//editor
		break;
		case 25:
		//hora: 21:30
			var expresion=new RegExp("[0-23]:[0-59]");
			if (obligatorio[1]==1){
				if ( (aux_cadena=="") && ((aux_cadena.search(expresion))!=1) ) {
						equivoc=1;
						msje+="· El campo '"+nombrecampo+"' es obligatorio.\n";
				}
			}else{
				if ( (aux_cadena!="") && ((aux_cadena.search(expresion))!=1) ) {
						equivoc=1;
						//msje+="· El campo '"+obligatorio[0]+"' debe contener una hora válida.\n";
						msje+="· El campo '"+nombrecampo+"' debe contener una hora válida.\n";
				}
			}
		break;
	
		default:
		//texto
			if ( (aux_cadena=="") && (obligatorio[1]==1) ) {
					equivoc=1;
					msje+="· El campo '"+nombrecampo+"' es obligatorio.\n";
			}
		break;
	}
}

/*ejempo de cadena:
validar('Idestado_civil!0|10#numero_hijos!0|1#f_nac!1|4#email!0|20#email2!0|20#Idlugar_nacimiento!0|10#','formulario')
siendo: nombre de campo!obligatorio|tipo de campo#; los tipos, los que hay arriba en la función checkeacampo
*/
function validar(valor,nombreform){

	var matriz_obligatorios=new Array();
	matriz_obligatorios=valor.split("#");
	var longitud=(matriz_obligatorios.length)-1;
	var matriztipo=new Array(2);
	var matrizcampos=new Array();
	
	for (i=0;i<longitud;i++){
		matriztipo=matriz_obligatorios[i].split("|");
		matrizcampos[i]=matriztipo;
	}
	
	for (i=0;i<longitud;i++){
		eval("checkeacampo("+matrizcampos[i][1]+",'"+matrizcampos[i][0]+"','"+nombreform+"')");
	}
	
	if (equivoc==0){
		eval("document."+nombreform+".submit()");
	}else{
		alert(msje);
		equivoc=0;
		msje="Por favor, revise los errores en los siguientes campos:\n\n";
	}
}

function cambioestado(campo,ide,direccion){
	
	aux_estado=eval("document.form1."+campo+"_"+ide+".checked");
	valor="0";
	if(aux_estado==true){
		valor="1";
	}
	document.location.href=direccion+'&id='+ide+"&estado="+valor;
}

/************************************************************************
FUNCIONES MARCIANAS
**************************************************************************/
function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}