/*Ramon flash and java*/

function AbrirCanalTV(canal, idioma)
{
	if(canal == "0" || canal == "")
		window.open('../espanyoltv/index.php?idioma='+idioma+'','newWin','width=1280,height=1024,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=Yes,fullscreen=No');
	else
		window.open('../espanyoltv/index.php?canal='+canal+'&idioma='+idioma+'','newWin','width=1280,height=1024,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=Yes,fullscreen=No');
}

function abreRodadorGrande(file) {
	//alert(file);
	//alert("hola");
	filex = file.replace( /XMLImagenes/g, "galeriaimagenrotator");
	window.open('http://www.rcdespanyol.com/'+filex,'newWin','width=820,height=665,toolbar=No,location=No,scrollbars=No,status=No,resizable=No,fullscreen=No');
	//window.open('http://www.rcdespanyol.com/'+filex,'newWin','');
}

function abreRodadorGrande2(file) {
	//alert(file);
	//alert("hola");
	filex = file.replace( /XMLImagenes/g, "galeriaimagenrotator2");
	window.open('http://www.rcdespanyol.com/'+filex,'newWin','width=820,height=665,toolbar=No,location=No,scrollbars=No,status=No,resizable=No,fullscreen=No');
}
/* ========================================= */
/* ========================================= */
/* FUNCIONES DOM                             */
/* Objetos del navegador                     */
/* ========================================= */
/* ========================================= */

/* ========================================= */
/* Objeto : Cualquiera que se quiera         */
/* ----------------------------------------- */
/* Propiedades                               */
/*       css        --> style                */
/*       objectType --> tagName              */
/*       id         --> id                   */
/*       name       --> name                 */
/*       className  --> className            */
/*       x          --> Posición X           */
/*       y          --> Posición Y           */
/*       w          --> Ancho                */
/*       h          --> Alto                 */
/* ----------------------------------------- */
/* Métodos                                   */
/*       setClass   --> Establecer una clase */
/* ========================================= */
function AnyObj(obj) {
    // Propiedades del objeto
    this.obj = obj;
    this.css = this.obj.style;
    this.objectType = this.obj.tagName;
    this.id = this.obj.id;
    this.name = this.obj.name;
    this.className = this.obj.className
    if (document.all || document.getElementById) {
        yPos = this.obj.offsetTop;
        xPos = this.obj.offsetLeft;
        tempImagen = this.obj.offsetParent;
        while (tempImagen != null) {
            yPos += tempImagen.offsetTop;
            xPos += tempImagen.offsetLeft;
            tempImagen = tempImagen.offsetParent;
        } // While
        this.x = xPos;
        this.y = yPos;
        this.w = this.obj.offsetWidth;
        this.h = this.obj.offsetHeight;
    } else {
        this.x = this.obj.x;
        this.y = this.obj.y;
    } // If

    this.SetClass = function (str_data) {
        if (str_data != "") this.className = this.obj.className = str_data;
    }
}

/* ========================================= */
/* Objeto: Imagen                            */
/* ----------------------------------------- */
/* Propiedades                               */
/*       css        --> style                */
/*       objectType --> "image"              */
/*       id         --> id                   */
/*       name       --> name                 */
/*       alt        --> alt                  */
/*       title      --> title                */
/*       src        --> src                  */
/*       x          --> Posición X           */
/*       y          --> Posición Y           */
/*       w          --> Ancho                */
/*       h          --> Alto                 */
/* ----------------------------------------- */
/* Métodos                                   */
/*       SetSrc     --> Establecer src       */
/*       SetSize    --> Establecer tamaño    */
/* ========================================= */
function ImgObj(str_NameImage) {
    this.objectType = "image";  
    this.obj = document.images[str_NameImage];
    this.css = this.obj.style;
    this.id = this.obj.id;
    this.name = this.obj.name;
    this.alt = this.obj.alt;
    this.title = this.obj.title;
    this.w = this.obj.width;
    this.h = this.obj.height;
    this.src = this.obj.src;

    if (document.all || document.getElementById) {
        yPos = this.obj.offsetTop;
        tempImagen = this.obj.offsetParent;
        while (tempImagen != null) {
            yPos += tempImagen.offsetTop;
            tempImagen = tempImagen.offsetParent;
        } // while
        xPos = this.obj.offsetLeft;
        tempImagen = this.obj.offsetParent;
        while (tempImagen != null) {
            xPos += tempImagen.offsetLeft;
            tempImagen = tempImagen.offsetParent;
        } // while
        this.x = xPos;
        this.y = yPos;
    } else {
        this.x = this.obj.x;
        this.y = this.obj.y;
    } // If
  
    this.SetSrc = function(src) {
        var obj_imgt = new Image();
        obj_imgt.src = src;
        this.obj.src = this.src = src;
        this.SetSize(obj_imgt.width, obj_imgt.height);
    }
  
    this.SetSize = function(wf, hf) {
        this.obj.width = this.w = wf;
        this.obj.height = this.h = hf;
    }
}

/* ============================================= */
/* Objeto: Layer                                 */
/* --------------------------------------------- */
/* Propiedades                                   */
/*       css        --> style                    */
/*       objectType --> "layer"                  */
/*       id         --> id                       */
/*       x          --> Posición X               */
/*       y          --> Posición Y               */
/*       w          --> Ancho                    */
/*       h          --> Alto                     */
/*       v          --> Visible                  */
/* --------------------------------------------- */
/* Métodos                                       */
/*       SetVisibility  --> Establecer visible   */
/*       SetPosition    --> Establecer posicion  */
/*       SetSize        --> Establecer tamaño    */
/*       SetScroll      --> Establecer scroll    */
/* ============================================= */
function DivObj(str_layername) {
    this.objectType = "layer";
    if (document.layers) {
        this.obj = document.layers[str_layername];
        this.css = this.obj;
        var wTam = parseInt(this.css.clip.width);
        var hTam = parseInt(this.css.clip.height);
        str_Visible = "show";
        str_Hidden = "hide";
    } else if (document.all) {
        this.obj = document.all[str_layername];
        this.css = this.obj.style;
        var wTam = parseInt(this.obj.offsetWidth);
        var hTam = parseInt(this.obj.offsetHeight);
        str_Visible = "visible";
        str_Hidden = "hidden";
    } else if (document.getElementById) {
        this.obj = document.getElementById(str_layername);
        this.css = this.obj.style;
        var wTam = parseInt(this.obj.offsetWidth);
        var hTam = parseInt(this.obj.offsetHeight);
        str_Visible = "visible";
        str_Hidden = "hidden";
    } // If
  
    this.id = this.obj.id;
    this.x = parseInt(this.css.left);
    this.y = parseInt(this.css.top);
    this.w = wTam;
    this.h = hTam;
    this.v = this.css.visibility;
    
    if (this.v == "") this.v = str_Visible;
    
    this.SetVisibility = function(status) {
        if (status == "off" || status == false) {
            this.css.visibility = this.v = str_Hidden;
        } else {
            this.css.visibility = this.v = str_Visible;
        } // if
    }
  
    this.SetPosition = function(xf,yf) {
        this.css.left = this.x = xf;
        this.css.top = this.y = yf;
    }
    
    this.SetSize = function(wf,hf) {
        if (wf > 0 && hf > 0) {
            if (document.layers) {
                this.obj.clip.width = this.w = wf;
                this.css.clip.height = this.h = hf;
            } else {
                this.css.width = this.w = wf;
                this.css.height = this.h = hf;
            } // If
        } // If
    }
  
    this.SetScroll = function(wf, hf) {
        if (wf > 0 && hf > 0) {
            this.css.overflow = "auto";
            this.SetSize(wf, hf);
        } // If
    }
}


/* ============================================= */
/* Objeto: Screen                                */
/* --------------------------------------------- */
/* Propiedades                                   */
/*       css        --> style                    */
/*       objectType --> "screen"                 */
/*       id         --> id                       */
/*       x          --> Posición X               */
/*       y          --> Posición Y               */
/*       aw         --> Ancho                    */
/*       ah         --> Alto                     */
/*       c          --> Depth                    */
/* ============================================= */
function ScreenObj() {
    this.objectType = "screen";
    if (document.all || document.getElementById) {
        this.obj = self.screen;
        this.css = this.obj.style;
    } else {
        return false;
    } // If
  
    this.id = this.obj.id;
    this.w = this.obj.width;
    this.h = this.obj.height;
    this.aw = this.obj.availWidth;
    this.ah = this.obj.availHeight;
    this.c = this.obj.colorDepth;
}

/* ============================================= */
/* Objeto: Browser                               */
/* --------------------------------------------- */
/* Propiedades                                   */
/*       objectType --> "browser"                */
/* ============================================= */
function BrowserObj() {
  this.objectType = "browser";
}
  
/* ============================================= */
/* Objeto: Ventana                               */
/* --------------------------------------------- */
/* Propiedades                                   */
/*       objectType --> "window"                 */
/*       x          --> Posición X               */
/*       y          --> Posición Y               */
/*       ow         --> offsetWidth              */
/*       oh         --> offsetHeight             */
/*       iw         --> innerWidth               */
/*       ih         --> innerHeight              */
/* --------------------------------------------- */
/* Métodos                                       */
/*       SetValues      --> Establecer valores   */
/*       Maximize       --> Maximizar Ventana    */
/*       Center         --> Centrar              */
/* ============================================= */
function WindowObj() {
    this.objectType = "window";
  
    if (document.all) {
        this.obj = window;
    } else if (document.getElementById) {
        this.obj = window;
    } else {
        return false;
    } // If
  
    this.setValues = function() {
        if (document.all) {
            this.x = top.screenLeft;
            this.y = top.screenTop;
            this.ow = top.document.body.offsetWidth;
            this.oh = top.document.body.offsetHeight;
            this.iw = top.document.body.innerWidth;
            this.ih = top.document.body.innerHeight;
      
            this.obj.moveTo(0, 0);
            tx = top.screenLeft;
            ty = top.screenTop;
            this.x = this.x - tx;
            this.y = this.y - ty;
            this.obj.moveTo(this.x, this.y);
        } else if (document.getElementById) {
            this.x = this.obj.screenX;
            this.y = this.obj.screenY;
            this.ow = this.obj.outerWidth;
            this.oh = this.obj.outerHeight;
            this.iw = this.obj.innerWidth;
            this.ih = this.obj.innerHeight;
        } // If
    } // SetValues
  
    this.setValues();
    
    this.Maximize = function () {
        this.setValues();
        var obj_screen = new ScreenObj();
        this.x = this.y = 0;
        this.obj.moveTo(this.x, this.y);
        this.ow = obj_screen.aw;
        this.oh = obj_screen.ah;
        this.obj.resizeTo(this.ow, this.oh);
    } // Maximize
  
    this.Center = function () {
        this.setValues();
        var obj_screen = new ScreenObj();
        this.x = (obj_screen.aw - this.ow) / 2;
        this.y = (obj_screen.ah - this.oh) / 2;
        this.obj.moveTo(this.x, this.y);
    } // Center
} // Function

/* ============================================= */
/* Objeto: Enlace                                */
/* --------------------------------------------- */
/* Propiedades                                   */
/*       objectType --> "A"                      */
/*       css        --> Style                    */
/*       id         --> id                       */
/*       name       --> name                     */
/*       href       --> href                     */
/*       title      --> title                    */
/*       className  --> className                */
/*       x          --> posicion x               */
/*       y          --> posicion y               */
/*       w          --> width                    */
/*       h          --> height                   */
/* --------------------------------------------- */
/* Métodos                                       */
/*       SetHRef        --> Establecer href      */
/*       SetClass       --> Establecer clase     */
/*       SetTitle       --> Establecer title     */
/*       SetIdName      --> Establecer id        */
/* ============================================= */
function AObj(obj) {
    this.obj = obj;
    this.css = this.obj.style;
  
    this.objectType = "A";
  
    this.id = this.obj.id;
    this.name = this.obj.name;
    this.href = this.obj.href;
    this.title = this.obj.title;
    this.className = this.obj.className;
  
    // Posicion en pantalla
    if (document.all || document.getElementById) {
        yPos = this.obj.offsetTop;
        xPos = this.obj.offsetLeft;
        tempImagen = this.obj.offsetParent;
        while (tempImagen != null) {
            yPos += tempImagen.offsetTop;
            xPos += tempImagen.offsetLeft;
            tempImagen = tempImagen.offsetParent;
        } // While
        this.x = xPos;
        this.y = yPos;
        this.w = this.obj.offsetWidth;
        this.h = this.obj.offsetHeight;
    } else {
        this.x = this.obj.x;
        this.y = this.obj.y;
    } // If
  
    this.SetHRef = function (str_data) {
        if (str_data != "") this.href = this.obj.href = str_data;
    } // SetHRef
  
    this.SetClass = function (str_data) {
        if (str_data != "") this.className = this.obj.className = str_data;
    } // SetClass
    
    this.SetTitle = function (str_data) {
        if (str_data != "") this.title = this.obj.title = str_data;
    } // SetTitle
    
    this.SetIdName = function (str_data) {
        if (str_data != "") {
            this.name = this.obj.name = str_data;
            this.id = this.obj.id = str_data;
        } // If
    } // SetIdName
} // Function


/* ============================================= */
/* ============================================= */
/* FUNCIONES MENUS                               */
/* Creación de menus                             */
/* ============================================= */
/* ============================================= */
  
/* ============================================= */
/* Funcion: fnColocar(str_ImgName,str_DivName)   */
/* --------------------------------------------- */
/* Muestra el menu de un opción a partir de la   */
/* posición de la imagen. El submenu se          */
/* encuentra en la capa str_DivName              */
/* ============================================= */
function fnColocar(str_ImgName, str_DivName,despx,despy) {
    var obj_Img = new ImgObj(str_ImgName);
    var obj_Div = new DivObj(str_DivName);
    var PosiY = obj_Img.y;
    var PosiX = obj_Img.x;
    PosiX = PosiX + despx;
    PosiY = PosiY + despy;
    obj_Div.SetPosition(PosiX, PosiY);
    obj_Div.SetVisibility("On");
} // function

function CalculaDistanciaImg(str_ImgName1,str_ImgName2){
    var obj_Img1 = new ImgObj(str_ImgName1);
    var obj_Img2 = new ImgObj(str_ImgName2);
    var PosiY1 = obj_Img1.y;
    var PosiY2 = obj_Img2.y;
    var dif=parseInt(PosiY2)-parseInt(PosiY1);
    return dif;
}
/* ==================================================== */
/* Funcion: fnColocarSubMenu(str_ImgName,str_DivName)   */
/* ---------------------------------------------------- */
/* Muestra el menu de una subopción a partir de la      */
/* posición de la imagen. El submenu se encuentra en la */
/* capa str_DivName                                     */
/* ==================================================== */
function fnColocarSubMenu(str_ImgName, str_DivName, despx, despy) {
    var obj_Img = new ImgObj(str_ImgName);
    var obj_Div = new DivObj(str_DivName);
    var PosiX = obj_Img.x;
    var PosiY = obj_Img.y;
    PosiX = PosiX + despx;
    PosiY = PosiY + despy;
    obj_Div.SetPosition(PosiX, obj_Img.y);
    obj_Div.SetVisibility("On");
}

/* ==================================================== */
/* Funcion: fnQuitar(str_DivName)                       */
/* ---------------------------------------------------- */
/* Oculta la capa del submenu especificado en           */
/* str_DivName                                          */
/* ==================================================== */
function fnQuitar(str_DivName) {
    var obj_Div = new DivObj(str_DivName);
    obj_Div.SetVisibility("off");
} // function

/* ==================================================== */
/* Funcion: newSize(datoX,datoY,capa)                       */
/* ---------------------------------------------------------- */
/* Redimensiona capa                                                  */
/* ==================================================== */
function newSize(datoX,datoY,capa) {
	if(document.all && !document.getElementById) {
 		eval("document.all['"+capa+"'].style.pixelWidth = datoX");
 		eval("document.all['"+capa+"'].style.pixelHeight = datoY");
	}else{
		eval("document.getElementById('"+capa+"').style.width = datoX");
		eval("document.getElementById('"+capa+"').style.height = datoY");
	}
}

//A partir de una array, selecciona todas las opciones en un lst
// vOpciones -> Vector con las opciones a seleccionar
// nombreLst -> nombre del lst (elemento) a tratar
function seleccionaOpcionesLst(vOpciones,nombreLst){
	for (i=0;i<document.getElementById(nombreLst).options.length;i++){
		for (j=0;j<vOpciones.length;j++){			
			if (parseInt(document.getElementById(nombreLst).options[i].value,10) == parseInt(vOpciones[j],10)){				
				document.getElementById(nombreLst).options[i].selected = true
			}
		}								
	}								
}

//A partir de una array, selecciona todas las opciones en un grupo de checkbox
// vOpciones -> Vector con las opciones a seleccionar
// nombreLst -> nombre del prefijo de las check a tratar
//JSO 19/01/2006 17:36

function seleccionaOpcionesCheck(vOpciones,nombreLst){	
	for (j=0;j<vOpciones.length;j++){			
		id = parseInt(vOpciones[j],10);				
		document.getElementById(nombreLst+id).checked = true
	}										
}

//Lanza una cookie al navegador del usuario

function SetCookie (nombre, valor) {
	  var argv = SetCookie.arguments;
	  var argc = SetCookie.arguments.length;
	  var expires = (argc > 2) ? argv[2] : null;
	  var path = (argc > 3) ? argv[3] : null;
	  var domain = (argc > 4) ? argv[4] : null;
	  var secure = (argc > 5) ? argv[5] : false;
	  document.cookie = nombre + "=" + escape (valor) +
	    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	    ((path == null) ? "" : ("; path=" + path)) +
	    ((domain == null) ? "" : ("; domain=" + domain)) +
	    ((secure == true) ? "; secure" : "");
} 

function replaceSelection (input,etiqueta) { 
	// getSelection
	var selectedText;
	if(window.getSelection) {
		selectedText = window.getSelection();
	} else if (document.getSelection) {
		selectedText = document.getSelection();
	} else if(document.selection) {
		selectedText = document.selection.createRange().text;
	}

	var replaceString = "<"+etiqueta+">" + selectedText + "</"+etiqueta+">";

	if (input.setSelectionRange) {
		var selectionStart = input.selectionStart;
		var selectionEnd = input.selectionEnd;
		input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd);
		if (selectionStart != selectionEnd) // has there been a selection
			setSelectionRange(input, selectionStart, selectionStart + replaceString.length);
		else // set caret
			setCaretToPos(input, selectionStart + replaceString.length);
	} else if (document.selection) {
		var range = document.selection.createRange();
		if (range.parentElement() == input){ 
			var isCollapsed = range.text == '';
			range.text = replaceString;
			if (!isCollapsed) {
				// it appears range.select() should select the newly 
				// inserted text but that fails with IE
				range.moveStart('character', - replaceString.length);
				range.select();
			}
		}
	}
}

//muestra una capa
function showLayer(idLayer){
	document.getElementById(idLayer).style.display = 'inline'
}
//oculta una capa
function hideLayer(idLayer){
	document.getElementById(idLayer).style.display = 'none'
}	

// trim() de cadena
function trim(cadena)
{
	if (cadena) {
		// alert(cadena);
		for(i=0; i<cadena.length; )
		{
			if(cadena.charAt(i)==" ")
				cadena=cadena.substring(i+1, cadena.length);
			else
				break;
		}
		for(i=cadena.length-1; i>=0; i=cadena.length-1)
		{
			if(cadena.charAt(i)==" ")
				cadena=cadena.substring(0,i);
			else
				break;
		}
	}
	return cadena;
}

/* Función que dada una cadena no comprueba si es válida o no*/
function validarCorreo (emailStr) {
/* Patrón que deben seguir las direcciones de correo */
var emailPat=/^(.+)@(.+)$/
/* Carácteres especiales que no queremos en la dirección */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* carácteres válidos en la dirección */
var validChars="\[^\\s" + specialChars + "\]"
/* Adoptamos medidas para las cuentas con comillas: 
Ej. "jiminy cricket"@disney.com es una dirección legal */
var quotedUser="(\"[^\"]*\")"
/* Dominios como dirección ip. Ej. joe@[123.124.233.4] .
NOTA: los corchetes son obligatorios */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* un átomo es una serie de carácteres no especiales. */
var atom=validChars + '+'
/* Con la definición anterior montamos las palabras. Un usuario será un átomo
o un nombre entre comillas */
var word="(" + atom + "|" + quotedUser + ")"
// En definitiva, este es e lpatron para los usuarios válidos
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* Patrón de un dominio "simbólico" */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

/* Comprobamos si la cuenta existe realmente */

var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
	/*alert("El mail es incorrecto")*/
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null) {
    /*alert("El nombre de usuario parece no ser correcto.")*/
    return false
}

var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        /*alert("Direccion IP no valida!")*/
		return false
	    }
    }
    return true
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
	/*alert("El nombre de dominio parece no ser correcto.")*/
    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) {
   // La dirección debe terminar en un dominio válido
   /*alert("La direccion de correo debe acabar en 3 letras de dominio o 2 de un pais.")*/
   return false
}

if (len<2) {
   var errStr="Esta direccion es desconocida como IP!"
   /*alert(errStr)*/
   return false
}

return true
}

function replaceSelection2 (input,etiqueta) { 
	// getSelection
	var selectedText;
	if(window.getSelection) {
		selectedText = window.getSelection();
	} else if (document.getSelection) {
		selectedText = document.getSelection();
	} else if(document.selection) {
		selectedText = document.selection.createRange().text;
	}
		
		if(etiqueta == "a"){
			var replaceString = "<"+etiqueta+" href=\"http://" + selectedText + "\" target=\"blank\">" + selectedText + "</"+etiqueta+">";
		} else if(etiqueta == "m"){
			var replaceString = "<a href=\"mailto:" + selectedText + "\">" + selectedText + "</a>";
		} else {
			var replaceString = "<"+etiqueta+">" + selectedText + "</"+etiqueta+">";
		}
		
	if (input.setSelectionRange) {
		var selectionStart = input.selectionStart;
		var selectionEnd = input.selectionEnd;
		input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd);
		if (selectionStart != selectionEnd) // has there been a selection
			setSelectionRange(input, selectionStart, selectionStart + replaceString.length);
		else // set caret
			setCaretToPos(input, selectionStart + replaceString.length);
	} else if (document.selection) {
		var range = document.selection.createRange();
		if (range.parentElement() == input){ 
			var isCollapsed = range.text == '';
			range.text = replaceString;
			if (!isCollapsed) {
				// it appears range.select() should select the newly 
				// inserted text but that fails with IE
				range.moveStart('character', - replaceString.length);
				range.select();
			}
		}
	}
}
