/**
 * @author Volkan
 */
 
 
/**
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * @class Validate
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 */
var Validate = Class.create( {
	initialize : function() {
	},

	/**
	 * @example
	 * 
	 * var validate = new Validate();
	 * 
	 * validate.all();
	 */
	all : function(form,type) {
		var isValidated = true;
		var getParameterList = $(form).serialize().toQueryParams();

		Object.keys(getParameterList).each( function(field) {
			if ($(field + '_validate')) {
				$(field + '_validate').style.display = 'none';

				if ($(field).value == '') {
					$(field + '_validate').style.color = '#CE0000';
					$(field + '_validate').style.display = 'block';
					$(field).focus();

					isValidated = false;
				}
			}

			if ($(field + '_validate_email')) {
				$(field + '_validate_email').style.display = 'none';

				if (new Helper_Common().validateEmail($(field).value) == false) {
					$(field + '_validate_email').style.color = '#CE0000';
					$(field + '_validate_email').style.display = 'block';
					$(field).focus();

					isValidated = false;
				}
			}			
		});

		if (isValidated == true) {
			if (type){
				return true;
			} else {
				$(form).submit();
			}
		} else {
			return false;
		}
	},

	/**
	 * @example
	 * 
	 * var validate = new Validate();
	 * 
	 * validate.confirmation();
	 */
	confirmation : function(division, link) {
		jQuery( function() {
			jQuery('#' + division).dialog( {
				bgiframe : true,
				resizable : false,
				height : 170,
				modal : true,
				draggable : false,
				overlay : {
					backgroundColor : '#000',
					opacity : 0.5
				},
				buttons : {
					'Yes' : function() {
						jQuery(this).dialog('destroy');
						document.location.href = link;
					},
					Cancel : function() {
						jQuery(this).dialog('destroy');
						jQuery(this).dialog('close');
					}
				}
			});
		});
	}
});


/**
 * 
 * 
 * @class Helper_Common
 * 
 * 
 */

var Helper_Common = Class.create( {
	initialize : function() {

	},

	checkCheckBox : function (division){
		if ($(division).checked) {
			$(division).value = '1';
		} else {
			$(division).value = '0';
		}
	},
	
	checkIsNumber: function (e, message){
		var key = (window.event) ? e.keyCode : e.which;
		if (((key < 58) && (key > 47)) || key == 13){
			return true;
		} else {
			if(typeof(message) != 'undefined'){
				alert(message);
			}
			return false;
		}
	},
	
	validateEmail: function(email){
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   if(reg.test(email) == false) {
	      return false;
	   } else {
		   return true;
	   }
	}
	
});