var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;


loaded=false;
var isInternetExplorer = (document.all) ? true : false;

function init() {
	try {
	menuArray=new Array();
	for (var i=0;i<5;i++) { //nav menus
		menuArray[i] = document.getElementById("navDrop"+i); 
		cleanWhiteSpace(menuArray[i]);
		var n = menuArray[i].childNodes[1];//menu 
		if (i==4) break;
		for (j=0;j<n.childNodes.length;j++) { 
			n.childNodes[j].className ="navMenuItemOff";  
			n.childNodes[j].childNodes[0].className ="navMenuItemLinkOff";  
			n.childNodes[j].makeRollObj = makeRollObj;
            n.childNodes[j].makeRollObj(n.childNodes[j]); 
		} 
	} 
	
	var imgArray = new Array('nav_view_cart','nav_checkout','btn_search');
	imgRollArray = new Array();
	for (var i=0;i<imgArray.length;i++){
		imgRollArray[i] = new Array();
		imgRollArray[i][0] = new Image();
		imgRollArray[i][0].src = "/emas/scripts/" + imgArray[i] + ".png";
		imgRollArray[i][1] = new Image();
		imgRollArray[i][1].src = "/emas/scripts/" + imgArray[i] + "_on.png";
		imgRollArray[i][2] = new Image();
		imgRollArray[i][2].src = "/emas/scripts/" + imgArray[i] + ".png";
		imgRollArray[i][3] = new Image();
		imgRollArray[i][3].src = "/emas/scripts/" + imgArray[i] + "_on.png";	
	} 
	
	loaded=true; 
	} catch(e) {
		loaded=false;
	}
} 

function makeRollObj(s) {
	this.onmouseover = function(){
		this.className = "navMenuItemOn"; 
		this.childNodes[0].className = "navMenuItemLinkOn";
	}
	this.onmouseout = function(){
		this.className = "navMenuItemOff";
		this.childNodes[0].className = "navMenuItemLinkOff";
	}
} 

function showMenu(mn,st){
	if (loaded) { 
		if (st==1) {
			for (var i=0;i<menuArray.length;i++) {
				menuArray[i].style.visibility  = "hidden";
			}
			if(isInternetExplorer) {
				hideObjects();
			}
		} else {
			if(isInternetExplorer) {
				showObjects();
			}
		}
		menuArray[mn].style.visibility  = (st==1) ? "visible" : "hidden";
	}
}  


function showRoll(s,w,st){
	if (loaded) {  
		s.src = imgRollArray[w][st].src;
	}
}  



function showAlphaItems(n) {
	var az = document.getElementById("alphaNumeric");
	cleanWhiteSpace(az);
	for (var i=0;i<az.childNodes.length;i++) {
		try {
			az.childNodes[i+1].style.border = "none";			
			document.getElementById("alpha"+i).style.visibility = "hidden";
		} catch(e) {}
	}
	 
	if (isInternetExplorer) {
		document.getElementById("allBrands").style.height = document.getElementById("alpha"+n).clientHeight;
	} else {
		document.getElementById("firefoxBug").innerHTML = '<p><img src="/images/spacer.gif" width=1 height='+document.getElementById("alpha"+n).clientHeight+'></p>';	
	}
	
	document.getElementById("alpha"+n).style.visibility = "visible";
	az.childNodes[(n+1)].style.border = "2px solid #CCCCCC";
	az.childNodes[(n+1)].style.borderBottom = "3px solid #ffffff";	
}

function showTab(n) {
	var tabs = document.getElementById("tabMenu");
	cleanWhiteSpace(tabs);
	for (var i=0;i<tabs.childNodes.length;i++) {
		try {
			tabs.childNodes[i].childNodes[0].src = replace(tabs.childNodes[i].childNodes[0].src,'_on.png','.png');
			document.getElementById("tab"+i).style.visibility = "hidden";
		} catch(e) {}
	}
	if (isInternetExplorer) {
		document.getElementById("allTabs").style.height = document.getElementById("tab"+n).clientHeight;
	} else {
		document.getElementById("firefoxBug").innerHTML = '<p><img src="img/spacer.gif" width=1 height='+document.getElementById("tab"+n).clientHeight+'></p>';	
	}	
	document.getElementById("tab"+n).style.visibility = "visible";
	tabs.childNodes[n].childNodes[0].src = replace(tabs.childNodes[n].childNodes[0].src,'.png','_on.png');
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}
function cleanWhiteSpace(node) {  
	var notWhiteSpace = /\S/;
	
	for (var x = 0; x < node.childNodes.length; x++) {
		var childNode = node.childNodes[x]
		if ((childNode.nodeType==3)&&(!notWhiteSpace.test(childNode.nodeValue))) { //whitespace text node
			node.removeChild(node.childNodes[x]);
			x--;
	    }
		if (childNode.nodeType == 1) {// elements can have text child nodes of their own
			cleanWhiteSpace(childNode);
	    }
	} 
}

function hideObjects()
{
     var selCount = document.all.tags("select");
     for (i=0; i<selCount.length; i++)
          selCount[i].style.visibility = "hidden";

}

function showObjects() {
 selCount=document.all.tags("select")
     for (i=0;i<selCount.length;i++)
          selCount[i].style.visibility="visible"
}

if (window.attachEvent) {  
	window.attachEvent("onload",init);
} else {   
	window.addEventListener("load",init,false);
}


//This function handles the onkeypress event.
//It prevents form submission when ENTER is hit
function handleKeystroke(e){
    var keyPressed;

    //Browser compatibility check
    if (document.all) {
        //Browser used: Internet Explorer 6
        keyPressed = e.keyCode;
    } else  {
        //Browser used: Firefox
        keyPressed = e.which;
    }
    
    var enterKey;
    //13 = ASCII code for Enter key
    if (keyPressed == 13) { 
       enterKey = false;
    } else {
        enterKey = true;
    }
    
    return enterKey;
}

function writeText(txt,id)
{
document.getElementById(id).innerHTML=txt;
}

function carga(est)
{
	var sitio1,sitio2,sitio3,sitio4,sitio5,sitio6;
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
    var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
    }
	if(isIE==true){
		if(ieversion>=7){
			var img=document.formEMAS.imagen.selectedIndex;
    		var prd=document.formEMAS.periodo.selectedIndex;
    		var vrb=document.formEMAS.variable.selectedIndex;

			if (img==0&&prd==0&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"MP10P.html";}
			if (img==0&&prd==1&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"MP60P.html";}
			if (img==0&&prd==2&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"MP24P.html";}
		
			if (img==0&&prd==0&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"MP10T.html";}
			if (img==0&&prd==1&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"MP60T.html";}
			if (img==0&&prd==2&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"MP24T.html";}
				
			if (img==0&&prd==0&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"MP10.html";}
			if (img==0&&prd==1&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"MP60.html";}
			if (img==0&&prd==2&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"MP24.html";}
		
			if (img==1&&prd==0&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"IR10P.html";}
			if (img==1&&prd==1&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"IR60P.html";}
			if (img==1&&prd==2&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"IR24P.html";}

			if (img==1&&prd==0&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"IR10T.html";}
			if (img==1&&prd==1&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"IR60T.html";}
			if (img==1&&prd==2&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"IR24T.html";}

			if (img==1&&prd==0&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"IR10.html";}
			if (img==1&&prd==1&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"IR60.html";}
			if (img==1&&prd==2&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"IR24.html";}

			if (img==2&&prd==0&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"VS10P.html";}
			if (img==2&&prd==1&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"VS60P.html";}
			if (img==2&&prd==2&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"VS24P.html";}

			if (img==2&&prd==0&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"VS10T.html";}
			if (img==2&&prd==1&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"VS60T.html";}
			if (img==2&&prd==2&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"VS24T.html";}
				
			if (img==2&&prd==0&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"VS10.html";}
			if (img==2&&prd==1&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"VS60.html";}
			if (img==2&&prd==2&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"VS24.html";}

			if (img==3&&prd==0&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"H210P.html";}
			if (img==3&&prd==1&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"H260P.html";}
			if (img==3&&prd==2&&vrb==0){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"H224P.html";}

			if (img==3&&prd==0&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"H210T.html";}
			if (img==3&&prd==1&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"H260T.html";}
			if (img==3&&prd==2&&vrb==1){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"H224T.html";}
				
			if (img==3&&prd==0&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"H210.html";}
			if (img==3&&prd==1&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"H260.html";}
			if (img==3&&prd==2&&vrb==2){
				window.location.href = "http://"+location.hostname+"/emas/"+est+"H224.html";}
		}
	}
	else
	{
		var img=document.formEMAS.imagen.value;
		var prd=document.formEMAS.periodo.value;
		var vrb=document.formEMAS.variable.value;
	}

	if (img=='Mapa'&&prd=='10 min.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"MP10P.html";}
	if (img=='Mapa'&&prd=='60 min.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"MP60P.html";}
	if (img=='Mapa'&&prd=='24 hr.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"MP24P.html";}
		
	if (img=='Mapa'&&prd=='10 min.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"MP10T.html";}
	if (img=='Mapa'&&prd=='60 min.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"MP60T.html";}
	if (img=='Mapa'&&prd=='24 hr.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"MP24T.html";}
		
	if (img=='Mapa'&&prd=='10 min.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"MP10.html";}
	if (img=='Mapa'&&prd=='60 min.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"MP60.html";}
	if (img=='Mapa'&&prd=='24 hr.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"MP24.html";}
		
	if (img=='Infrarojo'&&prd=='10 min.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"IR10P.html";}
	if (img=='Infrarojo'&&prd=='60 min.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"IR60P.html";}
	if (img=='Infrarojo'&&prd=='24 hr.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"IR24P.html";}

	if (img=='Infrarojo'&&prd=='10 min.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"IR10T.html";}
	if (img=='Infrarojo'&&prd=='60 min.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"IR60T.html";}
	if (img=='Infrarojo'&&prd=='24 hr.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"IR24T.html";}
		
	if (img=='Infrarojo'&&prd=='10 min.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"IR10.html";}
	if (img=='Infrarojo'&&prd=='60 min.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"IR60.html";}
	if (img=='Infrarojo'&&prd=='24 hr.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"IR24.html";}

	if (img=='Visible'&&prd=='10 min.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"VS10P.html";}
	if (img=='Visible'&&prd=='60 min.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"VS60P.html";}
	if (img=='Visible'&&prd=='24 hr.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"VS24P.html";}

	if (img=='Visible'&&prd=='10 min.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"VS10T.html";}
	if (img=='Visible'&&prd=='60 min.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"VS60T.html";}
	if (img=='Visible'&&prd=='24 hr.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"VS24T.html";}

	if (img=='Visible'&&prd=='10 min.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"VS10.html";}
	if (img=='Visible'&&prd=='60 min.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"VS60.html";}
	if (img=='Visible'&&prd=='24 hr.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"VS24.html";}
		
	if (img=='Vapor de Agua'&&prd=='10 min.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"H210P.html";}
	if (img=='Vapor de Agua'&&prd=='60 min.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"H260P.html";}
	if (img=='Vapor de Agua'&&prd=='24 hr.'&&vrb=='Precipitacion'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"H224P.html";}

	if (img=='Vapor de Agua'&&prd=='10 min.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"H210T.html";}
	if (img=='Vapor de Agua'&&prd=='60 min.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"H260T.html";}
	if (img=='Vapor de Agua'&&prd=='24 hr.'&&vrb=='Temperatura'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"H224T.html";}
		
	if (img=='Vapor de Agua'&&prd=='10 min.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"H210.html";}
	if (img=='Vapor de Agua'&&prd=='60 min.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"H260.html";}
	if (img=='Vapor de Agua'&&prd=='24 hr.'&&vrb=='Ninguna'){
		window.location.href = "http://"+location.hostname+"/emas/"+est+"H224.html";}
	
}

/* functions that handle preload. */
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0;
i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image;
d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

