$(document).ready(function() {

	// png fix for ie6
	if ( $.browser.msie && $.browser.version == '6.0' ) {
		$("#logo").pngFix();
		$("#left-column").css("background","#333");
		$(".generic-pane").css("background","#333");
		$(".register-list").css("background","#333");
		$("#form-errors-list").css("background","#333");
		$(".generic-table").css("background","#333");
		$(".holder-right").css("background","#333");
	}

	
	// nasty preloads ;(
	var img = new Image();
	img.src = "/images/ajax_loader.gif";
	
	var img1 = new Image();
	var img2 = new Image();
	var img3 = new Image();
	var img4 = new Image();
	img1.src = "/images/login90.png";
	img2.src = "/images/login180.png";
	img3.src = "/images/login270.png";
	img4.src = "/images/login360.png";

	// login form submit
	$("#login-button").click(function() {
		$(this).attr("src", "/images/login90.png");
		setTimeout(function() {
			$("#login-button").attr("src", "/images/login180.png");
			
			setTimeout(function() {
				$("#login-button").attr("src", "/images/login270.png");
				
				setTimeout(function() {
					$("#login-button").attr("src", "/images/login360.png");
					
					setTimeout(function() {
						$("#loginform").submit();	
					}, 500);
				}, 500);
			}, 500);
		}, 500);
	});
	
	
	
	// login button switch for ie6
	if ( $.browser.msie && $.browser.version == '6.0' ) {
		$("#login-button").hide();
	}
	else {
		$("#login").hide();
	}
	
	
	
	// disclaimers for account signup pages
	$("#submit-holder").click(function() {
		alert("By signing up, you agree to 3rd parties downloading your documents or Certificates.");
	});
	
	$("#submit-viewer").click(function() {
		alert("By signing up, you agree not to alter or change any documents or Certificates downloaded.");
	});
	
	
	
	
	// form errors highlighting function
	$("label").each(function() {
		
		// reference to each label obj.
		var label = $(this);
		
		// get text node from label.
		var txt = $(this).text();
		
		// replace colon, setup regular expression pattern.
		var regex = txt.replace(":", "");
		
		
		// reference to list item.
		$("#form-errors-list li").each(function() {
		 	
		 	// list item text node
			var haystack = $(this).text();
		 	
		 	// perform search for label in list item.
		 	var res = haystack.search(regex);
		 	
		 	// returns -1 for no match, or int for position in string.
		 	if (res != -1) {
		 		
		 		// use reference from top of function to set styling.
		 		$(label).css("color","#c00");
		 	
		 	}
		 	
		 });
		 
	});
	
	
	
	
	// disable expiry date input
	$("#no-expiry").change(function() { 
		
		// if no expiry checkbox checked.
		if ( $("#no-expiry:checked").val() == "on" ) {
			
			// truncate value.
			$("#expiry").val("");
			
			// disable expiry field.
			$("#expiry").attr("disabled","disabled");
		}
		else {
			
			// checkbox not checked so remove disabled state.
 			$("#expiry").removeAttr("disabled");
 		}
	
	});
	
	
	//var img = new Image();
	//img.src = "/images/ajax_loader.gif";
	
	// add ajax loader gif to page - done like this due to stupid IE bug.
	$("#submit-upload").click(function() {
	
		// if users click the button again.
		if ( $(this).attr("value") == "Please wait..." ) {
			exit();
		}
		
		$(this).attr("value", "Please wait...");
		
		
		
		setTimeout(function() 
		{  
			var img = document.createElement("img");
			img.src = "/images/ajax_loader.gif";
			document.getElementById("ajaxloader").appendChild(img);
		}, 500);
		
	});
	
	
	
	// doc type show/hide
	/*
	$("#doctypes").change(function() {
		
		if ( $(this).attr("value") == '-1' )  {
			$("#othertype").show();
		}
		else {
			$("#othertype").hide();
		}
		
	});
	*/
	
	
	
});
