// JavaScript Document

function clickObj(id)
{
	document.getElementById(id).click();
}

function overOutImg(obj, tipo)
{
	if( tipo == 'over' )
		obj.style.border = '3px solid #FF9900';
	else if( tipo == 'out' )
		obj.style.border = '3px solid #CCCCCC';
}

function reloadSemana(cod_obra_mes)
{
	document.getElementById('loadSemana').style.display = '';
	params  = 'tipo=semana';
	params += '&cod_obra_mes=' + cod_obra_mes;

	postText('ajaxSelect.php', params, returnReloadSemana);
}

function returnReloadSemana(Html)
{
	var ArrayObj     = new Array;
	var ArrayObjSelct = new Array;	
	
	ArrayObj[0]  = document.getElementById('inpt_semana');
	
	for ( var i=0; i<ArrayObj.length; i++ )
		if ( ArrayObj[i]!=null )
			ArrayObjSelct[i] = ArrayObj[i].value;
	
	for (i=0; i<ArrayObj.length; i++)
	{
		if ( ArrayObj[i]!=null )
		{
			select_innerHTML(ArrayObj[i], Html);
			ArrayObj[i].value  = ArrayObjSelct[i];	
		}
	}
	document.getElementById('loadSemana').style.display = 'none';
}

/**
* ***************************************************************
* 						select_innerHTML 						*
* ***************************************************************
* Created on 07/01/2008
* Funcao Que Add Option no Select
*
* Params(objeto,innerHTML)
* objeto=>this
* innerHTML=>option a add
* Return array
* @author David Moraes Silva (david.moraes@sofcore.com.br)
* @version 1.0.0
*
*/
function select_innerHTML(objeto,innerHTML){
/******
* select_innerHTML - corrige o bug do InnerHTML em selects no IE
* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
* Versão: 2.1 - 04/09/2007
* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
* @objeto(tipo HTMLobject): o select a ser alterado
* @innerHTML(tipo string): o novo valor do innerHTML
*******/
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.toLowerCase().replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
      
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  	var spantemp = selTemp.childNodes[i];
  
        if(spantemp.tagName){     
            opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }       
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML.toUpperCase() 
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}

function Numero(valor) 
{
	return (isNaN(valor) || valor=="") ? false : true;
}

function overOutNot(obj, tipo)
{
	if( tipo == 'over' )
		obj.bgColor = '#E9E9DA';
	else if( tipo == 'out' )
		obj.bgColor = '';
}

function mostraNoticia(cod_noticia)
{
	window.location.href = "noticia.php?cd=" + cod_noticia;
}

function mostraDadosTela()
{
	document.getElementById('tr_dados').style.display = '';
	document.getElementById('tr_load').style.display = 'none';
}

/*
	FUNCAO GLOBAL QUE FORMATA O TELEFONE
	
	VERIFICA SE A FUNCAO QUE DESEJA E PARA PESSOA FISICA O JURIDICA
		Objeto => this
		Evento => event
*/
function FormataFone(Objeto, Evento)
{
	tecla          = Evento.keyCode;
	
	if (
			(tecla>=47 && tecla<=57)	// NUMERO
			||
			(tecla>=96 && tecla<=105)	// NUMERO NUMERICO
			||
			tecla==144					// NUM LOCK
			||
			tecla==16					// SHIFT
			||
			tecla==13					// ENTER
			||
			tecla==39					// SETA A ESQUERDA
			||
			tecla==37					// SETA A ESQUERDA
			||
			tecla==9					// TAB
			||
			tecla==116					// F5
			||
			tecla==8					// BLACK SPACE 
			||
			tecla==46					// DELETE
			||
			tecla==57					// (
			||
			tecla==48					// )
			||
			tecla==107					// - NUMERICO
			||
			tecla==109					// - 
		)
	{
		// SE NAO ESTIVER DELETANDO, FORMATA
		if( tecla!=8 && tecla!=46 )
		{
			var vr= new String(Objeto.value);
			vr = vr.replace("-","");
			
			tam = vr.length + 1 ;
			
			if(tam==1)
				Objeto.value = "(" + vr;	
			
			if(tam==4)
				Objeto.value = vr +")";	
						
			if (tam > 8)
				Objeto.value = vr.substr(0,8) + '-' + vr.substr(8,tam);
		}
		return true;
	}
	else
		return false;
}



