// JavaScript Document
// Something in the CakePHP code is causing the usual
// jQuery new links code to break. We have to go back
// to using the plain old JavaScrip external links!
/*<![CDATA[*/ /*for valid xhtml*/
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;
/*]]>*/ 
$.noConflict();
 jQuery(document).ready(function($) {
	// Not working, for some reason						   
  /* $("body").click(function(event) { alert(event.target.rel);
    if ($(event.target).is("a[@rel*=external]"))  {
      $(event.target).attr('target','_blank');
    }
  });*/
  
   //$("body").click(function(event) { alert($(event.target.rel).is("external"));
    //if ($(event.target.rel).is("external") )  { alert($(event.target.rel).is("external"));
      //$(event.target).attr('target','_blank');
    //}
	
 // });
   
   // UNUSED. We'd rather use the rel attribute, than a class.   
	/*$('a.new-window').click(function(){
	
		window.open(this.href);
		
		return false;
	
	});*/
	
	if ($("a.fancybox").length > 0) {
		$("a.fancybox").fancybox({
			'titlePosition'	: 'over',
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});	
	}

	if ($("#userForm").length > 0) {	
		$("#userForm").validate();
	}
	
	if ($("#groupForm").length > 0) {	
		$("#groupForm").validate();
	}
	
	if ($("#permissionForm").length > 0) {	
		$("#permissionForm").validate();
	}
	
	if ($("#personForm").length > 0) {	
		$("#personForm").validate();
	}
	
	if ($("#postForm").length > 0) {	
		$("#postForm").validate();
	}
	
	if ($("#commentForm").length > 0) {	
		$("#commentForm").validate();
	}
	
	if ($("#tagForm").length > 0) {	
		$("#tagForm").validate();
	}
	
	if ($("#contactForm").length > 0) {	
		$("#contactForm").validate();
	}
	
	if ($("#resetPasswordForm").length > 0) {	
		$("#resetPasswordForm").validate();
	}
	
	if ($("#newPasswordForm").length > 0) {	
		$("#newPasswordForm").validate();
	}
	
	if ($("#searchForm").length > 0) {	
		$("#searchForm").validate();
	}
});

