/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
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;
		}
	}	
}

 
function abrir_login() { 
	document.getElementById('login').className='abrir';
} 
function cerrar_login() { 
	document.getElementById('login').className='cerrar';
} 

function abrir_pedido(od_id) { 
	document.getElementById(od_id).className='abrir';
	document.getElementById('ce_'+od_id).className='abrir';
	document.getElementById('ab_'+od_id).className='cerrar';
} 
function cerrar_pedido(od_id) { 
	document.getElementById(od_id).className='cerrar';
	document.getElementById('ce_'+od_id).className='cerrar';
	document.getElementById('ab_'+od_id).className='abrir';
}

function abrir_menu(id) { 
	document.getElementById(id).className='abrir';
	document.getElementById('cm_'+id).className='abrir';
	document.getElementById('am_'+id).className='cerrar';
} 
function cerrar_menu(id) { 
	document.getElementById(id).className='cerrar';
	document.getElementById('cm_'+id).className='cerrar';
	document.getElementById('am_'+id).className='abrir';
}

var origen = '';

function act_orig(ori) { 
	origen = ori;
} 

function abrirVentana(url) { 
	window.open(url, '_self');
}

function cambiafondo(url,aliv,alih,rep) {
	if(url){
		document.body.style.background = 'url(imagenes/category/'+url+') '+rep+' '+alih+' '+aliv; 
	}else{
		document.body.style.background = 'url(imagenes/fondo.jpg) no-repeat right top';
	}
}
