$(document).ready(function(){

$(".zip-search-container .zip-text").html("Check your On Demand menu or call your local video service provider to order for Too Much For TV today.");

//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 id='loading-screen'><img src='images/zip-locator/ajax-loader.gif' class='loading-bar' /></div>"

// 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-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();
			$("#mso-results").append(loading_html);
			$("#loading-screen").fadeIn();
		}, // end of beforeSend:
		complete: function(){
			$("#loading-screen").fadeOut("slow");
		}, //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")})});
})
	
}) // end of .ready()
