// JavaScript Document

		jQuery.preloadImages = function(){  
		    for(var i = 0; i<arguments.length; i++){
			  jQuery("<img>").attr("src", arguments[i]);
		     }
          }
		  
         $.preloadImages("/images/bkg_menu.gif","/images/bkg_menu_sel.gif");

		$(document).ready(function() {
								   
			//$(".fixHeight").equalHeights();					   

             $("a.send2friend").click(function(){
			    html = 'mailto:?subject=Article%20interssant&body=Je%20pense%20que%20tu%20vas%20trouver%20cet%20article%20interessant!:\n{t} ({u})';
				html = html.replace(/{u}/, window.location.href).replace(/{t}/, document.title);
				win = window.open(html,'emailWindow');
                if (win && win.open &&!win.closed) win.close()
			  return false			
			 })
		 
		 
			$("ul#nav li").hoverIntent(
				function () {
					$(this).addClass("hovering");
					if ( $(this).hasClass("hovering") ){
					//$(this).find(".level-1").queue("fx",[]);
					$(this).find(".level-1").slideDown("fast");
				;}},
				function () {
					 $(this).find(".level-1").slideUp("fast");
					 $(this).removeClass("hovering");
			});

//	$("ul#nav li").hoverIntent(function () { 
//			$(this).addClass("hovering").css("z-index", 200000);
//			if ( $(this).hasClass("hovering") ){
//				$(this).find(".level-1").queue("fx",[]);
//				$(this).find(".level-1").slideDown("slow");
//			}
//		},
//		function () {
//			 $(this).find(".level-1").slideUp("slow");
//			 $(this).removeClass("hovering");
//		}
//	);
//

		 
								   
		  $("form#suscribeClientForm").submit(function(){

			  $("#result").html('');
			
					$.ajax({
					  type: "POST",
					  url: 'ajax/clients_request.asp',
					  cache: false,
					  data: $("form#suscribeClientForm").serialize(),
					  success: function(msg){
						  if ( msg == 'ADDED' ) {
							   document.location = '/?idpage=2075'
							  } else {
								  alertMes(msg);
							 }
						
					  }
					});				   
			
		   return false
		  })
		  
								   
		  $("form#suscribeProForm").submit(function(){

			  $("#result").html('');
			
					$.ajax({
					  type: "POST",
					  url: 'ajax/pros_request.asp',
					  cache: false,
					  data: $("form#suscribeProForm").serialize(),
					  success: function(msg){
						  if ( msg == 'ADDED' ) {
							   document.location = '/?idpage=2094'
							  } else {
								  alertMes(msg);
							 }
						
					  }
					});				   
			
		   return false
		  })
		  
		  $('input[type="reset"]').click(function(){ $("#result").html(''); })
		  
		  
		  
		  
		  
		  
		  $("form#loginform").submit(function(){


             $('form#loginform input[type=submit]').attr("disabled", "disabled"); 	
			  $("#formresult").html('');
			    
					$.ajax({
					  type: "POST",
					  url: 'ajax/clients_request.asp',
					  cache: false,
					  data: $("form#loginform").serialize(),
					  success: function(msg){
						  
					  
							if(msg.indexOf("client") > -1 ){
								  document.location = '?client=secure';
							} else if(msg.indexOf("pro") > -1 ){
								  document.location = '?pro=secure';
							} else {
							  alertMes(msg);
							  setTimeout('$("#formresult").html("Courriel:"); $("form#loginform input[type=submit]").attr("disabled", "");', 2000);
							}					
						  
						
					  }
					});				   
			
		   return false
		  })
		  
		  $("#USEREMAIL").focus(function() {$(this).val('');} );
		  
		  
		  $("a.lostpassword ").click(function(){


				$('<div id=msgBox ><div class=alert ><h1>&nbsp;</h1><span id=lostpassmsg >Entrez votre courriel s.v.p</span><br/><form id=mylostpassword ><input type=text name=USEREMAIL /><input type=hidden name=formaction value=lostpassword /></form></div></div>').dialog({
					title: 'Residencia',
					modal:true,
					resizable:false, 
					overlay: {
						opacity: 0.2,
						background: "black"
					},
					buttons: { 
						"Envoyer mot de passe": function() { 
						
													$("#lostpassmsg").html('');
														  
													$.ajax({
													  type: "POST",
													  url: 'ajax/clients_request.asp',
													  cache: false,
													  data: $("form#mylostpassword").serialize(),
													  success: function(msg){
															  
															   if (msg == 'GO') {
																	$("#msgBox").dialog("destroy");
																	$("form#loginform").before("<div class=good ><h1>&nbsp;</h1>Votre mot de passe a été envoyé avec succès!</div>");
															   } else {  
																  $("#lostpassmsg").html(msg);
															   }
														   
														
													       }
													});				   
						  
						  
					                          }  
			                 } 
		
			   });
				
				
											  
		    //$('form#loginform input[type=password]').hide();
		    //$('#USEREMAIL').val('Entrez votre courriel ici');
		    //$('p.lostpassword').html('<input type=hidden name=formaction value=lostpassword />');
			
		   return false;
		  })
		  
		  
		   $("a[@href*='close']").click(function(){
				$('<div id="msgBox" ><div class=alert ><h1>Fermer session?</h1></div></div>').dialog({
					title: 'Residencia',
					modal:true,
					resizable:false, 
					overlay: {
						opacity: 0.2,
						background: "black"
					},
					buttons: { 
						"Oui": function() { 
						  $(this).dialog("destroy"); 
						  document.location='?site=close';
					}, 
						"Non": function() { 
						  $(this).dialog("destroy"); 
					}   
			   } 
		
			   });
				 return false
			});
		  
		  
		  
		  
		  
		  
		   	
		  
		  
		  
		  $("a.addarticle2bookmark").click(function(){
			 	$.post("ajax/clients_request.asp", { formaction: 'addarticle2bookmark', article_id: this.rel }, function(msg){
                      alertMes(msg)
                    });
		   return false
		 })
		  


		// ################## Trouver un PRO  ##################	
//		     $('.okbox').hide();
//			 
//              $('ul.categoryboxes li a').livequery('click',function() {
//																	
//					//$('form#addprojet input[type=submit]').hide();
//					
//					theDiv2reload = $(this).parents("ul").attr("id");
//					
//			         if (theDiv2reload == 'categoryboxes1') {$("ul#categoryboxes3").html('');} 
//					
//					theDiv2reload = theDiv2reload.replace('categoryboxes','');
//				 	theDiv2reload = parseInt(theDiv2reload)+1 ;
//                    theDiv2reload =  "categoryboxes"+theDiv2reload  
//										  
//			            var newTitle =  this.title ;
//						var newId =  this.rel ;
//						
//							$.ajax({
//							  type: "POST",
//							  url: 'ajax/clients_request.asp',
//							  cache: true,
//							  data: "formaction=getcategory&category_id=" + newId ,
//							  success: function(msg){
//								 if (msg.indexOf("END") == 0 ) {
//									    // end of loop... response is --> END: 5837
//									   var category_id = msg.substring(4)
//										 $("ul#"+theDiv2reload).html('');
//										 //$('form#addprojet input[type=submit]').fadeIn('slow');	
//										 $("input[@name='category_id']").val(category_id);
//										 
//										//$('.okbox').eq(0).css('backgroundImage','url(images/icons/Ok.png)');
//										 $('.okbox').eq(0).show('slow');
//										 
//										 
//										 
//										 $('#accordion h3').eq(0).find('a').html(newTitle);
//										// $('div.ui-accordion-content').eq(0).slideUp('slow');
//										// $('div.ui-accordion-content').eq(1).slideDown('slow');
//										 
//										 $("input.next1").attr({disabled:"true"});
//										 $('form#addprojet input[type=button]').attr("disabled", ""); 	
//										 
//										 //$('.clicktest').trigger('click');
//										 
//										 $('#accordion .ui-accordion-header').eq(1).trigger('click');
//										
//									 } else {
//										 // continue loop 
//										 $("ul#"+theDiv2reload).html(msg);
//										 //$('.okbox').eq(0).css('backgroundImage','none');
//										 $('.okbox').eq(0).hide('slow');
//										 $('form#addprojet input[type=button]').attr("disabled", "disabled"); 	
//										$('#accordion h3').eq(0).find('a').html('Sélectionnez votre catégorie');
//									  } ;
//								 
//							     }
//							});				   
//						
//					 return false;
//		  });
//
      
             $('form#addprojet input[type=button]').click(function(){
                    $("#clicktest").trigger("click"); 
					}); 	
		  
	  
		});


function alertMes(msg){
	
	// because we create a lot of dom on the fly, we must use this random ID to prevent no auto-closing
	 var theBoxId = "msgBox" + Math.floor(Math.random()*100)
	 
			$('<div id=' + theBoxId + '>' + msg + '</div>').dialog({
				title: 'Residencia',
				modal:true,
				resizable:false, 
				overlay: {
					opacity: 0.2,
					background: "black"
				},
				buttons: { 
					"OK": function() { 
					 $("#" + theBoxId).dialog("destroy"); 
				}   
		   } 

		   });
      setTimeout('$("#' + theBoxId + '").dialog("destroy"); ', 3000);
	
	}
	
	
function dialogForm(thelink,theform,thewidth,theheight){
	
	// because we create a lot of dom on the fly, we must use this random ID to prevent no auto-closing
	 var theBoxId = "msgBox" + Math.floor(Math.random()*100)
	 
			$('<div id=' + theBoxId + '></div>').dialog({
				title: 'Residencia',
				modal:true,
				width:thewidth,
				height:theheight,
				resizable:false
		   });

				$.ajax({
				  type: "POST",
				  url: thelink,
				  cache: false,
				  data: 'formaction=' + theform,
				  success: function(msg){
						  
						   if (msg == 'GO') {
								 $("#" + theBoxId).html(thelink);
						   } else {  
							    $("#" + theBoxId).html(msg);
						   }
					   
					
					   }
				});				   
		
		
		
	}
	
	
	function doAutoSlide(xSlide){
		  var xSlide
		 
		  if ( xSlide == 6 ) { xSlide = 0 }
		
		 $("#featured_articles-menu a").eq(xSlide).trigger("click");
		    xSlide++ ;
		    setTimeout("doAutoSlide(" + xSlide + ");", 10000);
		
		}
	
	
