var $foo = jQuery.noConflict();

function volta(){
	loadXMLDoc('inc/'+pagAnt+'.php', 'contGeral', 'GET');
	holdPagAnt = pagAnt;
	pagAnt = pagAtual;
	pagAtual = holdPagAnt;
	holdPagAnt = "";
}

function simplePreload() {
	var args = simplePreload.arguments;
	document.imageArray = new Array(args.length);
	for(var i=0; i<args.length; i++){
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
}

function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function validaFrmLigaremos(form){
	$foo("#form_alert div").show();
	if(form.txtNome.value==""){
		$foo("#form_alert div").html("Por favor, preencha o campo NOME!");
		form.txtNome.focus();
		return false;
	}
	if(form.txtEmail.value==""){
		$foo("#form_alert div").html("Por favor, preencha o campo EMAIL!");
		form.txtEmail.focus();
		return false;
	}else{
		if(!validaEmail(form.txtEmail.value)){
			$foo("#form_alert div").html("Por favor, informe um EMAIL V&Aacute;LIDO!");
			form.txtEmail.focus();
			return false;
		}
	}	
	
	if(form.txtPais.value==""){
		$foo("#form_alert div").html("Por favor, selecione um PAÍS!");
		form.txtPais.focus();
		return false;
	}
	if(form.txtFone.value==""){
		$foo("#form_alert div").html("Por favor, preencha o campo TELEFONE!");
		form.txtFone.focus();
		return false;
	}
	$foo("#form_alert div").load('ctrlImplementa.php?'+$foo("#frmLigaremos").formSerialize());
}

function validaContato2(form){
	$foo("#form_alert div").show();
	if(form.txtNome.value==""){
		$foo("#form_alert div").html("Por favor, preencha o campo NOME!");
		form.txtNome.focus();
		return false;
	}
	if(form.txtEmail.value==""){
		$foo("#form_alert div").html( "Por favor, preencha o campo EMAIL!");
		form.txtEmail.focus();
		return false;
	}else{
		if(!validaEmail(form.txtEmail.value)){
			$foo("#form_alert div").html("Por favor, informe um EMAIL V&Aacute;LIDO!");
			form.txtEmail.focus();
			return false;
		}
	}	
	if(form.txtFone.value==""){
		$foo("#form_alert div").html("Por favor, preencha o campo TELEFONE!");
		form.txtFone.focus();
		return false;
	}
	if(form.txtMensagem.value==""){
		$foo("#form_alert div").html("Por favor, preencha o campo MENSAGEM!");
		form.txtMensagem.focus();
		return false;
	}
	$foo("#form_alert div").load('ctrlImplementa.php?'+$foo("#contato2").formSerialize());
}


function abreHighslide(url, largura, altura, tipo){
	var link = document.createElement("a");
	link.setAttribute("href",url);
	
	if(!tipo){
		tipo = 'ajax';
	}

	hs.htmlExpand(link, {objectType:tipo, width:largura, height:altura, dimmingOpacity: 0.5, outlineType: 'glossy-dark', useControls: false, wrapperClassName: 'draggable-header no-footer'});
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0){
		offset = document.cookie.indexOf(search)
		if (offset != -1){
			offset += search.length
			end = document.cookie.indexOf(";", offset)
			if (end == -1)
			end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

function expira(){
	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime() + 1000*60*60*24*365);
	return expires;
}

function checaCookie(name,nomim) {
	if (getCookie(name)=='on'){
		Elemento = document.getElementById(nomim);
		Elemento.style.display="block";
	}
}

function onlyNumbers(){
	if (event.keyCode < 48 || event.keyCode > 57)
	event.returnValue = false;
}

function validaTelefone(elemId) {
	if (event.keyCode < 48 || event.keyCode > 57) {
		event.returnValue = false;
	}
	var nkey = event.keyCode;
	d = document.getElementById(elemId);
	if (nkey != 8) {
		if (d.value.length == 4) {
			d.value += "-";
		}
		else if (d.value.length == 9){
			return false;
		}
	}

}
function montaFlash(destino, flavez, width, height, trans, scale, salign){
	var myFlash =
	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+flavez+'" align="middle">'+
	'<param name="allowScriptAccess" value="sameDomain" />'+
	'<param name="movie" value="'+flavez+'.swf" />'
	;
	if (trans == "yes"){
		myFlash += '<param name="wmode" value="transparent" />';
		transMoz = 'wmode="transparent"';
	}
	if (salign != ""){
		myFlash += '<param name="salign" value="'+salign+'" />';
		salignMoz = 'salign="'+salign+'"';
	}
	if (scale == "yes"){
		myFlash += '<param name="scale" value="noscale" />';
		scaleMoz = 'scale="noscale"';
	}
	myFlash +=
	'<param name="quality" value="high" />'+
	'<param name="bgcolor" value="#ffffff" />'+
	'<embed src="'+flavez+'.swf" '+scaleMoz+' quality="high" '+transMoz+' bgcolor="#ffffff" '+salignMoz+' width="'+width+'" height="'+height+'" name="empresas" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
	'</object>'
	;
	document.getElementById(destino).innerHTML = myFlash;
}
function montaFlashParams(width, height, arquivo, params, destino){

	var parametro = false;
	
	if(params != null || params != "" || params != "none"){
		parametro = true;
	}
	
	var myFlash =
	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+arquivo+'" align="middle">'+
	'<param name="allowScriptAccess" value="sameDomain" />'+
	'<param name="movie" value="swf/'+arquivo+'.swf';if(parametro){ myFlash += '?'+params;} myFlash += '" />'+
	'<param name="wmode" value="transparent" />'+
	'<param name="scale" value="scale" />'+
	'<param name="quality" value="high" />'+
	'<param name="bgcolor" value="#ffffff" />'+
	'<embed src="swf/'+arquivo+'.swf'; if(parametro){ myFlash += '?'+params;} myFlash += '" wmode="transparent" quality="high" width="'+width+'" height="'+height+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
	'</object>'
	;
	document.getElementById(destino).innerHTML = myFlash;
}


function validaEmail(objMail){
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(objMail)))
	{
		email = false;
	}
	else{
		email = true;
	}
	return email;
}

function validaMail(objMail){
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(objMail)))
	{
		email = false;
	}
	else{
		email = true;
	}
	return email;
}

function MostraLinks(div){
	if(document.getElementById(div).style.display == ''){
		document.getElementById(div).style.display = 'none';
	} else {
		document.getElementById(div).style.display = '';
	}
}

//script das pagina cateEsq.php e subCateEsq.php que carrega as subcategorias de uma categoria
function loadSubCate(idMae,numSubCate){
	if(numSubCate>0){
		div = document.getElementById(idMae);

		if(div.style.display=="none"){
			div.style.display = "";
		}else{
			div.style.display = "none";
		}

		consultaAjaxText("internas/subCateEsq.php","idMae="+idMae,"post",idMae,"");
	}
	consultaAjaxText("ctrlImplementa.php","acao=exibe&idCate="+idMae,"post","mostraConteudo","");
}

//script que soma ou subtrai a qted de um input
function manipulaQtde(acao,qtde){
	if(acao=="+"){
		qtde.value++;
	}else if(acao=="-"){
		//se a qtnde de produto for 1
		if(qtde.value==1){
			alert("Essa já é a quantidade mínima!");
			return false;
		}
		qtde.value--;
	}
}


//adiciona um produto no carrinho
function addCarrinho(produCod,produNome,produValor,produQtde,cor,medida){
	parametros = "acao=addCarrinho&produCod="+produCod+"&produNome="+produNome+"&produValor="+produValor+"&produQtde="+produQtde+"&cor="+cor+"&medida="+medida;

	consultaAjaxText("ctrlImplementa.php", parametros, "post", "carrinhoDetalhes", "carregando carrinho");
}

//muda o tipo de exibição da loja "exibe.php"
function mudaExibe(modo){
	if(document.getElementById("qtdeProdu")){
		var qtdeProdu = document.getElementById("qtdeProdu").value;

		if(qtdeProdu>0){
			if(modo=="lista"){
				for(i=0;i<qtdeProdu;i++){
					document.getElementById("exibeLista"+i).style.display = "block";
					document.getElementById("exibeFoto"+i).style.display = "none";
				}
			}else if(modo=="foto"){
				for(i=0;i<qtdeProdu;i++){
					document.getElementById("exibeLista"+i).style.display = "none";
					document.getElementById("exibeFoto"+i).style.display = "block";
				}
			}
		}

		//chamando a pagina que grava em seção
		consultaAjaxText("ctrlImplementa.php", "acao=alteraExibe&modo_exibe="+modo, "post", "setaSecoes", "carregando carrinho");
	}else{
		alert("Voce precisa estar em uma listagem de produtos para pode mudar a forma de exibicao!");
		if(modo=="lista"){
			document.getElementById("modoExibeLista").checked = false;
			document.getElementById("modoExibeFotos").checked = true;
		}else{
			document.getElementById("modoExibeLista").checked = true;
			document.getElementById("modoExibeFotos").checked = false;
		}
	}
}

/* lista carrinho.php */
//atualiza o carrinho de compras
function atualizaCarrinho(){
	//atualizando o carrinho
	consultaAjaxText('ctrlImplementa.php', 'acao=atualizaCarrinho', 'post', 'carrinhoDetalhes', 'carregando carrinho...');
}

//remove um item do carrinho de comprar
function removeProdu(codProdu){
	//removendo item
	consultaAjaxText('ctrlImplementa.php', 'acao=removeProdu&codProdu='+codProdu, 'post', 'mostraConteudo', '');

	//atualizando o carrinho
	setTimeout('atualizaCarrinho()',200);
}

function manipulaQtdeLista(acao,qtde,codProdu){
	//alterando a qtde no input
	if(acao=="+"){
		++qtde.value;
	}else if(acao=="-"){
		//se a qtnde de produto for 1
		if(qtde.value==1){
			alert("Essa já é a quantidade mínima!");
			return false;
		}
		--qtde.value;
	}

	//alterando a qtde na seção
	consultaAjaxText('ctrlImplementa.php', 'acao=alterarItemLista&codProdu='+codProdu.value+'&qtde='+qtde.value, 'post', 'mostraConteudo', '');

	//atualizando o carrinho
	setTimeout('atualizaCarrinho()',200);
}

//frmEnviaOrc.php
function enviaOrc(nome,telefone,email,observacao){
	var erros = "";
	if(nome==""){
		erros += "Preencha o campo nome!\n";
	}
	if(telefone==""){
		erros += "Preencha o campo telefone!\n";
	}
	if(email==""){
		erros += "Preencha o campo e-mail!\n";
	}else{
		if(!validaMail(email)){
			erros += "E-mail invalido!\n";
		}
	}
	if(observacao==""){
		erros += "Preencha o campo observacao!";
	}
	if(erros!=""){
		alert("Você não pode continuar. Atenção para os erros:\n\n"+erros);
		return false;
	}else{
		consultaAjaxText('ctrlImplementa.php', 'acao=finalizaOrc&nome='+nome+'&telefone='+telefone+'&email='+email+'&observacao='+observacao, 'post', 'mostraConteudo', '');
		return true;
	}
}

function popUp(url, width, height, rola)	{
	if (rola==""){rola="yes"}
	window.open(url,"_blank","resizable=no,toolbar=no,status=no,top=" + (window.screen.height - height)/2 + ",left=" + (window.screen.width - width)/2 + ",menubar=no,scrollbars=" + rola + ",width=" + width + ",height=" + height);
}

function cadNews(email){
	if(email=="Digite aqui seu email"){
		alert("Informe seu e-mail");
		return false;
	}else{
		if(!validaEmail(email)){
			alert("E-mail invalido!");
			return false;
		}else{
			consultaAjaxText("../../ctrlImplementa.php", "acao=addNews&loja=true&email="+email, "post", "abreGaleria", "");
			//$foo('#abreGaleria').load("ctrlImplementa.php?acao=addNews&email="+email);
			//alert("E-mail cadastrado com sucesso!");
		}
	}
}

/* var $foo = jQuery.noConflict(); 


function redimensionaInternas() {
	var ie = /msie/i.test(navigator.userAgent);
	var ieBox = ie && (document.compatMode == null || document.compatMode == "BackCompat");

	var w, h; // Contem o width e o height da janela
	var canvasEl = ieBox ? document.body : document.documentElement;
	w = window.innerWidth || canvasEl.clientWidth;
	h = window.innerHeight || canvasEl.clientHeight;
	rh = document.getElementById('rodape').innerHeight || document.getElementById('rodape').clientHeight;
	if(parseInt(h-305-350-20)>rh){
		//document.getElementById('internas').setAttribute('style','min-height:'+parseInt(h-223-165)+'px;height: auto !important;');
		//document.getElementById('internas').style.height = parseInt(h-223-165)+'px';
		$foo('#rodape').css({minHeight:parseInt(h-305-350-20)+'px', height:'auto !important', height:parseInt(h-305-350-20)+'px'});
	}
}
*/
