var porid = {
	idname: function(e) {
		if(e.target.id){
			if(eval("this."+e.target.id)!=undefined){
				eval("this."+e.target.id)(e.target);
				}
			}
	},
	combos: function(){
		if ($j('#tipo').val()=="Consulta de sus productos y servicios"){
			$j('#asunto').html('<option value="">Seleccione un asunto</option><option value="Cuenta Corriente y Servicios">Cuenta Corriente y Servicios</option><option value="Tarjetas de cr&eacute;ditos / ChileCard">Tarjetas de cr&eacute;ditos / ChileCard</option><option value="Cr&eacute;ditos">Cr&eacute;ditos</option><option value="Productos de Inversi&oacute;n / Ahorro">Productos de Inversi&oacute;n / Ahorro</option><option value="Seguros">Seguros</option><option value="Otros productos y servicios Banco de Chile">Otros productos y servicios Banco de Chile</option>');
			document.getElementById('asunto').selectedIndex=0;
		}
		if ($j('#tipo').val()=="Solicitud de claves"){
			$j('#asunto').html('<option value="Redbanc, Internet, Fonobank">Redbanc, Internet, Fonobank</option>');
		}
		if ($j('#tipo').val()=="Línea Clientes"){
			$j('#asunto').html('<option value="">Seleccione un asunto</option>');
		}			
		if ($j('#tipo').val()==""){
			$j('#asunto').html('<option value="">Seleccione un asunto</option>');
		}
	}
}

var $j = jQuery.noConflict();
$j(document).ready( function() {
	if(document.getElementById('theform')) {
		jQuery.validator.addMethod("dv", function() {
			var M=0,S=1,T = $j('#rut').val();
			for(;T;T=Math.floor(T/10))
			S=(S+T%10*(9-M++%6))%11;
			var num = S?S-1:'K';
			if(num!= $j("#rut02").val() ){
				if ( $j("#rut02").attr("class")!="alert"){
					$j("#rut02").addClass('alert');
					$j("#err-rut").remove();
				}
			}
			else{
				$j("#err-rut02").html(' ');
			}
			return num==$j("#rut02").val();
		},
		"Ingrese un d&iacute;gito verificador correcto");
		jQuery.validator.addMethod("dEmp", function() {
			var M=0,S=1,T = $j('#rutEmp').val();
			for(;T;T=Math.floor(T/10))
			S=(S+T%10*(9-M++%6))%11;
			var num = S?S-1:'k';
			if(num!= $j("#rutEmp02").val() ){
				if ( $j("#rutEmp02").attr("class")!="alert"){
					$j("#rutEmp02").addClass('alert');
					$j("#err-rutEmp").remove();
				}
			}
			else{
				$j("#err-rutEmp02").html(' ');
			}
			return num==$j("#rutEmp02").val();
		},
		"Ingrese un d&iacute;gito verificador correcto");
		jQuery.validator.addMethod("telefono", function() {
			if( !$j("#fono").val()){
				if ( $j("#fono").attr("class")!="alert"){
					$j("#fono").addClass('alert');
					$j("#err-fono02").remove();
					$j("#err-fono").html('<span class="alert">Por favor, ingrese su c&oacute;digo de &aacute;rea</span>');
				}
			}
			else{
				$j("#fono").removeClass('alert');
				$j("#fono02").removeClass('alert');
				$j("#err-fono").html(' ');
			}
			return $j("#fono").val() || false;
		},
		"Por favor, ingrese su código de área");
		$j('#theform').validate({
			errorPlacement: function(error, element) {
				error.appendTo( $j("#err-"+element[0].id) );

			},
			rules: {
				tipcontacto: "required",
				tipo2: "required",
				asunto: "required",
				RazSoc: "required",
				rut01:  {
					required: true,
					number:true,
					minLength: 7,
					maxLength: 8
				},
				rut02:  {
					dv:true,
					minLength: 1,
					maxLength: 1
				},
				rutEmp: {
					required: true,
					number:true,
					minLength: 7,
					maxLength: 8
				},
				rutEmp02:  {
					dEmp:true,
					minLength: 1,
					maxLength: 1
				},
				nombre: "required",
				ap_paterno: "required",
				ap_materno: "required",
				cargCont: "required",
				telefono: {
					required: true,
					telefono:true,
					number:true,
					minLength: 6,
					maxLength: 8
				},
				mail: {
					required: true,
					email: true
				},
				confmail: {
					required: true,
					email: true,
					equalTo: "#email"					
				},
				sugerencia: "required"
			},
			messages: {
				tipcontacto: "Por favor, seleccione un tipo de contacto",
				tipo2: "Por favor, seleccione un producto",
				asunto: "Por favor, seleccione un asunto",
				RazSoc: "Por favor, ingrese Nombre o raz&oacute;n Social",
				rut01: "Por favor, ingrese un Rut V&aacute;lido",
				rutEmp: "Por favor, ingrese rut empresa",
				nombre: "Por favor, ingrese su nombre",
				ap_paterno: "Por favor, ingrese su apellido paterno",
				ap_materno: "Por favor, ingrese su apellido materno",
				cargCont: "Por favor, ingrese su cargo",
				telefono: "Por favor, ingrese un Tel&eacute;fono V&aacute;lido",
				mail: "Por favor, ingrese un mail V&aacute;lido",
				confmail: "Verifique que su mail coincida y sea v&aacute;lido",
				sugerencia: "Por favor, ingrese un mensaje"
			}
		});
	}
	$j('.remove').remove();
	$j('.hide').hide();
	$j('.show').show();
	if ($j('#tipo')) $j('#tipo').bind("change", porid.combos);
	$j('.mapa').bind("click", function(e){porclass.mapa(e); return false;});
	$j('.js').bind("click", function(e){porid.idname(e); return false;});
});

