function isset(variable_name) {
	try {
		if (typeof(eval(variable_name)) != 'undefined')
		if (eval(variable_name) != null)
		return true;
	} catch(e) { }
	return false;
}
function esMail( email ) {
	var filtro=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	return filtro.test( email );
}
function modulo11( dv, rut ) {
	/* proceso */
	var suma = 0;
	var mult = 2;

	if ( dv == "K" ) {
		dv = "10";
	}
	for ( i = rut.length - 1; i >= 0; i-- ) {
		c = rut.charAt(i);
		suma += parseInt( c, 10 ) * mult;
		mult++;
		if ( mult > 7 ) {
			mult = 2;
		}
	}
	var dvCalculado = 11 - suma % 11;
	if ( dvCalculado == 11 ) {
		dvCalculado = 0;
	}
	return( parseInt( dv ) == dvCalculado );
}

function validaRut( valorRut, valorDV ) {
	if( !valorRut || !valorDV )
		return false;
	var ElRut = valorRut.toUpperCase();
	var ElDv = valorDV.toUpperCase();
	var rut00 = "000000000";
	/* validaciones varias */
	if ( ( ElRut.length < 5 ) || ( ElRut.substring( 0, 1 ) == "0" ) || ( rut00.substring( 0, ElRut.length ) == ElRut ) 
		|| ( ElRut.length == 0 ) || ( ElDv.length == 0 ) ) {
		return false;
	}
	for( i = 0; i < ElRut.length; i++ ) {
		c = ElRut.charAt( i );
		if ( c < "0" || c > "9" ) {
			return false;
		}
	}
	c = ElDv.charAt(0);
	if ( ( c < "0" || c > "9" ) && c != "K" ) {
		return false;
	}
	return modulo11( ElDv, ElRut );
}

function validar_contacto(){
	if( $('nombre').value==""){
		alert( "Debe ingresar Nombre." );
		$('nombre').focus();
		return false;
	}
	if( $('apellido').value==""){
		alert( "Debe ingresar Apellido." );
		$('apellido').focus();
		return false;
	}
	if( $('rut').value=="" && $('tipo').value != 10){
		alert( "Debe ingresar RUT." );
		$('rut').focus();
		return false;
	}
	if(!validaRut($('rut').value,$('dv').value) && $('tipo').value != 10){
		alert( "Debe ingresar un RUT v\u00E1lido." );
		$('rut').focus();
		return false;
	}
	//valid rut
	if( $('mail').value==""){
		alert( "Debe ingresar su E-mail." );
		$('mail').focus();
		return false;
	}
	if( !esMail($('mail').value)){
		alert( "Debe ingresar un E-mail v\u00E1lido." );
		$('mail').focus();
		return false;
	}
	if( $('direccion').value==""){
		alert( "Debe ingresar Direcci\u00F3n." );
		$('direccion').focus();
		return false;
	}
	if( $('fono').value==""){
		alert( "Debe ingresar Tel\u00E9fono." );
		$('fono').focus();
		return false;
	}
	if( $('comuna').value==""){
		alert( "Debe ingresar Comuna." );
		$('comuna').focus();
		return false;
	}
	if ( $('tipo').value == "" ) {
		alert( "Debe seleccionar el Tipo de Consulta." );
		$('tipo').focus();
		return false;
	}
	if ( ( $('tipo').value == TIPOCONSULTA_ATENCION_VECINO || $('tipo').value == TIPOCONSULTA_SUGERENCIAS ) && $('asuntoAtencionVecino').value == "" ) {
		alert( "Debe ingresar el Asunto." );
		$('asuntoAtencionVecino').focus();
		return false;
	}
	if( $('subtipo').value==""){
		alert( "Debe seleccionar Especialidad." );
		$('tipo').focus();
		return false;
	}
	if ( $('tipo').value == 10 ){
		
		if ( $('archivoAdjunto').value == "" ){
			alert( "Debe ingresar Archivo." );
			$('archivoAdjunto').focus();
			return false;
		}
		
	}
	if( $('comentarios').value==""){
		alert( "Debe ingresar Comentarios." );
		$('comentarios').focus();
		return false;
	}
	
	
		
		
	
	return true;
}
