var browserIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1;
var dateObj = new Date();
var curTime = addZero_func(dateObj.getHours(),2)+""+addZero_func(dateObj.getMinutes(),2);
var curYear = dateObj.getFullYear();
var curDate = dateObj.getDate();
var curMonth = dateObj.getMonth()+1; //Add 1 to get it in format 1-12, javascript uses 0-11
preloadImgsArr = new Array("images/tab_inicio_over.gif", "images/tab_indicadores_over.gif", "images/tab_ayuda_over.gif","images/tab_cuidades_over.gif");

function setStyle_func(obj, stylevar, styleval){
	if (navigator.userAgent.toLowerCase().indexOf("msie") > -1){
		obj.style[stylevar]=styleval;
	} else {
		obj.style[stylevar]=styleval;
	}
}

function init_func(){
	preloadImgs_func(preloadImgsArr);
	navObjs = document.getElementsByTagName("img")
	navL = navObjs.length;	
	for(i=0;i<navL;i++){
		if (navObjs[i].className == "imgnav"){
			navObjs[i].onmouseover = navOver_func;
			navObjs[i].onmouseout = navOut_func;
			//navObjs[i].onmousedown = navDown_func;
		}
	}
	divObjs = document.getElementsByTagName("div")
	divL = divObjs.length;	
	for(i=0;i<divL;i++){
		if (divObjs[i].className == "boxheader"){
			iconImg = divObjs[i].getElementsByTagName("img");
			if (iconImg[0]){
				iconImg[0].onclick = boxClick_func;
				setStyle_func(iconImg[0], 'cursor', 'pointer');
			}
		}
	}	
}

function boxClick_func(){
	//alert(this.parentNode.nextSibling.innerHTML)
	//alert(this.nextSibling.innerHTML)
	obj = this.parentNode.nextSibling;
	if (obj.className == "boxbody"){
		if (obj.style.visibility=='hidden'){
			this.src="images/icon_less.gif"
			setStyle_func(obj, 'visibility', 'visible');
			setStyle_func(obj, 'position', 'relative');
			cl = obj.childNodes.length;
			for(ci=0;ci<cl;ci++){
				//setStyle_func(obj.childNodes[ci], 'visibility', 'visible');
				//setStyle_func(obj.childNodes[ci], 'position', 'relative');			
				
			}
		} else {
			this.src="images/icon_more.gif"
			setStyle_func(obj, 'visibility', 'hidden');
			setStyle_func(obj, 'position', 'absolute');
		}
	}
}

function navOver_func(){
	this.origsrc=this.src;	
	if (this.src != undefined){
		this.src=replace_func(this.src, ".gif", "_over.gif");	
		//window.status = this.src;
	}
}

function navOut_func(){
	if (this.origsrc != undefined){
		this.src=this.origsrc;
	}
}

function navDown_func(){
	this.src=replace_func(this.src, "_over.gif", "_sel.gif");	
}


function subnavOver_func(){
	setStyle_func(this, 'color', pgColor);
}

function subnavOut_func(){
	setStyle_func(this, 'color', '#B2B2B2');
}

function showDepDetails_func(selObj){
	if (selObj.value.length > 0){
		loc = location.href.split("?")
		if (loc.length < 1){
			location.href=location.href+"?depart="+selObj.value
		} else {
			location.href=loc[0]+"?depart="+selObj.value
		}
	}
}

function txtfocus_func(txtobj){
	//if (txtobj.init == undefined){
	if (txtobj.value=="location"){
		txtobj.init=1;
		txtobj.value="";
	}
}

function OpenBrWindow(url, wname, topleft, fullscreen, appw, apph, scroll) {
	if (fullscreen == 1){
		fscreen = "fullscreen"
	} else {
		fscreen = ""
	}
	if (topleft == 1){
		screenx = 0
		screeny = 0
	} else {
		sreenw = screen.width
		sreenh = screen.height
		screenx = (sreenw - appw)/2
		screeny = (sreenh - apph)/2
	}	
	newWin = window.open(url, wname, "toolbar=no,status=yes,"+fscreen+",scrollbars="+scroll+",resizable=yes,menubar=no,width="+appw+",height="+apph+",left="+screenx+",top="+screeny+", maximize=yes");
	//return newWin;	
}

function checkform_func(form){
	formlen = form.length;
	submitform = 1;
	for (i=0;i<formlen;i++){
		if (form.elements[i].type == "text" || form.elements[i].type == "textarea" || form.elements[i].type == "file" || form.elements[i].type == "password"){
			if (form.elements[i].value == "" ){
				submitform = 0
			}
		}
	}

	if (submitform == ""){
		alert("Complete por favor los campos requeridos!!")
		return false;
	} else {
		form.submit();
	}
}

function addZero_func(no, digits){
	if (String(no).length >= Number(digits)){
		return no;
	} else {		
		no_no = Number(digits) - String(no).length
		zeros = ""
		for(p=1;p<=no_no;p++){
			zeros += "0";
		}
		return zeros+no;
	}
}

function chgImg_func(imgobj, imgsrc){
	if (imgobj.src.indexOf("blogger_face.gif") == -1){
		if (imgobj.src.indexOf("_out") != -1){
			newSrc = imgobj.src.split("_over");
			imgobj.src = newSrc.join("_out");
		} else {
			imgobj.src = imgsrc;
		}
	}
}

function preloadImgs_func(arr){		
	for(i=0;i<arr.length;i++){
		var preloadImg = new Image();
		preloadImg.src = arr[i];
	}
}

function txtarea_func(txtareaObj, strlen){
	txtareal = txtareaObj.value.length;
	if (txtareal > strlen){
		txtareaObj.value = txtareaObj.value.substr(0,strlen);
	}
	if (browserIE){
		parElemt = txtareaObj.parentElement.getElementsByTagName('div');
	} else {
		parElemt = txtareaObj.parentNode.getElementsByTagName('div');
	}
	if (parElemt[0]){
		parElemt[0].firstChild.nodeValue = "(máx "+strlen+" caracteres, "+(strlen-txtareal)+" caracteres left)"
	}
}


// **** ADMIN FUNCTIONS ****
function gotourl_func(url){
	if (url != ""){
		location.href=url;
	}
}

// **** String function ****
function replace_func(txt, findtxt, replacetxt){
	newtxt = String(txt).split(findtxt);
	return newtxt.join(replacetxt);	
}




function showIndList_func(indgroupid){
	divArr = document.getElementsByTagName("div");
	for (i=0;i<divArr.length;i++){
		if (divArr[i].id == "indlist"+indgroupid){
			if (divArr[i].style.visibility=='visible'){
				setStyle_func(divArr[i], 'visibility','hidden');
				setStyle_func(divArr[i], 'position','absolute');
			} else {
				setStyle_func(divArr[i], 'visibility','visible');
				setStyle_func(divArr[i], 'position','relative');
			}
		}
	}
}

function hideObj_func(objid){
	obj = document.getElementById(objid);
	setStyle_func(obj, 'visibility','hidden');
	setStyle_func(obj, 'position','absolute');
}

function showObj_func(objid){
	obj = document.getElementById(objid);
	setStyle_func(obj, 'visibility','visible');
	setStyle_func(obj, 'position','relative');
}

function hideshowObj_func(objid){
	obj = document.getElementById(objid);	
	if (obj.style['visibility']=='hidden'){
		setStyle_func(obj, 'visibility','visible');
		setStyle_func(obj, 'position','relative');	
	} else {
		setStyle_func(obj, 'visibility','hidden');
		setStyle_func(obj, 'position','absolute');
	}
}

var xmlhttp
var xmlDoc
var currReplyObj

function httpxmlLoad_func(url){ //Load request xml template
	if (browserIE) { // code for IE		
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		xmlhttp.onreadystatechange=httpxmlInit_func
		xmlhttp.open("GET",url,true);
		xmlhttp.send();	
	} else if (window.XMLHttpRequest){// code for Mozilla, etc.
		xmlhttp=new XMLHttpRequest();
		xmlhttp.onload = httpxmlInit_func
		xmlhttp.open("GET",url,true)
		xmlhttp.send(null)
	}
}

function httpxmlInit_func(){
	/*if (window.XMLHttpRequest){// code for Mozilla, etc.
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onreadystatechange=httpxmlBuild_func;
		xmlDoc.loadXML(xmlhttp.responseText);
	} else if (window.ActiveXObject) { // code for IEx
		if (xmlhttp.readyState==4){// if xmlhttp shows "loaded"
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.onreadystatechange=httpxmlBuild_func;
			xmlDoc.loadXML(xmlhttp.responseText);
		}
	}
	*/
	if (window.ActiveXObject) { // code for IEx
		if (xmlhttp.readyState==4){// if xmlhttp shows "loaded"
			currReplyObj.innerHTML=xmlhttp.responseText
		}
	}
}

function showDetails_func(obj, commid, ind){
	currReplyObj = document.getElementById('replies'+commid);	
	if (currReplyObj.style['visibility']=='hidden'){	
		setStyle_func(currReplyObj, "position", "relative");
		setStyle_func(currReplyObj, "visibility", "visible");	
		setStyle_func(obj, "fontWeight", "bold");		
		httpxmlLoad_func('indicadores_forumreplies.asp?commid='+commid+"&ind="+ind);
	} else {
		setStyle_func(currReplyObj, "position", "absolute");
		setStyle_func(currReplyObj, "visibility", "hidden");		
		setStyle_func(obj, "fontWeight", "normal");
	}
	
}

function cnfirm_func(txt, url){
	confvar = confirm(txt)
	if (confvar){
		location.href=url;
	}
}

function translatePage_func(){
	window.open("http://babelfish.altavista.com/babelfish/trurl_pagecontent?lp=es_en&trurl="+escape(location.href))
}
