function load_order_status(order_id)
{
	displayWait("");
	var _url	= "/services/check-order-status";
	var _params	= "order_id=" + order_id;
	
	dojo.xhrPost( 
    {
       url: _url+"?"+_params, 
       handleAs: "text",
       timeout: 5000,
       load: function(response, ioArgs) 
       { 
    	 if(response == '-1')
    	 {
    		 hideWait();
    		 dijit.byId("information").attr('content',"une erreur s'est produite");
    		 dijit.byId("information").startup();
    		 dijit.byId("information").show();
    	 }
    	 else if (response == '2') {
    		 dijit.byId("information").attr('content',"Votre commande numéro : "+ order_id +" est bien validée");
    		 dijit.byId("information").startup();
    		 dijit.byId("information").show();
    		 hideWait();
		 }
       },
       error: function(response, ioArgs) 
       { 
         console.error("HTTP status code: ", ioArgs.xhr.status);
         return response; 
       }
    });
}


function updateShippingData(country)
{
	generateShippingOptions(country, weight);
}

function delete_promo()
{
	var _url	= "/services/delete-promo";
	var _params	= "";
	
	dojo.xhrPost( 
    {
       url: _url+"?"+_params, 
       handleAs: "text",
       timeout: 5000,
       load: function(response, ioArgs) 
       { 
    	 
       },
       error: function(response, ioArgs) 
       { 
         console.error("HTTP status code: ", ioArgs.xhr.status);
         return response; 
       }
    });
	generateBasket();
}

function updateBasketLine(product_id, size, quantity)
{
	if(quantity == 0)
	{
		//deleteProduct(product_id);
		var _url	= "/services/delete-from-cart";
		var _params	= "product_id=" + product_id + "&quantity="+quantity + "&size=" + size ;
	}
	else
	{
		var _url	= "/services/modify-product-quantity";
		var _params = "product_id=" + product_id + "&quantity="+quantity + "&size=" + size ;
	}
	
	dojo.xhrPost( 
    {
       url: _url+"?"+_params, 
       handleAs: "text",
       timeout: 5000,
       load: function(response, ioArgs) 
       { 
    	
       },
       error: function(response, ioArgs) 
       { 
         console.error("HTTP status code: ", ioArgs.xhr.status);
         return response; 
       }
    });
	generateBasket();
}

function addRow(item,tbody)
{
	var tr = document.createElement("tr");
	tr.setAttribute("class", "basket_selectable basket_item_single");
	
	var td1 = document.createElement("td");
	td1.setAttribute("class", "basket_item_quantity simple_table_quantity border_bottom");
	td1.appendChild(document.createTextNode(item.product_name + " - " + item.size));

	var input = document.createElement("input");
	input.setAttribute("name", "quantity_"+item.product_id);
	input.setAttribute("type", "quantity_"+item.product_id);
	input.setAttribute("value", item.product_quantity);
	input.setAttribute("class", "validate[required,custom[onlyNumber],length[1,2]] text-input");
	input.setAttribute("maxlength", "2");
	input.setAttribute("size", "2");
	input.setAttribute("onblur", "updateBasketLine("+item.product_id+", '"+item.size+"', this.value);");
	
	var td2 = document.createElement("td");
	td2.setAttribute("class", "basket_item_quantity simple_table_quantity border_bottom");
	td2.appendChild(input);
	
	var td3 = document.createElement("td");
	td3.setAttribute("class", "basket_item_image basket_image border_bottom");
	var div1 = document.createElement("div");
	div1.setAttribute("style", "float: left; position: relative;");
	var div2 = document.createElement("div");
	div2.setAttribute("class","photo_0");
	var img = document.createElement('img');
	img.setAttribute("width", "45");
	img.setAttribute("alt", "");
	img.setAttribute("src", '/public/img/products/thumb/'+item.image);
	
	div2.appendChild(img);
	div1.appendChild(div2);
	
	
	td3.appendChild(div1);
	
	var td4 = document.createElement("td");
	td4.setAttribute("class", "basket_product_action basket_action border_bottom");
	if(item.reward_percentage)
	{
		td4.appendChild(document.createTextNode("-"+item.reward_percentage+"%"));
	}
	else
	{
		td4.appendChild(document.createTextNode(" "));
	}
	
	var td5 = document.createElement("td");
	td5.setAttribute("class", "basket_item_unitprice simple_table_unitprice border_bottom");
	td5.appendChild(document.createTextNode(dojo.currency.format(item.price, {currency: currency})));
	
	var td6 = document.createElement("td");
	td6.setAttribute("class", "basket_item_lineprice simple_table_price border_bottom");
	
	if(!item.reward_percentage)
	{
		td6.appendChild(document.createTextNode(dojo.currency.format(item.price * item.product_quantity, {currency: currency})));
	}
	else
	{
		td6.appendChild(document.createTextNode(dojo.currency.format(item.price * item.product_quantity * ((100 - parseInt(item.reward_percentage))/100), {currency: currency})));
	}
	
	
	var td7 = document.createElement("td");
	td7.setAttribute("class", "basket_item_delete basket_delete border_bottom");
	var button = document.createElement("button");
	button.setAttribute("onclick", "javascript:deleteProduct("+item.product_id+",'"+item.size+"',"+item.product_quantity+")");
	button.setAttribute("dojoType", "dijit.form.Button");
	
	
	var img2 = document.createElement('img');
	img2.setAttribute("alt", "Supprimer");
	img2.setAttribute("src", '/public/img/trash.gif');
	button.appendChild(img2);
	td7.appendChild(button);
	
	tr.appendChild(td1);
	tr.appendChild(td2);
	tr.appendChild(td3);
	tr.appendChild(td4);
	tr.appendChild(td5);
	tr.appendChild(td6);
	tr.appendChild(td7);
	
	tbody.appendChild(tr);
}

function addNewShippingRow(tbody, obj, country, shipping_carrier_id)
{
	var tr = document.createElement("tr");
	
	var td1= document.createElement("td");
	td1.setAttribute("class", "checkout_delivery_left");
	
	var input = document.createElement("input");
	input.setAttribute("name", "checkout_delivery_product_id");
	input.setAttribute("type", "radio");
	input.setAttribute("id", "checkout_delivery_"+obj.shipping_carrier_id);
	input.setAttribute("value", obj.shipping_carrier_id);
	input.setAttribute("class", "input_radio checkout_delivery_product");
	input.setAttribute("onclick", "refreshBasket("+obj.shipping_carrier_id+",'"+country+"',weight,currency)");
	if(shipping_carrier_id == obj.shipping_carrier_id)
	{
		input.setAttribute("checked", "checked");
	}

	td1.appendChild(input);
	
	var td2= document.createElement("td");
	td2.setAttribute("class", "checkout_delivery_pic");
	
	var img = document.createElement('img');
	img.setAttribute("alt", "Supprimer");
	img.setAttribute("src", '/public/img/'+obj.logo_url);
	img.setAttribute("title", obj.shipping_carrier_name);
	
	td2.appendChild(img);
	
	var td3 = document.createElement('td');
	
	var div = document.createElement('div');
	div.setAttribute('class','checkout_inline');
	
	var bold = document.createElement('b');
	
	
	var link = document.createElement('a');
	link.setAttribute('href', '#');
	link.setAttribute('class', 'link_info');
	
	var span = document.createElement('span');
	var strong = document.createElement('strong');
	var br	   = document.createElement('br');	
	strong.appendChild(document.createTextNode(obj.shipping_carrier_name));
	
	var engagement = "nls.engagement_livraison_label_"+obj.shipping_carrier_id;
	
	span.appendChild(strong);
	span.appendChild(br);
	span.appendChild(document.createTextNode(eval(engagement)));
	
	link.appendChild(span);
	
	var detail = "nls.shipping_details_"+obj.shipping_carrier_id;
	
	bold.appendChild(document.createTextNode(eval(detail)));
	div.appendChild(bold);
	div.appendChild(link);
	td3.appendChild(div);
	
	var td4 = document.createElement('td');
	td4.setAttribute('class', 'checkout_delivery_right');
	var span2 = document.createElement('span');
	span2.setAttribute('id', 'checkout_delivery_product_label_'+obj.shipping_carrier_name);
	span2.appendChild(document.createTextNode(obj.price + ' €'));
	td4.appendChild(span2);
	
	tr.appendChild(td1);
	tr.appendChild(td2);
	tr.appendChild(td3);
	tr.appendChild(td4);
	
	tbody.appendChild(tr);
}

function generateShippingOptions(country, weight)
{
	displayWait("Veuillez patienter");
	//Initiaisation de la zone
	var tbody = dojo.byId("shipping_options_list");
	//tbody.innerHTML = "";
	
	var contenu_vide = document.createTextNode("");
	
	
	//Suppression des noeuds
	while(tbody.hasChildNodes())
	{
		tbody.removeChild(tbody.lastChild);
	}
	tbody.appendChild(contenu_vide);
	
	//Appel du service retorunant la liste des moyens d'expédition
	var params = "";
	params += "&country=" + country;
	params += "&weight=" + weight;
	
	var _url = '/services/get-shipping-options';
	dojo.xhrPost( 
	 { 
	   // The following URL must match that used to test the server.
	   url: _url + "?" + params, 
	   handleAs: "text",
	
	   timeout: 5000, // Time in milliseconds
	
	   // The LOAD function will be called on a successful response.
	   load: function(response, ioArgs) 
	   { 
	     var objs 	= dojo.fromJson(response);
	     
	     //console.dir(objs);
	     dojo.forEach(objs, function(obj, i){
	    	//add new row to tbody zone
	    	addNewShippingRow(tbody,obj, country, shipping_carrier_id);
			//document.getElementById('checkout_delivery_product_label_'+obj.shipping_carrier_id).innerHTML = dojo.currency.format(obj.price, {currency: _currency});
		 });
	     
	     refreshBasket(shipping_carrier_id,country,weight,currency);
	     
	     hideWait();
	     
	     //document.getElementById("shipping_cost").class = 'simple_table_price';
	     //document.getElementById("shipping_cost").innerHTML = dojo.currency.format(obj.price, {currency: _currency});
	   },
	   // The ERROR function will be called in an error case.
	   error: function(response, ioArgs) 
	   { 
		 console.dir(response);
	     console.error("HTTP status code: ", ioArgs.xhr.status);
	     return response; 
	   }
	  });
	
	//hideWait();
}

function generateBasket()
{
	displayWait("Veuillez patienter");
	var table = document.getElementById("cart_table");
	var tbody = dojo.byId("basket_elements");
	var basket_total_price = document.getElementById("basket_total_price");
	var basket_total_vat	= document.getElementById("basket_total_vat");
	
	
	var contenu_vide = document.createTextNode("");
	
	
	//Suppression des noeuds
	while(tbody.hasChildNodes())
	{
		tbody.removeChild(tbody.lastChild);
	}
	tbody.appendChild(contenu_vide);
	//var tbody = document.createElement("tbody");
	
	var _url = "/services/get-basket";
	var params = ""
	
	dojo.xhrPost( 
     { 
       // The following URL must match that used to test the server.
       url: _url + "?" + params, 
       handleAs: "text",

       timeout: 5000, // Time in milliseconds

       // The LOAD function will be called on a successful response.
       load: function(response, ioArgs) 
       { 
    	 var objs 	= dojo.fromJson(response);
    	 
    	 if(objs.items_quantity == 0)
    	 {
    		 location.reload();
    	 }
    	 
    	 //console.dir(objs);
    	 dojo.forEach(objs.items,function(item){
    		 addRow(item,tbody);
    	 });
    	 table.appendChild(tbody);
    	
    	 
    	 basket_total_price.innerHTML="";
    	 basket_total_price.appendChild(document.createTextNode(dojo.currency.format(objs.basket_total_amount, {currency: currency})));
    	 basket_total_vat.innerHTML="";
    	 basket_total_vat.appendChild(document.createTextNode(dojo.currency.format(objs.basket_total_vat, {currency: currency})));
    	 
    	 var promo_code_field = dojo.byId("promotion_code");
    	 
    	 if(objs.promo_code)
    	 { 
    		 promo_code_field.value = objs.promo_code;
    		 promo_code_field.style.background = "green";
         	 promo_code_field.style.color="white";
         	 promo_code_field.readOnly = true;

    		 dojo.style(dojo.byId('promo_code_button'),"display","none");
    		 dojo.style(dojo.byId('promo_code_delete_button'),"display","inline");
    	 }
    	 else
    	 {
    		promo_code_field.value = "";
        	promo_code_field.style.background = "white";
        	promo_code_field.style.color="black";
        	promo_code_field.readOnly = false;

	    	dojo.style(dojo.byId('promo_code_button'),"display","inline");
	    	dojo.style(dojo.byId('promo_code_delete_button'),"display","none");
    	 }
    	 
    	 try{
    		 updateShippingCost(shipping_carrier_id, country, objs.basket_weight, currency);
    	 }
    	 catch(e)
    	 {
    		 console.dir(e);
    	 }
    	 hideWait();
    	 
       },
       // The ERROR function will be called in an error case.
       error: function(response, ioArgs) 
       { 
	         //console.error("HTTP status code: ", ioArgs.xhr.status);
	         return null; 
       }
      });
}

function check_promo()
{
	displayWait("Veuillez patienter");
	var promo_code = '';
	if(promotion_code)
	{
		promo_code = promotion_code;
	}
	else
	{
		promo_code = dojo.byId('promotion_code').value;
	}
	
	if(promo_code != "")
	{
		
		//Traitement du code promo avec appel d'une rpc via json
		var _url = "/services/check-promo-code";
		var params = "code="+promo_code;
		
		dojo.xhrPost( 
	     { 
	       // The following URL must match that used to test the server.
	       url: _url + "?" + params, 
	       handleAs: "text",

	       timeout: 5000, // Time in milliseconds

	       // The LOAD function will be called on a successful response.
	       load: function(response, ioArgs) 
	       { 
	         //var objs 	= dojo.fromJson(response);
	         //console.dir(objs);
	    	 /*try{
	    		 
	    	 cosonle.log("debut chargement");
	    	 var objs = getBasket();
	    	 console.log("fin de chargement");
	    	 }
	    	 catch(e)
	    	 {
	    		 console.log(e); 
	    	 }*/
	    	 
	    	 if(response != '1') alert('Le code est invalide');
	    	 else generateBasket();
	    		 
	    	 hideWait();
	       },
	       // The ERROR function will be called in an error case.
	       error: function(response, ioArgs) 
	       { 
	         console.error("HTTP status code: ", ioArgs.xhr.status);
	         return response; 
	       }
	      });
		
	}
	
}

function getBasket()
{
	//Traitement du code promo avec appel d'une rpc via json
	var _url = "/services/get-basket";
	var params = "";
	
	dojo.xhrPost( 
     { 
       // The following URL must match that used to test the server.
       url: _url + "?" + params, 
       handleAs: "text",

       timeout: 5000, // Time in milliseconds

       // The LOAD function will be called on a successful response.
       load: function(response, ioArgs) 
       { 
    	 var objs 	= dojo.fromJson(response);
    	 //console.dir(objs);
         return objs;
       },
       // The ERROR function will be called in an error case.
       error: function(response, ioArgs) 
       { 
         console.error("HTTP status code: ", ioArgs.xhr.status);
         return null; 
       }
      });
}

function displayWait(txtContent) {
    if (!txtContent) {
        txtContent = "Please wait...";
    }
    txtContent = "<img src=\"/public/js/dojo1.2/dojox/image/resources/images/loading.gif\" alt=\"\" /> " + nls.please_wait;
    var dialog = dijit.byId("waiting");
    dialog.attr('content', txtContent);
    dialog.titleBar.style.display='none';
    dialog.startup();
    dialog.show();
}

function hideWait()
{
	var dialog = dijit.byId("waiting");
	dialog.hide();
}



function updateUserData()
{
	var params = $('myFormThree').serialize();
	alert(params);
	var url = "/services/update-user-data";
	new Ajax.Request(url, {
  		method: 'post',
  		parameters : params,
  		onSuccess: function(transport) {
  			alert(transport.responseText);
    		/*if(transport.responseText == 1)
    		{
    			alert("Mise � jour effectu�e");
    			location.reload();
    		}
    		else
    		{
    			alert("Une erreur s'est produite. Merci de renouveler l'op�ration");
    		}*/
  		},
  		onError : function() {
  			alert("Une erreur est survenue. Merci de r�essayer");
  		}
	});	
}

function updateShippingOptions(country, weight, _currency)
{
	var params = "";
	params += "&country=" + country;
	params += "&weight=" + weight;
	
	var _url = '/services/get-shipping-options';
	dojo.xhrPost( 
     { 
       // The following URL must match that used to test the server.
       url: _url + "?" + params, 
       handleAs: "text",

       timeout: 5000, // Time in milliseconds

       // The LOAD function will be called on a successful response.
       load: function(response, ioArgs) 
       { 
         var objs 	= dojo.fromJson(response);
         
         //console.dir(objs);
         dojo.forEach(objs, function(obj, i){
  			document.getElementById('checkout_delivery_product_label_'+obj.shipping_carrier_id).innerHTML = dojo.currency.format(obj.price, {currency: _currency});
		 });
         
         
         //document.getElementById("shipping_cost").class = 'simple_table_price';
         //document.getElementById("shipping_cost").innerHTML = dojo.currency.format(obj.price, {currency: _currency});
       },
       // The ERROR function will be called in an error case.
       error: function(response, ioArgs) 
       { 
         console.error("HTTP status code: ", ioArgs.xhr.status);
         return response; 
       }
      });
}

function showMessageBox(div,message)
{ 
	dijit.byId(div).attr('content',message);
	dijit.byId(div).startup();
	dijit.byId(div).show();
}

function refreshBasket(carrier_id, country, weight, _currency)
{
	var params = "";
	params += "carrier_id=" + carrier_id;
	params += "&country=" + country;
	params += "&weight=" + weight;
	
	var _url = '/services/get-shipping-cost';
	dojo.xhrPost( 
     { 
       // The following URL must match that used to test the server.
       url: _url + "?" + params, 
       handleAs: "text",

       timeout: 5000, // Time in milliseconds

       // The LOAD function will be called on a successful response.
       load: function(response, ioArgs) 
       { 
         var obj	= dojo.fromJson(response);
         document.getElementById("cart_shipping_amount_label").innerHTML = obj.shipping_carrier_name + ' :';
         document.getElementById("cart_shipping_amount").innerHTML = dojo.currency.format(obj.price, {currency: _currency});
         document.getElementById("cart_total_amount").innerHTML = dojo.currency.format(obj.total_amount, {currency: _currency});
       },
       // The ERROR function will be called in an error case.
       error: function(response, ioArgs) 
       { 
         console.error("HTTP status code: ", ioArgs.xhr.status);
         return response; 
       }
      });
}

function updateShippingCost(carrier_id, country, weight, _currency)
{
	var params = "";
	params += "carrier_id=" + carrier_id;
	params += "&country=" + country;
	params += "&weight=" + weight;
	
	var _url = '/services/get-shipping-cost';
	dojo.xhrPost( 
     { 
       // The following URL must match that used to test the server.
       url: _url + "?" + params, 
       handleAs: "text",

       timeout: 5000, // Time in milliseconds

       // The LOAD function will be called on a successful response.
       load: function(response, ioArgs) 
       { 
         
         var obj 	= dojo.fromJson(response);
         //document.getElementById("shipping_cost").class = 'simple_table_price';
         document.getElementById("shipping_cost").innerHTML = dojo.currency.format(obj.price, {currency: _currency});
         document.getElementById("shipping_carrier_label").innerHTML = obj.shipping_carrier_name;
         var basket_total_price = document.getElementById("basket_total_price");
         basket_total_price.innerHTML="";
    	 basket_total_price.appendChild(document.createTextNode(dojo.currency.format(obj.total_amount, {currency: _currency})));
         
       },
       // The ERROR function will be called in an error case.
       error: function(response, ioArgs) 
       { 
         console.error("HTTP status code: ", ioArgs.xhr.status);
         return response; 
       }
      });

}

function checkDelivery()
{
	
}

function showTermOfUse()
{
	var content = "";
}

function showFAQ()
{
	var content = "";
}

function getTeam(id)
{
	var _url = "/services/get-team-mate-by-id/";
	dojo.xhrPost( 
     { 
       // The following URL must match that used to test the server.
       url: _url + "?id=" + id, 
       handleAs: "text",

       timeout: 5000, // Time in milliseconds

       // The LOAD function will be called on a successful response.
       load: function(response, ioArgs) 
       { 
         if(response)
         {
         	try{
	         	var obj 	= dojo.fromJson(response);
	         	$('team_title').innerHTML = "<img src=\"/public/img/team/"+id+"/titre.jpg\" />";
	         	$('team_image1').innerHTML = "<img src=\"/public/img/team/"+id+"/photo01.jpg\" />";
	         	$('team_image2').innerHTML = "<img src=\"/public/img/team/"+id+"/photo02.jpg\" />";
	         	if(obj.interview)
	         	{
	         		$('team_interview').innerHTML = obj.interview;
	         	}
	         	else
	         	{
	         		$('team_interview').innerHTML = "<img src=\"/public/img/team/"+id+"/itw.jpg\" />";
	         	}
	         	$('team_image3').innerHTML = "<img src=\"/public/img/team/"+id+"/photo03.jpg\" />";
         	}
         	catch(e)
         	{
         		console.debug(e);
         	}
         }
       },

       // The ERROR function will be called in an error case.
       error: function(response, ioArgs) 
       { 
         console.error("HTTP status code: ", ioArgs.xhr.status);
         return response; 
       }
      });
}


function loadNews()
{
	var _url = "/services/get-top-news";
	dojo.xhrPost( 
     { 
       // The following URL must match that used to test the server.
       url: _url, 
       handleAs: "text",

       timeout: 5000, // Time in milliseconds

       // The LOAD function will be called on a successful response.
       load: function(response, ioArgs) 
       { 
         if(response)
         {
         	var obj 	= dojo.fromJson(response);
         	var obj2 	= obj.items[0];
         	console.dir(obj2);
         	var div = document.createElement("div");
         	div.innerHTML=obj2.news_content;
         	$('news').appendChild(div);
         	//console.dir("Reponse : " + dojo.fromJson(response));
         	//var newMe = dojox.json.ref.fromJson(response);
         	//var obj 	= dojo.fromJson(response);
         }
       },

       // The ERROR function will be called in an error case.
       error: function(response, ioArgs) 
       { 
         console.error("HTTP status code: ", ioArgs.xhr.status);
         return response; 
       }
      });
}

function showScaled(img)
{
	var content = "";
	content += "<div id=\"animation\" style=\"text-align: center;\">\n";
	content += "	<embed type=\"application/x-shockwave-flash\" src=\"/public/swf/interface.swf\" id=\"interface\" name=\"interface\" bgcolor=\"#ffffff\" quality=\"high\" flashvars=\"path=http://localhost:9002/&amp;verso=public/img/products/scaled/"+img+"&amp;recto=public/img/products/scaled/"+img+"\" width=\"800\" height=\"500\"/>\n";
	content += "</div>\n";
	content += "<script type=\"text/javascript\">\n";
	content += "	window.resizeTo(800, 600);\n";
	content += "	// <![CDATA[\n";
	content += "	var so = new SWFObject('/public/swf/interface.swf', 'interface', '800', '500', '8.0.23', '#ffffff', true);\n";
	content += "	so.addVariable('path', 'http://localhost:9002' );\n";
	content += "	so.addVariable('verso', '/public/img/products/girlie01.png');\n";
	content += "	so.addVariable('recto', '/public/img/products/girlie01.png');\n";

	content += "	so.write('animation');\n";
	content += "	// ]]>\n";
	content += "</script>\n";
	
	dijit.byId('scaled').setContent(content);
	dijit.byId('scaled').startup();
	dijit.byId('scaled').show()
}

function viewAccountDetails()
{
	document.location = '/my-account/details';
	return true;
}

function deleteProduct(product_id, size, quantity)
{
	var _url		= "/services/delete-from-cart";
	var _params		= "product_id=" + product_id + "&quantity="+quantity + "&size=" + size ;
	dojo.xhrPost( 
     { 
       // The following URL must match that used to test the server.
       url: _url+"?"+_params, 
       handleAs: "text",
       timeout: 5000, // Time in milliseconds
       // The LOAD function will be called on a successful response.
       load: function(response, ioArgs) 
       {
       		location.reload() ; 
       },
       // The ERROR function will be called in an error case.
       error: function(response, ioArgs) 
       { 
         //console.error("HTTP status code: ", ioArgs.xhr.status);
         //console.dir(ioArgs.xhr);
       }
      });
}

function addToCart(id, image)
{
	var pricing	 = document.getElementById("pricing");
	var currency = document.getElementById("currency");
	var product_name = document.getElementById("product_name");
	//var color	 = document.getElementById("color");
	var quantity = document.getElementById("quantity");
	var size = document.getElementById("size");
	var weight = document.getElementById("weight");
	var trademark_id = document.getElementById("trademark_id");
	var sub_category_id = document.getElementById("sub_category_id");
	
	var params = "";
	params += "id=" + id;
	//params += "&color=" + color.value;
	params += "&quantity=" + quantity.value;
	params += "&size=" + size.value;
	params += "&price=" + pricing.value;
	params += "&currency=" + currency.value;
	params += "&product_name=" + product_name.value;
	params += "&weight=" + weight.value;
	params += "&sub_category_id=" + sub_category_id.value;
	params += "&trademark_id=" + trademark_id.value;
	params += "&weight=" + weight.value;
	params += "&image=" + image;
	
	
	var url		= "/services/add-to-cart";

	_callAjax(url, params); 
}

function checkAccount()
{
	var params = $('registration').serialize();
	var url = "/services/check-account/";
	if(_callAjax(url,params))
	{
		return false;
	}
	else
	{
		return true;
	}
	
	return false; 
}

function _callAjax(_url, _params)
{
	dojo.xhrPost( 
     { 
       // The following URL must match that used to test the server.
       url: _url+"?"+_params, 
       handleAs: "text",

       timeout: 5000, // Time in milliseconds

       // The LOAD function will be called on a successful response.
       load: function(response, ioArgs) 
       { 
         if(response == 1)
         {
        	hideProductBox(); 
        	showProductCartConfirm('information',nls.product_added);	
         }
         else
         {
         	showMessageBox('erreur',nls.product_not_added);	
         }
       },

       // The ERROR function will be called in an error case.
       error: function(response, ioArgs) 
       { 
         console.error("HTTP status code: ", ioArgs.xhr.status);
         return response; 
       }
      });
}

function showMessageBox(div,message)
{ 
	dijit.byId(div).attr('content',message);
	dijit.byId(div).startup();
	dijit.byId(div).show();
}

function show(url)
{
	window.location = server_url + url;
}

function showProductCartConfirm(div, message)
{
	var content = message + "<br/><hr/><br/>";
	content += "<button dojoType=\"dijit.form.Button\" onclick=\"javascript:show('/store');\">Continuer le shopping</button>\n";
	content += "&nbsp&nbsp;";
	content += "<button dojoType=\"dijit.form.Button\" onclick=\"javascript:show('/cart');\">Aller au panier</button>";
	
	dijit.byId(div).attr('style', 'width: 500px;');
	dijit.byId(div).attr('content',content);
	dijit.byId(div).startup();
	dijit.byId(div).show();
}

function hideProductBox()
{
	dijit.byId('detail_produit').hide();
}

function initPopup(obj, type)
{
	var content = "";
	
	//content += "<div dojoType=\"dijit.form.Form\" id=\"myFormThree\" jsId=\"myFormThree\" id=\"product_details\">\n"; 
	content += "<table width=\"380\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
	content += "<tr><td colspan=\"2\">\n";
	content += "	<table width=\"290\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" >\n";
	content += "	  <tr>\n";
	content += "	    <td  style=\"height:25px;\"></td>\n";
	content += "	    <td width=\"63\"></td>\n";
	content += "	    <td width=\"85\"></td>\n";
	content += "	  </tr>\n";
	content += "	  <tr>\n";
	content += "	    <td rowspan=\"10\" width=\"142\" valign=\"top\" class=\"border\"><img src=\"/public/img/products/thumb/"+obj.product_thumb_image+"\" alt=\"product\" /></td>\n";
	content += "	    <td colspan=\"2\" class=\"border\" align=\"left\"><span class=\"article\">"+obj.product_name+"</span> </td>\n";
	content += "	    </tr>\n";
	content += "	  <tr>\n";
	content += "	    <td colspan=\"2\" class=\"border\" align=\"left\"><span class=\"reference\">ID : "+obj.product_reference+"</span> </td>\n";
	content += "	    </tr>\n";
	//content += "	  <tr>\n";
	//content += "	    <td align=\"left\"><span class=\"color\">"+nls.color+" :</span> </td>\n";
	//content += "	    <td align=\"left\">\n";
	//content += "		   <select dojoType=\"dijit.form.FilteringSelect\" class=\"choice\" id=\"color\" title=\"color\" style=\"width:75px;\" width=\"75\">\n";
	//content += "			  <option value =\"Black\">"+nls.black+"</option>\n";
	//content += "			  <option value =\"White\">"+nls.white+"</option>\n";
	//content += "			  <option value =\"Red\">"+nls.red+"</option>\n";
	//content += "			  <option value =\"Grey\">"+nls.gray+"</option>\n";
	//content += "			</select>\n";
	//content += "		\n";
	//content += "		\n";
	//content += "		</td>\n";
	//content += "	  </tr>\n";
	
	content += "	  <tr>\n";
	content += "	    <td align=\"left\"><span class=\"size\">"+nls.size+" :</span> </td>\n";
	content += "	    <td align=\"left\">\n";
	content += "		     <select dojoType=\"dijit.form.FilteringSelect\" class=\"choice\" id=\"size\" title=\"size\" style=\"width:70px;\" width=\"50\" >\n";
	if(type == 1)
	{
		content += "			  <option value =\"XL\">XL</option>\n";
		content += "			  <option value =\"S\">S</option>\n";
		content += "			  <option value =\"M\">M</option>\n";
		content += "			  <option value =\"L\">L</option>\n";
	}
	else if (type == 3) {
		content += "			  <option value =\"L\">L</option>\n";
	}
	else
	{
		content += "			  <option value =\"7p6\">7p6</option>\n";
		content += "			  <option value =\"7p75\">7p75</option>\n";
		content += "			  <option value =\"7p825\">7p825</option>\n";
		content += "			  <option value =\"8p\">8p</option>\n";
	}
	content += "			</select>\n";
	content += "		\n";
	content += "		</td>\n";
	content += "	  </tr>\n";
	content += "	  <tr>\n";
	content += "	    <td align=\"left\" class=\"border\"><span class=\"quantity\">"+nls.quantity+" :</span></td>\n";
	content += "	    <td align=\"left\">\n";
	content += "		     <select dojoType=\"dijit.form.FilteringSelect\" class=\"choice\" id=\"quantity\" title=\"quantity\" style=\"width:70px;\" width=\"50\" >\n";
	content += "			  <option value =\"1\">1</option>\n";
	content += "			  <option value =\"2\">2</option>\n";
	content += "			  <option value =\"3\">3</option>\n";
	content += "			  <option value =\"4\">4</option>\n";
	content += "			  <option value =\"5\">5</option>\n";
	content += "			  <option value =\"6\">6</option>\n";
	content += "			  <option value =\"7\">7</option>\n";
	content += "			</select>\n";
	content += "		\n";
	content += "		</td>\n";
	content += "	  </tr>\n";
	content += "	  <tr>\n";
	content += "	    <td></td>\n";
	content += "	    <td></td>\n";
	content += "	  </tr>\n";
	content += "	  <tr>\n";
	content += "	    <td height=\"35\" align=\"left\" class=\"border\">\n";
	content += "			<span class=\"price\">"+dojo.currency.format(obj.product_default_price, {currency: _currency})+"</span>\n";
	content += "			<input type=\"hidden\" id=\"pricing\" value=\""+obj.product_default_price+"\">\n";
	content += "			<input type=\"hidden\" id=\"product_name\" value=\""+obj.product_name+"\">\n";
	content += "			<input type=\"hidden\" id=\"weight\" value=\""+obj.weight+"\">\n";
	content += "			<input type=\"hidden\" id=\"trademark_id\" value=\""+obj.trademark_id+"\">\n";
	content += "			<input type=\"hidden\" id=\"sub_category_id\" value=\""+obj.sub_category_id+"\">\n";
	content += "			<input type=\"hidden\" id=\"currency\" value=\""+_currency+"\">\n";
	content += "		</td>\n";
	content += "	    <td align=\"left\" class=\"border\">&nbsp;</td>\n";
	content += "	  </tr>\n";
	content += "	  <tr>\n";
	content += "	    <td align=\"left\" colspan=\"2\">\n";
	content += "			<button dojoType=\"dijit.form.Button\" name=\"submitButtonThree\" onclick=\"addToCart("+obj.product_id+",'"+obj.product_thumb_image+"')\">"+nls.addtocart+"</button>\n";
	content += "		</td>\n";
	content += "	    </tr>\n";
	content += "	  <tr>\n";
	content += "	    <td>&nbsp;</td>\n";
	content += "	    <td>&nbsp;</td>\n";
	content += "	  </tr>\n";
	content += "	  <tr>\n";
	content += "	    <td class=\"border\">&nbsp;</td>\n";
	content += "	    <td class=\"border\">&nbsp;</td>\n";
	content += "	  </tr>\n";
	content += "	  <tr>\n";
	content += "	    <td align=\"left\" class=\"border\" style=\"height:23px;\"><span class=\"delai\">"+nls.shipping+"</span></td>\n";
	content += "	    <td class=\"border\">&nbsp;</td>\n";
	content += "	    <td class=\"border\">&nbsp;</td>\n";
	content += "	  </tr>\n";
	content += "	  <tr>\n";
	if(type ==1)
	{
		content += "	    <td align=\"left\" colspan=\"3\"><span class=\"descriptif\">Dry tech,&nbsp; Breathable,&nbsp; U.V protection,&nbsp; Lightweight sherpa lining,&nbsp; anti bacterial,&nbsp;&nbsp; 100% cotton material"+obj.product_description+"</span> </td>\n";
	}
	else
	{
		content += "	    <td align=\"left\" colspan=\"3\"><span class=\"descriptif\">"+obj.product_description+"</span> </td>\n";
	}
	content += "	    </tr>\n";
	content += "	  <tr>\n";
	content += "	    <td>&nbsp;</td>\n";
	content += "	    <td>&nbsp;</td>\n";
	content += "	    <td>&nbsp;</td>\n";
	content += "	  </tr>\n";
	content += "	  <tr>\n";
	content += "	    <td>&nbsp;</td>\n";
	content += "	    <td>&nbsp;</td>\n";
	content += "	    <td>&nbsp;</td>\n";
	content += "	  </tr>\n";
	content += "	</table>\n";
	content += "</td></tr>\n";
	content += "</table>\n";
	//content += "</div>\n"; 
	
	dijit.byId('detail_produit').attr('loadingMessage',"<center><img src=\"/public/img/loading.gif\"/></center>");
	dijit.byId('detail_produit').attr('content',content);
	dijit.byId('detail_produit').startup(); 
	dijit.byId('detail_produit').show(); 
}

function getProduct(id, type)
{
	var url = "/services/get-product-by-id/";
	var params = "id="+id;
	callAjax(url, params, id, type);
}


function callAjax(_url, _params, id, type)
{
	dojo.xhrPost( 
     { 
       // The following URL must match that used to test the server.
       url: _url+"?"+_params, 
       handleAs: "text",

       timeout: 5000, // Time in milliseconds

       // The LOAD function will be called on a successful response.
       load: function(response, ioArgs) 
       { 
         if(response)
         {
         	var obj 	= dojo.fromJson(response);
         	var obj2 	= obj.items[0];

         	if(!obj2)
         	{
         		alert("This product is not available yet!");
         	}
         	else
         	{
         		//console.dir(obj2);
         		initPopup(obj2, type);
         	}
         }
       },

       // The ERROR function will be called in an error case.
       error: function(response, ioArgs) 
       { 
         console.error("HTTP status code: ", ioArgs.xhr.status);
         return response; 
       }
      });
}

