$(document).ready(function() {
	var os = $.client.os;
	var browser = "unsupported";
	var versionArray = jQuery.browser.version.split(".");
	
	$('.hideonload').hide();
	
	if (jQuery.browser.webkit == true) {
		browser = "webkit";
	}
	else if (jQuery.browser.mozilla == true) {
		browser = "mozilla";
	}
	else if (jQuery.browser.msie == true) {
		browser = "msie";
	}
	
	//==================================================================
	
	$(".signUp_signUp .btn").click(
		function() {
			//alert($(".signUp_signUp .btn").find("a").attr("href"));
			window.location.href = ($(".signUp_signUp .btn").find("a").attr("href"));
		}
	);
	
	
	$(".showForgotPasswordCB").colorbox({width:"50%", inline:true, href:"#forgotPasswordCB"});
	
	//Adds the os version to the body to help with css;
	$('body').addClass(os);
	$('#browserType').addClass(browser);
	
	//Only used for to detect IE7 as other browsers version do not read correctly.
	$('#browserVersion').addClass("v"+versionArray[0]);
	
	//IE 8 Fix for keyword input box
	$("#searchKeyword").focus();
	$("#searchKeyword").blur();
	
	//==================================================================
	//START: Form validation (non-ajax)
	//==================================================================
	
	$("#loginForm").validationEngine();
	$("#signUp").validationEngine();
	$("#adminSubmitCF").validationEngine();
	$("#updateAccountForm").validationEngine();
	$("#updateCF").validationEngine();
	
	//==================================================================
	//END: Form validation (non-ajax)
	//==================================================================
	
	//==================================================================
	//START: Newsletter Signup AJAX
	//==================================================================

	$("#newsletterSignup").validationEngine({
		ajaxSubmit: true,
		ajaxSubmitFile: "retrieve.php",
		success: function() {
			$.colorbox({width:"50%", inline:true, href:"#newsletterCB"});
		},
		failure: function() {},
		showBox: false
	});
	
	//==================================================================
	//END: Newsletter Signup AJAX
	//==================================================================
	
	//==================================================================
	//START: Forgot password
	//==================================================================
	$("#forgotPW").validationEngine({
		ajaxSubmit: true,
		ajaxSubmitFile: "retrieve.php",
		success: function(data) {
				$("#forgotPWEmail").val("");
				$.colorbox({width:"50%", inline:true, href:"#forgotPasswordThanksCB"});
		},
		failure: function() {
			$("#invalidemail").html('Please enter a valid e-mail address');
		},
		showBox: false
	});
	
	//==================================================================
	//END: Forgot password
	//==================================================================
	
	//==================================================================
	//START: Add Career Fair AJAX
	//==================================================================
	$("#submitCF").validationEngine({
		ajaxSubmit: true,
		ajaxSubmitFile: "retrieve.php",
		success: function() {
			$.colorbox({width:"50%", inline:true, href:"#CFSubmitCB"});
		},
		failure: function() {},
		showBox: false
	});
	
	
	/*$("#submitCF").submit(
		function() {
			var xmlHttp = GetXmlHttpObject();

			if (xmlHttp == null) {
				alert ("Browser does not support HTTP Request");
				return
			}
			
			var url = "retrieve.php";
			url += "?ajax=true";
			url += "&action=newEvent";
			
			url += "&eventType="+$("#submitCF input:radio:checked").val();
			url += "&industry="+$("#industry").val();
			url += "&eventName="+$("#eventName").val();
			url += "&eventStartHour="+$("#eventStartHour").val();
			url += "&eventEndHour="+$("#eventEndHour").val();
			url += "&eventEndMin="+$("#eventEndMin").val();
			url += "&email="+$("#email").val();
			url += "&address="+$("#address").val();
			url += "&state="+$("#state").val();
			url += "&zip="+$("#zip").val();
			url += "&facebook="+$("#facebook").val();
			url += "&eventMonth="+$("#eventMonth").val();
			url += "&eventDay="+$("#eventDay").val();
			url += "&eventYear="+$("#eventYear").val();
			url += "&eventTimezone="+$("#eventTimezone").val();
			url += "&eventLocationName="+$("#eventLocationName").val();
			url += "&city="+$("#city").val();
			url += "&url="+$("#url").val();
			url += "&twitter="+$("#twitter").val();
			url += "&eventDescription="+$("#submitCF textarea:#eventDescription").val();

			alert(url);
			
			xmlHttp.onreadystatechange = function() {
				if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
					if (xmlHttp.status == 200) {
						//alert("xmlHttp.responseText: "+xmlHttp.responseText);
						
						//var valueArray = xmlHttp.responseText.split(",");
						//$("#shippingAmount").html("$"+valueArray[0]);
						//$("#cartTotal").html("$"+valueArray[1]);
						$.colorbox({width:"50%", inline:true, href:"#CFSubmitCB"});
						
						return false;
					}
					else {
						return false;
					}
				}
				else {
					return false;
				}
			} 
			
			xmlHttp.open("GET", url, true)
			xmlHttp.send();
			
			return false;
		}
	);
	*/
	//==================================================================
	//END: Add Career Fair AJAX
	//==================================================================
	
	
	//==================================================================
	//START: Contact Us AJAX
	//==================================================================
	$("#contactUs").validationEngine({
		ajaxSubmit: true,
		ajaxSubmitFile: "retrieve.php",
		success: function() {
			$.colorbox({width:"50%", inline:true, href:"#contactUsCB"});
		},
		failure: function() {
			//alert("fail");
		},
		showBox: false
	});
	
	//==================================================================
	//END: Contact Us AJAX
	//==================================================================
});
