function FormataCPF( el ) 
{ 
	vr = el.value; 
	tam = vr.length; 

	if ( vr.indexOf(".") == -1 ) 
	{ 
		if ( tam <= 3 ) 
			el.value = vr; 

		if ( (tam > 3) && (tam <= 7) ) 
			el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 4, tam ); 

		if ( (tam >= 8) && (tam <= 11) ) 
			el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 5, 3 ) + '-'; 

		if ( (tam >= 11) && (tam <= 18) ) 
			el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 2 ); 
	}

	return true; 

} 

function FormataCNPJ( el ) 
{ 
         vr = el.value; 
         tam = vr.length; 


      if ( vr.indexOf(".") == -1 ) 
      { 
      if ( tam <= 2 ) 
              el.value = vr; 
      if ( (tam > 2) && (tam <= 6) ) 
              el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam ); 
      if ( (tam >= 7) && (tam <= 10) ) 
              el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' 
+ vr.substr( 5, 3 ) + '/'; 
      if ( (tam >= 11) && (tam <= 18) ) 
             el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + 
vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ; 
      } 
      return true; 
} 

function isNum1( caractere ) 
{ 
         var strValidos = "0123456789" 
         if ( strValidos.indexOf( caractere ) == -1 ) 
                 return false; 
         return true; 
} 
function validaInteiro(campo, event) 
{ 
         var BACKSPACE=  8; 
         var key; 
         var tecla; 

         CheckTAB=true; 
         if(navigator.appName.indexOf("Netscape")!= -1) 
                 tecla= event.which; 
         else 
                 tecla= event.keyCode; 


         key = String.fromCharCode( tecla); 
         //alert( 'key: ' + tecla + '  -> campo: ' + campo.value); 

         if ( tecla == 13 ) 
                 return false; 
         if ( tecla == BACKSPACE ) 
                 return true; 
         return ( isNum1(key)); 
}

function isNum2( caractere ) 
{ 
         var strValidos = ".0123456789" 
         if ( strValidos.indexOf( caractere ) == -1 ) 
                 return false; 
         return true; 
} 
function validaDecimal(campo, event) 
{ 
         var BACKSPACE=  8; 
         var key; 
         var tecla; 

         CheckTAB=true; 
         if(navigator.appName.indexOf("Netscape")!= -1) 
                 tecla= event.which; 
         else 
                 tecla= event.keyCode; 

         key = String.fromCharCode( tecla); 
         //alert( 'key: ' + tecla + '  -> campo: ' + campo.value); 

         if ( tecla == 13 ) 
                 return false; 
         if ( tecla == BACKSPACE ) 
                 return true; 
         return ( isNum2(key)); 
}

function SaltaCampo (campo, prox, tammax, teclapres)
{
	var tecla = teclapres.keyCode;
	vr = campo.value;
	tam = vr.length;
	
	if (tecla != 0 && tecla != 10 && tecla != 24 && tecla != 16 && tecla != 9 && tecla != 46)
	{
		if (tam == tammax)
		{
			prox.focus();
		}
	}
}

function ValidaCampoEmail(o_email, branco, alerta)
{
	/*
	Se o parametro branco estiver true, permite valor em branco
	Se o parametro alerta estiver true, emite os alertas de erro
	*/

	p_email = o_email.value.toLowerCase();
  
	if (branco) // Permite o e-mail em branco
	{
		if (p_email == '')
		return true;
	}
  
	reg_email = /^[\w\-\.]+@[\w\-\.]+\.[a-z]{2,4}$/;
	if (! reg_email.test(p_email))
	{
		if (alerta) {
			alert(_msgEmailInvalido);
			o_email.focus();
			o_email.select();
		}

		return false;
	}

	return true;
}

function ValidaCampoCPF(valor_cpf)
{
	CPF = valor_cpf.value;
	
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" || CPF == "222222222221" ||  CPF == "333333333331" || CPF == "444444444441" || CPF == "555555555551" || CPF == "666666666661" || CPF == "777777777771" || CPF == "888888888881" || CPF == "999999999991")
	{
		alert('CPF inválido.');
		valor_cpf.value = '';
		valor_cpf.focus();
		return false;
	}
	else
	{
		soma = 0;

		for (i=0; i < 9; i ++)
		soma += parseInt(CPF.charAt(i)) * (10 - i);

		resto = 11 - (soma % 11);

		if (resto == 10 || resto == 11)
		resto = 0;

		if (resto != parseInt(CPF.charAt(9)))
		{
			alert('CPF inválido.');
			valor_cpf.value = '';
			valor_cpf.focus();
			return false;
		}

		soma = 0;
		for (i = 0; i < 10; i ++)
		soma += parseInt(CPF.charAt(i)) * (11 - i);

		resto = 11 - (soma % 11);

		if (resto == 10 || resto == 11)
	    resto = 0;

		if (resto != parseInt(CPF.charAt(10)))
		{
			alert('CPF inválido.');
			valor_cpf.value = '';
			valor_cpf.focus();
			return false;
		}

		return true;
	}
}

function ArrumaValor(valor)
{
	valor = valor.toString().replace(/\\$|\\,/g,'');

	if( isNaN( valor ))
	{
		valor = "0";
	}

	if ( valor < 0 )
	{
		valor = Math.abs( valor );
	}

	cents = Math.floor( ( valor * 100 + 0.5 ) % 100 );
	valor = Math.floor( ( valor * 100 + 0.5 ) / 100 ).toString();

	if ( cents < 10 )
	{
		cents = "0" + cents;
	}

	res = valor + '.' + cents;

	return res;
}

function set(n) 
{
	/* 
	<INPUT name=button onclick=set(1) type=button value="marcar todos">
	<INPUT name=button onclick=set(0) type=button value="desmarcar todos">
	<INPUT name=button onclick=Invers() type=button value="inverter seleção">
	*/

	temp = document.main_form.elements.length  ;
    for (i=0; i < temp; i++)
	{
		document.main_form.elements[i].checked=n;
	}
} 

function Invers()
{
	temp = document.main_form.elements.length ;
	for (i=0; i < temp; i++)
	{
		if(document.main_form.elements[i].checked == 1)
		{
			document.main_form.elements[i].checked = 0;
		}
		else
		{
			document.main_form.elements[i].checked = 1
		}
	}
}

function alert_keycode()
{
	if((event.keyCode == 22) || (event.keyCode == 34) || (event.keyCode == 39))
	{
		alert('Por favor, não utilize aspas.');
	 	return false;
	}
}

function PopImagemProduto(cod, foto, largura, altura, user, mold)
{
	var compl = '';
	if (mold) {
		compl = '&espmold=1'
	}
	
	if(user == 1)
	{
		window.open("admin/ver_produto.php?foto=" + foto + "&ProdId=" + cod + compl, "fotoProduto", "height=" + altura + ", width=" + largura + ", left=50, top=20, status=no, toolbar=no, directories=no, menubar=no, location=no, resizable=yes, scrollbars=yes");
	}
	else
	{
		window.open("ver_produto.php?foto=" + foto + "&ProdId=" + cod + compl, "fotoProduto", "height=" + altura + ", width=" + largura + ", left=50, top=20, status=no, toolbar=no, directories=no, menubar=no, location=no, resizable=yes, scrollbars=yes");
	}
}

function VerificaPesquisa(_msg)
{
	var PesqTexto = document.formPesquisa.PesqTexto.value.length;

	if(PesqTexto <= 3) {
		if (_msg) {
			alert(_msg);
		}
		return false;
	} else {
		return true;
	}
	return true;

}

function CadastrarEmail(action)
{
	if(document.formNews.n_email.value != '')
	{
		window.open("newsletter.php?action=" + action + "&email=" + document.formNews.n_email.value, "CadastrarEmail", "height=180, width=200, left=50, top=20, status=no, toolbar=no, directories=no, menubar=no, location=no, resizable=no, scrollbars=no");
		return true;
	}
	else
	{
		alert('Por favor, informe seu e-mail.');
		return false;
	}
}

function CheckPassLen(_msg)
{
	if(document.ChgPwd_form.senha_nova1.value.length < 6 || document.ChgPwd_form.senha_nova2.value.length < 6)
	{
		alert(_msg);
		return false;
	}
	else
	{
		return true;
	}
}


function CheckFormaPagto(_forma, objCheckPedido)
{
	if (_forma) {
		if (_forma == 'C') {
			if(document.main_form.cc_nome.value == '')
			{
				alert("<?=$messages[msg_erro_titular]; ?>.");
				document.main_form.cc_nome.focus();
				return false;
			}
		
			if(document.main_form.cc_nro.value == '')
			{
				alert("<?=$messages[msg_erro_numero_cartao]; ?>");
				document.main_form.cc_nro.focus();
				return false;
			}
		
			if(document.main_form.cc_dtval_mes.value == '' || document.main_form.cc_dtval_ano.value == '')
			{
				alert("<?=$messages[msg_erro_data_validade]; ?>");
				document.main_form.cc_dtval_mes.focus();
				return false;
			}
		
			if(document.main_form.cc_seccode.value  == '')
			{
				alert("<?=$messages[msg_erro_codigo_seguranca]; ?>");
				document.main_form.cc_seccode.focus();
				return false;
			}
			return CheckPedido(objCheckPedido);
		} else if (_forma == 'D') {
			return true;
		}
	}

}
function toggleDisplay()
{
	if (novoItemPedido.style.display == "none")
	{
		novoItemPedido.style.display = "block";
		doAddItemPedido.style.display = "block";
		main_form.showItemPedido.disabled = true;
	}
	else
	{
		novoItemPedido.style.display = "none";
		doAddItemPedido.style.display = "none";
		main_form.showItemPedido.disabled = false;
	}
}

function ValidaCadastro(msgNome, msgEmail, msgSenha1, msgSenha2, msgCpf, msgTel, msgEnd, mostraSenha, idiomaSite)
{
	if(document.main_form.nome_completo.value == '')
	{
		alert(msgNome);
		document.main_form.nome_completo.focus();
		return false;
	}

	if(document.main_form.email.value == '')
	{
		alert(msgEmail);
		document.main_form.email.focus();
		return false;
	}
	
	if (mostraSenha == 'S') {
		if(document.main_form.senha1.value.length < 6)
		{
			alert(msgSenha1);
			document.main_form.senha1.focus();
			return false;
		}
	
		if(document.main_form.senha2.value.length < 6)
		{
			alert(msgSenha2);
			document.main_form.senha2.focus();
			return false;
		}
	}
	
	if (idioma_site == 'P') {
		if(document.main_form.cpf.value == '')
		{
			alert(msgCpf);
			document.main_form.cpf.focus();
			return false;
		}
	}

	if((document.main_form.telefone_res_ddd.value == '' && document.main_form.telefone_res.value == '') && (document.main_form.telefone_com_ddd.value == '' && document.main_form.telefone_com.value == '') && (document.main_form.celular_ddd.value == '' && document.main_form.celular.value == ''))
	{
		alert(msgTel);
		document.main_form.telefone_res_ddd.focus();
		return false;
	}

	if(document.main_form.endereco.value == '' || document.main_form.endereco_cidade.value == '' || document.main_form.endereco_estado.value == '' || document.main_form.endereco_pais.value == '' || document.main_form.endereco_cep.value == '')
	{
		alert(msgEnd);
		document.main_form.endereco.focus();

		return false;
	}

	return true;
}


// Check browser version
var isNav4 = false, isNav5 = false, isIE4 = false
var strSeperator = "/";
// If you are using any Java validation on the back side you will want to use the / because
// Java date validations do not recognize the dash as a valid date separator.
var vDateType = 3; // Global value for type of date format
//                1 = mm/dd/yyyy
//                2 = yyyy/dd/mm  (Unable to do date check at this time)
//                3 = dd/mm/yyyy
var vYearType = 4; //Set to 2 or 4 for number of digits in the year for Netscape
var vYearLength = 2; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.
var err = 0; // Set the error code to a default of zero
if(navigator.appName == "Netscape") {
	if (navigator.appVersion < "5") {
		isNav4 = true;
		isNav5 = false;
	}
	else
	if (navigator.appVersion > "4") {
		isNav4 = false;
		isNav5 = true;
	}
}
else {
	isIE4 = true;
}
function DateFormat(vDateName, vDateValue, e, dateCheck, dateType) {
	vDateType = dateType;
	// vDateName = object name
	// vDateValue = value in the field being checked
	// e = event
	// dateCheck
	// True  = Verify that the vDateValue is a valid date
	// False = Format values being entered into vDateValue only
	// vDateType
	// 1 = mm/dd/yyyy
	// 2 = yyyy/mm/dd
	// 3 = dd/mm/yyyy
	//Enter a tilde sign for the first number and you can check the variable information.
	if (vDateValue == "~") {
		alert("AppVersion = "+navigator.appVersion+" \nNav. 4 Version = "+isNav4+" \nNav. 5 Version = "+isNav5+" \nIE Version = "+isIE4+" \nYear Type = "+vYearType+" \nDate Type = "+vDateType+" \nSeparator = "+strSeperator);
		vDateName.value = "";
		vDateName.focus();
		return true;
	}
	var whichCode = (window.Event) ? e.which : e.keyCode;
	// Check to see if a seperator is already present.
	// bypass the date if a seperator is present and the length greater than 8
	if (vDateValue.length > 8 && isNav4) {
		if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
		return true;
	}
	//Eliminate all the ASCII codes that are not valid
	var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
	if (alphaCheck.indexOf(vDateValue) >= 1) {
		if (isNav4) {
			vDateName.value = "";
			vDateName.focus();
			vDateName.select();
			return false;
		}
		else {
			vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
			return false;
		}
	}
	if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
	return false;
	else {
		//Create numeric string values for 0123456789/
		//The codes provided include both keyboard and keypad values
		var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
		if (strCheck.indexOf(whichCode) != -1) {
			if (isNav4) {
				if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >=1)) {
					alert(_msgDataInvalida);
					vDateName.value = "";
					vDateName.focus();
					vDateName.select();
					return false;
				}
				if (vDateValue.length == 6 && dateCheck) {
					var mDay = vDateName.value.substr(2,2);
					var mMonth = vDateName.value.substr(0,2);
					var mYear = vDateName.value.substr(4,4)
					//Turn a two digit year into a 4 digit year
					if (mYear.length == 2 && vYearType == 4) {
						var mToday = new Date();
						//If the year is greater than 30 years from now use 19, otherwise use 20
						var checkYear = mToday.getFullYear() + 30;
						var mCheckYear = '20' + mYear;
						if (mCheckYear >= checkYear)
						mYear = '19' + mYear;
						else
						mYear = '20' + mYear;
					}
					var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
					if (!dateValid(vDateValueCheck)) {
						alert(_msgDataInvalida);
						vDateName.value = "";
						vDateName.focus();
						vDateName.select();
						return false;
					}
					return true;
				}
				else {
					// Reformat the date for validation and set date type to a 1
					if (vDateValue.length >= 8  && dateCheck) {
						if (vDateType == 1) // mmddyyyy
						{
							var mDay = vDateName.value.substr(2,2);
							var mMonth = vDateName.value.substr(0,2);
							var mYear = vDateName.value.substr(4,4)
							vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
						}
						if (vDateType == 2) // yyyymmdd
						{
							var mYear = vDateName.value.substr(0,4)
							var mMonth = vDateName.value.substr(4,2);
							var mDay = vDateName.value.substr(6,2);
							vDateName.value = mYear+strSeperator+mMonth+strSeperator+mDay;
						}
						if (vDateType == 3) // ddmmyyyy
						{
							var mMonth = vDateName.value.substr(2,2);
							var mDay = vDateName.value.substr(0,2);
							var mYear = vDateName.value.substr(4,4)
							vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
						}
						//Create a temporary variable for storing the DateType and change
						//the DateType to a 1 for validation.
						var vDateTypeTemp = vDateType;
						vDateType = 1;
						var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
						if (!dateValid(vDateValueCheck)) {
							alert(_msgDataInvalida);
							vDateType = vDateTypeTemp;
							vDateName.value = "";
							vDateName.focus();
							vDateName.select();
							return false;
						}
						vDateType = vDateTypeTemp;
						return true;
					}
					else {
						if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
							alert(_msgDataInvalida);
							vDateName.value = "";
							vDateName.focus();
							vDateName.select();
							return false;
						}
					}
				}
			}
			else {
				// Non isNav Check
				if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
					alert(_msgDataInvalida);
					vDateName.value = "";
					vDateName.focus();
					return true;
				}
				// Reformat date to format that can be validated. mm/dd/yyyy
				if (vDateValue.length >= 8 && dateCheck) {
					// Additional date formats can be entered here and parsed out to
					// a valid date format that the validation routine will recognize.
					if (vDateType == 1) // mm/dd/yyyy
					{
						var mMonth = vDateName.value.substr(0,2);
						var mDay = vDateName.value.substr(3,2);
						var mYear = vDateName.value.substr(6,4)
					}
					if (vDateType == 2) // yyyy/mm/dd
					{
						var mYear = vDateName.value.substr(0,4)
						var mMonth = vDateName.value.substr(5,2);
						var mDay = vDateName.value.substr(8,2);
					}
					if (vDateType == 3) // dd/mm/yyyy
					{
						var mDay = vDateName.value.substr(0,2);
						var mMonth = vDateName.value.substr(3,2);
						var mYear = vDateName.value.substr(6,4)
					}
					if (vYearLength == 4) {
						if (mYear.length < 4) {
							alert(_msgDataInvalida);
							vDateName.value = "";
							vDateName.focus();
							return true;
						}
					}
					// Create temp. variable for storing the current vDateType
					var vDateTypeTemp = vDateType;
					// Change vDateType to a 1 for standard date format for validation
					// Type will be changed back when validation is completed.
					vDateType = 1;
					// Store reformatted date to new variable for validation.
					var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
					if (mYear.length == 2 && vYearType == 4 && dateCheck) {
						//Turn a two digit year into a 4 digit year
						var mToday = new Date();
						//If the year is greater than 30 years from now use 19, otherwise use 20
						var checkYear = mToday.getFullYear() + 30;
						var mCheckYear = '20' + mYear;
						if (mCheckYear >= checkYear)
						mYear = '19' + mYear;
						else
						mYear = '20' + mYear;
						vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
						// Store the new value back to the field.  This function will
						// not work with date type of 2 since the year is entered first.
						if (vDateTypeTemp == 1) // mm/dd/yyyy
						vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
						if (vDateTypeTemp == 3) // dd/mm/yyyy
						vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
					}
					if (!dateValid(vDateValueCheck)) {
						alert(_msgDataInvalida);
						vDateType = vDateTypeTemp;
						vDateName.value = "";
						vDateName.focus();
						return true;
					}
					vDateType = vDateTypeTemp;
					return true;
				}
				else {
					if (vDateType == 1) {
						if (vDateValue.length == 2) {
							vDateName.value = vDateValue+strSeperator;
						}
						if (vDateValue.length == 5) {
							vDateName.value = vDateValue+strSeperator;
						}
					}
					if (vDateType == 2) {
						if (vDateValue.length == 4) {
							vDateName.value = vDateValue+strSeperator;
						}
						if (vDateValue.length == 7) {
							vDateName.value = vDateValue+strSeperator;
						}
					}
					if (vDateType == 3) {
						if (vDateValue.length == 2) {
							vDateName.value = vDateValue+strSeperator;
						}
						if (vDateValue.length == 5) {
							vDateName.value = vDateValue+strSeperator;
						}
					}
					return true;
				}
			}
			if (vDateValue.length == 10&& dateCheck) {
				if (!dateValid(vDateName)) {
					// Un-comment the next line of code for debugging the dateValid() function error messages
					//alert(err);
					alert(_msgDataInvalida);
					vDateName.focus();
					vDateName.select();
				}
			}
			return false;
		}
		else {
			// If the value is not in the string return the string minus the last
			// key entered.
			if (isNav4) {
				vDateName.value = "";
				vDateName.focus();
				vDateName.select();
				return false;
			}
			else
			{
				vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
				return false;
			}
		}
	}
}
function dateValid(objName) {
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	// var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	//strDate = datefield.value;
	strDate = objName;
	if (strDate.length < 1) {
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	//Adjustment for short years entered
	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}
	strTemp = strDay;
	strDay = strMonth;
	strMonth = strTemp;
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) {
			if (intday > 29) {
				err = 9;
				return false;
			}
		}
		else {
			if (intday > 28) {
				err = 10;
				return false;
			}
		}
	}
	return true;
}

function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	}
	else {
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}

function checkFormaPagtoInfo(id)
{
	if(id == 1 || id == 4 || id == 5 || id == 6 || id == 13)
	{
		hideFormaPagtoInfo();
	}
	else
	{
		showFormaPagtoInfo();
	}
}

function showFormaPagtoInfo()
{
	cc_linha1.style.display = 'block';
	cc_linha2.style.display = 'block';
	cc_linha3.style.display = 'block';
	cc_linha4.style.display = 'block';
}

function hideFormaPagtoInfo()
{
	cc_linha1.style.display = 'none';
	cc_linha2.style.display = 'none';
	cc_linha3.style.display = 'none';
	cc_linha4.style.display = 'none';
}

function ShowCertif() {
	window.open("https://www.thawte.com/cgi/server/certdetails.exe?referer=https://www.floresnaweb.com/", "popCertif", "height=520, width=520, left=50, top=50, status=yes, toolbar=no, directories=no, menubar=no, location=no, resizable=no, scrollbars=yes");
}
function CheckPedido(objForm)
{
	if(objForm.totalPedido.value <= 0)
	{
		alert(_msgPedido_valor_invalido);
		return false;
	}

/*
	if(objForm.formaPagto.value <= 0)
	{
		alert(_msgPedido_forma_pagto);
		return false;
	}

	if(objForm.nome_completo.value == '')
	{
		alert(_msgPedido_destinatario_nome);
		objForm.nome_completo.focus();
		return false;
	}

	if(objForm.endereco.value == '')
	{
		alert(_msgPedido_destinatario_rua);
		objForm.endereco.focus();
		return false;
	}

	if(objForm.endereco_cidade.value == '')
	{
		alert(_msgPedido_destinatario_cidade);
		objForm.endereco_cidade.focus();
		return false;
	}

	if(objForm.endereco_estado.value == '')
	{
		alert(_msgPedido_destinatario_estado);
		objForm.endereco_estado.focus();
		return false;
	}

	if(objForm.endereco_pais.value == '')
	{
		alert(_msgPedido_destinatario_pais);
		objForm.endereco_pais.focus();
		return false;
	}

	if(objForm.endereco_cep.value == '')
	{
		alert(_msgPedido_destinatario_cep);
		objForm.endereco_cep.focus();
		return false;
	}
	
	if(objForm.dt_entrega.value == '')
	{
		alert(_msgPedido_data_entrega);
		return false;
	}
*/
	return true;
}

function changeCartMoldura(pdId) {
	var frm = document.main_form;
	frm.action = 'fecharcompra.php?AddToCart='+pdId;
	frm.submit();
}

var __curPdId;
var __curPdQt;
function setCurrentQtde(pdId, obj) {
	__curPdId = pdId;
	__curPdQt = obj.value;
}

function checkCurrentQtde(pdId, obj) {
	if (__curPdId == pdId) {
		var qtVal = obj.value;
		
		if (qtVal == '') {
			alert('Informe a quantidade desejada para este produto.');
			obj.focus();
			return false;
		} else if (qtVal.match(/[^0-9]/i)) {
			alert('Informe a quantidade desejada utilizando apenas números');
			obj.value = '';
			obj.focus();
			return false;
		} else if (qtVal > 9) {
			if (!confirm('A quantidade informada é muito grande. Esta informação está correta?')) {
				obj.value = '';
				obj.focus();
				return false;
			}
		}
		
		if (qtVal != __curPdQt) {
			var frm = document.main_form;
			frm.action = 'fecharcompra.php?AddToCart='+pdId;
			frm.submit();
		}
	}
}

function goPasso2() {
	if (document.main_form.msg_cartao) {
		if (document.main_form.msg_cartao.value == '') {
			if (!confirm('Você não informou a mensagem para o cartão de presente. Deseja continuar assim mesmo?')) {
				return false;
			}
		}
	}
	var frm = document.main_form;
	frm.action = 'fecharcompraummeio.php';
	frm.submit();
}

function changeCadTipo(_tipo) {
	if (_tipo == 'PF') {
		document.getElementById('tipoPF').style.display = 'block';
		document.getElementById('tipoPJ').style.display = 'none';
	} else if (_tipo == 'PJ') {
		document.getElementById('tipoPF').style.display = 'none';
		document.getElementById('tipoPJ').style.display = 'block';
	}
}

function submitCep(obj,frm,action) {
	if (!obj.value.match(/[0-9]{8}/i)) {
		alert('O CEP informado não é válido. Informe seu CEP utilizando apenas números.. Ex.: 99999-999 informe como 99999999');
		return false;
	}
	if (obj.value != __currCep) {
		frm.ac.value = 'changeCep';
		if (action) {
			frm.action = action;
		}
		frm.submit();
	}
}

var __currCep = '';
function setCurrCep(cep) {
	__currCep = cep;
}

function validaCadastroUsuario() {
	var doc = document.form_cadastro;
	
	var d = new Date();
	var min_date = d.getFullYear() - 18;
	
	if (doc.tipo[0].checked == false && doc.tipo[1].checked == false) {
		alert('Informe o tipo de cadastro.');
	} else {
		if (doc.tipo[0].checked == true) {
			if (doc.nome_exibicao.value == '') {
				alert('Informe o nome pelo qual você deseja ser chamado no site.');
			} else if (doc.nome.value == '') {
				alert('Informe o seu nome');
			} else if (doc.sobrenome.value == '') {
				alert('Informe o seu sobrenome');
			} else if (doc.cpf.value == '') {
				alert('Informe o número do seu CPF.');
			} else if (!ValidaCampoCPF(doc.cpf)) {
				//alert('O número do CPF informado é inválido.');
			} else if (doc.rg.value != '' && !doc.rg.value.match(/[0-9]{4,10}/i)) {
				alert('O número do RG informado é inválido. Caso seu RG termine com letra, substitua por 0 (zero).');
			} else if (doc.data_nascimento.value == '') {
				alert('Informe a sua data de nascimento.');
			} else if (!doc.data_nascimento.value.match(/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/i)) {
				alert('A data de nascimento informada é inválida.');
			} else if (doc.data_nascimento.value.substr(0,2) > 31 || 
						doc.data_nascimento.value.substr(3,2) > 12 || 
						doc.data_nascimento.value.substr(6,4) > min_date || 
						doc.data_nascimento.value.substr(6,4) < 1910) {
				alert('A data de nascimento informada é inválida.');
			} else if (doc.sexo.selectedIndex == '0') {
				alert('Informe o seu sexo.');
			} else {
				validaCadastroUsuarioComplemento(doc);
			}
		} else if (doc.tipo[1].checked == true) {
			if (doc.razao_social.value == '') {
				alert('Informe a Razão Social da empresa.');
			} else if (doc.nome_contato.value == '') {
				alert('Informe um nome de contato da empresa.');
			} else if (doc.cnpj.value == '') {
				alert('Informe o número do CNPJ da empresa.');
			} else if (!doc.cnpj.value.match(/[0-9]{14}/i)) {
				alert('O número do CNPJ informado é inválido. Utilize apenas números para o preenchimento do CNPJ.');
			} else if (doc.ie.value == '' && doc.ie_isento.checked == false) {
				alert('Informe o número da Inscrição Estadual da sua empresa ou marque a opção "Isento" caso sua empresa seja isenta de inscrição estadual.');
			} else if (doc.ie.value != '' && doc.ie_isento.checked == true) {
				alert('O número de Inscrição Estadual e a opção "Isento" estão simultaneamente preenchidos. Favor corrigir esta informação.');
			} else {
				validaCadastroUsuarioComplemento(doc);
			}
		}
	}
	return false;
}

function validaCadastroUsuarioComplemento(doc) {
	if (doc.email.value == '') {
		alert('Informe o seu endereço de e-mail');
	} else if (!doc.email.value.match(/^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-\._]+\.[a-zA-Z0-9]{2,4}$/)) {
		alert('O endereço de e-mail informado é inválido.');
	} else if (doc.senha.value.length < 6) {
		alert('Informe sua senha utilizando pelo menos 6 letras e/ou números.');
	} else if (doc.senha_repeticao.value != doc.senha.value) {
		alert('A confirmação de senha é diferente da senha informada.');
	} else if (doc.tipo_endereco.selectedIndex == '0') {
		alert('Informe o tipo de endereço.');
	} else if (doc.cep.value == '') {
		alert('Informe o CEP.');
	} else if (!doc.cep.value.match(/[0-9]{8}/i)) {
		alert('Informe o CEP utilizando 8 números.');
	} else if (doc.endereco.value == '') {
		alert('Informe o endereço.');
	} else if (doc.numero.value == '') {
		alert('Informe o número.');
	} else if (doc.bairro.value == '') {
		alert('Informe o bairro.');
	} else if (doc.cidade.value == '') {
		alert('Informe a cidade.');
	} else if (doc.estado.selectedIndex == '0') {
		alert('Informe o estado.');
	} else if (doc.tel1_ddd.value == '') {
		alert('Informe o ddd do primeiro telefone.');
	} else if (!doc.tel1_ddd.value.match(/[1-9]{1}[0-9]{1}/i)) {
		alert('Informe o ddd do primeiro telefone utilizando apenas números.');
	} else if (doc.tel1.value == '') {
		alert('Informe o primeiro telefone.');
	} else if (!doc.tel1.value.match(/[2-9]{1}[0-9]{6,7}/i)) {
		alert('Informe o primeiro telefone utilizando apenas números.');
	} else if ( (doc.tel2_ddd.value != '' && !doc.tel2_ddd.value.match(/[1-9]{1}[0-9]{1}/i)) || (doc.tel2.value != '' && !doc.tel2_ddd.value.match(/[2-9]{1}[0-9]{6,7}/i)) ) {
		alert('Informe o segundo número de telefone utilizando apenas números.');
	} else {
		document.form_cadastro.ac.value = 'createCad';
		//document.form_cadastro.action = 'cadastro.php';
		document.form_cadastro.submit();
		return true;
	}
	return false;
}

function validaCadastroNovoEndereco(edit) {
	var doc = document.form_criar_endereco;
	if (doc.tipo_endereco.selectedIndex == '0') {
		alert('Informe o tipo de endereço.');
	} else if (doc.cep.value == '') {
		alert('Informe o CEP.');
	} else if (!doc.cep.value.match(/[0-9]{8}/i)) {
		alert('Informe o CEP utilizando 8 números.');
	} else if (doc.endereco.value == '') {
		alert('Informe o endereço.');
	} else if (doc.numero.value == '') {
		alert('Informe o número.');
	} else if (doc.bairro.value == '') {
		alert('Informe o bairro.');
	} else if (doc.cidade.value == '') {
		alert('Informe a cidade.');
	} else if (doc.estado.selectedIndex == '0') {
		alert('Informe o estado.');
	} else if (doc.tel1_ddd.value == '') {
		alert('Informe o ddd do primeiro telefone.');
	} else if (!doc.tel1_ddd.value.match(/[1-9]{1}[0-9]{1}/i)) {
		alert('Informe o ddd do primeiro telefone utilizando apenas números.');
	} else if (doc.tel1.value == '') {
		alert('Informe o primeiro telefone.');
	} else if (!doc.tel1.value.match(/[2-9]{1}[0-9]{6,7}/i)) {
		alert('Informe o primeiro telefone utilizando apenas números.');
	} else if ( (doc.tel2_ddd.value != '' && !doc.tel2_ddd.value.match(/[1-9]{1}[0-9]{1}/i)) || (doc.tel2.value != '' && !doc.tel2.value.match(/[2-9]{1}[0-9]{6,7}/i)) ) {
		alert('Informe o segundo número de telefone utilizando apenas números.');
	} else {
		if (edit != '') {
			doc.ac.value = 'writeEnd|'+edit;
		} else {
			doc.ac.value = 'addEnd';
		}
		doc.submit();
		return true;
	}
	return false;
}

function editEnd(id) {
	document.form_criar_endereco.ac.value = 'editEnd|'+id;
	document.form_criar_endereco.submit();
}

function criarEnd() {
	document.getElementById('criarEndereco').style.display = 'block';
	document.getElementById('enderecosCadastrados').style.display = 'none';
}
function cancelaCriarEnd() {
	document.getElementById('criarEndereco').style.display = 'none';
	document.getElementById('enderecosCadastrados').style.display = 'block';
	document.form_criar_endereco.reset();
}

function usarEnd(id) {
	document.formpasso4.idend.value = id;
	document.formpasso4.submit();
}

function delEnd(id) {
	if (confirm('Você tem certeza que deseja remover o endereço?')) {
		document.form_criar_endereco.ac.value = 'delEnd|'+id;
		document.form_criar_endereco.submit();
	}
}

function finalizarPedido() {
	var checked = false;
	var doc = document.finalizar_pedido;
	for (var i=0; i<doc.formaPgto.length; i++) {
		if (doc.formaPgto[i].checked == true) {
			checked = true;
		}
	}
	if (checked == true) {
		if (_curPgForma == 'C') {
			if (doc.cc_numero.value == '') {
				alert('Informe o número do seu cartão de crédito.');
				return false;
			} else if (!doc.cc_numero.value.match(/[0-9]{12,18}/i)) {
				alert('Informe apenas números no campo "Número do Cartão"');
				return false;
			} else if (doc.cc_nome.value == '') {
				alert('Informe o nome impresso no cartão de crédito.');
				return false;
			} else if (doc.cc_val_m.options[0].selected == true) {
				alert('Informe o mês de validade do cartão de crédito');
				return false;
			} else if (doc.cc_val_a.options[0].selected == true) {
				alert('Informe o ano de validade do cartão de crédito');
				return false;
			} else if (doc.cc_cod_seg.value == '') {
				alert('Informe o código de segurança do cartão de crédito');
				return false;
			}
		}
		doc.submit();
		return true;
	} else {
		alert('Selecione uma forma de pagamento.');
		return false;
	}
}

var _curPgForma = '';

function setPgType(forma) {
	_curPgForma = forma;
}

function backCart() {
	window.location = 'fecharcompra.php';
}

function confirmarPedido() {
	window.location = 'finalizarcompra.php';
}


function validaCadastroUsuarioUpd() {
	var doc = document.form_cadastro;
	
	if (doc.tipo[0].checked == false && doc.tipo[1].checked == false) {
		alert('Informe o tipo de cadastro.');
	} else {
		if (doc.tipo[0].checked == true) {
			if (doc.nome_exibicao.value == '') {
				alert('Informe o nome pelo qual você deseja ser chamado no site.');
			} else if (doc.nome.value == '') {
				alert('Informe o seu nome');
			} else if (doc.sobrenome.value == '') {
				alert('Informe o seu sobrenome');
			} else if (doc.cpf.value == '') {
				alert('Informe o número do seu CPF.');
			} else if (!ValidaCampoCPF(doc.cpf)) {
				//alert('O número do CPF informado é inválido.');
			} else if (doc.rg.value != '' && !doc.rg.value.match(/[0-9]{4,10}/i)) {
				alert('O número do RG informado é inválido. Caso seu RG termine com letra, substitua por 0 (zero).');
			} else if (doc.data_nascimento.value == '') {
				alert('Informe a sua data de nascimento.');
			} else if (!doc.data_nascimento.value.match(/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/i)) {
				alert('A data de nascimento informada é inválida.');
			} else if (doc.data_nascimento.value.substr(0,2) > 31 || 
						doc.data_nascimento.value.substr(3,2) > 12 || 
						doc.data_nascimento.value.substr(6,4) > 1990 || 
						doc.data_nascimento.value.substr(6,4) < 1910) {
				alert('A data de nascimento informada é inválida.');
			} else if (doc.sexo.selectedIndex == '0') {
				alert('Informe o seu sexo.');
			} else {
				validaCadastroUsuarioComplementoUpd(doc);
			}
		} else if (doc.tipo[1].checked == true) {
			if (doc.razao_social.value == '') {
				alert('Informe a Razão Social da empresa.');
			} else if (doc.nome_contato.value == '') {
				alert('Informe um nome de contato da empresa.');
			} else if (doc.cnpj.value == '') {
				alert('Informe o número do CNPJ da empresa.');
			} else if (!doc.cnpj.value.match(/[0-9]{14}/i)) {
				alert('O número do CNPJ informado é inválido. Utilize apenas números para o preenchimento do CNPJ.');
			} else if (doc.ie.value == '' && doc.ie_isento.checked == false) {
				alert('Informe o número da Inscrição Estadual da sua empresa ou marque a opção "Isento" caso sua empresa seja isenta de inscrição estadual.');
			} else if (doc.ie.value != '' && doc.ie_isento.checked == true) {
				alert('O número de Inscrição Estadual e a opção "Isento" estão simultaneamente preenchidos. Favor corrigir esta informação.');
			} else {
				validaCadastroUsuarioComplementoUpd(doc);
			}
		}
	}
	return false;
}

function validaCadastroUsuarioComplementoUpd(doc) {
	if (doc.email.value == '') {
		alert('Informe o seu endereço de e-mail');
	} else if (!doc.email.value.match(/^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-\._]+\.[a-zA-Z0-9]{2,4}$/)) {
		alert('O endereço de e-mail informado é inválido.');
	} else {
		document.form_cadastro.ac.value = 'updCad';
		document.form_cadastro.submit();
		return true;
	}
	return false;
}

function openCV() {
	window.open('cod_seguranca.php', 'wndCodSeg', 'width=466,height=450,status=no,scrollbars=yes,top=50,left=50');
}
