/* F6.UI.ShopListControl class
 * Use to control the shop list behavior in CourseExpress_Step1 page.
 * In order to use it, let's define the init state F6.UI.ShopListControl.init with 2 params: control (the id or class of list control), displayList (the id or class of the display list). 
  Then let's define F6.UI.ShopListControl.addListItem(this); on all checkbox element to enable add item to the display list when click on checkbox
  Define F6.UI.ShopListControl.addListItem2(this); on OK button to enable add item to the display list when type in textbox and click ok
  Define F6.UI.ShopListControl.removeAll() on the button to remove all element in the display list.
 */
 $j=jQuery.noConflict();
 F6.UI.ShopListControl = {};
	 F6.UI.ShopListControl.checkboxItem = null;
	 F6.UI.ShopListControl.config = null;
	/* methods */
		/* SPECIFIQUE ATOS */
	F6.UI.ShopListControl.showError = function() {
	$j(".HighLightBox > .error").show();
	}
	/* FIN SPECIFIQUE ATOS */
		/* init state for shop list */
		F6.UI.ShopListControl.init = function(configObj) {
			config = configObj;
			checkboxItem = $j(config.control).find("input[type='checkbox']");
			checkboxItem.each(function() {
				if ($j(this).attr("checked")==true) {
					var val = $j(this).parent().find("label").text();
					$j(config.displayList).append("<p><a href=\"#\" title=\""+val+"\">"+ val + "</a><a href=\"#\" class=\"DeleteBtn\" title=\"Supprimer\" onclick=\"F6.UI.ShopListControl.removeListItem(this)\">Supprimer</a></p>");
				}
			});
			$j(config.displayList).jScrollPane();
		}
		/* add more item using checkbox */
		F6.UI.ShopListControl.addListItem = function(o) {
			if ($j(o).attr("checked")==true) {
				var val = $j(o).parent().find("label").text();
				if ($j(config.displayList).children().html()!=null) {
					$j(config.displayList).children().eq(0).before("<p><a href=\"#\" title=\""+val+"\">"+ val + "</a><a href=\"#\" class=\"DeleteBtn\" title=\"Supprimer\" onclick=\"F6.UI.ShopListControl.removeListItem(this);return false;\">Supprimer</a></p>");
				}
				else {
					$j(config.displayList).append("<p><a href=\"#\" title=\""+val+"\">"+ val + "</a><a href=\"#\" class=\"DeleteBtn\" title=\"Supprimer\" onclick=\"F6.UI.ShopListControl.removeListItem(this);return false;\">Supprimer</a></p>");
				}
				/* SPECIFIQUE ATOS */
				$j("#articleList")[0].value=$j("#articleList")[0].value+"/"+val;
				/* FIN SPECIFIQUE ATOS */
			}
			else {
				var val = $j(o).parent().find("label").text();
				$j(config.displayList).find("a").each(function() {
					if ($j(this).text()==val) {
						$j(this).parent().remove();
					}
				});
				/* SPECIFIQUE ATOS */
				$j("#articleList")[0].value=$j("#articleList")[0].value.replace("/"+val,"");
				/* FIN SPECIFIQUE ATOS */
			}
			$j(config.displayList).jScrollPane();
		}
		/* add more item using textbox */
		F6.UI.ShopListControl.addListItem2 = function(o, event) {
			var e = event ? event : window.event;
			try {
				e.stopPropagation();
			}
			catch (exp) {
				e.cancelBubble = true;
			}
			var val = $j(o).parent().find(".InputText").attr("value");
			$j(o).parent().find(".InputText").attr("value","Nom de produit, marque, ...");
			$j(o).parent().find(".InputText").css("color","#666");
			$j(o).parent().find(".InputText").css("font-style","italic");
			var check = false;
			if (val != "Nom de produit, marque, ..." && val !="") {
				if (val.length <=2) {
					$j(".HighLightBox > .error02").show();
				}
				else {
					$j(config.control).find("label").each(function() {
						if ($j(this).text()==val) {
							check = true;
							if ($j(this).parent().find("input[type='checkbox']").attr("checked")==false) {
								$j(this).parent().find("input[type='checkbox']").attr("checked","checked");
								if ($j(config.displayList).children().html()!=null) {
									$j(config.displayList).children().eq(0).before("<p><a href=\"#\" title=\""+val+"\">"+ val + "</a><a href=\"#\" class=\"DeleteBtn\" title=\"Supprimer\" onclick=\"F6.UI.ShopListControl.removeListItem(this);return false;\">Supprimer</a></p>");
								}
								else {
									$j(config.displayList).append("<p><a href=\"#\" title=\""+val+"\">"+ val + "</a><a href=\"#\" class=\"DeleteBtn\" title=\"Supprimer\" onclick=\"F6.UI.ShopListControl.removeListItem(this);return false;\">Supprimer</a></p>");
								}
							}
						}
					});
					$j(config.displayList).find("a").each(function() {
						if ($j(this).html()==val) {
							check = true;
						}
					});
					if (check == false) {
						if ($j(config.displayList).children().html()!=null) {
							$j(config.displayList).children().eq(0).before("<p><a href=\"#\" title=\""+val+"\">"+ val + "</a><a href=\"#\" class=\"DeleteBtn\" title=\"Supprimer\" onclick=\"F6.UI.ShopListControl.removeListItem(this);return false;\">Supprimer</button></a>");
						}
						else {
							$j(config.displayList).append("<p><a href=\"#\" title=\""+val+"\">"+ val + "</a><a href=\"#\"  class=\"DeleteBtn\" title=\"Supprimer\" onclick=\"F6.UI.ShopListControl.removeListItem(this);return false;\">Supprimer</a></p>");
						}
					}
					$j(config.displayList).jScrollPane();
					/* SPECIFIQUE ATOS */
					$j("#articleList")[0].value=$j("#articleList")[0].value+"/"+val;
					/* FIN SPECIFIQUE ATOS */
					return false;
				}
			}
			else {
				if ($j(".HighLightBox > .error01").length > 0) {
					$j(".HighLightBox > .error01").show();
				}
			}

			
		}
		/* remove one item */
      	F6.UI.ShopListControl.removeListItem = function(o) {
			var val2= $j(o).parent().find("a").eq(0).text();
			/* SPECIFIQUE ATOS */
			$j("#articleList")[0].value=$j("#articleList")[0].value.replace("/"+val2,"");
			/* FIN SPECIFIQUE ATOS */
			
			$j(o).parent().remove();
			$j(config.displayList).jScrollPane();
			var activeCheckbox =  $j(config.control).find("input[type='checkbox'][checked='true']");
			for (var i = 0; i < activeCheckbox.length; i++) {
				if (activeCheckbox.eq(i).parent().find("label").text() == val2) {
					activeCheckbox.eq(i).removeAttr("checked");
				}
			}
		}
		/* remove all item */
		F6.UI.ShopListControl.removeAll = function(o) {
			$j(config.displayList).children().remove();	
			$j(config.control).find("input[type='checkbox'][checked='true']").removeAttr("checked");
			$j(config.displayList).jScrollPane();
			/* SPECIFIQUE ATOS */
			$j("#articleList")[0].value="";
			/* FIN SPECIFIQUE ATOS */
		}
    /* End. methods */
