//Break out of frames
if (window != window.top)
top.location.href = location.href;

//Expirar página após um prazo
//Uso: <script>expirar(10); //em minutos</script>
function expirar(min) {
	if(arguments.length == 0)
		min = 10;
	setTimeout("window.top.location.href='timeou.asp'",(60000 * min));
}

//Open window function
function go(url) {
  open(url, "Logout", "toolbar=yes,menubar=yes,status=yes,directories=yes,location=yes,scrollbars=yes,resizable=yes,width=640,height=480,left=0,top=0,screenX=0,screenY=0");  
}
function OpenWindow(url,titulo) {
  open(url, titulo, "toolbar=no,menubar=no,status=no,directories=no,location=no,scrollbars=yes,resizable=yes,width=400,height=300,left=0,top=0,screenX=0,screenY=0");  
}

function openSubWindow(filename,title,w,h){
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = "height="+h+",width="+w+",top="+wint+",left="+winl+"toolbar=no,directories=no,status=no,scrollbars=yes,resize=no,menubar=no"
  /*window.alert("filename: " + filename)
  window.alert("title: " + title)
  window.alert("winprops: " + winprops)*/
  winVar=window.open(filename,title,winprops);
}

function Apaga(){
	if(document.form)
	{
		// verifica se existe mais de um formulário definidos com mesmo nome
		if(document.forms.length > 1)
			// se existir, percorre os elementos de todos os formulários com nome form
		   	for (i = 0; i < document.form.length; i++)
		  		for (j = 0; j < document.form[i].elements.length; j++)
				{
					var element = document.form[i].elements[j];
					if(element.nodeName == "INPUT" && element.type == "text")
	  				    element.value="";  
				}	
			// só existe um formulário cujos elementos são zerados
		else if (document.forms.length == 1)
			   	for (i = 0; i < document.form.elements.length; i++)
				{
					var element = document.form[i];
					if(element.nodeName == "INPUT" && element.type == "text")
	  				    element.value="";
	  		  if(element.nodeName == "TEXTAREA")
	  				    element.value="";  
				}	
	}
}

function trocaimagem(daSrc, daImage){
  var objStr,obj;
  /*
    Usage: trocaimagem(originalImage, 'newSourceUrl');

    Requires: WM_preloadImages() (optional, but recommended)
    Thanks to Ken Sundermeyer (ksundermeyer@macromedia.com) for his help
    with variables in ie3 for the mac. 
    */

  // Check to make sure that images are supported in the DOM.
  if(document.images){
    // Check to see whether you are using a name, number, or object
    if (typeof(daImage) == 'string') {
      // This whole objStr nonesense is here solely to gain compatability
      // with ie3 for the mac.
      objStr = 'document.' + daImage;
      obj = eval(objStr);
      obj.src = daSrc;
    } else if ((typeof(daImage) == 'object') && daImage && daImage.src) {
      daImage.src = daSrc;
    }
  }
}

function high(which2){
  theobject=which2
  highlighting=setInterval("highlightit(theobject)",50)
}
function low(which2){
  clearInterval(highlighting)
  which2.filters.alpha.opacity=20
}
function highlightit(cur2){
  if (cur2.filters.alpha.opacity<100)
  cur2.filters.alpha.opacity+=5
  else if (window.highlighting)
  clearInterval(highlighting)
}


function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function V2P(num){
// Substitui vírgula por ponto
   p = num.lastIndexOf(',');
   if ( p != -1 ) {
      num = " " + num;
      temp = "";
      for (i=1;i<7;i++) {
         if( num.charAt(i) != ',' ) { temp += num.charAt(i); }
         else { temp += '.'; } ;
      }
      num = parseFloat(temp);
   }
   if (isNaN(parseFloat(num))){ num = 0}
   if (num==""){ num = 0}
   return ( num );
}

function FormataDado(formulario,campo,tammax,pos,teclapres){
	var tecla = teclapres.keyCode;
	var formobj = document[formulario]
	vr = formobj[campo].value;
	vr = vr.replace( "-", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length ;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){ tam = tam - 1 ; }
			
	if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		formobj[campo].value = vr ;}
		if ( tam > pos && tam <= tammax ){
			formobj[campo].value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );}
	}
}

function FormataValor(formulario,campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	var formobj = document[formulario]
	vr = formobj[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		formobj[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		formobj[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		formobj[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		formobj[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		formobj[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		formobj[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}		
	
}

function SaltaCampo (formulario,campo,prox,tammax,teclapres){
	var tecla = teclapres.keyCode;
	var formobj = document[formulario]
	vr = formobj[campo].value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		formobj[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ",", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	tam = vr.length;	


		
	 	if (tecla != 0 && tecla != 9 && tecla != 16 )
			if ( tam == tammax )	
				formobj[prox].focus() ;	}
}

function FormataData(formulario, campo,teclapres) {
	var tecla = teclapres.keyCode;
	var formobj = document[formulario]
	vr = formobj[campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			formobj[campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			formobj[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}



/***
* 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 -> 99999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* C/C -> 999999-!
* Tel -> (99) 9999-9999
***/
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) == "/") || (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;
  }
}
////////////////////////////


 function cgc(pcgc)
 {
       // verifica o tamanho
 if (pcgc.length != 14) {
  sim=false
  alert ("Tamanho Invalido de CGC")
  }
 else {sim=true}

  if (sim )  // verifica se e numero
  {
  for (i=0;((i<=(pcgc.length-1))&& sim); i++)
  {
   val = pcgc.charAt(i)
       // alert (val)
   if
((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") &&
(val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false}
   }
   if (sim)  // se for numero continua
   {
    m2 = 2
    soma1 = 0
    soma2 = 0
    for (i=11;i>=0;i--)
    {
     val = eval(pcgc.charAt(i))
       // alert ("Valor do Val: "+val)
     m1 = m2
  if (m2<9) { m2 = m2+1}
  else {m2 = 2}
  soma1 = soma1 + (val * m1)
  soma2 = soma2 + (val * m2)
    }  // fim do for de soma

  soma1 = soma1 % 11
  if (soma1 < 2) {  d1 = 0}
   else { d1 = 11- soma1}

     soma2 = (soma2 + (2 * d1)) % 11
  if (soma2 < 2) { d2 = 0}
   else { d2 = 11- soma2}
        // alert (d1)
       // alert (d2)
    if ((d1==pcgc.charAt(12)) && (d2==pcgc.charAt(13)))
   { return true }
   else return false
   }
 }

 }


 function cpf(pcpf)
 {

 if (pcpf.length != 11) {sim=false}
 else {sim=true}

  if (sim )  // valida o primeiro digito
  {
  for (i=0;((i<=(pcpf.length-1))&& sim); i++)
  {
   val = pcpf.charAt(i)
   if

 ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")

 &&    (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false}
   }

   if (sim)
  {
    soma = 0
    for (i=0;i<=8;i++)
    {
     val = eval(pcpf.charAt(i))
     soma = soma + (val*(i+1))
    }

    resto = soma % 11
    if (resto>9) dig = resto -10
    else  dig = resto
    if (dig != eval(pcpf.charAt(9))) { sim=false }
   else   // valida o segundo digito
    {

     soma = 0
    for (i=0;i<=7;i++)
     {
     val = eval(pcpf.charAt(i+1))
      soma = soma + (val*(i+1))
    }

     soma = soma + (dig * 9)
    resto = soma % 11
     if (resto>9) dig = resto -10
     else  dig = resto
   if (dig != eval(pcpf.charAt(10))) { sim = false }
    else sim = true
   }
   }
  }

  if (sim) { return true }
  else
    return false
 }




function isemail(str)
{
 // pass the value of the field to be validated to the function isemail 
	// will return false if not a valid emailid.
	var valids = "abcdefghijklmnopqrstuvwxyz_-1234567890.";
	var validstart = "abcdefghijklmnopqrstuvwxyz1234567890";
	str = str.toLowerCase();
	var at = Number(str.indexOf("@"));
	var point = Number(str.lastIndexOf("."));
	if ((at < 1) || (!((point - at) > 1)))
	  // || (!((Number((str.length) - (point))) == 4))
		return false;
	var valida = false;
	var validb = false;
	var validc = false;
	for (var i=0;i<validstart.length;i++)
	{
		if ((str.charAt(0)) == (validstart.substr(i,1)))
			valida = true;
		if ((str.charAt(at+1)) == (validstart.substr(i,1)))
			validb = true;
		if ((str.charAt(point+1)) == (validstart.substr(i,1)))
			validc = true;
	}
	// this code is written by jignesh
	if ((!valida) ||(!validb) ||  (!validc))
		return false;
	var filteredemail = str.replace("@","");
	//filteredemail = filteredemail.replace(".","");
	for (var z=0;z<filteredemail.length;z++)
	{
		var isvalid = false;
		for (var i=0;i<valids.length;i++)
			if ((filteredemail.substr(z,1)) == (valids.substr(i,1)))
				isvalid = true;
		if (!isvalid)
			return false;
	}
	return true;
}



function checkdate(dateStr) {
  // Checks for the following valid date formats:
  // MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
  // Also separates date into month, day, and year variables

  //var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

  // To require a 4 digit year entry, use this line instead:
  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

  var matchArray = dateStr.match(datePat); // is the format ok?
  if (matchArray == null) {
  window.alert("A data escolhida não é válida");
  return false;
  }
  month = matchArray[3]; // parse date into variables
  day = matchArray[1];
  year = matchArray[4];
  if (month < 1 || month > 12) { // check month range
  window.alert("A data escolhida não é válida");
  return false;
  }
  if (day < 1 || day > 31) {
  window.alert("A data escolhida não é válida");
  return false;
  }
  if ((month==4 || month==6 || month==9 || month==11) && day==31) {
  alert("O mês "+month+" não tem 31 dias.")
  return false
  }
  if (month == 2) { // check for february 29th
  var g = parseInt(year / 4);
  if (day > 29 || (day == 29 && (year / 4) != g)) {
  alert("Fevereiro do ano "+year+" não tem "+day+" dias.")
  return false;
     }
  }
  return true;  // date is valid
}


function changeScrollbarColor(C) {
  if (document.all) {
    document.body.style.scrollbarBaseColor = C;
  }
}

function showtip(current,e,text){

  if (document.all){
    thetitle=text.split('<br>')
    if (thetitle.length>1){
    thetitles=''
    for (i=0;i<thetitle.length;i++)
    thetitles+=thetitle[i]
    current.title=thetitles
    }
    else
    current.title=text
    }
    else if (document.layers){
    document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
    document.tooltip.document.close()
    document.tooltip.left=e.pageX+5
    document.tooltip.top=e.pageY+5
    document.tooltip.visibility="show"
  }
  //if (document.getElementById)
  //document.getElementById("boxdescription").innerHTML=text
  //else
  //boxdescription.innerHTML=html
}

function hidetip(){
//boxdescription.innerHTML='&nbsp;';
if (document.layers)
document.tooltip.visibility="hidden"
}

function highlight(which,color){
if (document.all||document.getElementById)
which.style.backgroundColor=color
}

function verify(redirecturl){
  var destino = "" + redirecturl
  var confirmar = window.confirm('Tem certeza que deseja excluir? Não há como desfazer esta operação!!!');
  if (confirmar) {
    window.location.href = destino;
    return true;
  }
  return false;
}

function showHide(obj,objDir) {
  if (!document.all&&document.getElementById){document.all = document.getElementsByTagName("*")}
  ns4 = (document.layers)? true:false;
  ie4 = (document.all)? true:false;
  objArray = obj.split(",");
  if (ns4){skjul="hide";vis="show"}else{skjul="hidden";vis="visible"}
  for (var i = 0; i < objArray.length; ++i){
  	if (ns4)flipObj = document.layers[objArray[i]];
  	if (ie4)flipObj = document.all[objArray[i]].style;
  	objDir=="1"?doWhat=vis:doWhat=skjul;
  	if(!objDir){
			flipObj.visibility==skjul? flipObj.visibility=vis:flipObj.visibility=skjul;
		} else {
			flipObj.visibility=doWhat;
		}
	}
}



function expandIt(obj,objDir) {
  if (!document.all&&document.getElementById){document.all = document.getElementsByTagName("*")}
  ns4 = (document.layers)? true:false;
  ie4 = (document.all)? true:false;
  objArray = obj.split(",");
  if (ns4){skjul="none";vis="block"}else{skjul="none";vis="block"}
  for (var i = 0; i < objArray.length; ++i){
  	if (ns4)flipObj = document.layers[objArray[i]];
  	if (ie4)flipObj = document.all[objArray[i]].style;
  	objDir=="1"?doWhat=vis:doWhat=skjul;
  	if(!objDir){
			flipObj.display==skjul? flipObj.display=vis:flipObj.display=skjul;
		} else {
			flipObj.display=doWhat;
		}
	}
}


