/*
<body onload="mueveReloj()"> 
Vemos aqui o relógio funcionando...
<form name="form_reloj"> 
<input type="text" name="reloj" size="10"> 
</form>
</body>
*/
function mueveReloj(){
	momentoActual = new Date();
	hora = Right("00"+momentoActual.getHours(),2);
	minuto = Right("00"+momentoActual.getMinutes(),2);
	segundo = Right("00"+momentoActual.getSeconds(),2);
	
	horaImprimible = hora + " : " + minuto + " : " + segundo;
	
	//document.form_reloj.reloj.value = horaImprimible
	document.getElementById('relo').innerHTML=horaImprimible;
	
	setTimeout("mueveReloj()",1000);
}

// Função que monta Mês, Dia, e Ano para exibir no HTML
// Declaração de Variaveis que receberam os valores:
function dataExtens(){
  var now = new Date();
  //var hours = now.getHours();
  //var minutes = now.getMinutes();
  //var timeValue = "" + ((hours >12) ? hours -12 :hours)

  //Tratamento quantidade de Digitos nos Minutos e exibi se é 
  // dia ou noite, PM, AM.

  //timeValue += ((minutes < 10) ? ":0" : ":") + minutes
  //timeValue += (hours >= 12) ? " PM" : " AM"

  //timerRunning = true;
  mydate = new Date();
  myday = mydate.getDay();
  mymonth = mydate.getMonth();
  myweekday = mydate.getDate();
  weekday = myweekday;
  myyear = mydate.getFullYear();
  year = myyear;

  // Tratamento dos Dias da Semana
  if(myday == 0)
    day = " Domingo, "
  else if(myday == 1)
    day = " Segunda Feira, "
  else if(myday == 2)
    day = " Terça Feira, "
  else if(myday == 3)
    day = " Quarta Feira, "
  else if(myday == 4)
    day = " Quinta Feira, "
  else if(myday == 5)
    day = " Sexta Feira, "
  else if(myday == 6)
    day = " Sábado, "

  //Tratamento dos Meses
  if(mymonth == 0)
    month = " de Janeiro de "
  else if(mymonth ==1)
    month = " de Fevereiro de "
  else if(mymonth ==2)
    month = " de Março de "
  else if(mymonth ==3)
    month = " de April de "
  else if(mymonth ==4)
    month = " de Maio de "
  else if(mymonth ==5)
    month = " de Junho de "
  else if(mymonth ==6)
    month = " de Julho de "
  else if(mymonth ==7)
    month = " de Agosto de "
  else if(mymonth ==8)
    month = " de Setembro de "
  else if(mymonth ==9)
    month = " de Outubro de "
  else if(mymonth ==10)
    month = " de Novembro de "
  else if(mymonth ==11)
    month = " de Dezembro de "

  //Exibe na Pagina o Resultado concatenando(+) os valores
  return (day + myweekday + month + year);
}
function handleEnter(e, nxt){
	var characterCode;
	if(e && e.which)
	{
		e = e;
		characterCode = e.which;
	}
	else
	{
		e = event;
		characterCode = e.keyCode;
	}

	if(characterCode == 13)
	{
		document.getElementById(nxt).focus();
		return false;
	}
	else
	{
		return true;
	}
}

function escapeX(str) {
  str = escape(str);
//str = str.replace(/\//g,"%2F");
//str = str.replace(/\?/g,"%3F");
  str = str.replace(/=/g,"%3D");
//str = str.replace(/&/g,"%26");
//str = str.replace(/@/g,"%40");
  str = str.replace(/\+/g,"%2B");

  return str;
}

function codeXML(str){
  str = str.replace(/&/g,"&amp;");
  str = str.replace(/>/g, "&gt;");
  str = str.replace(/</g, "&lt;");
  str = str.replace(/"/g, "&quot;");
  
  return str;
}

function decodeXML(str){
  str= str.replace(/\&amp;/g, "&");
  str= str.replace(/\&gt;/g, ">");
  str= str.replace(/\&lt;/g, "<");
  str= str.replace(/\&quot;/g, "\"");
  
  return str;
}
  	 
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

// Exemplo de utilização:
//document.write (Trim("  Codigo Fonte    "));
function Trim(str){
    if(str.length == 0){
        return "";
    }else{
        return str.replace(/^\s+|\s+$/g,"");
    }
}

function include(arquivo){
//By Anônimo e Micox - http://elmicox.blogspot.com
   var novo = document.createElement("<script>");
   novo.setAttribute('type', 'text/javascript');
   novo.setAttribute('src', arquivo);
   document.getElementsByTagName('body')[0].appendChild(novo);
 //apos a linha acima o navegador inicia o carregamento do arquivo
 //portanto aguarde um pouco até o navegador baixá-lo. :)
}

function ajaxObj(){
   var ajax;

   if (window.XMLHttpRequest){
      // code for IE7+, Firefox, Chrome, Opera, Safari
      ajax=new XMLHttpRequest();
   }else{
      // code for IE6, IE5
     ajax=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
    return ajax;
}

function ajaxPost(pUrl, pArg, pRet){
    var ajax = ajaxObj();

    //se tiver suporte ajax
    if(ajax) {
       ajax.onreadystatechange = function () {
          if (ajax.readyState == 4 ) {
             var cType=ajax.getResponseHeader("Content-Type");
             if (cType.indexOf("xml") > 0) {
                // XML response
                pRet(ajax.responseXML);
             }else{
                // plain text response
                pRet(ajax.responseText);
             }
          }
       };

       ajax.open("POST", pUrl, true);
	   ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
       ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
       ajax.setRequestHeader("Pragma", "no-cache");
       ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded", charset="iso-8859-1");
	   
	   if (pArg){
          pArg = pArg+"&nOcAcH=" + new Date().getTime();
       }else{
          pArg = "nOcAcH=" + new Date().getTime();
       }
	   
       ajax.send(pArg);
    }
}

function ajaxGet(pUrl, pArg, pRet){
    var ajax = ajaxObj();

    //se tiver suporte ajax
    if(ajax) {
       ajax.onreadystatechange = function () {
          if (ajax.readyState == 4 ) {
             var cType=ajax.getResponseHeader("Content-Type");

             if (cType.indexOf("xml") > 0) {
                // XML response
                pRet(ajax.responseXML);
             }else{
                // plain text response
                pRet(ajax.responseText);
             }
          }
       };

       if (pArg){
          pArg = "?"+pArg+"&nOcAcH=" + new Date().getTime();
       }else{
          pArg = "?" + "nOcAcH=" + new Date().getTime();
       }

       ajax.open("GET", pUrl+pArg, true);
	   ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
       ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
       ajax.setRequestHeader("Pragma", "no-cache");
       ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded", charset="iso-8859-1");
       ajax.send();
    }
}

function postXML(pUrl, pXml, pFnc){
//alert(pXml);
    var ajax = ajaxObj();

    //se tiver suporte ajax
    if(ajax) {
       ajax.onreadystatechange = function () {
          if (ajax.readyState == 4 ){
              pFnc(ajax.responseText);
          }
       };
       
       ajax.open("POST",pUrl,true);
       //ajax.setRequestHeader('Content-Type','text/xml');
       ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded", charset="iso-8859-1");
//       ajax.setRequestHeader('encoding','iso-8859-1');
       ajax.send("pXml="+pXml);
    }
}

function form2xml(pFrm){
  var vXml = "<\?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?\>\n";
  vXml+= "<root>\n";
  vXml+="<"+pFrm.name+">\n";
  
  for (i=0; i<pFrm.elements.length; i++){
    vXml+="<"+pFrm.elements[i].name+">";
	vXml+=codeXML(pFrm.elements[i].value);
	vXml+="</"+pFrm.elements[i].name+">\n";
  }
  
  vXml+="</"+pFrm.name+">\n";
  vXml+= "</root>\n";
  
  return vXml;  
}

