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("GET",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);
				ajustarCesta();
			}
		} 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 ajustarCesta() {
	if(document.getElementById("prod_cesta")) {
		var cestaHeight = displayresol();
		//document.getElementById("prod_cesta").style.height = cestaHeight-305+'px';
	}
}

function cartadd(ref,modo) {
	var newurl = 'cartadd.asp?ref='+ref+'&modo='+modo;
	loadUrl(newurl,'cart');
}

function cartdel(ref,ped) {
	var newurl = 'cartdel.asp?ref='+ref+'&ped='+ped;
	loadUrl(newurl,'cart');
}

function ver_prod(id) {
	var newurl = 'ver_producto.asp?IDart='+id;
	loadUrl(newurl,'contenido_ventana_producto');
	abrir_vent_prod();
}

function ver_receta(idrec,idart) {
	var newurl = 'ver_receta.asp?IDrec='+idrec+'&IDart='+idart;
	loadUrl(newurl,'contenido_ventana_producto');
	abrir_vent_prod();
}

function ver_lugarc(imagen) {
	var newurl = 'ver_imagen.asp?img='+imagen;
	loadUrl(newurl,'contenido_ventana_producto');
	abrir_vent_prod();
}

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 highlight(event) {
	/*this.style.backgroundColor='#DEE9FF';*/
	this.style.borderBottomColor='#C0C0C0';
	//this.style.letterSpacing='2px';
	//this.style.paddingLeft='10px';
	//this.style.listStyleType='square';
	this.style.listStyleImage='url(img/ok2.gif)';
	//this.style.paddingTop='0px';
	//this.style.paddingBottom='6px';
	//this.style.textAlign='right';
	this.style.cursor='pointer';
}

function normal(event) {
	/*this.style.backgroundColor='#F3F3F3';*/
	this.style.borderBottomColor='#094EA3';
	//this.style.letterSpacing='1px';
	//this.style.paddingLeft='5px';
	//this.style.listStyleType='none';
	this.style.listStyleImage='none';
	//this.style.paddingTop='4px';
	//this.style.paddingBottom='2px';
	this.style.cursor='auto';
}

function redir(event) {
	document.location.href = this.firstChild.href;
}

function menu() {
	var z = document.getElementById("menuitems").getElementsByTagName("li").length;
	for (var i=1; i<=z; i++ ) {
		document.getElementById('menu'+i).onmouseover = highlight;
		document.getElementById('menu'+i).onmouseout  = normal;
		document.getElementById('menu'+i).onclick = redir;
	}
}

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;
}

function displaymenu(id) {
	//var x = document.getElementById("menuitems").getElementsByTagName("p").length;
	//for (var i=1; i<=x; i++) {
	//	document.getElementById("p"+i).style.borderTop='1px solid #FFFFFF';
	//	document.getElementById("p"+i).style.borderBottom='1px solid #FFFFFF';
	//}
	var z = document.getElementById("menuitems").getElementsByTagName("ul").length;
	for (var i=1; i<z; i++) {
		if(id!=i) {
			/*document.getElementById("p"+i).style.backgroundColor = '#FFFFFF';*/
			document.getElementById("p"+i).style.borderTop='1px solid #FFFFFF';
			document.getElementById("p"+i).style.backgroundColor='#FFFFFF';
			document.getElementById("p"+i).style.borderBottom='1px solid #FFFFFF';
			document.getElementById("m"+i).style.display = 'none';
		}
	}
	if(document.getElementById("m"+id).style.display=='block') {
		document.getElementById("p"+id).style.borderTop='1px solid #FFFFFF';
		document.getElementById("p"+id).style.borderBottom='1px solid #FFFFFF';
		document.getElementById("m"+id).style.display='none';
	} else {
		document.getElementById("p"+id).style.borderTop='1px solid #D9001D';
		document.getElementById("p"+id).style.backgroundColor='#FFCC99';
		document.getElementById("p"+id).style.borderBottom='1px solid #D9001D';
		//document.getElementById("p"+id).style.borderBottom='1px solid #D9001D';
		/*document.getElementById("p"+id).style.backgroundColor = '#FDD979';*/
		//document.getElementById("p"+id).color = '#FFFFFF';
		//document.getElementById("m"+id).style.borderBottom='1px solid #D9001D';
		document.getElementById("m"+id).style.display= 'block';
	}
}

function abrir_vent_prod() {
	var posleft = getBrowserWidth()/2-320;
	document.getElementById("ventana_producto").style.left = posleft+'px';
	//document.getElementById("contenido_ventana_producto").style.left = posleft+'px';
	document.getElementById("ventana_producto").style.display= 'block';
	document.getElementById("contenido_ventana_producto").style.display= 'block';

}

function cerrar_vent_prod() {
	document.getElementById("ventana_producto").style.display= 'none';
	document.getElementById("contenido_ventana_producto").style.display= 'none';
	document.getElementById("contenido_ventana_producto").innerHTML='';
}

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 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 displayresol() {
	var theHeight = getBrowserHeight();
	return theHeight;
}

function godoc(doc) {
	document.location.href = doc;
}

function EsDecimal(inputVal,inputNm) {
	oneDecimal=false;
	inputStr=""+inputVal;
	for (var i=0; i<inputStr.length; i++) {
		var oneChar=inputStr.charAt(i)
		if (i==0 && oneChar=="-") {
			continue;
		}
		if (oneChar=="," && !oneDecimal) {
			oneDecimal=true;
			continue;
		}
		if (oneChar<"0" || oneChar>"9") {
			//alert("Tiene que introducir un valor numérico. Para números decimales utilice la coma (,)");
			document.getElementById(inputNm).focus();
			return false;
		}
	}
	return true;
}

function EsEntero(inputVal,inputNm) {
	inputStr=""+inputVal;
	for (var i=0; i<inputStr.length; i++) {
		var oneChar=inputStr.charAt(i)
		if (i==0 && oneChar=="-") {
			continue;
		}
		if (oneChar<"0" || oneChar>"9") {
			//alert("Tiene que introducir un valor numérico. Para números decimales utilice la coma (,)");
			document.getElementById(inputNm).focus();
			return false;
		}
	}
	return true;
}

function showEnvio() {
	document.getElementById("dtotales").style.display='none';
	document.getElementById("dgenvio").style.display='block';
}

function showCesta() {
	cartadd(0,0);
	document.getElementById("dtotales").style.display='block';
	document.getElementById("dgenvio").style.display='none';
}

function calcEnvio() {
	var cpvalue = document.getElementById("cestacp").value;
	var newurl = 'calcenvio.asp?cp='+cpvalue;
	loadUrl(newurl,'dgenvio');
}

function ver_menus_catering(id) {
	var newurl = 'menues.asp?id='+id;
	loadUrl(newurl,'contenido_ventana_producto');
	abrir_vent_prod();
}

function limpiacontrol(campo,dato1,dato2) {
	if(dato1==dato2) {
		document.getElementById(campo).value = '';
	}
}

function buscarapida() {
	ff = document.getElementById("busqueda");
	if(ff.value=="" || ff.value=="búsqueda rápida") {
		alert("Debe introducir un texto. Por ejemplo: filetes");
		ff.focus();
	} else {
		document.brapida.submit();
	}
}

var mClientes = 'clientes' + '@' + 'sertina.es';
var linkContacto = '<a href="' + 'mailto:' + mClientes + '">' + mClientes + '</a>';

//window.onload = menu;

