<!--
/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
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


/**
* valida campos vazio
*/
function EstaVazio(campo){
   if (campo > ""){
      return false;
   }else{
      return true;
   }
}

/**
* valida campos numericos
*/
function checkNum (campo, flgChar, charac){
   for (var i = 0; i < campo.length; i++){
      var ch = campo.substring(i, i + 1)
      if (flgChar == true){
         if (ch != charac){
            if (ch < "0" || ch > "9")
               return false;
            }
      }else{
         if (ch < "0" || ch > "9")
            return false;
         }
      }
   return true;
}

/**
* valida cpf
*/ 
function checaCPF (CPF){
   if (CPF.length != 11 || 
   	CPF == "00000000000" || CPF == "11111111111" || CPF == "33333333333" || 
   	CPF == "44444444444" || CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
      CPF == "88888888888" || CPF == "99999999999" || CPF == "01234567890" ){
      return true;
   } else {
      soma = 0;
      for (i=0; i < 9; i ++){
         soma += parseInt(CPF.charAt(i)) * (10 - i);
      }
      resto = 11 - (soma % 11);
      if (resto > 9){
      	resto = 0;
      }
      if (resto != parseInt(CPF.charAt(9))){
      	return true;
      } else { 
         soma = 0;
         for (i = 0; i < 10; i ++){
            soma += parseInt(CPF.charAt(i)) * (11 - i);
         }
         resto = 11 - (soma % 11);
         if (resto > 9){
            resto = 0;
         }
         if (resto != parseInt(CPF.charAt(10))){
         	return true;
         }
		}
   }
   return false;
}

/**
* valida cnpj
*/
function checaCNPJ (CNPJ) {
   if (CNPJ.length != 14 || 
  		 CNPJ == "11111111111111" || CNPJ == "22222222222222" || CNPJ == "33333333333333" ||
  		 CNPJ == "44444444444444" || CNPJ == "55555555555555" || CNPJ == "66666666666666" || CNPJ == "77777777777777" ||
       CNPJ == "88888888888888" || CNPJ == "99999999999999" || CNPJ == "01234567890123" ){
      return true;
   } else {
		var dig1=0; 
		var dig2=0; 
		var x; 
		var Mult1 = '543298765432'; 
		var Mult2 = '6543298765432'; 
		for(x=0; x<=11; x++) { 
			dig1 = dig1 +(parseInt(CNPJ.slice(x,x+1)) * parseInt(Mult1.slice(x,x+1))); 
		} 
		for(x=0; x<=12; x++) { 
			dig2 = dig2 + (parseInt(CNPJ.slice(x, x+1)) * parseInt(Mult2.slice(x,x+1)));
		} 
		dig1 = (dig1 * 10)%11; 
		dig2 = (dig2 * 10)%11; 
		if (dig1 == 10) {dig1 = 0;} 
		if (dig2 == 10) {dig2 = 0;} 
		if (dig1 != parseInt(CNPJ.slice(12, 13))) { 
			return true; 
		} else { 
			if (dig2 != parseInt(CNPJ.slice(13, 14))) { 
				return true; 
			} else { 
				return false; 
			} 
		} 
	}    
}

/**
* valida email
*/
function IsEmail(str) {
	//verifica se o e-mail digitado é válido 
	var strAlfa = "ABCDEFGHIJKLMNOPQRSTUWVXYZ";
	var strNum = "0123456789";
	var strSpecial = "_.-@/";
	var strValid = strAlfa + strNum + strSpecial;
	var email = str.toUpperCase();
	//verifica se os caracteres do e-mail são válidos
	for (i=0; i<email.length; i++) {
		if (strValid.indexOf(email.charAt(i)) < 0) {
			return false;
		}
	}
	var strC = "@."; 
	//verifica se o e-mail contém @ e . (caracteres obrigatórios)
	for (i=0; i<strC.length; i++) {
		if (email.indexOf(strC.charAt(i)) < 0) 
			return false;
	}
	if (email.indexOf("@") != email.lastIndexOf("@"))
		return false;
	if (email.indexOf("@") > email.lastIndexOf("."))
	    return false;
	if (email.charAt(email.indexOf("@") + 1) == ".")
	    return false;
	if (!(email.indexOf("@") != 0 && email.lastIndexOf(".") != email.length-1))
		return false;
	return true;
}


/**
* remove espacos
*/
function trim(theString) {
	var aString = theString;
	var newString = "";
	var kBlank = " ";
	if (aString.indexOf(kBlank) >= 0)  {
		for (var i = 0; i < aString.length; i++)
			if (aString.charAt(i) != kBlank)
				break;
			
		for (var j =  aString.length-1; j >= 0; j--)
			if (aString.charAt(j) != kBlank)
				break;
			
		if (i == aString.length && j == -1)
			newString = "";
		else
			if (i != 0 || j != aString.length -1)
				newString = trim(aString.substring(i, j+1));
			else
				newString = aString.charAt(i) + trim(aString.substring(i+1, j+1)) + aString.charAt(j+1);
	}
	else
		newString = aString;
			
	return newString;
}

/**
* compara caracteres para validar
*/
function IsStrValid(strToValidate, strValidChar) {
	var flag;
	var i;
	flag = true;
	
	if ((trim(strToValidate) != "") && (trim(strValidChar) != "")) {
		for (i=0;i<strToValidate.length;i++) {
			if (strValidChar.indexOf(strToValidate.charAt(i).toLowerCase()) == -1) {
				flag = false;
				return flag
			}
		}
	} else flag = false;
	
	return flag;
}

/**
* valida cep
*/
function IsCEP(cep) {
	//verifica se o CEP está corretamente digitado aceitando apenas números
	cep1 = substr(cep,0,5);
	cep2 = substr(cep,6,9);
	var i, strCEP = "0123456789";
	cep = cep1.cep2;
	if (cep.length != 8) return false;
	for (i=0; i<cep.length; i++) {
		if ( strCEP.indexOf(cep.charAt(i)) < 0 )
			return false;
	}
	return true;
}


/**
* valida hora 99:99:99
*/
function IsHour(lStrHorario){
	var lHora, lMinuto, lSegundo, lPrimeiroSeparador, lSegundoSeparador;
	if (lStrHorario.length != 8){
		return false;
	}
	lHora = lStrHorario.substr(0, 2);
	lPrimeiroSeparador = lStrHorario.substr(2, 1);
	if (lPrimeiroSeparador != ':'){
		return false;
	}
	lMinuto = lStrHorario.substr(3, 2);
	if (lStrHorario.length > 5){
		lSegundoSeparador = lStrHorario.substr(5, 1);
		if (lSegundoSeparador != ':'){
			return false;
		}
		lSegundo = lStrHorario.substr(6, 2);
		if (lSegundo.length < 2){
			return false;
		}
	}
	//Valida Hora
	if (!(fJSIsNumber(lHora))){
		return false;
	}
	if (!(fJSInRange(lHora, 0, 23))){
		return false;
	}
	//Valida Minuto
	if (!(fJSIsNumber(lMinuto))){
		return false;
	}
	if (!(fJSInRange(lMinuto, 0, 59))){
		return false;
	}
	//Valida Segundo
	if (lStrHorario.length > 5){
		if (!(fJSIsNumber(lSegundo))){
			return false;
		}
		if (!(fJSInRange(lSegundo, 0, 59))){
			return false;
		}
	}
	return true;
}

/**
* Funcoes utilizadas para validação do horario
*/
function fJSInRange( inputStr, ini, fim ){
	var num = parseInt(inputStr, 10);
	if ( num < ini || num > fim ) {
		return false;
	}
	return true;
}

/**
* Funcoes utilizadas para validação do horario
*/
function fJSIsNumber( num ){
	var numeros = '0123456789,';
	var valor = num.toString();
	var lCount = 0;
	for ( var i=0; i < valor.length; i++ ){
		if ( numeros.indexOf( valor.substr(i,1) ) == -1 ){
      	return false;
	 	}
	   if ( valor.substr(i,1) == ',' ) {
	   	lCount += 1;
	      if ( lCount > 1 ) { 
				return false; 
			}
	 	}
	}
	return true;
}

/**
* valida data  DD/MM/YYYY
*/
function IsDate(sdata){
	day2   = sdata.substr(0,2);
	month2 = sdata.substr(3,2);
	year2  = sdata.substr(6,4);
	if ((sdata.substr(2,1) != "/") || (sdata.substr(5,1) != "/")){
		day2   = "";
		month2 = "";
		year2  = "";
	}
	var DayArray = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
	var inpDate = day2 + month2 + year2;
	var filter=/^[0-9]{2}[0-9]{2}[0-9]{4}$/;
	//Check ddmmyyyy date supplied
	if (! filter.test(inpDate)){
		return false;
	}
	/* Check Valid Month */
	filter=/01|02|03|04|05|06|07|08|09|10|11|12/;
	if (! filter.test(month2)) {
		return false;
	}
	/* Check For Leap Year */
	var N = Number(year2);
	if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) ){
		DayArray[1]=29;
	}
	/* Check for valid days for month */
	for(var ctr=0; ctr<=11; ctr++){
	   if (MonthArray[ctr]==month2){
	      if (day2<= DayArray[ctr] && day2 >0 ){
	        inpDate = day2 + '/' + month2 + '/' + year2;
	        return true;
	      }
	      return false;
	   }
	}
}

/**
* formata campo de valor
*/
function FormataValor(fld, milSep, decSep, e) 
{
	var browser_type=navigator.appName
	if(browser_type!="Microsoft Internet Explorer")
		return true;	
	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) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	if(len < 16)
	{
		for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
		aux = '';
		for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
		aux += key;
		len = aux.length;
		if (len == 0) fld.value = '';
		if (len == 1) fld.value = '0'+ decSep + '0' + aux;
		if (len == 2) fld.value = '0'+ decSep + aux;
		if (len > 2) {
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
			fld.value += aux2.charAt(i);
			fld.value += decSep + aux.substr(len - 2, len);
		}
	}
	return false;
}

/**
* impressao
*/
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 
function printPage()
{
  if (pr) // NS4, IE5
    window.print()
  else // other browsers
    alert("Desculpe seu browser não suporta esta função. Por favor utilize a barra de trabalho para imprimir a página.");
  return false;
}

/**
* impede que outros sites insiram o site em frames
*/
//if(top.frames.length!=0)
//{
//	top.location=self.document.location;
//}
/*
function textCounter(field, countfield, maxlimit) 
{
	var extra = 0;
  	if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)>=5)
  	{
    	var index = field.value.indexOf('\n');
     	while(index != -1) 
     	{
       		extra += 1;
       		index = field.value.indexOf('\n',index+1);
     	}
  	}
  	if (field.value.length + extra > maxlimit)
  	{
    	field.value = field.value.substring(0, maxlimit-extra);
  	}else
  	{
    	cntfield.value = maxlimit - field.value.length - extra;	
  	}
}*/ 
function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

/**
* getElementById melhorado 
*/
function getElement (e)
{
    if (document.layers)
	{
        f = (f) ? f : self;
        if (f.document.layers[e]) {
            return f.document.layers[e];
        }
        for (W=0; i < f.document.layers.length; W++) {
            return(getElement(e,f.document.layers[W]));
        }
    }
    if (document.all) 
    {
        return document.all[e];
    }
    return document.getElementById(e);
}
function getElementContent (id)
{
	return getElement(id).innerHTML;
}

function openPopup( windowURL,windowName, windowFeatures ) 
{ 
	return window.open( windowURL, windowName,windowFeatures);
}  
//-->
