// JavaScript Document
function PopUp(url, nome, largura, altura, sroll)
{
	var esq = (screen.width - largura) / 2;
	var top = (screen.height - altura) / 2;
	var jan = window.open(''+ url +'',''+ nome +'','width=' + largura + ',height=' + altura + ',top=' + top + ',left=' + esq + ',scrollbars='+ sroll +'');
	jan.focus();
}

function altLabel(msg)
{
	document.getElementById('labelLinguagem').innerHTML = msg;
}

function setCookie(cookie_name, cookie_value, expire_in_days)
{
	var cookie_expire = "";
	if (expire_in_days != null)
	{
		var expire = new Date();
		expire.setTime(expire.getTime() + 1000*60*60*24*parseInt(expire_in_days));
		cookie_expire = "; expires=" + expire.toGMTString();
	}

	document.cookie = escape(cookie_name) + "=" + escape(cookie_value) + cookie_expire;
}

function getCookie(cookie_name)
{
	if (!document.cookie.match(eval("/" + escape(cookie_name) + "=/")))
	{
		return false;
	}
	return unescape(document.cookie.replace(eval("/^.*?" + escape(cookie_name) + "=([^\\s;]*).*$/"), "$1"));
}

function altIdioma(valor)
{
	setCookie('idioma', valor, 100);
	window.location.href = window.location.href;
}
//######################################################################################
//    validar email
//######################################################################################
function validaEmail(email)
{
	var exp = /^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$/;
	if (!exp.test(email))
	{
		return false;
	}
	else
	{
		return true;
	}
}

//######################################################################################
//    validar cadastro newsletter
//######################################################################################
function validarCadastroNews(f)
{
	if (f.nomenews.value == '')
	{
		window.alert(VldNewsALERTcmpnome);
		f.nomenews.className = "textreq";
        f.nomenews.focus();
		return false;
	}
	if (f.emailnews.value.length==0){
        window.alert(VldNewsALERTcmpemail);
		f.emailnews.className = "textreq";
        f.emailnews.focus();
		return false;
	}
    if (!validaEmail(f.emailnews.value)){
       window.alert(VldNewsALERTcmpemailinc);
	   f.emailnews.className = "textreq";
       f.emailnews.focus();
		return false;
	}
}
//######################################################################################
//    validar fale conosco
//######################################################################################
function validarContato(f)
{
	if (f.nomecontato.value == '')
	{
		window.alert(VldFaleConALERTcmpnome);
		f.nomecontato.className = "textreq";
        f.nomecontato.focus();
		return false;
	}
	if (f.emailcontato.value == '')
	{
		window.alert(VldFaleConALERTcmpemail);
		f.emailcontato.className = "textreq";
        f.emailcontato.focus();
		return false;
	}
	if (!validaEmail(f.emailcontato.value)){
       window.alert(VldFaleConALERTcmpemailinc);
	   f.emailcontato.className = "textreq";
       f.emailcontato.focus();
		return false;
	}
	if (f.cidadecontato.value == '')
	{
		window.alert(VldFaleConALERTcmpcidade);
		f.cidadecontato.className = "textreq";
        f.cidadecontato.focus();
		return false;
	}
	if (f.estadocontato.value == '')
	{
		window.alert(VldFaleConALERTcmpestado);
		f.estadocontato.className = "textreq";
        f.estadocontato.focus();
		return false;
	}
	if (f.empresacontato.value == '')
	{
		window.alert(VldFaleConALERTcmpempresa);
		f.empresacontato.className = "textreq";
        f.empresacontato.focus();
		return false;
	}
	if (f.telefonecontato.value == '')
	{
		window.alert(VldFaleConALERTcmptelefone);
		f.telefonecontato.className = "textreq";
        f.telefonecontato.focus();
		return false;
	}
	if (f.assuntocontato.value == '')
	{
		window.alert(VldFaleConALERTcmpassunto);
		f.assuntocontato.className = "textreq";
        f.assuntocontato.focus();
		return false;
	}
	if (f.mensagemcontato.value == '')
	{
		window.alert(VldFaleConALERTcmpcomentario);
		f.mensagemcontato.className = "textreq";
        f.mensagemcontato.focus();
		return false;
	}
}
//######################################################################################
//    validar adicionar
//######################################################################################
function validarProduto(f) {

    if (f.qtde.value == '') {
	   window.alert(VldlojaALERTcmpqtdeinicial);
	   f.qtde.className = "textreq";
       f.qtde.focus();
		return false;
	}
}