var webPATH = "/retail/";
var fashioncart= "http://www.fashioncart.com/retail";
//var _HTTPPATH = "http://www.fashioncart.com/retail"


//////////////////////////////////////
// JQUERY
$(function(){
	var _HTTPPATH = $("body").attr("retailDomain");
		
	$("#breadcrumbs").jBreadCrumb();
		
	
	// /DEBUT - ROLLOVER	
	$(".ROLLOVER").hover(
		function() {
			this.src = this.src.replace("_on","_off");
		}, function() {
			this.src = this.src.replace("_off","_on");
		}
	);	
	// /FIN - ROLLOVER	
		
		
		
		
			
								
								
//AJAX CALL
	//BROWSE BY - START
	$("a.browse_by").click(function(e){
		var DesignerID = $("body").attr("DesignerID");
		var type = $(this).parent("li").parent("ul").attr("type");
		var value = $(this).attr("href");
		var this_button = $(this);

		$.ajax({
			type: "POST",
			url: webPATH+"includes/cfm/browse_by.cfm",
			data:"user_fk="+DesignerID+"&type="+type+"&value="+value,
			success: function(response) {
				$("a.browse_by").removeClass("browseBy_selected");
				$(this_button).addClass("browseBy_selected");
				window.location.reload();
			}
		});
		
		return false;
	});
	//BROWSE BY - END

	
	//PROMO CODE - START
	$("input[name=valideCode]").click(function(e){
		var DesignerID=$("body").attr("DesignerID");
		var code=$("input[name=code]").val();
		var ssTT=$(this).attr("ssTT");
		$.ajax({
			type: "POST",
			url: webPATH+"includes/cfm/validation.promoCode.cfm",
			data:"code="+code+"&user_fk="+DesignerID+"&ssTT="+ssTT,
			success: function(response) {
				if(response==0)
					$("input[name=code]").val("Invalid Code.");
				else {
					var data=response.split(",");
					$("#rowPromo").fadeOut(500);
					
					$("span.titlePromo").html("Promo<br/>").slideDown(500);
					$("span.montantPromo").html("-"+data[3]+data[2]+"<br/>").slideDown(500);
					

					$(".sousTOTALAVTX").html(data[4]);
					$(".totalTPS").html(data[5]);
					$(".totalTVQ").html(data[6]);
					$(".TOTAL").html(data[7]);
					$(".taxCalifornia").html(data[8]);
					$(".totalCalifornia").html(data[9]);
					
					window.location.reload();
				}
			}
		});
		return false;
	});
	//PROMO CODE - END
//AJAX CALL - END
									
	
	
	
	
	
	
	// RETIRER LE FOND GRIS DANS IE
	//$(document).pngFix(  { repeatMethod: "repeat-x" } );

	
	// UPDATE LA QUANTITÉ DU PRODUIT
	$(".update").click(function(event){  
		var _ROW = $(this).attr("row");
		var _QTY = $("#QTY_"+_ROW).val();
		var DESIGNER = $(this).attr("designer");
		var sku_id = $(this).attr("sku_id");
		if (_QTY < 0) {
			var content = "<div align='center' style='text-align:center;'><br /><br />You must enter a positive integer.<br /><br /><a href='"+webPATH+"update-cart/"+_ROW+"/"+_QTY+"/' title='OK'><img src='"+webPATH+"images/white-ok_on.png' border='0' /></a></div>";
			$.nyroModalManual({
				bgColor: '#000000',
				content: initTABLEAU( "350px",content )
			});				
		} else {
			$.ajax({
				type: "POST",
				url: webPATH+"includes/php/checkQTY.php",
				dataType: 'json',
				data:"sku_id="+sku_id+"&qty="+_QTY,
				success: function( data,status ) {
					if( data.msg == "true" )
						document.location.href = webPATH+"update-cart/"+ _ROW +"/"+ _QTY +"/";
					else {
						var content = "<div align='center' style='text-align:center;'><br /><br />"+data.msg+"<br /><br /><a href='"+webPATH+"update-cart/"+_ROW+"/"+data.qty+"/' title='OK'><img src='"+webPATH+"images/white-ok_on.png' border='0' /></a></div>";
						$.nyroModalManual({
							bgColor: '#000000',
							content: initTABLEAU( "350px",content )
						});				
					}
				}
			});
		}
		
		return false;
	});




	$("#paynow").click(function(event){
		var content = "<div align='center' style='text-align:center;'><br /><br /> You will receive a copy the invoice by email. <br /><br /> Pay now  with Paypal and ensure availability of your items. <br /><br /><br /><br /><a href='' titla='Cancel' class='nyroModalClose bouton ROLLOVER'><img src='"+webPATH+"images/white-cancel_on.png' border='0' /></a><a href='"+webPATH+"send-invoice/' titla='PAY LATER'><img src='"+webPATH+"images/pay-later.png' border='0' /></a><a href='"+webPATH+"paypal/' titla='OK'><img src='"+webPATH+"images/white-ok_on.png' border='0' /></a></div>";
		$.nyroModalManual({
			bgColor: '#000000',
			content: initTABLEAU( "350px",content )
		});				
		return false;
	});





		$("#sltColor").change(function(event){
			var product_id = $(this).attr("product_id");
			var colors_id = $(this).val();
			
			$.ajax({
				type: "POST",
				url: webPATH+"includes/php/getSIZE.php",
				data:"colors_id="+colors_id+"&product_id="+product_id,
				success: function( msg ) {
					$("#boxSIZE").html(msg).slideDown(500);
					$("#boxQTY").slideUp(500);
					$("#sltSize").change(function(event){
						var sku_id = $(this).val();
						$.ajax({
							type: "POST",
							url: webPATH+"includes/php/getQTY.php",
							data:"sku_id="+sku_id,
							success: function( msg ) {
								$("#boxQTY").html(msg).slideDown(500);
							}
						});
						
						return false;
					});
				}
			});
			
			return false;
		});

		$("#sltSize").change(function(event){
			var sku_id = $(this).val();
			$.ajax({
				type: "POST",
				url: webPATH+"includes/php/getQTY.php",
				data:"sku_id="+sku_id,
				success: function( msg ) {
					$("#boxQTY").html(msg).slideDown(500);
				}
			});
			
			return false;
		});
		






		$("#ADD").click(function(event){  
			var nobug = true;
			var msg = "";
			var tableau = new Array( true,"","" );	
			var _HTML = "";			
			
			
			if( $("#sltSize").val() == "0" ) {
				tableau[0] = false;
				tableau[1] += "Please select a size /";
				tableau[2] += "sltSize /";
			}
			if( $("#sltColor").val() == "0" ) {
				tableau[0] = false;
				tableau[1] += "Please select a color /";
				tableau[2] += "sltColor /";
			}
			if( $("#QTY").val() == "0" ) {
				tableau[0] = false;
				tableau[1] += "Please select a quantity /";
				tableau[2] += "QTY /";
			}
			
			if( tableau[0] != false ) {
				$("#frmProduct").submit();
			} else {
				var aMSG = tableau[1].split(" /");
				var aFIELD = tableau[2].split(" /");

				for( var i = 0; i < aMSG.length; i++ ) {
					if( aMSG[i] != "" ) {
						_HTML += "<li>"+aMSG[i]+"</li>";					
						$("#"+aFIELD[i]).addClass("redborder").fadeIn( 500 );
					}
				}
				
				$("#errors").html( _HTML );
				$("#errors").slideDown( 500 );
			}
			
			return false;
		});




		$("#sendContact").click(function(event){  
			var nobug = true;
			var msg = "";
			var tableau = new Array( true,"","" );	
			var _HTML = "";			

			est_la("email", tableau, "Please fill in your email address /", "email /");
			est_courriel_valide("email", tableau, "Please use a valid email address /", "email /");
			est_la("subject", tableau, "Please enter a subject message /", "subject /");
			est_la("comments", tableau, "Please enter a comments /", "comments /");
			
			if( tableau[0] != false ) {
				
				/*var email = $("#email").val();
				var subject = $("#subject").val();
				var comments = $("#comments").val();
				var to = $(this).attr("to");

				$.ajax({
					type: "POST",
					url: webPATH+"includes/cfm/contact.cfm",
					data:"email="+email+"&subject="+subject+"&comments="+comments+"&to="+to,
					success: function( msg ) {
						
						alert(msg);
						
						//$("#contact").slideUp(500);
						//$("#thanks").html("<p style='width:250px;'>Thanks!</p>").slideDown(500);
					}
				});*/
				
				return true;
			} else {
				var aMSG = tableau[1].split(" /");
				var aFIELD = tableau[2].split(" /");

				for( var i = 0; i < aMSG.length; i++ ) {
					if( aMSG[i] != "" ) {
						_HTML += "<li>"+aMSG[i]+"</li>";					
						$("#"+aFIELD[i]).addClass("redborder").fadeIn( 500 );
					}
				}
				
				$("#errors").html( _HTML );
				$("#errors").slideDown( 500 );
			}
			
			return false;
		});




		$(".modTY").click(function(event){  
			var _QTY = Number( $("#QTY").val() );
			var _OPERATEUR = $(this).attr("id");
		
			if( _OPERATEUR == "+" )
				_QTY+=1;
			else
			{
				if( _QTY > 1 )
					_QTY-=1;
			}
				
			$("#txt_QTY").text( _QTY );
			$("#QTY").val( _QTY );
			
			return false;
		});







		// /SUPPRIMER UN PRODUIT DU SHOPPINGCART
		$(".delete").click(function(e) {
			e.preventDefault();
			
			var _CONTENU = "";
			var itemNAME = $(this).attr("itemNAME");
			var urlNAME = $("body").attr("URLName");
			var itemROW = $(this).attr("itemROW");

			
			_CONTENU += '<div align="center"><br /><br /><p>Are you sure you want to remove <strong>'+ itemNAME +'</strong> from your shopping cart?</p></div>';
			_CONTENU += '<br />';
			
			_CONTENU += "<form name='deleteREQUEST' id='deleteREQUEST' method='post' action='"+_HTTPPATH+"/remove-item/' >";
			_CONTENU += '	<table border="0" cellpadding="0" cellspacing="5" align="center">';
			_CONTENU += '   	<tr>';
			_CONTENU += '       	<td>';   
			_CONTENU += '           	<input type="hidden" name="rowITEM" id="rowITEM" value="'+ itemROW +'" onClick="$(\'deleteREQUEST\').submit();" />';
			_CONTENU += '           	<input type="image" src="'+webPATH+'images/white-yes_on.png" class="ROLLOVER button" alt="YES" />';
			_CONTENU += '           </td>';
			_CONTENU += '           <td><input type="image" src="'+webPATH+'images/white-no_on.png" alt="NO" class="nyroModalClose ROLLOVER button" id="closeBut" /></a></td>';
			_CONTENU += '		</tr>';
			_CONTENU += '	</table>';
			_CONTENU += '</form>';
			
			
			_HTML = initTABLEAU( "350px",_CONTENU ); 			
			
			$.nyroModalManual({
				bgColor: '#000000',
				content: _HTML
			});
			
			
			return false;
		});




	// MODIFIER LE PRODUIT
	$(".edit").click(function(event){  
		var urlNAME = $(this).attr("urlNAME");
		var rowITEM = $(this).attr("rowITEM");
		var itemID = $(this).attr("itemID");
		var DesignerID = $(this).attr("DesignerID");
		var itemSIZE = $(this).attr("itemSIZE");
		var itemCOLOR = $(this).attr("itemCOLOR");


		$.ajax({
			type: "POST",
			url: webPATH+"includes/php/edit-item.php",
			data:"itemID="+ itemID +"&DesignerID="+ DesignerID +"&rowITEM="+ rowITEM +"&urlNAME="+ urlNAME +"&itemCOLOR="+ itemCOLOR +"&itemSIZE="+ itemSIZE,
			success: function( msg )
			{
				$("td#dropMSG").html( msg );
				$("div#cache").fadeIn();
				$("table#box").fadeIn();
			}
		});
				
	});


	// SIGNIN
	$("#signIN").click(function(event){
		var URLName = $(this).attr("URLName");
		var nobug = true;
		var msg = "";
		var tableau = new Array(true,'','');	
					
		est_la("email", tableau, "Please, provide your email address./", "email ");
		est_courriel_valide("email", tableau, "Please, use a valid email address./", "email ");
		est_la("password", tableau, "Please, provide a password.", "password");
		
		
		//	Si form pas valide
		if(tableau[0] != false)
		{			
			var emailADDRESS = $("#email").val();
			var password = $("#password").val();

			$.ajax({
				type: "POST",
				url: webPATH+"includes/php/connexion.php",
				data:"emailADDRESS="+emailADDRESS+"&password="+password,
			
				success: function( msg )
				{
					if( msg == "FALSE" )
					{
						sErreurs += "<p>The email address/password you entered is wrong!</p>";
						sErreurs += "<a href='javascript:doNOTremove();' class='ok' title='OK'><img src='"+webPATH+"images/ok.gif' alt='OK' border='0' /></a>";
						$("td#dropMSG").html( sErreurs );
						$("div#cache").fadeIn();
						$("table#box").fadeIn();
					}
					else
						window.location.href = webPATH+URLName+"/sign-in/"+msg+"/";
				}
			});
		}
		else
		{
			var sErreurs = "";
			var aMSG = tableau[1].split("/");
			var aCHAMPS = tableau[2].split(" ");

			sErreurs += "<ul id='erreurs'>";
			for( var i = 0; i < aCHAMPS.length; i++ )
			{
				if( aMSG[i] != "" && aCHAMPS[i] != "" )
				{
					sErreurs += "<li>"+ aMSG[i] +"</li>";
				}
			}
			sErreurs += "</ul>";
			sErreurs += "<br />";
	
			sErreurs += "<a href='javascript:doNOTremove();' class='ok' title='OK'><img src='"+webPATH+"images/ok.gif' alt='OK' border='0' /></a>";
			$("td#dropMSG").html( sErreurs );
			$("div#cache").fadeIn();
			$("table#box").fadeIn();
		}
	
		return false;
	
	});

	//$("#postalCODE_billing").mask("a9a 9a9");
	//$("#postalCODE_shipping").mask("a9a 9a9");

	//CHANGE PAYS dans le SELECT
	$("#country_billing").change(function(event){  
		var _PAYS = $(this).val();
		var _HTML = "";
			
		if( _PAYS != "-" )
		{
			switch( _PAYS )
			{
				// CANADA
				case "Canada":
					var _PROVINCES = Array({data:"",label:""}
											,{data:"AB",label:"Alberta"}
											,{data:"BC",label:"British Columbia"} 
											,{data:"MB",label:"Manitoba"}
											,{data:"NB",label:"New Brunswick"}
											,{data:"NL",label:"Newfoundland"}
											,{data:"NT",label:"Northwest Territories"}
											,{data:"NS",label:"Nova Scotia"}
											,{data:"NU",label:"Nunavut"}
											,{data:"ON",label:"Ontario"}
											,{data:"PE",label:"Prince Edward Island"}
											,{data:"QC",label:"Quebec"}
											,{data:"SK",label:"Saskatchewan"}
											,{data:"YT",label:"Yukon"}
										);

/*
					_HTML += "<td width='125px'><label for='province'>Province * </label></td>";
					_HTML += "<td>";
					_HTML += "<select name='statesprovinces' id='provinces'>";
*/
					
					_HTML += '<select name="statesprovinces_billing" id="statesprovinces_billing">';
					for( var i = 0; i < _PROVINCES.length; i++ )
						_HTML += "<option value='"+ _PROVINCES[i].data +"'>"+ _PROVINCES[i].label +"</option>";
					_HTML += '</select>';
/*
					_HTML += "</select>";
					_HTML += "</td>";
*/

					
					
					$("#td_province").html(_HTML);
					$("#tr_statesprovinces_billing").fadeIn(500);

					
					
/* 					$("#provincesSTATES tr").html( _HTML ); */
/* 					$("#provincesSTATES").slideDown( 500 ); */
                    $("#code tr").html('<td width="125px"><label for="postalCODE_billing">Postal Code * </label></td><td><input type="text" name="postalCODE_billing" id="postalCODE_billing" class="inputFORM" style="text-transform:uppercase;" value="" /></td>' ).slideDown(500);
					
					//$("#postalCODE_billing").mask("a9a 9a9");
					
					break;
				
				// ÉTATS-UNIS
				case "United States":																																																																																																																																																																												 
					var _STATES = new Array( {data:"",label:""}
											,{data:"AK",label:"Alaska"}
											,{data:"AL",label:"Alabama"}
											,{data:"AR",label:"Arkansas"}
											,{data:"AZ",label:"Arizona"}
											,{data:"CA",label:"California"}
											,{data:"CO",label:"Colorado"}
											,{data:"CT",label:"Connecticut"}
											,{data:"DE",label:"Delaware"}
											,{data:"DC",label:"District of Columbia"}
											,{data:"FL",label:"Florida"}
											,{data:"GA",label:"Georgia"}
											,{data:"HI",label:"Hawaii"}
											,{data:"IA",label:"Iowa"}
											,{data:"ID",label:"Idaho"}
											,{data:"IL",label:"Illinois"}
											,{data:"IN",label:"Indiana"}
											,{data:"KS",label:"Kansas"}
											,{data:"KY",label:"Kentucky"}
											,{data:"LA",label:"Louisiana"}
											,{data:"MA",label:"Massachusetts"}
											,{data:"MD",label:"Maryland"}
											,{data:"ME",label:"Maine"}
											,{data:"MI",label:"Michigan"}
											,{data:"MN",label:"Minnesota"}
											,{data:"MS",label:"Mississippi"}
											,{data:"MO",label:"Missouri"}
											,{data:"MT",label:"Montana"}
											,{data:"NC",label:"North Carolina"}
											,{data:"ND",label:"North Dakota"}
											,{data:"NE",label:"Nebraska"}
											,{data:"NH",label:"New Hampshire"}
											,{data:"NJ",label:"New Jersey"}
											,{data:"NM",label:"New Mexico"}
											,{data:"NV",label:"Nevada"}
											,{data:"NY",label:"New York"}
											,{data:"OH",label:"Ohio"}
											,{data:"OK",label:"Oklahoma"}
											,{data:"OR",label:"Oregon"}
											,{data:"PA",label:"Pennsylvania"}
											,{data:"RI",label:"Rhode Island"}
											,{data:"SC",label:"South Carolina"}
											,{data:"SD",label:"South Dakota"}
											,{data:"TN",label:"Tennessee"}
											,{data:"TX",label:"Texas"}
											,{data:"UT",label:"Utah"}
											,{data:"VA",label:"Virginia"}
											,{data:"VT",label:"Vermont"}
											,{data:"WA",label:"Washington"}
											,{data:"WI",label:"Wisconsin"}
											,{data:"WV",label:"West Virginia"}
											,{data:"WY",label:"Wyoming"}
										);

/*
					_HTML += "<td width='125px'><label for='states'>States * </label></td>";
					_HTML += "<td>";
					_HTML += "<select name='statesprovinces' id='states'>";
*/
					_HTML += '<select name="statesprovinces_billing" id="statesprovinces_billing">';
					for( var i = 0; i < _STATES.length; i++ )
						_HTML += "<option value='"+ _STATES[i].data +"'>"+ _STATES[i].label +"</option>";
					_HTML += '</select>';
/*
					_HTML += "</select>";
					_HTML += "</td>";
*/
					$("#td_province").html(_HTML);
					$("#tr_statesprovinces_billing").fadeIn(500);

/* 					$("#provincesSTATES tr").html( _HTML ); */
/* 					$("#provincesSTATES").slideDown( 500 ); */
                    $("#code tr").html( '<td width="125px"><label for="postalCODE_billing">Zipcode * </label></td><td><input type="text" name="postalCODE_billing" id="postalCODE_billing" class="inputFORM" style="text-transform:uppercase;" value="" /></td>' ).slideDown( 500 );
					//$("#postalCODE_billing").mask("999999");
					break;
			}
		} else {
			$("#provincesSTATES").html( "" );
		}

		if(_PAYS == "France" || _PAYS == "Italy" || _PAYS == "Belgique" || _PAYS == "Spain" || _PAYS == "Portugal" || _PAYS == "United Kingdom" || _PAYS == "Ireland" || _PAYS == "Germany" || _PAYS == "Switzerland" || _PAYS == "Norway" || _PAYS == "Sweden" || _PAYS == "Finland" || _PAYS == "Netherland") {
			$("#td_province").html("<input type='text' name='statesprovinces_billing' id='statesprovinces_billing' value='"+_PAYS+"' />");
			$("#tr_statesprovinces_billing").fadeOut(500);
		}
	});
























	//CHANGE PAYS dans le SELECT --- SHIPPING
	$("#country_shipping").change(function(event){  
		var _PAYS = $(this).val();
		var _HTML = "";
		
		if( _PAYS != "-" )
		{
			switch( _PAYS )
			{
				// CANADA
				case "Canada":
					var _PROVINCES = Array({data:"",label:""}
											,{data:"AB",label:"Alberta"}
											,{data:"BC",label:"British Columbia"} 
											,{data:"MB",label:"Manitoba"}
											,{data:"NB",label:"New Brunswick"}
											,{data:"NL",label:"Newfoundland"}
											,{data:"NT",label:"Northwest Territories"}
											,{data:"NS",label:"Nova Scotia"}
											,{data:"NU",label:"Nunavut"}
											,{data:"ON",label:"Ontario"}
											,{data:"PE",label:"Prince Edward Island"}
											,{data:"QC",label:"Quebec"}
											,{data:"SK",label:"Saskatchewan"}
											,{data:"YT",label:"Yukon"}
										);

					//_HTML += "<td width='97px'><label for='statesprovinces_shipping'>Province * </label></td>";
					//_HTML += "<td>";
					//_HTML += "<select name='statesprovinces_shipping' id='statesprovinces_shipping'>";
					
					_HTML += '<select name="statesprovinces_shipping" id="statesprovinces_shipping">';
					for( var i = 0; i < _PROVINCES.length; i++ )
						_HTML += "<option value='"+ _PROVINCES[i].data +"'>"+ _PROVINCES[i].label +"</option>";
					_HTML += '</select>';
					
					//_HTML += "</select>";
					//_HTML += "</td>";
					
					$("#td_province_shipping").html(_HTML);
					$("#tr_statesprovinces_billing_shipping").fadeIn(500);
					
					//$("#provincesSTATES_shipping tr").html( _HTML );
/* 					$("#provincesSTATES_shipping").slideDown( 500 ); */
                    $("#code tr").html( '<td width="125px"><label for="postalCODE_shipping">Postal Code * </label></td><td><input type="text" name="postalCODE_billing" id="postalCODE_billing" class="inputFORM" style="text-transform:uppercase;" value="" /></td>' ).slideDown( 500 );
				//	$("#postalCODE_shipping").mask("a9a 9a9");
					break;
				
				// ÉTATS-UNIS
				case "United States":																																																																																																																																																																												 
					var _STATES = new Array( {data:"",label:""}
											,{data:"AK",label:"Alaska"}
											,{data:"AL",label:"Alabama"}
											,{data:"AR",label:"Arkansas"}
											,{data:"AZ",label:"Arizona"}
											,{data:"CA",label:"California"}
											,{data:"CO",label:"Colorado"}
											,{data:"CT",label:"Connecticut"}
											,{data:"DE",label:"Delaware"}
											,{data:"DC",label:"District of Columbia"}
											,{data:"FL",label:"Florida"}
											,{data:"GA",label:"Georgia"}
											,{data:"HI",label:"Hawaii"}
											,{data:"IA",label:"Iowa"}
											,{data:"ID",label:"Idaho"}
											,{data:"IL",label:"Illinois"}
											,{data:"IN",label:"Indiana"}
											,{data:"KS",label:"Kansas"}
											,{data:"KY",label:"Kentucky"}
											,{data:"LA",label:"Louisiana"}
											,{data:"MA",label:"Massachusetts"}
											,{data:"MD",label:"Maryland"}
											,{data:"ME",label:"Maine"}
											,{data:"MI",label:"Michigan"}
											,{data:"MN",label:"Minnesota"}
											,{data:"MS",label:"Mississippi"}
											,{data:"MO",label:"Missouri"}
											,{data:"MT",label:"Montana"}
											,{data:"NC",label:"North Carolina"}
											,{data:"ND",label:"North Dakota"}
											,{data:"NE",label:"Nebraska"}
											,{data:"NH",label:"New Hampshire"}
											,{data:"NJ",label:"New Jersey"}
											,{data:"NM",label:"New Mexico"}
											,{data:"NV",label:"Nevada"}
											,{data:"NY",label:"New York"}
											,{data:"OH",label:"Ohio"}
											,{data:"OK",label:"Oklahoma"}
											,{data:"OR",label:"Oregon"}
											,{data:"PA",label:"Pennsylvania"}
											,{data:"RI",label:"Rhode Island"}
											,{data:"SC",label:"South Carolina"}
											,{data:"SD",label:"South Dakota"}
											,{data:"TN",label:"Tennessee"}
											,{data:"TX",label:"Texas"}
											,{data:"UT",label:"Utah"}
											,{data:"VA",label:"Virginia"}
											,{data:"VT",label:"Vermont"}
											,{data:"WA",label:"Washington"}
											,{data:"WI",label:"Wisconsin"}
											,{data:"WV",label:"West Virginia"}
											,{data:"WY",label:"Wyoming"}
										);

/*
					_HTML += "<td width='97px'><label for='states_shipping'>States * </label></td>";
					_HTML += "<td>";
					_HTML += "<select name='statesprovinces_shipping' id='statesprovinces_shipping'>";
*/
					_HTML += '<select name="statesprovinces_shipping" id="statesprovinces_shipping">';
					for( var i = 0; i < _STATES.length; i++ )
						_HTML += "<option value='"+ _STATES[i].data +"'>"+ _STATES[i].label +"</option>";
					_HTML += '</select>';
						
						
						
/*					
					
					_HTML += "</select>";
					_HTML += "</td>";
*/
					$("#td_province_shipping").html(_HTML);
					$("#tr_statesprovinces_billing_shipping").fadeIn(500);
/* 					$("#provincesSTATES_shipping tr").html( _HTML ); */
/* 					$("#provincesSTATES_shipping").slideDown( 500 ); */
                    $("#code tr").html( '<td width="125px"><label for="postalCODE_shipping">Zipcode * </label></td><td><input type="text" name="postalCODE_shipping" id="postalCODE_shipping" class="inputFORM" style="text-transform:uppercase;" value="" /></td>' ).slideDown( 500 );
					//$("#postalCODE_shipping").mask("99999");
					break;
			}
		}
		else
		{
			$("#provincesSTATES").html( "" );
		}

		if(_PAYS == "France" || _PAYS == "Italy" || _PAYS == "Belgique" || _PAYS == "Spain" || _PAYS == "Portugal" || _PAYS == "United Kingdom" || _PAYS == "Ireland" || _PAYS == "Germany" || _PAYS == "Switzerland" || _PAYS == "Norway" || _PAYS == "Sweden" || _PAYS == "Finland" || _PAYS == "Netherland") {
			$("#td_province_shipping").html("<input type='text' name='statesprovinces_billing' id='statesprovinces_billing' value='"+_PAYS+"' />");
			$("#tr_statesprovinces_billing_shipping").fadeOut(500);
		}

	});





























	
	// FOCUS/BLUR DES CHAMPS
	$(".inputFORM").focus(function(event){ 

		$(this).css({

		  "background" : "#E6E6E6"
		
		});
		
	});

	$(".inputFORM").blur(function(event){ 

		$(this).css({

		  "background" : "#FFFFFF"
		
		});
		
	});


	//////////////
	// CHECKOUT //

		// ÉTAPE 03 DU CHECKOUT
		
		jQuery.fn.fadeToggle = function(speed, easing, callback) { 
		   return this.animate({opacity: 'toggle'}, speed, easing, callback); 
		}; 			

		
		$(".shipTO").click(function(event) {
			var shippinginfos = $(this).val();
			
			if(shippinginfos=="Billing address") {
				$("#shippinginfos").fadeOut(500);
			} else {
				$("#shippinginfos").fadeIn(500);
			}
		});
		
		
		$("#register").click(function(event){  
			$("#register_password").slideToggle( 500 );		
		});
		
		
		$("#password_02").blur(function(event){  
			if( $("#password_02").val() != $("#password_01").val() ) {
				$("#errors").html( "The password confirmation doesn't match" );
				$("#errors").slideDown( 500 );
				$("#password_02").addClass("redborder").fadeIn( 500 );
			} else {
				if( $("#password_02").val()  != "" ) {
					$("#errors").html( "" );
					$("#errors").slideUp( 500 );
					$("#password_02").removeClass("redborder").fadeIn( 500 );
				}
			}
		});
		

		$("#email_billing").blur(function(event){  
	
 			var _LOGIN = $("#email_billing").val();
			var user_fk = $("body").attr("DesignerID");
			$.ajax({
				type: "POST",
				url: webPATH+"includes/php/check-login.php",
				data:"login="+_LOGIN+"&user_fk="+user_fk,
			
				success: function( msg ) {
					if( msg == 1 ) {
						$("#errors").html( "The email address is already registered" );
						$("#errors").slideDown( 500 );
						$("#email_billing").addClass("redborder").fadeIn( 500 );
					} else {
						if( $("#email_billing").val()  != "" ) {
							$("#errors").html( "" );
							$("#errors").slideUp( 500 );
							$("#email_billing").removeClass("redborder").fadeIn( 500 );
						}
					}
				}
			});
		});


		
	// /ETAPE 03 (BILLIN/SHIPPING INFORMATIONS) DU PROCESSUS DE PAIEMENT
		$("#STEP3").click(function(event){  
			var nobug = true;
			var msg = "";
			var tableau = new Array( true,"","","" );	
			var _HTML = "";
			
		// /BILLING INFORMATIONS	
			est_la("email_billing", tableau, "Please fill in your email address /", "email_billing /","billing /");
			est_courriel_valide("email_billing", tableau, "Please use a valid email address /", "email_billing /","billing /");
			
			if(document.getElementById("register").checked==true) {
				est_la("password_01", tableau, "Please enter a password /", "password_01 /","billing /");
				est_la("password_02", tableau, "Please confirm your password /", "password_02 /","billing /");			
			} else

			est_la("Fname_billing", tableau, "Please fill in your first name /", "Fname_billing /","billing /");
			est_la("Lname_billing", tableau, "Please fill in your last name /", "Lname_billing /","billing /");
			est_la("address01_billing", tableau, "Please fill in your address /", "address01_billing /","billing /");	
			est_la("statesprovinces_billing", tableau, "Please fill in your province /", "statesprovinces_billing /","billing /");
			est_la("city_billing", tableau, "Please fill in your city /", "city_billing /","billing /");
			
			
			est_la("postalCODE_billing", tableau, "Please fill in your postal code /", "postalCODE_billing /","billing /");
	
			est_la("phone_billing", tableau, "Please fill in your phone number /", "phone_billing /","billing /");
						



			
		// /SHIPPING INFORMATIONS
			if(document.getElementById("anotherADDRESS").checked==true) {
				est_la("Fname_shipping", tableau, "Please fill in your first name /", "Fname_shipping /","shipping /");
				est_la("Lname_shipping", tableau, "Please fill in your last name /", "Lname_shipping /","shipping /");
				est_la("address01_shipping", tableau, "Please fill in your address /", "address01_shipping /","shipping /");	
				est_la("statesprovinces_shipping", tableau, "Please fill in your province /", "statesprovinces_shipping /","shipping /");
				est_la("city_shipping", tableau, "Please fill in your city /", "city_shipping /","shipping /");
				est_la("postalCODE_shipping", tableau, "Please fill in your postal code /", "postalCODE_shipping /","shipping /");
				
			}
			
			
			
			
			
			
			if($("#shippingMETHOD").val()=="") {
				tableau[0] = false;
				tableau[1] += "Please select shipping method /";
				tableau[2] += "shippingMETHOD /";
				tableau[3] += "billing /";
			}
			

			if(tableau[0]!=false) {
				if(document.getElementById("register").checked==true) {
					var users_fk = $("body").attr("DesignerID");
					var _LOGIN = $("#email_billing").val();
					$.ajax({
						type: "POST",
						url: webPATH+"includes/php/check-login.php",
						data:"login="+_LOGIN+"&user_fk="+users_fk,
						success: function( msg ) {
							if( msg == 1 ) {
								$("#errors").html( "The email address is already registered" );
								$("#errors").slideDown( 500 );
							} else {
								$("#form_billing").submit();
							}
						}
					});
				} else
					$("#form_billing").submit();
			} else {
				var aMSG = tableau[1].split(" /");
				var aFIELD = tableau[2].split(" /");
				var aCONTAINER = tableau[3].split(" /");
				var _HTML_billing = "";
				var _HTML_shipping = "";

				for( var i = 0; i < aMSG.length; i++ ) {
					if( aMSG[i] != "" ) {
						if( aCONTAINER[i] == "shipping" )
							_HTML_shipping += "<li>"+aMSG[i]+"</li>";
						else if( aCONTAINER[i] == "billing" )
							_HTML_billing += "<li>"+aMSG[i]+"</li>";
						
						$("#"+aFIELD[i]).addClass("redborder").fadeIn( 500 );
					}
				}
				
				$("#errors").html( _HTML_billing );
				$("#errors").slideDown( 500 );
				
				$("#errors_shipping").html( _HTML_shipping );
				$("#errors_shipping").slideDown( 500 );
			}
			
		});
		
	// CHECKOUT //
	//////////////


function valid_step3() {
			var nobug = true;
			var msg = "";
			var tableau = new Array( true,"","","" );	
			var _HTML = "";
			
		// /BILLING INFORMATIONS	
			est_la("email_billing", tableau, "Please fill in your email address /", "email_billing /","billing /");
			est_courriel_valide("email_billing", tableau, "Please use a valid email address /", "email_billing /","billing /");
			
			if(document.getElementById("register").checked==true) {
				est_la("password_01", tableau, "Please enter a password /", "password_01 /","billing /");
				est_la("password_02", tableau, "Please confirm your password /", "password_02 /","billing /");			
			} else

			est_la("Fname_billing", tableau, "Please fill in your first name /", "Fname_billing /","billing /");
			est_la("Lname_billing", tableau, "Please fill in your last name /", "Lname_billing /","billing /");
			est_la("address01_billing", tableau, "Please fill in your address /", "address01_billing /","billing /");	
			est_la("statesprovinces_billing", tableau, "Please fill in your province /", "statesprovinces_billing /","billing /");
			est_la("city_billing", tableau, "Please fill in your city /", "city_billing /","billing /");
			
			
			est_la("postalCODE_billing", tableau, "Please fill in your postal code /", "postalCODE_billing /","billing /");
	
			est_la("phone_billing", tableau, "Please fill in your phone number /", "phone_billing /","billing /");
						



			
		// /SHIPPING INFORMATIONS
			if(document.getElementById("anotherADDRESS").checked==true) {
				est_la("Fname_shipping", tableau, "Please fill in your first name /", "Fname_shipping /","shipping /");
				est_la("Lname_shipping", tableau, "Please fill in your last name /", "Lname_shipping /","shipping /");
				est_la("address01_shipping", tableau, "Please fill in your address /", "address01_shipping /","shipping /");	
				est_la("statesprovinces_shipping", tableau, "Please fill in your province /", "statesprovinces_shipping /","shipping /");
				est_la("city_shipping", tableau, "Please fill in your city /", "city_shipping /","shipping /");
				est_la("postalCODE_shipping", tableau, "Please fill in your postal code /", "postalCODE_shipping /","shipping /");
				
			}
			
			
			
			
			
			
			if($("#shippingMETHOD").val()=="") {
				tableau[0] = false;
				tableau[1] += "Please select shipping method /";
				tableau[2] += "shippingMETHOD /";
				tableau[3] += "billing /";
			}
			

			if(tableau[0]!=false) {
				if(document.getElementById("register").checked==true) {
					var users_fk = $("body").attr("DesignerID");
					var _LOGIN = $("#email_billing").val();
					$.ajax({
						type: "POST",
						url: webPATH+"includes/php/check-login.php",
						data:"login="+_LOGIN+"&user_fk="+users_fk,
						success: function( msg ) {
							if( msg == 1 ) {
								$("#errors").html( "The email address is already registered" );
								$("#errors").slideDown( 500 );
							} else {
								$("#form_billing").submit();
							}
						}
					});
				} else
					$("#form_billing").submit();
			} else {
				var aMSG = tableau[1].split(" /");
				var aFIELD = tableau[2].split(" /");
				var aCONTAINER = tableau[3].split(" /");
				var _HTML_billing = "";
				var _HTML_shipping = "";

				for( var i = 0; i < aMSG.length; i++ ) {
					if( aMSG[i] != "" ) {
						if( aCONTAINER[i] == "shipping" )
							_HTML_shipping += "<li>"+aMSG[i]+"</li>";
						else if( aCONTAINER[i] == "billing" )
							_HTML_billing += "<li>"+aMSG[i]+"</li>";
						
						$("#"+aFIELD[i]).addClass("redborder").fadeIn( 500 );
					}
				}
				
				$("#errors").html( _HTML_billing );
				$("#errors").slideDown( 500 );
				
				$("#errors_shipping").html( _HTML_shipping );
				$("#errors_shipping").slideDown( 500 );
			}

}





	//////////////////
	// REGISTRATION //
	
		// VÉRIFICATION DANS LA BD SI LE EMAIL EXISTE DEJA
		$("#login").blur(function(event){  
		
			var nobug = true;
			var msg = "";
			var tableau = new Array(true,'','');
			var _HTML = "";
		
			est_courriel_valide("login", tableau, "Please, use a valid email address.*", "login ");
		
			if( tableau[0] == false )
			{
				document.getElementById( "login" ).value = "";

				_HTML += "<table align='center'><tr><td><img src='"+webPATH+"images/warning.gif'/></td><td>The email address you have specified appears to be invalid.</td></tr></table> <br /><br />";
				_HTML += '<a href="javascript:doNOTremove();" title="OK"><img src="'+webPATH+'images/ok.gif" border="0" alt="OK" /></a>';
				
				$("td#dropMSG").html( _HTML );
				$("div#cache").fadeIn();
				$("table#box").fadeIn();
				
				$("#login").focus();
			}
			else
			{
				var _LOGIN = $(this).val();
				$.ajax({
					type: "POST",
					url: webPATH+"includes/php/check-login.php",
					data:"login="+_LOGIN,
				
					success: function( msg )
					{
						if( msg == 1 )
						{
							document.getElementById( "login" ).value = "";
						
							_HTML += "<table align='center'><tr><td><img src='"+webPATH+"images/warning.gif'/></td><td>The email address specified is already in use.</td></tr></table> <br /><br />";
							_HTML += '<a href="javascript:doNOTremove();" title="OK"><img src="'+webPATH+'images/ok.gif" border="0" alt="OK" /></a>';
							
							$("td#dropMSG").html( _HTML );
							$("div#cache").fadeIn();
							$("table#box").fadeIn();
							
							$("#login").focus();
						}
					}
				});
			}
	
		});
	
		
		// VÉRIFICATION DU MOT DE PASSE
		$("#password02").blur(function(event){  
		
			var _PWD01 = $("#password01").val();
			var _PWD02 = $("#password02").val();
			var _HTML = "";
	
			if( _PWD02 != _PWD01 )
			{
				document.getElementById( "password02" ).value = "";
	
				_HTML += "<table align='center'><tr><td><img src='"+webPATH+"images/warning.gif'/></td><td>The passwords you have entered do not match.</td></tr></table> <br /><br />";
				_HTML += '<a href="javascript:doNOTremove();" title="OK"><img src="'+webPATH+'images/ok.gif" border="0" alt="OK" /></a>';
				
				$("td#dropMSG").html( _HTML );
				$("div#cache").fadeIn();
				$("table#box").fadeIn();
			}
	
		});
		
		
		
			
		
		
		
		
		
		
		
	// REGISTRATION //
	//////////////////
	
	
	
	
	
	
	
	
	
	
	
	

	
	
	
	/// ZOOM PRODUCT
	$(".jqzoom").jqzoom({
	    zoomWidth: 300,
	    zoomHeight: 300,
	    showEffect:'show',
	    hideEffect:'fadeout',
	    fadeoutSpeed: 'slow',
	    title :false
	});	




	
	/// EDIT PROFILE
	$("#edit-profile").click(function(event){  		
		$("#profile").slideUp("slow");
		$("#editFORM").slideDown("slow");
	});
	/// CANCEL EDIT PROFILE
	$("#cancel-profile").click(function(event){  		
		$("#editFORM").slideUp("slow");
		$("#profile").slideDown("slow");
		
		return false;
	});		

	$("#save-profile").click(function(event){
		var _ID = $("#id").val();  		
		var _FIRSTNAME = $("#Fname").val();
		var _LASTNAME = $("#Lname").val();
		var _ADDRESS01 = $("#address01").val();
		var _ADDRESS02 = $("#address02").val();

		var _CITY = $("#city").val();
		var _POSTALCODE = $("#postalCODE").val();
		var _PHONE = $("#phone").val();
		var _CELL = $("#cell").val();
						
		$.ajax({
			type: "POST",
			url: webPATH+"includes/php/edit-profile.php",
			data:"id="+_ID+"&Fname="+_FIRSTNAME+"&Lname="+_LASTNAME+"&address01="+_ADDRESS01+"&address02="+_ADDRESS02+"&city="+_CITY+"&postalCode="+_POSTALCODE+"&phone="+_PHONE+"&cell="+_CELL,
			success: function( msg ) {
				$("#editFORM").slideUp("slow");
				$("#profile").slideDown("slow");
			}
		});
	});	
	
	
	
	
	
	
	
	
	// /CONNEXION DU CLIENT
	$("#CONNEXION").click(function(event) {
		var nobug = true;
		var msg = "";
		var tableau = new Array(true,'','');	
					
		est_la("email", tableau, "Please, enter an email address/", "email ");
		est_courriel_valide("email", tableau, "Please, use a valid email address/", "email ");
		est_la("password", tableau, "Please, enter a password/", "password");
		
		
		//	Si form pas valide
		if(tableau[0] != false) {
			var emailADDRESS = $("#email").val();
			var password = $("#password").val();
			var URLName = $("body").attr( "URLName" );
			var users_fk = $("body").attr("DesignerID");
			
			$.ajax({
				type: "POST",
				url: webPATH+"includes/php/connexion.php",
				data:"emailADDRESS="+emailADDRESS+"&password="+password+"&users_fk="+users_fk,
			
				success: function( msg )
				{
					
				
					if( msg == "FALSE" ) {
						$("#errors").html( "<li>Your email address/password appears to be wrong</li>" );
						$("#errors").slideDown( 500 );
					} else {
						$("#customerID").val( msg );
						$("#form_signin").attr( "action",_HTTPPATH+"/checkout-1.1/" );
						$("#form_signin").submit();
					}	
				}
			});
		} else {
			var aMSG = tableau[1].split("/");
			var _HTML = "";
			
			for( var i = 0; i < aMSG.length; i++ ) {
				if( aMSG[i] != "" )
					_HTML += "<li>"+aMSG[i]+"</li>";	
			}
			
			$("#errors").html( _HTML );
			$("#errors").slideDown( 500 );
		}
			
		return false;
	});
});



function REQUESTdelete( urlNAME,itemROW,itemNAME )
{
	var _CONTENT = "";
	
	_CONTENT += '<p>Are you sure you want to remove <strong>'+ itemNAME +'</strong> from your shopping cart?</p>';
	_CONTENT += '<br />';
	
	_CONTENT += "<form name='deleteREQUEST' id='deleteREQUEST' method='post' action='"+_HTTPPATH+"/remove-item/' >";
	_CONTENT += '	<table border="0" cellpadding="0" cellspacing="5" align="center">';
	_CONTENT += '   	<tr>';
	_CONTENT += '       	<td>';   
	_CONTENT += '           	<input type="hidden" name="rowITEM" id="rowITEM" value="'+ itemROW +'" />';
	_CONTENT += '               <a href="javascript:doREMOVE();" title="YES" id="YES"><img src="'+webPATH+'images/yes.png" border="0" alt="YES" /></a>';
	_CONTENT += '           </td>';
	_CONTENT += '           <td><a href="javascript:doNOTremove();" title="NO"><img src="'+webPATH+'images/no.png" border="0" alt="NO" /></a></td>';
	_CONTENT += '		</tr>';
	_CONTENT += '	</table>';
	_CONTENT += '</form>';
	
	$("td#dropMSG").html( _CONTENT );
	$("div#cache").fadeIn();
	$("table#box").fadeIn();
}




function doNOTremove()
{
	var _CONTENT = "";
		
	$("table#box").fadeOut();
	$("div#cache").fadeOut();
	//$("td#dropMSG").html(_CONTENT);
}

function doREMOVE()
{
	$("#deleteREQUEST").submit();
}


// /Session expiré, on redirige
function sessionEXPIRE()
{
	var _CONTENU = "";
	
	_CONTENU += '<br><div align="center"><img src="'+webPATH+'images/warning.gif"/><br /><p>Your session has expired.<br>You will be redirected to the main page.</p></div>';
	_CONTENU += "<form name='sessionEXPIRE' id='sessionEXPIRE' method='post' action='"+webPATH+"' >";
	_CONTENU += '	<table border="0" cellpadding="0" cellspacing="5" align="center">';
	_CONTENU += '   	<tr>';
	_CONTENU += '       	<td>';
	_CONTENU += '           	<input type="image" src="'+webPATH+'images/ok.gif" class="ROLLOVER button" alt="OK" />';
	_CONTENU += '           </td>';
	_CONTENU += '		</tr>';
	_CONTENU += '	</table>';
	_CONTENU += '</form>';
	
	_HTML = initTABLEAU( "350px",_CONTENU ); 			

	$(document).ready(function(e){
		$.nyroModalManual({
			bgColor: '#000000',
			content: _HTML
		});
	});
	
	
	
	return false;
}






function cancelEDIT()
{
	var _CONTENT = "";
		
	$("table#box").fadeOut();
	$("div#cache").fadeOut();
	//$("td#dropMSG").html(_CONTENT);
}

function updateEDIT()
{
	document.getElementById( "editFORM" ).submit();
}







//////////////////////////////////////
// VALIDATION DES CHAMPS DE FORMULAIRE
function est_la(le_id, retour, msg, champ, error_container) {
	var nobug = retour[0];
    var obj = document.getElementById( le_id );
	
		if(trim(obj.value) == "") {
			retour[1] += msg;
			retour[2] += champ;
			retour[3] += error_container;
			if (nobug==true)
				obj.focus();
			retour[0] = false;
		}
		
	return retour[0];
}

function trim(val) {
	if (!val) 
		return val;
	
	while(val.charAt(0) == ' ') val = val.substring(1,val.length);
	while(val.charAt(length)==' ') val = val.substring(0,val.length-1);
	
	return val;
}

function est_courriel_valide(le_id, retour, msg, champ, error_container)
{
	var nobug = retour[0];
    var obj = document.getElementById( le_id );
	var at = obj.value.indexOf("@")
	var lAt = obj.value.lastIndexOf("@")
	var dot = obj.value.indexOf(".") 
	var lDot = obj.value.lastIndexOf(".")
	var x = obj.value.charAt(0)
	
	if(trim(obj.value)!="")
	{
		if((at <= 0) || (dot <= 0) || (lAt != at) || (lDot < at) || (lDot == (obj.value.length-1)) || ((at +1) == dot) || (obj.value.indexOf("..") >=0) || (! caracteres(obj.value)) || ((lDot+3) < obj.value.length-1))
		{
			retour[1] += msg;
			retour[2] += champ;
			retour[3] += error_container;
			if (nobug==true)
				obj.focus();
			retour[0] = false;
		}
	}
}

function caracteres(valu) 
{
  var parsed = true;
  
  for (var i=0; i < valu.length; i++) 
  {
  	if (i==0)
		var caracteres = "abcdefghijklmnopqrstuvwxyz.";
	else if (i==valu.length-1 || i==valu.length-2 || i==valu.length-1)
		var caracteres = "abcdefghijklmnopqrstuvwxyz";
	else
  		var caracteres = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
	var lettre = valu.charAt(i).toLowerCase();
    if (caracteres.indexOf(lettre) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
} //////////////////////////
// VALIDATION DES CHAMPS DE FORMULAIRE
//////////////////////////////////////












// SIGN IN
function signinVALIDATION()
{
	var nobug = true;
	var msg = "";
	var tableau = new Array(true,'','');	
	
	document.getElementById( "erreurs" ).innerHTML = "";
	
	document.getElementById( "email" ).style.borderColor = "#000000";
	document.getElementById( "password" ).style.borderColor = "#000000";
		
	est_la("email", tableau, "Please fill the email field./", "email ");
	est_courriel_valide("email", tableau, "Please, use a valid email address./", "email ");
	est_la("password", tableau, "Please fill the password field.", "password");
	
	
	//	Si form pas valide
	if(tableau[0] != false)
		document.getElementById( "form_signin" ).submit();
	else
	{
		var sErreurs = "";
		var aMSG = tableau[1].split("/");
		var aCHAMPS = tableau[2].split(" ");
		
		for( var i = 0; i < aCHAMPS.length; i++ )
		{
			if( aMSG[i] != "" && aCHAMPS[i] != "" )
			{
				sErreurs += "<li>"+ aMSG[i] +"</li>";
				document.getElementById( aCHAMPS[i] ).style.borderColor = "#F20000";
			}
		}
		
		document.getElementById( "erreurs" ).innerHTML = sErreurs;
		$("#erreurs").fadeIn("slow");
	}
}

// CONNEXION
function connexion()
{
	var nobug = true;
	var msg = "";
	var tableau = new Array(true,'','');	
	var URLName = document.getElementById( "URLNAME" ).value;
	var _URL = $("#connexion").attr("URL");
	
	document.getElementById( "erreurs" ).innerHTML = "";
	
	document.getElementById( "email" ).style.borderColor = "#000000";
	document.getElementById( "password" ).style.borderColor = "#000000";
		
	est_la("email", tableau, "Please fill the email field./", "email ");
	est_courriel_valide("email", tableau, "Please, use a valid email address./", "email ");
	est_la("password", tableau, "Please fill the password field.", "password");
	
	
	//	Si form pas valide
	if(tableau[0] != false)
	{
			var emailADDRESS = document.getElementById( "email" ).value;
			var password = document.getElementById( "password" ).value;

			$.ajax({
				type: "POST",
				url: webPATH+"includes/php/connexion.php",
				data:"emailADDRESS="+emailADDRESS+"&password="+password,
			
				success: function( msg )
				{
					if( msg == "FALSE" )
					{
						sErreurs += "<p>The email address/password you entered is wrong!</p>";
						sErreurs += "<a href='javascript:doNOTremove();' class='ok' title='OK'><img src='"+webPATH+"images/ok.gif' alt='OK' border='0' /></a>";
						$("td#dropMSG").html( sErreurs );
						$("div#cache").fadeIn();
						$("table#box").fadeIn();
					}
					else
					{
						$("#customerID").val( msg );
						$("#form_signin").submit();
					}	
				}
			});
	}
	else
	{
		var sErreurs = "";
		var aMSG = tableau[1].split("/");
		var aCHAMPS = tableau[2].split(" ");
		
		for( var i = 0; i < aCHAMPS.length; i++ )
		{
			if( aMSG[i] != "" && aCHAMPS[i] != "" )
			{
				sErreurs += "<li>"+ aMSG[i] +"</li>";
				document.getElementById( aCHAMPS[i] ).style.borderColor = "#F20000";
			}
		}
		
		document.getElementById( "erreurs" ).innerHTML = sErreurs;
		$("#erreurs").fadeIn("slow");
	}
}
















// CHANGER DE SAISON
function changeSAISONS()
{
	window.location.href = document.getElementById( "sltSaisons" ).value;
}


// AJOUTER LE PRODUIT AU PANIER
function addtocart( B_validation )
{
	if( B_validation == true )
	{
		var tableau = new Array();
		var color = document.getElementById( "sltColor" ).value;
		var size = document.getElementById( "sltSize" ).value;
		var sErreurs = new String();
		
		document.getElementById( "sltColor" ).style.borderColor = "#000000";		
		document.getElementById( "sltSize" ).style.borderColor = "#000000";		
		
		if( color == "0" )
			tableau.push( new Array( "sltColor","Please select a color" ) );
			
		if( size == "0" )
			tableau.push( new Array( "sltSize","Please select a size" ) );
	
		
		if( tableau.length == 0 )
			document.getElementById( "frmProduct" ).submit();
		else
		{
			for( var i = 0; i < tableau.length; i++ )
			{
				document.getElementById( tableau[i][0] ).style.borderColor = "#FF0000";
				
				sErreurs += "<li>"+ tableau[i][1] +"</li>";
				document.getElementById( "erreurs" ).innerHTML = sErreurs;
				$("#erreurs").fadeIn("slow");
			}
		}
	}
	else
		document.getElementById( "frmProduct" ).submit();
}


// RETIRER LE PRODUIT DU PANIER
function removeITEM( DESIGNER,sessionROW,itemNAME )
{
	if( confirm( "Are you sure you want to remove "+ itemNAME +" from your shopping cart?" ) )
		window.location.href = webPATH + DESIGNER +"/remove-item/"+ sessionROW +"/";
}




// /CONSTRUCTION D'UN TABLEAU DYNAMIQUE
function initTABLEAU( _LARGEUR,_HTML ) {
	
	var _TABLEAU = "";
	
	_TABLEAU += '<table border="0" cellspacing="0" cellpadding="0" width="375px">';
	_TABLEAU += '    <tr>';
	_TABLEAU += '        <td class="topLEFT">&nbsp;</td>';
	_TABLEAU += '        <td class="top"></td>';
	_TABLEAU += '        <td class="topRIGHT">&nbsp;</td>';
	_TABLEAU += '    </tr>';
	_TABLEAU += '    <tr>';
	_TABLEAU += '        <td class="LEFT">&nbsp;</td>';
	_TABLEAU += '        <td style="background:#ffffff;">';
	
	_TABLEAU += 			_HTML;
	
	_TABLEAU += '        </td>';
	_TABLEAU += '        <td class="RIGHT">&nbsp;</td>';
	_TABLEAU += '    </tr>';
	_TABLEAU += '    <tr>';
	_TABLEAU += '        <td class="bottomLEFT">&nbsp;</td>';
	_TABLEAU += '        <td class="bottom">&nbsp;</td>';
	_TABLEAU += '        <td class="bottomRIGHT">&nbsp;</td>';
	_TABLEAU += '    </tr>';
	_TABLEAU += '</table>';



	// /OUTPUT DU TABLEAU
	return _TABLEAU;
	
}