var tmr;
var tmr2;

//Loading na pagina
n=document.layers
ie=document.all

ns4 = (document.layers) ? true : false;
ie4 = (document.all) ? true : false;


function MudarFoco(pObj)
{
    try
	{
	    if(pObj != null)
	    {
            if(pObj.getAttribute("maxlength") != null)
            {
                if(pObj.getAttribute("maxlength") > 0)
                {
	                if(pObj.getAttribute("maxlength") == pObj.value.length)
	                {
		                for(i = 0; i < pObj.form.elements.length; i++)
		                {
                            if(pObj.form.elements[i].name == pObj.id)
                            {
                                pObj.form.elements[i + 1].focus();
		                    }
		                }
	                }
	            }
            }	
	    }
	}catch(e){}
}

function ZerarCampo(pObj)
{
	if(pObj.value == '')
	{
		pObj.value = 0;
	}
}

function SomenteNumeros()
{
	var keyCode = event.keyCode;
	
	if(!(keyCode > 47 && keyCode < 58))
	{
		event.keyCode = 0;
	}
}

function SomenteNumerosDecimais(pObj)
{
	var keyCode = event.keyCode;
	
	//Bloqueia virgulas repetidas
	if ((pObj.value.indexOf(',') > -1) && (keyCode == 44))
	{
	    event.keyCode = 0;
	}
	
	//Bloqueia caracteres que nao sao numericos e nem virgulas
	if(!(keyCode > 47 && keyCode < 58) && (keyCode != 44))
	{
		event.keyCode = 0;
	}
}

function AbrirPopup1(url, largura, altura)
{
	topo     = (screen.height/2)-(altura/2);
	esquerda = (screen.width/2) - (largura/2);
	
	window.open(url, "popup",'width=' + largura + ',height=' + altura + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=' + topo + ',left=' + esquerda);
}

function AbrirPopup2(url, largura, altura, scroll)
{
	topo     = (screen.height/2)-(altura/2);
	esquerda = (screen.width/2) - (largura/2);
	
	if(scroll != "1")
	{
	    scroll = "no";
	}
	else
	{
	    scroll = "yes";
	}
	
	window.open(url, "popup",'width=' + largura + ',height=' + altura + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scroll + ',resizable=no,top=' + topo + ',left=' + esquerda);
}

function SelecionarItemCombo(pCombo, pValor)
{
    var combo = document.getElementById(pCombo);
    
    if (combo != null)
    {
        for(i = 0; i < combo.options.length; i++)
        {
            if(combo.options[i].value == pValor)
            {
                combo.selectedIndex = i;
                
                break;
            }
        }
    }
}

function CriaMascara(_RefObjeto, _Modelo)
{ 
    var valorAtual = _RefObjeto.value;
    var valorNumerico = '';
    var nIndexModelo = 0;
    var nIndexString = 0;
    var valorFinal = '';
    var adicionarValor = true;
			  
			 
	// limpa a string valor atual para verificar
	// se todos os caracteres são números
	for (i=0;i<_Modelo.length;i++)
    {
        if (_Modelo.substr(i,1) != '#')
        {
            valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
        }
    }
    
	// verifica se todos os caracteres são números
    for (i=0;i<valorAtual.length;i++)
    {
        if (!isNaN(parseFloat(valorAtual.substr(i,1))))
        {
            valorNumerico = valorNumerico + valorAtual.substr(i,1);
        }
    }
    
    // aplica a máscara ao campo informado usando
    // o modelo de máscara informado no script
    for (i = 0; i < _Modelo.length; i++)
    {
        if (_Modelo.substr(i,1) == '#')
        {
            if (valorNumerico.substr(nIndexModelo,1) != '')
            {
                valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
                nIndexModelo++;
                nIndexString++;
            }
            else 
            {
                adicionarValor = false;
            }
        }
  		else 
        {
            if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != '')
            {
                valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
                nIndexString++;
            }
        }
    }
	
    _RefObjeto.value = valorFinal
}

function CriaMascaraAlpha(_RefObjeto, _Modelo)
{
    var valorAtual = _RefObjeto.value;
    var valorNumerico = '';
    var nIndexModelo = 0;
    var nIndexString = 0;
    var valorFinal = '';
    var adicionarValor = true;
    
	// limpa a string valor atual para verificar
	// se todos os caracteres são números
	for (i=0;i<_Modelo.length;i++)
    {
        if (_Modelo.substr(i,1) != '#')
        {
            valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
        }
    }
    
	// verifica se todos os caracteres são números
    for (i=0;i<valorAtual.length;i++)
    {
        //if (isNaN(parseFloat(valorAtual.substr(i,1))) ||
        //    !isNaN(parseFloat(valorAtual.substr(i,1))))
        //{
            valorNumerico = valorNumerico + valorAtual.substr(i,1);
        //}
    }
    
    // aplica a máscara ao campo informado usando
    // o modelo de máscara informado no script
    for (i = 0; i < _Modelo.length; i++)
    {
        if (_Modelo.substr(i,1) == '#')
        {
            if (valorNumerico.substr(nIndexModelo,1) != '')
            {
                valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
                nIndexModelo++;
                nIndexString++;
            }
            else 
            {
                adicionarValor = false;
            }
        }
  		else 
        {
            if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != '')
            {
                valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
                nIndexString++;
            }
        }
    }
	
    _RefObjeto.value = valorFinal
}

function ExibirDiv(pObj, pVisivel)
{
    if(pObj != null)
    {
        if(pVisivel)
        {
            document.getElementById(pObj).style.display = 'block';
        }
        else
        {
            document.getElementById(pObj).style.display = 'none';
        }
    }
}

function MudarCorLabel(pObj, pMudar)
{
    if(pObj != null)
    {        
        if(pMudar)
        {
            document.getElementById(pObj).style.color = '#FF0000';            
        }
        else
        {
            document.getElementById(pObj).style.color = '#000000';            
        }
    }
}

function SetarTexto(pObj, pTexto)
{
    if(pObj != null)
    {
        document.getElementById(pObj).innerHTML = pTexto;
    }
}

function CampoDecimal(Campo, precisao) 
{
	var Caracteres="0123456789,";
	var Keyascii = event.keyCode;
	
	var carac = String.fromCharCode(Keyascii);
	
	if (Caracteres.indexOf(String.fromCharCode(Keyascii))==-1)
	{
		event.returnValue = 0;
		return;
	}

	if(Campo.value.indexOf(",")!=-1)
	{
		if(carac==",")
		{
			//impede mais de uma virgula
			event.returnValue = 0;
			return;
		}
	
		var arrChar = Campo.value.split(",")
		var x = arrChar[1];
		
		if(x.length >= precisao)
		{
			event.returnValue = 0;
			return;
		}
	}
	else
	{
		if(Campo.value.length<(Campo.maxLength - precisao))
		{
			if(Campo.value.length==(Campo.maxLength - precisao - 1))
			{
				if(carac!=",")
				{
					event.returnValue = 0;
				}
			}
		}
		else
		{
			event.returnValue = 0;
		}
		return;		
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	return [curleft,curtop];
}

function SomenteEmail(e) {
	var keyNumber = (isIE) ? event.keyCode : e.which;
	if 	(
			!( 
				( 	
					((keyNumber > 43) && (keyNumber<58))  ||
					((keyNumber > 63) && (keyNumber<91))  ||
					((keyNumber > 96) && (keyNumber<123)) ||
					((keyNumber > 191) && (keyNumber<221)) ||
					((keyNumber > 223) && (keyNumber<253)) ||
					(keyNumber==32) || 
					(keyNumber==8) ||
					(keyNumber==95)
				) && 
				(keyNumber!=168)
			)
		)
	{
		if (isIE) {
			event.keyCode=0
		}
		return false;
	}
	return true;
}

function PreloadImages() 
{
    var d = document;
    
    if(d.images)
    {
        if(!d.MM_p)
        {
            d.MM_p = new Array();
        }
        
        var i, j = d.MM_p.length, a = 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 Bloquear_Enter()
{
	var objEvent = event.srcElement;
	
	if(event.keyCode == 13 && objEvent.id == "")
	{ 
		// Cancela o evento default
		event.returnValue = false; 
		event.cancel = true; 
		
		//btn.click(); 
	}
}

function ForcarOnKeyPress(pObj)
{
    var obj = document.getElementById(pObj);
    
    if(obj != null)
    {
        try
        {
            obj.onkeypress();
        }
        catch(e)
        {
            a = e.toString();
        }
    }
}

function currencyFormat(fld, milSep, decSep, 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) 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;

	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;
}


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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

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_showHideLayers() { //v6.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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function dateDifference(strDate1, strDate2)
{
     var date1 = document.getElementById(strDate1).value;
     var date2 = document.getElementById(strDate2).value;

     date1 = date1.split("/");
     date2 = date2.split("/");

     var sDate = new Date(date1[1]+"/"+date1[0]+"/"+date1[2]);
     var eDate = new Date(date2[1]+"/"+date2[0]+"/"+date2[2]);

     var daysApart = Math.abs(Math.round((sDate-eDate)/86400000))+ 1;
     
     if(eDate < sDate)
     {
        return -1;
     }
     else
     {     
        return daysApart;
     }
 }

function Load_Page()
{
    if(ie || n)
    {
	    if(n)
	    {
	        if(document.divLoadCont != null)
	        {
	            document.divLoadCont.visibility="hidden"
	        }
	    }
	    else
	    {
	        if(divLoadCont != null)
	        {
	            divLoadCont.style.visibility="hidden"
	        }
	    }
    }
}

function pause(numberMillis) 
{
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    
    while (true) 
    {
        now = new Date();
        if (now.getTime() > exitTime)
        return;
    }
}

function trataBackSpaceMascaraValorRT(campo, event)
{
   NumDig = campo.value;
   TamDig = NumDig.length;
   TamDig--;
   Contador = 0;
   if ((TamDig >= 0) && (event.keyCode == 8))
    {
      numer = "";
      for (i = TamDig; (i >= 0); i--){
          if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9))
            {
             Contador++;
             /*alert(NumDig.substr(i, 1) + " Contador " + Contador+ " numer "+ numer+ " TamDig " +TamDig + " i " + i );*/
             if ((Contador == 4) && ((TamDig -i) < 5))
              {numer = ","+numer;
               Contador = 0;
               }
             else if ((Contador == 3) && ((numer.length) > 4))  
              {numer = "."+numer;
               Contador = 0;
              }
              
             numer = NumDig.substr(i, 1)+numer;
            
            }
        }
            if (numer == "001" || numer == "000" || numer == "002" || numer == "003" || numer == "004" || numer == "005" || numer == "006" || numer == "007" || numer == "008" || numer == "009") 
                numer="";       
            if ((numer.length) == 3 )
                numer= "0," + numer;

        campo.value = numer;
      };
}
function mascaraValorRT(fld, milSep, decSep, 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;


    trataBackSpaceMascaraValorRT(fld, e);

    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;
    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;
}

function trataBackSpaceMascaraValorRT4CasasDecimais(campo, event)
{   
   NumDig = campo.value;
   TamDig = NumDig.length;
   TamDig--;
   Contador = 0;
   if ((TamDig >= 0) && (event.keyCode == 8))
    {
      numer = "";
      for (i = TamDig; (i >= 0); i--){
          if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9))
            {
             Contador++;
             /*alert(NumDig.substr(i, 1) + " Contador " + Contador+ " numer "+ numer+ " TamDig " +TamDig + " i " + i );*/
             if ((Contador == 6) && ((TamDig -i) < 7))
              {numer = ","+numer;
               Contador = 0;
               }
             else if ((Contador == 5) && ((numer.length) > 6))  
              {numer = "."+numer;
               Contador = 0;
              }
              
             numer = NumDig.substr(i, 1)+numer;
            
            }
        }
            if (numer == "00000" || numer == "00001" || numer == "00002" || numer == "00003" || numer == "00004" || numer == "00005" || numer == "00006" || numer == "00007" || numer == "00008" || numer == "00009") 
                numer="";       
            if ((numer.length) == 5 )
                numer= "0," + numer;

        campo.value = numer;
      };
}

function mascaraValorRT4CasasDecimais(fld, milSep, decSep, 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;


    trataBackSpaceMascaraValorRT4CasasDecimais(fld, e);

    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;
    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 + '000' + aux;
    if (len == 2) fld.value = '0'+ decSep + '00' + aux;
    if (len == 3) fld.value = '0'+ decSep + '0' + aux;
    if (len == 4) fld.value = '0'+ decSep + aux;
    if (len > 4) {
        aux2 = '';
        for (j = 0, i = len - 5; 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 - 4, len);
    }
    return false;
}

function arredondar(valor, casas)
{
	var numberField = valor;
	var rnum = numberField.value;
	var rlength = casas; // The number of decimal places to round to
	
	if (rnum > 8191 && rnum < 10485) //Isso devido a um BUG do Javascript
	{
		rnum = rnum-5000;
		var newnumber = Math.round(rnum * Math.pow(10, rlength)) / Math.pow(10,rlength);
		newnumber = newnumber + 5000;
	}
	else 
	{
		var newnumber = Math.round(rnum * Math.pow(10, rlength)) / Math.pow(10, rlength);
	}
	
	return newnumber;
}

function ExisteBloqueadorPopup()
{
    var mine = window.open('','','width=1,height=1,left=-10,top=-10,scrollbars=no');
    var popUpsBlocked;
    
    if(mine != null)
    {
        if(mine)
        {
            popUpsBlocked = false
        }
        else
        {
            popUpsBlocked = true
        }
        
        mine.close();
    }
    else
    {
        popUpsBlocked = true
    }
    
    if(popUpsBlocked)
    {
        alert('Foi detectado que você está usando bloqueador de popup. Por favor, desabilite o bloqueador, pois algumas funcionalidades do sistema SSDP dependem de popups.');
    }
}

function InserirTelefone(obj)
{
    var nomeLinha = obj.id.replace('imbAdd','linha');
    var nomeTabela = obj.id.replace('imbAdd','tabelaPrincipal');
    var objLinha = document.getElementById(nomeLinha);
    var objTabela = document.getElementById(nomeTabela);
    var tabela = null;
    
    //Clona a tabela
    tabela = objTabela.cloneNode(true);
    
    //Limpa o nome dela
    tabela.setAttribute('id','');
    
    //Limpa a caixa de telefone
    tabela.childNodes(0).childNodes(0).childNodes(0).childNodes(0).value = '';
    
    //Limpa a caixa de ramal
    tabela.childNodes(0).childNodes(0).childNodes(2).childNodes(0).value = '';
    
    //IdTelefone
    tabela.childNodes(0).childNodes(0).childNodes(3).childNodes(0).value = '0';
    
    objLinha.childNodes(1).appendChild(tabela);
    
    return false;
}

function RemoverTelefone(obj)
{
    var nomeLinha = obj.id.replace('imbRem','linha');
    var objLinha = document.getElementById(nomeLinha);
    var qtdTabelas = objLinha.childNodes(1).childNodes.length;
    
    if(qtdTabelas > 1)
    {
        objLinha.childNodes(1).removeChild(objLinha.childNodes(1).childNodes(parseInt(qtdTabelas) - 1));
    }
    
    return false;
}

function ColetarTelefones()
{
    var hddTelefones = null;
    var tabela = null;
    var qtdTabelas = 0;
    var idTipoTelefone = 0;
    var idTelefone = 0;
    var todosTelefones = '';
    
    hddTelefones = document.getElementById('ctl00_ContentPlaceHolder1_hddTels');
    tabela = document.getElementById('ctl00_ContentPlaceHolder1_tblTelefones');
    
    //Pega o valor dos hiddens de tipo de telefone:
    //alert(tabela.rows[i].childNodes(0).getElementsByTagName('input')[0].value);
    
    //Retorna qtas tabelas existem de telefone dentro da linha
    //tabela.rows[i].childNodes(1).getElementsByTagName('table').length
    
    for(i = 0; i < tabela.rows.length; i++)
    {
        idTipoTelefone = tabela.rows[i].childNodes(0).getElementsByTagName('input')[0].value;
        qtdTabelas = tabela.rows[i].childNodes(1).getElementsByTagName('table').length;
        
        for(j = 0; j < qtdTabelas; j++)
        {
            telefone = tabela.rows[i].childNodes(1).childNodes(j).childNodes(0).childNodes(0).getElementsByTagName('input')[0].value;
            ramal = tabela.rows[i].childNodes(1).childNodes(j).childNodes(0).childNodes(0).getElementsByTagName('input')[1].value;
            idTelefone = tabela.rows[i].childNodes(1).childNodes(j).childNodes(0).childNodes(0).getElementsByTagName('input')[2].value;
            
            todosTelefones += idTipoTelefone + ';' + idTelefone + ';' + telefone + ';' + ramal + '|';
        }
    }
    
    hddTelefones.value = todosTelefones;
    
    return true;
}

function ValidarDataDigitacao(pObj)
{
    if(pObj.value != "")
    {
        if(!Data_Valida(pObj))
        {
            alert("Data inválida!");
            event.keyCode = 0;
            pObj.value = '';
            pObj.focus();
        }
    }
}

function Data_Valida(obj)
{
    var data = obj.value;
    var barra1 = data.indexOf('/');
    var barra2 = data.lastIndexOf('/');
    var ano = data.substring(barra2+1, data.length);
    var dia = data.substring(0,barra1);
    var mes = data.substring(barra1+1,barra2);
    var anoMod  = ano%4;
    var mesMod  = mes%2;
    var retorno = true;

    //verifica as barras
    if ((barra1==-1) || (barra1==barra2))
    {
        retorno=false; 
    }
    
    // verifica se os campos dia, ano , mes são numéricos e se possuem a quantidade de caracteres suficientes
    if  ((isNaN(ano)) || (isNaN(dia)) || (isNaN(mes))  || (ano<1900)  || (ano>2200) || (mes < 1)|| (mes > 12) ||(dia > 31)|| (dia < 1) )
    { 
        retorno=false; 
    }
    
    // ferifica o mes de fevereiro
    if ((((anoMod != 0) && (dia > 28)) || ((anoMod==0) && (dia > 29))) && (mes == 2))
    { 
        retorno=false; 
    }
    
    if (mesMod == 1)
    { 
        if  ((mes >= 9) &&  (dia >30))
        {		
            retorno=false; 
        }
    }
    else
    { 
        if  ((mes < 7 ) &&  (dia >30))
        {		
            retorno=false; 
        } 
    }
    
    if ((retorno==false))
    {
        return false; 
    }
    else
    { 
        return (true); 
    }
}

function Arredondar(valor, casas)
{
	//var numberField = valor;
	var rnum = valor;
	var rlength = casas; // The number of decimal places to round to
	
	if (rnum > 8191 && rnum < 10485) //Isso devido a um BUG do Javascript
	{
		rnum = rnum-5000;
		var newnumber = Math.round(rnum * Math.pow(10, rlength)) / Math.pow(10,rlength);
		newnumber = newnumber + 5000;
	}
	else 
	{
		var newnumber = Math.round(rnum * Math.pow(10, rlength)) / Math.pow(10, rlength);
	}
	
	return newnumber;
}

function PesquisarFornecedor()
{
    altura   = 400;
    largura  = 600;
    topo     = (screen.height/2)-(altura/2);
	esquerda = (screen.width/2) - (largura/2);
	
    var ret = window.open('PesquisarFornecedor.aspx?controle1=ctl00_ContentPlaceHolder1_hddIdPessoaFornecedor&controle2=ctl00_ContentPlaceHolder1_hddRazao', "popup",'width=' + largura + ',height=' + altura + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scroll + ',resizable=no,top=' + topo + ',left=' + esquerda);
    
    return false;
}

function MostrarHorariosTurma() {
var objdiv = document.getElementById("divHorariosTurma");

var visibilidade = objdiv.getAttribute("style").display;

if (visibilidade == "none")
{
objdiv.getAttribute("style").display = "block";
} 
else
{
objdiv.getAttribute("style").display = "none";
}


return false;
}

function ValidarContatoCadastro(botao)
{
    var txtNome = document.getElementById(botao.id.replace('cmdInserir', 'txtNome'));
    var txtTelefone1 = document.getElementById(botao.id.replace('cmdInserir', 'txtTelefone1'));
    var ddlTipoMidia = document.getElementById(botao.id.replace('cmdInserir', 'ddlMidia'));
    
    if(txtNome.value == '')
    {
        alert('Digite o nome');
        txtNome.focus();
        
        return false;
    }
    
    if(txtTelefone1.value == '(__) ____-____')
    {
        alert('Telefone inválido');
        txtTelefone1.focus();
        
        return false;
    }
    
    if(ddlTipoMidia.value == 0)
    {
        alert('Selecione o tipo de mídia');
        ddlTipoMidia.focus();
        
        return false;
    }
    
    return true;
}

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){ 
                    return true; 
                }
    }else{
        return false;
        }
}

function ValidarCadastroNewsletter()
{
    var txtEmail = document.getElementById('CadastroNewsletter1_txtEmail');
    var txtNome = document.getElementById('CadastroNewsletter1_txtNome');
    var retorno = false;
    
    if(txtNome != null)
    {
        if(txtNome.value == '')
        {
            alert('Digite o seu nome');
            
            txtNome.focus();
            
            return false;
        }
    }
    
    if(txtEmail != null)
    {
        retorno = checkMail(txtEmail.value);
        
        if(!retorno)
        {
            alert('Email inválido');
            
            txtEmail.focus();
            
            return false;
        }
    }
    
    return true;
}

function ValidarCadastroDados()
{
    var txtEmail = document.getElementById('txtEmail');
    var txtNome = document.getElementById('txtNome');
    var txtEndereco = document.getElementById('txtEndereco');
    var txtBairro = document.getElementById('txtBairro');
    var txtCEP = document.getElementById('txtCEP');
    
    var retorno = false;
    
    if(txtNome != null)
    {
        if(txtNome.value == '')
        {
            alert('Digite o seu nome');
            
            txtNome.focus();
            
            return false;
        }
    }
    
    if(txtEndereco != null)
    {
        if(txtEndereco.value == '')
        {
            alert('Digite o seu endereço');
            
            txtEndereco.focus();
            
            return false;
        }
    }
    
    if(txtBairro != null)
    {
        if(txtBairro.value == '')
        {
            alert('Digite o seu bairro');
            
            txtBairro.focus();
            
            return false;
        }
    }
    
    if(txtCEP != null)
    {
        if(txtCEP.value == '')
        {
            alert('Digite o seu CEP');
            
            txtCEP.focus();
            
            return false;
        }
    }
    
    if(txtEmail != null)
    {
        retorno = checkMail(txtEmail.value);
        
        if(!retorno)
        {
            alert('Email inválido');
            
            txtEmail.focus();
            
            return false;
        }
    }
    
    return true;
}

function ValidarContato()
{
    var txtEmail = document.getElementById('txtEmail');
    var txtNome = document.getElementById('txtNome');
    
    if(txtNome != null)
    {
        if(txtNome.value == '')
        {
            alert('Digite o seu nome');
            
            txtNome.focus();
            
            return false;
        }
    }
    
    if(txtEmail != null)
    {
        retorno = checkMail(txtEmail.value);
        
        if(!retorno)
        {
            alert('Email inválido');
            
            txtEmail.focus();
            
            return false;
        }
    }
    
    return true;
}