/**
*  email form validation
*/
            function validateForm()
            {
	             error = '';
	             fname = document.fm_pplinfo.fname.value;
	             sname = document.fm_pplinfo.sname.value;
	             email = document.fm_pplinfo.email.value;
	             
	             //fname must have one or more letters
	             if (fname.length == 0){
		             error = 'Please enter a valid first name\n';
		             document.fm_pplinfo.fname.setfocus;
	             }
	             else if (sname.length < 2){
		             error = 'Please enter a valid surname\n';
		             document.fm_pplinfo.sname.setfocus;
	             }
	             else if (email.length == 0){
		             error = 'Please enter a valid email address\n';
		             document.fm_pplinfo.email.setfocus;
	             }else{	             
	                  error = isEmail(email);
	                  if (error.length != 0)
	                  {
		                  error = 'Invalid Email Address (' + error  +')';    
	                  }
                 }
	             
                 if (error.length == 0)
                 {
	                     return true;
                 }else{
	                alert(error); 
	                return false;   
                 }
            }
            
            /**
            *  checks email addresses
            *  Reurns a str to say the error found ('' is no error)
            */
            function isEmail(l_email)
            {
	            atSymbol   = '@';
	            dotSymbol  = '.';
	            var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	            eArray = l_email.split(atSymbol); //There shouldonly be 2 parts, name and domain  
	            error = '';
	            
	            if (eArray.length != 2){
		            error = (''  + (eArray.length-1) + ' @ symbols found');
	            }
	            else if ((l_email.indexOf('.@') != -1)
	                   || (l_email.indexOf('..') != -1)
	                   || (l_email.indexOf('@.') != -1)
	                   || (l_email.indexOf('@@') != -1))
	            {
		            error = ('invalid format');
    	        }
    	        else if (eArray[0].length == 0)
	    	    {
		    	    error = ('Name is to short');    
	    	    }
	    	    else if (eArray[1].length == 0)
	    	    {
		    	    error = ('Domain is to short');    
	    	    }
	    	    else if ( (eArray[1].indexOf('.') == -1) || (eArray[1].lastIndexOf('.') == (eArray[1].length-2)) )
	    	    {
		    	    error = ('Domain must contain a valid suffix');    
	    	    }
	    	    else if ( (eArray[1].indexOf('.') < 2) )
	    	    {
		    	    error = ('Invalid domain name');    
	    	    }
	    	    else
	    	    { 
						    	    	    	    
					for (i=0; i<invalidChars.length; i++) {
					   if (l_email.indexOf(invalidChars.charAt(i),0) > -1) {
					        error = ('email address contains invalid characters');
					   }
					}  
					        
                }
                
                return error;
        
	            
            }//endfunction
           
            
            /**
            * Checks the email address
            */
            function unsubscribeMe(email)
            {
	            error = isEmail(email);
	            if (error.length != 0)
	            {
		            error = 'Invalid Email Address (' + error  +')';    
	            }
	            
	            
	            if (error.length == 0)
                 {
	                     return true;
                 }else{
	                alert(error); 
	                return false;   
                 }
	            
            } 

   
//J-Query [http://docs.jquery.com/]
$(document).ready(
function()
{
     
     $("#car_images_table a").click(JQPopupwindow);
     $("#car_main_image a").click(JQPopupwindow);
     
     function JQPopupwindow()
	  {
	      
	      l_url = $(this).attr("title");                
	      l_urlHref = $(this).html();
	              
	      if (l_urlHref.length > 0)
          {
              l_urlHref = l_urlHref.replace('width="260"','');
              l_urlHref = l_urlHref.replace('width="100"','');
              l_urlHref = l_urlHref.replace('width=100',''); 
              l_urlHref = l_urlHref.replace('width=260','');           
              l_urlHref = l_urlHref.replace('alt="Click for full size image"','');
              //l_urlHref = l_urlHref.replace('.jpg','.jpg?id=nocach');//to sort ie not resizeing images
              
              
              $("#image_full").addClass("hidden_div").html('<a href="Javascript:;" id="dialog" title="Click to close this image">' + l_urlHref + '</a>');   
				//set the pop-up's title
              $("#image_full").attr("title",l_url);
              $("#image_full").removeClass("hidden_div").dialog({ 
			    	modal: true, 
				    overlay: { 
				    opacity: 0.5, 
				    background: "black" 
				    },
				    height:500,
				    width:750
			    });  
		  }
		return false;
	  }
	  
	  /**
      *  Hides the large img hidden_div
      */
      $("#image_full").click(function ()
      {
	      $(this).dialog("close");
      });

     
     
});     
      