﻿

function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
	
		// this deletes the cookie when called
		function Delete_Cookie( name, path, domain ) {
			if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
			}

function controlPrograma(){
	var oEditor = FCKeditorAPI.GetInstance('desc_regalo') ;
	var length = GetLength();						
	if(length >20000 && length != globalLength){
		alert("<cfoutput>#application.V.MENUCENTER.MODIFCOURSE.ALERT_PROGRAMCHARS#</cfoutput>");					
	}
	globalLength = length;
	document.getElementById("longitud").value=length;
}
function FCKeditor_OnComplete( editorInstance )
{

	var oEditor = FCKeditorAPI.GetInstance('desc_regalo') ;
	if(!document.all){
		oEditor.Events.AttachEvent( 'OnSelectionChange', controlPrograma ) ;
	}
	oEditor.EditorDocument.body.onkeypress = controlPrograma;
	oEditor.EditorDocument.body.onkeyup = controlPrograma;
	oEditor.EditorDocument.body.onfocus = controlPrograma;
	document.getElementById("longitud").value=GetLength();
	
}
function GetLength() 
{ 
     // This functions shows that you can interact directly with the editor area 
     // DOM. In this way you have the freedom to do anything you want with it. 
  
     // Get the editor instance that we want to interact with. 
     var oEditor = FCKeditorAPI.GetInstance('desc_regalo') ; 
  
     // Get the Editor Area DOM (Document object). 
     var oDOM = oEditor.EditorDocument ; 
  
     var iLength ; 
  
     // The are two diffent ways to get the text (without HTML markups). 
     // It is browser specific. 
 
     if ( document.all )     // If Internet Explorer. 
     { 
            content = oDOM.body.innerText ; 
	    conte=content.replace(/\s/g, '');
	    conte=conte.replace(new RegExp('<br>','gi'), ' ');
	    conte=conte.replace(new RegExp('&nbsp;','gi'), ' ');
	    conte=conte.replace(new RegExp('&lt;','gi'), ' ');
	    conte=conte.replace(new RegExp('&gt;','gi'), ' ');
	    conte=conte.replace(new RegExp('<[^>]*>','gi'), '');
	    iLength = conte.length;
     } 
     else                    // If Gecko. 
     { 
         var r = oDOM.createRange() ; 
         r.selectNodeContents( oDOM.body ) ; 
         content = r.toString() ; 
	 conte=content.replace(/\s/g, '');
	 conte=conte.replace(new RegExp('<br>','gi'), ' ');
	 conte=conte.replace(new RegExp('&nbsp;','gi'), ' ');
	 conte=conte.replace(new RegExp('&lt;','gi'), ' ');
	 conte=conte.replace(new RegExp('&gt;','gi'), ' ');
	 conte=conte.replace(new RegExp('<[^>]*>','gi'), '');
	 iLength = conte.length;
     } 
     
     return iLength; 
} 

function isNumeric(sText)

{
   var ValidChars = "0123456789.,-";
   var IsNumber=true;
   var Char;
	var i;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

 
function emailCheck (emailStr) {
/* Verificar si el email tiene el formato user@dominio. */
var emailPat=/^(.+)@(.+)$/;

/* Verificar la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";

/* Verifica los caracteres que son válidos en una dirección de email */
var validChars="\[^\\s" + specialChars + "\]";

var quotedUser="(\"[^\"]*\")";

/* Verifica si la dirección de email está representada con una dirección IP Válida */


var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* Verificar caracteres inválidos */

var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/*domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");


var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("La dirección de mail parece no ser correcta (comprueba que tiene @ y .)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Si el user "user" es valido 
if (user.match(userPat)==null) {
// Si no
alert("El nombre de usuario no es válido.");
return false;
}

/* Si la dirección IP es válida */
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("IP de destino inválida");
return false
}
}
return true
}

var domainArray=domain.match(domainPat);
if (domainArray==null) {
alert("El dominio parece no ser válido.");
return false
}

var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if (domArr[domArr.length-1].length<2 || 
domArr[domArr.length-1].length>3) {

alert("La dicrección debe tener 3 letras si es .com o 2 si en de algún pais.");
return false
}

if (len<2) {
var errStr="La dirección es erronea";
alert(errStr);
return false
}

// La dirección de email ingresada es Válida
return true;
}
// End -->
// this function gets the cookie, if it exists

function creaXML(){
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp=false;
	  }
	 }
	@else
	 xmlhttp=false
	 @end @*/
	
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

function ponerMenuUsuario(){
	var xmlhttp=creaXML();
	var urlcaja="/home_usuario/cargar_menu.php";
	xmlhttp.open("GET",urlcaja,false);
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttp.send(null);
	
	if (xmlhttp.readyState==4) {		
		document.getElementById("nombre_usuario").innerHTML=xmlhttp.responseText;
		}
	}

function desconectar(){
			Delete_Cookie("hash_logado","/","telocambio.com");
			document.location="/";
		}
		
function combo_provincia(pais,id_provincia){
	var xmlhttp=creaXML();
	var urlcaja="/commons/carga_provincias.php?id_pais="+pais+"&id_provincia="+id_provincia;
	xmlhttp.open("GET",urlcaja,false);
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttp.send(null);
	
	if (xmlhttp.readyState==4) {		
		document.getElementById("capa_provincias").innerHTML=xmlhttp.responseText;
		}
	}
	
function combo_ciudades(provincia,id_ciudad){
	var xmlhttp=creaXML();
	var urlcaja="/commons/carga_ciudades.php?id_provincia="+provincia+"&id_ciudad="+id_ciudad;
	xmlhttp.open("GET",urlcaja,false);
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttp.send(null);
	if (xmlhttp.readyState==4) {			
   		document.getElementById("capa_ciudades").innerHTML=xmlhttp.responseText;
		}
	}
function combo_categorias(categoria,id_categ_sel,orden){
	if(orden<3){
	var xmlhttp=creaXML();
	var urlcaja="/menu_centros/carga_categorias.php?id_categ="+categoria+"&id_categ_sel="+id_categ_sel+"&orden="+orden;
	xmlhttp.open("GET",urlcaja,false);
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttp.send(null);
	if (xmlhttp.readyState==4) {											
   		document.getElementById("capa_categorias"+orden).innerHTML=xmlhttp.responseText;
		}
	}
}

// Mostramos ventana de información (Compra - Packs, etc...)
function InfoWindow1(page) {	
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');	
	objOverlay.style.display = 'none';
	objBody.appendChild(objOverlay);

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';

	objBody.appendChild(objLightbox);
			
	hideSelectBoxes();
	hideFlash();
			
	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	alert(arrayPageSize[1]);
	Element.setHeight('overlay', arrayPageSize[1]);		
	new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: overlayOpacity });


	// calculate top offset for the lightbox and display 
	ajaxpagesin(page,'lightbox');
			
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
	Element.setTop('lightbox', lightboxTop);
	Element.show('lightbox');	
}

function CloseInfoWindow1() {
	Element.hide('overlay');
	Element.removeChild('lightbox');
	if(typeof(FCKeditorAPI)!="undefined") {FCKeditorAPI=null;}
	showSelectBoxes();
	showFlash();	
}

function validar_info()
{
	if(document.getElementById('password_info').value!=""){
		return emailCheck(document.getElementById('mail_info').value);
	}else{
		alert ("Debes poner un password");
		return false;
	}
}

function validar_info_login(){
	if(document.getElementById('password').value!=""){
		return emailCheck(document.getElementById('mail').value);
	}else{
		alert ("Debes poner un password");
		return false;
	}
}


function enviar_quini(){
	a=true;
	a=emailCheck(document.getElementById('mail').value);
	if(document.getElementById('password').value=="" && a){
		alert("Debes introducir el password");
		a= false;
	}
	if(document.getElementById('partido1').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 1");
		a= false;
	}
	if(document.getElementById('partido2').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 2");
		a= false;
	}
	if(document.getElementById('partido3').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 3");
		a= false;
	}
	if(document.getElementById('partido4').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 4");
		a= false;
	}
	if(document.getElementById('partido5').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 5");
		a= false;
	}
	if(document.getElementById('partido6').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 6");
		a= false;
	}
	if(document.getElementById('partido7').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 7");
		a= false;
	}
	if(document.getElementById('partido8').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 8");
		a= false;
	}
	if(document.getElementById('partido9').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 9");
		a= false;
	}
	if(document.getElementById('partido10').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 10");
		a= false;
	}
	if(document.getElementById('partido10').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 11");
		a= false;
	}
	if(document.getElementById('partido12').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 12");
		a= false;
	}
	if(document.getElementById('partido13').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 13");
		a= false;
	}
	if(document.getElementById('partido14').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 14");
		a= false;
	}
	if(document.getElementById('partido15').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 15");
		a= false;
	}
	if(a){
		document.getElementById('pronostico').submit();
	}
	}
var linkantic;
function enviar_prono(id_prono){
	document.getElementById('anuncio').value=id_prono;
	a=true;
	if(document.getElementById('mail').value!="" && document.getElementById('password').value==""){
		alert("Debes introducir el password");
		a= false;
	}
	if(document.getElementById('partido1').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 1");
		a= false;
	}
	if(document.getElementById('partido2').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 2");
		a= false;
	}
	if(document.getElementById('partido3').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 3");
		a= false;
	}
	if(document.getElementById('partido4').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 4");
		a= false;
	}
	if(document.getElementById('partido5').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 5");
		a= false;
	}
	if(document.getElementById('partido6').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 6");
		a= false;
	}
	if(document.getElementById('partido7').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 7");
		a= false;
	}
	if(document.getElementById('partido8').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 8");
		a= false;
	}
	if(document.getElementById('partido9').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 9");
		a= false;
	}
	if(document.getElementById('partido10').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 10");
		a= false;
	}
	if(document.getElementById('partido10').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 11");
		a= false;
	}
	if(document.getElementById('partido12').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 12");
		a= false;
	}
	if(document.getElementById('partido13').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 13");
		a= false;
	}
	if(document.getElementById('partido14').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 14");
		a= false;
	}
	if(document.getElementById('partido15').value=="" && document.getElementById('mail').value!="" && a){
		alert("Debes introducir el resultado del partido 15");
		a= false;
	}
	if(a){
		document.getElementById('pronostico').submit();
	}else{
		linkantic=document.getElementById('banner'+id_prono).href;
		document.getElementById('banner'+id_prono).href="javascript:recuperalink("+id_prono+")";
	}
}
function recuperalink(id_prono){
	document.getElementById('banner'+id_prono).href=linkantic;
}

