
/*#ONLOAD#*/
window.name = 'pf_browser';


/*# VALIDA E-MAIL [expressão regular] */
function verficaEmail(campo) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(campo)) {
		return	'';
	}
	return '- O E-MAIL digitado é inválido.\n';
}

/*# aceita só números digitados num campo */
function soNumero(evtKeyPress) {
	var nTecla;
	nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
	
	if((nTecla > 47 && nTecla < 58) || nTecla == 8 || nTecla == 9)
		return true;
	else
		return false;
}

/*# MASCARA */
function mascarar(vc_campo,vc_mascara) {
	var i		= vc_campo.value.length;
	var x		= vc_mascara.substring(0,1);
	var y		= vc_mascara.substring(i);
	
	if (y.substring(0,1) != x) {
		vc_campo.value += y.substring(0,1);
	}
}

/*# VERIFICA DATA #*/
function verificaData(vc_campo) { 
	if (vc_campo.value.length > 0) {  
		it_dia		= (vc_campo.value.substring(0,2)); 
		it_mes		= (vc_campo.value.substring(3,5)); 
		it_ano		= (vc_campo.value.substring(6,10)); 
		it_erro		= 0; 
		
		if ((it_dia < 1) || (it_dia < 1 || it_dia > 30) && (it_mes == 4 || it_mes == 6 || it_mes == 9 || it_mes == 11 ) || it_dia > 31) { 
			it_erro	= 1; 
		} 

		if (it_mes < 1 || it_mes > 12 ) { 
			it_erro	= 1; 
		} 

		if (it_mes == 2 && (it_dia < 1 || it_dia > 29 || (it_dia > 28 && (parseInt(it_ano / 4) != it_ano / 4)))) { 
			it_erro	= 1; 
		} 

		if ((it_ano < 1900) || (it_ano > 2078)){
			it_erro	= 1;
		}
		
		if (it_erro == 1) { 
			alert("Por favor, preencha uma data válida!"); 
			vc_campo.value	= '';
			vc_campo.focus(); 
		}
	} 
}


/*# iFrame virtual [ crossBrowser ] #*/
function iframeVirtual(vc_url) {
	// pega iframeVirtual pelo ID ou cria um iframeVirtual caso ñ exista
	var tempIFrame = (document.getElementById('iframe_virtual')) ? document.getElementById('iframe_virtual') : document.createElement('iframe');
	
	tempIFrame.style.border		= '0px';
	tempIFrame.style.width		= '0px';
	tempIFrame.style.height		= '0px';
	
	tempIFrame.setAttribute('id','iframe_virtual');
	tempIFrame.setAttribute('name','iframe_virtual');
	tempIFrame.setAttribute('src',vc_url);
	
	IFrameObj		= document.body.appendChild(tempIFrame);
}


/*# TRIM - Função que verifica se há espaços no início e fim de uma string, semelhante ao trim #*/
function trim(vc_string) {
 
  //Remove os espaços do Inicio
  while ((vc_string.substring(0,1) == ' ') || (vc_string.substring(0,1) == '\n') || (vc_string.substring(0,1) == '\r')) {
    vc_string = vc_string.substring(1,vc_string.length);
  }
 
  //Remove os espaços do Final
  while ((vc_string.substring(vc_string.length-1,vc_string.length) == ' ') || (vc_string.substring(vc_string.length-1,vc_string.length) == '\n') || (vc_string.substring(vc_string.length-1,vc_string.length) == '\r')) {
    vc_string = vc_string.substring(0,vc_string.length-1);
  }
 
 return vc_string;
}

/*# CONTA CARACTER #*/
function contaCaracter(campoVC,caracterN,limiteN) {
	if (campoVC.value.length > limiteN) {
		campoVC.value		= campoVC.value.substring(0,limiteN);
	} else {
		caracterN.value	= limiteN - campoVC.value.length;
	}
}

/*# GET RADIO VALUE  #*/
function get_radio_value (radio_array){
	var i;
	for (i = 0; i < radio_array.length; ++ i)
		if (radio_array [i].checked)
		return radio_array [i].value;
	return null;
}


/*# REPLACE GERAL - Função replace que substitui todos e não só um como a padrão #*/
function replaceGeral(vc_texto, vc_str_1, vc_str_2){
/*----------------------------------------------------  
	vc_texto 	= String onde será procurado o valor
   	vc_str_1 	= Valor que deve ser substituido.
   	vc_str_2 	= Valor por qual deve ser substituido  
------------------------------------------------------*/
	while (vc_texto.indexOf(vc_str_1) > 0){
  	vc_texto = vc_texto.replace(vc_str_1,vc_str_2);
 	}
 
 	return vc_texto;
}




/***********************************************************************
*		N E W S L E T T E R 
***********************************************************************/

/*# VERIFICAR #*/
function newsletterVerificar() {
	vc_erro		= '';
	
	if (trim(document.getElementById("newsletterFRM").contatoVC.value).length == 0){
		vc_erro	= vc_erro + 'Digite o NOME.\n';		
	}
	
	if (trim(document.getElementById("newsletterFRM").emailVC.value).length == 0) {
		vc_erro	= vc_erro + 'Digite o E-MAIL.\n';		
	} else {
		vc_erro	= vc_erro + verficaEmail(document.getElementById("newsletterFRM").emailVC.value);
	}
	
	if (vc_erro.length == 0) {
		document.getElementById("newsletterFRM").submit();
	} else {
		alert('ATENÇÃO!\n\nPara receber nossas ofertas, você deve preencher seus dados corretamente');
		return false;
	}
}



/*# ALTURA MENU - Ajusta a altura do menu de Categorias de acordo com o tamanho da pag. #*/
function alturaCategorias(){
	document.getElementById('tamanho_menu').style.height   =  document.getElementById('dv_corpo').clientHeight - 130;
}


/***********************************************************************
*		B A N N E R S 
***********************************************************************/

/*# BANNER #*/
function bannerCount(bannerID) {
	codigo.location.href	= './codigos/banner.asp?bannerID='+bannerID;
}

/***********************************************************************
*		C A R R I N H O
***********************************************************************/
/*#FINALIZAR#*/
function carrinhoFinalizar() {
	location.href			= './?actA=12';
}


/*funcao que adiciona a ordem na query string*/
function mudaOrdem(ordenacaoID){
	codigo.location.href	= '/temp/ordenacao.asp?ordenacaoID=' + ordenacaoID;
}