//<![CDATA[

//Inicializa recursos ajax
try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}


js_target = '';
isBusy    = '';
xmlhttp   = '';

function hiddenGetAjax(page,varsa)
{
		if (window.XMLHttpRequest)
		{xmlhttp = new XMLHttpRequest();}
		else if(window.ActiveXObject)
		{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}

    //Abre a url
		if(varsa=="undefined"||varsa==""||varsa==false)
			{
			var varsa=""
			xmlhttp.open("GET","ajax.php?page="+page,true);
      isBusy = true;
			xmlhttp.setRequestHeader('Content-Type','text/html');
			xmlhttp.setRequestHeader('encoding','ISO-8859-1');
			}
			else
			{
			var varsa = varsa;
			xmlhttp.open("GET","ajax.php?page="+page+varsa,true);
      isBusy = true;
			xmlhttp.setRequestHeader('Content-Type','text/html');
			xmlhttp.setRequestHeader('encoding','ISO-8859-1');
			}
		xmlhttp.send(null);
}


function hiddenGetAjaxReturn(page,varsa)
{
		if (window.XMLHttpRequest)
		{xmlhttp = new XMLHttpRequest();}
		else if(window.ActiveXObject)
		{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}

    //Abre a url
		if(varsa=="undefined"||varsa==""||varsa==false)
			{
			var varsa=""
			xmlhttp.open("GET","ajax.php?page="+page,true);
      isBusy = true;
			xmlhttp.setRequestHeader('Content-Type','text/html');
			xmlhttp.setRequestHeader('encoding','ISO-8859-1');
			}
			else
			{
			var varsa = varsa;
			xmlhttp.open("GET","ajax.php?page="+page+varsa,true);
      isBusy = true;
			xmlhttp.setRequestHeader('Content-Type','text/html');
			xmlhttp.setRequestHeader('encoding','ISO-8859-1');
			}
		xmlhttp.onreadystatechange= processGetReturn;
		xmlhttp.send(null);
}


function getAjax(page,target,varsa,loader)
{
		js_target = target;
    if(loader!='0')
    {
		document.getElementById(target).innerHTML = "<p style=\"text-align:center;padding:50px;color:#036;color:#fff;\"><img src=\"images/ajax-loader.gif\" width=\"128\" height=\"15\" border=\"0\" alt=\"Carregando\"><br /><br />"+loader+"</p>\n";
    }
    else
    {
    document.getElementById(target).innerHTML = "Carregando\n";
    }

		if (window.XMLHttpRequest)
		{xmlhttp = new XMLHttpRequest();}
		else if(window.ActiveXObject)
		{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}

    //Abre a url
		if(varsa=="undefined"||varsa==""||varsa==false)
			{
			var varsa=""
			xmlhttp.open("GET","ajax.php?page="+page,true);
      isBusy = true;
			xmlhttp.setRequestHeader('Content-Type','text/html');
			xmlhttp.setRequestHeader('encoding','ISO-8859-1');
			}
			else
			{
			var varsa = varsa;
			xmlhttp.open("GET","ajax.php?page="+page+varsa,true);
      isBusy = true;
			xmlhttp.setRequestHeader('Content-Type','text/html');
			xmlhttp.setRequestHeader('encoding','ISO-8859-1');
			}
		xmlhttp.onreadystatechange= processGet;
		xmlhttp.send(null);
}


function processGet()
{
	//Executada quando o navegador obtiver o código
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			if (xmlhttp.status)
			{
				if (xmlhttp.status == 200)
				{
					//Lê o texto
					var js_xcontent	=	xmlhttp.responseText

					//Desfaz o urlencode
					//texto=unescape(texto)

					//Exibe o texto no div conteúdo
					if(document.getElementById(js_target))
					{
						document.getElementById(js_target).innerHTML	=	js_xcontent;
            isBusy = false;
            if(document.getElementById('alertMessage'))
            {
              if(document.getElementById('alertMessage').value!="")
              {
              alert(document.getElementById('alertMessage').value)
              }
            }
					}
				}
				else
				{
					//alert("An error occurs during get requisition" + xmlhttp.statusText);
					alert("Ocorreu um erro durante o processamento, por favor tente novamente. Erro: " + xmlhttp.statusText);
				}
			}
		}
	}
}


function processGetReturn()
{
	//Executada quando o navegador obtiver o código
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			if (xmlhttp.status)
			{
				if (xmlhttp.status == 200)
				{
					//Lê o texto
					var js_xcontent	=	xmlhttp.responseText
          isBusy = false;

					//Desfaz o urlencode
					//texto=unescape(texto)
          eval(js_xcontent);
				}
				else
				{
					//alert("An error occurs during get requisition" + xmlhttp.statusText);
					alert("Ocorreu um erro durante o processamento, por favor tente novamente." + xmlhttp.statusText);
				}
			}
		}
	}
}






function postAjax(formToPost,page,target,varsa,loader)
{
  js_target = target;

  if(document.getElementById('validator'))
  {
    var form_error      = 0;
    var js_check        = window.document.getElementById(formToPost);
    var js_validator    = document.getElementById('validator').value;
    eval(js_validator);
  }
  else
  {
    var form_error = 0;
  }

  if(form_error==0)
  {

  function adaptChars(string)
  {
    string=string.replace(/\+/g,"[||]");
    string=string.replace(/\&/g,"[|||]");
    return string;
  }

		//le os campos do forumulário
		var js_fields		= window.document.getElementById(formToPost);
		var js_nfields	= js_fields.elements.length;
    if(document.getElementById('validator'))
    {
		var js_nnnum		= js_nfields -1;
    }
    else
    {
    var js_nnnum		= js_nfields;
    }
		var js_ynum			= 0;
		var js_poststr	= "";
		var field_value = "";



		while(js_ynum<js_nnnum)
		{
			if(js_ynum>0){var js_add = "&";}else{js_add ="";}

			if(js_fields.elements[js_ynum].type!=undefined&&js_fields.elements[js_ynum].name!='validator')
			{
			field_value = js_fields.elements[js_ynum].value;
			var js_poststr = js_poststr+js_add+js_fields.elements[js_ynum].name+"="+encodeURI(adaptChars(field_value));
			//limpa campo lido
			js_fields.elements[js_ynum].value = "";
			}
		js_ynum ++;
		}

		js_poststr=js_poststr.replace(/\+/g,"[||]");

		document.getElementById(target).innerHTML = "<p style=\"text-align:center;padding:50px;color:#fff;\"><img src=\"images/ajax-loader.gif\" width=\"128\" height=\"15\" border=\"0\" alt=\"Carregando\"><br /><br />"+loader+"</p>\n";

		if (window.XMLHttpRequest)
		{xmlhttp = new XMLHttpRequest();}
		else if(window.ActiveXObject)
		{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
		xmlhttp.onreadystatechange = processpost;
		xmlhttp.open('POST',"ajax.php?page="+page, true);
    isBusy = true;
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader('encoding','ISO-8859-1');
		xmlhttp.setRequestHeader("Content-length", js_poststr.length);
		xmlhttp.setRequestHeader("Connection", "close");
		//alert(js_poststr);
		//alert(js_poststr.length);
		xmlhttp.send(js_poststr);
  }
}

//rotina final do post
function processpost()
{
	if (xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200)
		{
		var js_content	= xmlhttp.responseText;
    isBusy = false;
		document.getElementById(js_target).innerHTML = js_content;
    if(document.getElementById('alertMessage'))
    {
      if(document.getElementById('alertMessage').value!="")
      {
      alert(document.getElementById('alertMessage').value)
      }
    }
		//alert(js_content);
		}
		else
		{
			//alert("Occurs a problem with your requisition!");
			alert("Ocorreu um erro durante o processamento, por favor tente novamente.");
		}
	}
}

function mask(o,f)
{
    v_obj=o
    v_fun=f
    setTimeout("execmask()",1)
}

function execmask()
{
    v_obj.value=v_fun(v_obj.value)
}

function onlyNumber(v)
{
    return v.replace(/\D/g,"")
}

function onlyNumbersAndChars(v)
{
  var size  = v.length;
  var chars = v.replace(/[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]/g,"");
  if(chars.length!=size)
  {
  alert('Somente Letras ou Números');
  return chars;
  }
  else
  {
  return chars;
  }
}



function verificaForca( campo ) {
    var valor = campo.value;
    if(valor!='')
    {
      var contemNumeros   = /[0-9]/;
      var contemLetras    = /[a-z]/;
      var contemLETRAS    = /[A-Z]/;
      //var contemEspecial  = /[@#$%&amp;amp;*]/;
      var contagem = 0;
      var mensagem = "";

      if ( valor.length > 0 ) {
          if ( contemNumeros.test( valor ) ) contagem++;
          if ( contemLetras.test( valor ) ) contagem++;
          if ( contemLETRAS.test( valor ) ) contagem++;

          switch ( contagem ) {
              case 1: mensagem = "<b style=\"color:#900;\">SEGURANÇA FRACA!</b>";
                          break;
              case 2: mensagem = "<b style=\"color:#66cc33;\">SEGURANÇA MEDIA!</b>";
                          break;
              case 3: mensagem = "<b style=\"color:#00f;\">SEGURANÇA BOA!</b>";
                          break;
              default: mensagem = "<b>ops! Erro!</b>";
          }

          document.getElementById('levelpass').innerHTML = mensagem;
      }
    }
    else
    {
    document.getElementById('levelpass').innerHTML = "";
    }
}


//]]>