function OpenPopupPanier()
{
  //document.getElementById("popup_panier").style.display = (document.getElementById("popup_panier").style.display == "none" ? "block" : "none");
}
function OpenPopupPanier2()
{
  //document.getElementById("popup_panier2").style.display = (document.getElementById("popup_panier2").style.display == "none" ? "block" : "none");
}
function ClosePopupPanier()
{
  //document.getElementById("popup_panier").style.display = "none";
}
function ClosePopupPanier2()
{
  //document.getElementById("popup_panier2").style.display = "none";
}
function OpenPopupErreur()
{
  //document.getElementById("popup_erreur").style.display = "block";
}
function ClosePopupErreur()
{
  document.getElementById("popup_erreur").style.display = "none";
}







function GetPanierCheck(nom)
{
  var s = '';
  var aItem = GetArray(nom);
  var aItem2 = GetArray(nom + "_check");
  for (var i=0; i<aItem.length;i++) {
    if (aItem2[i] == 1) s += (s == "" ? "|" : "") + aItem[i] + "|";
  }
  return(s);
}
function GetPanier(nom)
{
  var content = '';
  var deb,fin
  var deb = document.cookie.indexOf(nom + "=")
  if (deb >= 0) {
    deb += nom.length + 1
    fin = document.cookie.indexOf(";",deb)
    if (fin < 0) fin = document.cookie.length
    content = document.cookie.substring(deb,fin)
  }
  return(content);
}
function GetArray(nom)
{
  content = GetPanier(nom);
  var aItem = content.split("|");
  aItem.splice(0, 1);
  aItem.splice(aItem.length - 1, 1);
  return(aItem);
}

function AddMedia(nom, num)
{
  var expDate = new Date();
  expDate.setTime(expDate.getTime() + (360 * 24 * 3600 * 1000));
  
  var debut, fin;
  debut = document.cookie.indexOf(nom + "=")
  debut2 = document.cookie.indexOf(nom + "_check" + "=")
  if (debut >= 0) {
    content = GetPanier(nom);
    content2 = GetPanier(nom + "_check");
    if (content.indexOf(String("|" + num + "|")) == -1) {
      content += (content == "" ? "|" : "") + num + "|";
      content2 += (content2 == "" ? "|" : "") + "1|";
      document.cookie = nom + "=" + content + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()
      document.cookie = nom + "_check" + "=" + content2 + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()
    } else {
      OpenPopupErreur();
    }
  } else {
    document.cookie = nom + "=" + String("|" + num + "|") + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()
    document.cookie = nom + "_check" + "=" + String("|1|") + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()
  }

  ClosePopupPanier();
  ComptePanier(nom);
}
function Affiche(nom)
{
  content = GetPanier(nom);
  alert(content);
}

function ComptePanier(nom)
{
  var aItem = GetArray(nom);
  document.getElementById("panier_count").innerHTML = (lang == "fr" ? "Partage : " : "Sharing : ") + aItem.length;
}
function ComptePanier2(nom)
{
  var aItem = GetArray(nom);
  document.getElementById("panier_count2").innerHTML = aItem.length + (lang == "fr" ? " Film" : " Movie") + (aItem.length > 1 ? "s" : "");
}
function ComptePanier3(nom)
{
  var aItem = GetArray(nom);
  var nb2 = CountCheck(nom);
  document.getElementById("panier_count3").innerHTML = aItem.length + (lang == "fr" ? " Film" : " Movie") + (aItem.length > 1 ? "s" : "") + " - " + nb2 + (lang == "fr" ? " Film" : " Movie") + (nb2 > 1 ? "s" : "") + (lang == "fr" ? " coch&eacute;" : " checked") + (nb2 > 1 && lang == "fr" ? "s" : "");
  document.getElementById("panier_count_bis").innerHTML = "(" + aItem.length + ")";
}
function ComptePanier4(nom)
{
  var aItem = GetArray(nom + "_check");
  var nb = 0;
  for (var i=0; i<aItem.length;i++) {
    if (aItem[i] == 1) nb++;
  }
  document.getElementById("panier_count4").innerHTML = nb + (lang == "fr" ? " Film" : " Movie") + (nb > 1 ? "s" : "");
  //document.getElementById("panier_count5").innerHTML = nb + " Film" + (nb > 1 ? "s" : "");
}
function AffichePanier(nom, lang)
{
  var aItem = GetArray(nom);
  var aItem2 = GetArray(nom + "_check");

	container = document.getElementById("liste_panier");
	while(container.hasChildNodes()) container.removeChild(container.childNodes[0])

  aListeImg = new Array();
  for (i=aItem.length-1; i>=0; i--)
	{
    s = aItem[i];
    c = aItem2[i];

		new_element = document.createElement('li');
    //new_element.innerHTML = '<div><input type="checkbox" name="check_' + aItem[i] + '" id="check_' + aItem[i] + '" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a id="lien_' + aItem[i] + '" href="#" onMouseOver="SetImage(' + aItem[i] + ');"><span id="ti_' + aItem[i] + '"></span></a></div>';
    new_element.innerHTML = '<div class="fd"><a id="lien2_' + aItem[i] + '" href="#"><img class="img" src="" width="116" height="87" id="img_' + aItem[i] + '" /></a><div class="check"><input type="checkbox" name="check_' + aItem[i] + '" id="check_' + aItem[i] + '" /></div><div class="delete"><a href="#" onClick="Delete1(' + aItem[i] + ', \'' + nom + '\');"><img src="/v2/img/panier/close.gif" /></a></div><div class="t"><a id="lien_' + aItem[i] + '" href="#"><div class="txt1" id="txt1_' + aItem[i] + '">&nbsp;</div><div class="txt2" id="txt2_' + aItem[i] + '">&nbsp;</div></a></div></div>';
		new_element.setAttribute("id", "liste_panier_" + aItem[i]);
		new_element.setAttribute("class", "liste");
		container.insertBefore(new_element, container.firstChild);
		
		icbCBoxtoImgCB('check_' + aItem[i], (c == 1 ? true : false), '/v2/img/panier/checked.png', '/v2/img/panier/check.png', '36, 33');
		ajax_media(aItem[i], lang);
	}
	
	document.getElementById("liste_panier").style.width = (aItem.length * 124) + "px";
	CSBfleXcroll('mycustomscroll');
}
function ajax_media(mid, lang)
{
	var xhr = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
	xhr.onreadystatechange = function() { alert_ajax_media(xhr); };
	xhr.open("GET", "/v2/get_media_infos.php?lang=" + lang + "&id=" + mid, true);
	xhr.send(null);
}
function alert_ajax_media(xhr)
{
	var docXML = xhr.responseXML;
	var items = docXML.getElementsByTagName("xml_item");
	node = items.item(0);
	sReturn = node.attributes.getNamedItem("info").value + "[]" + node.childNodes[0].firstChild.nodeValue + "[]" + node.childNodes[1].firstChild.nodeValue;
	detail = sReturn.split("[]");
	document.getElementById("txt1_" + detail[4]).innerHTML = detail[9];
	document.getElementById("txt2_" + detail[4]).innerHTML = detail[8];
	document.getElementById("img_" + detail[4]).src = detail[6];
	document.getElementById("lien_" + detail[4]).href = document.getElementById("lien2_" + detail[4]).href = "/v2/films/v2view-" + detail[0] + "-" + detail[1] + "/" + detail[2] + "/" + detail[3] + "-" + detail[4] + "-" + detail[5] + ".html";
	aListeImg.push(new Array(detail[4], detail[6]));
}
function SetImage(my_id)
{
  for (var i=0; i<aListeImg.length; i++)
  {
    if (aListeImg[i][0] == my_id) document.getElementById('img_over').src = aListeImg[i][1];
  }
}

function VisitePanier(content)
{
  aItem = content.split("|");
  aItem.splice(0, 1);
  aItem.splice(aItem.length - 1, 1);

  document.getElementById("panier_count").innerHTML = aItem.length;

	container = document.getElementById("liste_panier");
	while(container.hasChildNodes()) container.removeChild(container.childNodes[0])

	for (i=aItem.length-1; i>=0; i--)
	{
    s = aItem[i];

		new_element = document.createElement('li');
    new_element.innerHTML = '<div>' + s + '</div>';
		new_element.setAttribute("id", "liste_panier_" + aItem[i]);
		new_element.setAttribute("class", "liste");
		container.insertBefore(new_element, container.firstChild);
	}
}

function CheckAll(nom)
{
	var aItem = GetArray(nom);
  var content2 = '';
  for (var i=0; i<aItem.length; i++) {
		c = document.getElementById("check_" + aItem[i]);
		c.checked = true;
		icbImgUpdate(document.getElementById("icbcheck_" + aItem[i]));
		
		content2 += (content2 == "" ? "|" : "") + "1|";
	}
	
  var expDate = new Date();
  expDate.setTime(expDate.getTime() + (360 * 24 * 3600 * 1000));
  document.cookie = nom + "_check" + "=" + content2 + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()
	
	ComptePanier3(nom);
}
function UncheckAll(nom)
{
	var aItem = GetArray(nom);
  var content2 = '';
  for (var i=0; i<aItem.length; i++) {
		c = document.getElementById("check_" + aItem[i]);
		c.checked = false;
		icbImgUpdate(document.getElementById("icbcheck_" + aItem[i]));
		
		content2 += (content2 == "" ? "|" : "") + "0|";
	}
	
  var expDate = new Date();
  expDate.setTime(expDate.getTime() + (360 * 24 * 3600 * 1000));
  document.cookie = nom + "_check" + "=" + content2 + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()
	
	ComptePanier3(nom);
}
function InverseCheck(nom)
{
	var aItem = GetArray(nom);
  var content2 = '';
  for (var i=0; i<aItem.length; i++) {
		c = document.getElementById("check_" + aItem[i]);
		current = c.checked;
		c.checked = (current ? false : true);
		icbImgUpdate(document.getElementById("icbcheck_" + aItem[i]));
		
		content2 += (content2 == "" ? "|" : "") + (current ? '0' : '1') + "|";
	}
	
  var expDate = new Date();
  expDate.setTime(expDate.getTime() + (360 * 24 * 3600 * 1000));
  document.cookie = nom + "_check" + "=" + content2 + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()
	
	ComptePanier3(nom);
}
function CountCheck(nom)
{
  var aItem = GetArray(nom);
  
  var nb = 0;
	for (var i=0; i<aItem.length; i++) {
		c = document.getElementById("check_" + aItem[i]);
		if (c.checked) nb++;
	}
	return(nb);
}
function UpdatePanier3(nom)
{
	var aItem = GetArray(nom);
  var content2 = '';
  for (var i=0; i<aItem.length; i++) {
		c = document.getElementById("check_" + aItem[i]);
		current = c.checked;
		content2 += (content2 == "" ? "|" : "") + (!current ? '0' : '1') + "|";
	}

  var expDate = new Date();
  expDate.setTime(expDate.getTime() + (360 * 24 * 3600 * 1000));
  document.cookie = nom + "_check" + "=" + content2 + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()
  
  ComptePanier3(nom);
}
function Efface(nom)
{
  if (confirm((lang == "fr" ? "Confirmer ?" : "Confirm ?")))
  {
    var aItem = GetArray(nom);
    var content = content2 = '';
  	for (var i=0; i<aItem.length; i++) {
  		c = document.getElementById("check_" + aItem[i]);
  		if (!c.checked) {
        content += (content == "" ? "|" : "") + aItem[i] + "|";
  		  content2 += (content2 == "" ? "|" : "") + "1|";
 		  }
  	}

    var expDate = new Date();
    expDate.setTime(expDate.getTime() + (360 * 24 * 3600 * 1000));
    document.cookie = nom + "=" + content + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()
    document.cookie = nom + "_check" + "=" + content2 + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()

    AffichePanier(nom);
    ComptePanier3(nom);
  }
}
function Delete1(id, nom)
{
  if (confirm((lang == "fr" ? "Confirmer ?" : "Confirm ?")))
  {
    var aItem = GetArray(nom);
    var aItem2 = GetArray(nom+"_check");
    var content = content2 = '';
  	for (var i=0; i<aItem.length; i++) {
  		if (aItem[i] != id) {
        content += (content == "" ? "|" : "") + aItem[i] + "|";
  		  content2 += (content2 == "" ? "|" : "") + aItem2[i] + "|";
 		  }
  	}

    var expDate = new Date();
    expDate.setTime(expDate.getTime() + (360 * 24 * 3600 * 1000));
    document.cookie = nom + "=" + content + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()
    document.cookie = nom + "_check" + "=" + content2 + ";path=/v2/;domain=wizz.fr;expires=" + expDate.toGMTString()

    AffichePanier(nom);
    ComptePanier3(nom);
  }
}



function GeneratePanier(sPanier)
{
  var aItem = sPanier.split('|');

	container = document.getElementById("liste_panier");
	while(container.hasChildNodes()) container.removeChild(container.childNodes[0])

	for (i=aItem.length-1; i>=0; i--)
	{
    s = aItem[i];
    detail = s.split('[]');
    url = "/v2/films/v2view2-" + detail[0] + "-" + detail[1] + "/" + detail[2] + "/" + detail[3] + "-" + detail[4] + "-" + detail[5] + ".html";

		new_element = document.createElement('li');
    //new_element.innerHTML = '<div><img src="' + detail[7] + '" style="position:absolute;visibility:hidden;"><a href="' + url + '" onMouseOver="document.getElementById(\'img_over\').src = \'' + detail[7] + '\';">' + detail[6] + '</a></div>';
    new_element.innerHTML = '<a href="' + url + '"><div class="fd"><img class="img" src="' + detail[7] + '" width="116" height="87" /><div class="txt1">' + detail[6] + '</div><div class="txt2">' + detail[8] + '</div></div></a>';
		new_element.setAttribute("class", "liste");
		container.insertBefore(new_element, container.firstChild);
	}
	
	CSBfleXcroll('mycustomscroll');
}










function AffichePanierSelect(nom, lang, id)
{
  var aItem = GetArray(nom);

	container = document.getElementById("film_listing");
	while(container.hasChildNodes()) container.removeChild(container.childNodes[0])

  for (i=aItem.length-1; i>=0; i--)
	{
    s = aItem[i];

		new_element = document.createElement('option');
		container.appendChild(new_element);
		new_element.setAttribute("id", "film_listing_" + s);
		//new_element.setAttribute("value", s);
		if (id == s) new_element.setAttribute("selected", true);
		ajax_media_select(aItem[i], lang);
	}
}
function ajax_media_select(mid, lang)
{
	var xhr = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
	xhr.onreadystatechange = function() { alert_ajax_media_select(xhr); };
	xhr.open("GET", "/v2/get_media_infos.php?lang=" + lang + "&id=" + mid, true);
	xhr.send(null);
}
function alert_ajax_media_select(xhr)
{
	var docXML = xhr.responseXML;
	var items = docXML.getElementsByTagName("xml_item");
	node = items.item(0);
	sReturn = node.attributes.getNamedItem("info").value + "[]" + node.childNodes[0].firstChild.nodeValue + "[]" + node.childNodes[1].firstChild.nodeValue;
	detail = sReturn.split("[]");
	document.getElementById("film_listing_" + detail[4]).text = detail[9] + " - " + detail[8];
	document.getElementById("film_listing_" + detail[4]).value = "/v2/films/v2view3-" + detail[0] + "-" + detail[1] + "/" + detail[2] + "/" + detail[3] + "-" + detail[4] + "-" + detail[5] + ".html";
}

function reload_url_select()
{
  u = document.getElementById("film_listing").value;
  document.location.href = u;
}