function checkEmail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)){
		return true;
	}else{
		return false;
	}
}

function intval (mixed_var, base) {
    // Get the integer value of a variable using the optional base for the conversion
    //
    // version: 910.813
    // discuss at: http://phpjs.org/functions/intval    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Matteo
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4
    // *     example 3: intval(42, 8);    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9
    // *     example 5: intval('1e', 16);
    // *     returns 5: 30    var tmp;

    var type = typeof( mixed_var );

    if (type === 'boolean') {        return (mixed_var) ? 1 : 0;
    } else if (type === 'string') {
        tmp = parseInt(mixed_var, base || 10);
        return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;
    } else if (type === 'number' && isFinite(mixed_var) ) {        return Math.floor(mixed_var);
    } else {
        return 0;
    }
}

function urlencode(str) {
    return escape(str.replace(/%/g, '%25').replace(/\+/g, '%2B')).replace(/%25/g, '%');
}


function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

};

function addZero(i){
	if(i <= 9){
		return '0' + i;
	}else{
		return i;
	}
};

function isHour(sHour){
	var sSeparator = ':';
	var withSeconds = false;
	if(sHour.match("^[0-9]{2}:[0-9]{2}:[0-9]{2}$")) var withSeconds = true;
	else if(!sHour.match("^[0-9]{2}:[0-9]{2}$")) return false;
	var arHour = sHour.split(sSeparator);
	var iHour = parseInt(arHour[0]);
	var iMinute = parseInt(arHour[1]);
	if(withSeconds)	var iSecs = parseInt(arHour[2]);
	else 						var iSecs = 0;
	return 	(iHour >= 0 && iHour < 24) && (iMinute >= 0 && iMinute < 60) && (iSecs >= 0 && iSecs < 60);
};

/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*/
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";

	if(typeof(arr) == 'object') { //Array/Hashes/Objects
	 for(var item in arr) {
	  var value = arr[item];

	  if(typeof(value) == 'object') { //If it is an array,
	   dumped_text += level_padding + "'" + item + "' ...\n";
	   dumped_text += dump(value,level+1);
	  } else {
	   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
	  }
	 }
	} else { //Stings/Chars/Numbers etc.
	 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
};


/**
$('#form_submit').click(function(){
	var inputs = new Array();
		inputs.push( new Array('form_text','text') );

	if( check_inputs(jQuery, inputs) == false){
		$(this).attr('disabled');
		$('.form_contact').trigger('submit');
	}
	$(this).trigger('blur');
});*/
function check_inputs($, inputs ){

	var errorForm = false;
	var class_name = 'input_error';

	if( arguments.length > 2 ){
		class_name = arguments[2];
	}

	for( var i in inputs ){
		var input = inputs[i];

		if( typeof(input[0]) == 'undefined' || input[0] == 'undefined' ){
			continue;
		}

		$('#' + input[0] ).removeClass(class_name);
		if( $('#' + input[0] ).val() == '' ){
			errorForm = true;
			$('#' + input[0] ).addClass(class_name);
		}

		if( input[1] == 'email' && !checkEmail( $('#' + input[0] ).val() ) ){
			errorForm = true;
			$('#' + input[0] ).addClass(class_name);
		}

		if( input[1] == 'number' && !IsNumeric( $('#' + input[0] ).val() ) ){
			errorForm = true;
			$('#' + input[0] ).addClass(class_name);
		}

		if( input[1] == 'hour' && !isHour( $('#' + input[0] ).val() ) ){
			errorForm = true;
			$('#' + input[0] ).addClass(class_name);
		}

		if( typeof(input[2]) != 'undefined' && $('#' + input[0] ).val() != $('#' + input[2] ).val() ){
			errorForm = true;
			$('#' + input[0] ).addClass(class_name);
		}

	}

	return errorForm;
}

