// Object Control
	Control = {}
	
	Control.Color;
	Control.Noticias;
	Control.PageNoticias;
	Control.Count = 0;
	Control.Posicao = 1;

//******************
//** Trava a Tela **
//******************	
function setContext(ev){
	
	if(ev.button == 2){
		alert('Copyright© 2010 Versifico.');
		return false;
	}
}
	
//***********************************
//** Esconde o div de Apresentação **
//***********************************
function esconde_Splash(){
	document.getElementById('splash').style.display = 'none';
}

//******************
//** Abre Loading **
//******************
function openLoading(){
	document.getElementById('loading').style.display = '';
}

//******************
//** fecha Loading **
//******************
function closeLoading(){
	document.getElementById('loading').style.display = 'none';
}

//*****************************
//** Muda o Fundo dos Botões **
//*****************************
function MudaFundoBot(obj){
	if(obj.className == "fundoBot"){
		obj.className = "fundoBot2";
	}
	else{
		obj.className = "fundoBot";
	}
}

//****************************************
//** Muda a Imagem do botão de Noticías **
//****************************************
function mudaImage(obj){
	n = obj.src.substr(obj.src.length -5, obj.src.length);
	
	if(n == '1.png'){
		obj.src = obj.src.substring(0, obj.src.length - 5) + "0.png";
	}else{
		obj.src = obj.src.substring(0, obj.src.length - 5) + "1.png";
	}
}

//*********************
//** Abre as Páginas **
//*********************
function openPage(page){
	
	if(Main){
		Main.location.href = page;
	}
}

//*************************
//** Abre as Sub Páginas **
//*************************
function openSubPage(page){
	
	if(SubMain){
		SubMain.location.href = page;
	}
}

//*****************************************
//** MUDA COR DO TEXTO AO PASSAR O MOUSE **
//*****************************************
function colorsOver(obj){
	
	if(obj.className == 'subTop'){
		obj.className = 'subTopOver';	
		Control.Color = 1;
	}
	
	if(obj.className == 'subTopOut'){
		obj.className = 'subTopOver';
	}
}

//****************************************
//** MUDA COR DO TEXTO AO TIRAR O MOUSE **
//****************************************
function colorsOut(obj){
	
	if(obj.className == 'subTopOver'){
		obj.className = 'subTopOut';
	}
	
	if(Control.Color == 1){
		obj.className = 'subTop';
		Control.Color = 0;
	}
}

//*********************************
//** MUDA COR DO TEXTO AO CLICAR **
//*********************************
function colorsClick(obj){
		
	if(document.getElementById("1")){
		if(obj.id != 1){
			obj.className = 'subTop';
			document.getElementById("1").className = 'subTopOut';
			document.getElementById("1").id = 0;
			obj.id = 1;
		}
	}
}

//*******************
//** ABRE SUB MENU **
//*******************
function subMenu(){
	var menu;
	
	menu = document.getElementById('subMenu');
	menu.className = 'ContextSubMenu';
	menu.style.display = '';
	
	tamanhoTela = window.screen.width + "X" + window.screen.height;
	
	switch(tamanhoTela){
		case "800X600": menu.style.top = 138;
						menu.style.left = 219;
		break;
		case "1024X768": menu.style.top = 138;
						 menu.style.left = 314;
		break;
		case "1280X800": menu.style.top = 138;
						 menu.style.left = 440;
		break;
		case "1280X1024": menu.style.top = 138;
						 menu.style.left = 440;
		break;
		case "1600X1200": menu.style.top = 138;
						 menu.style.left = 440;
		break;
	}
	
	menu.innerHTML = BuildContextMenu();
}

//**********************
//** HTML DO SUB MENU **
//**********************
function BuildContextMenu(){
var sText = '<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=ISO-8859-1\">';

	sText = sText + '<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">' +
	'<tr><td height=\"20px\" class=\"fundoBot\" onMouseOver=\"MudaFundoBot(this);\" onMouseOut=\"MudaFundoBot(this); ClearSubMenuPr(\'nfe\');\" onClick=\"openPage(\'cases_nfe.htm\'); openLoading(); ClearSubMenu();\">&nbsp;Nota Fiscal Eletrônica</td></tr>' +
	'<tr><td height=\"20px\" class=\"fundoBot\" onMouseOver=\"MudaFundoBot(this);\" onMouseOut=\"MudaFundoBot(this); ClearSubMenuPr(\'esirap\');\" onClick=\"openPage(\'cases_esirap.htm\'); openLoading(); ClearSubMenu();\">&nbsp;e-SIRAP</td></tr>' +
	'<tr><td height=\"20px\" class=\"fundoBot\" onMouseOver=\"MudaFundoBot(this);\" onMouseOut=\"MudaFundoBot(this); ClearSubMenuPr(\'ello\');\" onClick=\"openPage(\'cases_ello.htm\'); openLoading(); ClearSubMenu();\">&nbsp;Ello</td></tr>' +
	'<tr><td height=\"20px\" class=\"fundoBot\" onMouseOver=\"MudaFundoBot(this);\" onMouseOut=\"MudaFundoBot(this); ClearSubMenuPr(\'fabrica\');\" onClick=\"openPage(\'cases_fabrica.htm\'); openLoading(); ClearSubMenu();\">&nbsp;Fábrica de Software</td></tr>' +
	'</table>';
	return sText;	
}

//********************
//** FECHA SUB MENU **
//********************
function ClearSubMenu(){
	document.getElementById('subMenu').style.display = 'none';
}

function ClearSubMenuPr(obj){
	
	x = window.event.screenX;
	y = window.event.screenY;
	
	tamanhoTela = window.screen.width + "X" + window.screen.height;
	
	switch(tamanhoTela){
		case "1024X768": 
			if(obj == 'nfe'){
				if((x == 400) || ((x >= 470) && (x <= 550)) || ((y >= 100) && (y <= 265))){
					ClearSubMenu();
				}
			}
			if(obj == 'esirap'){
				if((x >= 470) && (x <= 550)){
					ClearSubMenu();
				}
			}
			if(obj == 'ello'){
				if((x >= 470) && (x <= 550)){
					ClearSubMenu();
				}
			}
			if(obj == 'fabrica'){
				if(((x >= 470) && (x <= 550)) || ((y >= 330) && (y <= 420))){
					ClearSubMenu();
				}
			}
		break;
		case "1280X800":
			if(obj == 'nfe'){
				if((x == 400) || ((x >= 600) && (x <= 700)) || ((y >= 100) && (y <= 248))){
					ClearSubMenu();
				}
			}
			if(obj == 'esirap'){
				if((x >= 600) && (x <= 700)){
					ClearSubMenu();
				}
			}
			if(obj == 'ello'){
				if((x >= 600) && (x <= 700)){
					ClearSubMenu();
				}
			}
			if(obj == 'fabrica'){
				if(((x >= 600) && (x <= 700)) || ((y >= 305) && (y <= 400))){
					ClearSubMenu();
				}
			}
		break;
		case "1280X1024":
			if(obj == 'nfe'){
				if((x == 400) || ((x >= 600) && (x <= 650)) || ((y >= 100) && (y <= 260))){
					ClearSubMenu();
				}
			}
			if(obj == 'esirap'){
				if((x >= 600) && (x <= 650)){
					ClearSubMenu();
				}
			}
			if(obj == 'ello'){
				if((x >= 600) && (x <= 650)){
					ClearSubMenu();
				}
			}
			if(obj == 'fabrica'){
				if(((x >= 600) && (x <= 650)) || ((y >= 320) && (y <= 400))){
					ClearSubMenu();
				}
			}
		break;
		case "1600X1200":
			if(obj == 'nfe'){
				if((x == 400) || ((x >= 600) && (x <= 650)) || ((y >= 100) && (y <= 260))){
					ClearSubMenu();
				}
			}
			if(obj == 'esirap'){
				if((x >= 600) && (x <= 650)){
					ClearSubMenu();
				}
			}
			if(obj == 'ello'){
				if((x >= 600) && (x <= 650)){
					ClearSubMenu();
				}
			}
			if(obj == 'fabrica'){
				if(((x >= 600) && (x <= 650)) || ((y >= 293) && (y <= 360))){
					ClearSubMenu();
				}
			}
		break;
	}
}

//**********************
//** CARREGA NOTICIAS **
//**********************
function loadNoticias(){
	
	switch(Control.Count){
		case 0: 
				Control.Noticias = "<b>Penalty adota nota fiscal eletrônica em suas fábricas utilizando a solução da Versifico.</b><p>Leia Mais...";
				Control.Posicao = 1;
				rola();
				Control.PageNoticias = 'noticias1.htm';
			break;
		case 1: 
				
				Control.Noticias = "<b>Nota Fiscal Eletrônica<br>Empresas obrigadas a partir de 01/04/2010</b><p>Veja o protocolo na integra com a lista completa de segmentos obrigatórios para 01/04/2010<p>Leia Mais...";
				Control.Posicao = 1;
				rola();
				Control.PageNoticias = 'noticias2.htm';
			break;
		case 2: 
				Control.Noticias = "<b>Nota Fiscal Eletrônica<br>Empresas obrigadas a partir de 01/07/2010</b><p>Veja o protocolo na integra com a lista completa de segmentos obrigatórios para 01/07/2010<p>Leia Mais...";
				Control.Posicao = 1;
				rola();
				Control.PageNoticias = 'noticias3.htm';
			break;
		/*case 3:
				Control.Noticias = "<b>Participantes da CW Connect confessam dificuldades com a NF-e.</b><p>À medida que avança, o projeto da Nota Fiscal Eletrônica (NF-e) segue gerando questionamentos e dúvidas. Implantação dos sistemas não é tão fácil como diz a receita...<p>Leia Mais...";
				Control.Posicao = 1;
				rola();
				Control.PageNoticias = 'noticias4.htm';
			break;*/
	}
	
	Control.Count++;
	
	if(Control.Count >= 3){
		Control.Count = 0;
	}
	
	setTimeout("loadNoticias()",20000);
}

function rola(){
	
	Noticias.document.getElementById('not').innerHTML = Control.Noticias.substring(0,Control.Posicao);
	Control.Posicao++;
	
	if(Control.Posicao == Control.Noticias.length+1){
		Control.Posicao = 1;
	}else{
		setTimeout("rola()",30);
	}
}

//***********************
//** VALIDA FORMULÁRIO **
//***********************
function validaForm(){
	
	erro="";
	
	for(c=0; c<document.forms[0].length;c++){
		if(document.forms[0].elements[c].id == "V"){
			if(document.forms[0].elements[c].value == ""){
				erro += "Campo " + document.forms[0].elements[c].name + " obrigatório!\n";
			}
		}
	}
	
	if(erro != ""){
		alert(erro);
	}else{
		document.frm_fale_conosco.submit();
	}
}

//*************************
//******MASCARA CNPJ*******
//*************************  

function mascaraCNPJ(obj, ev){
	enableLetter(ev, obj);
	var CNPJ = obj;
	var c;
	
	if(ev.keyCode == 46){obj.value.substr(0, obj.value.length - 1)};
	
	if((ev.keyCode != 8)&&(ev.keyCode != 46)&&(ev.keyCode != 37)&&(ev.keyCode != 39)){
		if((obj.value.substr(0,1)!= '.')&&(obj.value.length >= 2)&&(obj.value.length < 3)){
			obj.value = obj.value + '.';
		}
		if((obj.value.substr(6,1)!= '.')&&(obj.value.length >= 6)&&(obj.value.length < 8)){
			obj.value = obj.value + '.';	
		}
		if((obj.value.substr(10,1)!= '/')&&(obj.value.length >= 10)&&(obj.value.length < 12)){
			obj.value = obj.value + '/';
		}	
		
		if((obj.value.substr(15,1)!= '-')&&(obj.value.length >= 15)&&(obj.value.length < 18) && (obj.value.indexOf('-') <= 0)){
			obj.value = obj.value + '-';
		}	
		
		
		if((obj.value.length >= 18)&&(((ev.keyCode >= 48) && (ev.keyCode <= 57)) || (ev.keyCode == 144))){
			for(c=0;c<document.forms[0].length;c++){
				if(document.forms[0].elements[c].name == obj.name){
					if(document.forms[0].elements[c+1]){
						document.forms[0].elements[c+1].focus();
					}
				}
			}
		}
	}
}
     
function enableLetter(ev, obj){

	if(ev.keyCode==190){
		obj.value = obj.value.substring(0, obj.value.length -1);
	}
	if((ev.keyCode==193)||(ev.keyCode==111)){
		obj.value = obj.value.substring(0, obj.value.length -1);
	}
	if((ev.keyCode==189)||(ev.keyCode==109)){
		obj.value = obj.value.substring(0, obj.value.length -1);
	}
}

//*****************
//** VALIDA CNPJ **
//*****************
function validaCNPJ(n) {
	n = n.name;
	
     CNPJ = eval('document.forms[0].' + n + '.value');
     erro = new String; 
         
     if(CNPJ != ''){
         if (CNPJ.length < 18) erro += "É necessário preencher corretamente o número do CNPJ! \n\n"; 
         if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
         if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! \n\n";
         }
         //substituir os caracteres que não são números
       if(document.layers && parseInt(navigator.appVersion) == 4){
               x = CNPJ.substring(0,2);
               x += CNPJ. substring (3,6);
               x += CNPJ. substring (7,10);
               x += CNPJ. substring (11,15);
               x += CNPJ. substring (16,18);
               CNPJ = x; 
       } else {
               CNPJ = CNPJ. replace (".","");
               CNPJ = CNPJ. replace (".","");
               CNPJ = CNPJ. replace ("-","");
               CNPJ = CNPJ. replace ("/","");
       }
       var nonNumbers = /\D/;
       if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n"; 
	  	
       var a = [];
       var b = new Number;
       var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
       for (i=0; i<12; i++){
               a[i] = CNPJ.charAt(i);
               b += a[i] * c[i+1];
		}
       if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
       b = 0;
       for (y=0; y<13; y++) {
               b += (a[y] * c[y]); 
       }
       if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
       if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
               erro +="CNPJ Inválido!";
       }
       
       if(CNPJ == "00000000000000"){
	       erro +="CNPJ Inválido!";
       }
       
       if (erro.length > 0){
               alert(erro);
               foco = eval('document.forms[0].' + n);                      
               foco.focus();
               foco.select();
               return false;
       }                
   }
}

//**************************
//****** MÁSCARA CEP *******
//**************************

function mascaraCEP(obj, ev){
	cep = obj;
	if((obj.value.substr(4,1) != '-')&&(obj.value.length == 5)){
		obj.value = obj.value + '-';
	}	
}

//**********************
//** Mascara Telefone **
//**********************
function mascaraTelefone(obj){
	fone = obj;
	if((fone.value.substr(4,1) != '-')&&(fone.value.length == 4)){
		fone.value = obj.value + '-';
	}	
}

//*******************
//** Passa o Focus **
//*******************
function nextFld(obj,nextf,lengthf){
	if(obj.value.length == lengthf){
		eval('document.forms[0].elements["' + nextf + '"].focus()')
	}
}

function changeImage(obj, sid){
	var o = eval(document.getElementById(sid));
	
	if(o.style.display == 'none'){
		o.style.display	= '';
		obj.src='images/minor.gif';
	}else{
		o.style.display	= 'none';
		obj.src='images/plus.gif';
	}
}