/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var tiempoRotaBanner=25000;
var banerActual=1;
var numBanners=1;
var banerNuevo=0;
var timeBanner;
  var contehtml="";
 $(document).ready(function() {
    MSDropDown.init("#webmenu");
    $('.error').hide();
    $('#enviandomensaje').hide();
	
    numBanners=$('#cdban').children().size();

    $("#clinks a").each(function(i) {
        $(this).click(function() {
             var d=$(this).html();
             //$("#dim"+banerActual).fadeOut("slow");
             //$("#dim"+d).fadeIn("slow");
             //banerActual=d;

              d=parseInt(d)
              banerNuevo=d;
              movBanner(d)
        });
    });
    timeBanner=setTimeout("rotaBaner()", tiempoRotaBanner );


    $(".botondetalles img").mouseover(function(){
      $(this).attr("src","/images/botonverdetalles2.png");
    }).mouseout(function(){
      $(this).attr("src","/images/botonverdetalles.png");
    });


    $(".bontobuscadominio input").mouseover(function(){
      $(this).attr("src","/images/boton_buscardominio2.png");
    }).mouseout(function(){
      $(this).attr("src","/images/boton_buscardominio.png");
    });

    $('li.clickable').css('cursor', 'pointer');

    $("li.clickable").click(function(){
       window.location = $('a', this).attr('href');
    });
    
    $("li.clickable").mouseover(function(){
        $('a', this).trigger('mouseenter');
    });
    $("#enlaceform").click(function() {
     	showForm();
    });
    $("#cerrarformcontacto").click(function() {
     	hideForm();
    });
	 $('#enviaformcontacto').click(function(){
		enviaForm(this, false);
		return false;
		
		});
	
 });
function rotaBaner(){
   
   if(banerNuevo==numBanners){
        banerNuevo=1;
   } else{
        banerNuevo=banerActual+1
   }

   movBanner(banerNuevo)
   
}
function movBanner(banerNuevo){
	clearTimeout(timeBanner);
	//alert(banerActual +" -- "+banerNuevo);
    $("#dim"+banerActual).hide();
	 // $("#dim4").fadeOut();
    $("#dim"+banerActual).css('zIndex', 0)
    $("#dim"+banerNuevo).fadeIn("slow");
    $("#dim"+banerNuevo).css('zIndex', 10)
    banerActual=banerNuevo;
	timeBanner=setTimeout("rotaBaner()", tiempoRotaBanner );
}



function cambiaPais(pais){
    //alert(pais);
    document.location.href="<?php //echo url_for('contenido/cambiaculture/nculture/',true) ?>"+pais;
}


function showForm(){
	var pos = $("#enlaceform").offset();
//	alert(pos.top );
  	if(contehtml!=""){
		  $('.contewindow').html(contehtml);
	}
	$("#formcontacto").css( { "left": (pos.left - 260) + "px", "top": (pos.top-385) + "px" } );
	$("#formcontacto").show();
}
function hideForm(){
	$("#formcontacto").hide();
}

function enviaForm(){
  $('.error').hide();
  $('#enviandomensaje').hide();

	  var name = $("input#nombre").val();
		if (name == "") {
      $("label#nombre_error").show();
      $("input#nombre").focus();
      return false;
    }
	var email = $("input#email").val();
	if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
	if(isValidEmailAddress(email)==false) {	
      $("label#email_error").show();
      $("input#email").focus();
      return false;
	}
	 $('#enviandomensaje').show();
	 
	var dataString=	$("#formcontacto form").serialize();
//		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;
		//alert (dataString);return false;
		$.ajax({
      type: "POST",
      url: "/enviar_contactof.html",
      data: dataString,
      success: function() {
		$('#enviandomensaje').hide();
		contehtml=$('.contewindow').html();
        $('.contewindow').html("<div id='message'></div>");
        $('#message').html("<h2>Su Consulta ha sido enviada!</h2>")
        .append("<p>Le contestaremos lo mas pronto posible.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
		
}

function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}