/*
#####################################################
# 
# GLobal Leaders Academy
# Global JavaScript utilities library
#
# Aggregated and written by Phenotype (phenotype.net)
# See source comments for individual credits
#
#####################################################
*/

	////////////////////////////////////////////////////////////////////
	//	Function definitions
	////////////////////////////////////////////////////////////////////
	
	/* 
	externalLinks()
	
	Function to open links to external sites in a new browser window
	(target attribute not allowed by XHTML 1.0 Strict)
	
	(c) SitePoint.com 2003
	(http://www.sitepoint.com/article/standards-compliant-world/)
	-----------------------------------------------------------------------
	*/
	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";
		}
	} // End externalLinks()

	/* Example usage:

	<a href="#" rel="external">Link</a>
	*/
	
	/* 
	clearTypeFade()
	
	Function to fix aliased text after changing opacity of 
	ClearType-rendered text on MSIE (use as callback function from jQuery
	animations)
	-----------------------------------------------------------------------
	*/
	function clearTypeFade() {
		
		if($.browser.msie){
			$(this).get(0).style.removeAttribute('filter');
		}
		
	}; // End clearTypeFade()
	
	
	/* 
	setupContactForm()
	-----------------------------------------------------------------------
	*/
	function setupContactForm() {
		
		$('#button-submit').click( function (){

			$('#contact').submit();
			
		});
		
		// validate when the form is submitted
		$('#contact').submit( function(){
		
			var reg_email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/; 
		
			var inputcheck = $('#origin_name');
			// if field has something in it, do submit actions, otherwise write out error
			if( inputcheck.val() == '' ){
				// add class to change colour
				$('#origin_name + em').remove();
				inputcheck.addClass("required").after('<em>&nbsp;Required</em>').get(0).focus();
				return false;
			}else{
				inputcheck.removeClass("required");
				$('#origin_name + em').remove();
			}
			
			var inputcheck = $('#origin_email');
			// if field has something in it, do submit actions, otherwise write out error
			if( inputcheck.val() == '' || !reg_email.test( inputcheck.val() ) ){
				// add class to change colour
				$('#origin_email + em').remove();
				inputcheck.addClass("required").after('<em>&nbsp;Required</em>').get(0).focus();
				return false;
			}else{
				inputcheck.removeClass("required");
				$('#origin_email + em').remove();
			}
			
			var inputcheck = $('#captcha');
			// if field has something in it, do submit actions, otherwise write out error
			if( inputcheck.val() == '' ){
				// add class to change colour
				inputcheck.addClass("required").get(0).focus();
				return false;
			}else{
				inputcheck.removeClass("required");
			}
			
		});
	}; // End setupContactForm()