function objAjax()
{
	var xmlhttp=false;
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	 	}
		catch(E)
		{
			xmlhttp = false;
		}
	}

	if(!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function getPage(url, elm, met, par)
{
	var cont, prel;
	cont = document.getElementById(elm);
	mens = document.getElementById('msg');
	if (met == "GET") url += "?" + par;

	ajax = objAjax();
	ajax.open(met, url, true);
	ajax.onreadystatechange=function()
	{
		if(ajax.readyState==1)
		{
			mens.style.visibility = "visible";
		}
		else if(ajax.readyState==4)
		{
			if(ajax.status==200)
			{
				cont.innerHTML = ajax.responseText;
			}
			else if(ajax.status==404)
			{
				cont.innerHTML = "La p&aacute;gina no existe";
			}
			else
			{
				cont.innerHTML = "Error:".ajax.status;
			}
			mens.style.visibility = "hidden";
		}
	}
	if (met == "POST")
	{
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(par);
	}
	else if (met == "GET")
	{
		ajax.send(null);
	}
}

function getParm()
{
  var getstr = "";
	elem = document.getElementsByTagName("INPUT")
  for (i=0;i<elem.length;i++) 
	{
  	if (elem[i].type == "password") 
  		getstr += elem[i].name + "=" + hex_sha1(elem[i].value) + "&";
  	if (elem[i].type == "text" || elem[i].type == "hidden") 
  		getstr += elem[i].name + "=" + elem[i].value + "&";
  	if (elem[i].type == "checkbox") 
  		if (elem[i].checked) 
  			getstr += elem[i].name + "=" + elem[i].value + "&";
  		else 
  			getstr += elem[i].name + "=&";
  	if (elem[i].type == "radio") 
  		if (elem[i].checked) 
  			getstr += elem[i].name + "=" + elem[i].value + "&";
  }   
	elem = document.getElementsByTagName("SELECT")
  for (i=0;i<elem.length;i++) 
 		getstr += elem[i].name + "=" + elem[i].options[elem[i].selectedIndex].value + "&";
	elem = document.getElementsByTagName("TEXTAREA")
  for (i=0;i<elem.length;i++) 
 		getstr += elem[i].name + "=" + elem[i].value + "&";

	return getstr;
}

function Trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function Decval(dec)
{ 
	if (isNaN(parseInt(dec)))
		return false;
	else if (parseInt(dec)>9999999999)
		return false;
	else if (dec.indexOf(".")>-1)
		if (dec.substring(dec.indexOf(".")+1).length>2)
			return false;
	    
	return true;
} 

function getVal(des)
{
  var par="";
  var val="";
  tbl = document.getElementById("tblval").tBodies[0];
  for(i=tbl.childNodes.length; i>0; i--)
	{
		n=0;
    rws = tbl.childNodes[i-1];
		if (rws.bgColor == "#005dab")
		{
      for(e=0; e<rws.childNodes.length; e++)
      {
        if (rws.childNodes[e].tagName == "TD")
  			{
          if (n==0 || n==des)
          {
            val = rws.childNodes[e].innerHTML.replace(/,/g,"");
            par=par+"|"+val;
          }
          n++;
        }
  		}
  	}
  }
  gra="indicadores";
  par=par.substring(1);
  document.getElementById("fgra").src="charts/charts.php?data="+gra+".php&dato="+par;
}

function shwArc(arc, swh)
{
	if (arc == 'videos/vialidades.html')
	{
		document.getElementById('topvid').src = 'imgs/topvidgrd.gif';
		document.getElementById('video').height = 310;
		document.getElementById('video').width = 425;
	}
	else
	{
		document.getElementById('topvid').src = 'imgs/topvid.gif';
		document.getElementById('video').height = 250;
		document.getElementById('video').width = 320;
	}
	document.getElementById('video').src = arc;
	document.getElementById('marco').style.top = 125;
	document.getElementById('marco').style.left = (screen.availWidth/2)-(document.getElementById('video').width/2);
	document.getElementById('marco').style.visibility = swh;
} 

function getHEX(red,green,blue)
{
	var c="0123456789abcdef";

  with (Math) {
  	numOne=c.substring(floor(red/16),floor(red/16)+1);
  	numTwo=c.substring(red%16,(red%16)+1);
  	numThree=c.substring(floor(green/16),floor(green/16)+1);
  	numFour=c.substring(green%16,(green%16)+1);
  	numFive=c.substring(floor(blue/16),floor(blue/16)+1);
  	numSix=c.substring(blue%16,(blue%16)+1);	
  }
  varHex=numOne+""+numTwo+""+numThree+""+numFour+""+numFive+""+numSix;
  return varHex;
}

function getRGB(hex)
{
	pound=0;
	hexidec=new Array(7);
	
	for (i=0;i<7;i++){
		hexidec[i]=hex.charAt(i);
		temp=hexidec[i];
		if (temp=='#')
			pound++;
		if ((temp=='a')||(temp=='A'))
			hexidec[i]=10;
		if ((temp=='b')||(temp=='B'))
			hexidec[i]=11;
		if ((temp=='c')||(temp=='C'))
			hexidec[i]=12;
		if ((temp=='d')||(temp=='D'))
			hexidec[i]=13;
		if ((temp=='e')||(temp=='E'))
			hexidec[i]=14;
		if ((temp=='f')||(temp=='F'))
			hexidec[i]=15;
	}
	red=((hexidec[0+pound]*16)- -hexidec[1+pound]);
	green=((hexidec[2+pound]*16)- -hexidec[3+pound]);
	blue=((hexidec[4+pound]*16)- -hexidec[5+pound]);
	return red+","+green+","+blue;
}
