var hw_host = "encartelera.com";

var whitespace = " \t\n\r";
var reWhitespace = /^\s+$/

/*
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
	if (IE) { //para IE
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	}
	else { //para netscape
		tempX = e.pageX;
		tempY = e.pageY;
	}
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}
	document.Show.MouseX.value = tempX;
	document.Show.MouseY.value = tempY;
	return true;
}
*/

function isEmpty(s){
	return ((s == null) || (s.length == 0))
}
 
function isWhitespace (s){
	return (isEmpty(s) || reWhitespace.test(s));
}

function overVotos(actual,id,num){
		
	switch (actual){
		case 'http://www.'+hw_host+'/img/cartelera/interior/ficha/valoracion.off.gif':
			
			var a=id.split('_');
			id_length=a[1];
			var i=1;
			var j=0;
			
			for(i=1;i<=id_length;i++){
				
				document.getElementById('votos_'+i).src='http://www.'+hw_host+'/img/cartelera/interior/ficha/valoracion.on.gif';
				
			}
			
		break;
		case 'http://www.'+hw_host+'/img/cartelera/interior/ficha/valoracion.on.gif':
			
			var a=id.split('_');
			id_length=a[1];
			var i=1;
			for(i=1;i<=num;i++){
				if(id_length<i || id_length==1){
					document.getElementById('votos_'+i).src='http://www.'+hw_host+'/img/cartelera/interior/ficha/valoracion.off.gif';
				}
						
			}
		break;
	}
	
}

function ajaxobj() {
	try {
		_ajaxobj = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			_ajaxobj = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			_ajaxobj = false;
		}
	}
	if (!_ajaxobj && typeof XMLHttpRequest!='undefined') {
		_ajaxobj = new XMLHttpRequest();
	}
	return _ajaxobj;
}

function sumaVotos(nota,id_peli){
	
	var parameters = "nota=" + nota + "&id_peli=" + id_peli;
			
	ajax = ajaxobj();
	ajax.open("POST", "http://cartelera."+hw_host+"/inc/cjob/catch/votos/votos-0001.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
			var res=datos.split("--");

			
			document.getElementById('respuesta').innerHTML=res[1];
			if(res[2]!='0'){
				document.getElementById('nota_val').innerHTML=res[0];
				document.getElementById('nota').innerHTML="<b>"+res[2]+"</b>";
				document.getElementById('total_votos').innerHTML="("+res[3]+" votos)";
			}
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);

	

}
function sumaVotosCine(nota,id_cine){
	
	var parameters = "nota=" + nota + "&id_cine=" + id_cine;
			
	ajax = ajaxobj();
	ajax.open("POST", "http://cines."+hw_host+"/inc/cjob/catch/votos/votos-0002.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
			var res=datos.split("--");

			
			document.getElementById('respuesta').innerHTML=res[1];
			document.getElementById('tr_respuesta').style.display="";
			if(res[2]!='0'){
				document.getElementById('nota_val').innerHTML=res[0];
				document.getElementById('tr_nota_val').style.display="";
				document.getElementById('total_votos').innerHTML="("+res[3]+" valoraciones)";
			}
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);

	

}	

function muestraForm(cual,ruta){
	switch (cual){
		case 'foto':
			if(ruta == 'http://www.'+hw_host+'/img/cines/ficha/+.gif'){
				document.getElementById('anadir_foto').src = 'http://www.'+hw_host+'/img/cines/ficha/-.gif';
				document.getElementById('form_foto').style.display = '';
			}else{

				document.getElementById('anadir_foto').src = 'http://www.'+hw_host+'/img/cines/ficha/+.gif';
				document.getElementById('form_foto').style.display = 'none';
			
			} 
		break;

		case 'info':
			if(ruta == 'http://www.'+hw_host+'/img/cines/ficha/+.gif'){
				document.getElementById('anadir_info').src = 'http://www.'+hw_host+'/img/cines/ficha/-.gif';
				document.getElementById('form_info').style.display = '';
			}else{

				document.getElementById('anadir_info').src = 'http://www.'+hw_host+'/img/cines/ficha/+.gif';
				document.getElementById('form_info').style.display = 'none';
			
			} 
		break;

		case 'no_info':
			if(ruta == 'http://www.'+hw_host+'/img/cines/ficha/+.gif'){
				document.getElementById('anadir_rect_info').src = 'http://www.'+hw_host+'/img/cines/ficha/-.gif';
				document.getElementById('form_rect_info').style.display = '';
			}else{

				document.getElementById('anadir_rect_info').src = 'http://www.'+hw_host+'/img/cines/ficha/+.gif';
				document.getElementById('form_rect_info').style.display = 'none';
			
			} 
		break;
	
	}
}

function setInfo(texto, id_cine){
	if(isWhitespace(texto.value)!=false){
		alert('Falta el texto');
		return false;
	}	
	var parameters = "info=" + texto.value + "&id_cine=" + id_cine;
			
	ajax = ajaxobj();
	ajax.open("POST", "http://cines."+hw_host+"/inc/cjob/catch/extras/extra-0001.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
			document.getElementById('resp_info').innerHTML=datos;
			
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);

	

}

function setInfoRect(texto, id_cine){
	if(isWhitespace(texto.value)!=false){
		alert('Falta el texto');
		return false;
	}	
	var parameters = "info=" + texto.value + "&id_cine=" + id_cine;
			
	ajax = ajaxobj();
	ajax.open("POST", "http://cines."+hw_host+"/inc/cjob/catch/extras/extra-0002.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
			document.getElementById('resp_rect').innerHTML=datos;
			
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);

	

}	

function getCiudades(id_provincia,subdom,id_desp){
	
	var parameters = "id_provincia=" + id_provincia;
	
	if(subdom=='home')subdom='www';
			
	ajax = ajaxobj();
	ajax.open("POST", "http://"+subdom+"."+hw_host+"/inc/cjob/catch/mapa/mapa-0001.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;

			var desg=datos.split("---");
			
			document.getElementById(id_desp).innerHTML=desg[0];
			
			
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);
}	



function getCinesCiudad(id_ciudad){
	
	var parameters = "id_ciudad=" + id_ciudad;
			
	/*ajax = ajaxobj();
	ajax.open("POST", "http://cines.encartelera.com/inc/cjob/catch/mapa/mapa-0002.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
			document.getElementById('cines_en').innerHTML=datos;
			
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);
	*/
}


function buscaPeli(titulo){
	
	var parameters = "titulo=" + titulo;
			
	ajax = ajaxobj();
	ajax.open("POST", "http://cines."+hw_host+"/inc/cjob/catch/mapa/mapa-0003.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
				if(datos==0){
					document.getElementById('desp_pelis').style.display="none";
				}else{
				document.getElementById('desp_pelis').style.display="";
				document.getElementById('desp_pelis').innerHTML=datos;
				}
						
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);
}	

function buscaPeliPortada(titulo){
	
	var parameters = "titulo=" + titulo;
			
	ajax = ajaxobj();
	ajax.open("POST", "http://www."+hw_host+"/inc/cjob/catch/mapa/mapa-0003.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
				if(datos==0){
					document.getElementById('desp_pelis').style.display="none";
				}else{
				document.getElementById('desp_pelis').style.display="";
				document.getElementById('desp_pelis').innerHTML=datos;
				}
						
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);
}	

function buscaPeliCartelera(titulo){
	
	var parameters = "titulo=" + titulo;
			
	ajax = ajaxobj();
	ajax.open("POST", "http://cartelera."+hw_host+"/inc/cjob/catch/buscador/busca-0001.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
				if(datos==0){
					document.getElementById('desp_pelis').style.display="none";
				}else{
				document.getElementById('desp_pelis').style.display="";
				document.getElementById('desp_pelis').innerHTML=datos;
				}
						
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);
}	
function buscaPeliTrailer(titulo){
	
	var parameters = "titulo=" + titulo;
			
	ajax = ajaxobj();
	ajax.open("POST", "http://trailers."+hw_host+"/inc/cjob/catch/trailers/trailer-0001.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
				if(datos==0){
					document.getElementById('desp_pelis').style.display="none";
				}else{
				document.getElementById('desp_pelis').style.display="";
				document.getElementById('desp_pelis').innerHTML=datos;
				}
						
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);
}
function buscaPeliProx(titulo){
	
	var parameters = "titulo=" + titulo;
			
	ajax = ajaxobj();
	ajax.open("POST", "http://proximos-estrenos."+hw_host+"/inc/cjob/catch/buscador/busca-prox-0001.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
				if(datos==0){
					document.getElementById('desp_pelis').style.display="none";
				}else{
				document.getElementById('desp_pelis').style.display="";
				document.getElementById('desp_pelis').innerHTML=datos;
				}
						
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);
}	

function muestraInfo(){
	if(document.getElementById('mas_info').style.display=='none'){
		document.getElementById('mas_info').style.display='';
	}else{
		document.getElementById('mas_info').style.display='none'
	}
}

function goToCines(frm){

	if(frm.provs.value=='0'){
		frm.provs.value="";
		alert("Selecciona una provincia");
		return false;
	}

		
}

function goToCinesCiudad(frm){

	/*if(frm.ciudades.value=='0'){
		frm.ciudades.value="";
		alert("Selecciona una ciudad");
		return false;
	}*/

		
}

function mostrarMapa2(url_prov, url_ciu, id_cine, tipo, reducido){
	var url_obj = 'http://'+hw_host + "/swf/googlemap2.swf";
	var w = "450";
	var h = "400";
	if (reducido=="1"){
		h = "30";
	}
	if (url_ciu!=""){
		var param = "id=&ruta=http://"+hw_host+"/inc/cjob/catch/mapa/cines.php?prov="+url_prov+"/"+url_ciu+"&tipo=1";
	}else{
		var param = "id=&ruta=http://"+hw_host+"/inc/cjob/catch/mapa/ciudades.php?prov="+url_prov+"&tipo=0";
	}
	if (id_cine!="")
	{
		var param = "id="+id_cine+"&ruta=http://"+hw_host+"/inc/cjob/catch/mapa/cines.php?prov="+url_prov+"/"+url_ciu+"&tipo=1";
	}
//	alert (param);
//	mostrarObjeto(url_obj, w, h, param);
	var result = '';
	result = result + '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="' + w + 'px" height="' + h + 'px">'+"\n";
	result = result + '<param name="movie" value="' + url_obj + '">'+"\n";
	result = result + '<param name="quality" value="high">'+"\n";
	result = result + '<param name="Flashvars" value="' + param + '">'+"\n";
	result = result + '<param name="allowScriptAccess" value="always">'+"\n";
	result = result + '<param name="wmode" value="transparent">'+"\n";
	result = result + '<param name="swLiveConnect" value="true">'+"\n";
	result = result + '<param name="wmode" value="transparent">'+"\n";
	result = result + '<param name="flashVars" value="key=ABQIAAAAob7oMi80LL9f3losiDeNqxStmloK4wGo_TRkXn6vs75vcZRMuBSXeCbTCqG5F-Byy7pvUzLDAT7AYw">'+"\n";
	result = result + '<embed wmode="transparent" width="' + w + 'px" height="' + h + 'px" src="' + url_obj + '" wmode="transparent" Flashvars="' + param + '&key=ABQIAAAAob7oMi80LL9f3losiDeNqxStmloK4wGo_TRkXn6vs75vcZRMuBSXeCbTCqG5F-Byy7pvUzLDAT7AYw" allowScriptAccess="always" swLiveConnect="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash">'+"\n";
//	result = result + '<embed width="' + w + 'px" height="' + h + 'px" src="' + url_obj + '" Flashvars="' + param + '" allowScriptAccess="always" swLiveConnect="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash">'+"\n";
	result = result + '</object>';
	
	document.write(result);
}
/*ABQIAAAAob7oMi80LL9f3losiDeNqxStmloK4wGo_TRkXn6vs75vcZRMuBSXeCbTCqG5F-Byy7pvUzLDAT7AYw*/

function validaBusc(frm){
	if(frm.ciudades){
		if(frm.ciudades.value==0){
			alert('Selecciona una ciudad');
			return false;
		}
	}else if(frm.busq_peli.value==''){
		return false;
	}else frm.submit();
}

/*función para eliminar cine de 'tus cines'*/
function delTusCines(id_cookie, id_cine){
	var parameters = "id_cookie=" + id_cookie + "&id_cine=" + id_cine;
			
	ajax = ajaxobj();
	ajax.open("POST", "http://cines."+hw_host+"/inc/cjob/catch/cines/cines-0001.cjob.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
			document.getElementById(id_cine).style.display="none";
			document.getElementById('sep_'+id_cine).style.display="none";
				
						
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);
}

/*mapa de provincias:*/
function mostrarMapa(){
	var url_obj = "http://" +hw_host + "/swf/MapaInterbusca.swf";
	var w = "450";
	var h = "400";
	var param = "colorlineas=0x868484&colorfondo=0x313131&colorprov=0x272727&colorprov_over=0xFF7300&rutaXML=http://"+hw_host+"/inc/xml/provincias.xml";
	var result = '';
	result = result + '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="' + w + 'px" height="' + h + 'px">'+"\n";
	result = result + '<param name="movie" value="' + url_obj + '">'+"\n";
	result = result + '<param name="quality" value="high">'+"\n";
	result = result + '<param name="Flashvars" value="' + param + '">'+"\n";
	result = result + '<param name="allowScriptAccess" value="always">'+"\n";
	result = result + '<param name="wmode" value="transparent">'+"\n";
	// result = result + '<param name="allowfullscreen" value="true">'+"\n";
	result = result + '<embed wmode="transparent" width="' + w + 'px" height="' + h + 'px" src="' + url_obj + '?' + param + '" allowScriptAccess="always" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash">'+"\n";
	result = result + '</object>';

	document.write(result);
}

/*	PERSIANAS	*/
function overClas(id){
	
	document.getElementById('div_clasif_'+id).style.cursor = "pointer";
}
function outClas(id){
	
	//document.getElementById('p_clasif_'+id).style.color = '#757371';
}

function openClasif(id, tot){
	
	for (i=0; i<tot; i++){
		if (document.getElementById('div_desc_clasif_'+i)){
			document.getElementById('div_desc_clasif_'+i).style.display = 'none';
			
		}
	}
	if (document.getElementById('div_desc_clasif_'+id)){
		document.getElementById('div_desc_clasif_'+id).style.display = 'inline';
		
	}
}
function overClas(id, tot){
	for (i=0; i<tot; i++){
		if (document.getElementById('div_clasif_'+i))
		{
				//próximos estrenos
				if(document.getElementById('cual_acordeon').value=='prox'){
					
					document.getElementById('div_clasif_'+i).style.backgroundImage = "url(http://www."+hw_host+"/img/prox/icono.cerrado.gif)";
				
					document.getElementById('div_desc_clasif_'+i).style.borderBottom = "0px";
				}

				//módulo derecho próximos estrenos con trailer
				if(document.getElementById('cual_acordeon').value=='mod_prox'){
					
					document.getElementById('icon_'+i).src = 'http://www.'+hw_host+'/img/mod/prox-estrenos/icono.cerrado.gif';
					
				}
				
	
		}
	}
	
	//próximos estrenos
	if(document.getElementById('cual_acordeon').value=='prox'){
		
		document.getElementById('div_clasif_'+id).style.backgroundImage = 'url(http://www.'+hw_host+'/img/prox/icono.abierto.gif)';
	
		document.getElementById('div_desc_clasif_'+id).style.borderBottom = "1px solid #CCCCCC";
	}

	//módulo derecho próximos estrenos con trailer
	if(document.getElementById('cual_acordeon').value=='mod_prox'){
		
		document.getElementById('icon_'+id).src = 'http://www.'+hw_host+'/img/mod/prox-estrenos/icono.abierto.gif';
		
	}
	
}

/*Reducir/aumentar texto: */
var letra = 12;
var inter_letra = 1;
var letra_max = 16;
var letra_min = 10;

function tamanoFuente(valor){
	
	if(valor=='mas'){
		if (letra_max!=letra){
			letra = letra + inter_letra;
			document.getElementById('center_text').style.fontSize = letra+"px";
			document.getElementById('center_text').style.lineHeight = letra+(inter_letra*3)+"px";
		}
	}else if(valor=='menos'){
		
		if (letra_min!=letra){
			letra = letra - inter_letra;
			document.getElementById('center_text').style.fontSize = letra+"px";
			document.getElementById('center_text').style.lineHeight = letra+(inter_letra*3)+"px";
		}
	}
	
}
/*añadir a favoritos*/
function favoritos(url,nombre_seccion){

	if (window.sidebar&&window.sidebar.addPanel){
		window.sidebar.addPanel(hw_host + " - " + nombre_seccion,url,"");
	}else{
		window.external.AddFavorite(url, hw_host + " - " + nombre_seccion);
	}
}

/*enviar a un amigo*/
function layerEnviar(){

	document.getElementById("send").style.display="inline";

	var a = (screen.width-1000)/2;
	var b = a+163;
	document.getElementById("send").style.left=b+"px";
	document.getElementById("send").style.top="385px";
	
	

}
function layerEnviarCine(){
	
	document.getElementById("send_cine").style.display="inline";

	var a = (screen.width-1000)/2;
	var b = a+10;
	document.getElementById("send_cine").style.left=b+"px";
	document.getElementById("send_cine").style.top="378px";

	
}
function layerEnviarCineMapa(){
	
	document.getElementById("send_cm").style.display="inline";
	var ruta = document.getElementById("center_text_mail").innerHTML;
	//alert("1"+ruta);
	ruta=ruta.replace(/&nbsp;/g, " ");
	document.getElementById("ruta_layer").value = ruta;
	//alert("ruta layer: "+document.getElementById("ruta_layer").value);
	//alert("2"+document.getElementById("ruta_layer").value);


	var a = (screen.width-1000)/2;
	var b = a+105;
	document.getElementById("send_cm").style.left=b+"px";
	document.getElementById("send_cm").style.top="920px";

	
}
function layerEnviarProx(){
	
	document.getElementById("send_prox").style.display="inline";

	var a = (screen.width-1000)/2;
	var b = a+163;
	document.getElementById("send_prox").style.left=b+"px";
	document.getElementById("send_prox").style.top="385px";

	

}
function validarEmail(valor) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor)){
		return true;
	} else {
		return false;
	}
}
function submitSend(frm){
	if(isWhitespace(frm.nombre.value)){
		alert("Por favor, introduce tu nombre");
		frm.nombre.focus();
		return false;
	}
	if(isWhitespace(frm.email.value)){
		alert("Por favor, introduce tu e-mail");
		frm.email.focus();
		return false;
	}
	if(!validarEmail(frm.email.value)){
		alert("Tu e-mail no es correcto\n");
		return false;
	}
	if(isWhitespace(frm.destinatarios.value)){
		alert("Por favor, introduce mínimo 1 destinatario");
		frm.destinatarios.focus();
		return false;
	}

	frm.destinatarios.value=frm.destinatarios.value.replace(/,/g, ";");
	var destinosOrig = frm.destinatarios.value;
	var destinos = frm.destinatarios.value;
	destinos = destinos.split(";");
	var total_destinos = destinos.length;
	
	var x=0;
	var ok=true;
	for(x=0;x<total_destinos;x++){
		if(destinos[x]!="" && destinos[x]!= " "){
			if(!validarEmail(destinos[x])){
				alert("El e-mail '"+destinos[x]+"' no tiene un formato correcto. Por favor, revise los e-mails de destino.\n");
				ok=false;
			}
		}
	}

	if (ok){
		var div1=document.getElementById('send1');
		var div2=document.getElementById('send2');
		var div3=document.getElementById('send3');


		var parameters = "mail=" + destinosOrig + "&email=" +frm.email.value+ "&url=" + frm.url_actual.value + "&nombre=" + frm.nombre.value + "&mensaje=" + frm.mensaje.value+"&url_pel_bbdd="+frm.url_pel_bbdd.value; //declaramos los parámetros a comparar
		document.getElementById("btn_submit_sendfriend").style.display="none";
		ajax = ajaxobj(); //inicializamos el objeto ajax
		ajax.open("POST", "http://cartelera."+hw_host+"/inc/cjob/catch/envio/sendfriend.php"); //llamamos al proceso ajax
		ajax.onreadystatechange=function(){
		

			if (ajax.readyState==4) {
				var datos = ajax.responseText; //capturamos el resultado de la búsqueda
				switch (datos)
				{
				case '1':/*fallo en el envío*/
					document.getElementById("btn_submit_sendfriend").style.display="";
					div1.style.display="none";
					div2.style.display="none";
					div3.style.display="inline";
				break;
				case '2':/*envío correcto*/
					document.getElementById("btn_submit_sendfriend").style.display="";
					div1.style.display="none";
					div2.style.display="inline";
					div3.style.display="none";
				break;
				
				}
				
			}
		}
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;'); 
		ajax.send(parameters); 
	}
	return null; 
}

function submitSendCineMapa(frm){
	
	if(isWhitespace(frm.nombre_cm.value)){
		alert("Por favor, introduce tu nombre");
		frm.nombre_cm.focus();
		return false;
	}
	if(isWhitespace(frm.email_cm.value)){
		alert("Por favor, introduce tu e-mail");
		frm.email_cm.focus();
		return false;
	}
	if(!validarEmail(frm.email_cm.value)){
		alert("Tu e-mail no es correcto\n");
		return false;
	}
	if(isWhitespace(frm.destinatarios_cm.value)){
		alert("Por favor, introduce mínimo 1 destinatario");
		frm.destinatarios_cm.focus();
		return false;
	}

	frm.destinatarios_cm.value=frm.destinatarios_cm.value.replace(/,/g, ";");
	var destinos = frm.destinatarios_cm.value;
	var destinosOrig = frm.destinatarios_cm.value;
	destinos = destinos.split(";");
	var total_destinos = destinos.length;
	
	var x=0;
	var ok=true;
	for(x=0;x<total_destinos;x++){
		if(destinos[x]!="" && destinos[x]!= " "){
			if(!validarEmail(destinos[x])){
				alert("El e-mail '"+destinos[x]+"' no tiene un formato correcto. Por favor, revise los e-mails de destino.\n");
				ok=false;
			}
		}
	}

	if (ok){
		var div1=document.getElementById('send1_cm');
		var div2=document.getElementById('send2_cm');
		var div3=document.getElementById('send3_cm');
		var parameters = "mail=" + destinosOrig + "&ruta=" +frm.ruta_layer.value+ "&email=" +frm.email_cm.value+ "&url=" + frm.url_actual_cm.value + "&nombre=" + frm.nombre_cm.value + "&mensaje=" + frm.mensaje_cm.value+ "&url_cine_bbdd=" + frm.url_cinemapa_bbdd.value; //declaramos los parámetros a comparar

		document.getElementById("btn_submit_cinemapa").style.display="none";

		ajax = ajaxobj(); //inicializamos el objeto ajax
		ajax.open("POST", "http://cines."+hw_host+"/inc/cjob/catch/envio/sendfriend-cineMapa.php"); //llamamos al proceso ajax
		ajax.onreadystatechange=function(){
		
	
			if (ajax.readyState==4) {
				var datos = ajax.responseText; //capturamos el resultado de la búsqueda
				switch (datos)
				{
				case '1':/*fallo en el envío*/
					div1.style.display="none";
					div2.style.display="none";
					div3.style.display="inline";
					document.getElementById("btn_submit_cinemapa").style.display="";
				break;
				case '2':/*envío correcto*/
					div1.style.display="none";
					div2.style.display="inline";
					div3.style.display="none";
					document.getElementById("btn_submit_cinemapa").style.display="";
				break;
				
				}
				
			}
		}
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;'); 
		ajax.send(parameters); 
	}
	return null; 
}

function submitSendCine(frm){
	
	if(isWhitespace(frm.nombre_c.value)){
		alert("Por favor, introduce tu nombre");
		frm.nombre_c.focus();
		return false;
	}
	if(isWhitespace(frm.email_c.value)){
		alert("Por favor, introduce tu e-mail");
		frm.email_c.focus();
		return false;
	}
	if(!validarEmail(frm.email_c.value)){
		alert("Tu e-mail no es correcto\n");
		return false;
	}
	if(isWhitespace(frm.destinatarios_c.value)){
		alert("Por favor, introduce mínimo 1 destinatario");
		frm.destinatarios_c.focus();
		return false;
	}

	frm.destinatarios_c.value=frm.destinatarios_c.value.replace(/,/g, ";");
	var destinos = frm.destinatarios_c.value
	var destinosOrig = frm.destinatarios_c.value;
	destinos = destinos.split(";");
	var total_destinos = destinos.length;
	
	var ok=true;
	for(x=0;x<total_destinos;x++){
		if(destinos[x]!="" && destinos[x]!= " "){
			if(!validarEmail(destinos[x])){
				alert("El e-mail '"+destinos[x]+"' no tiene un formato correcto. Por favor, revise los e-mails de destino.\n");
				ok=false;
			}
		}
	}

	if (ok){
		var div1=document.getElementById('send1_cine');
		var div2=document.getElementById('send2_cine');
		var div3=document.getElementById('send3_cine');
		
		document.getElementById("btn_submit_cine").style.display="none";

		var parameters = "mail=" + destinosOrig + "&email=" +frm.email_c.value+ "&url=" + frm.url_actual_c.value + "&nombre=" + frm.nombre_c.value + "&mensaje=" + frm.mensaje_c.value+"&url_cine_bbdd="+frm.url_cine_bbdd.value; //declaramos los parámetros a comparar

		ajax = ajaxobj(); //inicializamos el objeto ajax
		ajax.open("POST", "http://cines."+hw_host+"/inc/cjob/catch/envio/sendfriend-cine.php"); //llamamos al proceso ajax
		ajax.onreadystatechange=function(){
			if (ajax.readyState==4) {
				var datos = ajax.responseText; //capturamos el resultado de la búsqueda
				switch (datos)
				{
				case '1':/*fallo en el envío*/
					div1.style.display="none";
					div2.style.display="none";
					div3.style.display="inline";
					document.getElementById("btn_submit_cine").style.display="";
				break;
				case '2':/*envío correcto*/
					div1.style.display="none";
					div2.style.display="inline";
					div3.style.display="none";
					document.getElementById("btn_submit_cine").style.display="";
				break;
				
				}
				
			}
		}
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;'); 
		ajax.send(parameters); 
	}
	return null; 
}

function submitSendProx(frm){
	
	if(isWhitespace(frm.nombre_p.value)){
		alert("Por favor, introduce tu nombre");
		frm.nombre_p.focus();
		return false;
	}
	if(isWhitespace(frm.email_p.value)){
		alert("Por favor, introduce tu e-mail");
		frm.email_p.focus();
		return false;
	}
	if(!validarEmail(frm.email_p.value)){
		alert("Tu e-mail no es correcto\n");
		return false;
	}
	if(isWhitespace(frm.destinatarios_p.value)){
		alert("Por favor, introduce mínimo 1 destinatario");
		frm.destinatarios_p.focus();
		return false;
	}

	frm.destinatarios_p.value=frm.destinatarios_p.value.replace(/,/g, ";");
	var destinos = frm.destinatarios_p.value;
	var destinosOrig = frm.destinatarios_p.value;
	destinos = destinos.split(";");
	var total_destinos = destinos.length;
	
	var ok=true;
	for(x=0;x<total_destinos;x++){
		if(destinos[x]!="" && destinos[x]!= " "){
			if(!validarEmail(destinos[x])){
				alert("El e-mail '"+destinos[x]+"' no tiene un formato correcto. Por favor, revise los e-mails de destino.\n");
				ok=false;
			}
		}
	}

	if (ok){
		var div1=document.getElementById('send1_p');
		var div2=document.getElementById('send2_p');
		var div3=document.getElementById('send3_p');
		var parameters = "mail=" + destinosOrig + "&email=" +frm.email_p.value+ "&url=" + frm.url_actual_p.value + "&nombre=" + frm.nombre_p.value + "&mensaje=" + frm.mensaje_p.value+"&url_pel_bbdd="+frm.url_pel_bbdd.value; //declaramos los parámetros a comparar

		document.getElementById("btn_submit_proxestrenos").style.display="none";

		ajax = ajaxobj(); //inicializamos el objeto ajax
		ajax.open("POST", "http://proximos-estrenos."+hw_host+"/inc/cjob/catch/envio/sendfriend-prox.php"); //llamamos al proceso ajax
		ajax.onreadystatechange=function(){
			if (ajax.readyState==4) {
				var datos = ajax.responseText; //capturamos el resultado de la búsqueda
				switch (datos)
				{
				case '1':/*fallo en el envío*/
					div1.style.display="none";
					div2.style.display="none";
					div3.style.display="inline";
					document.getElementById("btn_submit_proxestrenos").style.display="";
				break;
				case '2':/*envío correcto*/
					div1.style.display="none";
					div2.style.display="inline";
					div3.style.display="none";
					document.getElementById("btn_submit_proxestrenos").style.display="";
				break;
				
				}	
			}
		}

		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;'); 
		ajax.send(parameters); 
	}
	return null; 
}

function imprime(){
	var contenido = document.getElementById("center_text").innerHTML;
	
	window.frames[0].document.getElementById("center_text_oculto").innerHTML = contenido;
			
	window.frames[0].print();
}
function imprimeMapa(){
	var contenido = document.getElementById("center_text_mail").innerHTML;
	
	window.frames[0].document.getElementById("center_text_oculto").innerHTML = contenido;
			
	window.frames[0].print();
}

function layerBoletin(){
	
	document.getElementById("layer_boletin").style.display="inline";

	var a = (screen.width-1000)/2;
	var b = a+20;
	document.getElementById("layer_boletin").style.left=b+"px";
	document.getElementById("layer_boletin").style.top="580px";

	

}

function submitBoletin(frm,subdom){

	if(subdom=='home')subdom='www';

	if(isWhitespace(frm.nombre_b.value)){
		alert("Por favor, introduce tu nombre");
		frm.nombre_b.focus();
		return false;
	}
	if(isWhitespace(frm.apellidos_b.value)){
		alert("Por favor, introduce tus apellidos");
		frm.apellidos_b.focus();
		return false;
	}
	if(isWhitespace(frm.email_b.value)){
		alert("Por favor, introduce tu e-mail");
		frm.email_b.focus();
		return false;
	}
	if(!validarEmail(frm.email_b.value)){
		alert("Tu e-mail no es correcto\n");
		return false;
	}
	if(isWhitespace(frm.sexo_b.value)){
		alert("Por favor, selecciona tu sexo");
		frm.sexo_b.focus();
		return false;
	}
	if(frm.ciudades.value==0){
		alert("Por favor, selecciona tu ciudad");
		frm.ciudades.focus();
		return false;
	}

	var parameters = "nombre=" +frm.nombre_b.value+ "&apellidos=" +frm.apellidos_b.value+ "&email=" +frm.email_b.value+ "&sexo=" +frm.sexo_b.value+ "&ciudad=" +frm.ciudades.value;
	ajax = ajaxobj(); //inicializamos el objeto ajax
	ajax.open("POST", "http://"+subdom+"."+hw_host+"/inc/cjob/catch/envio/boletin.php"); //llamamos al proceso ajax

	ajax.onreadystatechange=function(){
		if (ajax.readyState==4) {
			var datos = ajax.responseText; //capturamos el resultado de la búsqueda
			var div1=document.getElementById('boletin_1');
			var div2=document.getElementById('boletin_2');
			var div3=document.getElementById('boletin_3');
			var div4=document.getElementById('boletin_4');
			
			var res = ajax.responseText;
			var datos=res.split("--");
			switch (datos[0])
			{
				case '1':/*fallo en el envío*/
					div1.style.display="none";
					div2.style.display="none";
					div3.style.display="inline";
					div4.style.display="none";
				break;
				case '2':/*envío correcto*/
					div1.style.display="none";
					div2.style.display="inline";
					div3.style.display="none";
					div4.style.display="none";
				break;
				case '3':/*registro repetido*/
					div1.style.display="none";
					div2.style.display="none";
					div3.style.display="none";
					div4.style.display="inline";
				break;
			}

			/*link a cines de la ciudad*/
			if(datos[0]=='2'){
				document.getElementById('link_provs').innerHTML=datos[1];
			}
			
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);

}

function getPlayerFavoritos(id){
	var parameters = "id_video_fav=" + id;
	ajax = ajaxobj();
	ajax.open("POST", "/inc/cjob/catch/envio/favorito.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			var res=datos.split("--");
			favoritos(res[0],res[1]);						
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);	
}
  
function getPlayerCompartir(id){

	document.getElementById("send_player").style.display="inline";
	document.getElementById("id_video").value=id;

	window.onscroll=scrollIt;
	
	var posicion2 = "";
	if(window.pageYOffset){
		posicion2 = window.pageYOffset;
	}else {
		posicion2 = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	}
	var	posicion_top = (screen.height/2)-220 + posicion2;
	var posicion_left = (screen.width/2)-247
	
	document.getElementById('send_player').style.top  = posicion_top + "px";
	document.getElementById('send_player').style.left  = posicion_left + "px";
}

function scrollIt(ev){

	window.status="scrolling";
	var posicion2 = "";
	if(window.pageYOffset){
		posicion2 = window.pageYOffset;
	}else {
		posicion2 = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	}
	var	posicion = (screen.height/2)-200 + posicion2;
	
	document.getElementById('send_player').style.top  = posicion + "px";
}


function scrollIt_Permalink(ev){

	window.status="scrolling";
	var posicion2 = "";
	if(window.pageYOffset){
		posicion2 = window.pageYOffset;
	}else {
		posicion2 = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	}
	var	posicion = (screen.height/2)-200 + posicion2;
	
	document.getElementById('permalink').style.top = posicion + "px";
}


function getPlayerPermalink(id){
	
	var parameters = "id_video_perm=" + id;
	window.onscroll=scrollIt_Permalink;

	ajax = ajaxobj();
	ajax.open("POST", "/inc/cjob/catch/envio/getPermalink.php");
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4){
			var datos = ajax.responseText;
			
			document.getElementById("permalink").style.display="inline";
			document.getElementById("id_video_perm").value=datos;
			
			

			var posicion2 = "";
			if(window.pageYOffset){
				posicion2 = window.pageYOffset;
			}else {
				posicion2 = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
			}
			var	posicion_top = (screen.height/2)-200 + posicion2;
			var posicion_left = (screen.width/2)-247

			document.getElementById("permalink").style.left=posicion_left+"px";
			document.getElementById("permalink").style.top=posicion_top+"px";
				
						
		}
	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
	ajax.send(parameters);
	
}




function submitSendPlayer(frm,subdom){

	if(subdom=='home')subdom='www';

	if(isWhitespace(frm.nombre_pl.value)){
		alert("Por favor, introduce tu nombre");
		frm.nombre_pl.focus();
		return false;
	}
	if(isWhitespace(frm.email_pl.value)){
		alert("Por favor, introduce tu e-mail");
		frm.email_pl.focus();
		return false;
	}
	if(!validarEmail(frm.email_pl.value)){
		alert("Tu e-mail no es correcto\n");
		return false;
	}
	if(isWhitespace(frm.destinatarios_pl.value)){
		alert("Por favor, introduce mínimo 1 destinatario");
		frm.destinatarios_pl.focus();
		return false;
	}
	document.getElementById("destinatarios_pl").value=document.getElementById("destinatarios_pl").value.replace(/,/g, ";");

	var destinosOrig = document.getElementById("destinatarios_pl").value;
	var destinos = document.getElementById("destinatarios_pl").value;
	destinos = destinos.split(";");
	var total_destinos = destinos.length;
	
	//alert("destinos:"+total_destinos+" "+destinos+" "+destinos[0]+" "+destinos[1]);
	var x=0;
	var ok=true;
	for(x=0;x<total_destinos;x++){
		if(destinos[x]!="" && destinos[x]!= " "){

			if(!validarEmail(destinos[x])){
				alert("El e-mail '"+destinos[x]+"' no tiene un formato correcto. Por favor, revise los e-mails de destino.\n");
				ok=false;
			}
		}
	}
	
	if (ok){
		var div1=document.getElementById('send1_pl');
		var div2=document.getElementById('send2_pl');
		var div3=document.getElementById('send3_pl');

		document.getElementById("btn_submit_sendplayer").style.display="none";

		var parameters = "mail=" + destinosOrig + "&email=" +frm.email_pl.value+ "&id_video=" + frm.id_video.value + "&nombre=" + frm.nombre_pl.value + "&mensaje=" + frm.mensaje_pl.value; //declaramos los parámetros a comparar
		ajax = ajaxobj(); //inicializamos el objeto ajax

		ajax.open("POST", "http://"+subdom+"."+hw_host+"/inc/cjob/catch/envio/sendPlayer.php"); //llamamos al proceso ajax
		ajax.onreadystatechange=function(){
		
			if (ajax.readyState==4) {
				var datos = ajax.responseText; //capturamos el resultado de la búsqueda
				switch (datos)
				{
				case '1':/*fallo en el envío*/
					document.getElementById("btn_submit_sendplayer").style.display="";
					div1.style.display="none";
					div2.style.display="none";
					div3.style.display="inline";
				break;
				case '2':/*envío correcto*/
					document.getElementById("btn_submit_sendplayer").style.display="";
					div1.style.display="none";
					div2.style.display="inline";
					div3.style.display="none";
				break;
				
				}
				
			}
		}
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;'); 
		ajax.send(parameters); 
	}
	return null; 

}

function submitTaq(frm,valor){
	
	frm.submit();

}

function submitContacto(frm){
	
	if(isWhitespace(frm.nombre.value)){
		alert("Por favor, introduce tu nombre");
		frm.nombre.focus();
		return false;
	}
	if(isWhitespace(frm.email.value)){
		alert("Por favor, introduce tu e-mail");
		frm.email.focus();
		return false;
	}
	if(!validarEmail(frm.email.value)){
		alert("Tu e-mail no es correcto\n");
		return false;
	}
	if(isWhitespace(frm.comentario.value)){
		alert("Por favor, introduce tu comentario");
		frm.comentario.focus();
		return false;
	}

	frm.submit();
}

function mostrarOcultar(id,titulo){
	
	if(document.getElementById(id).style.display==''){
		document.getElementById(id).style.display='none';
		document.getElementById(titulo).innerHTML='mostrar';

	}else{
		document.getElementById(id).style.display='';
		document.getElementById(titulo).innerHTML='ocultar';
	}

}

function submitBaja(frm){
	if(window.confirm('¿Estás seguro?')){
		if(frm.motivo.value=='4' && (isWhitespace(frm.otro_motivo.value))){
			
			alert("Por favor, introduce un motivo");
			frm.otro_motivo.focus();
			return false;
			
		}
		frm.submit();
	}
}

//Limitador de textos para los textaarea
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

//manejador de formulario de alta de boletines. Muestra u oculta capas
function setFormularioBoletin(){
	document.getElementById("boletin_1").style.display="";
	document.getElementById("boletin_2").style.display="none";
	document.getElementById("boletin_3").style.display="none";
	document.getElementById("boletin_4").style.display="none";
}
