//Document JavaScript par JFRanger Juin 2008

   newUniqueID = function(){
	  return (new Date()).getTime() % 1000000000;
	 }
	 
 
		jQuery.preloadImages = function()
		{
		  for(var i = 0; i<arguments.length; i++)
		  {
			jQuery("<img>").attr("src", arguments[i]);
		  }
}


//										
//												if ($.browser.safari) {
//												 document.location = 'safari.asp'
//												  //alert('you are using SAFARI')
////													 $.ajax({
////													  type: "GET",
////													  url: "evolio.js",
////													  dataType: "script"
////													});
//											   } 




          $(document).ready(function(){$("a").bind("focus",function(){if(this.blur)this.blur();});});

			 
			 $(document).ready(function() {
										
				  // $('#outerWrapper').hide();	
				  // $('#animation').hide();	
				 //  $('#promoflash').hide();				
			      // $('#menu').hide();
				//   $('#pagemoto').hide();  		
				 //  $('#pageboutique').hide();  		
				 
	            //  $('#outerWrapper').fadeIn(5000, function(){ $('#promoflash').show() });
				
	   $("td.calendarEventOnddddd").click(function(){
											
			var theLink = encodeURI($(this).attr('rel'))								
									
				 $("#eventdetail").load( theLink + ' #content',  function(){ 
				      	//$.scrollTo( $('#scrolllink'), {speed:1000} );
				   })					
									
//			  $("#dynamicContent").slideUp('slow', function(){ 
//				 $("#dynamicContent").load( theLink + ' #dynamicContent',  function(){ 
//				    $("#dynamicContent").slideDown('slow',function(){ $.scrollTo( $('#scrolllink'), {speed:1000} );});
//				   })
//				})
			  
			 return false;
		 })
				
				  
										
			      $("ul#ticker01").liScroll();
				  
			
				   $("#dynamicnews").click( function() {
						document.location = '?idpage=2030'							 
					   });  
				   
				   $("#containerTopSite, #containerTopBoutique, #containerTop, #containerTopSiteblanc").click( function() {
						document.location = 'http://www.monettesports.com'							 
					   });  
				   
			  

//								$.ajax({
//								  type: "POST",
//								  url: 'cart.asp',
//								  cache: false,
//								  data: "action=showcart&noCache=" + newUniqueID ,
//								  success: function(msg){
//									 $("#cart").html(msg).fadeIn('slow') ;
//								  }
//								});				   
				   
				   
				   
				  $('#promotions a[@href*=http://showrooms]').click(function(){
					  theLink = encodeURI($(this).attr('href'))	
					 document.location = '?action=showroom&url=' + theLink		
					  // alert('?action=showroom&url=' + theLink	)
					  return false;
					  
//								$('#contentWrapper').fadeOut('fast', function() {
//																			  
//									 $("#dynamicnews").after('<div id=theloader style="background : url(images/body-loader.gif) no-repeat 355px 150px ; width:100%; height:200px; postion:absolute;" ></div>');
//																				
//										 $('#sitecontenublanc').load('contentShowRoom.asp?url='+theLink,{noCache:newUniqueID()}, function() {
//																											  
//													 $('#theloader').remove(); 		
//													$('#pagesiteblanc').fadeIn('fast'); 		
//													
//												 } ) ;																				
//											 })
//					  
//					  
// 				      return false;
				  });
					
				   
				   
				   
/*				   $('#menuboutique a:not(a.parmanufacturier)').not("[href^=content]").click( function() {

                                theLink = $(this).attr('href');
								// window.location.hash = 'boutique';
								 
								
								$('#contentWrapper').fadeOut('fast', function() {
																			  
									 $("#dynamicnews").after('<div id=theloader style="background : url(images/body-loader.gif) no-repeat 355px 150px ; width:100%; height:200px; postion:absolute;" ></div>');
																				
										 $('#boutiquecontenu').load(theLink,{noCache:newUniqueID()}, function() {
																											  
													 $('#theloader').remove(); 		
													$('#pageboutique').fadeIn('fast'); 		
													
												 } ) ;																				
											 })
								  
								 return false;
						
					   });  
				   				   
*/
					
					
			
//				  $('#menuboutique a[@href*=content]').click(function(){
//					  theLink = encodeURI($(this).attr('href'));
//					  openPage(theLink);
// 				      return false;
//				  });
			
			
			
			
			
			
//				   $('#magasin a, a.pagepromo').click( function() {
//														
//								 theLink = $(this).attr('href');
//								 window.location.hash = 'pages';	
//								 openPage(theLink);
//								 return false;
//						
//					   });  
//				   
					
					
					
					
			
//				   $('#motosUsagees a').click( function() {
//														
//								 theLink = $(this).attr('href');
//								 window.location.hash = 'motosusagees';
//								 
//								  $('#contentWrapper').fadeOut('fast', function() {
//										 $('#sitecontenublanc').load(theLink,{noCache:newUniqueID()}, function() {
//													$('#pagesiteblanc').fadeIn('fast'); 			  
//												 } ) ;																				
//											 })
//								    return false;
//					   });  
				   
					
					
				  $('a.parmanufacturier').click(function(){
				     jQuery.facebox({ ajax: $(this).attr('href') });
				    return false;
				  });
			
			
					
					
				  $('#promotions a[@href*=detail]').click(function(){
					  //theLink = encodeURI($(this).attr('href')+'&promo=true')					
				     jQuery.facebox({ ajax: $(this).attr('href')+'&promo=true' });
				   return false;
				  });
					

//				  $('#promotions a[@href*=boutique2]').click(function(){
//					     theLink = encodeURI($(this).attr('href'))					
//								$('#contentWrapper').fadeOut('fast', function() {
//																			  
//									 $("#dynamicnews").after('<div id=theloader style="background : url(images/body-loader.gif) no-repeat 355px 150px ; width:100%; height:200px; postion:absolute;" ></div>');
//																				
//										 $('#boutiquecontenu').load(theLink,{noCache:newUniqueID()}, function() {
//																											  
//													 $('#theloader').remove(); 		
//													$('#pageboutique').fadeIn('fast'); 		
//													
//												 } ) ;																				
//											 })
// 				      return false;
//				  });
//
					
					
					
					
						$("#newsletterform").submit(function() {

						  $("#resultnewsletter").fadeOut('slow');
							
								$.ajax({
								  type: "POST",
								  url: 'functions.asp',
								  cache: false,
								  data: "Add2News=TRUE&EMAILNEWSLETTER=" + decodeURI($("#EMAIL").val()),
								  success: function(msg){
									 $("#resultnewsletter").html(msg).fadeIn('slow') ;
								  }
								});				   
							
						    return false;
						 } );


//						$("#footer a").click(function() {
//							openPage(this.href);
//						    return false;
//						 } );
						
						

						$("#EMAIL").focus(function() {
						   $(this).css('background-color','#666666');
						 } );
						
						$("#EMAIL").blur(function() {
						   $(this).css('background-color','#000000');
						 } );
					
					
					
					
					
					
				});
				
		   
			   
 
  
   $(document).ready(function() {
		
		// Preload all rollovers
		$("#menu img").each(function() {
			// Set the original src
			rollsrc = $(this).attr("src");
			rollON = rollsrc.replace(/.jpg$/ig,"_ON.jpg");
			$("<img>").attr("src", rollON);
		});
		
		// Navigation rollovers
		$("#menu a").mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			
  		if (imgsrc) {
				matches = imgsrc.match(/_ON.jpg/);
				// don't do the rollover if state is already ON
				if (!matches) {
				imgsrcON = imgsrc.replace(/.jpg$/ig,"_ON.jpg"); // strip off extension
				$(this).children("img").attr("src", imgsrcON);
				}

			}
			
		});
		$("#menu a").mouseout(function(){
			$(this).children("img").attr("src", imgsrc);
		});
		
					
						  
				 
				//$("#gotocart").click(function() {
				  $('#gotocart').livequery('click',function() {
				
				    window.location.hash = 'cart';
				 
						if($('#pagemoto').css("display") == 'block'){
							theDivToHide = 'pagemoto';
						}else if($('#pageboutique').css("display") == 'block'){
							theDivToHide = 'pageboutique';
						}else if($('#pagesite').css("display") == 'block'){
							theDivToHide = 'pagesite';
						}else { theDivToHide = 'contentWrapper'; } 	
										
											
							  $("#"+theDivToHide).fadeOut('fast', function()  {
								  
								 $("#dynamicnews").after('<div id=theloader style="background : url(images/body-loader.gif) no-repeat 355px 150px ; width:100%; height:200px; postion:absolute;" ></div>');
																			
									 $('#sitecontenublanc').load('cart.asp',{action:'cartdetail',noCache:newUniqueID()}, function() {
																										  
												 $('#theloader').remove(); 		
												$('#pagesiteblanc').fadeIn('fast'); 		
												
											 } ) ;																				
										 })
							  
							 return false;
				 });
				 
				 
				 
				 
										
						$("form#sondageservice, form#sondage2, form#sondageventes").submit(function() {
																 
							 var theForm = $(this) 
							 var theFormID = $(this).attr('id') 
							 var theName = $("#" + theFormID + " input#NOM").val();
							 var theDate = $("#" + theFormID + " input#date").val();
							 var thePhone = $("#" + theFormID + " input#TELEPHONE").val();
							 var theEmail = $("#" + theFormID + " input#EMAIL").val();
							 var themessage = 'S.v.p vérifier le(s) champ(s) suivant: \n'
							 
							 var hasError = false;
		                     var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
							 $("#" + theFormID + " .error").remove(); 
							 
							 
							if(theName == '') {
								$("#" + theFormID + " input#NOM").after('<span class="error">*Erreur</span>');
								themessage = themessage + "\n- NOM";
								hasError = true;
							}
							
							if(theDate == '') {
								$("#" + theFormID + " input#date").after('<span class="error">*Erreur</span>');
								themessage = themessage + "\n- DATE";
								hasError = true;
							}

							if(theEmail == '') {
								$("#" + theFormID + " input#EMAIL").after('<span class="error">*Erreur</span>');
								themessage = themessage + "\n- EMAIL";
								hasError = true;
							} else if(!emailReg.test(theEmail)) {
								$("#" + theFormID + " input#EMAIL").after('<span class="error">*Erreur</span>');
								themessage = themessage + "\n- EMAIL";
								hasError = true;
							}
					
							if(thePhone == '') {
								$("#" + theFormID + " input#TELEPHONE").after('<span class="error">*Erreur</span>');
								themessage = themessage + "\n- TELEPHONE";
								hasError = true;
							}
							
							
						  if(hasError == false) {
							   theForm.submit();
						  }	else {
							  
							  alert(themessage);
							  return false;
						 }						
						   return false;
						 });
										
			
						$("form#survey1, form#survey2, form#survey3").submit(function() {
																 
							 var theForm = $(this) 
							 var theFormID = $(this).attr('id') 
							 var theName = $("#" + theFormID + " input#NOM").val();
							 var theDate = $("#" + theFormID + " input#date").val();
							 var thePhone = $("#" + theFormID + " input#TELEPHONE").val();
							 var theEmail = $("#" + theFormID + " input#EMAIL").val();
							 var themessage = 'Please check field(s): \n'
							 
							 var hasError = false;
		                     var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
							 $("#" + theFormID + " .error").remove();
							 
							if(theName == '') {
								$("#" + theFormID + " input#NOM").after('<span class="error">*Error</span>');
								themessage = themessage + "\n- NAME";
								hasError = true;
							}
							
							if(theDate == '') {
								$("#" + theFormID + " input#date").after('<span class="error">*Error</span>');
								themessage = themessage + "\n- DATE";
								hasError = true;
							}

							if(theEmail == '') {
								$("#" + theFormID + " input#EMAIL").after('<span class="error">*Error</span>');
								themessage = themessage + "\n- EMAIL";
								hasError = true;
							} else if(!emailReg.test(theEmail)) {
								$("#" + theFormID + " input#EMAIL").after('<span class="error">*Error</span>');
								themessage = themessage + "\n- EMAIL";
								hasError = true;
							}
					
							if(thePhone == '') {
								$("#" + theFormID + " input#TELEPHONE").after('<span class="error">*Error</span>');
								themessage = themessage + "\n- PHONE";
								hasError = true;
							}
							
							
						  if(hasError == false) {
							   theForm.submit();
						  }	else {
							  alert(themessage);
							  return false;
						 }						
						   return false;
						 });
	
	});
				
function openCart(tempIdcust,lang){
	
	 tb_show('MONETTE SPORTS','http://shop.webloft.ca/shopV2.asp?siteid=248&iduser=' + tempIdcust + '&amp;lang=' + lang +'&amp;TB_iframe=true&amp;height=400&amp;width=800', '')
		 return false
		
	}
	
	
function showEvent(uniqueCalID,thedate){
											
			var theLink = 'default.asp?calID=' + uniqueCalID + '&goDate=' + thedate 							
									
				 $("#eventdetail").load( theLink + ' #content',  function(){ 
				      	//$.scrollTo( $('#scrolllink'), {speed:1000} );
				   })					
									
//			  $("#dynamicContent").slideUp('slow', function(){ 
//				 $("#dynamicContent").load( theLink + ' #dynamicContent',  function(){ 
//				    $("#dynamicContent").slideDown('slow',function(){ $.scrollTo( $('#scrolllink'), {speed:1000} );});
//				   })
//				})
			  
			 return false;

	}
	
