var porid = {
	idname: function(e) {
		if(e.target.id){
			if(eval("this."+e.target.id)!=undefined){
				eval("this."+e.target.id)(e.target);
				}
			}
	},
	validacion: function (){
		if ($j('#oculVali').css("display")=="none"){
			$j('#oculVali').fadeIn('slow');
		}else{
			$j('#oculVali').fadeOut('slow');
		}
	},
	
	closeVali: function(){
		$j('#oculVali').fadeOut('slow');
	},
	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">Tarjetas de Cr&eacute;ditos / MultiEdwards</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 Edwards">Otros Productos y Servicios Banco Edwards</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 porclass = {
	valores : function(){
		if(document.getElementById('dolar')) $j('#dolar').html(valores[0].dolar);
		if(document.getElementById('euro')) $j('#euro').html(valores[0].euro);
		if(document.getElementById('uf')) $j('#uf').html(valores[0].uf);
		if(document.getElementById('ipc')) $j('#ipc').html(valores[0].ipc);
	},
	randoms : function(){
		$j.map($j('.imagTop'),function(e){e.id = 'imagTop'+parseInt(Math.random()*5+1);});
		$j.map($j('.bannSide'),function(e){e.id = 'bannSide'+parseInt(Math.random()*5+1);});
	},
	mapa : function(e){
		$j('#'+e.target.id).toggleClass('cerrar');
		if(!document.getElementById('mapa'+e.target.id)){
			$j('#'+e.target.id).parent().parent().after("<tr id='mapa"+e.target.id+"' class='acti actiMapa'></tr>");
			$j('#'+e.target.id).parent().parent().addClass('acti');
			$j('#mapa'+e.target.id).html(eval("mapas[0]."+e.target.id));
		}
		else{
			$j('#'+e.target.id).parent().parent().removeClass('acti');
			$j('#mapa'+e.target.id).remove();
		}
	}
}
var $j = jQuery.noConflict();
$j(document).ready( function() {
	if(document.getElementById('formulario')) {
		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í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ódigo de á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('#formulario').validate({
			errorPlacement: function(error, element) {
				error.appendTo( $j("#err-"+element[0].id) );

			},
			rules: {
				tipo: "required",
				asunto: "required",
				rut:  {
					required: true,
					number:true,
					minLength: 7,
					maxLength: 8
				},
				rut02:  {
					dv:true,
					number:true,
					minLength: 1,
					maxLength: 1
				},
				nombres: "required",
				paterno: "required",
				materno: "required",
				fono02: {
					required: true,
					telefono:true,
					number:true,
					minLength: 6,
					maxLength: 8
				},
				email: {
					required: true,
					email: true
				},
				reemail: {
					required: true,
					email: true,
					equalTo: "#email"
				},
				mensaje: "required"
			},
			messages: {
				tipo: "Por favor, seleccione un tipo de consulta",
				asunto: "Por favor, seleccione un asunto",
				rut: "Por favor, ingrese su rut",
				nombres: "Por favor, ingrese su nombre",
				paterno: "Por favor, ingrese su apellido paterno",
				materno: "Por favor, ingrese su apellido materno",
				fono02: "Por favor, ingrese su teléfono",
				email: "Por favor, ingrese su email",
				reemail: "Su email no coincide",
				mensaje: "Por favor, ingrese un mensaje"
			}
		});
	}
	$j('.remove').remove();
	$j('.hide').hide();
	$j('.show').show();
	porclass.valores();
	porclass.randoms();
	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;});
});