var forms = [];
$(document).ready(function(){
	
	initForm();
		
});


function initForm(){
	
	forms = document.getElementsByTagName("form");
	
	//loop all the forms --- "i" is a counter
	$('form').each(function(i){
	
		//console.log(forms[i]);

		//process all the input text fields 
		$(this).find("input[type='text']").each(function(){
			var val = $(this).attr('value');
			$(this).focus(function(){
				$(this).attr("value","");
			});
			$(this).blur(function(){
				if($(this).attr("value") == ""){
					$(this).attr("value",val);
				}
			});
		});
		
		//process all the select to autosubmit
		$(this).find("select").each(function(){

			$(this).change(function(){
				//console.log(forms[i],i);
				forms[i].submit();
			});
		});
		
		// hide submit button
		$(this).find("input[type='submit']").each(function(){
			$(this).hide();
		});
		
	});
}






