function navegacaoPop(	vForm, vProgramaCod, vSiteInclude, vTemplate, largura  , altura )
{
	var w=largura;
	
	if(altura!="99999999")
		var h=altura;
	else
		var h=400;
		
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	var param = Math.floor(Math.random()*60);
	
	window.open( '' ,'win_'+vProgramaCod+param , 'left='+winl+',top='+wint+',width='+w+',height='+h+',toolbar=yes,resizable=yes,scrollbars=yes' );
	//window.open( '' ,'win', 'left='+winl+',top='+wint+',width='+w+',height='+h+',toolbar=yes,resizable=yes,scrollbars=yes,status=yes' );
		
	var tahgetantigo= vForm.target;
	vForm.target = "win_"+vProgramaCod+param;
	navegacaoJanela(vForm, vProgramaCod, vSiteInclude, vTemplate);
	vForm.target=tahgetantigo;
	return true;	
}

/*
function navegacaoPop(	vForm, vProgramaCod, vSiteInclude, vTemplate, largura  , altura )
{
	var w=largura;
	
	if(altura!="99999999")
		var h=altura;
	else
		var h=400;
		
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	
	//window.open( '' ,'win', 'left='+winl+',top='+wint+',width='+w+',height='+h+',toolbar=0,resizable=0,scrollbars=yes' );
	window.open( '' ,'win', 'left='+winl+',top='+wint+',width='+w+',height='+h+',toolbar=yes,resizable=yes,scrollbars=yes,status=yes' );
		
	var tahgetantigo= vForm.target;
	vForm.target = "win";
	navegacaoJanela(vForm, vProgramaCod, vSiteInclude, vTemplate);
	vForm.target=tahgetantigo;
	return true;	
}
*/
function navegacaoJanela(vForm, vProgramaCod, vSiteInclude, vTemplate)
{
	if(!vForm)			vForm = document.formPadrao;

	if(!vProgramaCod)		vForm.ProgramaCod.value = "";
	else					vForm.ProgramaCod.value = vProgramaCod;
	
	if(!vSiteInclude)		vForm.SiteInclude.value = "";
	else					vForm.SiteInclude.value = vSiteInclude;
	
	if(!vTemplate)			vForm.Template.value = "";
	else					vForm.Template.value = vTemplate;
	
	vForm.submit();
}
	
function EnviarLogin(vForm, SiteInclude)
{
	if(!vForm)			vForm = document.formPadrao;
	
	if(!vForm.Login.value)   
	{
		alert("Por favor, digite o login.");
		vForm.Login.focus();
		return false;
	}
	
	if(!vForm.Senha.value)   
	{
		alert("Por favor, digite a senha.");
		vForm.Senha.focus();
		return false;
	}
	
	vForm.SiteInclude.value=SiteInclude;
	vForm.submit();
}

function mouseOver(cursor)
{
	cursor.style.cursor = 'pointer';
}

function mouseOut(cursor)
{
	cursor.style.cursor = 'default';
}

function somenteNumeros()
{
	var key_code = window.event.keyCode;
	
	if( !(key_code>=48 && key_code<=57) && !(key_code>=96 && key_code<=105) 
		&& key_code!=9 && key_code!=8
		&& key_code!=36 && key_code!=35
		&& key_code!=18 && key_code!=16
		&& key_code!=46 )
		window.event.returnValue = 0;
}

function somenteDatas()
{
	var key_code = window.event.keyCode;
	
	if( !(key_code>=48 && key_code<=57) && !(key_code>=96 && key_code<=105) 
		&& key_code!=9 && key_code!=8
		&& key_code!=36 && key_code!=35
		&& key_code!=18 && key_code!=16
		&& key_code!=46 && key_code!=193
		&& key_code!=111 )
		window.event.returnValue = 0;
}

function limparData(objeto)
{
	if(objeto.value=="DD/MM/YYYY")
		objeto.value = "";
}


function submeterEnterLogin(vInclude)
{
	var key_code = window.event.keyCode;
	
	if(key_code==13)
		EnviarLogin( document.formLogin, vInclude);
}


function submeterEnterConsulta()
{
	var key_code = window.event.keyCode;
	
	if(key_code==13)
		alert('ENTER');
}

/* FUNÇÃO PARA MASCARA DE TELEFONE */
function MascTel(campo) 
{ 
      qtdcaracteres = (campo.value).length; 

      if(qtdcaracteres == '') 
        campo.value = campo.value + "("; 

     if(qtdcaracteres == 3) 
        campo.value = campo.value + ")"; 

     if(qtdcaracteres == 8) 
        campo.value = campo.value + "-"; 
} 

/*	FUNÇÃO PARA MASCARA DE CEP */
function MascCep(campo) 
{ 
      qtdcaracteres = (campo.value).length; 

      if(qtdcaracteres == 5) 
        campo.value = campo.value + "-"; 
} 

/* FUNÇÃO PARA MASCARA DE DATA */

function MascData(campo) 
{ 
      qtdcaracteres = (campo.value).length; 

      if(qtdcaracteres == 2 || qtdcaracteres == 5) 
        campo.value = campo.value + "/"; 
}

/* função  que formata cnpj */
function FormataCNPJ(Campo, teclapres){

	var tecla = teclapres.keyCode;

	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1 ;

	
	if (tecla != 9 && tecla != 8){
		if (tam > 2 && tam < 6)
			Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		if (tam >= 6 && tam < 9)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		if (tam >= 9 && tam < 13)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		if (tam >= 13 && tam < 15)
			Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
		}
}


/* funcão que formata o CPF */
function FormataCPF(Campo, teclapres){
	var tecla = teclapres.keyCode;
	
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");

	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8){
		if (tam > 3 && tam < 7)
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		if (tam >= 7 && tam <10)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		if (tam >= 10 && tam < 12)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
		}
}




// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// April 20, 2005: Fixed the removeSelectedOptions() function to 
//                 correctly handle single selects
// June 12, 2003: Modified up and down functions to support more than
//                one selected option
/*
DESCRIPTION: These are general functions to deal with and manipulate
select boxes. Also see the OptionTransfer library to more easily 
handle transferring options between two lists

COMPATABILITY: These are fairly basic functions - they should work on
all browsers that support Javascript.
*/


// -------------------------------------------------------------------
// hasOptions(obj)
//  Utility function to determine if a select object has an options array
// -------------------------------------------------------------------
function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}

// -------------------------------------------------------------------
// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
//  This is a general function used by the select functions below, to
//  avoid code duplication
// -------------------------------------------------------------------
function selectUnselectMatchingOptions(obj,regex,which,only) {
	if (window.RegExp) {
		if (which == "select") {
			var selected1=true;
			var selected2=false;
			}
		else if (which == "unselect") {
			var selected1=false;
			var selected2=true;
			}
		else {
			return;
			}
		var re = new RegExp(regex);
		if (!hasOptions(obj)) { return; }
		for (var i=0; i<obj.options.length; i++) {
			if (re.test(obj.options[i].text)) {
				obj.options[i].selected = selected1;
				}
			else {
				if (only == true) {
					obj.options[i].selected = selected2;
					}
				}
			}
		}
	}
		


// -------------------------------------------------------------------
// selectMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Currently-selected options will not be changed.
// -------------------------------------------------------------------
function selectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",false);
	}
// -------------------------------------------------------------------
// selectOnlyMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Selected options that don't match will be un-selected.
// -------------------------------------------------------------------
function selectOnlyMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",true);
	}
// -------------------------------------------------------------------
// unSelectMatchingOptions(select_object,regex)
//  This function Unselects all options that match the regular expression
//  passed in. 
// -------------------------------------------------------------------
function unSelectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"unselect",false);
	}
	
// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) {
	var o = new Array();
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a 
//  multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before 
//  submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(obj) {
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}
	
// -------------------------------------------------------------------
// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes. Works best with
//  multi-select boxes to create the common Windows control effect.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box.
//  If a third argument of 'false' is passed, then the lists are not
//  sorted after the move.
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT or the options. If 
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  You can also put this into the <SELECT> object as follows:
//    onDblClick="moveSelectedOptions(this,this.form.target)
//  This way, when the user double-clicks on a value in one box, it
//  will be transferred to the other (in browsers that support the 
//  onDblClick() event handler).
// -------------------------------------------------------------------
function moveSelectedOptions(from,to) {
	// Unselect matching options, if required
	if (arguments.length>3) {
		var regex = arguments[3];
		if (regex != "") {
			unSelectMatchingOptions(from,regex);
			}
		}
	// Move them over
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
			to.options[index] = new Option( o.text, o.value, false, false);
			}
		}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(from);
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of 
//  moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(from,to) {
	var options = new Object();
	if (hasOptions(to)) {
		for (var i=0; i<to.options.length; i++) {
			options[to.options[i].value] = to.options[i].text;
			}
		}
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
				if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
				to.options[index] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  Move all options from one select box to another.
// -------------------------------------------------------------------
function moveAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		moveSelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		moveSelectedOptions(from,to,arguments[2]);
		}
	else if (arguments.length==4) {
		moveSelectedOptions(from,to,arguments[2],arguments[3]);
		}
	}

// -------------------------------------------------------------------
// copyAllOptions(select_object,select_object[,autosort(true/false)])
//  Copy all options from one select box to another, instead of
//  removing items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		copySelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		copySelectedOptions(from,to,arguments[2]);
		}
	}

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}
	
// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
//  Remove all selected options from a list
//  (Thanks to Gene Ninestein)
// -------------------------------------------------------------------
function removeSelectedOptions(from) { 
	if (!hasOptions(from)) { return; }
	if (from.type=="select-one") {
		from.options[from.selectedIndex] = null;
		}
	else {
		for (var i=(from.options.length-1); i>=0; i--) { 
			var o=from.options[i]; 
			if (o.selected) { 
				from.options[i] = null; 
				} 
			}
		}
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// removeAllOptions(select_object)
//  Remove all options from a list
// -------------------------------------------------------------------
function removeAllOptions(from) { 
	if (!hasOptions(from)) { return; }
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
		} 
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// addOption(select_object,display_text,value,selected)
//  Add an option to a list
// -------------------------------------------------------------------
function addOption(obj,text,value,selected) {
	if (obj!=null && obj.options!=null) {
		obj.options[obj.options.length] = new Option(text, value, false, selected);
		}
	}
function valida_form(OBJ)
{
	with(OBJ)
	{
		
		var Fields = validar.value.split(",");
		var Tipos = tipos.value.split(",");
		var FieldValue;
		for (i=0; i<Fields.length; i++)
		{
			FieldValue = document.getElementById(Fields[i]).value;
			
				if (FieldValue.length == 0)
				{
					alert("Campo obrigatório não preenchido!");
					document.getElementById(Fields[i]).focus();
					return false;
				}
				
				if (document.getElementById(Fields[i]).lang == 'email' && (FieldValue.indexOf("@") == -1 || FieldValue.indexOf(".") == -1))
				{
					alert("O e-mail informado não é válido");
					document.getElementById(Fields[i]).focus();
					return false;
				}
				if (document.getElementById(Tipos[i]).lang == "senha" && FieldValue.length < 4)
				{
					alert("A senha senha deve ter ao menos 4 dígitos");
					document.getElementById(Fields[i]).focus();
					return false;
				}
				/*
				if (Fields[i] == "senha" && confirma_senha.value != FieldValue)
				{
					alert("A senha informada não confere com a confirmação");
					document.getElementById(Fields[i]).focus();
					return false;
				}
				*/
		}
	}
	return true;
}

















/*** 
Não sei quem foi o autor desse script, mas foi o primeiro que eu peguei sem nenhum erro 
e completamente adaptável, 

os campos no formulário aparecem assim(evento onKeypress) 


altere  
onkeypress="return txtBoxFormat(document.NOME_FORMULARIO, 'NOME_CAMPO', '(99) 9999-9999', event);" 
  
* Descrição.: formata um campo do formulário de  
* acordo com a máscara informada...  
* Parâmetros: - objForm (o Objeto Form)  
* - strField (string contendo o nome  
* do textbox)  
* - sMask (mascara que define o  
* formato que o dado será apresentado,  
* usando o algarismo "9" para  
* definir números e o símbolo "!" para  
* qualquer caracter...  
* - evtKeyPress (evento)  
* Uso.......: <input type="textbox"  
* name="xxx".....  
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);">  
* Observação: As máscaras podem ser representadas como os exemplos abaixo:  
* CEP -> 99.999-999  
* CPF -> 999.999.999-99  
* CNPJ -> 99.999.999/9999-99  
* Data -> 99/99/9999  
* Tel Resid -> (99) 999-9999  
* Tel Cel -> (99) 9999-9999  
* Processo -> 99.999999999/999-99  
* C/C -> 999999-!  
* E por aí vai...  
***/ 

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) { 
     var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla; 

     if(document.all) { // Internet Explorer 
       nTecla = evtKeyPress.keyCode; } 
     else if(document.layers) { // Nestcape 
       nTecla = evtKeyPress.which; 
     } 

     sValue = objForm[strField].value; 

     // Limpa todos os caracteres de formatação que 
     // já estiverem no campo. 
     sValue = sValue.toString().replace( "-", "" ); 
     sValue = sValue.toString().replace( "-", "" ); 
     sValue = sValue.toString().replace( ".", "" ); 
     sValue = sValue.toString().replace( ".", "" ); 
     sValue = sValue.toString().replace( "/", "" ); 
     sValue = sValue.toString().replace( "/", "" ); 
     sValue = sValue.toString().replace( "(", "" ); 
     sValue = sValue.toString().replace( "(", "" ); 
     sValue = sValue.toString().replace( ")", "" ); 
     sValue = sValue.toString().replace( ")", "" ); 
     sValue = sValue.toString().replace( " ", "" ); 
     sValue = sValue.toString().replace( " ", "" ); 
     fldLen = sValue.length; 
     mskLen = sMask.length; 

     i = 0; 
     nCount = 0; 
     sCod = ""; 
     mskLen = fldLen; 

     while (i <= mskLen) { 
       bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/")) 
       bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " ")) 

       if (bolMask) { 
         sCod += sMask.charAt(i); 
         mskLen++; } 
       else { 
         sCod += sValue.charAt(nCount); 
         nCount++; 
       } 

       i++; 
     } 

     objForm[strField].value = sCod; 

     if (nTecla != 8) { // backspace 
       if (sMask.charAt(i-1) == "9") { // apenas números... 
         return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9 
       else { // qualquer caracter... 
         return true; 
       } } 
     else { 
       return true; 
     } 
   } 
//Fim da Função Máscaras Gerais 
