/******************************************************************************************

	Trata Formularios GERAIS

*******************************************************************************************/

var CharEmail = new RegExp("[A-Za-z0-9_.-]+@([A-Za-z0-9_]+\.)+[A-Za-z]{2,4}");

function Del(Word) {
	a = Word.indexOf("<");
	b = Word.indexOf(">");
	len = Word.length;
	c = Word.substring(0, a);
	if(b == -1)
	b = a;
	d = Word.substring((b + 1), len);
	Word = c + d;
	tagCheck = Word.indexOf("<");
	
	if(tagCheck != -1){
		Word = Del(Word);
		return false;
	}else{
		return true;
	}
}
var isIE = false;
var req;
var msg;

function loadPHP( url, div )
{	
	Div = document.getElementById(div);
		
    if ( window.XMLHttpRequest )
	{
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open( "GET", url, true );
        req.send( null );
    }
	else if ( window.ActiveXObject )
	{
        isIE = true;
        req = new ActiveXObject( "Microsoft.XMLHTTP" );
        if ( req )
		{
            req.onreadystatechange = processReqChange;
            req.open( "GET", url, true );
            req.send(url);
        }
    }

}
function processReqChange()
{
	if ( req.readyState == 1 )
	{
		Div.innerHTML	=	"Carregando...";
	}
	if ( req.readyState == 4 )
	{
		if ( req.status == 200 )
		{
			var answer = req.responseText/*.replace(/\+/g," ")*/;
			Div.innerHTML = answer;
		}
		else
		{
			alert( "Ocorreu um problema na comunicação com o PHP:\n" + req.statusText );
		}
	}
}
/******************************************************************************************

	Minhas Configurações

*******************************************************************************************/
function CallContent( url, div )
{
	try
	{
		loadPHP( url, div );
	}
	catch ( e )
	{
		alert( "Não foi possível recuperar o conteúdo solicitado:\n" + msg );
		return;
	}
}
/******************************************************************************************

	MTESTE DE POST

*******************************************************************************************/
function loadSamePHP( url, div )
{
	Div = document.getElementById(div);
	
    if ( window.XMLHttpRequest )
	{
		req = new XMLHttpRequest();
		req.onreadystatechange = processSameChange;
		req.open( "POST", url, false );
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req.setRequestHeader("Referer",url);
		req.send();
    }
	else if ( window.ActiveXObject )
	{
        isIE = true;
        req = new ActiveXObject( "Microsoft.XMLHTTP" );
        if ( req )
		{
			req.onreadystatechange = processSameChange;
			req.open( "POST", url, false );
			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			//req.setRequestHeader("User-Agent", "Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)");
			req.setRequestHeader("Referer",url);
         req.send(url);
        }
    }
}

function processSameChange()
{
	if ( req.readyState == 1 )
	{
		Div.innerHTML	=	"Carregando...";
	}
	if ( req.readyState == 4 )
	{
		if ( req.status == 200 )
		{
			var answer = req.responseText;
			Div.innerHTML = answer;
		}
		else
		{
			alert( "Ocorreu um problema na comunicação com o PHP:\n" + req.statusText );
		}
	}
}

function ProcessUrl( url, div )
{
	try
	{
		loadSamePHP( url, div );
	}
	catch ( e )
	{
		alert( "Não foi possível recuperar o conteúdo solicitado:\n" + msg );
		return;
	}
}
/******************************************************************************************

	Janela POPUP

*******************************************************************************************/
function janelaPopUp(url, W, H){
	window.open(url,'Titulo','width='+ W +',height='+ H +',scrollbars=no,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=100');
}
function resizeOuterTo(w,h) {
	if (parseInt(navigator.appVersion)>3) {
	 top.resizeTo(w+10,h+60);
	}
}

function init()
{
  resizeOuterTo(document.images['Imagem'].width, document.images['Imagem'].height);
}
function fecharJanela(){
	self.close();
}
/******************************************************************************************

	Trocar imagem no Mouse do Menu

*******************************************************************************************/
/*sfHover = function() {

	var sfEls = document.getElementById("menu").getElementsByTagName("div");

	for (var i=0; i<sfEls.length; ++i) {

		sfEls[i].onmouseover=function() {

			this.className+=" sfhover";

		}

		sfEls[i].onmouseout=function() {

			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");

		}

	}

}

if (window.attachEvent) window.attachEvent("onload", sfHover);*/

/******************************************************************************************

	Login

*******************************************************************************************/
function trataLogin()
{
	if ( document.Login.pLoginStr.value == "" ) {
		alert ("Preencha o campo Login");
		document.Login.pLoginStr.focus ();
		return false;
	}else if( document.Login.pSenhaStr.value == "" ) {
		alert ("Preencha o campo Senha");
		document.Login.pSenhaStr.focus ();
		return false;
	}else{
		document.getElementById("Login").submit ();
		return true;
	}
}
function submitLogin(evt){
var charCode = (evt.which) ? evt.which : event.keyCode
	if(charCode == "13"){
		trataLogin();
	}
}
/******************************************************************************************

	Retirar 'Clique para ativar este controle' do Internet Explorer

*******************************************************************************************/
function ReescreverFlash(src) {
	document.write(src);
}
/******************************************************************************************

	Formulario de Cliente

*******************************************************************************************/
function escondeCPF() {
	document.Form.pCPFStr.disabled = true;
	document.Form.pCPFStr.value = "";
	document.Form.pCPFStr.className = "inputDisable";
	
	document.Form.pCNPJStr.disabled = false;
	document.Form.pCNPJStr.className = "input";
}

function escondeCNPJ() {
	document.Form.pCNPJStr.disabled = true;
	document.Form.pCNPJStr.value = "";
	document.Form.pCNPJStr.className = "inputDisable";
	
	document.Form.pCPFStr.disabled = false;
	document.Form.pCPFStr.className = "input";
}
function escondeCNPJCPF() {
	document.Form.pCNPJStr.disabled = true;
	document.Form.pCNPJStr.value = "";
	document.Form.pCNPJStr.className = "inputDisable";
	
	document.Form.pCPFStr.disabled = true;
	document.Form.pCPFStr.value = "";
	document.Form.pCPFStr.className = "inputDisable";
}
/******************************************************************************************

	Mostra e Esconde Menu Interativo

*******************************************************************************************/
var velocidade = 48;
var inter;
var maxi;
function MostraMenu()
{
	if(velocidade == 156)
	{
	clearInterval(inter);
	return;
	maxi = 1;
	}

	obj = document.getElementById("menuReplace");
	obj.style.visibility = 'visible';
	velocidade += 4;
	obj.style.width = velocidade + 'px';
}
function EscondeMenu()
{
	obj = document.getElementById("menuReplace");

	if(velocidade == 48)
	{
	obj.style.visibility = 'visible';
	obj.style.width = '48px';
	clearInterval(inter);
	return;
	}
	velocidade -= 4;
	obj.style.width = velocidade + 'px';
}

function decideMenu(){
	if(document.getElementById("menuReplace").style.width=='156px'){
		return inter=setInterval('EscondeMenu();',3);return false;
	}else{
		return inter=setInterval('MostraMenu();',3);return false;
	}
}