// JavaScript Document
function updateTips(text) {
	alert(text);
	//tips.text(t).effect("highlight",{},1500);
}

function checkLength(o,n,min,max) {
	if ( o.val().length > max || o.val().length < min ) {
		o.addClass('ui-state-error');
		updateTips("Length of " + n + " must be between "+min+" and "+max+".");
		return false;
	} else {
		return true;
	}
}

function checkRegexp(o,regexp,n) {
	if ( !( regexp.test( o.val() ) ) ) {
		o.addClass('ui-state-error');
		updateTips(n);
		return false;
	} else {
		return true;
	}
}
	
function checkSame(a,b) {
	if ( a.val() !== b.val() ) {
		b.addClass('ui-state-error');
		updateTips('For security reasons passwords field must be equal');
		return false;
	} else {
		return true;
	}
}

function checkFile(o) {
	if (o.val().length < 1){
		o.addClass('ui-state-error');
		updateTips('You must select a file');
		return false;
	} else { return true; }
}

function checkExt(o){
	if (o.val().length > 1){
		ext = (o.val().substring(o.val().lastIndexOf("."))).toLowerCase(); 
		if (ext != '.jpg'){
			o.addClass('ui-state-error');
			alert('The image must be a valid jpg file');			
			return false;	
		} else { return true; }
	} else { return true; }
}