
$(document).ready(function () {
							
	var alt = $('#center-in').height()
	
	if (alt  < 720)
		$('#center-in').css('height','720px');
});
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//função redimensiona

function getPageScroll()
{

	var yScroll;
	
	if (self.pageYOffset) 
	{
		yScroll = self.pageYOffset;
	} 
	else if(document.documentElement && document.documentElement.scrollTop)
	{ // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} 
	else if (document.body) 
	{// all other Explorers
		yScroll = document.body.scrollTop;
	}
	
	arrayPageScroll = new Array('',yScroll)
	
	return arrayPageScroll;
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}




function zoomImage(image) {
	
	$.blockUI();
	
	$("#zoomImage").remove();
	
	var Window = "<div id=\"zoomImage\" width=\"400\" style=\"z-index:2000\"><img src=\"_imagens/" + image + "\" name=\"zoomFoto\" id=\"zoomFoto\"  /></div>";
	
	$(Window).insertBefore("#container");
	
	var page = getPageSize();
	
	$('.blockUI').height(page[1]);
	
	var w = ((page[0] - 480) / 2) + 'px';
	
	$("#zoomImage").css('left',w);
	
	
	var btnCloseWindow = "<div id=\"btnCloseWindow\"><img src=\"images/btnCloseZoomImage.jpg\" name=\"btnCloseZoomImage\" id=\"btnCloseZoomImage\" /></div>";
	
	$(btnCloseWindow).insertAfter("#zoomFoto");
	
	$('#btnCloseWindow').click( function() {
		
		$("#zoomImage").remove();
		
		$.unblockUI();
									
	});
	
	$("#zoomFoto,#btnCloseWindow").mouseover( function() {
		$('#btnCloseWindow').fadeIn('slow');
	})
	$("#zoomFoto").mouseout( function() {
		$('#btnCloseWindow').fadeOut('slow');
	});;

}


function fechaDiv(div)
{
	$('#'+div).toggle('slider');
	$.unblockUI();
}

function fechaDiv2(div)
{
	$('#'+div).hide('slider');
	$.unblockUI();
}

//verifica se é numero
function verificaNumero(obj)
{
	//verifica se não é numero
	if (isNaN(obj.value))
	{
		alert('Você deve digitar um número!');
		obj.value = "";
	}	
}


var Carrinho = {
	
		'AddProduto': function(id_produto)
		{
			var qtd = $('#qtdProduto_'+id_produto).val();
			
			//verifica se não é numero
			if (isNaN(qtd))
				qtd = 1;
			
			$.unblockUI();
			
			if(id_produto)
			{
				$('#divCarrinho').load('load-carrinho.php?QTD='+qtd+'&ID='+id_produto+'&CMD=adicionar');
			}
			else
				$('#divCarrinho').load('load-carrinho.php');
				
			jQuery.blockUI({message: null, overlayCSS: { backgroundColor: '#6397BE' } });

		},
		
		
		'AddProduto2': function(id_produto,IDG,IDSG,IDC,IDSC)
		{
			var qtd = $('#qtdProduto_'+id_produto).val();
			
			//verifica se não é numero
			if (isNaN(qtd))
				qtd = 1;
			
			$.unblockUI();
			
			if(id_produto)
			{
				$('#divCarrinho').load('load-carrinho.php?QTD='+qtd+'&ID='+id_produto+'&IDG='+IDG+'&IDSG='+IDSG+'&IDC='+IDC+'&IDSC='+IDSC+'&CMD=adicionar');
			}
			else
				$('#divCarrinho').load('load-carrinho.php');
				
			jQuery.blockUI({message: null, overlayCSS: { backgroundColor: '#6397BE' } });

		},
		
		
		'Atualiza':function(id_produto,qtd)
		{
			//verifica se não é numero
			if (isNaN(qtd))
				qtd = 1;

			$('#qtdProduto_'+id_produto).val(qtd);
						
			$.ajax({
				type: "GET",
				url: "load-carrinho.php",
				data: "CMD=adicionar&ID="+id_produto+"&QTD="+qtd
			});
			
		},


		'RemoveProduto':function(id_produto)
		{
		
			$.ajax({
				type: "GET",
				url: "load-carrinho.php",
				data: "CMD=excluir&ID="+id_produto
			});
			
			$('#tr' + id_produto).remove();
			$('#linha' + id_produto).remove();
			
		},
	
		'Valida': function()
		{
		
			if ( $('#nome').val() == "")
			{
				alert('Você precisa digitar o seu nome! ');
				$('#nome').focus();
				return false;
			}
			
			if($('email').val() == "" || document.getElementById('email').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
			{
				alert('Você precisa digitar um endereço de e-mail válido! ')
				$('#email').focus();
				return false;
			}
			
			if ( $('#telefone').val() == "")
			{
				alert('Você precisa digitar o seu telefone! ');
				$('#telefone').focus();
				return false;
			}
				
			if ( $('#mensagem').val() == "")
			{
				alert('Você precisa digitar a sua mensagem ! ');
				$('#mensagem').focus();
				return false;
			}
		}
}


function Pesquisa()
{
	if ( $('#pesquisa').val() == "")
	{
		alert('Você precisa digitar uma palavra chave para pesquisar!');
		$('#pesquisa').focus();
		return false;
	}
}


//----------------------------------------------------------------------------------//
// Contato
//-----------------------------------------------------------------------------------//

//valida contato
var Contato = {
	
	'Valida': function()
	{
		
		if ( $('#nome').val() == "")
		{
			alert('Você precisa digitar o seu nome!');
			$('#nome').focus();
			return false;
		}
		
		if($('email').val() == "" || document.getElementById('email').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) 
		{
			alert('Você precisa digitar um endereço de e-mail válido!')
			$('#email').focus();
			return false;
		}
		
		if ( $('#fone').val() == "")
		{
			alert('Você precisa digitar o seu telefone!');
			$('#fone').focus();
			return false;
		}
		
		if ( $('#assunto').val() == "")
		{
			alert('Você precisa digitar o assunto!');
			$('#assunto').focus();
			return false;
		}

		if ( $('#mensagem').val() == "")
		{
			alert('Você precisa digitar a sua mensagem !');
			$('#mensagem').focus();
			return false;
		}
	}
}

//----------------------------------------------------------------------------------//
// Contato
//-----------------------------------------------------------------------------------//

//valida contato
var Indicacao = {
	
	'Valida': function()
	{
		
		if ( $('#nome').val() == "")
		{
			alert('Você precisa digitar o seu nome!');
			$('#nome').focus();
			return false;
		}
		
		if($('email').val() == "" || document.getElementById('email').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) 
		{
			alert('Você precisa digitar um endereço de e-mail válido!')
			$('#email').focus();
			return false;
		}
		
		if ( $('#nome_indicado').val() == "")
		{
			alert('Você precisa digitar o nome do seu amigo que recebará o e-mail!');
			$('#nome_indicado').focus();
			return false;
		}
		
		if($('email_indicado').val() == "" || document.getElementById('email_indicado').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) 
		{
			alert('Você precisa digitar um endereço de e-mail válido,\n para que seu amigo receba sua indicação!')
			$('#email_indicado').focus();
			return false;
		}

		if ( $('#mensagem').val() == "")
		{
			alert('Você precisa digitar a sua mensagem !');
			$('#mensagem').focus();
			return false;
		}
	}
}


/*
	
	'_open': function(div,W,H) 
	{
	
	$('#'+div).show('slider');
	$('#'+div).focus();
	//if (document.all)
	//var pos = evt.clientY;
	//else
	// var pos = window.pageYOffset;
	
	var pageSize = getPageSize();
	
	var objScroll = getPageScroll();
	
	//alert(objScroll[1]);
	
	var winW = pageSize[0];
	var winY = pageSize[1];
	
	//menos a largura da div
	var w = (winW - W) / 2;
	 //menos a altura da div
	var y = (winY - H) / 2;
	
	//alert(w);
	//alert(y);
		document.getElementById(div).style.left = w + 'px';
		//document.getElementById(div).style.top = y + 'px';
		y = 10 + objScroll[1];
		document.getElementById(div).style.top = y + 'px';
	
	}
	

}
*/

//CENTRALIZADA serve para previem de noticia, artigo, etc...
function openWin(url, name, w, h, s) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+s+',resizable=no';
//	winprop = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes';
	
	win = window.open(url, name, winprops)
	if(parseInt(navigator.appVersion) >= 4) {
		win.window.focus(); 
	}
}

//---------------------------------------------------------------------------------//
// COMMONS
//---------------------------------------------------------------------------------//

var Common = {
	
	// ID = id do que se quer escluir
	// URL = pagina que sera feita a exclusao
	//MSG = se quiser definir mensagem especial para exclusao
	'Delete': function(URL,MSG,VINCULO)
	{
		if (VINCULO > 0)
			alert('Impossivel apagar pois há '+VINCULO+' vinculo(s) de produto, apague os produtos primeiro! ');
		else
		{
			if (MSG == "" || MSG == null)
				MSG = "Tem certeza que deseja excluir ?";
				
		   if(confirm(MSG))
		   document.location = URL;
		}
	},
	
	//Função para formatar moeda R$
	'formataMoeda': function(campo,event)
	{
		//Pega o código da tecla
		function getKey(e)
		{
		if (e == null) 
		{ // ie
			keycode = event.keyCode;
		} 
		else 
		{ // mozilla
			keycode = e.which;
		}
		//key = fromCharCode(keycode).toLowerCase();
		
		return keycode;
		}
		
		
		
		//Bloqueia caracteres que não sejam números
		function teclas(campo,event)
		{
			if(((event.keyCode < 96) || (event.keyCode > 105)) && ((event.keyCode < 48) || (event.keyCode > 57)) )
			{
			   campo.value = campo.value.replace(String.fromCharCode(event.keyCode).toLowerCase(),"");
			}
		}

	   //para evitar caracteres alfas.
	   teclas(campo,event);
	   str = campo.value;
	
	   while(str.search(",") != -1)
		   str = str.replace(",","");
	   i = 0;
	
	   while(i< str.length){
		   if(str.substr(i,1) == ".")
			  str = str.replace(".","");
			  i++;
	   }
	
	   part1 = str.substr(0,str.length - 2);
	   while(part1.search(" ") != -1)
		   part1 = part1.replace(" ","");
	
		   part2 = str.substr(str.length - 2,2);
		   res = "";
		   i = part1.length;
		   sob = i % 3;
		   if((sob != 0) && (i > 2))
			  res = part1.substr(0,sob) + ".";
		   else
			  res = part1.substr(0,sob);
		   j = 1;
		   part1 = part1.substr(sob);
		   i = 0;
		   while(i < part1.length){
			  if(j == 3){
				 if(i + 1 == part1.length)
					res = res + part1.substr(i-2,3);
				 else res = res + part1.substr(i-2,3) + ".";
			  }
			  i++;
			  j = j<3?j+1:1;
		   }
		   campo.value = res + "," + part2;
	}

}