if (self != top) { top.location = self.location; }

function trim(s) {
	return s.replace(/^\s+|\s+$/g, '');
}

function loadContent(action){
	if('forgot'==action){
		loadUsername();
	}else if('reset'==action){
		loadChangePassword(action);
	}else if('new'==action){
		loadChangePassword(action);
	}else if('fail'==action){
		loadLogin(action);
	}else if('expired'==action){
		loadLogin(action);
	}else if('login'==action){
		loadLogin(action);
	}else if('invalid'==action){
		loadLogin(action);
	}
}

function checkDataConsistencyResetPass(){
	if(trim($('#txt_uid').val()) === ''){
		alert('Please specify value for Username.');
		return false;
	} else {
		return true;
	};
}

function registerPreloaders() {
	$('.ajaxcontainer').ajaxStart(function() {
		 $('#progress').show();
		 $('#notification').hide();
	});
	$('.ajaxcontainer').ajaxStop(function() {
		$('#progress').hide();
		
	});
}

function loadLogin(act){
	$("#login_form").load('ajax_jsp/dologin.html',{action:act});
}

function setFocus(id)
{
	$("#" + id).focus();
}

function loadUsername(act, send){
	if(null == act){act = 'none';}
	var params = {action:act};
	if(null != send){params['send']='send';}
	if($('#txt_uid').length > 0){
		params['uid']=$('#txt_uid').val();
	}
	$("#login_form").load('ajax_jsp/reset_password.html',params);
}

function loadChangePassword(act, update){
	var params = {action:act};
	if($('#hid_uid').length > 0){
		params['uid']=$('#hid_uid').val();
	}
	if($('#hid_fromurl').length > 0){
		params['fromurl']=$('#hid_fromurl').val();
	}
	if($('#hid_tmp').length > 0){
		params['tmp']=$('#hid_tmp').val();
	}
	if($('#txt_pass').length > 0){
		params['newpass']=$('#txt_pass').val();
	}
	if($('#txt_oldpass').length > 0){
		params['oldpass']=$('#txt_oldpass').val();
	}
	if(null != update){
		params['update']=update;
	}
	
	$.post(	'ajax_jsp/change_password.html',
			params,
			function(data){
				$("#login_form").html(data);
			   });
}

function checkDataConsistencyPassChange() 
{
	if(($('#txt_oldpass') > 0) && (trim($('#txt_oldpass').val()) === '')){
		alert('The field \'Old password\' should not be empty!');
		return false;
	}
	if(trim($('#txt_pass').val()) === ''){
		alert('The field \'New password\' should not be empty!');
		return false;
	}
	if(trim($('#txt_pass').val()) !== trim($('#txt_confirmpass').val())){
		alert('The values in \'New password\' and \'Confirm new\' are different!');
		return false;			
	}

	return true;
}

function showNotification(color, message)
{
	$('#notification').attr('class', color + '_box');
	$('#notification_message').attr('innerHTML', message);
	$('#notification').show();
}
