// JavaScript Document
var mensajeError = new Array();
mensajeError['campoVacio'] = "El campo no puede estar Vacio";
mensajeError['soloLetras'] = "Ingrese solo caracteres Alfabeticos";
mensajeError['soloNumeros'] = "Ingrese solo Números";
mensajeError['valorDecimal'] = "El dato debe ser Décimal";
mensajeError['cedulaIncorrecta'] = "El formato de la Cédula es incorrecto";
mensajeError['fechaIncorrecta'] = "El formato de la Fecha es incorrecto (dd/mm/aaa)";
mensajeError['diaError'] = "El día debe estar entre 1 y 31";
mensajeError['mesError'] = "El mes debe estar entre 1 y 12";
mensajeError['anoError'] = "El año debe ser mayor a 1900";
mensajeError['telefonoIncorrecto'] = "El formato del teléfono es 0000-000000";
mensajeError['mailIncorrectoEspacio'] = "Ingrese un Correo Valido";
mensajeError['mailIncorrectoArroa'] = "Ingrese un Correo Valido";
mensajeError['mailIncorrectoPunto'] = "Ingrese un Correo Valido";
// ****************************************************************
//check email
	
	function check_email(e) 
{
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	var i=0;
	for(i=0; i < e.length ;i++)
	{
		if(ok.indexOf(e.charAt(i))<0)
		{ 
			return (false);
		}
	} 
		
	if (document.images) 
	{
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) 
		{
			return (-1);
		} 
	}	
}

function show_bill_controls()
{
 if(document.form1.needbill[0].checked==true) 
 {
	document.getElementById("billfields").style.visibility='visible';
	document.getElementById("billfields").style.height='100%';

	 
}
if(document.form1.needbill[1].checked==true)
	{
		document.getElementById("billfields").style.visibility='hidden';
	document.getElementById("billfields").style.height='2px';
	}
}

function textCounter(field, countfield, maxlimit)
{
if (field.value.length > maxlimit) // to0 long ->trim
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
function messageWindow(msg)
{
  var width="500", height="200";
  var title="Informaci&oacute;n del Ponente:";
  var cadena="info_ponente.php?ponente="+msg;
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open(cadena,"msgWindow", styleStr);
//  var head = '<head><title>'+title+'</title></head>';
//  var body = '<center>'+msg+'<br><p><form><input type="button" value="   Cerrar   " onClick="self.close()"></form>';
//  msgWindow.document.write(head + body);
}
// ****************************************************************
function sumar(campo,c2,valor)
{
	var a=parseInt(campo.value,10);
	var b=parseInt(c2.value,10);
	var valor=parseInt(valor,10);
	a=a+valor-b;
	campo.value=a;
	c2.value=valor;
}
function sumar_tot(campo1,campo2,dest)
{
	var a=parseInt(campo1.value,10);
	var b=parseInt(campo2.value,10);
	dest.value=a+b;
}
// ****************************************************************
function validar()
{
	var forma=document.form1;
    var i,a,x,y,dfg;
	a=false;
	x=false;
	y=false;
    dfg=false;
    for (i = 0; i < forma.opban.length; i++)
       if(forma.opban[i].checked)
              a=true;
   
   
   for (i = 0; i < forma.acts0.length; i++)
	   if(forma.acts0[i].checked)
		  	dfg=true;
            
            
	  
	if (isEmpty(forma.apellidos.value))
		alert("Debe Llenar el campo apellidos");
	else
	if (isEmpty(forma.nombres.value))
        alert("Debe Llenar el campo nombres");
    else
    if (isEmpty(forma.nif.value))
		alert("Debe Llenar el campo NIF o pasaporte");
	else
	//if (isEmpty(forma.domicilio.value))
		//alert("Debe Llenar el campo domicilio");
	//else
   
	if (isEmpty(forma.ciudad.value))
		alert("Debe Llenar el campo ciudad");
	else
	if (isEmpty(forma.hospital.value))
		alert("Debe Llenar el campo hospital");
	else
	//if (isEmpty(forma.cp.value))
		//alert("Debe Llenar el campo C.P.");
	//else
	if (forma.profesion.value.length < 4)
        alert("Debe Llenar el campo profesion");
    else
    
    if (forma.especialidad.value.length < 4)
		alert("Debe Llenar el campo especialidad");
	else
	//if (isEmpty(forma.telefono1.value))
		//alert("Debe Llenar el campo telefono1");
	//else
            
	if (isEmpty(forma.correo.value))
		alert("Debe Llenar el campo correo");
	else
	if (forma.dep.value=="0")
		alert("Seleccione un Simposio y/o Curso");
	else
	if (!a)
			alert("Debe Seleccionar una forma de pago");
	else
    if (!dfg)
            alert("Usted tiene que elegir si desea incluir Comidas y / o Actividades opcionales");
    else
	if(forma.needbill[0].checked==true)
	{
		if (isEmpty(forma.factura_nei.value))
		alert("Debe Llenar el campo Nombre/Empresa/Institucion");
		else
		if (isEmpty(forma.factura_nif_cif.value))
		alert("Debe Llenar el campo NIF/CIF");
		else
		if (isEmpty(forma.factura_dirrecion.value))
        alert("Debe Llenar el campo Direccion");
        else
        
		if (isEmpty(forma.factura_codpostal.value))
		alert("Debe Llenar el campo Codigo Postal");
		else
		if (isEmpty(forma.factura_ciudad.value))
		alert("Debe Llenar el campo Ciudad");
		else
		if (isEmpty(forma.factura_nombre.value))
		alert("Debe Llenar el campo Nombre de  la persona de contacto");
		else
		if (isEmpty(forma.factura_nombre.value))
		alert("Debe Llenar el campo Nombre de  la persona de contacto");
		else
		if (isEmpty(forma.factura_tel.value))
		alert("Debe Llenar el campo Telefono");
		else
		if (isEmpty(forma.factura_email.value))
		alert("Debe Llenar el campo E-mail");
		else
		if (!check_email(forma.factura_email.value))
		alert("E-mail Incorrecto.");
		else
		{
			forma.submit();
		}
	}
       
	else
	{
		forma.submit();
	}
	
}
// oyente
function validar_oyente()
{
	var forma=document.form1;

	  
	if (isEmpty(forma.apellidos.value))
		alert("Debe Llenar el campo apellidos");
	else
	if (isEmpty(forma.nombres.value))
		alert("Debe Llenar el campo nombres");
	else
	if (isEmpty(forma.domicilio.value))
		alert("Debe Llenar el campo domicilio");
	else
	if (isEmpty(forma.ciudad.value))
		alert("Debe Llenar el campo ciudad");
	else
	if (isEmpty(forma.hospital.value))
		alert("Debe Llenar el campo hospital");
	else
	if (isEmpty(forma.cp.value))
		alert("Debe Llenar el campo C.P.");
	else
	if (isEmpty(forma.especialidad.value))
		alert("Debe Llenar el campo especialidad");
	else
	if (isEmpty(forma.telefono1.value))
		alert("Debe Llenar el campo telefono1");
	else
	if (isEmpty(forma.correo.value))
		alert("Debe Llenar el campo correo");
	else
	{
			forma.submit();
	}


	
}
// ****************************************************************
function setFontColor(id,color)
{
	document.getElementById(id).style.color =  color; 
}
// ****************************************************************

function overm(celno,color,texte,colort)
{
	var chgcell;
	chgcell = document.getElementById(celno).bgColor=""+color;
	setFontColor(texte,""+colort);
}
// ****************************************************************

function outm(celno,color,texte,colort)
{ 
	var chgcell;
	chgcell = document.getElementById(celno).bgColor=""+color;
	setFontColor(texte,""+colort);
} 

// ****************************************************************

function cambiar(ref1)
{
	window.location = ref1;
}
// ****************************************************************

function Activar(cual)
{
	document.getElementById(cual).checked=true;
}
// ****************************************************************
function isEmpty(s)
{   return ((s == null) || (s.length == 0) || (s == 0))
}

// ****************************************************************
// s es numero de telefono valido
function isPhoneNumber (campo)
{ 
	var Expresion = new RegExp("[0-9]{4}-[0-9]{6,7}");
	var Texto = new String(campo.value);
	
	if(campo.value!="")
	{
		if (!Expresion.test(campo.value))
		{
			mensaje(mensajeError['telefonoIncorrecto']);
			seleccionar(campo);
		}
	}
}

// ****************************************************************
// s es una direccion de correo valida
function isEmail (cadena)
{
		
   var s = cadena.value;
   if (!isEmpty(s)) 
    {
		
		 for (i = 0; i < s.length; i++)
		 {   
			var c = s.substr(i,1);
			if (c == ' ' ||  c == 32 || c == 20)
			{
				mensaje(mensajeError['mailIncorrectoEspacio'] );
				seleccionar(cadena);
			}
		 } 
		var i=0;
		var sLength = s.length;
		while ((i < sLength) && (s.charAt(i) != "@"))
		{ i++
		}
			
		if ((i >= sLength) || (s.charAt(i) != "@")) 
		{
			mensaje(mensajeError['mailIncorrectoArroa']);
			seleccionar(cadena);
		}
		else
		{
			i += 2;		
			while ((i < sLength) && (s.charAt(i) != "."))
			{ i++
			}
		
			if ((i >= sLength - 1) || (s.charAt(i) != ".")) 
			{
				mensaje(mensajeError['mailIncorrectoPunto']);
				seleccionar(cadena);
			}
		}
	}
}

// ****************************************************************
function verificarCampo(campo)
{
	if (campo.value=="")
	{
		mensaje(mensajeError['campoVacio']);
		seleccionar(campo);
	}
}

// ****************************************************************
function agregarMetodo(forma,metodo)
{
	forma.METODO.value = metodo;
}

// ****************************************************************
function validarTexto(campo)
{

	var Expresion = new RegExp("^[a-zñA-ZÑáéíóú]+\.?\s?[a-zñA-ZÑáéíóú]+\.?$");
	var Texto = new String(campo.value);
	var i, codigoAscii;

	if(campo.value!="")
	{
		if (!Expresion.test(campo.value))
		{
			mensaje(mensajeError['soloLetras']);
			seleccionar(campo);
		}
	}
}

// ****************************************************************
function validarLetra(campo)
{
	var Expresion = new RegExp("^[a-zñA-ZÑáéíóú]{1}$");
	var Texto = new String(campo.value);
	var i, codigoAscii;

	if(campo.value!="")
	{
		if (!Expresion.test(campo.value))
		{
			mensaje(mensajeError['soloLetras']);
			seleccionar(campo);
		}
	}
}

// ****************************************************************
function validarNumero(campo)
{
	var i;
	var Expresion = new RegExp("^[0-9]+$");

	if(campo.value!="")
	{
		if (!Expresion.test(campo.value))
		{
			mensaje(mensajeError['soloNumeros']);
			seleccionar(campo);
		}
	}
}

// ****************************************************************
function validarCedula(campo)
{
	var Expresion = new RegExp("^[0-9]{1,2}\.?[0-9]{3}\.?[0-9]{3}$");
	var Texto = new String(campo.value);
	
	if(campo.value!="")
	{
		if (!Expresion.test(campo.value))
		{
			mensaje(mensajeError['cedulaIncorrecta']);
			seleccionar(campo);
		}
	}
}

// ****************************************************************
function validarFecha(campo)
{
	var Expresion = new RegExp("[0-9]{2}(/|-)[0-9]{2}(/|-)[0-9]{4}");
	var fechaCompleta = new String(campo.fechaNacimiento.value);
	var fechaActual = new Date();
	var dia, mes, ano, edad;

	if(campo.fechaNacimiento.value!="")
	{
		if (!Expresion.test(campo.fechaNacimiento.value))
		{
			mensaje(mensajeError['fechaIncorrecta']);
			seleccionar(campo.fechaNacimiento);
		}	
	
		dia = fechaCompleta.substring(0,2);
		mes = fechaCompleta.substring(3,5);
		ano = fechaCompleta.substring(6,10);

		if((parseInt(dia)>31 || parseInt(dia)==0) && (dia!="08" && dia!="09"))
		{
			mensaje(mensajeError['diaError']);
			seleccionar(campo.fechaNacimiento);
		}
		if((parseInt(mes)>12 || parseInt(mes)==0) && (mes!="08" && mes!="09"))
		{
			mensaje(mensajeError['mesError']);
			seleccionar(campo.fechaNacimiento);
		}
		if(parseInt(ano)<1900 || parseInt(ano)==0)
		{
			mensaje(mensajeError['anoError']);
			seleccionar(campo.fechaNacimiento);
		}
	
		edad = fechaActual.getFullYear() - parseInt(ano);
		if((fechaActual.getMonth()+1)<parseInt(mes))
			edad--;
		else
		{
			if((fechaActual.getMonth()+1)==parseInt(mes))
			{
				if(fechaActual.getDate()<parseInt(dia))
					edad--;
			}
		}
		campo.edad.value = parseInt(edad);
	}

}

// ****************************************************************
function mensaje(mensaje)
{
	alert(mensaje);
}

// ****************************************************************
function seleccionar(campo)
{
	campo.focus();
	campo.select();	
	return false;
}

//******************************************************************************************
function validarPalabra(forma,palabra)
{
	if (forma.criterio.value==1)
		validarCedula(palabra);
	else
		validarFechas(palabra);
}

//****************************************************************************************
function agregar(campo,destino,t)
{
	if(campo.selectedIndex<=0){ alert("Debe seleccionar un ponente"); return; }
    var no= destino.length;
    var indice = campo.selectedIndex;
    var valor = campo.options[indice].value; 
    var textoEscogido = campo.options[indice].text; 
	var y;
	for(y=0;y<30;y++)
		if(destino.options[y].value=="-1" || destino.options[y].value==valor)
			break;
	if(destino.options[y].value!=valor)
	{
		destino.options[y].value=valor;
		destino.options[y].text=textoEscogido;
	}
	var i="";
	for(y=1;y<30;y++)
		if(destino.options[y].value!="-1")
			i+=destino.options[y].value+"/";
	t.value=i;
}
//****************************************************************************************
function ordenp(campo,destino,t)
{
	var y;
    var valor = campo.value; 
	if(campo.checked)
	{
		for(y=0;y<9;y++)
			if(destino.options[y].value=="-1" || destino.options[y].value==valor)
				break;
		if(destino.options[y].value!=valor)
		{
			destino.options[y].value=valor;
			if(campo.name=="Correo")
				destino.options[y].text="Correo Electronico";
			else
			if(campo.name=="Observacion")
				destino.options[y].text="Observaciones";
			else				
			if(campo.name=="nombre")
				destino.options[y].text="Nombres";
			else				
			if(campo.name=="apellido")
				destino.options[y].text="Apellidos";
			else				
				destino.options[y].text=campo.name;
			
		}
	}else
	{
		for(y=0;y<9;y++)
			if(destino.options[y].value=="-1" || destino.options[y].value==valor)
				break;
		if(destino.options[y].value==valor)
		{
			for(var u=y;u<8;u++)
			{
				destino.options[u].value=destino.options[u+1].value;
				destino.options[u].text=destino.options[u+1].text;
			}
		}
	}
	var i="";
	for(y=0;y<8;y++)
		if(destino.options[y].value!="-1")
			i+=destino.options[y].value+"/";
	t.value=i;
}
//****************************************************************************************
function cambiarp(campo,dir,t)
{
    var indice = campo.selectedIndex;
    var valor = campo.options[indice].value; 
    var textoEscogido = campo.options[indice].text; 
    var valor = campo.value; 
	if(dir==1 && indice<6 && valor!="-1")
	if(campo.options[indice+1].value!="-1")
	{
				campo.options[indice].value=campo.options[indice+1].value;
				campo.options[indice].text=campo.options[indice+1].text;
				campo.options[indice+1].value=valor;
				campo.options[indice+1].text=textoEscogido;
				campo.selectedIndex=indice+1;
	}
	if(dir==2 && indice>0 && valor!="-1")
	if(campo.options[indice-1].value!="-1")
	{
				campo.options[indice].value=campo.options[indice-1].value;
				campo.options[indice].text=campo.options[indice-1].text;
				campo.options[indice-1].value=valor;
				campo.options[indice-1].text=textoEscogido;
				campo.selectedIndex=indice-1;
	}
	var i="";
	for(y=0;y<7;y++)
		if(campo.options[y].value!="-1")
			i+=campo.options[y].value+"/";
	t.value=i;
}
//****************************************************************************************
function eliminar(campo,destino,t)
{
    var indice = destino.selectedIndex;
    var valor = destino.options[indice].value; 
	if(destino.selectedIndex<=0 || valor==-1) { alert("Debe seleccionar un ponente"); return; }
    var textoEscogido = destino.options[indice].text; 
	var y;
	for(y=indice;y<30;y++)
	{
		destino.options[y].value=destino.options[y+1].value;
		destino.options[y].text=destino.options[y+1].text;
	}
	destino.options[29].value="";
	destino.options[29].text="";
	var i="";
	for(y=1;y<30;y++)
		if(destino.options[y].value!="-1")
			i+=destino.options[y].value+"/";
	t.value=i;

}
//****************************************************************************************
function grabar(formu)
{
	formu.val.value=1000;
	formu.submit();
}
//****************************************************************************************
function validarFechas(campo)
{

	var Expresion = new RegExp("[0-9]{2}(/|-)[0-9]{2}(/|-)[0-9]{4}");
	var fechaCompleta = new String(campo.value);
	var dia, mes, ano;
	
	if(campo.value!="")
	{
		if (!Expresion.test(campo.value))
		{
			mensaje(mensajeError['fechaIncorrecta']);
			seleccionar(campo);
		}	
		dia = fechaCompleta.substring(0,2);
		mes = fechaCompleta.substring(3,5);
		ano = fechaCompleta.substring(6,10);

		if((parseInt(dia)>31 || parseInt(dia)==0) && (dia!="08" && dia!="09"))
		{
			mensaje(mensajeError['diaError']);
			seleccionar(campo);
		}
		if((parseInt(mes)>12 || parseInt(mes)==0) && (mes!="08" && mes!="09"))
		{
			mensaje(mensajeError['mesError']);
			seleccionar(campo);
		}
		if(parseInt(ano)<1900 || parseInt(ano)==0)
		{
			mensaje(mensajeError['anoError']);
			seleccionar(campo);
		}
		
	}
}
//******************************************************************************************
