/*
	Desabilita tecla Enter

function kH(e) {
	var pK = e ? e.which : window.event.keyCode;
	return pK != 13;
}
if (!isInStr("/admin/",window.location.href)) {
	document.onkeypress = kH;
	if (document.layers) document.captureEvents(Event.KEYPRESS);
}
*/

/*
	Strip whitespace from the beginning and end of a string
	Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

function isInStr(pattern, string) {
	var _m = pattern.toLowerCase(); // pattern to match.
	var _s = string.toLowerCase();
	var _c = 0; // count
	for (var i=0;i<_s.length;i++) {
		if (_m == _s.substr(i,_m.length))
		 _c++;
	}
	if (_c > 0) {
		return true;
	} else {
		return false;
	}
}

/*
	Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}

/*
	Verifica se o cep está preenchido e contém 8 caracteres
*/
function valida_cep(obj) {
	 form = document.frmCart;
	 if (obj['cepDest'].value.length == 0) {
		alert("Por favor digite um CEP !");
		form['cepDest'].focus();
		return false;
	 }
	 s = limpa_string(obj['cepDest'].value);
	 if (s.length != 8) {
		alert("O CEP deve ter 8 caracteres numericos !");
		obj['cepDest'].focus();
		return false;
	 }
	 return true;
}

/*
	Deixa so' os digitos no numero
*/
function limpa_string(S){
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	for (var i=0; i<S.length; i++) {
	  digito = S.charAt(i);
	  if (Digitos.indexOf(digito)>=0){temp=temp+digito}
	}
	return temp
}

function popUp(arquivo)
{
	attr = "toolbars=no,status=no,resize=no,scrollbars=no,width=633,height=530,top=50,left=100";
	window.open(arquivo,"",attr);
}

function checkMail(field)
{
	var x = field.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(x)) {
		alert('O email informado é inválido');
		field.focus();
		return false;
	} else {
		return true;
	}
}

function valida_user_senha(obj) {
	s = obj.value;	
	if (s.length <6) {
		alert("O Nome de Usuário e a Senha devem ter no mínimo 6 caracteres !");
		obj.focus();
		return false;
	}
	return true;
}

function check_radio(obj)
{
	checked = false;
	for (i=0;i<obj.length;i++) {
		if (obj[i].checked) {
			checked = true;
		}
	}
	return checked;
}

function checkFrmLogin(form) {
	with (form) {
		if (isEmpty(txtUserName, 'Você deve entrar com seu nome de usuário')) {
			return false;
		} else if (isEmpty(txtPassword, 'Você deve entrar com sua senha')) {
			return false;
		} else {
			return true;
		}
	}
}

function checkFrmSearch(form) {
	with (form) {
		if (isEmpty(search, 'Para fazer uma busca, você deve entrar com uma palavra-chave')) {
			return false;
		} else if (search.value.length < 3) {
			alert('O termo a ser utilizado na busca deve ter, no mínimo, 3 caracteres');
			search.focus();
			return false;
		} else {
			return true;
		}
	}
}