
isNull = function(x) {
    if ((x == 'undefined') || (x == null)) { return true; }
    else { return false; }
}

isObject = function(x) {
    if (!isNull(x)) {
        if (x.constructor == Object) { return true; }
        else { return false; }
    }
    else { return false; }
}

isFunction = function(x) {
    if (!isNull(x)) {
        if (x instanceof Function) { return true; }
        else { return false; }
    }
    else { return false; }
}

isBoolean = function(x) {
    if (!isNull(x)) {
        if (x.constructor == Boolean) { return true; }
        else { return false; }
    }
    else { return false; }
}

isArray = function(x) {
    if (!isNull(x)) {
        if (x.constructor == Array) { return true; }
        else { return false; }
    }
    else { return false; }
}

isString = function(x) {
    if (!isNull(x)) {
        if (x.constructor == String) { return true; }
        else { return false; }
    }
    else { return false; }
}

isDate = function(x) {
    if (!isNull(x)) {
        if (x.constructor == Date) { return true; }
        else { return false; }
    }
    else { return false; }
}

isNumber = function(x) {
    if (!isNull(x)) {
        if (!isNaN(x) && (x.constructor != Boolean) && (x.constructor != Array)) { return true; }
        else { return false; }
    }
    else { return false; }
}

isInteger = function(x) {
    if (!isNull(x)) {
        if (isNumber(x)) {
            if ((x % 1) == 0) { return true; }
            else { return false; }
        }
        else { return false; }
    }
    else { return false; }
}

//Trim
function Trim(str) 
{
    return str.replace(/^\s+|\s+$/g, "");
}

// Inicio de preload imagens
function MM_preloadImages() {
  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];}}
}
// Fim de preload imagens

// MENU 
	// Copyright 2006-2007 javascript-array.com
    
    var timeout	= 500;
    var closetimer	= 0;
    var ddmenuitem	= 0;
    
    // open hidden layer
    function mopen(id)
    {	
		// cancel close timer
		mcancelclosetime('');
		
		// close old layer
		if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
		
		// get new layer and show it
		ddmenuitem = document.getElementById(id);
		ddmenuitem.style.visibility = 'visible';
    
    }
    // close showed layer
    function mclose()
    {
    	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
    }
    
    // go close timer
    function mclosetime(id)
    {
    	closetimer = window.setTimeout(mclose, timeout);
		

		if(document.getElementById(id))
		{
			var menuItem = document.getElementById(id);
			menuItem.style.backgroundColor = '';
		}
    }
    
    // cancel close timer
    function mcancelclosetime(id)
    {
		if(closetimer)
    	{
			window.clearTimeout(closetimer);
			closetimer = null;
   		}
		if(document.getElementById(id))
		{
		  var menuItem = document.getElementById(id);
		  menuItem.style.backgroundColor = '#C66300';
		}
    }
	

    // close layer when click-out
    document.onclick = mclose; 
//FIM MENU

//Validação CPF
function ChecarCPF(lngCPF)
//http://imasters.uol.com.br/artigo/2410/javascript/algoritmo_do_cpf/
//Retorna false se o CPF não for válido
{
    if (lngCPF.length < 11) 
     {
        return false;
     }
     var nonNumbers = /\D/;
    if (nonNumbers.test(lngCPF))
     {
        return false;
     }
    if (lngCPF == "00000000000" || lngCPF == "11111111111" || lngCPF == "22222222222" || lngCPF == "33333333333" || lngCPF == "44444444444" || lngCPF == "55555555555" || lngCPF == "66666666666" || lngCPF == "77777777777" || lngCPF == "88888888888" || lngCPF == "99999999999")
    {
        return false;
    }
    var a = [];
    var b = new Number;
    var c = 11;
    for (i=0; i<11; i++)
    {
       a[i] = lngCPF.charAt(i);
       if (i < 9) b += (a[i] * --c);
    }
    if ((x = b % 11) < 2) 
    { 
        a[9] = 0 
    } 
    else 
    { 
        a[9] = 11-x 
    }
    b = 0;
    c = 11;
    for (y=0; y<10; y++)
    {
         b += (a[y] * c--); 
    }
    if ((x = b % 11) < 2) 
    { 
        a[10] = 0; 
    } 
    else 
    { 
        a[10] = 11-x; 
    }
    if ((lngCPF.charAt(9) != a[9]) || (lngCPF.charAt(10) != a[10]))
    {
            return false;
    }
    return true;
}
//checar se uma data é válida
function ChecarDataValida(dtmData)
//http://forum.wmonline.com.br/index.php?showtopic=150300
//Retorna false se a data não for válida
 {
    var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
    var vdt = new Date();
    var vdia = vdt.getDay();
    var vmes = vdt.getMonth();
    //Utilizado getFullYear ao invés de getYear devido ao Safari
    //retornar Ano - 1900 como valor (por exemplo, para 2009 no safari o retorno é 109)
    var vano = vdt.getFullYear();
    if ((dtmData.match(expReg)) && (dtmData!=''))
    {
        var dia = dtmData.substring(0, 2);
        
        var mes = dtmData.substring(3,5);
        var ano = dtmData.substring(6, 10);
        if((mes==04 && dia > 30) || (mes==06 && dia > 30) || (mes==09 && dia > 30) || (mes==11 && dia > 30))
        {
            return false;
        }
        else
        { 
            if(ano%4 != 0 && mes== 2 && dia > 28)
            {
                return false;
            } 
            else
            {
                if(ano%4==0 && mes==2 && dia>29)
                {
                    return false;
                } 
                else
                {  
                    if (ano > vano)
                     {
                          return false;
                     }else
                     { 
                        return true;
                     } 
                } 
            }
        }
    } 
    else 
    {
        return false;
    }
    return true;
}

//Checar se um e-mail é válido
function ChecarEmail(stremail)
//http://forum.imasters.uol.com.br/lofiversion/index.php/t201090.html
{
    var ExpReg = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;
    if(ExpReg.exec(stremail))
    {
        return true;
    } 
    else 
    {
        return false;
    }
}

function ChecarCaracteres(strValor, blnLetras, blnNumeros, blnCaracteresEspeciais, strCaracteresEspeciais)
{
    var strLetras   = "ABCDEFGHIJKLMNOPQRSTUVXYWZabcdefghijklmnopqrstuvwxyz";
    var strNumeros  = "0123456789";

    var strCaracteresPermitidos = "";
    if (blnLetras)
    {
        strCaracteresPermitidos += strLetras;
    }
    if (blnNumeros)
    {
        strCaracteresPermitidos += strNumeros;
    }
    if (blnCaracteresEspeciais)
    {
        strCaracteresPermitidos += strCaracteresEspeciais;
    }
    
    var strValorTemp;
    for (var i=0;i<strValor.length;i++)
    {
      strValorTemp=strValor.substring(i,i+1)
      if (strCaracteresPermitidos.indexOf(strValorTemp)== -1)
      {
        strValor = strValor.substring(0,i);
        return false;
        break;
      }
    }
    return true;
}
function AbrirJanela(strURL, strNomeJanela, lngWidth, lngHeight, strOpcoes )
{
    //Adicionando barra de rolagem:
    //scrollbars = yes
    //Adicionando barra de status:
    //status=yes 
    //Removendo barra de endereços:
    //location = no 
    //Removendo barra de ferramentas:
    //toolbar = no 
    //Adicionando barra de menu:
    //menubar=yes
    //Opção de modificar tamanho da janela:
    //resizable=yes
    if (strOpcoes != "") 
    {
        strOpcoes += ",";
    }
    window.open(strURL, strNomeJanela, "width=" + lngWidth + "," + "height=" + lngHeight + strOpcoes);
}

function ValidaForm(objForm) {

    if (objForm) {

        if (document.getElementById("txtnome")) {
            var txtnome = document.getElementById("txtnome");
            if (txtnome.value == "") {
                alert("Preenchimento do campo Nome é obrigatório");
                return false;
            }
        }

        if (document.getElementById("txtassunto")) {
            var objAssunto = document.getElementById("txtassunto");
            if (objAssunto.value == "") {
                alert("Preenchimento do campo Assunto é obrigatório");
                return false;
            }
        }


        if (document.getElementById("txtdescricao")) {
            var objDescricao = document.getElementById("txtdescricao");
            if (objDescricao.value == "") {
                alert("Preenchimento do campo Descrição é obrigatório");
                return false;
            }
        }

        if (document.getElementById("txtcorpo")) {
            var objCorpo = document.getElementById("txtcorpo");
            if (objCorpo.value == "") {
                alert("Preenchimento do campo Mensagem é obrigatório");
                return false;
            }
        }

        if (document.getElementById("txtFCKEditor")) {
            var oEditor = FCKeditorAPI.GetInstance("txtFCKEditor");
            if (oEditor) {
                if (oEditor.GetHTML('formatted') == "") {
                    alert("Preenchimento do campo Mensagem é obrigatório");
                    return false;
                }
            }
        }
    }

    else // objForm
    {
        alert("Formulário não encontrado");
        return false;
    }
    return;
}
//função com problema
function ValidarFormularioExclusao(objForm, strChkApagar)
 {
    if (objForm) {
        for (i = 0; i < document.getElementsByName(strChkApagar).length; i++)
        {
            if (document.getElementsByName(strChkApagar)[i].checked) 
            {
                if (confirm("Deseja apagar o(s) registro(s) selecionado(s)?")) 
                {
                    return true;
                    i = document.getElementsByName(strChkApagar).length;
 
                }
                else 
                {
                    return false;
                }
                
            }
        }
        alert("Nenhum registro selecionado");
        return false;
    }
    else 
    {
        alert("Formulário não encontrado");
    }
}

function ValidarFormularioAtivacao(objForm, strChkApagar) {
    if (objForm) {
        for (i = 0; i < document.getElementsByName(strChkApagar).length; i++) {
            if (document.getElementsByName(strChkApagar)[i].checked) {
                if (confirm("Deseja ativar a(s) noticia(s) selecionada(s)?")) {
                    return true;
                    i = document.getElementsByName(strChkApagar).length;
                }
                else {
                    return false;
                }

            }
        }
        alert("Nenhum registro selecionado");
        return false;
    }
    else {
        alert("Formulário não encontrado");
    }
}
//http://www.kirupa.com/developer/php/ajax_intro.htm
//Cabeçalho de expiração deve estar na página de destino
//A página de destino deve estar codificada para mostrar acentos, ç, etc.
//Funcao: no caso assincrono (ajax ser utilizado), é a função que será chamada
//        quando o resultado estiver disponível

//strMetodo (GET OU POST)
//strUrl (página e parâmetros)
function RPC(strUrl, strMetodo, blnAssincrono, Funcao) 
{
    
    var xmlHttp;
    var strRetorno;
    
    strMetodo = (strMetodo == undefined) ? "GET" : strMetodo;
    blnAssincrono = (blnAssincrono != true) ? false : true;
    try 
    {   //Criando Objeto
        if (window.ActiveXObject) //IE
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if (window.XMLHttpRequest) // Firefox, etc
        {
            xmlHttp = new XMLHttpRequest();
        }
        else {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")
        }
        //Realizando a requisição
        if (xmlHttp)
        {
            xmlHttp.open(strMetodo, strUrl, blnAssincrono); //true para modo assíncrono e false para modo síncrono
            xmlHttp.setRequestHeader('Content-Type',"application/x-www-form-urlencoded;charset=iso-8859-1");
            if (blnAssincrono)
            {
                xmlHttp.onreadystatechange = function()
                {
                    if(xmlHttp.readyState==4)
                    {                        
						if(xmlHttp.status == 200)
						{
							strRetorno = xmlHttp.responseText;
							if(typeof Funcao=="function")
							{
								eval(Funcao(strRetorno));
							}
						}
					}
                }
                xmlHttp.send(null); //Enviar null ou parâmetros?
            }
            else
            {
                xmlHttp.send(null);
                if( xmlHttp.status == 200)
                {
                    strRetorno = xmlHttp.responseText;
                }
            }
        }
    }
    catch(e)
    {
    }
    return strRetorno;
} 

