function AjaxInit(){

	try{
		xmlhttp = new XMLHttpRequest();
	}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }catch(E){
				xmlhttp = false;
      }
    }
	}

	return xmlhttp;

}


function WAWindow(vsUrl,vsNome,viWidth,viHight,viTop,viLeft,vbScroll) {
	alert('ola');
	var vsMyWIndow	=	null;

	if (viWidth != ''){
		vsMyWIndow=window.open(vsUrl,vsNome,'width='+viWidth+',height='+viHight+',toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars='+vbScroll+',resizable=1,left='+viLeft+',top='+viTop+' resize=no,fullscreen = yes');
	} else {
		vsMyWIndow=window.open (vsUrl,vsNome,"location=0,status=0,scrollbars=1,fullscreen=yes,resizable=yes");
	}
}

function WXWindow(vsIdJanela,vsTipoConteudo,vsFonteConteudo,vsTituloJanela,vsAtributos,vsRecal){
	/*
	alert('NEW SYSTEM WINDOW')
  var voJanela = dhtmlwindow.open(vsIdJanela,vsTipoConteudo,vsFonteConteudo,vsTituloJanela, vsAtributos,vsRecal);
  return voJanela;
	*/
}

function Janela2(url,nome){
	/*
	alert('FUNCTION NOVA');
	var voWindow = WXWindow(nome,'iframe',url,'WebAssist 4.0',"width=779px,height=540px,center=1,scrolling=0",'');
	voWindow.moveTo('center', '5');
	*/
}


var novajanela=null;

function janela(url,nome,largura,altura,topo,esquerda,scroll) {

	novajanela=window.open(url,nome,'width='+largura+',height='+altura+',toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars='+scroll+',resizable=1,left='+esquerda+',top='+topo+' resize=no');


	return novajanela;
	/*
	if(novajanela==null){
		novajanela=window.open(url,nome,'width='+largura+',height='+altura+',toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars='+scroll+',resizable=1,left='+esquerda+',top='+topo+' resize=no');
  }

	if (novajanela=='[object]'  || '[object window]') {
		novajanela.close();
		novajanela=window.open(url,nome,'width='+largura+',height='+altura+',toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars='+scroll+',resizable=1,left='+esquerda+',top='+topo+' resize=no');
	}
	*/
}



function muda_cor_linha(evento,id,cor){

var obj       = document.getElementById('itens_'.concat(id));
var check     = document.getElementById('check_'.concat(id));
var cor_click = '#FF8C00'


  if(evento == 'CLICK'){

    if(check.checked == false){
      check.checked = true;
      obj.style.background= cor_click;
      obj.style.color= '#FFFFFF';
      return;
    }

    if(check.checked == true){
      check.checked = false;
      obj.style.background= '#C1D2EE';
      obj.style.border= '#316AC5';
      obj.style.cursor= 'pointer';
      obj.style.color= '#000000';

    }

  }

  if(check.checked == false){
    if(evento == 'OVER'){
      //obj.style.background= '#C1D2EE';
      obj.style.background= '#316AC5';
      obj.style.border= '#316AC5';
      obj.style.cursor= 'pointer';
      obj.style.color= '#FFFFFF';
    }
  }

  if(check.checked == false){
    if(evento == 'OUT'){
      obj.style.background = cor;
      obj.style.color= '#000000';
    }
  }

}


function CorLinha(evento,id,cor){

var obj       = document.getElementById(id);

var cor_click = '#FF8C00'



    if(evento == 'OVER'){
      //obj.style.background= '#C1D2EE';
      obj.style.background= '#316AC5';
      obj.style.border= '#316AC5';
      obj.style.cursor= 'pointer';
      obj.style.color= '#FFFFFF';

    }



    if(evento == 'OUT'){
      obj.style.background = cor;
      obj.style.color= '#000000';
    }


}

function trim(str){


  while (str.charAt(0) == " ")
    str = str.substr(1,str.length -1);

  while (str.charAt(str.length-1) == " ")
    str = str.substr(0,str.length-1);

  return str;
}

function data_atual(){

  data = new Date();

  var dia = data.getDate();
  var mes = data.getMonth();
  mes++;//Em JavaScript, Janeiro == 0 e Dezembro == 11
  var ano = data.getFullYear();
  var data = dia+"/"+mes+"/"+ano;

  return data;
}

function hora_atual(){

  time = new Date();

  var hora = time.getHours();
  var min  = time.getMinutes();
  var sec  = time.getSeconds();
  var hora = hora+":"+min+":"+sec;


  return hora;

}
/*
FORMAS DE USO
CAMPO -> CAMPO : onKeyPress="EnterAsTab(event,'ID_PROXIMO_CAMPO','');"
CAMPO -> SUBMIT : onKeyPress="EnterAsTab(event,'SUBMIT','document.NM_FORM');"
*/
function EnterAsTab(evento,campo,frm) {

  var tecla = evento.keyCode;

  if(tecla == 13){
    if(campo == 'SUBMIT'){
      $(fr).submit();
    }
    else{
      document.getElementById(campo).focus();
    }
  }
}


/**
* A funcao mostra_oculta() tem a funcao de executar
* processos DHTML (HTML Dinâmico), ocultando ou
* mostrando uma DIV, TD, TR ou TABLE.
* Deve-se passar o ID do objeto HTML que sera'
* manipulado
*
* @author Juliano Biscaia
* @date 29-01-2007
*/
function mostra_oculta(id){
  var obj = $(id);

  if(obj.style.display == 'none'){
    obj.style.display = '';
  }
  else {
    obj.style.display = 'none'
  }
}


function MontaSelect(objeto,innerHTML){
	objeto.innerHTML = ""

	var selTemp = document.createElement("DynamicSelect")
  var opt;
    selTemp.id="DynamicSelect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("DynamicSelect1")
    selTemp.style.display="none"
    if(innerHTML.indexOf("<option")<0){//se não é option eu converto
        innerHTML = "<option>" + innerHTML + "</option>"
    }

    innerHTML = innerHTML.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;
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  }
 }
 document.body.removeChild(selTemp)
 selTemp = null
}

function CarregaSelect(viIdSelectOri,viIdSelectDest,vsPath) {
	$('ovO_UfVazio').innerHTML			=	"Aguarde, carregando dados...";


	var voAjax	=	AjaxInit();
	//$(viIdSelectDest).selectedIndex	=	'0';
	var vsVlrOrigem									=	$(viIdSelectOri).value;

  //Iniciando o processo AJAX para salvar as informacoes no BD
  voAjax.open("POST",vsPath,true);
  voAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1");
  voAjax.setRequestHeader("Cache-Control","no-store, no-cache, must-revalidate");
  voAjax.setRequestHeader("Cache-Control","post-check=0, pre-check=0");
  voAjax.setRequestHeader("Pragma", "no-cache");
  voAjax.onreadystatechange=function() {
    if (voAjax.readyState==4){
      if(voAjax.status == 200){
				MontaSelect(document.getElementById(viIdSelectDest),voAjax.responseText);
      }//fim if
    }//fim if
  }//fim function
  vsParametro = "vsParam="+vsVlrOrigem;

  voAjax.send(vsParametro);

}


function MarcaTodos(vsIdForm){

  var vaElementos       = $(vsIdForm).elements;
  var viQntdElementos   = vaElementos.length

  for(viAux=0;viAux<viQntdElementos;viAux++){
  	if (vaElementos[viAux].type == 'checkbox') {
  		vaElementos[viAux].checked = true;
  	}
  }//fim form

}//fim function


function DesmarcaTodos(vsIdForm){

  var vaElementos       = $(vsIdForm).elements;
  var viQntdElementos   = vaElementos.length

  for(viAux=0;viAux<viQntdElementos;viAux++){
  	if (vaElementos[viAux].type == 'checkbox') {
  		vaElementos[viAux].checked = false;
  	}
  }//fim form

}//fim function


function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}



Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		// Matches identical (===), not just similar (==).
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};




function getXYMouseClick(event) {
	var vaPos = Array();
	vaPos[0]	=	event.clientX;
	vaPos[1]	=	event.clientY;

	return vaPos;
}


function getXYScreenClick(event) {
	var vaPos = Array();
	vaPos[0]	=	event.screenX;
	vaPos[1]	=	event.screenY;

	return vaPos;
}

//Retorna a posicao em XY do scroll
function getXYScroll(dbody) {
	var vaPos = Array();
	vaPos[0]	=	dbody.scrollTop
 	vaPos[1]	=	dbody.scrollLeft
 	vaPos[2]	=	dbody.scrollWidth
 	vaPos[3]	=	dbody.scrollHeight

	return vaPos;
}



//Funcao usada no novo sistema de abas do WA
function ChangeTab(IdTab,vsSufix) {

	//ABAS
	var d	=	document.getElementsByTagName('li');
	for(x=0;x<d.length;x++){
		//Caso exista uma ABA de MENU ACOES, nao deve ser trocada o estilo da mesma.
		if(d[x].id != 'ActMenu')
			d[x].className = 'TabLnkI';
	}

	for(x=0;x<d.length;x++){
		var j = d[x].id.split('-')
		if (j[1] == IdTab)
			d[x].className = 'TabLnkA';
	}

	//CONTEUDO
	var d	=	document.getElementsByTagName('div');
	for(x=0;x<d.length;x++){
		var j = d[x].id.split('-')
		if (j[0] == 'ovD_TabContent')
			d[x].style.display = 'none'
	}

	for(x=0;x<d.length;x++){
		var j = d[x].id.split('-')
		if (j[0] == 'ovD_TabContent' && j[1] == IdTab)
			d[x].style.display = ''
	}
}




function cal(linha,botao){
	Calendar.setup(
		{
			inputField  : linha,         // ID of the input field
	    ifFormat    : "%d/%m/%Y",    // the date format
	    button      : botao       // ID of the button
	  }
  );
}



function print_r(theObj){
	
	//var animals = ['PHP', 'Javs', 'C++', 'C#', 'VB.NET'];
	//print_r(animals);
	
	
   if(theObj.constructor == Array || theObj.constructor == Object){
      document.write("<ul>")
      for(var p in theObj){
         if(theObj[p].constructor == Array || theObj[p].constructor == Object){
            document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
            document.write("<ul>")
            print_r(theObj[p]);
            document.write("</ul>")
         } else {
            document.write("<li>["+p+"] => "+theObj[p]+"</li>");
         }
      }
      document.write("</ul>")
   }
}



