/*
 * Thanks to Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/)
 */
FlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver || 6;
	this.align = "middle";
	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	this.altTxt = "<a href='http://www.macromedia.com/go/getflashplayer'>Instalar Flash</a>.";
	this.params = new Object();
	this.variables = new Object();
	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'high');
}
FlashObject.prototype.addParam = function(name, value) {
	this.params[name] = value;
}
FlashObject.prototype.getParams = function() {
    return this.params;
}
FlashObject.prototype.getParam = function(name) {
    return this.params[name];
}
FlashObject.prototype.addVariable = function(name, value) {
	this.variables[name] = value;
}
FlashObject.prototype.getVariable = function(name) {
    return this.variables[name];
}
FlashObject.prototype.getVariables = function() {
    return this.variables;
}
FlashObject.prototype.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    if (paramTags == "") {
        paramTags = null;
    }
    return paramTags;
}
FlashObject.prototype.getHTML = function() {
    var flashHTML = "";
    if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" />';
        if (this.getParamTags() != null) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    else { // Everyone else
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs() != null) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    }
    return flashHTML;
}
FlashObject.prototype.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) {
        variablePairs.push(name + "=" + escape(this.getVariable(name)));
    }
    if (variablePairs.length > 0) {
        return variablePairs.join("&");
    }
    else {
        return null;
    }
}
FlashObject.prototype.write = function(elementId) {
	if(detectFlash(this.version) || this.doDetect=='false') {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
		if (this.redirect != "") {
			document.location.replace(this.redirect);
		}
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.altTxt;
		} else {
			document.write(this.altTxt);
		}
	}		
}
function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x){
			if (x.description) {
				var y = x.description;
	   			flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
	} else {
		result = false;
	    for(var i = 15; i >= 3 && result != true; i--){
   			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
   			flashversion = i;
   		}
	}
	return flashversion;
}
function detectFlash(ver) {	
	if (getFlashVersion() >= ver) {
		return true;
	} else {
		return false;
	}
}


startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("menunav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

function buscafocus(ele) {
	if(ele.value == "Buscar en el sitio") {
		ele.value = "";
	}
}

function buscablur(ele) {
	if(ele.value=="") {
		ele.value = "Buscar en el sitio";
	}
}

function buscago(forma) {
	if (forma.s.value=="Buscar en el sitio" || forma.s.value=="") {
		alert("Nada que buscar");
		return true;
	}
	if (!forma.s.value.match(/^([a-zA-Z0-9áéíóúñÁÉÍÓÚÑ][a-zA-Z0-9áéíóúñÁÉÍÓÚÑ ]{2,})$/i)) {
		alert("Solo puede buscarse palabras o freses simples de más de 3 caracteres.\nSin guiones, comillas, apostrofes o signos.");
		return true;
	}
	forma.submit();
	
}

function addLoad(funcion) {
	if(typeof window.onload == "function") {
    	var previousOnload = window.onload;
		window.onload = function() {
			previousOnload();
			funcion();
		}
	}else{
		window.onload = funcion;
	}
}

var totalFotos, divGal, galBotIzq, galBotDer, imgGalFoto, galTxt, galImgCont, galActual, foto;

function showGaleria() {
	if(strFotos.match(/([0-9])(,[0-9])*/) && document.getElementById) {
		foto = new Array();
		arrFotos = strFotos.split(",");
		totalFotos = arrFotos.length;
		cadEval = "";
		for(i=0;i<totalFotos;i++) {
			cadEval+= "foto[" + i + "]=new Image();";
			cadEval+= "foto[" + i + "].src='/img/" + arrFotos[i] + ".jpg';";
		}
		eval(cadEval);
		divGal = document.getElementById("galeria");
		galBotIzq = document.getElementById("galBotIzq");
		galBotDer = document.getElementById("galBotDer");
		galTxt = document.getElementById("galTxt");
		galImgCont = document.getElementById("galImgCont");
		imgGalFoto = new Image();
		galActual = 0;
		imgGalFoto.src = foto[galActual].src;
		galImgCont.appendChild(imgGalFoto);
		galBotIzq.onclick = function() {
			if(galActual>0) {
				galActual--;
				imgGalFoto.src = foto[galActual].src;
				alteraTxt();
			}
		}
		galBotDer.onclick = function() {
			if((galActual+1)<totalFotos) {
				galActual++;
				imgGalFoto.src = foto[galActual].src;
				alteraTxt();
			}
		}
		alteraTxt();
		divGal.style.display = "block";
	}
}

function alteraTxt() {
	if(galTxt) {
		galTxt.innerHTML = "Foto " + (galActual + 1) + " de " + totalFotos;
	}
}

function preparaforma() {
	forma = document.getElementById("fc");
	forma.onsubmit = function() {
		var errorfc = false;
		var errormsg = "No se puede procesar el formulario.\nSe han encontrado los siguientes errores:\n";
		var separa = "\n";
		if (forma.nombre.value=="") {
			errorfc = true;
			errormsg+= separa + "El campo Nombre no puede estar vacío";
		}
		if(forma.nombre.value!="" && !forma.nombre.value.match(/^([a-zA-ZáéíóúÁÉÍÓÚñÑ\- ]{4,})$/i)) {
			errorfc = true;
			errormsg+= separa + "El campo Nombre no tiene formato válido";
		}
		if (forma.email.value=="") {
			errorfc = true;
			errormsg+= separa + "El campo Email no puede estar vacío";
		}
		if(forma.email.value!="" && !forma.email.value.match(/^([a-zA-Z0-9\-_][a-zA-Z0-9\-_\.]+)([@])([a-zA-Z0-9][a-zA-Z0-9\-\.]+)(\.[a-zA-Z]{2,3})$/i)) {
			errorfc = true;
			errormsg+= separa + "El campo Email no tiene formato válido";
		}
		if (forma.comentarios.value=="") {
			errorfc = true;
			errormsg+= separa + "El campo Comentarios no puede estar vacío";
		}
		
		if (errorfc) {
			alert(errormsg);
			return false;
		} else {
			return true;
		}
	}
}