var datos = {}
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>');
				$j.id('#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>');
			}
	},
	startImagTop : function(){
		$j('#imagTopHome').innerfade({
			animationtype: 'fade',
			speed: 500,
			timeout: 6000,
			type: 'random_start',
			containerheight: '175px'
		});
		if(navigator.userAgent.match(/Safari/)) {
			$j('#global #imagTopHome li').css("height","175px");
		}
		$j('.imagTopThum').bind("click",function(e){ porid.stopImagTop(e); return false; });
	},
	stopImagTop : function(e){
		clearTimeout(time);
		$j(".topThum li").removeClass("acti");
		imag = e.target.id.split("-");
		$j("#imagTopHome li").fadeOut(500)
		$j("#"+imag[1]).fadeIn(500);
		$j("#"+e.target.id).parent().parent().addClass("acti");
	},

	carrusel : function(){
		$j("#carrusel").jcarousel({ scroll : 13 });
		//$j("#carrusel li:first-child").addClass("acti");
		if ($j.id("#proCam")){
			$j(".jcarousel-item a img").bind("click",function(e){ porid.mostrarCamp(e); return false; });
		}
	},
	mostrarCamp : function(e){
		id = e.target.id.split("_");
		if($j.id("#imagCamp")){
			$j("#imagCamp li").fadeOut(500);
			$j("#imagCamp_"+id[1]).fadeIn(500);
		}
		if($j.id("#imagProm")){
			$j("#imagProm li").fadeOut(500);
			$j("#imagProm_"+id[1]).fadeIn(500);
		}
		$j(".jcarousel-item").removeClass("acti");
		$j("#"+e.target.id).parent().parent().addClass("acti");
	},
	menuCampCont : function(){
		$j(".seccCamp").hide();
		if(document.URL.match(/#n/)){
			url = document.URL.split("#");
			$j("#"+url[1]).show();
			$j("#link-"+url[1]).parent().addClass("acti");
		}
		else{
			$j("#n1").show();
			$j("#link-n1").parent().addClass("acti");
		}
	},
	linkMenuCampCont : function(e){
		url = e.target.href.split("#");
		$j(".seccCamp").hide();
		$j("#menuCampCont li").removeClass("acti");
		$j("#"+url[1]).show();
		$j("#"+e.target.id).parent().addClass("acti");
	}
}
var porclass = {
	valores : function(){
 		$j('.tablIndi').remove();
		$j.getScript("http://www.valorfuturo.com/contenidos_vf/proyectos/clientes/js/indicadoresEmpresa.js", function(){
			$j('.bloqBann').after('<div class="indicadores cf"><h4>Indicadores Económicos</h4><dl><dt>'+monedas.moneda[0].tipo+': </dt><dd>'+monedas.moneda[0].valor+'</dd><dt>'+monedas.moneda[1].tipo+': </dt><dd>'+monedas.moneda[1].valor+'</dd><dt>'+monedas.moneda[2].tipo+': </dt><dd>'+monedas.moneda[2].valor+'</dd><dt>'+monedas.moneda[3].tipo+': </dt><dd>'+monedas.moneda[3].valor+'</dd></dl><a href="http://www.valorfuturoplus.com/contenidos_vf/indicadores.asp" title="Ver más indicadores - link a Valor Futuro" class="out" rel="External">Ver más indicadores</a></div>');
		})
	},
	google_analytics: function(page){
            var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
            $j.getScript(gaJsHost + 'google-analytics.com/ga.js', function(){
                        var pageTracker = _gat._getTracker("UA-1694937-4");
                        pageTracker._initData();
                        pageTracker._trackPageview(page);
            });
	},

	valores_home : function(){
		$j.getScript("http://www.valorfuturo.com/contenidos_vf/proyectos/clientes/js/indicadoresEmpresa.js", function(){
			$j('#contHome','#main').append('<div class="indicadores cf"><h4>Indicadores Económicos</h4><dl><dt>'+monedas.moneda[0].tipo+': </dt><dd>'+monedas.moneda[0].valor+'</dd><dt>'+monedas.moneda[1].tipo+': </dt><dd>'+monedas.moneda[1].valor+'</dd><dt>'+monedas.moneda[2].tipo+': </dt><dd>'+monedas.moneda[2].valor+'</dd><dt>'+monedas.moneda[3].tipo+': </dt><dd>'+monedas.moneda[3].valor+'</dd></dl><a href="http://www.valorfuturoplus.com/contenidos_vf/indicadores.asp" title="Ver más indicadores - link a Valor Futuro" class="out" rel="External">Ver más indicadores</a></div>');
		})
	},
 	randoms : function(){
		$j.map($j('.imagTop'),function(e){ 
			if(e.id=="a" || e.id==""){ e.id = 'imagTop'+parseInt(Math.random()*5+1); }
			if(e.id=="servicios"){ e.id = 'imagServ'+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(!$j.id('#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();
		}
	},
	tooltip : function(e){
		alt = e.target.alt;
		$j("#"+e.target.id).parent().attr("title","");
		mouseX = e.pageX;
		mouseY = e.pageY;
		if(!document.getElementById("toolTip")){
			var toolTip = document.createElement("div");
			toolTip.id = "toolTip";
			toolTip.innerHTML = "<p>"+alt+"</p>";
			document.getElementsByTagName('body')[0].appendChild(toolTip);
		}
		else{
			var toolTip = document.getElementById("toolTip");
		}
		toolTip.style.opacity = .8;
		if(parseInt(document.documentElement.clientWidth) < parseInt(toolTip.offsetWidth + mouseX)){
			if(navigator.userAgent.match(/MSIE/)){
				toolTip.style.top = (mouseY+15)+'px';
			}
			else{
				toolTip.style.top = mouseY+'px';
			}
			toolTip.style.left = (mouseX-toolTip.offsetWidth)+'px';
		}
		else{
			if(navigator.userAgent.match(/MSIE/)){
				toolTip.style.top = (mouseY+15)+'px';
				toolTip.style.left = (mouseX+15)+'px';
			}
			else{
				toolTip.style.top = mouseY+'px';
				toolTip.style.left = mouseX+'px';
			}
		}
	},
	tooltip_out : function(e){
		$j("#toolTip").remove();
		$j("#"+e.target.id).parent().attr("title",e.target.alt);
	}
}
var formulario = {
	validacion :function(){
		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,
					minLength: 7,
					maxLength: 8
				},
				rut02:  {
					dv:true,
					minLength: 1,
					maxLength: 1
				},
				nombres: "required",
				paterno: "required",
				materno: "required",
				residencia: "required",
				atencion: "required",

				fono02: {
					required: true,
					telefono:true,
					minLength: 6,
					maxLength: 8
				},
				fonoA02: {
					required: true,
					telefono:true,
					minLength: 6,
					maxLength: 8
				},
				email: {
					required: true,
					email: true
				},
				reemail: {
					required: true,
					email: true,
					equalTo: "#email"
				},
				mensaje: "required"
			},
			messages: {
				tipo: "Por favor, selecciona un tipo de consulta",
				asunto: "Por favor, ingresa un asunto",
				producto: "Por favor, selecciona un tipo de producto",
				rut: "Por favor, ingresa tu rut",
				nombres: "Por favor, ingresa tu nombre",
				paterno: "Por favor, ingresa tu apellido paterno",
				materno: "Por favor, ingresa tu apellido materno",
				residencia: "Por favor, selecciona tu comuna de residencia",
				atencion: "Por favor, selecciona tu comuna de atención",
				fonoA02: "Por favor, ingrese su teléfono",
				email: "Por favor, ingrese su email",
				reemail: "Su email no coincide",
				mensaje: "Por favor, ingrese un mensaje"
			}
		});
	}
}
var $j = jQuery.noConflict();
$j(document).ready( function() {
	//porclass.valores();
	if($j.id("#home")) porclass.valores_home();
	$j('.remove').remove();
	$j('.hide').hide();
	$j('.show').show();
	if(!$j.id("#imagTopHome")){ porclass.randoms(); }
	if($j.id("#imagTopHome")){  porid.startImagTop();}
	if($j.id("#tipo")){ $j('#tipo').bind("change", porid.combos); }
	if($j.id("#imagCamp") || $j.id("#imagProm")){
		$j.id("#imagProm")?$j("#imagProm").html():$j("#imagcamp").html();
		$j("carrusel").html("");
		porid.carrusel();
	}
	if($j.id("#menuCampCont")){
		porid.menuCampCont();
		$j("#menuCampCont li a").bind("click",function(e){porid.linkMenuCampCont(e); return false; });
		$j(".soliProd a").bind("click",function(e){porid.linkMenuCampCont(e); return false; });
	}
	$j('.ga').bind("click", function(page){porclass.google_analytics(this.rel); return;});
	if($j.id("#formulario")) { formulario.validacion();}
	$j('.mapa').bind("click", function(e){porclass.mapa(e); return false;});
	$j('.js').bind("click", function(e){porid.idname(e); return false;});
	$j('.tooltip img').mousemove(function(e){porclass.tooltip(e); return false;});
	$j('.tooltip img').mouseout(function(e){porclass.tooltip_out(e); return false;});
	$j.getScript("http://www.bancoedwards.cl/func-bancochile/ajax/mensaje.js", function(){
                dt = new Date ();
                dy = dt.getDate();
                hr = dt.getHours();
                var msg = ((dy<=Dia) && (hr<hora) || (dy<Dia) && (hr>=hora) ? Mensaje : msg);
                msg = ((dy>=Dia) && (hr>=hora) || (dy>Dia) && (hr<hora) || (0==Dia) ? "" : msg);
                msg = $j("#logiSide").after(msg);
        });
});

jQuery.extend({
	id : function(id) {
		var id = id.split("#");
		return document.getElementById(id[1])?true:false;
	}
});