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

function resetText(textBox)
{	
	if (textBox.value.length == 0) {
		textBox.value = 'Nombre';		
	} 
}

function clearText(textBox)
{	
	if (textBox.value == 'Nombre') {
		textBox.value = '';		
	} 
}

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

var origen = '';

function act_orig(ori) { 
	origen = ori;
} 

function abrirVentana(url) { 
	window.open(url, '_self');
	//location.href=url;
	//location.replace(url);
} 

function getEkomi() {
	
    var xhr = getTransport();
    xhr.onreadystatechange = function() {
        updateDataEkomi(xhr);
    }
	xhr.open('get', 'ekomi/ausgabe.php', true);
    xhr.send('');
	
}


function updateDataEkomi(xhr) {
    if (xhr.readyState == 4) {
        if (xhr.status == 200) { 
			updateEkomi(xhr.responseText);			
        } else {
            //alert('Error: ' + xhr.status + '!');
        }
    }
}
function updateEkomi(html) {
                var content = document.getElementById('ekomi');
                content.innerHTML = html;
                
                while (html.match(/(<script[^>]+javascript[^>]+>\s*(\/\/*<!\[CDATA\[)?(<!--)?\s*)/i)) {
                    html = html.substr(html.indexOf(RegExp.$1) + RegExp.$1.length);
                    if (!html.match(/((\/\/ *\]\]>)?(-->)?\s*<\/script>)/)) break;
                    block = html.substr(0, html.indexOf(RegExp.$1));
                    html = html.substring(block.length + RegExp.$1.length);
                    eval(block);
                }
}
            
