//var $j = jQuery.noConflict();
//Javascript Document
/*
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;
}
//AJAX

function getXmlHttpObject() {
	var xmlhttp;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
}
@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		}
		catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}
function traeformlogin() {
	var http = getXmlHttpObject(); 
	http.open("GET", "http://www.bazarfreak.com/include/inc-usr-login.php?lang=es", true);
	http.onreadystatechange = function () {
		if (http.readyState == 1) {
			document.getElementById('usr').innerHTML = "<div id=\"mensaje\">Cargando...</div>";
		}
		if (http.readyState == 4) {
			results = http.responseText;
			document.getElementById('usr').innerHTML = results;
		}
	}
	http.send(null);
}
function traeregistrarse() {
	var http = getXmlHttpObject(); 
	http.open("GET", "http://www.bazarfreak.com/include/inc-usr-registrar.php?lang=es", true);
	http.onreadystatechange = function () {
		if (http.readyState == 1) {
			document.getElementById('usr').innerHTML = "<div id=\"mensaje\">Cargando...</div>";
		}
		if (http.readyState == 4) {
			results = http.responseText;
			document.getElementById('usr').innerHTML = results;
		}
	}
	http.send(null);
}
/*function handleHttpResponse() {
	if (http.readyState == 1) {
		document.getElementById('fotos').innerHTML = "<div id=\"mensaje\">Cargando...</div>";
	}
	if (http.readyState == 4) {
		results = http.responseText;
		document.getElementById('fotos').innerHTML = results;
	}
}*/
function recargaCaptcha(tiempo) {
	var http = getXmlHttpObject(); 
	http.open("GET", "http://www.bazarfreak.com/captcha/inc_captcha.php?tiempo=1283921152", true);
	http.onreadystatechange = function () {
		if (http.readyState == 1) {
			document.getElementById("captcha").innerHTML = "<div id=\"mensaje\">Cargando...</div>";
		}
		if (http.readyState == 4) {
			document.getElementById("captcha").innerHTML = http.responseText;
		}
	};
	http.send(null);
}

sobre=false;
function novisi()
{
	if (!sobre)
	{
		if (document.all)
		{
			document.all['cartflota'].className = 'oculto';
		}
		else if (document.getElementById)
		{
			document.getElementById('cartflota').className = 'oculto';
		}
	}
}
function visi()
{
	if (document.all)
	{
		document.all['cartflota'].className = 'ocflota';
	}
	else if (document.getElementById)
	{
		document.getElementById('cartflota').className = 'ocflota';

	}
}
function compraCancelar(orden)
{
	if (confirm("¿Cancelar la orden de compra?")) {
		window.location.href = 'library/processCancelar.php?ordenId=' + orden;
	}
}
