var fontSize=readCookie('fontSize');
function changeSize(objs,increase){
	for(var i=0;i<objs.length;i++){
		var size=objs[i].style.fontSize.replace('px','');
		objs[i].style.fontSize=(16+increase)+'px';
	}
	if(isNaN(objs.length)){objs.style.fontSize=(16+increase)+'px';}
	return size;
}
function changeFontSize(obj,increase){
	obj=get(obj,null,null,1);
	if(obj.length<=0){return false;}
	if(isNaN(increase) || increase==''){increase=0;}
	fontSize+=increase;
	fontSize=Math.max(-6,Math.min(fontSize,6));
	for(var i=0;i<obj.length;i++){
		temp=obj[i];
		changeSize(temp,fontSize);
		objs=get(temp,null,null,1);
		changeSize(objs,fontSize);
		objs=get(null,null,temp,1);
		changeSize(objs,fontSize);
	}
	saveCookie('fontSize',fontSize,'10');
}

function saveCookie(cookieName,cookieValue,days){
	var date=new Date();
	var expires;
	if(days){
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires='EXPIRES='+date.toGMTString()+';';
	}
	if(document.cookie=cookieName+"="+cookieValue+";"+expires+"PATH=/"){
		return true;
	}
	return false;
}

function readCookie(cookieName){
	var cookieString=document.cookie;
	var index1=cookieString.indexOf(cookieName);
	if(index1<0 || cookieName==''){return "";}
	var index2=cookieString.indexOf(';',index1);
	if(index2<0){index2=cookieString.length;}
	return unescape(cookieString.substring(index1+(cookieName.length+1),index2));
}

function abreFoto(src){
	window.open("foto.php?src="+src, "Foto", "width=40,height=40,top=90,left=90,menubar=no,location=no,resizable=no,scrollbars=0,status=no");
}

function convertRGB(hex){
	var red=parseInt(hex.substring(1,3),16);
	var grn=parseInt(hex.substring(3,5),16);
	var blu=parseInt(hex.substring(5,7),16);
	return [red,grn,blu];
}

function rgb2hex(red,green,blue){
	var decColor=blue+256*green+65536*red;
	return decColor.toString(16);
}

/* ### BIBLIOTECA DE CÓDIGOS JAVASCRIPT ###############################################################################################################
function inputVal(obj) - apaga o valor de obj (input) caso este valor seja o padrão. Uso: onFocus="inputVal(this);"
function limpaForm(form) - solicita ao usuario se ele deseja realmente limpar os valores preenchidos do formulário. Uso: onclick="return limpaForm(this.form);"
function highlite(obj,type) - altera o className e ID do objeto passado como parametro e baseado no type. Uso: onmouseover="highlite(this,1);" onmouseout="highlite(this,-1);" onfocus="highlite(this,2);" onblur="highlite(this,-2);"
prototype trim() - remove espaços em branco de uma string, uso: obj.value.trim()
prototype replaceAll(findstr,newstr) - substitue todas ocorrencias de uma string por outra. uso: var result=obj.value.replaceAll('á','a')
function innerTxt(obj) - retorna o mesmo que a funcao javascript innerText, porém este funciona no IE/Mozilla
function addEvent(object,evType,func,useCapture) - cria um event handler para o objeto, funciona no IE/Mozilla, (objeto/evento/funcao/parametros). exemplo: var func=function(){alert("minha funcao");}addEvent(document, "click", func);
function removeEvent=function(o,e,f,s) - remove um evento previamente definido atraves da funcao addEvent(), para remover a função, os parametros passados para esta função devem ser os mesmos daqueles passados em addEvent, Exemplo: removeEvent(document, "click", func);
function saveCookie(cookieName,cookieValue,days) - grava o cookie no computador do usuário.
function readCookie(cookieName) - retorna o valor do cookie (cookieName) salvo no computador do usuário.
function getMousePos(e) - retorna um array de 2 elementos(0 e 1, x e y respectivamente) com as coordenadas do mouse na tela do computador. Uso: document.onmousemove=getMousePos;
function checkEmail(string) - retorna true se a string passada for um email válido, caso contrário, retorna false.
#####################################################################################################################################################*/

function inputVal(obj){
	if(obj.defaultValue==obj.value){obj.value=''};
}

function limpaForm(form){
	return confirm('Tem certeza de que deseja limpar os valores preenchidos acima?');
}
function atualizaDataHora(){
	var data = new Date();
	var hora = str_pad (data.getHours(), 2, '0', "STR_PAD_LEFT");
	var minutos = str_pad (data.getMinutes(), 2, '0', "STR_PAD_LEFT");
	document.getElementById('horaCerta').innerHTML = hora + ':' + minutos;
	setTimeout("atualizaDataHora()",1000);
}
	
function highlite(obj,type){  //uso: onmouseover="highlite(this,1);" onmouseout="highlite(this,-1);" onfocus="highlite(this,2);" onblur="highlite(this,-2);"
	if(type==-1){obj.className=obj.className.replace(/inputOver/,'');}
	else if(type==1){obj.className+=' inputOver';}
	else if(type==2){obj.id='inputOver';}
	else{obj.id='';obj.className=obj.className.replace(/inputOver/,'');}
}

function checkEmail(valor){
	if(valor==''){return true;}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){return (true);}
	return (false);
}

/*#####################################################################################################################################################*/
//VARIAVEIS IMPORTANTES
var IE=document.all?true:false;

//FUNCTION PROTOTYPES
String.prototype.trim=function(){  //trim leading or trailing whitespace and extra spaces
	return this.replace(/^\s*/, "").replace(/\s*$/, "").replace(/\s{2,}/, " ");
}

String.prototype.replaceAll=function(findstr,newstr){  //replace all occurences of string
	return this.replace(eval('/'+findstr+'/gi'),newstr);  //case insensitive
}

//OTHER FUNCTIONS
function innerTxt(obj){  //retorna o mesmo que innerText - para IE/Mozilla
	if(!obj){return '';}
	return (obj.innerText)?obj.innerText:obj.textContent;
}

//EXEMPLOS:var func=function(){alert("minha funcao");}addEvent(document, "click", func);
addEvent=function(o,e,f,s){  //adiciona evento ao objeto IE/FF - objeto/evento/funcao/parametros
	var r=o[r="_"+(e="on"+e)]=o[r] || (o[e]?[[o[e],o]]:[]),a,c,d;
	r[r.length]=[f,s || o],o[e]=function(e){
		try{
			(e=e || event).preventDefault || (e.preventDefault=function(){e.returnValue = false;});
			e.stopPropagation || (e.stopPropagation=function(){e.cancelBubble=true;});
			e.target || (e.target=e.srcElement || null);
			e.key=(e.which+1 || e.keyCode+1)-1 || 0;
		}catch(f){}
		for(d=1, f=r.length; f;r[--f] && (a=r[f][0],o=r[f][1],a.call?c=a.call(o,e):(o._=a,c=o._(e),o._=null),d &=c!==false));
		return e=null,!!d;
	}
};

//EXEMPLOS:removeEvent(document, "click", func);
removeEvent=function(o,e,f,s){  //remove evento do objeto IE/FF
	for(var i=(e=o["_on"+e] || []).length;i;)
	if(e[--i] && e[i][0]==f && (s || o)==e[i][1])
	return delete e[i];
	return false;
};

function addEvent(object,evType,func,useCapture){  //attacha um evento a um elemento IE/MOZILLA
	useCapture=true;
	if(object.addEventListener){
		object.addEventListener(evType,func,useCapture);
	}else if(object.attachEvent){
		object.attachEvent("on"+evType,func);
	}
}

function str_pad (input, pad_length, pad_string, pad_type)
{
  input = String (input);
  pad_string = pad_string != null ? pad_string : " ";
  if (pad_string.length > 0)
  {
    var padi = 0;
    pad_type = pad_type != null ? pad_type : "STR_PAD_RIGHT";
    pad_length = parseInt (pad_length);
    switch (pad_type)
    {
      case "STR_PAD_BOTH":
        input = str_pad (input
                       , input.length + Math.ceil ((pad_length - input.length) / 2.0)
                       , pad_string, "STR_PAD_RIGHT");
     // break;  // kein break!
      case "STR_PAD_LEFT":
        var buffer = "";
        for (var i = 0, z = pad_length - input.length; i < z; ++i)
        {
          buffer += pad_string.charAt(padi); // [padi] IE 6.x bug
          if (++padi == pad_string.length)
            padi = 0;
        }
        input = buffer + input;
        break;
      default:
        for (var i = 0, z = pad_length - input.length; i < z; ++i)
        {
          input += pad_string.charAt(padi);
          if (++padi == pad_string.length)
            padi = 0;
        }
        break;
    }
  }
  return input;
}


function saveCookie(cookieName,cookieValue,days){
	var date=new Date();
	var expires;
	if(days){
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires='EXPIRES='+date.toGMTString()+';';
	}
	if(document.cookie=cookieName+"="+cookieValue+";"+expires+"PATH=/"){
		return true;
	}
	return false;
}

function readCookie(cookieName){
	var cookieString=document.cookie;
	var index1=cookieString.indexOf(cookieName);
	if(index1<0 || cookieName==''){return "";}
	var index2=cookieString.indexOf(';',index1);
	if(index2<0){index2=cookieString.length;}
	return unescape(cookieString.substring(index1+(cookieName.length+1),index2));
}

var mousePos=new Array();
function getMousePos(e){  //pega a posicao do mouse
	if(IE){
		mousePos[0]=event.clientX+document.body.scrollLeft;
		mousePos[1]=event.clientY+document.body.scrollTop;
	}else{
		mousePos[0]=e.pageX;
		mousePos[1]=e.pageY;
	}
	mousePos[0]=Math.max(0,mousePos[0]);
	mousePos[1]=Math.max(0,mousePos[1]);
	return ([mousePos[0],mousePos[1]]);
}

function toggle(idName,visible){
	var obj;
	if(typeof(idName)=='object'){obj=idName;}else{obj=document.getElementById(idName);}
	if(!obj){return;}
	if(visible>0){  //force display
		obj.style.display="";
		return 1;
	}
	else if(visible<0){  //force hide
		obj.style.display="none";
		return -1;
	}
	else{  //toggle display on/off
		if(obj.style.display=='none'){
			obj.style.display="";
			return 1;
		}
		else{
			obj.style.display="none";
			return -1;
		}
	}
}

function get(id,tag,childOf,returnArray){  //getElementById
	if(!tag){tag="*";}
	if(typeof(childOf)=='string'){childOf=document.getElementById(childOf);}
	var anchs=document.getElementsByTagName(tag);
	var total_anchs=anchs.length;
	var regexp=new RegExp('\\b'+id+'\\b');
	var class_items=new Array();
	
	for(var i=0;i<total_anchs;i++){ //Go thru all the links seaching for the id name
		var this_item=anchs[i];
		if(regexp.test(this_item.id) || !id){
			if(childOf){
				pai=this_item.parentNode;
				if(!pai){continue;}
				while(pai!=null){
					if(pai==childOf){class_items.push(this_item);break;}
					pai=pai.parentNode;
				}
			}else{class_items.push(this_item);}
		}
	}
	if(returnArray){return class_items;}
	if(class_items.length<=0){return null;}
	else if(class_items.length==1){return class_items[0];}
	return class_items;
}

function backTop(){
	window.scrollTo(0,0);
}

function checkEmail(valor){
	if(valor==''){return true;}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){return (true);}
	return (false);
}

function checkdate(d,m,y)
{
	if(!IsNumeric(d) || !IsNumeric(m) || !IsNumeric(y) || d.length<2 || m.length<2 || y.length<4){return false;}
	var yl=1900; // least year to consider
	var ym=2500; // most year to consider
	if (m<1 || m>12) return(false);
	if (d<1 || d>31) return(false);
	if (y<yl || y>ym) return(false);
	if (m==4 || m==6 || m==9 || m==11)
	if (d==31) return(false);
	if (m==2)
	{
		var b=parseInt(y/4);
		if (isNaN(b)) return(false);
		if (d>29) return(false);
		if (d==29 && ((y/4)!=parseInt(y/4))) return(false);
	}
	return(true);
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}

function isHour(value){
	if(value==''){alert('Favor digite uma hora.');return false;}
	var splitted=value.split(':');
	var hora=splitted[0];
	var minuto=splitted[1];
	var segundo=splitted[2];
	if(!IsNumber(hora) || !IsNumber(minuto) || !IsNumber(segundo) || hora>24 || minuto>59 || segundo>59){return false;}
	return true;
}
function isVisible(obj){  //verifica se o elemento está visivel
	if(!obj.parentNode){return false;}
	while(obj.parentNode!=null){
		if(obj.style.display.toLowerCase()=='none' || obj.style.visibility.toLowerCase()=='hidden'){return false;}
		obj=obj.parentNode;
	}
	return true;
}
function mascaraData(data_nascimento){
		  var data_nascimento = data_nascimento.value;
		  if (data_nascimento.length == 2){
			  data_nascimento = data_nascimento + '/';
			  document.forms[0].data_nascimento.value = data_nascimento;
  return true;              
		  }
		  if (data_nascimento.length == 5){
			  data_nascimento = data_nascimento + '/';
			  document.forms[0].data_nascimento.value = data_nascimento;
			  return true;
		  }
}
function checaCampos(form){
	if(!form){return false;}
	var element,enviar=true;
	for(var i=0;i<form.elements.length;i++){
		element=form.elements[i];
		if(element.className.indexOf('required')>=0){  //campo requerido
			if(!isVisible(element)){continue;}
			if(element.type.toUpperCase()=='CHECKBOX'){  //se for um checkbox
				checkboxes=document.getElementsByName(element.name);
				for(var c=0;c<checkboxes.length;c++){
					if(checkboxes[c].checked){break;}
				}
				if(c<checkboxes.length){continue;}
				alert(element.title);
				element.focus();
				return false;
			}
			if(element.value==element.defaultValue || element.value.length<=0){  //nao preenchido
				if(element.type.toUpperCase().indexOf('SELECT')>=0){
					alert(element.title);
				}else{
					if(!isVisible(element)){continue;}
					alert(element.title);
				}
				element.focus();
				enviar=false;
				break;
			}
		}
		if(element.className.indexOf('email')>=0){  //campo tipo email
			if(!checkEmail(element.value.trim())){
				alert(element.title);
				element.focus();
				enviar=false;
				break;
			}
		}
		if(element.className.indexOf('hour')>=0){  //campo tipo hora HH:mm:ss
			if(!isHour(element.value.trim())){
				alert(element.title);
				element.focus();
				enviar=false;
				break;
			}
		}
		if(element.className.indexOf('number')>=0){  //campo tipo numero
			if(!IsNumeric(element.value.trim())){
				alert(element.title);
				element.focus();
				enviar=false;
				break;
			}
		}
	}
	return enviar;
}

function inputVal(obj,type){
	if(type==2){if(obj.value==''){obj.value=obj.defaultValue;}return;}
	if(obj.defaultValue==obj.value){obj.value=''};
}
