function hideErrors() {
	$("p.errorField").each(
			function(){
				$(this).css('display', 'none');
			}
	);
	$("div.ctrlHolder").each(
			function(){
				$(this).removeClass('error');
			}
	);
};
function hidePreviewError() {
	$("#error_custom_param").each(
			function(){
				$(this).css('display', 'none');
			}
	);
	$("#div_custom_param").each(
			function(){
				$(this).removeClass('error');
			}
	);
};
function displayErrors() {
	var obj = this;
	hideErrors();
	for ( var i in errors )
	{
		var supDiv = $('#'+errors[i]['name']).parents('p1');
		supDiv.addClass('error');
		var downP = $('#'+errors[i]['name']).children();
		supDiv.children('p').append(errors[i]['msg']);
		supDiv.children('p').css('display', 'block');
	}
	errors = {};
};
function displayPreviewError(msg) {
	$("div_custom_param").attr('class','error');
	$("error_custom_param").attr('', msg);
	$("error_custom_param").css('display', 'none');
	
};


function updateTips(t,tip) {
	tip;
	tip.removeClass('error');
	tip.removeClass('success');
	tip
		.text(t)
		.addClass('tip-highlight');
//	setTimeout(function() {
//		tip.removeClass('tip-highlight');
//	}, 500);
	setTimeout(function() {
		tip.addClass('error', 1500);
	}, 500);
};

function updateTipsSuccess(t,tip) {
	tip;
	tip.removeClass('error');
	tip.removeClass('success');
	tip
		.text(t)
		.addClass('tip-highlight');
//	setTimeout(function() {
//		tip.removeClass('tip-highlight');
//	}, 500);
	setTimeout(function() {
		tip.addClass('success', 1500);
	}, 500);
};

function checkLength(o,n,min,max) {
	if ( o.val().length > max || o.val().length < min ) {
		o.addClass('ui-state-error');
		updateTips(lenght + n + between +min+and+max+".",o.next());
		return false;
	} else {
		return true;
	}
};

function checkLengthMin(o,n,min) {
	if ( o.val().length < min ) {
		o.addClass('ui-state-error');
		updateTips(lenght + n + bigger_than +min+".",o.next());
		return false;
	} else {
		return true;
	}
};

function checkLengthOtherMin(v,o,n,min) {
	if ( v.val().length < min ) {
		v.addClass('ui-state-error');
		updateTips(lenght + n + bigger_than +min+".",o);
		return false;
	} else {
		return true;
	}
};

function checkLengthNotNull(o,n) {
	if ( !o.val() || o.val().length <= 0 ) {
		o.removeClass('idleField').addClass('ui-state-error');
		updateTips(n + is_required ,o.next());
		return false;
	} else {
		return true;
	}
};

function checkLengthOtherNotNull(v,o,n) {
	if ( v.val().length <= 0 ) {
		v.addClass('ui-state-error');
		updateTips(n + is_required ,o.next());
		return false;
	} else {
		return true;
	}
};

function otherCheckLengthNotNull(v,o,n) {
	if ( v.val().length <= 0 ) {
		v.addClass('ui-state-error');
		updateTips(n + is_required ,o);
		return false;
	} else {
		return true;
	}
};

function checkRegexp(o,regexp,n) {
	if ( !( regexp.test( o.val() ) ) ) {
		o.addClass('ui-state-error');
		updateTips(n,o.next());
		return false;
	} else {
		return true;
	}
};

function checkOtherRegexp(v,o,regexp,n) {
	if ( !( regexp.test( v.val() ) ) ) {
		v.addClass('ui-state-error');
		updateTips(n,o);
		return false;
	} else {
		return true;
	}
};

function checkValueRegexp(o, val,regexp,n) {
	if ( !( regexp.test( val ) ) ) {
		o.addClass('ui-state-error');
		updateTips(n,o.next());
		return false;
	} else {
		return true;
	}
};

$(document).ready(function(){
	$('#statemessageform').submit(function() {
		return false;
	});
	$('#speak').click(function(){
		
	});
	$('#msgstatus').addClass("idleField");
    $('#msgstatus').focus(function() {
    	$('#status_cache').val($('#msgstatus').html());
    	$('#msgstatus').removeClass("idleField").addClass("focusField");
    	x = $('#msgstatus').css('height');
    	$('#speak').css('display', 'block');
    	
    });
    var mouseOver = false;
    $("#speak")
	    .mouseover(function() { mouseOver = true; })
	    .mouseout(function() { mouseOver = false; });

    $('#msgstatus').blur(function() {
    	$('#msgstatus').removeClass("focusField").addClass("idleField");
    	if (mouseOver) {
	    	if($('#msgstatus').html()){
				$.ajax({
					type : "POST"
				  	,url : "/index/ajax-user-update/"
				  	,data : { 
				  		format: 'json'
				  		, text: $('#msgstatus').html()
						}
			  		,dataType : "json"
				  	,success:function(data){
			  			if(!data){
			  				
			  			}else if(data.success){
			  				$('#msgstatus').html(data.text);
			  				$('#msgstatus').css('color', '#999999');
			  				if(data.text){
			  					$('#status_hidden').attr('value', data.text);
			  				}else{
			  					$('#status_hidden').attr('value', $('#status_cache').val());
			  				}
						}
			  	    	$('#speak').css('display', 'none');
					}
			  		,error:function(){
			  			alert('error');
			  		}
				});
			}
	    	return;
	    }else{
	    	$('#msgstatus').html($('#status_cache').val());
	    }
	    $('#speak').css('display', 'none');
    });
});
