CAD = 1.17;
USD = 1.20;
EUR = 0.89;

var xmlHttp;

function setInnerHTML(elem, text){
	var myReference = elem
	if( myReference.adjacentHTML ) {
		myReference.adjacentHTML (text);
	  } else if( typeof( myReference.innerHTML ) != 'undefined' ) {
		myReference.innerHTML = text;
	  }
}

function getReference(elem) {
	if( document.layers ) { //Netscape layers
		return document.layers[elem]; }
	if( document.getElementById ) { //DOM; IE5, NS6, Mozilla, Opera
		return document.getElementById(elem); }
	if( document.all ) { //Proprietary DOM; IE4
		return document.all[elem]; }
	if( document[elem] ) { //Netscape alternative
		return document[elem]; }
	return false;
}

function search(frm){
	location.href = (-1 == location.href.indexOf("index.asp") && ((-1 != location.href.indexOf("index.asp") || -1 != location.href.indexOf("search.asp")))? "search.asp?" : "../search.asp?") + document.frmSearch.txtSearch.value;	
}
function $random(min, max){
	return Math.floor(Math.random() * (max - min + 1) + min);
}

function setPromo(index){
	var promos = new Array();
	promos[0] = '<a href="http://www.supermarket.treew.com"><img src="http://www.comidacuba.com/images/supermarket.gif" alt="Supermarket Treew. Sa tienda para enviar alimentos a sus familiares en Cuba" width="215" height="81" border="0" /></a>';
	promos[1] = '<a href="http://www.supermarket.treew.com/category.asp?v=&amp;categoryid=406&amp;c=M&Oacute;DULOS/Carne"><img src="http://www.comidacuba.com/images/carnicos.gif"  width="215" height="145" alt="M&oacute;dulos de Carne" border="0" /></a>';
	promos[2] = '<a href="http://www.supermarket.treew.com/category.asp?categoryid=122&amp;c=BODEGA/Bebidas/"><img src="http://www.comidacuba.com/images/bebidas.gif" alt="Bebidas" width="195" height="185" border="0" /><br /></a>';
	promos[3] = '<a href="http://www.supermarket.treew.com/category.asp?categoryid=96&amp;c=BODEGA/Alimentos/"><img src="http://www.comidacuba.com/images/enlatados.gif" alt="Alimentos" width="215" height="110" border="0" /></a>';
	promos[4] = '<a href="http://www.supermarket.treew.com/category.asp?categoryid=230"><img src="http://www.comidacuba.com/images/aceites-salsas.gif" alt="Aceites y Salsas" width="190" height="180" border="0" /></a>';
	if(null==index)index=$random(1,promos.length-1);
	document.write ('<p align="center" style="margin:0px">'+ promos[0]+'<br/>' + promos[index] + '</p>');
}
	
	function StartService(url)
	{ 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) return "Su navegador no soporta AJAX.";
		xmlHttp.onreadystatechange=stateChanged;	
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
	
	function stateChanged() 
	{ 
		if (xmlHttp.readyState==4) {
		alert(xmlHttp.responseText);
		}
	}
	
	function GetXmlHttpObject() {
		var xmlHttp=null;
		try  {
		  	// Firefox, Opera 8.0+, Safari
		  	xmlHttp=new XMLHttpRequest();
		}
		catch (e) {
		  	// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
		  	catch (e) {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		return xmlHttp;
	}

	function SendEmailToFriend(){
		if(-1 == document.frmSentEmailToFriend.cmbSentEmailToFriend.selectedIndex) {
			alert("Seleccione la receta que desea enviar.");
			return;
		}
		if(!validarEmail(document.frmSentEmailToFriend.txtSentEmailToFriend.value)){
			alert("Escriba correctamente la dirección de correo electrónico de su amigo.");
			return;
		}
		StartService("../sendRecetas.asp?email=" + document.frmSentEmailToFriend.txtSentEmailToFriend.value + "&recipeId=" + document.frmSentEmailToFriend.cmbSentEmailToFriend.value);
	}

	function Subscribe(){
		
		if(!validarEmail(document.frmSubscribe.txtSubscribe.value)){
			alert("Escriba correctamente su dirección de correo electrónico.");
			return;
		}
		StartService("http://www.comidacuba.com/subscribe.asp?email=" + document.frmSubscribe.txtSubscribe.value);
		
	}

	function validarEmail(email) {
		return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))	
	}

	function ThisUrlIsIn(url, td){
		var lnks = td.getElementsByTagName("A");
		for(lnk=0;lnk<lnks.length;lnk++){
			if(-1!=unescape(lnks[lnk].href).indexOf(url))return true;
		}
	}

	function PrepareDocument(){
		
		var url = unescape(location.href);
		var dash = 0;
		currentCategory = "";
		for(i=0;i<url.length;i++)dash=(url.substr(i,1)=="/")?i:dash;
		document.frmSentEmailToFriend.cmbSentEmailToFriend.value = url.substr(dash+1).replace(".html", "");
	
		links = getReference("menu").getElementsByTagName("A");
		tds = getReference("menu").getElementsByTagName("TD");
		/*for(td=1; td<tds.length;td++){
			if(tds[td].className == "category"){
				currentCategory = unescape(tds[td].getElementsByTagName("A")[0].href);
			}
			else if(tds[td].className == ""){
				tds[td].style.display = (ThisUrlIsIn(url.substr(dash+1), tds[td]) ||
				-1 != unescape(document.location.href).indexOf(currentCategory))?"":"none";
			}
		}*/
	}

	function round(value, digits){
		if(null == digits)digits = 2;
		var x = Math.pow(10, digits);
		return Math.round(value*x)/x
	}
	
	
