/*	Aliase  */
function $new(element)
{
	return document.createElement(element);
}


function $id(id)
{
	return document.getElementById(id);
}


function is_string(string)
{
	if(string.constructor==String)
	{
		return true;
	}
	else
	{
		return false;
	}
}


function is_array(array)
{
	if(array.constructor==Array)
	{
		return true;
	}
	else
	{
		return false;
	}
}


function getExt(filename)
{
	ext = filename.substring(filename.lastIndexOf(".") + 1, filename.length);
	ext = ext.toLowerCase();
	return ext;
}


function in_array( strBusca, array ){
	bol = false;
	for( var i=0 ; i < array.length ; i++ ){
		if( strBusca == array[i] ){
			bol = true;
			break;
		}
	}
	return bol;
}
function validarDataTempo(obj)
{
	if ( obj.value.substring(0,2) == ""){
		alert("O Dia Não Foi Informado");
		return false;
	}
	parte1 = parseInt( obj.value.substring(0,2) );
	if( parte1 >= 32 ){
		alert("O Dia Informado Está com Erros");
		return false;
	}
	if ( obj.value.substring(3,5) == ""){
		alert("O Mês Não Foi Informado");
		return false;
	}
	parte2 = parseInt( obj.value.substring(3,5) );
	if( parte2 >= 13 ){
		alert("O Mês Informado Está com Erros");
		return false;
	}
	if ( obj.value.substring(6,10) == "" ){
		alert("O Ano Não Foi Informado");
		return false;
	}

	//HORA
	if( obj.value.substring(11,14) == '' ){
		alert("A Hora não foi informada");
		return false;
	}
	intHora = parseInt( obj.value.substring(11,14) );
	if( intHora > 23 ){
		alert("A Hora Informada Está com Erros!");
		return false;
	}

	//MINUTO
	if( obj.value.substring(14,17) == '' ){
		alert("Os minutos não foram Informados");
		return false;
	}
	intMinuto = parseInt( obj.value.substring(14,17) );
	if( intMinuto > 59 ){
		alert("Os minutos Informados Estão com Erros!");
		return false;
	}

	//SEGUNDOS
	if( obj.value.substring(17,20) == '' ){
		alert("Os segundos não foram Informados");
		return false;
	}
	intSegundo = parseInt( obj.value.substring(17,20) );
	if( intSegundo > 59 ){
		alert("Os segundos Informados Estão com Erros!");
		return false;
	}
	return true;
}
function validarData( string )
{
	if( string.value.substring(0,2) == "")
	{
		alert("O Dia Não Foi Informado");
		return false;
	}
	parte1 = parseInt( string.value.substring(0,2) );
	if( parte1 >= 32 ){
		alert("O Dia Informado Está Com Erros");
		return false;
	}
	if ( string.value.substring(3,5) == ""){
		alert("O Mês Não Foi Informado");
		return false;
	}
	parte2 = parseInt( string.value.substring(3,5) );
	if( parte2 >= 13 ){
		alert("O Mês Informado Está Com Erros");
		return false;
	}
	if ( string.value.substring(6,10) == "" ){
		alert("O Ano Não Foi Informado");
		return false;
	}
	return true;
}
function bloquearDataAntiga( strData ){
	objData = new Date()

	intAno = parseInt( strData.value.substring(6,10) );
	intMes = parseInt( strData.value.substring(3,5) );
	if( parseInt( strData.value.substring(0,2) ) == 0 ){
		intDia = parseInt( strData.value.substring(1,2) );
	}else{
		intDia = parseInt( strData.value.substring(0,2) );
	}
	if( intAno == objData.getYear() ){
		if( intMes == objData.getMonth() + 1 ){
			if( intDia < objData.getDate() ){
				alert("O Dia Informado não pode ser Menor que o Atual");
				return false;
			}
		}
		else{
			if( intMes < objData.getMonth() + 1 ){
				alert("O Mês Informado não pode ser Menor que o Atual");
				return false;
			}
		}
	}else{
		if( intAno < objData.getYear() ){
			alert("O Ano Informado não pode ser Menor que o Atual");
			return false;
		}
	}
	return true;
}
//MANIPULADORES DE DATA
function brDataHora2DateTime( strData ){
	intAno = strData.substring(6,10);
	intMes = strData.substring(3,5);
	intDia = strData.substring(0,2);
	intHora = strData.substring(11,19);
	return intAno + '-' + intMes + '-' + intDia + ' ' + intHora;
}
function brData2Date( strData ){
	intAno = strData.substring(6,10);
	intMes = strData.substring(3,5);
	intDia = strData.substring(0,2);
	return intAno + '-' + intMes + '-' + intDia;
}
function date2brData( strData ){
	intAno = strData.substring(0,4);
	intMes = strData.substring(5,7);
	intDia = strData.substring(8,10);
	return intDia + '/' + intMes + '/' + intAno;
}
function dateTime2brDataHora( strData ){
	intAno = strData.substring(0,4);
	intMes = strData.substring(5,7);
	intDia = strData.substring(8,10);
	intHora = strData.substring(11,19);
	return intDia + '/' + intMes + '/' + intAno + ' ' + intHora;
}

function XML2Obj(objXML){
	//Copyright 2005-2007 Kawasaki Yusuke <u-suke@kawa.net>
	//Adaptação de Pablo F. Moreira
	//alert( "nodeType: "+JKL.ParseXML.MAP_NODETYPE[objXML.nodeType]+" <"+objXML.nodeName+">" );

    //  COMMENT_NODE

    if ( objXML.nodeType == 7 ) {
        return;
    }

    //  TEXT_NODE CDATA_SECTION_NODE

	if ( objXML.nodeType == 3 || objXML.nodeType == 4 ) {
        // var bool = objXML.nodeValue.match( /[^\u0000-\u0020]/ );
        var bool = objXML.nodeValue.match( /[^\x00-\x20]/ ); // for Safari
        if ( bool == null ) return;     // ignore white spaces
        // debug.print( "TEXT_NODE: "+objXML.nodeValue.length+ " "+bool );
		return objXML.nodeValue;
    }

    var retval;
    var cnt = {};

    //  parse attributes

    if ( objXML.attributes && objXML.attributes.length ) {
		retval = {};
        for ( var i=0; i<objXML.attributes.length; i++ ) {
            var key = objXML.attributes[i].nodeName;
            if ( typeof(key) != "string" ) continue;
            var val = objXML.attributes[i].nodeValue;
            if ( ! val ) continue;
            if ( typeof(cnt[key]) == "undefined" ) cnt[key] = 0;
            cnt[key] ++;

	        if ( cnt[key] == 1 ) {
	        	// 1st sibling
			   retval[key] = val;
	        } else if ( cnt[key] == 2 ) {
	        	// 2nd sibling
	            retval[key] = [ retval[key], val ];
	        } else {
				// 3rd sibling and more
	            retval[key][retval[key].length] = val;
	        }
        }
    }

    //  transforma os nós filhos (recursividade)


	if ( objXML.childNodes && objXML.childNodes.length ) {
        var textonly = true;
        if ( retval ) textonly = false;        // some attributes exists
        for ( var i=0; i<objXML.childNodes.length && textonly; i++ ) {
            var ntype = objXML.childNodes[i].nodeType;
            if ( ntype == 3 || ntype == 4 ) continue;
            textonly = false;
        }
        if ( textonly ) {
            if ( ! retval ) retval = "";
            for ( var i=0; i<objXML.childNodes.length; i++ ) {
                retval += objXML.childNodes[i].nodeValue;
            }
        } else {
            if ( ! retval ) retval = {};
            for ( var i=0; i<objXML.childNodes.length; i++ ) {
                var key = objXML.childNodes[i].nodeName;
                if ( typeof(key) != "string" ) continue;
				//Recursividade
                var val = XML2Obj( objXML.childNodes[i] );
                if ( ! val ) continue;
                if ( typeof(cnt[key]) == "undefined" ) cnt[key] = 0;
                cnt[key] ++;

		        if ( cnt[key] == 1 ) {
		        	// 1st sibling
				   retval[key] = val;
		        } else if ( cnt[key] == 2 ) {
		        	// 2nd sibling
		            retval[key] = [ retval[key], val ];
		        } else {
					// 3rd sibling and more
		            retval[key][retval[key].length] = val;
		        }
			}
        }
    }
    return retval;
}
function ExtraiScript(texto){
    var ini, pos_src, fim, codigo;
    var objScript = null;
    ini = texto.indexOf('<script', 0)
    while (ini!=-1){
        var objScript = document.createElement("script");
        //Busca se tem algum src a partir do inicio do script
        pos_src = texto.indexOf(' src', ini)
        ini = texto.indexOf('>', ini) + 1;

        //Verifica se este e um bloco de script ou include para um arquivo de scripts
        if (pos_src < ini && pos_src >=0){//Se encontrou um "src" dentro da tag script, esta e um include de um arquivo script
            //Marca como sendo o inicio do nome do arquivo para depois do src
            ini = pos_src + 4;
            //Procura pelo ponto do nome da extencao do arquivo e marca para depois dele
            fim = texto.indexOf('.', ini)+4;
            //Pega o nome do arquivo
            codigo = texto.substring(ini,fim);
            //Elimina do nome do arquivo os caracteres que possam ter sido pegos por engano
            codigo = codigo.replace("=","").replace(" ","").replace("\"","").replace("\"","").replace("\'","").replace("\'","").replace(">","");
            // Adiciona o arquivo de script ao objeto que sera adicionado ao documento
            objScript.src = codigo;
        }else{//Se nao encontrou um "src" dentro da tag script, esta e um bloco de codigo script
            // Procura o final do script
            fim = texto.indexOf('</script>', ini);
            // Extrai apenas o script
            codigo = texto.substring(ini,fim);
            // Adiciona o bloco de script ao objeto que sera adicionado ao documento
            objScript.text = codigo;
        }

        //Adiciona o script ao documento
        document.body.appendChild(objScript);
        // Procura a proxima tag de <script
        ini = texto.indexOf('<script', fim);

        //Limpa o objeto de script
        objScript = null;
    }
}
function getNavegador()
{
	if(navigator.appName == 'Netscape')
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

