// JavaScript Document

//funciones para validar el rut
function revisarDigito( dvr )
{	
	dv = dvr + ""	
	if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')	
	{		
		alert("Debe ingresar un digito verificador valido");		
		//window.document.FORM1.rut.focus();		
		//window.document.FORM1.rut.select();		
		return false;	
	}	
	return true;
}

function revisarDigito2( crut )
{	
	largo = crut.length;	
	/*if ( largo < 2 )	
	{		
		alert("Debe ingresar el rut completo")		
		window.document.FORM1.rut.focus();		
		window.document.FORM1.rut.select();		
		return false;	
	}**/	
	if ( largo > 2 )		
		rut = crut.substring(0, largo - 1);	
	else		
		rut = crut.charAt(0);	
	dv = crut.charAt(largo-1);	
	revisarDigito( dv );	

	if ( rut == null || dv == null )
		return 0	

	var dvr = '0'	
	suma = 0	
	mul  = 2	

	for (i= rut.length -1 ; i >= 0; i--)	
	{	
		suma = suma + rut.charAt(i) * mul		
		if (mul == 7)			
			mul = 2		
		else    			
			mul++	
	}	
	res = suma % 11	
	if (res==1)		
		dvr = 'k'	
	else if (res==0)		
		dvr = '0'	
	else	
	{		
		dvi = 11-res		
		dvr = dvi + ""	
	}
	if ( dvr != dv.toLowerCase() )	
	{		
		alert("EL rut es incorrecto")		
		//window.document.FORM1.rut.focus();		
		//window.document.FORM1.rut.select();		
		return false	
	}

	return true
}

function Rut(texto)
{	
	var tmpstr = "";	
	for ( i=0; i < texto.length ; i++ )		
		if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' )
			tmpstr = tmpstr + texto.charAt(i);	
	texto = tmpstr;	
	largo = texto.length;	

	
	if ( largo < 2 )	
	{		
		alert("Debe ingresar el rut completo")		
		//window.document.FORM1.rut.focus();		
		//window.document.FORM1.rut.select();		
		return false;	
	}	

	for (i=0; i < largo ; i++ )	
	{			
		if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" )
 		{			
			alert("El valor ingresado no corresponde a un R.U.T valido");			
			//window.document.FORM1.rut.focus();			
			//window.document.FORM1.rut.select();			
			return false;		
		}	
	}	

	var invertido = "";	
	for ( i=(largo-1),j=0; i>=0; i--,j++ )		
		invertido = invertido + texto.charAt(i);	
	var dtexto = "";	
	dtexto = dtexto + invertido.charAt(0);	
	dtexto = dtexto + '-';	
	cnt = 0;	

	for ( i=1,j=2; i<largo; i++,j++ )	
	{		
		//alert("i=[" + i + "] j=[" + j +"]" );		
		if ( cnt == 3 )		
		{			
			dtexto = dtexto + '.';			
			j++;			
			dtexto = dtexto + invertido.charAt(i);			
			cnt = 1;		
		}		
		else		
		{				
			dtexto = dtexto + invertido.charAt(i);			
			cnt++;		
		}	
	}	

	invertido = "";	
	for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ )		
		invertido = invertido + dtexto.charAt(i);	

	window.document.inscripcion.rut.value = invertido.toUpperCase()		

	if ( revisarDigito2(texto) )		
		return true;	

	return false;
}

//fin de funciones para validar rut 

function valida_inscripcion(){
	var valida = true;
	blanco = '#ffffff';
	color = '#d1e4f5';
	if (document.getElementById('textservicio').value ==''){
	document.getElementById('textservicio').style.backgroundColor = color;
	}else document.getElementById('textservicio').style.backgroundColor = blanco;
	
	if (document.getElementById('direccion').value ==''){
		document.getElementById('direccion').style.backgroundColor = color;
		}else document.getElementById('direccion').style.backgroundColor = blanco;
		
	if (document.getElementById('region').value ==''){
		document.getElementById('region').style.backgroundColor = color;
		}else document.getElementById('region').style.backgroundColor = blanco;
		
	if (document.getElementById('comuna').value ==''){
		document.getElementById('comuna').style.backgroundColor = color;
		}else document.getElementById('comuna').style.backgroundColor = blanco;
		
	if(document.getElementById('razon_social').value == ''){
		document.getElementById('razon_social').style.backgroundColor = color;
		valida = false;
	
}else document.getElementById('razon_social').style.backgroundColor = blanco;

if(document.getElementById('nom_fantasia').value == ''){
		document.getElementById('nom_fantasia').style.backgroundColor = color;
		valida = false;
	
}else document.getElementById('nom_fantasia').style.backgroundColor = blanco;

if(document.getElementById('rut').value == ''){
		document.getElementById('rut').style.backgroundColor = color;
		valida = false;
	
}else document.getElementById('rut').style.backgroundColor = blanco;
if(document.getElementById('giro').value == ''){
		document.getElementById('giro').style.backgroundColor = color;
		valida = false;
	
}else document.getElementById('giro').style.backgroundColor = blanco;
if(document.getElementById('telefono').value == ''){
		document.getElementById('telefono').style.backgroundColor = color;
		valida = false;
	
}else document.getElementById('telefono').style.backgroundColor = blanco;
if(document.getElementById('nom_contacto').value == ''){
		document.getElementById('nom_contacto').style.backgroundColor = color;
		valida = false;
	
}else document.getElementById('nom_contacto').style.backgroundColor = blanco;
if(document.getElementById('apell_contacto').value == ''){
		document.getElementById('apell_contacto').style.backgroundColor = color;
		valida = false;
	
}else document.getElementById('apell_contacto').style.backgroundColor = blanco;
if(document.getElementById('cargo_contacto').value == ''){
		document.getElementById('cargo_contacto').style.backgroundColor = color;
		valida = false;
	
}else document.getElementById('cargo_contacto').style.backgroundColor = blanco;
if(document.getElementById('telefono_contacto').value == ''){
		document.getElementById('telefono_contacto').style.backgroundColor = color;
		valida = false;
	
}else document.getElementById('telefono_contacto').style.backgroundColor = blanco;



if (valida == false ){
	alert("Favor complete los datos que estan destacados *");

}else {
		document.inscripcion.submit();
}

	}
	
	
function busca_emp(){
	if(document.getElementById('as').value == '1'){
		document.frmfind.submit();
		}
	}

function busca_empresa(){

	document.busca.submit();
	document.getElementById('txtbuscar').value = '';
	document.getElementById('as').value = '1';
	}

function validaform(){
	var retorno = true;
if(document.getElementById('txtnombre').value == ''){
		document.getElementById('txtnombre').style.backgroundColor = '#d1e4f5';
		retorno = false;
	
}else document.getElementById('txtnombre').style.backgroundColor = '#ffffff';

if(document.getElementById('txtemail').value == ''){
		document.getElementById('txtemail').style.backgroundColor = '#d1e4f5';
		retorno = false;
		

}else document.getElementById('txtemail').style.backgroundColor = '#ffffff';

if(document.getElementById('txtfono').value == ''){
		document.getElementById('txtfono').style.backgroundColor = '#d1e4f5';
		retorno = false;
	

}else document.getElementById('txtfono').style.backgroundColor = '#ffffff';

if (retorno == false ){
	alert("Favor complete los datos que estan destacados");
	


}else {
		document.contacto.submit();
}
}

function validencuesta(){
	if (document.getElementById('textpregunta').value == ''){
		alert("Debe ingresar su respuesta antes de enviar la encuesta.");
		
		}else{ 
		document.encuesta.submit();
		document.getElementById('textpregunta').value = '';
		}
		
		
	}
	
function validaingreso(){
	envio = true;
if (document.getElementById('txtrut').value == ''){
	document.getElementById('txtrut').style.backgroundColor = '#d1e4f5';
	envio = false;
	}else document.getElementById('txtrut').style.backgroundColor = '#ffffff';
	
	if (document.getElementById('txtnom').value == ''){
	document.getElementById('txtnom').style.backgroundColor = '#d1e4f5';
	envio = false;
	}else document.getElementById('txtnom').style.backgroundColor = '#ffffff';
	
	if (document.getElementById('txtrazon').value == ''){
	document.getElementById('txtrazon').style.backgroundColor = '#d1e4f5';
	envio = false;
	}else document.getElementById('txtrazon').style.backgroundColor = '#ffffff';
	
	if (document.getElementById('txtgiro').value == ''){
	document.getElementById('txtgiro').style.backgroundColor = '#d1e4f5';
	envio = false;
	}else document.getElementById('txtgiro').style.backgroundColor = '#ffffff';
	
	if (document.getElementById('txtfono').value == ''){
	document.getElementById('txtfono').style.backgroundColor = '#d1e4f5';
	envio = false;
	}else document.getElementById('txtfono').style.backgroundColor = '#ffffff';
	
	if (document.getElementById('txtnombre').value == ''){
	document.getElementById('txtnombre').style.backgroundColor = '#d1e4f5';
	envio = false;
	}else document.getElementById('txtnombre').style.backgroundColor = '#ffffff';
	
	if (document.getElementById('txtapellido').value == ''){
	document.getElementById('txtapellido').style.backgroundColor = '#d1e4f5';
	envio = false;
	}else document.getElementById('txtapellido').style.backgroundColor = '#ffffff';
	
	
	if (document.getElementById('txtcargo').value == ''){
	document.getElementById('txtcargo').style.backgroundColor = '#d1e4f5';
	envio = false;
	}else document.getElementById('txtcargo').style.backgroundColor = '#ffffff';
	
	if (document.getElementById('txtfono_contacto').value == ''){
	document.getElementById('txtfono_contacto').style.backgroundColor = '#d1e4f5';
	envio = false;
	}else document.getElementById('txtfono_contacto').style.backgroundColor = '#ffffff';
	
	

if (envio == false ){
	alert("Favor complete los datos que estan destacados ");

}else {
		document.frmemp.submit();
}

}

//funcion valida numeros
function validar(e) { 
    tecla = (document.all) ? e.keyCode : e.which; 
    if (tecla==8) return true; 
    patron =/[0-9-(-)-\s]/;
    te = String.fromCharCode(tecla); 
    return patron.test(te); 
} 


	