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
var preloadImgsArr;
preloadImgsArr = new Array("images/nav_background_over.gif", "images/nav_vision_over.gif", "images/nav_links_over.gif", "images/nav_involved_over.gif", "images/nav_contact_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);
	navheadObj = document.getElementById('nav');
	navObjs = navheadObj.getElementsByTagName("img")
	navL = navObjs.length;
	for(i=0;i<navL;i++){
		navObjs[i].onmouseover = navOver_func;
		navObjs[i].onmouseout = navOut_func;
	}
	txtSize = GetCookie_func("my-textsize");
	if (txtSize){
		chgFontSize_func(txtSize);
	}
}

function navOver_func(){
	window.status = this.src;
	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;
	}
}

// **** Accessibility functions ****
var currAccessNo;
function chgFontSize_func(fsize){
	var ano;
	if (fsize.toLowerCase() == "small"){
		ano = 1;
		fnosize = '11px';
	} else if (fsize.toLowerCase() == "medium"){
		ano = 2;
		fnosize = '13px';
	} else if (fsize.toLowerCase() == "large"){
		ano = 3;
		fnosize = '15px';
	}
	if (document.getElementById('headContentFontSize'+ano)){
		if (currAccessNo){
			setStyle_func(document.getElementById('headContentFontSize'+currAccessNo),"textDecoration","none");
		}
		setStyle_func(document.getElementById('headContentFontSize'+ano),"textDecoration","underline");
		currAccessNo = ano;
	}
	setStyle_func(document.body, "fontSize", fnosize);
	SetCookie_func("my-textsize",fsize,365);
}

function SetCookie_func(name,value,days) {
	var cookie = name + "=" + value + ";";
	if (days) {
		var myDate=new Date();
		myDate.setTime(myDate.getTime()+(days*24*60*60*1000));
		cookie += " expires=" + myDate.toGMTString() + ";";
	}
	cookie += " path=/";
	document.cookie = cookie;
}

function GetCookie_func(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(";");
	for(var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == " ") c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return;
}

// *********************************

// **** Generic functions ****
// ***************************
function gotourl_func(url){
	if (url != ""){
		location.href=url;
	}
}

function replace_func(txt, findtxt, replacetxt){
	newtxt = String(txt).split(findtxt);
	return newtxt.join(replacetxt);
}

function cnfirm_func(txt, url){
	confvar = confirm(txt)
	if (confvar){
		location.href=url;
	}
}

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;
	}
}

// **** Pre load images ****
function preloadImgs_func(arr){
	for(i=0;i<arr.length;i++){
		var preloadImg = new Image();
		preloadImg.src = arr[i];
	}
}

// **** OPpen Browser Window ****
function OpenBrWindow_func(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 txtfocus_func(txtobj){
	if (txtobj.init == undefined){
		txtobj.init=1;
		txtobj.value="";
	}
}

// *** ADMIN FUNCTIONS***
function initAdmin_func(){
    contenBox = document.getElementById('contentTxtMain');
    //setStyle_func(contenBox, "border", "dashed 1px #FF0000");
    //contentBox.addChild()
}
// ***********************



String.prototype.wordWrap = function(m, b, c){
    var i, j, s, r = this.split("\n");
    if(m > 0) for(i in r){
        for(s = r[i], r[i] = ""; s.length > m;
            j = c ? m : (j = s.substr(0, m).match(/\S*$/)).input.length - j[0].length
            || m,
            r[i] += s.substr(0, j) + ((s = s.substr(j)).length ? b : "")
        );
        r[i] += s;
    }
    return r.join("\n");
};


// HTML ENCODE FUNCTIONS
function autoHTML( strSrc,optAtt ) {
 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 // autoHTML function
 // author: T. Kang
 // contact: txkang@hotmail.com
 // This function will make http,https,ftp,www and email strings clickable.
 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

 strSrc = strSrc.replace( /\s(https:\/\/|http:\/\/|ftp:\/\/|www.)([^\s]*)/gi,
   ' <a href=http://$2 ' + optAtt + '>$1$2</a>' );
 strSrc = strSrc.replace( /\s([^\s]*@[^\s]*)/gi,' <a href=mailto:$1>$1</a>' );
 return strSrc;
}

function escapeHTML (str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
};