// Mudanca de estilo(cor)
function onIn (Item) {
	Item.style.color = "Red";
	}
function onOut (Item) {
	Item.style.color = "Black";
	}
function onInBranco (Item) {
	Item.style.color = "Red";
	}
function onOutBranco (Item) {
	Item.style.color = "White";
	}
function onOutVerde (Item) {
	Item.style.color = "DarkGreen";
	}
function onOutVermelho (Item) {
	Item.style.color = "Red";
	}
function onOutAmarelo (Item) {
	Item.style.color = "Darkorange";
	}	
	
//Menu Principal(Efeito de sub menus)
var img1, img2;
img1 = new Image();
img1.src = "../images/plus.gif";
img2 = new Image();
img2.src = "../images/minus.gif";

function doOutline() {
  var targetId, srcElement, targetElement,targetactive;
  srcElement = window.event.srcElement;
  if (srcElement.className == "LEVEL1") {
    srcElement = srcElement.id
    //alert(srcElement);
    srcElement = srcElement.substr(0, srcElement.length-1);
 
    targetId = srcElement + "s";
  
    srcElement = srcElement + "i";

    srcElement = document.all(srcElement);
    targetElement = document.all(targetId);
    
     
    if (targetElement) {
      if (targetElement.style.display == "none") {
        targetElement.style.display = "";
        
        srcElement.src = "../images/minus.gif";
      } else {
        targetElement.style.display = "none";
        srcElement.src = "../images/plus.gif";
      }
    }
  }
}
document.onclick = doOutline;

function isNumeric (strValor) 
{ 
	var re = /\./g; 
	var strNewValor = strValor.replace (re, ""); 
	re = /,/g; 
	strNewValor = strNewValor.replace (re, "."); 
	return !isNaN(strNewValor) && (strNewValor != ""); 
} 

function isDateRange (strDtDe, strDtAte) {
	var isOk;
	var strDia;
	var strMes;
	var strAno;
	var dtValorDe;
	var dtValorAte;
	var strChar;

	isOk = true;

	if (strDtDe.length != 10) {
		alert ("Data inicial inválida, ano deve ser informado com 4 dígitos.");
		isOk = false;
		}

	if (isOk) {
		strDia = strDtDe.substr (0, 2);
		strMes = strDtDe.substr (3, 2);
		strAno = strDtDe.substr (6, 4);

		if (isNaN (strDia)) {
			alert ("Dia inicial não reconhecido como número.");
			isOk = false;
			}

		if (isOk && isNaN (strMes)) {
			alert ("Mês inicial não reconhecido como número.");
			isOk = false;
			}

		if (isOk && isNaN (strAno)) {
			alert ("Ano inicial não reconhecido como número.");
			isOk = false;
			}

		if (isOk) {

			if (Number(strAno) < 1980) {
				alert ("Ano inicial não pode ser inferior a 1980.");
				isOk = false;
				}

			if (isOk && Number(strAno) > 2099) {
				alert ("Ano inicial não pode ser superior a 2099.");
				isOk = false;
				}

			if (isOk) {

				dtValorDe = new Date (strAno, Number(strMes) - 1, strDia);

				if (isNaN(dtValorDe)) {
					alert ("Data inicial inválida.");
					isOk = false;
					}

				if (isOk && dtValorDe.getDate() != Number(strDia)) {
					alert ("Data inicial inválida.");
					isOk = false;
					}

				if (isOk && dtValorDe.getMonth() != Number(strMes) - 1) {
					alert ("Data inicial inválida.");
					isOk = false;
					}

				if (isOk && dtValorDe.getFullYear() != Number(strAno)) {
					alert ("Data inicial inválida.");
					isOk = false;
					}
				}
			}
		}
	if (isOk) {
		if (strDtAte.length != 10) {
			alert ("Data final inválida, ano deve ser informado com 4 dígitos.");
			isOk = false;
			}

		if (isOk) {
			strDia = strDtAte.substr (0, 2);
			strMes = strDtAte.substr (3, 2);
			strAno = strDtAte.substr (6, 4);

			if (isNaN (strDia)) {
				alert ("Dia final não reconhecido como número.");
				isOk = false;
				}

			if (isOk && isNaN (strMes)) {
				alert ("Mês final não reconhecido como número.");
				isOk = false;
				}

			if (isOk && isNaN (strAno)) {
				alert ("Ano final não reconhecido como número.");
				isOk = false;
				}

			if (isOk) {

				if (Number(strAno) < 1980) {
					alert ("Ano final não pode ser inferior a 1980.");
					isOk = false;
					}

				if (isOk && Number(strAno) > 2099) {
					alert ("Ano final não pode ser superior a 2099.");
					isOk = false;
					}

				if (isOk) {

					dtValorAte = new Date (strAno, Number(strMes) - 1, strDia);

					if (isNaN(dtValorAte)) {
						alert ("Data final inválida.");
						isOk = false;
						}

					if (isOk && dtValorAte.getDate() != Number(strDia)) {
						alert ("Data final inválida.");
						isOk = false;
						}

					if (isOk && dtValorAte.getMonth() != Number(strMes) - 1) {
						alert ("Data final inválida.");
						isOk = false;
						}

					if (isOk && dtValorAte.getFullYear() != Number(strAno)) {
						alert ("Data final inválida.");
						isOk = false;
						}
					}
				}
			}
		}
	if (isOk) {
		strChar = strDtDe.substr (2, 1);
		if (strChar != '/') {
			isOk = false;
			}
		strChar = strDtDe.substr (5, 1);
		if (strChar != '/') {
			isOk = false;
			}
		strChar = strDtAte.substr (2, 1);
		if (strChar != '/') {
			isOk = false;
			}
		strChar = strDtAte.substr (5, 1);
		if (strChar != '/') {
			isOk = false;
			}
		if (!isOk) {
			alert ("Data deve ser informada no formato dd/mm/aaaa.");
			isOk = false;
			}
		}
	if (isOk) {
		if (dtValorDe > dtValorAte) {
			alert ("Data final não pode ser inferior à data inicial.");
			isOk = false;
			}
		}
	return isOk;
	}

function onToUpper()
	{
	var caracter
	
	caracter = String.fromCharCode(window.event.keyCode);
	caracter = caracter.toUpperCase();
	window.event.keyCode = caracter.charCodeAt();	
	}

function DateAdd (strType, intQuant, strDate) {
	var strOut = '';
	var dtIn;
	var strDay;
	var strMonth;
	var strYear;
	
	if (isDate (strDate)) {
		dtIn = ConvertDate (strDate);
		
		switch (strType) {
			case 'day':
				intDay = dtIn.getDate();
				intDay += Number(intQuant);
				dtIn.setDate (intDay);
				break;
				
			case 'month':
				intMonth = dtIn.getMonth();
				intMonth += Number(intQuant);
				dtIn.setMonth (intMonth);
				break;
			
			case 'year':
				intYear = dtIn.getFullYear();
				intYear += Number(intQuant);
				dtIn.setFullYear (intYear);
				break;
				
			}
		
		strOut = DateToStr(dtIn);
		}
	else {
		strOut = 'Data inválida';
		}
		
	return (strOut);
	}

function isTime (strTime) {
	var isOk;
	var strHora;
	var strMinuto;
	var strSep;

	isOk = true;

	if (strTime.length != 5) {
		alert ("Hora inválida, formato deve ser 'HH:MM'.");
		isOk = false;
		}

	if (isOk) {
		strHora = strTime.substr (0, 2);
		strSep =  strTime.substr (2, 1);
		strMinuto = strTime.substr (3, 2);

		if (isNaN (strHora)) {
			alert ("Hora inválida.");
			isOk = false;
			}

		if (strSep != ":") {
			alert ("Hora inválida, formato deve ser 'HH:MM'.");
			isOk = false;
			}

		if (isOk && isNaN (strMinuto)) {
			alert ("Minuto inválido.");
			isOk = false;
			}

		if (isOk && Number (strHora) < 0) {
			alert ("Hora deve ser maior ou igual a zero.");
			isOk = false;
			}

		if (isOk && Number (strHora) > 23) {
			alert ("Hora deve ser menor ou igual a 23.");
			isOk = false;
			}

		if (isOk && Number (strMinuto) < 0) {
			alert ("Minutos devem ser maiores ou iguais a zero.");
			isOk = false;
			}

		if (isOk && Number (strMinuto) > 59) {
			alert ("Minutos não podem ser maiores que 59.");
			isOk = false;
			}
		}
	return isOk;
	}
	
function onConvVlr(strValor) 
{		
	while (strValor.indexOf(".") != -1)
	    {
		strValor = strValor.replace(".",",");
		}
			
	return strValor.replace(",",".");
}

function FormatDecimal (dblValor, numDecimal)
{
	var strInteiro;
	var strDecimal;
	var strValor = dblValor.toString();

	var re = /\,/;
	strValor = strValor.replace (re, ".");

	if (strValor.indexOf (".") != -1)
	{
		strInteiro = strValor.substring (0, strValor.indexOf ("."));
		strDecimal = strValor.substring (strValor.indexOf (".") + 1);
	}
	else
	{
		strInteiro = strValor;
		strDecimal = "";
	}

	while (numDecimal > strDecimal.length)
	{
		strDecimal += "0";
	}
		
	if (numDecimal < strDecimal.length)
	{
		strDecimal = strDecimal.substr (0, numDecimal);
	}
	strValor = strInteiro;
	if (strDecimal.length > 0)
	{
		strValor += "." + strDecimal;
	}
	return strValor;
}

function FormatNumber (numGeral) 
{
 	var intRaiz = Math.floor (numGeral);
	var intDecimal = Math.round ((numGeral - intRaiz) * 100);
	
	var strRaiz = intRaiz.toString();

	for (intPos = 1; intPos <= strRaiz.length; intPos++) {
		strAux = strRaiz.charAt (strRaiz.length - intPos) + strAux;
		if (intPos != strRaiz.length) {
			if ((intPos / 3) - Math.floor (intPos / 3) == 0) {
				strAux = "," + strAux;
				}
			}
		}

	strRaiz = strAux;
	strAux = intDecimal.toString();

	if (strAux.length < 2) {strAux = "0" + strAux;}
	if (strAux.length > 2) {strAux = strAux.substring (0, 2);}

	return (strRaiz + "." + strAux);
	
	}

function ConvertDate (strDate) 
{
	var strDia = strDate.substr (0, 2);
	var strMes = strDate.substr (3, 2);
	var strAno = strDate.substr (6, 4);
	
	var dtValor = new Date (strAno, Number(strMes) - 1, strDia);

	return (dtValor);
}

function AmericanWay (strNum) 
{
	var rePonto = new RegExp ("[.]");

	while (strNum.match (rePonto)) {
		strNum = strNum.replace (rePonto, "");
		}

	rePonto = new RegExp ("[,]");
	strNum = strNum.replace (rePonto, ".");

	return (strNum);
}


function isDate (strDate) 
{
	var isOk;
	var strDia;
	var strMes;
	var strAno;
	var dtValor;
	var strChar;

	isOk = true;

	if (strDate.length != 10) {
		alert ("Data inválida, ano deve ser informado com 4 dígitos.");
		isOk = false;
		}

	if (isOk) {
		strDia = strDate.substr (0, 2);
		strMes = strDate.substr (3, 2);
		strAno = strDate.substr (6, 4);

		if (isNaN (strDia)) {
			alert ("Dia não reconhecido como número.");
			isOk = false;
			}

		if (isOk && isNaN (strMes)) {
			alert ("Mês não reconhecido como número.");
			isOk = false;
			}

		if (isOk && isNaN (strAno)) {
			alert ("Ano não reconhecido como número.");
			isOk = false;
			}

		if (isOk) {

			if (Number(strAno) < 1980) {
				alert ("Ano não pode ser inferior a 1980.");
				isOk = false;
				}

			if (isOk && Number(strAno) > 2099) {
				alert ("Ano não pode ser superior a 2099.");
				isOk = false;
				}

			if (isOk) {

				dtValor = ConvertDate(strDate);

				if (isNaN(dtValor)) {
					alert ("Data inválida.");
					isOk = false;
					}

				if (isOk && dtValor.getDate() != Number(strDia)) {
					alert ("Data inválida.");
					isOk = false;
					}

				if (isOk && dtValor.getMonth() != Number(strMes) - 1) {
					alert ("Data inválida.");
					isOk = false;
					}

				if (isOk && dtValor.getFullYear() != Number(strAno)) {
					alert ("Data inválida.");
					isOk = false;
					}
				}
			}
		}
	if (isOk) {
		strChar = strDate.substr (2, 1);
		if (strChar != '/') {
			isOk = false;
			}
		strChar = strDate.substr (5, 1);
		if (strChar != '/') {
			isOk = false;
			}
		if (!isOk) {
			alert ("Data deve ser informada no formato dd/mm/aaaa.");
			isOk = false;
			}
		}
	return isOk;
}

function DateToStr (dtIn) {
	var strDay = dtIn.getDate().toString();
	var strMonth = (dtIn.getMonth() + 1).toString();
	var  strYear = dtIn.getFullYear().toString();

	if (strDay.length < 2) { strDay = '0' + strDay; }
	if (strMonth.length < 2) { strMonth = '0' + strMonth; }

	return (strDay + "/" + strMonth + "/" + strYear);
	}

function FormatDate (strValor) {

	if (strValor.length == 8) {
		if (strValor.indexOf ("/") == -1) {
			var strDia = strValor.substr (0, 2);
			var strMes = strValor.substr (2, 2);
			var strAno = strValor.substr (4, 4);
	
			strValor = strDia + "/" + strMes + "/" + strAno;
			}
		}
	else if (strValor.length == 6) {
		if (strValor.indexOf ("/") == -1) {
			var strDia = strValor.substr (0, 2);
			var strMes = strValor.substr (2, 2);
			var strAno = strValor.substr (4, 2);
			
			if (parseInt (strAno) > 90) {
				strAno = "19" + strAno;
				}
			else {
				strAno = "20" + strAno;
				}
			
			strValor = strDia + "/" + strMes + "/" + strAno;
			}
		}
	return (strValor);
	}

function FormatTime (strValor) {
	if (strValor.length == 4) {
		if (strValor.indexOf (":") == -1) {
			var strHora = strValor.substr (0, 2);
			var strMinuto = strValor.substr (2, 2);
			
			strValor = strHora + ":" + strMinuto;
			}
		}
	return (strValor);
	}
	
function trim (strValue)
	{
	strValue = strValue + "";
	while (strValue.substr (0,1) == " ")
		{
		strValue = strValue.substr (1);
		}
	while (strValue.substr (strValue.length - 1, 1) == " ")
		{
		strValue = strValue.substr (0, strValue.length - 1);
		}
		
	return (strValue);
	}

function LPad (strValor, intTam)
{ 
	var strAux = "";
	var strNewValue;
    var intPos;
    
    strNewValue = strValor;
    
    for (intPos = 1; intPos <= (intTam - strNewValue.length); intPos++) 
        {
          strAux = strAux + "0";
        }
    
    strNewValue = strAux + strNewValue;
    return (strNewValue);     
          
}

function FormatCGC (strValor)
{
  var strAux = trim(strValor);
  var strCGC = "";
  var intPos;
  
  for (intPos = 0; intPos <= (strAux.length); intPos++) 
        {
          if (isNumeric(strAux.substr (intPos, 1)) == true)
             {
              strCGC = strCGC + strAux.substr (intPos, 1);
             } 
        }
  
  if (strCGC.length < 14)
     {
      strCGC = LPad(strCGC, 14);
     }

  strCGC = strCGC.substr (0, 2) + "." + strCGC.substr (2, 3) + "." + strCGC.substr (5, 3) + "/" + strCGC.substr (8, 4) + "-" + strCGC.substr (12, 2);
  return (strCGC);
}

function NoRightClick() 
{
	if (event.button == 2)
	{
		alert("Proibido clicar com o botão direito");
	}
}

function NoOpenNewWindow()
{
	if (window.event.keyCode == 17)
	{
		alert("Proibido Abrir uma nova Janela")
	}
}

function onCampoNumeros()  
{
	if (event.keyCode < '48' || event.keyCode > '58') 
	{
		event.keyCode = '';
		event.keyCode = '127';
		return false;
	}
}
	
function onContrato(contrato,fase)
{ 
	window.showModalDialog('/Contratos/Contrato_dados_consulta.asp?txtNumContrato='+contrato+'&txtFase='+fase+'','Contrato','dialogWidth: 650px; dialogHeight: 550px; dialogTop: 10px; dialogLeft: 10px; scrollbars: Yes; status: No; resizable: Yes;');
}

function onItem(contrato,itemCont,cdItemEnd,cdEndConf,cdItemConf,fase)
{ 
	window.showModalDialog('/Contratos/ItemContrato_dados_consulta.asp?txtNumContrato='+contrato+'&txtNumItemContrato='+itemCont+'&txtFase='+fase+'&ItemEnd='+cdItemEnd+'&EndConf='+cdEndConf+'&ItemConf='+cdItemConf+'','ItemContrato','dialogWidth: 650px; dialogHeight: 550px; dialogTop: 10px; dialogLeft: 10px; scrollbars: Yes; status: No; resizable: Yes;');
}

function onLibera(cdContrato,cdItemContrato)
{ 
	window.showModalDialog('/CallCenter/LiberaPedBCWeb_altera.asp?txtNumContrato='+cdContrato+'&txtNumItem='+cdItemContrato+'','LiberaPedido','dialogWidth: 650px; dialogHeight: 550px; dialogTop: 10px; dialogLeft: 10px; scrollbars: Yes; status: No; resizable: Yes;');
}

function onMovimentacao(cdMovimentacao,fase)
{ 
	window.showModalDialog('/Contratos/Rastreamento_dados.asp?cdMovimenta='+cdMovimentacao+'&txtFase='+fase+'','Rastreamento','dialogWidth: 750px; dialogHeight: 550px; dialogTop: 10px; dialogLeft: 10px; scrollbars: Yes; status: No; resizable: Yes;');
}

function ClearNumber(fltNro){
	if(fltNro == "") return 0;
	fltNro = String(fltNro); 
	bNegative = (fltNro.charAt(0) == '-')?true:false;
	bolJaTem = false; 
	fltNovoNumero = ""	
	for(var i=fltNro.length;i>0;i--) {
		strEsteCar = fltNro.charAt(i-1)
		if((strEsteCar == "," || strEsteCar == ".") && !bolJaTem) {
			bolJaTem = true;
			fltNovoNumero = "."+fltNovoNumero
		} else if (strEsteCar >= "0" && "9" >= strEsteCar) fltNovoNumero = strEsteCar+fltNovoNumero
	}
	fltNovoNumero = parseFloat(fltNovoNumero);
	fltNovoNumero = (bNegative)?-(fltNovoNumero):fltNovoNumero;

	return fltNovoNumero;
}

function FormatCurrency (number, precision, negativeMode) {
	number = ClearNumber(number);
	if(precision == null) precision = 2
	if(negativeMode == null) negativeMode = 1
	precision = ClearNumber(precision);

	number = Math.round(number * Math.pow(10, precision))/Math.pow(10, precision);

	var bNegative = false;
	if(number < 0) {
		bNegative = true;
		number *= -1;
	}
	var pFlt = ""
	if(!isNaN(number)){
		pInt = parseInt(number); number = String(number); pt = number.indexOf(".");
		if(pt != -1) { 
			pFlt = number.substring(pt+1,number.length); 
			while(pFlt.length < precision) pFlt = pFlt+String("0");
		} else 
			while(pFlt.length < precision) pFlt = pFlt+"0";

		pInt = String(pInt);
		nPts = parseInt(pInt.length / 3);
		if(nPts != 0) { for(q=nPts;q>0;q--) { pos = pInt.length-(q*3); if(pos!=0) pInt = pInt.substring(0,pos)+"."+pInt.substring(pos,pInt.length) } }
		number = (precision <= 0)?pInt:pInt+","+pFlt; 
		if(negativeMode == 1) return (bNegative)?'('+number+')':number;
		else return (bNegative)?'-'+number:number;
	}else{
		number = 0;
		return number;
	}
}

//Validação de email
function validaEmail(email,campo)
{ 
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/; 
	var check=/@[\w\-]+\./; 
	var checkend=/\.[a-zA-Z]{2,3}$/; 
	if(campo.value.length!=0)
	{
		if(((email.search(exclude) != -1)||(email.search(check)) == -1)||(email.search(checkend) == -1))
		{ 
			alert('O e-mail está incorreto!'); 
			campo.focus();
			return false; 
		}else{ 
			return true; 
		} 
	}
} 


