



// CLEAR FORM
$(document).ready(function(){

	$('.js-clear').click(
	function(event){ 
		$(this).parents('form').reset(); 
		
		}
	);

});
//



// FORM AUTOVALUES
$(document).ready(function(){

	function populateElement(selector, defvalue) {
		$(selector).focus(function() {
			if ($(selector).val() == 'Website') {
				$(selector).val('http://');
			} else if ($(selector).val() == defvalue) {
				$(selector).val('');
			}
		});

		$(selector).blur(function() {
				if ($.trim($(selector).val()) == '') {
						$(selector).val(defvalue);
				}
		});
	};

	$('form').find('input[type="text"], input[type="password"], textarea').each(function() {
				populateElement($(this), $(this).val());
			}
	);

});
//

// FORM SUBMIT + VALIDATE
$(document).ready(function(){
	function validateNoempty(text) {
		if (!text || text.length < 2) { return false;	}

		return true;
	}

	function validateText(text) {
		if (!validateNoempty(text)) { return false; }

		var re_text = /[^A-Za-z0-9\s!@#$%^&()_+-=}{';":.,><]/;
		if (text.match(re_text) != null ) { return false; }
		return true;
	}

	function validateEmail(email) {
		if (!validateNoempty(email)) { return false; }

		var splitted = email.match("^(.+)@(.+)$");
		if (splitted == null) return false;
		if (splitted[1] != null ) {
			var regexp_user=/^\"?[\w-_\.]*\"?$/;
			if (splitted[1].match(regexp_user) == null) { return false; }
		}

		if(splitted[2] != null) {
			var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
			if (splitted[2].match(regexp_domain) == null) {
				var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
				if (splitted[2].match(regexp_ip) == null) { return false; }
			}
			return true;
		}
		return false;
	}

	$('.js-proceed').click( function(event) {
			event.preventDefault();
			error = false;

			$(this).parents('form').children('fieldset').children('input[type="text"], textarea').each( function() {
				if ($(this).hasClass('v-noempty')) {
					if (!validateNoempty($(this).val())) {
						$(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 );
						error = true;
					}

				} else if ($(this).hasClass('v-text')) {
					if (!validateText($(this).val())) {
						$(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 ).animate( { opacity: 0.2 }, 150 ).animate( { opacity: 1 }, 150 ).animate( { opacity: 0.2 }, 150 ).animate( { opacity: 1 }, 150 );
						
						error = true;
					}
				} else if ($(this).hasClass('v-mail')) {
					if (!validateEmail($(this).val())) {
						$(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 ).animate( { opacity: 0.2 }, 150 ).animate( { opacity: 1 }, 150 ).animate( { opacity: 0.2 }, 150 ).animate( { opacity: 1 }, 150 );
						error = true;
					}
				}
			});

			if (!error) {
				//var node = $(this).parents('.js-hidebox');
				//node.slideUp('slow');
				//loadnote($(this));
				$(this).parents('form').submit();
			}

			//alert( (error)?'error' : 'no' ) ;
			return false;
		}
	);

	var _char_count = 500;

	$('textarea').keydown( function() {
			var node = $(this).parents('form').children('.w-left').
												 children('.w-action').children('.js-count-char').children('em');

			if ($(this).val().length >= _char_count) {
				$(this).val( $(this).val().substr(0, _char_count) );
			}

			node.html( _char_count - $(this).val().length );

		}
	);

});
//



$(document).ready(function(){


	$('.open-info').click(
	function(event){ 
		var infoid=$(this).find('img').attr('alt'); 
		var timg=$(this).find('img');
		var imgs=$(this).parents('.menu-holder').find('img');
		var infos=$('.info-box');
		
		if($('#'+infoid).css('display')=='none')
		{
			infos.animate({height:'hide',opacity:'hide'}, 'slow');
			$('#'+infoid).animate({height:'show',opacity:'show'}, 'slow');
			imgs.removeClass('fade21');
			timg.addClass('fade21');
			
			
		}
		else
		{
		
			$('#'+infoid).animate({height:'hide',opacity:'hide'}, 'slow');		
			timg.removeClass('fade21');
		
		}
		
		
		}
	);


});
//


Cufon.replace('.font-bank');
