window.onload = loadJquery;

function loadJquery() {
	if(typeof jQuery === "undefined" || $.browser.msie) {
		document.getElementById('username3').value = "";
		document.getElementById('password4').value = "";
	}
	else {
		defaultInput();
	}
}

function defaultInput(){
	$('#username3').data('def_value', $('#username3').attr('value'));
	$('#dmshuk_login').children('input').each(function() {
		$(this).data('def_value', $(this).attr('value'));
		$(this).data('def_color', $(this).css('color'));

		$(this).focus(function() {
			if($(this).css('color') != "rgb(0, 0, 0)") {
				$(this).css('color', "rgb(0, 0, 0");
			}
			
			if($(this).attr('value') == $(this).data('def_value')) {
				$(this).attr('value', "");
			}
		});

		$(this).focusout(function() {
			if($(this).css('color') != $(this).data('def_color')) {
				$(this).css('color', $(this).data('def_color'));
			}
			
			if($(this).attr('value') == "") {
				$(this).attr('value', $(this).data('def_value'));
			}
		})
	});

	if($('#username3').data('def_value')) {
		$('#username').focus();
	}

	$('#dmshuk_login').submit(function(evt) {
		var loginErrors = [];
		$('#login_submit').focus();
		$('#dmshuk_login').children('input').each(function() {		
			if($(this).attr('value') == $(this).data('def_value') || $(this).attr('value') == "") {
				switch($(this).attr('id')) {
					case "username3":
						loginErrors.push("Username is empty!");
						$('#username3').css('color', 'rgb(255, 0, 0)');
					break;
					case "password4":
						loginErrors.push("Password is empty!");
						$('#password4').css('color', 'rgb(255, 0, 0)');
					break;
				}
			}
		});
		
		if(loginErrors.length > 0) {
			evt.preventDefault();
		}
	});
}

