maxNest = 1;

function setVisibility(id, visible) {
	$(id).style.visibility = (visible ? 'visible' : 'hidden');
	$(id).style.display = (visible ? 'block' : 'none');
}

function setFade(id, fade_in, block) {
	if (fade_in)
		$(id).setStyles({display: ((block == null || block == true) ? 'block' : 'inline'), opacity: 0}).set('tween', {duration: 250}).fade('in');
	else
		$(id).setStyles({display: 'none'});
	return $(id);
}

function ajax(url) {
	var xhr_object = null;
	if (window.XMLHttpRequest) var xhr_object = new XMLHttpRequest();
	else if (window.ActiveXObject) var xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	xhr_object.open("GET", url, false);   
	xhr_object.send(null);
	return xhr_object;
}
function getCodeCat() {
	for (k = maxNest; k >= 0; k--) {
		ddk = $("theme" + k).value;
		if (ddk != "-") {
			return ddk;
		}
	}
	return 0;
}
function dropDownChange(i, code_mother) {
	if (code_mother != "-") {
		xhr_object = ajax(BasePath + "/shop/rt_gettheme.php?code_mother="+code_mother);
		if (xhr_object.readyState == 4 && xhr_object.responseText != "-") {
			themesArray = new Array();
			themesArray = xhr_object.responseText.split('@');
			dropdown_below = $("theme" + i);
			clearDropDown(dropdown_below);
			for(j = 0; j < themesArray.length; j++) {
				themeArray = new Array();
				themeArray = themesArray[j].split('#');
	 			dropdown_below.options[j+1] = new Option(themeArray[1], themeArray[0], false, false);
			}
			if (themesArray.length) {
				setFade("theme" + i, true);
				setFade("theme" + i + "Div", true);
			}
		}
		else clearAndHideDrowDown("theme" + i);
		for (k = i+1; k <= maxNest; k++) clearAndHideDrowDown("theme" + k);
	}
	else for (k = i; k <= maxNest; k++) clearAndHideDrowDown("theme" + k);
}
function clearDropDown(dropdownId) {
	for(j = 1; j < dropdownId.options.length; j++) dropdownId.options[j] = null;
	dropdownId.options.length = 1;
	dropdownId.selectedIndex = 0;
}
function clearAndHideDrowDown(dropdownId) {
	clearDropDown($(dropdownId));
	setFade(dropdownId, false);
	setFade(dropdownId + "Div", false);
}

function basketBlink() { alert("L'élément a bien été ajouté à votre panier"); }

function addToBasket(code_product, quantity) {
	if (quantity == null) quantity = $("nb_" + code_type).value;
	$('NbInBasket').load(BasePath + "/shop/rt_basket_add.php?code_product=" + code_product + "&quantity=" + quantity);
	// if (type == 'SUBSCRIBE') location.href = BasePath + '/shop/basket.php';
	basketBlink();
}

function alertFctn(msg, elmtId) {
	/*
	myStickyWin = new StickyWin({
		content: '<div class="closeSticky">' + msg + '</div>',
		relativeTo: $(elmtId+'Input'),
		position: 'bottomLeft'
	});
	setTimeout(myStickyWin.hide, 2500);
	*/
	alert(msg);
	
	highlightField(elmtId);
}

function highlightField(fieldName) {
	$(fieldName).set('morph', {duration: 500}).morph({
		color: ['#ffffff', '#000000'],
		backgroundColor: ['#cb0427', '#ffffff']
	});
	
	return $(fieldName);
}

