//add the 'validate' attribute to the metadata plugin
$.metadata.setType("attr", "validate");

$(document).ready(function(){
	/*
	//load the site data xml file
	$.ajax({
		type: "GET",
		url: "sitedata.xml",
		dataType: "xml",
		success: function(xml){
			//get recruitment node to see what we need to put in the notice on the apply page
			var recruitmentNode = $(xml).find("recruitment");
			if (recruitmentNode != undefined && recruitmentNode != null)
			{
				switch($(recruitmentNode).attr("state"))
				{
					case "FriendsFamily":
						$("#recruitmentNotice").text("We are currently only recruiting for friends and family of existing members. You are still encouraged to apply if you do not have a referral, but your application will not be processed until general recruitment is reopened.");
						$("#recruitmentNotice").css("display", "block");
					break;
					case "Closed":
						$("#recruitmentNotice").text("Recruitment is currently closed in all categories. You are still encouraged to apply if you do not have a referral, but your application will not be processed until general recruitment is reopened.");
						$("#recruitmentNotice").css("display", "block");
					break;
				}
			}
		},
		error: function(){
		}
	});
	*/
	
	$("#questions").append("<div class='offlineNotice'>Our web application is currently offline. For the time being, please use our <a href='http://www.drakenrising.com/forums/index.php/topic,15.0.html'>forum application</a> to apply to the guild. Thanks.</div>");
	
	/* Application currently disabled
	$.ajax({
		type: "GET",
		url: "application.xml",
		dataType: "xml",
		success: function(xml){
			$(xml).find("question").each(function(){
					$("#questions").append("<p class='question'><label for='"+$(this).attr("name")+"'>"+$(this).attr("text")+"</label></p>");
					$(this).find("subtext").each(function(){
						$("#questions").append("<p class='questionSub'>"+$(this).attr("text")+"</p>");
					});
					switch($(this).attr("type"))
					{
						case "textbox":
							$("#questions").append("<input size='55' name='"+$(this).attr("name")+"' validate='required:true' />");
							break;
						case "textarea":
							$("#questions").append("<textarea rows='4' cols='55' name='"+$(this).attr("name")+"' validate='required:true'></textarea>");
							break;
						case "yesNo":
							$("#questions").append("<select name='"+$(this).attr("name")+"' validate='required:true'><option value=''>...</option><option value='Yes'>Yes</option><option value='No'>No</option></select>");
							break;
						case "select":
							$("#questions").append("<select name='"+$(this).attr("name")+"' validate='required:true'>");
							$("#questions select[@name='"+$(this).attr("name")+"']").append("<option value=''>Select one...</option>");
							$(this).find("option").each(function(){
								 $("#questions select[@name='"+$(this).parent().parent().attr("name")+"']").append("<option value='"+$(this).attr("value")+"'>"+$(this).attr("text")+"</option>");
							});
							break;
						case "confirm":
							$("#questions").append("<input type='checkbox' name='"+$(this).attr("name")+"' validate='required:true'> I Agree");
							break;
					}
					$("#questions").append("<br /><br />");
			});
			$("#questions").append("<input type='submit' value='Submit Application' />");
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			$("#questions").append("<p>There was an error during processing</p><h1>OMG IT'S GOING TO BLOW UP!!!!</h1><p>"+XMLHttpRequest+"<br />"+textStatus+"<br />"+errorThrown+"</p>");
		}
	});
	$("#application").validate({
	    onfocusout: true,
	    onkeyup: true,
	    onclick: true,
	    errorContainer: $("#errorHeader"),
		errorClass: "errorText",
	    highlight: function(element, errorClass){
	        //highlight the label of the element with error
	        $(element.form).find("label[for="+element.name+"]").addClass("errorText").attr("title", this.errorMap[element.name]);
	        //add a tooltip to the element
            $("input[name='"+element.name+"']").attr("title", this.errorMap[element.name]);	        
	    },
	    unhighlight: function(element, errorClass){
	        //remove the highlight from the element
	        $(element.form).find("label[for="+element.name+"]").removeClass("errorText").attr("title", "");
	        //remove the tooltip from the element and its label
	        $("input[name='"+element.name+"']").attr("title", "");
	    }
	});*/
});
