var FreefoamFrench = {
	Search : {
		Validate:function( argText ) {
			if( $( "searchBox" ).value.blank() || $( "searchBox" ).value==argText ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "searchBox" );
				$( "searchBox" ).value = "";
				return false;
			}
			return true;
		},
		Clear:function() {
			$( "searchBox" ).value = "";
		},
		Populate:function( argText ) {
			if( $( "searchBox" ).value.blank() ) {
				$( "searchBox" ).value = argText;
			}
		}
	},
	InformationForm : {
		Validate:function() {
			
			if( $("name").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "name" );
				return false;
			}	
			if( $("companyName").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "companyName" );
				return false;
			}	
			if( $("position").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "position" );
				return false;
			}			
			if( $("email").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "email" );
				return false;
			}				
			if( $("telephone").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "telephone" );
				return false;
			}					
			if( $("address1").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "address1" );
				return false;
			}
			if( $("city").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "city" );
				return false;
			}
			if( $("country").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "country" );
				return false;
			}
							
			if( $("enquiry").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "enquiry" );
				return false;
			}	
			
			return true;
		}
	},
	ContactForm : {
		SwitchSection:function() {
			var section = $("contactMethod").value;
			switch( section ) {
				case "email":
					$("p_email").show();
					$("p_telephone").hide();
					$("p_address").hide();
				break;
				case "telephone":
					$("p_email").hide();
					$("p_telephone").show();
					$("p_address").hide();
				break;
				case "post":
					$("p_email").hide();
					$("p_telephone").hide();
					$("p_address").show();
				break;
			} 
		},
		Validate:function() {
			var section = $("contactMethod").value;
			
			if( $("name").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "name" );
				return false;
			}	
			if( $("companyName").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "companyName" );
				return false;
			}	
			
			switch( section ) {
				case "email":
					if( $("email").value.blank() ) {
						FreefoamFrench.ContactForm.HighlightAndFocus( "email" );
						return false;
					}				
				break;
				case "telephone":
					if( $("telephone").value.blank() ) {
						FreefoamFrench.ContactForm.HighlightAndFocus( "telephone" );
						return false;
					}	
				break;
				case "post":
					if( $("address1").value.blank() ) {
						FreefoamFrench.ContactForm.HighlightAndFocus( "address1" );
						return false;
					}
					if( $("city").value.blank() ) {
						FreefoamFrench.ContactForm.HighlightAndFocus( "city" );
						return false;
					}
					if( $("country").value.blank() ) {
						FreefoamFrench.ContactForm.HighlightAndFocus( "country" );
						return false;
					}
				break;
			} 
			
			if( $("enquiry").value.blank() ) {
				FreefoamFrench.ContactForm.HighlightAndFocus( "enquiry" );
				return false;
			}	
			
			return true;
		},
		HighlightAndFocus:function( id ) {
			new Effect.Highlight($(id));
			$(id).focus();
		}
	}	
}

String.prototype.isEmail = function () { 
	var rx = new RegExp("\\w+([-+.\’]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"); 
	var matches = rx.exec(this); 
	return (matches != null && this == matches[0]); 
}

function isNumeric(x) { 
	var y=parseInt(x); 
	if (isNaN(y)) {
	   return false; 
	} else {
		return true;
	}
} 

function LoadingAjax(txt) {
	if(typeof(txt)=="undefined") {
		txt = "Loading...";
	}
	return "<div class='ajaxMsg' id='widgetAjaxMsg'> "+txt+"</div>";
}

function parseJSON( json ){
	var o = eval('(' + json + ')');
	if( o.redirectURL )
	{
		document.location = o.redirectURL;
		return;
	}
	if( $("message") != null ) new Element.remove( "message" );
	if( o.errMsg )
	{
		if( o.errMsgTitle == null ) o.errMsgTitle = "Error";
		if( o.errMsgTimer == null ) o.errMsgTimer = 5000;
		tw.ShowMessage( o.errMsgTitle, o.errMsg, "error", o.errMsgTimer, o.errMsgPosition );
		return o;
	}
	if( o.msgTitle || o.msg )
	{
		if( o.msgTimer == null ) o.msgTimer = 5000;
		tw.ShowMessage( o.msgTitle, o.msg, o.msgClass, o.msgTimer, o.msgPosition );
	}
	return o;
}

var errFunc = function(t) {
	var win = window.open("", "win", "width=1024,height=700,resizable=yes,scrollbars=yes,status=no"); // a window object
	win.document.open("text/html", "replace");
	win.document.write( "<html><body style='margin:0'><div style='border-bottom:1px solid #222;background:#666;padding:10px;'><h1 style='color:#FFF;margin:0;padding:0;'>Digital Crew Ajax Error</h1></div><div style='padding:10px;'>"+t.responseText.replace(/^\s+|\s+$/, '') + "</div></body></html>" );
	win.document.close();
	win.focus();
}
