// JavaScript Document

// REFORMAS EN LA CLASE STRING

String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g, '');
};

String.prototype.noSpecialChars = function() {
	var patron = /^\w+$/;
	return patron.test(this);
};

String.prototype.isNumber = function() {
	var patron = /^[0-9]+$/;
	return patron.test(this);
};

// --- FIN REFORMAS


function getObj(n, d) { //v4.01
	var p,i,x;  
	if (!d) d=document; 
	if ((p=n.indexOf("?")) > 0 && parent.frames.length) {
	d = parent.frames[n.substring(p+1)].document; 
	n = n.substring(0,p);
	}
	if (!(x = d[n]) && d.all) x = d.all[n]; 
	for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	for (i = 0; !x && d.layers && i < d.layers.length; i++) x = getObj(n, d.layers[i].document);
	if (!x && d.getElementById) x = d.getElementById(n); 
	return x;
}

var enabledClose = true;

function sesOut() {
	var sx = "";
	if (enabledClose) {
		document.location = removeId(document.location.toString());
		enabledClose = false;
	}
}

function removeId(st) { 
	var stt = "?id=";
	pos_ = st.indexOf(stt);
	return st.substr(0, pos_);
}

function irA(u) {
	document.location = u;
}

function redirige(ruta) {
	if (ruta != "no" )	{
		document.location = ruta;
	}
}

//FUNCIONES PARA SWAP DE IMÁGENES

function precargaImgsInfo (lst, arr) {
//lst es array de las fotografías con ruta
//arr es un array vacío
//devuelve el total de las fotografías cargadas
	tot = lst.length;
	for (i= 0; i < tot; i++) {
/*		archImg = rutaBase + nomBase;
		if (i < 10) archImg = archImg + '0';
		archImg = archImg + i + '.jpg'; 
		arrImgs[i] = new Image;	
		arrImgs[i].src = archImg; */
		arr[i] = new Image;	
		arr[i].src = lst[i]; 
//trace ('[imgs.js:precargaImgs()]Nombre del archivo imagen: [' + archImg + ']');
	}
	return tot;
}

function putNextImgInfo(objImg, arr, act, tot) {
//arr es el array de las fotografías precargadas
//objImg es el objeto HTML imagen donde se mostrará la imagen
//devuelve la posición nueva
	act = (act + 1) % tot;
	objImg.src = arr[act].src;
	return act;
}

function printPosIndex(objTxt, act, tot){
	//actv = act + 1;
	objTxt.innerHTML = "&nbsp;[" + act + "/" + tot + "]";
}

///////////////////////////////////////////
// CAMBIO IMGS "OVER"
// Cada página carga su array de imágenes 
///////////////////////////////////////////

function ClassObjImgSwap (r, ov, ou) {
	
	//ruta = ""; // Terminará en barra inclinada '/'
	this.imgOver = new Image(); this.imgOver.src = r + ov;
	this.imgOut = new Image(); this.imgOut.src = r + ou;
	this.state = 0; //0 - Out loaded ; 1 - Over loaded
}

var imgsSwap = null; //Array de objs oImgSwap

//VERSION DE LA FUNCION PRIVADA
function swapImagen (id, oImgHtm) {
//Id es el indice de la imagen a tratar en su correspondiente array	
//oImgHtm es el objeto IMG html

	if (imgsSwap && imgsSwap[id] && oImgHtm) {
		if (imgsSwap[id].state == 0) {
			oImgHtm.src = imgsSwap[id].imgOver.src;
			imgsSwap[id].state = 1;
			
		} else {
			oImgHtm.src = imgsSwap[id].imgOut.src
			imgsSwap[id].state = 0;
		}		
	}
}

function sw (iid, idImg) {
	oI = getObj (idImg);
	if (oI) {
		swapImagen (iid, oI);
	}
}


///////////////////////////////////////////
// INTERACCIÓN CON FLASH
///////////////////////////////////////////


function getFlashObj(idFlash) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
		 return window[idFlash];
	 } else {
		 return document[idFlash];
	 }
}
 
function testJsComm() {
	return true;
}

function stopFlashMusic(fName) {
	//alert("Orden Flash!");
	if (!fName) {
		fName = "mp3_player_v01";
	}
	var flashMovie = getFlashObj(fName);
	//alert("Flash Movie" + flashMovie);
	flashMovie.stopFlashMusic();	
}
 
function playFlashMusic(fName) {
	//alert("Orden Flash!");
	if (!fName) {
		fName = "mp3_player_v01";
	}
	var flashMovie = getFlashObj(fName);
	//alert("Flash Movie" + flashMovie);
	//flashMovie.playFlashMusic();	
}

 function stopFlashVideo(fName) {
	//alert("Orden Flash!");
	if (!fName) {
		fName = "FlashID2";
	}
	var flashMovie = getFlashObj(fName);
	//alert("Flash Movie" + flashMovie);
	flashMovie.stopFlashVideo();	
}
 
function playFlashVideo(fName) {
	//alert("Orden Flash!");
	if (!fName) {
		fName = "FlashID2";
	}
	var flashMovie = getFlashObj(fName);
	//alert("Flash Movie" + flashMovie);
	flashMovie.playFlashVideo();	
}
 
 
 
 
 
 
