//response.charset = "ISO-8859-1"

var objMenu;

function validaFrmLogin(){
	var usuario = document.getElementById('usuario');
	var senha = document.getElementById('senha');
	var msgBox = document.getElementById('msgBox');
	
	if(usuario.value.length == 0){
		msgBox.innerHTML = 'Digite seu usuário';
		msgBox.style.color = '#800000';
		usuario.focus();
	}else if(senha.value.length == 0){
		msgBox.innerHTML = 'Digite sua senha';
		msgBox.style.color = '#800000';
		senha.focus();
	}else{
		msgBox.innerHTML = 'Verificando login, aguarde...';
		msgBox.style.color = '#008000';
		startAjax('include/login.asp?usuario='+usuario.value+'&senha='+senha.value,12);
	}
}

function login(){
	var msgBox = document.getElementById('msgBox');
	
	if(xmlhttp.readyState==4){
		if(xmlhttp.responseText=='0'){
			msgBox.innerHTML = 'Login incorreto';
			msgBox.style.color = '#800000';
		}else{
			msgBox.innerHTML = 'Login correto, entrando...';
			msgBox.style.color = '#008000';
			window.location = 'admin/';
		}
	}
}


function getBrowserWidth(){
	if (window.innerWidth){
		return window.innerWidth;
	}else if (document.documentElement && document.documentElement.clientWidth != 0){
		return document.documentElement.clientWidth;
	}else if (document.body){
		return document.body.clientWidth;
	}else if (window.screen){
		return window.screen.width;
	}else if (document.body.scrollWidth){
		return document.body.scrollWidth;
	}else return 0;
}

function posicao(){
	var obj = document.getElementById('Layer1');
	var posIni = 0;
	alert(getBrowserWidth());
	if (getBrowserWidth()>770) posIni = (getBrowserWidth() - 770)/2;	
	obj.style.left = posIni + 150 + 'px';
	obj.style.display = '';
}

function mover(){
	var obj;
	var isNetscape = (navigator.appName == 'Netscape');
	var xMais	=	new Number(getBrowserWidth());

	if(isNetscape){
		if(xMais>800){
			xMais = (xMais-800)/2;
		}else{
			xMais = 0;
		}
	}else{
		if(xMais>779){
			xMais = (xMais-779)/2;
		}else{
			xMais = 0;
		}
	}
	
	//Altera o flash
	obj = document.getElementById('flashIdioma');
	obj.style.left = 605+xMais+'px';
	
	//Altera a página
	obj = document.getElementById('divPagina');
	obj.style.left = 0+xMais+'px';
	
	//Altera o subMenu1
	obj = document.getElementById('subMenu1');
	obj.style.left = 219+xMais+'px';
	
}

function votar(idCampo){
	startAjax('pesquisaVoto.asp?idPesquisaCampo='+idCampo,4);
}


function mudaPagina(pagina, queryString){
	document.getElementById('pagina').value				=	pagina;
	document.getElementById('queryString').value	=	queryString;
	
	startAjax(pagina+'?'+queryString,1);
}

function reloadPagina(){
	if(xmlhttp.readyState==4){
		var	pagina			=	document.getElementById('pagina').value;
		var	queryString	=	document.getElementById('queryString').value;
		
		mudaPagina(pagina, queryString);
	}
}

function geraPagina(){
	if(xmlhttp.readyState==4){
		document.getElementById('conteudo').innerHTML = xmlhttp.responseText;
		startAjax('include/titulo.asp?pagina='+document.getElementById('pagina').value+'&'+document.getElementById('queryString').value, 2)
	}
}

function trocaMenu(idLinguagem){
	var campoLink	=	document.getElementById('link');

	switch(idLinguagem){
		case	1	:	if (AC_FL_RunContent == 0) {
								alert("Esta página precisa do arquivo de ativação do flash.");
							} else {
								AC_FL_RunContent(
									'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
									'width', '161',
									'height', '83',
									'src', 'flash/menuLinguagemPortugues',
									'quality', 'high',
									'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
									'align', 'middle',
									'play', 'true',
									'loop', 'true',
									'scale', 'showall',
									'wmode', 'transparent',
									'devicefont', 'false',
									'id', 'topo',
									'bgcolor', '#ffffff',
									'name', 'flashIdioma',
									'menu', 'false',
									'allowScriptAccess','sameDomain',
									'movie', 'flash/menuLinguagemPortugues',
									'salign', ''
									);
							}
							campoLink.innerHTML = '<a class="desenvolve" href="http://www.pampasweb.com.br" target="_blank">desenvolvido por pampasWEB</a>';
							break;
		case	2	:	if (AC_FL_RunContent == 0) {
								alert("Esta página precisa do arquivo de ativação do flash.");
							} else {
								AC_FL_RunContent(
									'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
									'width', '161',
									'height', '83',
									'src', 'flash/menuLinguagemIngles',
									'quality', 'high',
									'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
									'align', 'middle',
									'play', 'true',
									'loop', 'true',
									'scale', 'showall',
									'wmode', 'transparent',
									'devicefont', 'false',
									'id', 'topo',
									'bgcolor', '#ffffff',
									'name', 'flashIdioma',
									'menu', 'false',
									'allowScriptAccess','sameDomain',
									'movie', 'flash/menuLinguagemIngles',
									'salign', ''
									);
							}
							campoLink.innerHTML = '<a class="desenvolve" href="http://www.pampasweb.com.br" target="_blank">developed by pampasWEB</a>';
							break;
		case	3	:	if (AC_FL_RunContent == 0) {
								alert("Esta página precisa do arquivo de ativação do flash.");
							} else {
								AC_FL_RunContent(
									'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
									'width', '161',
									'height', '83',
									'src', 'flash/menuLinguagemEspanhol',
									'quality', 'high',
									'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
									'align', 'middle',
									'play', 'true',
									'loop', 'true',
									'scale', 'showall',
									'wmode', 'transparent',
									'devicefont', 'false',
									'id', 'topo',
									'bgcolor', '#ffffff',
									'name', 'flashIdioma',
									'menu', 'false',
									'allowScriptAccess','sameDomain',
									'movie', 'flash/menuLinguagemEspanhol',
									'salign', ''
									);
							}
							campoLink.innerHTML = '<a class="desenvolve" href="http://www.pampasweb.com.br" target="_blank">desenvolvido por pampasWEB</a>';
	}
	mover();
	startAjax('include/idioma.asp?idioma='+idLinguagem,5);
	
}

function menuTexto(){
	if(xmlhttp.readyState==4){
		startAjax('include/menuTexto.asp',3);
	}
}

function alterarTitulo(){
	if(xmlhttp.readyState == 4){
		document.getElementById('titulo').innerHTML = xmlhttp.responseText;
		
		var pagina = document.getElementById('pagina').value
		var queryString	=	document.getElementById('queryString').value
		
		
		if(pagina=='paises.asp'){
			startAjax('paisesDetalhes.asp?'+queryString,6);
		}else if(pagina=='fale.asp'){
			startAjax('faleFrm.asp?'+queryString,7);
		}
	}
}

function alterarMenuTexto(){
	if(xmlhttp.readyState == 4){
		document.getElementById('menu').innerHTML = xmlhttp.responseText;
		startAjax('include/subMenu1.asp',9);
	}
}

function alteraSubMenu1Texto(){
	if(xmlhttp.readyState == 4){
		document.getElementById('subMenu1').innerHTML = xmlhttp.responseText;
		
		var pagina			= document.getElementById('pagina').value;
		var queryString	=	document.getElementById('queryString').value;
		
		mudaPagina(pagina, queryString);
	}
}

function capa(){
	mudaPagina('capa.asp','');
}

function fale(){
	mudaPagina('fale.asp','');
}

function empresa(){
	mudaPagina('empresa.asp','');
}

function produto(){
	mudaPagina('produto.asp','');
}

function loginFrm(){
	mudaPagina('loginFrm.asp','');
}

function produtoCliente(idCliente){
	mudaPagina('produtoCliente.asp','idCliente='+idCliente);
}

function produtoDetalhe(paginaVoltar,idVoltar,idDetalhe,idProduto){
	mudaPagina('produtoDetalhe.asp','paginaVoltar='+paginaVoltar+'&idVoltar='+idVoltar+'&idProdutoDetalhe='+idDetalhe+'&idProduto='+idProduto);
}

function paises(idPais){
	mudaPagina('paises.asp','idPais='+idPais);
}

function pesquisaAnterior(){
	mudaPagina('pesquisaAnterior.asp','');
}

function clientes(){
	mudaPagina('clientes.asp','');
}

function campoFocus(obj){
	obj.style.backgroundColor = '#E0E0E0';
}

function campoBlur(obj){
	obj.style.backgroundColor = '';
}

function subMenuOver(obj){
	try{
		objMenu.style.backgroundColor = '';
	}catch(objMenu){}
	obj.style.backgroundColor = '#E0E0E0';
	objMenu = obj;
}

function subMenuOut(obj){
	obj.style.backgroundColor = '';
}

function menuOver(obj){
	obj.style.color = '#E75552';
}

function menuOut(obj){
	obj.style.color = '';
}

function produtoOver(){
	document.getElementById('subMenu1').style.display = '';
	menuOver(document.getElementById('menuProduto'));
}

function produtoOut(){
	document.getElementById('subMenu1').style.display = 'none';
	menuOut(document.getElementById('menuProduto'));
}

function trocaDestinoFale(index){
	document.getElementById('destino').selectedIndex = index;
}

function validaEmail(str) {
	expressaoEmail = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[a-zA-Z]$";
	var expressaoRegular = new RegExp(expressaoEmail);
	return (!(expressaoRegular.test(str)));
}


function validaFrmFale(idioma){
	var nome				=	document.getElementById('nome');
	var empresa			=	document.getElementById('empresa');
	var email				=	document.getElementById('email');
	var destino			=	document.getElementById('destino');
	var assunto			=	document.getElementById('assunto');
	var mensagem		=	document.getElementById('mensagem');
	var strMensagem	=	mensagem.value;
	var ok					=	false;
	
	while(strMensagem.indexOf('\n')>0){
		strMensagem = strMensagem.replace('\n', '<br />');
	}

	
	switch(idioma){
		case	1	:		if(nome.value.length == 0){
									alert('Digite o nome para contato.');
									nome.focus();
								}else if(empresa.value.length == 0){
									alert('Digite o nome da empresa.');
									empresa.focus();
								}else if(email.value.length == 0){
									alert('Digite um e-mail para contato.');
									email.focus();
								}else if(validaEmail(email.value)){
									alert('Digite um e-mail válido.');
									email.focus();
								}else if(mensagem.value.length == 0){
									alert('Digite a sua mensagem.');
									mensagem.focus();
								}else{
									ok = true;
								}
								break;
		case	2	:		if(nome.value.length == 0){
									alert('Enter name.');
									nome.focus();
								}else if(empresa.value.length == 0){
									alert('Enter company.');
									empresa.focus();
								}else if(email.value.length == 0){
									alert('Enter e-mail.');
									email.focus();
								}else if(validaEmail(email.value)){
									alert('Enter a valid e-mail.');
									email.focus();
								}else if(mensagem.value.length == 0){
									alert('Enter message.');
									mensagem.focus();
								}else{
									ok = true;
								}
								break;
		case	3	:		if(nome.value.length == 0){
									alert('Enter name.');
									nome.focus();
								}else if(empresa.value.length == 0){
									alert('Enter company.');
									empresa.focus();
								}else if(email.value.length == 0){
									alert('Enter e-mail.');
									email.focus();
								}else if(validaEmail(email.value)){
									alert('Enter a valid e-mail.');
									email.focus();
								}else if(mensagem.value.length == 0){
									alert('Enter message.');
									mensagem.focus();
								}else{
									ok = true;
								}
								break;
	}
	
	if(ok){
		document.getElementById('queryString').value = '';
		startAjax('faleEnviar.asp?nome='+nome.value+'&empresa='+empresa.value+'&email='+email.value+'&destino='+destino.value+'&assunto='+assunto.value+'&mensagem='+strMensagem,8);
	}
}

function geraFrmFale(){
	startAjax('faleFrm.asp',7);
}

function geraFrmFaleEnviar(){
	if(xmlhttp.readyState == 4){
		startAjax('faleFrm.asp?enviar=ok',7);
	}
}

function montaFrmFale(){
	if(xmlhttp.readyState == 4){
		document.getElementById('frmFale').innerHTML = xmlhttp.responseText;
	}
}

function alterarPaisDetalhe(){
	if(xmlhttp.readyState == 4){
		document.getElementById('paisDetalhe').innerHTML = xmlhttp.responseText;
		startAjax('paisesProdutos.asp?'+document.getElementById('queryString').value,11);
	}
}

function geraPaisDetalhe(idPais){
	document.getElementById('queryString').value = 'idPais='+idPais;
	startAjax('paisesDetalhes.asp?idPais='+idPais,6);
}

function alterarPaisProduto(){
	if(xmlhttp.readyState == 4){
		document.getElementById('paisProdutos').innerHTML = xmlhttp.responseText;
	}
}
