function ajaxRequest(url, params, complete_method) {
	new Ajax.Request( url, { method: 'get', parameters:params, onSuccess: complete_method });	
}

function redirect(url) {
	document.location.href = url;
}

/**
 * Is empty
 * 
 * @param string elementId
 * @return bool
 */
function isEmpty(elementId) {
	var validator = new Validator();
	
	if ( validator.isEmpty($F(elementId)) || validator.isWhiteSpace($F(elementId)) ) {
		$(elementId).value = "";
		return true;
	} else {
		return false;
	}
}

/**
 * Is correct email or not 
 * 
 * @param string email
 */
function isEmail(email) {
	var validator = new Validator();
	return validator.isEmail(email); 
}

var ERROR_CLASS_NAME = "errorInput";

function setErrorClass(elementId){
	element = $(elementId);
	element.addClassName(ERROR_CLASS_NAME);
	element.focus();
}

function updateCaptcha(){
	var captchaImg = $("captcha_img");
	var errorMessage = $("error");
	captchaImg.src = "";
	captchaImg.setStyle({visibility: 'hidden'});
	if (errorMessage){
		errorMessage.setStyle({display: 'none'});
	}
	ajaxRequest(updateCaptchaUrl, "", updateCaptchaComplit);	
}

function updateCaptchaComplit(originalRequest, json){
	if (json.captcha_id != null && json.captcha_id != ""){
		var captchaImg = $("captcha_img");
		var captchaId = $("captcha_id");
		captchaImg.observe('load', function(){
			captchaImg.setStyle({visibility: 'visible'});
		});
		captchaImg.src = captchaImageUrl + json.captcha_id + ".png";
		captchaId.value = json.captcha_id;
	}
}
