// JavaScript Document
	image0 = new Image();
	image0.src = "images/bg_html.jpg";

	$(document).ready(function() {
	   
	   
	 //  $("a[href*='#']").click(function(){
	//		  alert('En construction!');
	//	 })
	   
	   
			 $("a.fav").click(function(){
					 
				 var iddetail = encodeURI($(this).attr('rel'))
					 
					  $.ajax({
						  type: "POST",
						  url: 'ajax/cart.asp',
						  cache: false,
						  data: "iddetail=" + iddetail ,
						  success: function(msg){
						    $(".add" + iddetail ).show("slow").hide("slow") ;
 						  }
					  });	
								   
				 });	
	   
	   
	   
			 $(".selectWood a").click(function(){

				 var theImage =  $(this).attr('rel') 
				 var theTitle =  $(this).text() 
				 var groupClass =  $(this).attr('class') 
				 
				 $("." + groupClass + " a").removeClass('sel')
				 $(this).addClass('sel')
					 
			    $("." + groupClass + " img").eq(0).attr('src', theImage).attr('alt', theTitle);
								   
			  });	
	   
	   
						$("form#formcontact").submit(function() {
																							 
							 var theForm = $(this) 
							 var theFormID = $(this).attr('id') 
							 var theName = $("#" + theFormID + " input#NOM").val();
							// var theVille = $("#" + theFormID + " input#VILLE").val();
							// var theMessage = $("#" + theFormID + " input#MESSAGE").val();
							 var theEmail = $("#" + theFormID + " input#EMAIL").val();
							 var themessage = 'S.v.p verifier le(s) champ(s) suivant: \n'
							 
							 var hasError = false;
		                     var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
							// $("#" + theFormID + " .error").remove(); 
							 $("#" + theFormID + " .error").removeClass('error'); 
							 
							 
							if(theName == '') {
								//$("#" + theFormID + " input#NOM").before('<span class="error">*</span>');
								$("#" + theFormID + " input#NOM").addClass('error');
								
								themessage = themessage + "\n- Votre Nom";
								hasError = true;
							}
							
//							if(theVille == '') {
//								//$("#" + theFormID + " input#NOM").before('<span class="error">*</span>');
//								$("#" + theFormID + " input#VILLE").addClass('error');
//								
//								themessage = themessage + "\n- Votre Ville";
//								hasError = true;
//							}
							

							if(theEmail == '') {
								//$("#" + theFormID + " input#EMAIL").before('<span class="error">*</span>');
								$("#" + theFormID + " input#EMAIL").addClass('error');
								themessage = themessage + "\n- Votre Courriel";
								hasError = true;
							} else if(!emailReg.test(theEmail)) {
								//$("#" + theFormID + " input#EMAIL").before('<span class="error">*</span>');
								$("#" + theFormID + " input#EMAIL").addClass('error');
								themessage = themessage + "\n- Votre Courriel";
								hasError = true;
							}
					
							
						  if(hasError == false) {
							  // theForm.submit();
									
							 	$("form#" + theFormID + " input[type='submit']").before('<img class="spinner" src="http://bin.webloft.ca/images/wait.gif">');
									
								$.ajax({
								  type: "POST",
								  url: 'ajax/clients_request.asp',
								  cache: false,
								  data: $("form#" + theFormID ).serialize(),
								  success: function(msg){
									  
										if(msg.indexOf("error") > 0 ){
											alert(msg);
											return false;
										 } else {  
										   $("form#" + theFormID + " input[type='submit']").before('<span class="good">' + msg + '</span>');
										   $("form#" + theFormID + " input[type='submit']").remove() ;
 										   $("img.spinner").html(msg).remove() ;
									   }
									  
								  }
								});				   
					
								
							   
						  }	else {
							  
							  alert(themessage);
							  return false;
						 }						
						   return false;
						 });
						 
                 //thickbox replacement
				  var closeModal = function(hash)
				  {
					  var $modalWindow = $(hash.w);
			  
					  //$('#jqmContent').attr('src', 'blank.html');
					  $modalWindow.fadeOut('2000', function()
					  {
						  hash.o.remove();
						  //refresh parent
			  
						  if (hash.refreshAfterClose === 'true')
						  {
			  
							  window.location.href = document.location.href;
						  }
					  });
				  };
				  var openInFrame = function(hash)
				  {
					  var $trigger = $(hash.t);
					  var $modalWindow = $(hash.w);
					  var $modalContainer = $('iframe', $modalWindow);
					  var myUrl = $trigger.attr('href');
					  var myTitle = $trigger.attr('title');
					  var newWidth = 0, newHeight = 0, newLeft = 0, newTop = 0;
					  $modalContainer.html('').attr('src', myUrl);
					  //$('#jqmTitleText').text(myTitle);
					  myUrl = (myUrl.lastIndexOf("#") > -1) ? myUrl.slice(0, myUrl.lastIndexOf("#")) : myUrl;
					  var queryString = (myUrl.indexOf("?") > -1) ? myUrl.substr(myUrl.indexOf("?") + 1) : null;
			  
					  if (queryString != null && typeof queryString != 'undefined')
					  {
						  var queryVarsArray = queryString.split("&");
						  for (var i = 0; i < queryVarsArray.length; i++)
						  {
							  if (unescape(queryVarsArray[i].split("=")[0]) == 'width')
							  {
								  var newWidth = queryVarsArray[i].split("=")[1];
							  }
							  if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'height')
							  {
								  var newHeight = queryVarsArray[i].split("=")[1];
							  }
							  if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'jqmRefresh')
							  {
								  // if true, launches a "refresh parent window" order after the modal is closed.
			  
								  hash.refreshAfterClose = queryVarsArray[i].split("=")[1]
							  } else
							  {
			  
								  hash.refreshAfterClose = false;
							  }
						  }
						  // let's run through all possible values: 90%, nothing or a value in pixel
						  if (newHeight != 0)
						  {
							  if (newHeight.indexOf('%') > -1)
							  {
			  
								  newHeight = Math.floor(parseInt($(window).height()) * (parseInt(newHeight) / 100));
			  
							  }
							  var newTop = Math.floor(parseInt($(window).height() - newHeight) / 2);
						  }
						  else
						  {
							  newHeight = $modalWindow.height();
						  }
						  if (newWidth != 0)
						  {
							  if (newWidth.indexOf('%') > -1)
							  {
								  newWidth = Math.floor(parseInt($(window).width() / 100) * parseInt(newWidth));
							  }
							  var newLeft = Math.floor(parseInt($(window).width() / 2) - parseInt(newWidth) / 2);
			  
						  }
						  else
						  {
							  newWidth = $modalWindow.width();
						  }
			  
						  // do the animation so that the windows stays on center of screen despite resizing
						  $modalWindow.css({
							  width: newWidth,
							  height: newHeight,
							  opacity: 0
						  }).jqmShow().animate({
							  width: newWidth,
							  height: newHeight,
							  top: newTop,
							  left: newLeft,
							  marginLeft: 0,
							  opacity: 1
						  }, 'slow');
					  }
					  else
					  {
						  // don't do animations
						  $modalWindow.jqmShow();
					  }
			  
				  }
			  
				  $('#modalWindow').jqm({
					  overlay: 60,
					  modal: false,
					  trigger: 'a.thickbox',
					  target: '#jqmContent',
					  onHide: closeModal,
					  onShow: openInFrame
				  });
	  
						 
						 
	  });

