function	autoUrl(name, dest)
{
	var loc;
	var id_list;

	id_list = document.getElementById(name);
	loc = id_list.options[id_list.selectedIndex].value;
	if (loc != 0)
		location.href = dest+loc;
	return ;
}

function	autoUrlNoList(name, dest)
{
	var loc;

	loc = document.getElementById(name).checked;
	location.href = dest + (loc == true ? 1 : 0);
	return ;
}

/*
** show or hide element e depending on condition show
*/
function toggle(e, show)
{
	e.style.display = show ? '' : 'none';
}

function toggleMultiple(tab)
{
    var len = tab.length;

    for (var i = 0; i < len; i++)
        if (tab[i].style)
            toggle(tab[i], tab[i].style.display == 'none');
}

/**
* Show dynamicaly an element by changing the sytle "display" property
* depending on the option selected in a select.
*
* @param string $select_id id of the select who controls the display
* @param string $elem_id prefix id of the elements controlled by the select
*   the real id must be : 'elem_id'+nb with nb the corresponding number in the
*   select (starting with 0).
*/
function showElemFromSelect(select_id, elem_id)
{
	var select = document.getElementById(select_id);
	for (var i = 0; i < select.length; ++i)
	{
	    var elem = document.getElementById(elem_id + select.options[i].value);
		if (elem != null)
			toggle(elem, i == select.selectedIndex);
	}
}

/**
* Get all div with specified name and for each one (by id), toggle their visibility
*/
function openCloseAllDiv(name, option)
{
	var tab = $('*[name='+name+']');
	for (var i = 0; i < tab.length; ++i)
		toggle(tab[i], option);
}

/**
* Toggle the value of the element id_button between text1 and text2
*/
function toggleElemValue(id_button, text1, text2)
{
	var obj = document.getElementById(id_button);
	if (obj)
		obj.value = ((!obj.value || obj.value == text2) ? text1 : text2);
}

function addBookmark(url, title)
{
	if (window.sidebar)
		return window.sidebar.addPanel(title, url, "");
	else if ( window.external )
		return window.external.AddFavorite( url, title);
	else if (window.opera && window.print)
		return true;
	return true;
}

function writeBookmarkLink(url, title, text, img)
{
	var insert = '';
	if (img)
		insert = writeBookmarkLinkObject(url, title, '<img src="' + img + '" alt="' + escape(text) + '" title="' + escape(text) + '" />') + '&nbsp';
	insert += writeBookmarkLinkObject(url, title, text);
	document.write(insert);
}

function writeBookmarkLinkObject(url, title, insert)
{
	if (window.sidebar || window.external)
		return ('<a href="javascript:addBookmark(\'' + escape(url) + '\', \'' + escape(title) + '\')">' + insert + '</a>');
	else if (window.opera && window.print)
		return ('<a rel="sidebar" href="' + escape(url) + '" title="' + escape(title) + '">' + insert + '</a>');
	return ('');
}

function checkCustomizations()
{
	for (var i = 0; i < customizationFields.length; i++)
		/* If the field is required and empty then we abort */
		if (parseInt(customizationFields[i][1]) == 1 && $('#' + customizationFields[i][0]).val() == '')
			return false;
	return true;
}


function div_over_ie(el){
	//alert(el.className);
	//if (document.all&&document.getElementById) {
		el.className=" over";
		alert(el.className);
	//}
}

function div_out_ie(el){
	if (document.all&&document.getElementById) {
		el.className="";
	}	
}

function pintar_carrito(elemento){
	 	elemento.style.color="#FFFFFF";
	 	elemento.style.backgroundColor ="#97172E";
	 	elemento.style.backgroundImage='url(themes/prestashop/img/icon/cart_01.gif)';
	// 	alert(elemento.className);
	 	//alert(elemento.style.backgroundColor);	
}

function nopintar_carrito(elemento){
	 	elemento.style.color="#5d717e";
	 	elemento.style.backgroundColor ="#E0E2DD";
	 	elemento.style.backgroundImage ='url(themes/prestashop/img/icon/cart.gif)';
}

function ver_carrito_emergente(){
	document.getElementById('div_carrito').style.display = "block"; 
}

function nover_carrito_emergente(){
	document.getElementById('div_carrito').style.display = "none"; 
}

function campos_empresa(){
 	document.getElementById('customer_firstname').innerHTML = "Compa&ntilde;ia";
	document.getElementById('div_empresa').style.display = "";
	document.getElementById('apellido_principal').style.display = "none";
	document.getElementById('meter_campo').innerHTML = "<input type='hidden' id='customer_lastname' name='customer_lastname' value=' '";
	//document.getElementById('desaparecer_1').style.display = "none";
	document.getElementById('desaparecer_2').style.display = "none";
	document.getElementById('firstname').innerHTML = "Compa&ntilde;ia";
	document.getElementById('lastname').value = " ";
}

function no_ver_campos_empresa(){
 	document.getElementById('customer_firstname').innerHTML = "Nombre";
	document.getElementById('div_empresa').style.display = "none";
	document.getElementById('apellido_principal').style.display = "";
	document.getElementById('meter_campo').innerHTML = "";
	//document.getElementById('desaparecer_1').style.display = "";
	document.getElementById('desaparecer_2').style.display = "";
	document.getElementById('lastname').value = "";
	document.getElementById('firstname').innerHTML = "Nombre";
}

function handleHttpResponse6() {
	if (http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1) {
			var response = http.responseXML;
			document.getElementById('price_add').value = response.getElementsByTagName('data').item(0).firstChild.data;
			document.getElementById('price_add_hid').value = response.getElementsByTagName('data').item(0).firstChild.data;
			document.getElementById('price_add_brut').value = response.getElementsByTagName('data').item(0).firstChild.data;
			document.getElementById('reference_add').value = response.getElementsByTagName('reference').item(0).firstChild.data;
			document.getElementById('ean13_add').value = response.getElementsByTagName('ean13').item(0).firstChild.data;
			if (response.getElementsByTagName('attribute').item(0) === null){
			}else{
				document.getElementById('attribute_add').value = response.getElementsByTagName('attribute').item(0).firstChild.data;
				document.getElementById('attribute_add').value = document.getElementById('attribute_add').value + "~" + response.getElementsByTagName('attributename').item(0).firstChild.data;
			}
			isWorking = false;
		}
	}
}

var isWorking = false;
function price_calcule(product, privilege){
 	http = new XMLHttpRequest();
	if (!product){
		alert("Ha ocurrido un error interno, consulte con el administrador de la tienda");
		return false;
	}
	if (!privilege){
		privilege = 1;
	}
	var url = "../js/ajax/calcule_price.php?product="+product+"&privilege="+privilege;
	http.open("GET", url, true);
	http.onreadystatechange = handleHttpResponse6;
	isWorking = true;
	http.send(null);
}

function qty_price_calculate(qty){
 	if (form_input_is_numeric(qty)){
		price = document.getElementById('price_add_hid').value;
		total_price = price * qty;
		total_price = total_price.toFixed(2)
		document.getElementById('price_add').value = total_price;
		document.getElementById('price_add_brut').value = total_price;
	}
}

function form_input_is_numeric(input){
    return !isNaN(input);
  }

