TOTAL_PAGE = false;
PAGE_ATUAL = 1;
ADDRESS = false;
function changePage(changePageId){
	var $id = changePageId;
	if($id!=PAGE_ATUAL){
		var $obj = $$('page_'+PAGE_ATUAL);
		$obj.style.display = 'none';
		var $show = $$('page_'+$id);
		$show.style.display = 'block';
		PAGE_ATUAL = $id;
		if(ADDRESS==false){
			ADDRESS = window.location+'#';
		}
		ADDRESS = ADDRESS.substr(0,ADDRESS.indexOf('#')+1);
		self.location = ADDRESS+$id;
	}
	showPagination('paginationUp');
	showPagination('paginationDown');
}
function nextPage(){
	if(PAGE_ATUAL<TOTAL_PAGE){
		changePage(PAGE_ATUAL+1);
	}
}
function previowsPage(){
	if(PAGE_ATUAL>1){
		changePage(PAGE_ATUAL-1);
	}
}
function showPage(){
	var $link = window.location+'';
	var $indexOf = $link.indexOf('#');
	if($indexOf!='-1'){
		var $page = $link.substr($indexOf+1);
		if($page!=''){
			PAGE_ATUAL = $page;
		}
	}
	var $obj = $$('page_'+PAGE_ATUAL);
	$obj.style.display = 'block';
	showPagination('paginationUp');
	showPagination('paginationDown');
}
function showPagination(showPaginationId){
	var $id = showPaginationId;
	var $ul = $$($id);
	var $li = $ul.getElementsByTagName('li');
	var $total = $li.length;
	for($i=0;$i<$total;$i++){
		$li[$i].style.display = 'none';
		$li[$i].style.fontWeight = 'normal';
	}
	PAGE_ATUAL*=1;
	var $min = PAGE_ATUAL-2;
	if($min<1){
		$min = 1;
		$max = 5;
	}
	$max = $min+4;
	if($max>$total){
		$min-= $max-$total;
		$max = $total;
	}
	if($min<1){
		$min = 1;
	}
	$li[PAGE_ATUAL-1].style.fontWeight = 'bold';
	for($i=$min;$i<=$max;$i++){
		$li[$i-1].style.display = 'block';
	}
}
function changePhoto(changePhotoId,changePhotoURL){
	var $obj = $$(changePhotoId);
	var $url = changePhotoURL;
	$obj.src = $url;
}
function pesquisarProduto(pesquisarProdutoForm){
	var $form = pesquisarProdutoForm;
	var $pesquisar = $form.pesquisar;
	var $param = $form.param;
	if($pesquisar.value!=''){
		$param.value = 'pesquisar='+$pesquisar.value;
		return true;
	}else{
		$pesquisar.focus();
		return false;
	}
}
function faleConosco(faleConoscoForm){
	var $form = faleConoscoForm;
	var $nomeFC = $form.nomeFC;
	var $emailFC = $form.emailFC;
	var $assuntoFC = $form.assuntoFC;
	var $mensagemFC = $form.mensagemFC;
	var $validation = new Validation();
	
	if($nomeFC.value==''){
		$nomeFC.focus();
		vxmAlert('Preencha o campo Nome corretamente.');
		return false;
	}
	if($validation.checkEmail($emailFC.value)===false){
		$emailFC.focus();
		vxmAlert('Preencha o campo Email corretamente.');
		return false;
	}
	if($assuntoFC.value==''){
		$assuntoFC.focus();
		vxmAlert('Preencha o campo Assunto corretamente.');
		return false;
	}
	if($mensagemFC.value==''){
		vxmAlert('Preencha o campo Mensagem corretamente.');
		return false;
	}
	
	disableButton($form);
	return true;
}
function newsletter(newsletterForm){
	var $form = newsletterForm;
	var $nomeContato = $form.nomeContato;
	var $emailContato = $form.emailContato;
	var $validation = new Validation();
	
	if($nomeContato.value==''||$nomeContato.value=='NOME'){
		$nomeContato.focus();
		vxmAlert('Preencha o campo Nome corretamente.');
		return false;
	}
	if($validation.checkEmail($emailContato.value)===false){
		$emailContato.focus();
		vxmAlert('Preencha o campo Email corretamente.');
		return false;
	}
	
	disableButton($form);
	return true;
}
function cadastro(cadastroForm){
	var $form = cadastroForm;
	var $nomeCadastro = $form.nomeCadastro;
	var $nascimentoCadastro = $form.nascimentoCadastro;
	var $sexoCadastro = $form.sexoCadastro;
	var $emailCadastro = $form.emailCadastro;
	var $enderecoRuaCadastro = $form.enderecoRuaCadastro;
	var $enderecoNumeroCadastro = $form.enderecoNumeroCadastro;
	var $enderecoComplementoCadastro = $form.enderecoComplementoCadastro;
	var $bairroCadastro = $form.bairroCadastro;
	var $cepCadastro = $form.cepCadastro;
	var $codEstado = $form.codEstado;
	var $codCidade = $form.codCidade;
	var $dddTelefoneCadastro = $form.dddTelefoneCadastro;
	var $telefoneCadastro = $form.telefoneCadastro;
	var $dddCelularCadastro = $form.dddCelularCadastro;
	var $celularCadastro = $form.celularCadastro;
	var $emailCadastro = $form.emailCadastro;
	var $validation = new Validation();
	
	if($nomeCadastro.value==''){
		$nomeCadastro.focus();
		vxmAlert('Preencha o campo Nome corretamente.');
		return false;
	}
	if($validation.checkDate($nascimentoCadastro.value)===false){
		$nascimentoCadastro.focus();
		vxmAlert('Preencha o campo Nascimento corretamente.');
		return false;
	}
	if($sexoCadastro.value==''||$sexoCadastro.value=='-1'){
		$sexoCadastro.focus();
		vxmAlert('Selecione um Sexo.');
		return false;
	}
	if($validation.checkEmail($emailCadastro.value)===false){
		$emailCadastro.focus();
		vxmAlert('Preencha o campo Email corretamente.');
		return false;
	}
	if($enderecoRuaCadastro.value==''){
		$enderecoRuaCadastro.focus();
		vxmAlert('Preencha o campo Endereço corretamente.');
		return false;
	}
	if($validation.checkInt($enderecoNumeroCadastro.value)===false){
		$enderecoNumeroCadastro.focus();
		vxmAlert('Preencha o campo Número (nº) corretamente.');
		return false;
	}
	if($bairroCadastro.value==''){
		$bairroCadastro.focus();
		vxmAlert('Preencha o campo Bairro corretamente.');
		return false;
	}
	if($validation.checkCEP($cepCadastro.value)===false){
		$cepCadastro.focus();
		vxmAlert('Preencha o campo CEP corretamente.');
		return false;
	}
	if($codEstado.value==''||$codEstado.value=='-1'){
		$codEstado.focus();
		vxmAlert('Selecione um estado.');
		return false;
	}
	if($codCidade.value==''||$codCidade.value=='-1'){
		$codCidade.focus();
		vxmAlert('Selecione uma cidade.');
		return false;
	}
	if($validation.checkDDD($dddTelefoneContrato.value)===false){
		$dddTelefoneContrato.focus();
		vxmAlert('Preencha o campo DDD Telefone corretamente.');
		return false;
	}
	if($validation.checkPhoneNumber($telefoneContrato.value)===false){
		$telefoneContrato.focus();
		vxmAlert('Preencha o campo Telefone corretamente.');
		return false;
	}
	
	var $q = window.confirm('Deseja realmente CADASTRAR este registro?');
	if($q===true){
		disableButton($form);
		return true;
	}else{
		return false;
	}
}
