var SOTD = {
	init: function() {
		SOTD.vis.Search();
		SOTD.vis.Comment();
		SignUpLogin.user();
	},
	
	core: {
		CheckInputMatch : function(oInput,sMatchTerm) {
			if (oInput.val()==sMatchTerm)
				return true;
			else
				return false;
		},
		displayhideBox: function(oBox) {
			oBox.stop(false,true);
			if (oBox.is(":hidden"))
				oBox.slideDown('normal');
			else
				oBox.slideUp('normal');
		}
	},
	
	vis: {
		Search : function() {
			if ($('#input-search').val()=='' || $('#input-search').val()==SOTD.GLB.defaultSearchTxt) {
				$('#input-search').val(SOTD.GLB.defaultSearchTxt).bind('focus',function(){
					if (SOTD.core.CheckInputMatch($(this),SOTD.GLB.defaultSearchTxt))
						$(this).val('');
				});
			}
		},
		Comment : function() {
			if ($('#addcomment').val()=='' || $('#addcomment').val()==SOTD.GLB.defaultCommentTxt) {
				$('#addcomment').val(SOTD.GLB.defaultCommentTxt).bind('focus',function(){
					if (SOTD.core.CheckInputMatch($(this),SOTD.GLB.defaultCommentTxt)) {
						$(this).val('');
						$(this).css('color','#000');
					}
				});
			}
		}
	},
	
	vote: {
		Check : function() {
			if ($('#reason-select').val()=='') {
				alert('Please select a reason for your vote...');
				return false;
			} else
				return true;
		}	
	},
	
	signup: {
		Check : function() {
			sError='';
			if ($('#competition-checkbox').is(':checked')==true) {
				if ($('#PMSPeopleCountry').val()==0)
					sError+='\n - Your country of residence';
				if ($('#PMSPeopleBirthdateD').val()==0 || $('#PMSPeopleBirthdateM').val()==0 || $('#PMSPeopleBirthdateY').val()==0)
					sError+='\n - Your date of birth';
			} 
			
			if (sError!='') {
				alert('In order to enter you in the prize draw, we need the following details from you:'+sError);
				return false;
			} else
				return true;
		}
	},
	
	GLB: {
		defaultSearchTxt: 'Search for song / artist / year',
		defaultCommentTxt: 'Have your say...'
	}
}

var SignUpLogin = {
	init: function() {
		$('#div-reset-pw').hide();
		$('#link-forgotten-pw').html('<a href="javascript:void(0)">Forgotten Password?</a>').bind('click',function(){
			PW.core.displayhideBox($('#div-reset-pw'));
		});
		
		if ($('#input-login-username').val()=='' || $('#input-login-username').val()==SignUpLogin.GLB.defaultUsernameTxt) {
			$('#input-login-username').val(SignUpLogin.GLB.defaultUsernameTxt).bind('focus',function(){
				if (PW.core.CheckInputMatch($(this),SignUpLogin.GLB.defaultUsernameTxt))
					$(this).val('');
			});
		}
		
		if ($('#input-signup-email').val()=='') {
			$('#input-signup-email').val(SignUpLogin.GLB.defaultEmailTxt).bind('focus',function(){
				if (PW.core.CheckInputMatch($(this),SignUpLogin.GLB.defaultEmailTxt))
					$(this).val('');
			});
		}
		
		if ($('#input-lostpw-email').val()=='') {
			$('#input-lostpw-email').val(SignUpLogin.GLB.defaultEmailTxt).bind('focus',function(){
				if (PW.core.CheckInputMatch($(this),SignUpLogin.GLB.defaultEmailTxt))
					$(this).val('');
			});
		}
	},
	user: function() {
		$('#link-logout').bind('click', function(e) {
			if (confirm('Are you sure you want to logout?')) return true;
			else return false;
		});
	},
	GLB: {
		defaultUsernameTxt: 'Enter your VIP username',
		defaultEmailTxt: 'Enter your email address'
	}
}
