// ------------------------------------------
// Detectar idioma
// ------------------------------------------
function langCheck() {
	if(langPHPSession!=undefined)
	{
		switch(langPHPSession)
		{
			case "ca":
				this.lang = "ca";
				this.folderLang = "/ca/";
			break;
			case "es":
				this.lang = "es";
				this.folderLang = "/es/";
			break;
			case "en":
				this.lang = "en";
				this.folderLang = "/en/";
			break;
			default:
				this.lang = "ca";
				this.folderLang = "/ca/";
			break;
		}
	}
	else
	{
		var locationActual = location.href;
		if(locationActual.indexOf("/es") != -1){
			this.lang = "es";
			this.folderLang = "/es/";
		} else if(locationActual.indexOf("/en") != -1){
			this.lang = "en";
			this.folderLang = "/en/";
		} else {
			this.lang = "ca";
			this.folderLang = "/";
		}
	}
}
lang = new langCheck();
// ------------------------------------------
// Carga de imágenes para el menú
// ------------------------------------------
for (i=1; i<=9; i++){
	eval("menuOut"+i+" = new Image()");
	eval("menuOut"+i+".src = \"/images/common/menu_item_off_00" + i + "_" + lang.lang + ".gif\"");
	eval("menuOver"+i+" = new Image()");
	eval("menuOver"+i+".src = \"/images/common/menu_item_on_00" + i + "_" + lang.lang + ".gif\"");
}

for (i=10; i<=11; i++){
	eval("menuOut"+i+" = new Image()");
	eval("menuOut"+i+".src = \"/images/common/menu_item_off_0" + i + "_" + lang.lang + ".gif\"");
	eval("menuOver"+i+" = new Image()");
	eval("menuOver"+i+".src = \"/images/common/menu_item_on_0" + i + "_" + lang.lang + ".gif\"");
}

// ------------------------------------------
// Para Carger el plato grande de cátering
// ------------------------------------------
function cambiarPlatoGrande(args1, args2){
	if (document.all) {
		if(lang.lang == "ca")
		{
			window.document.catering002.SetVariable("_root.plato", args1);
			window.document.catering002.SetVariable("_root.nombre", args2);
			window.document.catering002.TCallLabel("/", "startPlato");
		}
		else if(lang.lang == "es")
		{
			window.document.catering002_es.SetVariable("_root.plato", args1);
			window.document.catering002_es.SetVariable("_root.nombre", args2);
			window.document.catering002_es.TCallLabel("/", "startPlato");
		}
		else if(lang.lang == "en")
		{
			window.document.catering002_en.SetVariable("_root.plato", args1);
			window.document.catering002_en.SetVariable("_root.nombre", args2);
			window.document.catering002_en.TCallLabel("/", "startPlato");
		}
	}
	else
	{
		window.document.embeds[1].SetVariable("_root.plato", args1);
		window.document.embeds[1].SetVariable("_root.nombre", args2);
		window.document.embeds[1].TCallLabel("/", "startPlato");
	}
}
// ------------------------------------------
// Chequear los valores de búsqueda
// ------------------------------------------
function checkSearch()
{
		if(document.frmsearch.keyword.value =="")
		{
			alert("Please Enter Search Text");
			document.frmsearch.keyword.focus();
			return false;
		}
}
// ------------------------------------------
// Revisar la fecha de búsqueda de las recetas
// ------------------------------------------

function CampoVacio(campo){
	longit = campo.length;
	if(longit == 0){return true;}
	else{return false;}
}

function revisarFechasDeBusqueda(_f_){
	
	var returnResult = true;
	_form_ = eval(_f_)
	
	dia = _form_.vDay.value;
	mes = _form_.vMonth.value;
	anio = _form_.vYear.value;
	
	if((CampoVacio(dia)) || (CampoVacio(mes)) || (CampoVacio(anio)) || (anio.length != 4))
	{
		alert("La fecha introducida no es correcta");
		returnResult = false;
	}
	else
	{
		if(anio >= 2004){
			
			if(mes>=1 && mes<=12){
				
				if(mes == 1){
					if(dia<1 || dia>31){
						returnResult = false;
					}
				}
				
				if(mes == 2){
					if ((anio%4)==0){
						if(dia<1 || dia>29){
							returnResult = false;
						}
					} else {
						if(dia<1 || dia>28){
							returnResult = false;
						}
					} 
				}
				
				if(mes==3){
					if(dia<1 || dia>31){
						returnResult = false;
					}
				}
				
				if(mes==4){
					if(dia<1 || dia>30){
						returnResult = false;
					}
				}
				
				if(mes==5){
					if(dia<1 || dia>31){
						returnResult = false;
					}
				}
				
				if(mes==6){
					if(dia<1 || dia>30){
						returnResult = false;
					}
				}
				
				if(mes==7){
					if(dia<1 || dia>31){
						returnResult = false;
					}
				}
				
				if(mes==8){
					if(dia<1 || dia>31){
						returnResult = false;
					}
				}
				
				if(mes==9){
					if(dia<1 || dia>30){
						returnResult = false;
					}
				}
				
				if(mes==10){
					if(dia<1 || dia>31){
						returnResult = false;
					}
				}
				
				if(mes==11){
					if(dia<1 || dia>30){
						returnResult = false;
					}	
				}
				
				if(mes==12){
					if(dia<1 || dia>31){
						returnResult = false;
					}
				}
			}
			else
			{
				returnResult = false;
			}
			
			if(!returnResult){alert("La fecha introducida no es correcta")};
		} else {
			alert("No existen recetas con fecha posterior al 01/01/2004");
			returnResult = false;
		}
	}
	
	
	return returnResult;
}
// ------------------------------------------
// Cambio de idioma
// ------------------------------------------
function OpenCambioDeIdioma(ThisIdioma){
	if(is.ie){
		cambioDeIdiomaWin = "document.getElementById(\"CambioDeIdiomaCapa\")";
	}else{
		cambioDeIdiomaWin = "document.CambioDeIdiomaCapa";
	}
	if(eval(cambioDeIdiomaWin)==null)
	{
		ThisLocation = document.location.toString();
		BufferImg = "/images";
		if (ThisIdioma == "ca") {
			BufferTxt1 = "Canvi d'idioma";
			BufferTxt2 = "Castellà";
			BufferTxt3 = "Anglès";			
			BufferTxt4 = "Tancar";
			BufferAction1 = "javascript: CambioDeIdioma(\'es\')";
			BufferAction2 = "javascript: CambioDeIdioma(\'en\')";
		} else if (ThisIdioma == "es") {
			BufferTxt1 = "Cambio de idioma";
			BufferTxt2 = "Catalán";
			BufferTxt3 = "Inglés";
			BufferTxt4 = "Cerrar";						
			BufferAction1 = "javascript: CambioDeIdioma(\'ca\')";
			BufferAction2 = "javascript: CambioDeIdioma(\'en\')";
		} else if (ThisIdioma == "en") {
			BufferTxt1 = "Language";
			BufferTxt2 = "Spanish";
			BufferTxt3 = "Catalan";			
			BufferTxt4 = "Close";			
			BufferAction1 = "javascript: CambioDeIdioma(\'es\')";
			BufferAction2 = "javascript: CambioDeIdioma(\'ca\')";
		}
	
		var CambioDeIdiomaTable = new Array();
			CambioDeIdiomaTable[0] = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#FFFFFF\">\
										<tr>\
											<td background=\""+BufferImg+"/common/idioma_box_001.gif\" rowspan=\"3\"><img src=\""+BufferImg+"/filer.gif\" width=\"1\" height=\"1\" border=\"0\"></td>\
											<td background=\""+BufferImg+"/common/idioma_box_001.gif\" height=\"1\"><img src=\""+BufferImg+"/filer.gif\" width=\"1\" height=\"1\" border=\"0\"></td>\
											<td background=\""+BufferImg+"/common/idioma_box_001.gif\" rowspan=\"3\"><img src=\""+BufferImg+"/filer.gif\" width=\"1\" height=\"1\" border=\"0\"></td>\
										</tr>\
										<tr>\
											<td>\
												<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"150\">";
			CambioDeIdiomaTable[1] = "<tr>\
											<td align=\"left\"><b>"+BufferTxt1+"</b></td>\
										</tr>\
										<tr>\
											<td class=\"textoNormalDestacadoViolet\">-&nbsp;<a href=\""+BufferAction1+"\" class=\"textoNormalDestacadoViolet\">"+BufferTxt2+"</a></td>\
										</tr>\
										<tr>\
											<td class=\"textoNormalDestacadoViolet\">-&nbsp;<a href=\""+BufferAction2+"\" class=\"textoNormalDestacadoViolet\">"+BufferTxt3+"</a></td>\
										</tr>\
										<tr>\
											<td align=\"right\"><a href=\"javascript:DestruirCapa(\'CambioDeIdiomaCapa\'); \"  class=\"textoNormalDestacadoViolet\">"+BufferTxt4+"</a></td>\
										</tr>";
			CambioDeIdiomaTable[2] = "</table>\
												</td>\
											</tr>\
											<tr>\
												<td background=\""+BufferImg+"/common/idioma_box_001.gif\" height=\"1\"><img src=\""+BufferImg+"/filer.gif\" width=\"150\" height=\"1\" border=\"0\"></td>\
											</tr>\
										</table>";
	
		Contenido = CambioDeIdiomaTable[0] + CambioDeIdiomaTable[1] + CambioDeIdiomaTable[2];
		
		CrearCapa('CambioDeIdiomaCapa',null,932,88,155,105,Contenido,null,'visible', '15');
		
		refreshLayers('CambioDeIdiomaCapa', '932', '88', '-293');
	}
}

function CambioDeIdioma(_l){
	var _f = document.changeLang;
	
	if(_f != null)
	{
		var newLocation = "";
		var thisLocation = document.location.toString();
		if(_l == "es" || _l == "en")
		{
			document.changeLang.redirectToIndex.value = "y";
			newLocation = "index.php";
		}
		else
		{
			if(thisLocation.indexOf(".php") > 0)
			{
				if(thisLocation.indexOf("LANG") > 0)
				{
					newLocation = thisLocation.substring(thisLocation.lastIndexOf("/")+1, thisLocation.lastIndexOf("?"))
				}
				else
				{
					newLocation = thisLocation.substr(thisLocation.lastIndexOf("/")+1)
				}
			}
			else
			{
				newLocation = "index.php"
			}
		}
		document.changeLang.action = newLocation;
		document.changeLang.vLangCode.value = _l;
		document.changeLang.submit();
	}
	else
	{
		var newLocation = "";
		var newFolderLang = "";
		var thisLocation = document.location.toString();
		var thisPage = thisLocation.substr(thisLocation.lastIndexOf("/")+1, thisLocation.length);
		switch(_l)
		{
			case "ca":
				newFolderLang = "/";
			break;
			case "es":
				newFolderLang = "/es/";
			break;
			case "en":
				newFolderLang = "/en/";
			break;
			default:
				newFolderLang = "/";
			break;
		}
		newLocation = newFolderLang + thisPage;
		location.href = newLocation;
	}
}
// ------------------------------------------
// Colocar la capa en su sitio
// ------------------------------------------
function getBrowseWidth()
{
 if (window.innerWidth) return window.innerWidth;
 else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
 else return 0;
}
function refreshLayers(_l, _x, _y, _k)
{
	var w = getBrowseWidth();
	var x = _x;
	
	if(w > 874)
	{
		newX = w/2-_k;
	}
	else
	{
		newX = _x;
	}
		
	MoverA(_l, newX, _y);
}