// JavaScript Document
//@uthor : Jaime Cifuentes P.
//Fecha  : Agosto 2008

function addFavoritosInterior()
{
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) 
	{
		url = document.location.href ; 
		partes = url.split('/'); 

		NombrePagInicio ='';
		for( i=3;i<partes.length-1;i++)
		{
			if(i==3)
				NombrePagInicio = partes[i]; 
			else
				NombrePagInicio = NombrePagInicio +'/'+  partes[i]; 
		}
		
		var titulo="VTR - "+NombrePagInicio;
		window.external.AddFavorite(url,titulo);
	}
	else
	{
		if(navigator.appName == "Netscape") 
			alert ("Presiona Crtl+D para agregar esta web a tus Favoritos");
	}
} 

function addInicioInterior(objk,direccion)
{ 
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>3))
	{ 
    	objk.style.behavior="url(#default#homepage)"; 
        objk.setHomePage("http://vtr.com/"); 
	} 
    else
	{ 
		alert("su navegador no dispone de esta opción"); 
    } 
} 
function addFavoritos(fav)
{
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) 
	{
		var url="http://vtr.com/";
		var titulo=""+fav;
		window.external.AddFavorite(url,titulo);
	}
	else
	{
		if(navigator.appName == "Netscape") 
			alert ("Presiona Crtl+D para agregar esta web a tus Favoritos");
	}
}  

function addInicio(objk,direccion)
{ 
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>3))
	{ 
    	objk.style.behavior="url(#default#homepage)"; 
//        objk.setHomePage(direccion); 
//        objk.setHomePage("http://vtr.com/<? echo $_SESSION['origen'];?>"); 
        objk.setHomePage("http://vtr.com/"+direccion); 
		
	} 
    else
	{ 
		alert("su navegador no dispone de esta opción"); 
    } 
} 

function abre_video(e)
{
		var url = "video.php?id="+e+"&keepThis=true&TB_iframe=true&height=520&width=810"; 
		tb_show("galeria_externa",url,"");
}
function abre_minigaleria(url){
	
	    var idgaleria = url.split("&");
		var url = "/galeria/galeria_vod.php?"+idgaleria[3]+"&keepThis=true&TB_iframe=true&height=490&width=775"; 
		tb_show("galeria_externa",url,"");
	
	
	}

function carga_destacados_categoria(idcat){

	
		$.ajax({
		url: "destacada_categoria.php?cat="+idcat+"",
		scriptCharset:"UTF-8",
		cache: false,
		success: function(html)
			{
			 
   			 $("#carga_detacada").html(html);
			
			 
  			}
		});
	}
	
/*function carga_trailer(){
	
	$("#trailer_pelicula").fadeOut("slow");
	nombre_trailer_central = "";
		$.ajax({
		url: "carga_trailer.php",
		scriptCharset:"UTF-8",
		cache: false,
		success: function(html)
			{
			// $("#trailer_pelicula").hide();
   			 $("#contenedor_trailer_central").html(html);
			 $("#trailer_pelicula").fadeIn("slow");
			 $("#titulo_trailer_central").html(nombre_trailer_central);
			 
  			}
		});
	
	
	}*/

/*function carga_imagen_trailer_rand(){
	$("#trailer_pelicula").fadeOut("slow");
		$.ajax({
		url: "destacadas.php",
	scriptCharset:"UTF-8",
		cache: false,
  		success: function(html)
			{

			// $("#destacadas").hide();
   			 $("#destacadas").html(html);
			 $("#destacadas").fadeIn("slow");

  			}
		});
	
	
	}*/



function carga_destacada(){
	$("#destacadas").fadeOut("slow");
	
	$.ajax({
		url: "destacadas.php",
		scriptCharset:"UTF-8",
		cache: false,
  		success: function(html)
			{

			 //$("#destacadas").hide();
   			 $("#destacadas").html(html);
			 $("#destacadas").fadeIn("slow");

  			}
		});
}

function trailers_destacados(num){
		$("#rotativa_inferior").hide("fast");
	
	$.ajax({
		url: "trailers_principal.php?num="+num,
		scriptCharset:"UTF-8",
		cache: false,
  		success: function(html)
			{
				
			// $("#rotativa_inferior").hide("fast");
   			 $("#rotativa_inferior").html(html);
			 $("#rotativa_inferior").show("fast");
			
			
			
  			}
		});
	

	return siguiente;
	
	}
	
	
function trailers_lista(num){
		//S$("#scroller_trailer").hide("fast");
	
	$.ajax({
		url: "lista_trailers.php?num="+num,
		scriptCharset:"UTF-8",
		cache: false,
  		success: function(html)
			{
				
			// $("#scroller_trailer").hide("fast");
   			 $("#scroller_trailer").html(html);
			// $("#scroller_trailer").show("fast");
			
			
			
  			}
		});
	

	return siguiente;
	
	}	
	
function fichas_relacionadas(cat,reg,inicio,rand){
	$("#contenedor_relacionadas").fadeOut("fast");
	
	$.ajax({
		url: "relacionadas.php?cat="+cat+"&reg="+reg+"&inicio="+inicio+"&random="+rand,
		scriptCharset:"UTF-8",
		cache: false,
  		success: function(html)
			{
			$("#contenedor_relacionadas").fadeOut("fast");
   			$("#contenedor_relacionadas").html(html);
			$("#contenedor_relacionadas").fadeIn("fast");
  			}
		});
	}







//////////////////////////////////////////////////////////////////////////7
	
	
var siguiente = 0;
var siguiente1 = 0;
var siguiente2 = 0;

$(document).ready( function(){
				
				
				
				//carga_trailer();
					 //>setInterval("carga_trailer()",15000); //cambia cada 15 segundos		
							
				carga_destacada(); // ultimas peliculas
				setInterval("carga_destacada()",10000); //cambia cada 10 segundos
 				
				trailers_destacados(0); // trailers
				trailers_lista(0);	// lista de trailers		
					
					
				  $("#siguiente_trailer").click(function(){
														 continua = siguiente +1;
														 trailers_destacados(continua);
														 
														 siguiente = siguiente +1;
														 //return siguiente;
														 return false;
														 });
				  
				  $("#trailer_previo").click(function(){
													  	 previo = siguiente - 1;
														 trailers_destacados(previo);
								 						 siguiente = siguiente - 1;
														 
														 return false;
														 
														 });
				  $("#lista_trailer_arriba").click(function(){
														 continua1 = siguiente1 +1;
														 trailers_lista(continua1);
														 
														 siguiente1 = siguiente1 +1;
														 //return siguiente;
														 return false;
														 });
				  
				  $("#lista_trailer_abajo").click(function(){
													  	 previo1 = siguiente1 - 1;
														 trailers_lista(previo1);
								 						 siguiente1 = siguiente1 - 1;
														 
														 return false;
														 
														 });
				  
				   });


//////////////////////////validacion

function agrega_label(elemento, mensaje){
	
	$("#for_"+elemento+"").remove();
	
	var label = $("<div class='error errorcito' id='for_"+elemento+"'>");
	
	label.html(mensaje);
	
	$("#"+elemento+"").after(label);
	
	label.show("slow");
	}

function borra_label(elemento,accion,alternativo){
	
	if (accion == "keypress"){
		$("#"+elemento+"").keypress(function (){
												  
												  $("#for_"+elemento+"").remove();
												  $("#for_"+alternativo+"").remove();
												  });
												}
	if (accion == "click"){
		$("#"+elemento+"").click(function (){
												  
												  $("#for_"+elemento+"").remove();
												  $("#for_"+alternativo+"").remove();
												  });
												}
		
		}
		
function valEmail(valor){
    re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }
}

function validar()
{
	
	
	envia = 1;
	
	$(".errorcito").remove();
	 
	 
	if (document.form1.textfield.value.length==0){ 
		   agrega_label("textfield","Ingrese su nombre.");
		  
		   borra_label("textfield","keypress");
		 
		  document.form1.textfield.focus();
	  envia = 0; 
    }
	if (document.form1.textfield2.value.length==0){ 
		   agrega_label("textfield2","Ingrese su e-mail.");
		  
		   borra_label("textfield2","keypress");
		 
		  document.form1.textfield2.focus();
	  envia = 0; 
    }
	else{
		if(!valEmail(document.form1.textfield2.value)){
			agrega_label("textfield2","Ingrese un e-mail v&aacute;lido.");
		  
		   borra_label("textfield2","keypress");
		 
		  document.form1.textfield2.focus();
	  envia = 0; 
			
			}
		
		
		}
	if (document.form1.textfield3.value.length==0){ 
		   agrega_label("textfield3","Ingrese el codigo del recuadro.");
		  
		   borra_label("textfield3","keypress");
		 
		  document.form1.textfield3.focus();
	  envia = 0; 
    }
	else{
		
		dato = document.form1.textfield3.value;
		$.ajax({
		url: "captcha/verifica.php",
		type: "POST",
		data: "codigo="+dato,
		scriptCharset:"UTF-8",
		cache: false,
  		success: function(text)
			{
				 if(text =="0")
				 {
					 $("#captcha").remove();
					
					agrega_label("textfield3","El c&oacute;digo es incorrecto, int&eacute;ntelo nuevamente.");
		  
		  		 	borra_label("textfield3","keypress");
					$("#validador").html("<img src='captcha/captcha.php' alt='' width='185' height='51' id='captcha' />");
					
				 }
				else{
					
					
					
					
					}
  			}
		});
	   }
	
	if (document.form1.textarea.value.length==0){ 
		   agrega_label("textarea","Ingrese el mensaje.");
		  
		   borra_label("textarea","keypress");
		 
		  document.form1.textarea.focus();
	  envia = 0; 
    }
	
	if (envia == 1){
		
		nombre = document.form1.textfield.value;
		email = document.form1.textfield2.value;
		mensaje = document.form1.textarea.value;
		
		$.ajax({
		url: "mensaje_contacto.php",
		type: "POST",
		data: "nombre="+nombre+"&email="+email+"&mensaje="+mensaje,
		cache: false,
  		success: function(text)
			{
				alert("Muchas Gracias por sus comentarios.");
				document.location.href = "index.php";
  			}
		});
		
		}
	
}