	function VerificaData(digData) 
	{
		var bissexto = 0;
		var data = digData; 
		var tam = data.length;
		if (tam == 10) 
		{
				var dia = data.substr(0,2)
				var mes = data.substr(3,2)
				var ano = data.substr(6,4)
				if ((ano > 1900)||(ano < 2100))
				{
						switch (mes) 
						{
								case '01':
								case '03':
								case '05':
								case '07':
								case '08':
								case '10':
								case '12':
										if  (dia <= 31) 
										{
												return true;
										}
										break
								
								case '04':              
								case '06':
								case '09':
								case '11':
										if  (dia <= 30) 
										{
												return true;
										}
										break
								case '02':
										/* Validando ano Bissexto / fevereiro / dia */ 
										if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)) 
										{ 
												bissexto = 1; 
										} 
										if ((bissexto == 1) && (dia <= 29)) 
										{ 
												return true;                             
										} 
										if ((bissexto != 1) && (dia <= 28)) 
										{ 
												return true; 
										}                       
										break                                           
						}
				}
		}       
		//alert("A Data "+data+" é inválida!");
		return false;
	}

	function Left(str, n, inicio){
		if (n <= 0)
			return "";
		else if (n > String(str).length)
			return str
		else
			return String(str).substring(inicio,n);
		}
	
	function Right(str, n){
		if (n <= 0)
			return "";
		else if (n > String(str).length)
			return str;
		else
			var iLen = String(str).length;
			return String(str).substring(iLen, iLen - n);
	}

	function verificaNSerie(mdl){
		
		var opt = document.getElementsByTagName('option');
		var efetuaValidacao = 0;
		/* SABER SE MÁQUINA É NACIONAL */
		for(i=0;i<opt.length;i++){
			
			var optAtual = opt[i];
			
			if(optAtual.getAttribute('nacional') != null && optAtual.getAttribute('value') == mdl){
	
				efetuaValidacao = optAtual.getAttribute('nacional');

			}
		}
		
		//var maquina = document.getElementById('cboModelo').options[document.getElementById('cboModelo').selectedIndex].text;
		var maquina = document.getElementById('txtNumeroSerie').value;		
		var campo   = document.getElementById('txtNumeroSerie').value;

		if(/*(Left(maquina,1,0) == 'c' || Left(maquina,1,0) == 'C') &&* */efetuaValidacao == 0){

			//if(Left(campo,1,0) != 'c' && Left(campo,1,0) != 'C'){alert('Número de série inválido!');return false;}
			
			//if(Left(campo,1,0) < 0 || Left(campo,1,0) > 9 || isNaN(Left(campo,1,0)) || Left(campo,1,0) == ''){alert('Número de série inválido!');return false;}			
			
			//if(Left(campo,1,2) < 0 || Left(campo,1,2) > 3 || isNaN(Left(campo,1,2)) || Left(campo,1,2) == ''){alert('Número de série inválido!');return false;}			
			/*
			if(Left(campo,2,3) < 0 || Left(campo,2,3) > 6 || isNaN(Left(campo,2,3)) || Left(campo,2,3) == ''){alert('Número de série inválido!');return false;}			

			if(Left(campo,3,4) < 0 || Left(campo,3,4) > 6 || isNaN(Left(campo,3,4)) || Left(campo,3,4) == ''){alert('Número de série inválido!');return false;}			

			if(Left(campo,4,5) < 0 || Left(campo,4,5) > 9 || isNaN(Left(campo,3,4)) || Left(campo,4,5) == ''){alert('Número de série inválido!');return false;}			
			
			if(Left(campo,5,6) < 0 || Left(campo,5,6) > 9 || isNaN(Left(campo,5,6)) || Left(campo,5,6) == ''){alert('Número de série inválido!');return false;}			

			if(Left(campo,6,7) < 0 || Left(campo,6,7) > 9 || isNaN(Left(campo,6,7)) || Left(campo,6,7) == ''){alert('Número de série inválido!');return false;}			

			if(Left(campo,7,8) < 0 || Left(campo,7,8) > 9 || isNaN(Left(campo,7,8)) || Left(campo,7,8) == ''){alert('Número de série inválido!');return false;}			
			*/
			return true;

		}else{

			return true;

		}
		
	}


function confirmForm() {
if (confirm("Se você recebeu a peça via SAC, favor não incluí-la!"))
{
window.open('ordem_servico_pop_peca.php?aut_codigo=' + document.getElementById('postAutorizado').value, 'popPeca', 'width=400, height=300, statusbar=no, scrollbars=yes');
}
else
return false;
}
function isNumeric(eventObj, obj){
	var CodTecla;

	if (document.all) 
		CodTecla=eventObj.keyCode;
	else
		CodTecla=eventObj.which;

	var str=obj.value

	if((CodTecla < 48 || CodTecla > 58) && (CodTecla != 46)){ 
		return false;
	}

	return true;
}

/*
	Descrição: Passa valores para os objetos. Essa fução é usada especialmente pela Pop De Busca.
			   O parametro ar deve ser um array com três colunas. 
			   Ex: ar[{int nLinhas}][3]; 
			   Onde a coluna{0} guarda o id(DOM) do objeto, a coluna{2} leva o valor do mesmo e
			   a coluna{3} é um valor boolean (true ou false) que indica se esse campo deve ser 
			   procurado na janela que abriu essa outra janela 
			   entende-se que assim a janela que esta usando essa função é uma Pop.
	Por......: Lucas Henrique Vicente
	Data.....: 17/08/2004
	
*/
function popBuscaPassaValor(ar) {
	var campo;
	var valor;
	for (var i=0; i<ar.length; i++) {
			campo = (ar[i][2] ? window.opener.document.getElementById(ar[i][0]) : document.getElementById(ar[i][0]));
			valor = ar[i][1];
			campo.value = valor;
	}
		
}

/*
	Descrição: Coloca máscara em Telefones ex.: 19-33333333
	Por......: Lucas Henrique Vicente
	Data.....: 17/08/2004
*/
function mascTel(c, e) {
	var appName = window.navigator.appName;
	var txtField = document.getElementById(c);
	var keyCode = null;
	
	txtField.maxLength = 14;
	
	if (document.all) keyCode = e.keyCode;
	else keyCode = e.which;	

	if ((keyCode < 48 || keyCode > 58) && keyCode != 8) {
		return false;
	} else {
		if (keyCode != 8) {
			switch(txtField.value.length) {
				case 2 : txtField.value = "(" + txtField.value + ") "; break;
				case 9 : txtField.value += "-"; break;
			}
		}
		return true;
	}
}

/*
	Descrição: Coloca máscara em Telefones ex.: 19-33333333
	Por......: Lucas Henrique Vicente
	Data.....: 17/08/2004
*/
function mascTel2(c, e) {
	var appName = window.navigator.appName;
	var txtField = document.getElementById(c);
	var keyCode = null;
	
	txtField.maxLength = 11;
	
	if (document.all) keyCode = e.keyCode;
	else keyCode = e.which;	
	
	if ((keyCode < 48 || keyCode > 58) && keyCode != 8) {
		return false;
	} else {
		if (keyCode != 8) {
			switch(txtField.value.length) {
				case 2 : txtField.value += "-"; break;
			}
		}
		return true;
	}
}

/*
	Descrição: Coloca máscara em CNPJs
	Por......: Lucas Henrique Vicente
	Data.....: 17/08/2004
*/
function mascCEP(c, e) {
	var appName = window.navigator.appName;
	var txtField = document.getElementById(c);
	var keyCode = null;
	
	txtField.maxLength = 9;
	
	if (document.all) keyCode = e.keyCode;
	else keyCode = e.which;	
	
	if ((keyCode < 48 || keyCode > 58) && keyCode != 8) {
		return false;
	} else {
		if (keyCode != 8) {
			switch(txtField.value.length) {
				case 5 : txtField.value += "-"; break;
			}
		}
		return true;
	}
}


/*
	Descrição: Coloca máscara em CNPJs
	Por......: Lucas Henrique Vicente
	Data.....: 17/08/2004
*/
function mascCPF(c, e) {
	var appName = window.navigator.appName;
	var txtField = document.getElementById(c);
	var keyCode = null;
	
	txtField.maxLength = 14;
	
	if (document.all) keyCode = e.keyCode;
	else keyCode = e.which;	
	
	if ((keyCode < 48 || keyCode > 58) && keyCode != 8) {
		return false;
	} else {
		if (keyCode != 8) {
			switch(txtField.value.length) {
				case 3  :
				case 7  : txtField.value += "."; break;
				case 11 : txtField.value += "-"; break;
			}
		}
		return true;
	}
}


/*
	Descrição: Coloca máscara em CNPJs
	Por......: Lucas Henrique Vicente
	Data.....: 17/08/2004
*/
function mascCNPJ(c, e) {
	var appName = window.navigator.appName;
	var txtField = document.getElementById(c);
	var keyCode = null;
	
	txtField.maxLength = 18;
	
	if (document.all) keyCode = e.keyCode;
	else keyCode = e.which;
	
	if ((keyCode < 48 || keyCode > 58) && keyCode != 8) {
		return false;
	} else {
		if (keyCode != 8) {
			switch(txtField.value.length) {
				case 2  :
				case 6  : txtField.value += "."; break;
				case 10 : txtField.value += "/"; break;
				case 15 : txtField.value += "-"; break;
			}
		}
		return true;
	}
}

/* 
	Máscara de para datas
	Por..: Lucas Henrique Vicente
	Data.: 26/07/2004
*/
function mascData(fieldid, nextfieldid, e) {
	var appName = window.navigator.appName;
	var txtField = document.getElementById(fieldid);
	var keyCode = null;
	
	txtField.maxLength = 18;
	
	if (document.all) keyCode = e.keyCode;
	else keyCode = e.which;
	
	if ((keyCode < 48 || keyCode > 58) && keyCode != 8) {
		return false;
	} else {
		if (keyCode != 8) {
			var field = document.getElementById(fieldid);
			field.maxLength = 10;
			if (nextfieldid != "")
				var next  = document.getElementById(nextfieldid);
			
			var reg1 = /^[0-9]{2}$/;
			var reg2 = /^[0-9]{2}\/[0-9]{2}$/;
			var reg3 = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
			
			if (reg1.test(field.value) || reg2.test(field.value)) {
				field.value += "/";
			} else if (reg3.test(field.value)) {
				if (nextfieldid != "") {
					next.focus();
					//next.select();
				}
			}
		}
		return true;
	} 
}

function ret(e) {
	var appName = window.navigator.appName;
	var keyCode;
	if (appName == "Netscape") {
		keyCode = e.which;
		if ((!(keyCode >= 48 && keyCode <= 57)) && (keyCode != 8 && keyCode != 127))
			return false;
	} else {
		keyCode = event.keyCode;
		if ((!(keyCode >= 48 && keyCode <= 57)) && (keyCode != 8 && keyCode != 127))
			return false;
	}
}

/*
	Descrição: Trava caracteres só premite digitar números
	Por......: Lucas Henrique Vicente
	Data.....: 26/07/2004
	ex.: campoNumerico(this, event)
*/
function campoNumerico(obj, evt) {
	var CodTecla;

	if (document.all){ CodTecla = evt.keyCode; } 
	else { CodTecla = evt.which; }
			
	var str = obj.value;
	
	if((CodTecla >= 48 && CodTecla <= 58)	|| 
	   (CodTecla >= 96 && CodTecla <= 105)	|| 
	   (CodTecla == 46)						||
	   (CodTecla == 8)						||
	   (CodTecla == 9)						||
	   (CodTecla == 0)						||
	   (CodTecla == 45)) { 
		return true;
	}

	return false;
}


//-----------------------------------------------------
//Funcao: MascaraMoeda
//Sinopse: Mascara de preenchimento de moeda
//Parametro:
//   objTextBox : Objeto (TextBox)
//   SeparadorMilesimo : Caracter separador de milésimos
//   SeparadorDecimal : Caracter separador de decimais
//   e : Evento
//Retorno: Booleano
//Autor: Gabriel Fróes - www.codigofonte.com.br
//-----------------------------------------------------
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
	
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}


/* 
	Máscara de valor monetário
	Por..: Lucas Henrique Vicente
	Data.: 26/07/2004
*/
function valorMonetario(id, e) {
	var txtBox   = document.getElementById(id);	
	if (!campoNumerico(id, e)) {
		return false;
	} else {
		valorDecimal(id, e);
		
		var aux		 = txtBox.value.replace(".", "");
		for (var j=0; j<20; j++) aux = aux.replace(".", "");
		
		var parteInt = aux.split(",");		
		
		if (parteInt.length == 2) {
			var i, start;
			var strMilhar = new String(parteInt[0]);
			var milhar    = new Array();
			var nPontos   = Math.floor(parteInt[0].length / 3);	
			
			for (i=0; i<nPontos; i++) {
				start = strMilhar.length - ((i + 1) * 3);
				milhar[i] = strMilhar.substr(start, 3);					
			}
			
			if (start > 0) milhar[milhar.length] = strMilhar.substr(0, start);				
			
			if (milhar.length > 0) {
				txtBox.value = "";
				for (i=(milhar.length-1); i>=0; i--) {
					txtBox.value += milhar[i] + (i == 0 ? "" : ".");
				}
				
				txtBox.value += "," + parteInt[1];
			}
		}
		return true;
	}
}

/* 
	Máscara de valor decimal
	Por..: Lucas Henrique Vicente
	Data.: 26/07/2004
*/
function valorDecimal(id, e) {
	var txtBox   = document.getElementById(id);
	var offSet;
	var keyCode = null;
	
	if (document.all) keyCode = e.keyCode;
	else keyCode = e.which;	
	
	if (!campoNumerico(id, e)) {
		return false;
	} else {
		if (txtBox.value.length >= 2) {
			if (txtBox.value.length == 4 && 
				txtBox.value.substr((txtBox.value.length - 3), 1) == "," &&
				e.keyCode == 8) 
				txtBox.value = txtBox.value.replace(",", "");
			else if (txtBox.value.length >= 2 && e.keyCode != 8)
				putComma(txtBox, 1);
			else if (txtBox.value.length >= 2 && e.keyCode == 8)
				putComma(txtBox, 3);
		}
	}	
}

/* 
	Coloca vírgula
	Por..: Lucas Henrique Vicente
	Data.: 26/07/2004
*/
function putComma(ctl, precision) {
	ctl.value = ctl.value.replace(",", "");
	var begin = (ctl.value.length - precision);
	var end   = begin;
	
	if (begin >= 0) {
		var parteDec = ctl.value.substr(begin, precision);
		var parteInt = ctl.value.substr(0, end);
		ctl.value	 = parteInt + "," + parteDec;
	}
}

/* 
	Máscara de para datas
	Por..: Lucas Henrique Vicente
	Data.: 26/07/2004
*/
function dateMask(fieldid, nextfieldid) {
	var field = document.getElementById(fieldid);
	if (nextfieldid != "")
		var next  = document.getElementById(nextfieldid);
	
	var reg1 = /^[0-9]{2}$/;
	var reg2 = /^[0-9]{2}\/[0-9]{2}$/;
	var reg3 = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	
	if (reg1.test(field.value) || reg2.test(field.value)) {
		field.value += "/";
	} else if (reg3.test(field.value)) {
		if (nextfieldid != "") {
			next.focus();
			//next.select();
		}
	} 
}

/* 
	Função que verifica se os campos obrigatórios de um form
	estão preenchidos
	Por..: Lucas Henrique Vicente
	Data.: 26/07/2004
*/
function checkFill(arrFields, msg) {
	var len = arrFields.length;
	var i, f;
	for (i=0; i<len; i++) {
		f = document.getElementById(arrFields[i]);
		if (f.value == "") { 
			if (msg != "") alert(msg);
			return false;
		}
	}
}

/* 
	Função que abre uma popup em tempo de execução para informar uma ação.
	Quando o postback termina ele fecha a mesma.
	Por..: André Luis Bassi
	Data.: 26/07/2004
*/

var workingWin;
function showWorking(phtml) {
	x = screen.availWidth / 2 - 200;
	y = screen.availHeight / 2 - 50;
	workingWin = window.open(phtml, "working",
	"left=" + x + ",top=" + y +
	",height=100,width=400,fullscreen=no,toolbar=no," +
	"status=no,menubar=no,scrollbars=no,resizable=no," +
	"directories=no,location=no");
}

function clearWorking() {
	try {
		workingWin.close();
	} catch (e) {}
}



/* 
	Função que abre uma popup qualquer centralizada na tela.
	Por..: André Luis Bassi
	Data.: 30/07/2004
*/
function Popup(pPagina, pNome, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no,status='+scroll
	win = window.open(pPagina, pNome, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

/* 
	Função que determina o foco a um controle dentro do formulário corrente
	Por..: Danilo Lima
	Data.: 16/11/2004
*/

function Foco(strControle)
{
	document.all('strControle').focus();
}

function checaCPF(c) {
	var ctr = document.getElementById(c);
	CPF = ctr.value.replace('.', '').replace('.', '').replace('-', '');
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999")
		return false;
	soma = 0;
	for (i=0; i < 9; i ++)
		soma += parseInt(CPF.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(9))) {
		ctr.focus();
		alert('CPF inválido!');
	}
	soma = 0;
	for (i = 0; i < 10; i ++)
		soma += parseInt(CPF.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(10))) {
		ctr.focus();
		alert('CPF inválido!');
	}
 }
 

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function


