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

}

/*
	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);
	
	var _isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

var step=2;
//var stepanterior = 1;
function slideit(CantidaddeImagenes){
//if browser does not support the image object, exit.
if (!document.images)
return
if (step <= CantidaddeImagenes) document.images.slide.src=eval("image"+step+".src");

if (step < CantidaddeImagenes) {
step++;
} else {
step=1
}
}

//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 submitBuscAdv (linksamigables) {
	var theForm = document.getElementById('frmbuscadv');
	var query = document.getElementById('queryadv');
  if (linksamigables) theForm.action = theForm.action + query.value;
  else theForm.action = theForm.action + "&query=" + query.value;
  theForm.submit(theForm);
  return false;
}
function getCiudadesbusc (ruta,idioma) {
	var http = getXmlHttpObject(); 
	var banner = Array('','Cargando','Loading');
	var region = document.getElementById('region_busc').value;
	var ciudad = document.getElementById('ciudad_hidden').value;
	http.open("GET", ruta + "inc_cambiaciudad.php?region=" + region + "&ciudad=" + ciudad, true);
	http.onreadystatechange = function () {
		if (http.readyState == 1) {
			document.getElementById("cambiaciudad").innerHTML = "<div id=\"mensaje\">"+banner[idioma]+"...</div>";
		}
		if (http.readyState == 4) {
			document.getElementById("cambiaciudad").innerHTML = http.responseText;
		}
	};
	http.send(null);
}

//check mail para alta en mailing promo
function checkmailpromo(campo,idioma) {
	var textos = Array(0,'El e-mail ingresado no es válido. Intenta nuevamente');
	var campomail = document.getElementById(campo);
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!filter.test(campomail.value)) {
		alert(textos[idioma]);
		campomail.focus();
		return false;
	}
	return true;
}



String.prototype.replaceAll = function(pcFrom, pcTo){
	var i = this.indexOf(pcFrom);
  var c = this;
  while (i > -1){
		c = c.replace(pcFrom, pcTo);
		i = c.indexOf(pcFrom);
	}
  return c;
}

