function Validator(theForm)
{
	var error = ""; 
	var error2 ="";
	var digits = "0123456789";
	
	/*
	if (theForm.dd.options[0].selected == true)
	{
		error += "Please select from the dropdown list.";
	}
	*/
	// Apellidos 
	if (theForm.apellidos.value == "")
	{
		error += "- Apellidos\n";
	}
	// Nombres
	if (theForm.nombres.value == "")
	{
		error += "- Nombres\n";
	}
	// Cedula
	if (theForm.cedula.value == "")
	{
		error += "- Numero de Cédula\n";
	}
	// Cedula
	if (theForm.contrasena_1.value == "" || theForm.contrasena_2.value == "")
	{
		error += "- Contrase–a\n";
	}
    else if( theForm.contrasena_1.value != theForm.contrasena_2.value)
    {
		error += "- Las Contrase–as entradas no son iguales\n";        
    }
    
    
	// Lugar de expedicion de la Cedula
	if (theForm.cedulaexp.value == "")
	{
		error += "- Ciudad de expedicion de la Cédula\n";
	}
	// Fecha de Nacimiento
	if (theForm.fechanaci.value == "")
	{
		error += "- Fecha de Nacimiento\n";
	}
	// Lugar de Nacimiento
	if (theForm.ciunaci.value == "")
	{
		error += "- Ciudad de Nacimiento\n";
	}
	// Estado Civil
	if (theForm.estadocivil.options[theForm.estadocivil.selectedIndex].value == "_")
	{
		error += "- Estado Civil\n";
	}
	// Sexo
	if (!theForm.sexo[0].checked && !theForm.sexo[1].checked)
	{
		error += "- Sexo\n";
	}
	
	// Pasaporte
	/*
	if (theForm.pasaporteno.value == "")
	{
		error += "- Pasaporte\n";
	}
	// Lugar de expedicion del Pasaporte
	if (theForm.pasaporteexp.value == "")
	{
		error += "- Lugar de expedición del pasaporte\n";
	}
	// Fecha de Expedicion del Pasaporte
	if (theForm.fechaexp.value == "")
	{
		error += "- Fecha de expedición del pasaporte\n";
	}
	// Fecha de Nacimiento
	if (theForm.fechavenc.value == "")
	{
		error += "- Fecha de vencimiento del pasaporte\n";
	}
	// Fecha de Nacimiento
	if (theForm.fechaaus.value == "")
	{
		error += "- Fecha de ingreso a Australia\n";
	}
	*/

	// Pais
	if (theForm.pais.options[theForm.pais.selectedIndex].value == "_")
	{
		error += "- Pais\n";
	}
	// Domicilio
	if (theForm.domicilioau.value == "")
	{
		error += "- Direccion domicilio\n";
	}
	// Suburbio
	if (theForm.suburbio.value == "")
	{
		error += "- Suburbio\n";
	}
	// Estado
	if (theForm.estado.options[theForm.estado.selectedIndex].value == "_")
	{
		error += "- Estado\n";
	}
	// Post Code
	if (theForm.postcode.value == "")
	{
		error += "- Postcode\n";
	}
	// Post Code
	if (theForm.celular.value == "" && theForm.telcasa.value == "" )
	{
		error += "- Numero Telefónico (Celular o Casa) \n";
	}

	/*
	if (theForm.number.value == "")
	{
		error += "Please fill in a number.";
	}
	*/
	/*
	for (var i = 0; i < theForm.number.value.length; i++)
	{
		temp = theForm.number.value.substring(i, i+1)

		if (digits.indexOf(temp) == -1 && 
			theForm.number.value != "")
		{
			error += "The numerical text must be a number.";
			break;
		}
	}
	*/


	if (theForm.correoe.value == "")
	{
		error += "- Email\n";
	}
	
    var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    var RE_EMAIL = /^(\w+[\-\.])*\w+@(\w+\.)+[A-Za-z]+$/;    
    if (!filter.test(theForm.correoe.value)){
		error2 += "\nEl Correo electronico suministrado es invalido";
    }else if(!RE_EMAIL.test(theForm.correoe.value)){
		error2 += "\nEl Correo electronico suministrado es invalido";
    }
    

    /*
    alert("-"+theForm.correoe.value+"-");	
    
	if ((theForm.correoe.value.indexOf ('@',0) == -1 ||
		theForm.correoe.value.indexOf ('.',0) == -1) &&
		theForm.correoe.value != "")
	{	
		error2 += "\nEl Correo electronico suministrado es invalido";
	}
	else
	{
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
        if (theForm.correoe.value.match(illegalChars)) {
		    error2 += "\n The email address contains illegal characters.";
		}           
	}
    */
		
	if (!theForm.autred[0].checked && !theForm.autred[1].checked)
	{
		error += "- Red de Estudiantes\n";
	}

	if (error != "")
	{
		error = "Los siguientes datos son requeridos:\n" + error;
		if (error2 != "")
		{
			error += error2;
		}
		alert(error);
		return false;
	}
	
	// Lock Submit Button
	return disableForm(theForm);
}

function Validator2(theForm)
{
	var error = ""; 
	var error2 ="";
	var digits = "0123456789";
	
	// Apellidos 
	if (theForm.apellidos.value == "")
	{
		error += "- Apellidos\n";
	}
	// Nombres
	if (theForm.nombres.value == "")
	{
		error += "- Nombres\n";
	}
	// Nombres
	if (theForm.nombre_comercial.value == "")
	{
		error += "- Nombre Comercial\n";
	}
	// Cedula
	if (theForm.cedula.value == "")
	{
		error += "- Numero de Cédula\n";
	}
	// Lugar de expedicion de la Cedula
	if (theForm.cedulaexp.value == "")
	{
		error += "- Ciudad de expedicion de la Cédula\n";
	}
	// Categoria
	if (theForm.categoria.options[theForm.categoria.selectedIndex].value == "_")
	{
		error += "- Categoria\n";
	}
	// Tipo Categoria
	if (theForm.subcategoria.options[theForm.subcategoria.selectedIndex].value == "_")
	{
		error += "- Area\n";
	}
	// Pais
	if (theForm.pais.options[theForm.pais.selectedIndex].value == "_")
	{
		error += "- País\n";
	}
	// Domicilio
	if (theForm.domicilioau.value == "")
	{
		error += "- Direccion domicilio\n";
	}
	// Suburbio
	if (theForm.suburbio.value == "")
	{
		error += "- Suburbio\n";
	}
	// Estado
	if (theForm.estado.options[theForm.estado.selectedIndex].value == "_")
	{
		error += "- Estado\n";
	}
	// Post Code
	if (theForm.postcode.value == "")
	{
		error += "- Postcode\n";
	}
	// Post Code
	if (theForm.celular.value == "" && theForm.telcasa.value == "" )
	{
		error += "- Numero Telefónico (Celular o Casa) \n";
	}
	if (theForm.correoe.value == "")
	{
		error += "- Email\n";
	}
	if ((theForm.correoe.value.indexOf ('@',0) == -1 ||
		theForm.correoe.value.indexOf ('.',0) == -1) &&
		theForm.correoe.value != "")
	{
		error2 += "\nEl Correo electronico suministrado es invalido";
	} 

	if (error != "")
	{
		error = "Los siguientes datos son requeridos:\n" + error;
		if (error2 != "")
		{
			error += error2;
		}
		alert(error);
		return false;
	}
	
	// Lock Submit Button
	return disableForm(theForm);
}

function Validator_cedulas(theForm)
{
	var error = ""; 
	var error2 ="";
	var digits = "0123456789";
	
	// Renovacion o Duplicado
	if (!theForm.tipo_solicitud[0].checked && !theForm.tipo_solicitud[1].checked)
	{
		error += "- Renovación ó Duplicado\n";
	}
	// Nombres
	if (theForm.nombres.value == "")
	{
		error += "- Nombres\n";
	}
	// Apellidos 
	if (theForm.apellidos.value == "")
	{
		error += "- Apellidos\n";
	}
	// Cedula
	if (theForm.cedula.value == "")
	{
		error += "- Numero de Cédula\n";
	}
	// Lugar de expedicion de la Cedula
	if (theForm.cedulaexp.value == "")
	{
		error += "- Ciudad de expedicion de la Cédula\n";
	}
	// Fecha de Nacimiento
	if (theForm.fechanaci.value == "")
	{
		error += "- Fecha de Nacimiento\n";
	}
	// Lugar de Nacimiento
	if (theForm.ciunaci.value == "")
	{
		error += "- Ciudad de Nacimiento\n";
	}
	// Lugar de Nacimiento
	if (theForm.deptonaci.value == "")
	{
		error += "- Departamento de Nacimiento\n";
	}
	// Factor RH
	if (theForm.factor_rh.options[theForm.factor_rh.selectedIndex].value == "_")
	{
		error += "- Factor RH\n";
	}
	// Estatura
	if (theForm.estatura.options[theForm.estatura.selectedIndex].value == "_")
	{
		error += "- Estatura\n";
	}

	
	// Padre
	if (theForm.padre.value == "")
	{
		error += "- Nombres y Apellidos del Padre\n";
	}
	// Madre
	if (theForm.madre.value == "")
	{
		error += "- Nombres y Apellidos de la Madre\n";
	}
	// Pais
	if (theForm.pais.options[theForm.pais.selectedIndex].value == "_")
	{
		error += "- Pais\n";
	}
	// Domicilio
	if (theForm.domicilioau.value == "")
	{
		error += "- Direccion domicilio\n";
	}
	// Suburbio
	if (theForm.suburbio.value == "")
	{
		error += "- Suburbio\n";
	}
	// Estado
	if (theForm.estado.options[theForm.estado.selectedIndex].value == "_")
	{
		error += "- Estado\n";
	}
	// Post Code
	if (theForm.postcode.value == "")
	{
		error += "- Postcode\n";
	}
	// Post Code
	if (theForm.celular.value == "" && theForm.telcasa.value == "" )
	{
		error += "- Numero Telefónico (Celular o Casa) \n";
	}

	/*
	if (theForm.number.value == "")
	{
		error += "Please fill in a number.";
	}
	*/
	/*
	for (var i = 0; i < theForm.number.value.length; i++)
	{
		temp = theForm.number.value.substring(i, i+1)

		if (digits.indexOf(temp) == -1 && 
			theForm.number.value != "")
		{
			error += "The numerical text must be a number.";
			break;
		}
	}
	*/


	if (theForm.correoe.value == "")
	{
		error += "- Email\n";
	}
	if ((theForm.correoe.value.indexOf ('@',0) == -1 ||
		theForm.correoe.value.indexOf ('.',0) == -1) &&
		theForm.correoe.value != "")
	{
		error2 += "\nEl Correo electronico suministrado es invalido";
	} 
	if (!theForm.consulado_movil[0].checked && !theForm.consulado_movil[1].checked && !theForm.consulado_movil[2].checked)
	{
		error += "- Consulado Movil (Brisbane, Nueva Zelanda o Sydney)\n";
	}

	if (error != "")
	{
		error = "Los siguientes datos son requeridos:\n" + error;
		if (error2 != "")
		{
			error += error2;
		}
		alert(error);
		return false;
	}
	
	// Lock Submit Button
	return disableForm(theForm);
}


function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function disableForm(theform) {
	if (document.all || document.getElementById) {
		for (i = 0; i < theform.length; i++) {
			var tempobj = theform.elements[i];
			if (tempobj.type) // If the element has a type (fieldset does not have a type then generates an error.
				if (tempobj.type.toLowerCase() == "submit")
					tempobj.disabled = true;
		}
	}
	return true;
}

function enableForm(theform) {
	if (document.all || document.getElementById) {
		for (i = 0; i < theform.length; i++) {
			var tempobj = theform.elements[i];
			if (tempobj.type) // If the element has a type (fieldset does not have a type then generates an error.
				if (tempobj.type.toLowerCase() == "submit")
					tempobj.disabled = false;
		}
	}
	return true;
}

function changeElementValue(elementId,text)
{
	document.getElementById (elementId).innerHTML=text;
	return true ;
}

function resetReportes(theform,elementId,text)
{
	return enableForm(theform) && changeElementValue(elementId,text);
}

function changeSelectedOption(list, value)
{
	for(i=0;i<list.options.length;i++)
	{
		if(list.options[i].value==value)
		{
			list.selectedIndex=i ;
		}
	}
}

function Validator05(theForm)
{
	var error = ""; 
	
	// Tramite
	if (theForm.tramite.options[theForm.tramite.selectedIndex].value == "_")
	{
		error += "- Tramite\n";
	}
	
	if (error != "")
	{
		error = "Los siguientes datos son requeridos:\n" + error;
		alert(error);
		return false;
	}
	
	// Lock Submit Button
	return disableForm(theForm);
}
