
$(function() {
fieldLabels();
})

function fieldLabels (){
	// fieldArr will store original placeholder text values
	var fieldArr = new Array();
  	$( '.formLabels' ).each(
		//listIndex is iteration index
     	function(listIndex){
     		fieldArr[listIndex]=this.innerHTML;		
		}
    );
    //loop over each text input element
    $('.promo_input').each(
		//fieldIndex is iteration index
     	function(fieldIndex){
     		this.value=fieldArr[fieldIndex];
    	 	//bind the focus and blur events to clear or restore original placeholder text
   			$( this ).bind (
    				"focus",
    				function(){
						if (this.value==fieldArr[fieldIndex]) {
						this.value="";
						}
					}
				 );
		  	$( this ).bind (
    				"blur",
    				function(){
						if (this.value=='') {
							this.value=fieldArr[fieldIndex];
   						}
					 } 
		 	);
    	}
    ); 
	//finds the search/submit button
	 $('.promo_search').each(
		//fieldIndex is iteration index
     	function(fieldIndex){
     		this.value=fieldArr[fieldIndex];
    	 	//bind the onclick event to function which clears out labels if unwanted
   			$( this ).bind (
    				"click",
    				function(){
						$('.promo_input').each(
						//subIndex is iteration index
     					function(subIndex){
							if (this.value==fieldArr[subIndex]) {
							this.value="";
						}
    				}
  			  ); 		
			}
		);
    }
    ); 
}
