function botonin(mybot) {
	document.getElementById(mybot).style.cursor = 'pointer';
	document.getElementById(mybot).src = 'img/boton2.gif';
}

function botonout(mybot) {
	document.getElementById(mybot).style.cursor = 'normal';
	document.getElementById(mybot).src = 'img/boton1.gif';
}

function bin(mybot) {
	document.getElementById(mybot).style.cursor = 'pointer';
	document.getElementById(mybot).src = 'img/boton4.gif';
}

function bout(mybot) {
	document.getElementById(mybot).style.cursor = 'normal';
	document.getElementById(mybot).src = 'img/boton3.gif';
}

function cursorin(img,dest) {
	document.getElementById(img).style.display = 'block';
	document.getElementById(dest).style.display = 'block';
}

function cursorout(img,dest) {
	document.getElementById(img).style.display='none';
	document.getElementById(dest).style.display='none';
}

function godoc(strUrl) {
	document.location.href = strUrl;
}

function checkforblanks() {
	for (var i = 0; i < arguments.length; i += 2) {
		if (!arguments[i]) {
			alert("El campo  " + arguments[i+1] + " es obligatorio.");
			return false;
		}
	}
	return true;
}

/*
function sendsuscripcion() {
	var f = document.formsuscripcion;
	var dirmail = f.email.value;
	var filter = /^.+@.+\..{2,3}$/;
	var validmail;
	if (filter.test(dirmail)) {
		validmail = true;
	} else {
		validmail = false;
	}
	if (f.persona.value=="" || f.email.value=="") {
		alert("Debes proporcionarnos al menos un nombre y una dirección de correo.")
	} else {
		if(validmail==false) {
			alert("La dirección de correo indicada no es válida");
		} else {
			f.submit();
		}
	}
}

function sendcontacto() {
	var f = document.formcontacto;
	var dirmail = f.email.value;
	var filter = /^.+@.+\..{2,3}$/;
	var validmail;
	if (filter.test(dirmail)) {
		validmail = true;
	} else {
		validmail = false;
	}
	if (f.contacto.value=="" || f.email.value=="") {
		alert("Debes proporcionarnos al menos un nombre y una dirección de correo.")
	} else {
		if(validmail==false) {
			alert("La dirección de correo indicada no es válida");
		} else {
			f.submit();
		}
	}
}

function sendinteresa() {
	var f = document.forminteresa;
	if (f.que1.value=="" || f.que2.value=="") {
		alert("Debes decirnos qué ofreces y qué te interesa.")
	} else {
		if (f.contacto.value=="" || f.telefono.value=="") {
			alert("Debes proporcionarnos al menos un nombre y un número de teléfono.")
		} else {
			f.submit();
		}
		}
}
*/

function formin(myfield,len) {
	document.getElementById(myfield).style.backgroundImage = 'url(img/campo'+len+'f.gif)';
}

function formout(myfield,len) {
	document.getElementById(myfield).style.backgroundImage = 'url(img/campo'+len+'.gif)';
}

function opchat() {
	var parameters="toolbar=0,scrollbars=0,location=0,status=false,menubar=0,resizable=0,width=750,height=450,left=25,top=25";
	var url = 'chat/login.asp';
	newwindow = window.open(url,'wchat',parameters);
	newwindow.focus();
}

function catFilter() {
	document.catalogo.submit();
}

function getBrowserWidth() {
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth != 0) {
		return document.documentElement.clientWidth;
	} else if (document.body) {
		return document.body.clientWidth;
	}
	return 0;
}

function displayresol() {
	var theWidth = getBrowserWidth();
	//var theWidth = screen.width;
	if (theWidth<1020) {
		document.getElementById("tagstyle").href = "_estilos800.css";
	//} else {
	//	if (theWidth>1024) {
	//		document.getElementById("tagstyle2").href = "_estilos1026.css";
	//	}
	}
}

function getBrowserHeight() {
	if (window.innerHeight) {
		return window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight != 0) {
		return document.documentElement.clientHeight;
	} else if (document.body) {
		return document.body.clientHeight;
	}
	return 0;
}

function displayh() {
	var theHeight = getBrowserHeight();
	newh = theHeight-10+'px';
	document.getElementById("contenido").style.height = newh;
	//alert(theHeight+" ("+newh+")");
}

function sp(npag) {
	document.form_catalogo.pag.value = npag;
	document.form_catalogo.submit();
}

function spord(ord) {
	document.form_catalogo.orden.value = ord;
	document.form_catalogo.submit();
}

var ajaxurl="";
var ajaxtarget = "";

/*function loadUrl(strurl,strdest) {
	ajaxurl = strurl;
	ajaxtarget = strdest;
	if (window.XMLHttpRequest) { // code for Mozilla, etc.
		xmlhttp=new XMLHttpRequest();
		xmlhttp.onreadystatechange=xmlhttpChange;
		xmlhttp.open("POST",ajaxurl,true);
		xmlhttp.send(null);
	}
	else if (window.ActiveXObject) { // code for IE
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) {
			xmlhttp.onreadystatechange=xmlhttpChange;
			xmlhttp.open("POST",ajaxurl,true);
			xmlhttp.send();
		}
	}
}

function xmlhttpChange() {
	var nuevoTexto = "";
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {
			if (xmlhttp.responseText!="") {
				nuevoTexto = xmlhttp.responseText;
				document.getElementById(ajaxtarget).innerHTML = nuevoTexto;
			}
		} else {
			alert("Ha ocurrido un error al intentar recuperar los datos.");
		}
	}
}
*/



function URLEncode(strEncode) {
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = strEncode;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
	return false;
}


function URLDecode(strDecode) {
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = strDecode;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
   return false;
}

function loadUrl(strurl,strdest) {
	ajaxurl = strurl;
	ajaxtarget = strdest;
	if (window.XMLHttpRequest) { // code for Mozilla, etc.
		xmlhttp=new XMLHttpRequest();
		xmlhttp.onreadystatechange=xmlhttpChange;
		xmlhttp.open("GET",ajaxurl,true);
		xmlhttp.send(null);
	}
	else if (window.ActiveXObject) { // code for IE
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) {
			xmlhttp.onreadystatechange=xmlhttpChange;
			xmlhttp.open("POST",ajaxurl,true);
			xmlhttp.send();
		}
	}
}

function xmlhttpChange() {
	var nuevoTexto = "";
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {
			if (xmlhttp.responseText!="") {
				nuevoTexto = xmlhttp.responseText;
				document.getElementById(ajaxtarget).innerHTML = URLDecode(nuevoTexto);
			}
		} else {
			alert("Ha ocurrido un error al intentar recuperar los datos.");
		}
	}
}

function buscaproductos() {
		document.buscador.submit();
}

function findempresa(data,param1) {
	var newtarget = param1;
	var newurl = "busca_empresa1.asp?prod="+data;
//	loadUrl(newurl,newtarget);
	loadUrl(newurl,'empresas');
}

function findempresa2(data,param1) {
	var newtarget = param1;
	var newurl = "busca_empresa2.asp?prov="+data;
	loadUrl(newurl,newtarget);
}

function findferia(data1,data2,param) {
	var newtarget = param;
	var newurl = "xpferias4.asp?year="+data1+"&lang="+data2;
	loadUrl(newurl,newtarget);
}

function findempresamapa (data,param1) {
	document.getElementById("provincia").value = data;
	findempresa2(data,param1);
	//var newtarget = param1;
	//var newurl = "busca_empresa2.asp?prov="+data;
	//loadUrl(newurl,newtarget);		
}


function navbuscador(pag) {
	if(document.buscador.query.value=="") {
		alert("debe introducir un texto de búsqueda");
	} else {
		if(pag==0) {
			document.buscador.action = "buscador1.asp";
		} else {
			document.buscador.pag.value = pag;
			document.buscador.action = "buscador2.asp";
		}
		document.buscador.submit();
	}
}

function displaymenu(id) {
	var z = document.getElementById("admenu").getElementsByTagName("li").length;
	if(document.getElementById("m"+id)) {
		if(document.getElementById("m"+id).style.display=='block') {
			document.getElementById("m"+id).style.borderTop = '1px solid #003399';
			document.getElementById("m"+id).style.display = 'none';
			//document.getElementById("p"+id).style.borderBottom = '1px solid #003399';
		} else {
			document.getElementById("m"+id).style.borderTop = '2px solid #ffcc00';
			document.getElementById("m"+id).style.display = 'block';
			//document.getElementById("p"+id).style.borderBottom = '1px solid #ffcc00';
		}
		for (var i=1; i<z; i++) {
			if(document.getElementById("m"+i)) {
				if(id!=i) {
					document.getElementById("m"+i).style.borderTop = '1px solid #003399';
					document.getElementById("m"+i).style.display = 'none';
					//document.getElementById("p"+i).style.borderBottom = '1px solid #003399';
				}
			}
		}
	}
}

function displaymarconormas(id) {
	if (id==0){ 
		var z = document.getElementById("all_normas").getElementsByTagName("div").length;
		for (var i=1; i<=z; i++ ) {
			document.getElementById('marco'+i).style.display='block';
		}
	} else {		
		document.getElementById("marco"+id).style.display='block';
		var z = document.getElementById("all_normas").getElementsByTagName("div").length;
		for (var i=1; i<=z; i++ ) {
			if (i!=id){
				document.getElementById('marco'+i).style.display='none';
			}
		}
	}
}

function right(str,q) {
	var strRight = '';
	var n;
	if(q>str.length) {
		n=0;
	} else {
		n=str.length-q;
	}
	for (var s=n; s<str.length; s++) {
		strRight=strRight+str.charAt(s);
	}
	return strRight;
}

function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}


function afnDisplay(id) {
	var arts = document.getElementById('afncontenido').getElementsByTagName('div');
	var tabs = getElementsByClass('navegador');
	if(id==0 || id=="") {
		for (var i=1;i<arts.length+1;i++) { 
			document.getElementById('afn'+i).style.display='block';
		}
		for(i=0; i<tabs.length; i++) {
			tabs[i].style.display = 'none';
		}
	} else {
		for(i=0; i<tabs.length; i++) {
			tabs[i].style.display = 'block';
		}
		for (var i=1;i<arts.length+1;i++) { 
			document.getElementById('afn'+i).style.display='none';
		}
		document.getElementById('afn'+id).style.display='block';
	}
	//document.location.hash = "container";
	scroll(0,0);
}

function mostrarEmp(id) {
	if(document.getElementById("ficha_"+id).style.display == 'block') {
		document.getElementById("ficha_"+id).style.display = 'none';
	} else {
		document.getElementById("ficha_"+id).style.display = 'block';
	}
}

function CreateControlFlash(divid, objectid, width, height, url, mode) {
	var d = document.getElementById(divid);
	var strHTML = '<object id="' + objectid + '" type="application/x-shockwave-flash" data="' + url + '" width="' + width + '" height="' + height + '">';
	strHTML = strHTML + '<param name="movie" value="' + url + '" />';
	if(mode=='1') { strHTML = strHTML + '<param name="wmode" value="transparent" />'; }
	strHTML = strHTML + '<a href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;Lang=Spanish&amp;P5_Language=Spanish"><img src="flash/noflash.gif" border="0" alt="no tiene flash" /></a>';
	strHTML = strHTML + '</object>';
	d.innerHTML = strHTML;
}

//displayresol();