// JavaScript Document
/*Busqueda Rapida ----------------------------------*/
addEvent(window,'load',getComplex,false);
function getComplex()
{
  if (window.event)
  {    window.event.returnValue=false;
   	   cargarSelect();     
  }
  else
  {   cargarSelect();     
  }
}

var conexion1;
function cargarSelect()
{	  conexion1=crearXMLHttpRequest()
  	  conexion1.onreadystatechange = procesarEventos;
	  conexion1.open("GET", "ajax_data_complex.php", true);
 	  conexion1.send(null);
}

function procesarEventos()
{   var detalles = document.getElementById("selectcines");
  	if(conexion1.readyState == 4)
  	{
    	detalles.innerHTML = conexion1.responseText;
		var pagina = document.getElementById("page").value;
//		alert(pagina);
		if(pagina=="pdetail")
		{
			var cineSelec = document.getElementById("codigo_cine").value;
			document.getElementById("complex").value=cineSelec;
			getFilmHomAjax();
		}
  	} 
}
/*Segundo Combo Busqueda Rapida ---------------------------------*/
function getFilmHomAjax()
{
	var idComplejo=document.getElementById("complex").options[document.getElementById("complex").selectedIndex].value;
	document.getElementById("cod_cine").value=idComplejo;
	document.getElementById("combo_filmt").style.display='none';
	document.getElementById("gif").style.display='block';
	document.getElementById("selectpeliculas").innerHTML='';
	cargarSelectFilm(idComplejo);
}


var conexion2;
function cargarSelectFilm(idCom)
{	
	  conexion2=crearXMLHttpRequest()
  	  conexion2.onreadystatechange = procesarFilm;
	  conexion2.open("GET", "ajax_data_film.php?id="+idCom, true);
 	  conexion2.send(null);
}

function procesarFilm()
{   var detallesFilm = document.getElementById("selectpeliculas");
  	if(conexion2.readyState == 4)
  	{
    	detallesFilm.innerHTML = conexion2.responseText;
  	} 
}

/*Vota y Comenta (combo)-------------------------------------*/
function getAjaxFunc()
{
var idPelVyc=document.getElementById("filmvyc").options[document.getElementById("filmvyc").selectedIndex].value;
getStars(idPelVyc);
getCommented(idPelVyc);
getImagVyc(idPelVyc);
//updateScroll();
}
/*Vota y Comenta (imagen)*/
function getImagVyc(idP)
{
	document.getElementById("imageFilm").innerHTML='<img src="../images/votaycomenta/'+idP+'.jpg" width="310" height="89" />'
	document.getElementById("txt_pelicula").value=idP;

}
/*Vota y Comenta (estrellas)-----------------------------------*/

var conexion4;
function getStars(idEst)
{
	
	conexion4=crearXMLHttpRequest();
	conexion4.onreadystatechange = procesarEstrellas;
	conexion4.open("GET","ajax_estrellas.php?idpel="+idEst,true);
	conexion4.send(null);
}

function procesarEstrellas()
{
	var detallesEstre = document.getElementById("textStars");
	if(conexion4.readyState == 4)
	{
		detallesEstre.innerHTML = conexion4.responseText;
	}
}

/*Vota y Comenta (comentarios)------------------------------*/

var conexion5;
function getCommented(idCmen)
{	//alert(idCmen);
	conexion5=crearXMLHttpRequest();
	conexion5.onreadystatechange = procesarComentarios;
	conexion5.open("GET","ajax_comentarios.php?id="+idCmen,true);
	conexion5.send(null);
}

function procesarComentarios()
{
	var detallesComent = document.getElementById("content_commented");
	if(conexion5.readyState == 4)
	{
		detallesComent.innerHTML = conexion5.responseText;
		updateScroll();
		
	}
}

/*Vota y Comenta (guarda Comentario Usuario)-------------------------*/

var conexion3;
function enviaDataFormCommented(datos)
{
	//alert(datos);
	conexion3=crearXMLHttpRequest()
	conexion3.onreadystatechange = saveDataComent;
	conexion3.open("GET","ajax_save_commented.php?dat="+datos,true);
	conexion3.send(null);
}
function saveDataComent()
{
	var detalsaveCom = document.getElementById("textSave");
	if(conexion3.readyState == 4)
	{
		document.getElementById("window_save").style.display="block";
		detalsaveCom.innerHTML = conexion3.responseText;
		
	}
}

/*Vota y Comenta (guarda Comentario Nuevo Registro y Comentario)--------*/
var conexion6
function enviarDataFormRegisterCommented(datosr)
{
	conexion6=crearXMLHttpRequest()
	conexion6.onreadystatechange = saveDataComentRegister;
	conexion6.open("GET","ajax_save_commented_regis.php?datr="+datosr,true);
	conexion6.send(null);
}

function saveDataComentRegister()
{
	var detalsaveComReg = document.getElementById("textSave");
	if(conexion6.readyState == 4)
	{
		document.getElementById("window_save").style.display="block";
		detalsaveComReg.innerHTML = conexion6.responseText;
		
	}
}

/*Detalle de Peliculas */
/* Fechas de Detalle--------------------------------------------------*/
function get_fechas()  // por defecto 
{
	var ncine=document.getElementById("cine_d").value;
	var idpel=document.getElementById("codigo_pel").value;
	var fecha=document.getElementById("fecha").value;
	getFechaspel(ncine,idpel,fecha);	
}

var conexion7
function getFechaspel(cin,pel,fec)
{
	conexion7=crearXMLHttpRequest()
	conexion7.onreadystatechange = procesarFechasPel;
	conexion7.open("GET","ajax_fechas_peliculas.php?cine="+cin+"&pelic="+pel+"&fecha="+fec,true);
	conexion7.send(null);
}

function procesarFechasPel()
{
	var dataFechas = document.getElementById("dv_fechas");
	if(conexion7.readyState == 4)
	{
		dataFechas.innerHTML = conexion7.responseText;
	}
}


/* Funciones de Detalle------------------------------------------------------*/
function get_funciones()  // por defecto
{
	var ncin=document.getElementById("cine_d").value;
	var idpe=document.getElementById("codigo_pel").value;
	var fech=document.getElementById("fecha").value;
	getFuncionespel(ncin,idpe,fech);
}
var conexion8
function getFuncionespel(ici,ipe,ife)
{
	conexion8=crearXMLHttpRequest()
	conexion8.onreadystatechange = procesarFuncionesPel;
	conexion8.open("GET","ajax_funciones_peliculas.php?cine="+ici+"&pelic="+ipe+"&fecha="+ife,true);
	conexion8.send(null);
}
function procesarFuncionesPel()
{
	var dataFunciones = document.getElementById("horario");
	if(conexion8.readyState == 4)
	{
		dataFunciones.innerHTML = conexion8.responseText;
	}
}
/*-------------------------------------------------*/

function getDetail(cin,pel,fec)
{	
	getFechaspel(cin,pel,fec);
	getFuncionespel(cin,pel,fec);
}
/* Imprimir cartelera de Detalle  --------------------------------*/
function getInprimir(codcin)
{
 ajaxImprDetalle(codcin);
}

var conexion9
function ajaxImprDetalle(codci)
{
	conexion9=crearXMLHttpRequest()
	conexion9.onreadystatechange = procesarImpresion;
	conexion9.open("GET","ajax_get_imprime.php?cine="+codci,true);
	conexion9.send(null);
}
function procesarImpresion()
{
	var dataImpresion = document.getElementById("contenido");
	if(conexion9.readyState == 4)
	{
		dataImpresion.innerHTML = conexion9.responseText;
		updateScroll();
	}
}

/* Wallpapers --------------------------------*/
function getWallpaper(codpel)
{
	ajaxWallpapers(codpel);
}

var conexion10
function ajaxWallpapers(idpwal)
{
	conexion10=crearXMLHttpRequest()
	conexion10.onreadystatechange = procesarWallpapers;
	conexion10.open("GET","ajax_get_wallpaper.php?pelwa="+idpwal,true);
	conexion10.send(null);
}

function procesarWallpapers()
{
	var dataWallpapers = document.getElementById("contenidowallpaper");
	if(conexion10.readyState == 4)
	{
		dataWallpapers.innerHTML = conexion10.responseText;
		updateScroll();
	}
}


/*------------------------------------------------*/
/*FUNCIONES AJAX EN COMUN ---------------------------------*/
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;
}