/**
 * @encoding UTF-8
 */

/**
 * 
 * @param {Object} myElementId
 * @param {Object} myOptionValue
 */
function autoSelect(myElementId, myOptionValue) {
  myElement = document.getElementById(myElementId);
  myOptions = myElement.options;
  n = myOptions.length;
  for (i = 0; i < n; i++) {
    if (myOptions[i].value == myOptionValue) {
      myElement.selectedIndex = i;
      break;
    }
  }
}

/**
 * 
 */
function unFrame() {
  if (window!=top) { top.location=window.location; }
}

/**
 * 
 */
function doTheCookieStuff() {
  sp = getCookie('selected_panel');
  if (sp != null) {
    p.show(sp, document.getElementById(sp + '_cursor'));
  }
}

/**
 * 
 * @param {Object} ElementID
 * @param {Object} Path
 */
function setLoadingDiv(ElementID, Path, Message) 
{
	if(arguments.length <= 1 || arguments[1].length < 1)
	{
		Path = '../..';
	}
	if(arguments.length <= 2 || arguments[2].length < 1)
	{
		Message = '';
	}
	$(ElementID).innerHTML = '<img src="' + Path + '/shop/images/ajax_loading.gif" /> '+ Message;
}

/**
 * 
 * @param {Object} ElementID
 */
function unsetLoadingDiv(ElementID) 
{
  $(ElementID).innerHTML = '';
}

/**
 * 
 * @param {Object} ProductID
 * @param {Object} quantityToAdd
 * @param {Object} maxQuantity
 */
function setQuantity(inputID, quantityToAdd, maxQuantity)
{
	var currentQuantity = parseInt($F(inputID));
	var futureQuantity  = currentQuantity + parseInt(quantityToAdd);
	
	if (futureQuantity < 0)
	{
		alert('Vous ne pouvez pas disposer d\'un produit en quantité négative !');
	}
	else
	{
		$(inputID).value = futureQuantity;
	}
	
	var name = "quantity"; 
	var id = inputID.substring(name.length, inputID.length);
	
	if (id != "")
	{
		calculTotalPanier(id);
	}
}

function calculTotalPanier(id)
{
	
}

function emptyCart()
{
	if (confirm('Voulez-vous vraiment vider votre panier ?'))
	{
		var xmlHttp = new Ajax.Request('../../../shop/ajax/emptyShoppingCart.php',
									{
										asynchronous: false
									});
		
		if (xmlHttp.transport.responseText == '1')
		{			
			window.location.reload();
		}
	}
}

/**
 * 
 * @param {Object} id
 */
function openClose(id)
{
	var o = document.getElementById(id);
	if(o)
	{
		if(o.style.display == 'none')
		{
			o.style.display = 'block';
		}
		else
		{
			o.style.display = 'none';
		}
	}
}

function openClose2(id)
{
	var o = document.getElementById(id);
	if(o)
	{
		if(o.style.display == 'block')
		{
			o.style.display = 'none';
		}
		else
		{
			o.style.display = 'none';
		}
	}
}


function showBubble(e){
	if (document.all) {
		e = event;
	}
	var obj  = document.getElementById('bubble');
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if (navigator.userAgent.toLowerCase().indexOf('safari')>=0) {
		st = 0; 
	}
	var leftPos = e.clientX - 190;
	if (leftPos<0) {
		leftPos = 0;
	}
	obj.style.left = leftPos + 'px';
	obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';
}	
	
function hideBubble() {
	document.getElementById('bubble').style.display = 'none';
}


function attrSelect(Main, Sub)
{		
	new Ajax.Request('../../../ajax/attrSelect.php', {
		method: 'post', 
		parameters: 'main=' + Main  +'&sub='+ Sub,
		onComplete: function(t) {
			eval(t.responseText);
		},
		evalScripts: true
	});
}
	
function addAttr(selectName, Ovalue, Otext, Otitle, Oclass, Oselection)
{
	var oOption = document.createElement("option");
	oOption.text= Otext;
	oOption.title = Otitle;
	oOption.value = Ovalue;
	oOption.className = Oclass;
	oOption.label = Otext;
	if(Oselection == 1)
	{
		oOption.selected = true;
	}
	$(selectName).appendChild(oOption);	
}

function setAttrStock(Stock)
{
	$("stock_level").src = "/images/icons/stock_vert_level_"+ Stock +".gif";
}

/*
 * Gestion du player MP3
 */
var statut_player = '';

function player_play(rootpath)
{
	var dewp = $('player');
	
	if (dewp != null)
	{
		dewp.dewplay();
		$('img_global_sound').src = rootpath + '/templates/fichiers/images/rysons/sound_on.png';
		$('link_global_sound').href = 'javascript:player_stop(rootpath);';
		statut_player = 'play';
	}
}

function player_replay(rootpath)
{
	if (statut_player == 'pause')
	{
		player_play(rootpath);
	}
}

function player_stop(rootpath)
{
	var dewp = $('player');
	
	if (dewp != null)
	{
		dewp.dewstop();
		$('img_global_sound').src = rootpath + '/templates/fichiers/images/rysons/sound_off.png';
		$('link_global_sound').href = 'javascript:player_play(rootpath);';
		statut_player = 'stop';
	}
}

function player_pause(rootpath)
{
	var dewp = $('player');
	
	if (dewp != null && statut_player == 'play')
	{
		dewp.dewpause();
		$('img_global_sound').src = rootpath + '/templates/fichiers/images/rysons/sound_off.png';
		$('link_global_sound').href = 'javascript:player_play(rootpath);';
		statut_player = 'pause';
	}
}