var SEPARADOR = "@EULAS@";
var COOKIE_NAME = "MPTOURS_CART";
var productos = "";

function clearCart() {
	var str = "/web/cart.php?";
	var arr_prds = productos.split(SEPARADOR);

	for (var i=0; i<arr_prds.length; i++) {
		str += "&remove_id[]=" + arr_prds[i];
	}

	document.location = str;
}

function addProduct(id) {
	if (!existe(id)) {
		if (productos == "")	productos = id;
		else					productos += SEPARADOR + id;
	}
}

function existe(id) {
	var rV = (productos == id);
	rV = rV || (productos.indexOf(id + SEPARADOR) > -1);
	rV = rV || (productos.indexOf(SEPARADOR + id) > -1);

	return rV;
}

function removeProduct(id) {
	var arr_prds = productos.split(SEPARADOR);

	new_prods = "";
	for (i=0; i<arr_prds.length; i++) {
		if (arr_prds[i] != id) {
			new_prods += ((new_prods=="")?"":SEPARADOR) + arr_prds[i];
		}
	}

	productos = new_prods;
}

var removed = new Array();
function check(id, i) {
	if (existe(id)) {
		removeProduct(id);
		removed.push(id);
		
		document.getElementById("check_" + i).className = "TextImage Mark";
	} else {
		addProduct(id);

		var _newremoved = new Array();
		for (var j=0; j<removed.length; j++) {
			if (removed[j] != id) _newremoved.push(removed[j]);
		}
		removed = _newremoved;

		document.getElementById("check_" + i).className = "TextImage UnMark";
	}
}

function updateProduct(id, oid)
{
	var obj = document.getElementById("Language_" + oid);

	if (obj) {
		removeProduct(id);
		removed.push(id);
		update("id=" + obj.value);
	}
}

function update(pref) {
	pref = pref ? pref : "";
	var _to = document.location.href.indexOf("?") == -1 ? document.location.href.length : document.location.href.indexOf("?");
	var str = document.location.href.substr(0, _to) + "?" + pref;
	for (var i=0; i<removed.length; i++) {
		str += "&remove_id[]=" + removed[i];
	}

	if (document.getElementById('pay_form')) {
		document.getElementById('pay_form').action = str;
		document.getElementById('pay_form').submit();
	} else {
		document.location = str;
	}
}

function disclaimer() {
	_new("/web/disclaimer.pop.php", "disclaimer", 610, 330);
}

function _new(url, name, w, h) {
	var _option;
	_option = "fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,";	
	_option += "width=" + w + ",height=" + h;
	
	var _window = window.open(url, name, _option);
	return _window;
}

function filterCities(where, id){
    if(id=="EMPTY"){
        $('#ToursList').hide();
        return true
    }else{
        $('#ToursList').show();
       
        $(".C_item_").each(
            function(){
                if($(this).hasClass("C_" + id + "_"))   $(this).show();
                else                                    $(this).hide();
            }
        );
    }
}
