function textClear (obj,text){
	if($(obj).val() == text){
		$(obj).val("");
	}
}

function textRelace (obj,text){
	if($(obj).val() == ""){
		$(obj).val(text);
	}
}


$(document).ready(function(){

//zebra lines
$("#mso-list li:nth-child(even), #mso-list-results li:nth-child(even)").addClass("even");
// open links in new window
$("#mso-list li a, #mso-list-results a").attr('target', '_blank');

var loading_html = "<div class='loading-screen'><img src='images/ajax-loader.gif' class='loading-bar' /></div>"

$('#reset-list').hide();

// openbox
$(".thickbox").colorbox({iframe:true, innerWidth:690, innerHeight:580});


// hide content on zip submit
$('#submit-btn').click(function(){
	var load_url = "/findTM4TV.do"; // this is the jsf file that the query will call. Please update to the one that will work for this page
	var zip = $('#zip-search').val(); // get the value input on the field
	
	//validation
	if (zip =="") {
		$(".zip-label").show();
		$(".zip-label").css("background", "#f0d8df");
		$("#zip-search").focus();
		return false;
	}
	
	if(zip != ""){
		$('.zip-label').hide();
	}
	
	$.ajax({
		type: "POST", // GET or POST?
		url: load_url, 
		data: "zip="+zip + "&action=zip-locator",		
		beforeSend: function(){
			$("#mso-list").fadeOut();
			$("#submit-btn").fadeOut();
			$("#mso-results").append(loading_html);
			$(".loading-screen").fadeIn();
		}, // end of beforeSend:
		complete: function(){
			$(".loading-screen").fadeOut("slow", function(){$(".loading-screen").html("");} );
		}, //end of complete:
		success: function(html) {
			$("#mso-list-results").fadeIn(function(){$('#reset-list').fadeIn("slow")});
			$("#mso-list-results").html(html);
			//alert(html);
			//$("#mso-list li:nth-child(even)").addClass("even"); //apply zebra lines after html is done
		} // end of success:
	}); // end of .ajax()
	
}); // end of .click()

/* testing
$('#hide').click(function(){
	$("#mso-list").fadeOut();
}); 
*/

$('#reset-list').click(function(){
	$("#mso-list-results").fadeOut(
		function(){$("#mso-list").fadeIn(
			function(){$('#reset-list').fadeOut("slow")}
		);
		$("#submit-btn").fadeIn();
		$(".zip-label").fadeIn();
		}
	);
})
	
}) // end of .ready()