addEvent(window,'load',inicializarEventos,false);

function inicializarEventos()
{
  var ob;
  ob=document.getElementById('firmaLibro');
  addEvent(ob,'submit',enviarDatos,false);
}
function enviarDatos(e)
{
  if (window.event)
    window.event.returnValue=false;
  else
    if (e)
      e.preventDefault();
  enviarFormulario();
}


function retornarDatos()
{
  var cad='';
  var nom=document.getElementById('name').value;
  var email=document.getElementById('email').value;
  var country=document.getElementById('country').value;
  var message=document.getElementById('message').value;
  var privado = document.getElementById('private').checked;
  cad='name='+encodeURIComponent(nom)+'&email='+encodeURIComponent(email)+'&country='+encodeURIComponent(country)+'&message='+encodeURIComponent(message)+'&private='+encodeURIComponent(privado);
  return cad;
}

var conexion1;
function enviarFormulario() 
{
  conexion1=crearXMLHttpRequest();
  conexion1.onreadystatechange = procesarEventos;
  conexion1.open('POST','saveBook.php', true);
  conexion1.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  conexion1.send(retornarDatos());  
}

function procesarEventos()
{
  var resultados = document.getElementById("resultados");
  if(conexion1.readyState == 4)
  {
    resultados.innerHTML = 'Su mensaje fue enviado y está a la espera de ser aprobado. Muchas gracias y que Dios le bendiga.';
  } 
  else 
  {
    resultados.innerHTML = 'Procesando...';
  }
}

//***************************************
//Funciones comunes a todos los problemas
//***************************************
function addEvent(elemento,nomevento,funcion,captura)
{
  if (elemento.attachEvent)
  {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else  
    if (elemento.addEventListener)
    {
      elemento.addEventListener(nomevento,funcion,captura);
      return true;
    }
    else
      return false;
}

function crearXMLHttpRequest() 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}

//form libro de visitas
$(document).ready(function(){
	
	// abrir/cerrar formulario
	$("#abrirForm").click(function(){
		$("#firmaLibro").slideToggle();
	});
	$("#cerrar").click(function(){
		$("#firmaLibro").slideToggle();
	});

	//Slider
	$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
	
	//la viña
	$("#lavina").click(function(){
		$("#vinaBig").fadeIn("normal");
	});
	$(".contentVina .close").click(function(){
		$("#vinaBig").fadeOut("normal");
	});
	
});


//funcion popup
function popup(pagina,ancho,alto) {
	var opciones = "toolbar=no, menubar=no, scrollbar=no, resizable=no, width="+ancho+", height="+alto;
	window.open(pagina,"",opciones);
}


////// VIDEOS FLASH //////
function embedFlash(pathCompleto,ancho,alto){
	  document.write('<object width="'+ancho+'" height="'+alto+'">');
		document.write('<param name="movie" value="'+pathCompleto+'" />');
		document.write('<param name="allowFullScreen" value="true" />');
		document.write('<param name="allowscriptaccess" value="true" />');
		document.write('<embed src="'+pathCompleto+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+ancho+'" height="'+alto+'"></embed>');
	  document.write('</object>');
}


//countdown congreso 2011
function calcula(id){
	var fecha=new Date('2011','3','21','18','00','00')
	var hoy=new Date()
	var dias=00
	var horas=00
	var minutos=00
	var segundosunction=00
	
	if (fecha>hoy){
		var diferencia=(fecha.getTime()-hoy.getTime())/1000
		dias=Math.floor(diferencia/86400)
		diferencia=diferencia-(86400*dias)
		horas=Math.floor(diferencia/3600)
		diferencia=diferencia-(3600*horas)
		minutos=Math.floor(diferencia/60)
		diferencia=diferencia-(60*minutos)
		segundos=Math.floor(diferencia)
		
		document.getElementById(id).innerHTML='<a href="http://cordoba11.blogspot.com/" title="Congreso Internacional de Jóvenes Córdoba 2011" target="_blank" class="link" ></a><div class="num" style="color:#e5d110;">' + dias + '</div> <div class="num" style="color:#f6e745;">' + horas + '</div> <div class="num" style="color:#efe465;">' + minutos + '</div> <div class="num" style="color:#f8ef90;">' + segundos + '</div><div id="txtCount"><div>días</div><div>horas</div><div>minutos</div><div>segundos</div></div>'
		
		if (dias>0 || horas>0 || minutos>0 || segundos>0){
			setTimeout("calcula(\"" + id + "\")",1000)
		} else if(dias==0 && horas==0 && minutos==0 && segundos==0) {
			document.location = 'http://cba11.citaconlavida.com.ar'
		}
		
	} else {
		document.getElementById('restante').innerHTML='Quedan ' + dias + ' D&iacute;as, ' + horas + ' Horas, ' + minutos + ' Minutos, ' + segundos + ' Segundos'
	}
}
