$(document).ready( function () {

 	if(!isSupportsPlaceholder()) {
		$("input[placeholder],textarea[placeholder]").each(function() {
			 var $input = $(this);
			 
			  //activate placeholder
			 	placeholder($input);	
			 
				$input.focus(function() {
					removePlaceholder($input);
				});
				
				$input.blur(function() {
					placeholder($input);
				});
			
    });         	
  }          	
	
});

//checks if browser supports placeholders
function isSupportsPlaceholder() {
	var test = document.createElement('input');
	return 'placeholder' in test;
}

//activates placeholder on a field
function placeholder(el) {
	if(el.val() === '') {
		el.val(el.attr('placeholder'));		
		el.attr('placedholder', (el.css('color') ? el.css('color') : ''));
		el.css('color', '#ccc');
	}
}

//this methods removes placeholder
function removePlaceholder(el) {
	if(el.attr('placedholder')) {
		el.val('');
		el.css('color', el.attr('placedholder'));
		el.removeAttr('placedholder');
	}
}

//this method has to be called when u submit a form in order to fix 
//fields to submit properly
function removePlaceholders() {
	if(!isSupportsPlaceholder()) {
		$("input[placeholder],textarea[placeholder]").each(function() {
			removePlaceholder($(this));
		});
	}
}


