// JavaScript Document
//Mypod Pod page init

$(document).ready(function() {
			
  	//accordion
			$('#accordion').accordion({
				header: ".ui-accordion-header",
				clearStyle: true
			});

 
	// open window
	$('a.newwin').click(function() {
    var href = $(this).attr('href');
    window.open(href, 'livestock Transport',
    'height=600,width=600,scrollbars=yes,toolbar=no');
    return false;
  });

$("#TripTicket").tablesorter( 
			  {widgets: ['zebra']
    }); 
$("#MyTickets").tablesorter( 
			  {widgets: ['zebra']
    }); 
$("#Haulerlst").tablesorter( 
			  {headers :{4:{sorter: false}} ,widgets: ['zebra']
    }).tablesorterPager({container: $("#pager"), size:30,positionFixed: false});;
$("#Triplst").tablesorter( 
			  {widgets: ['zebra'],sortList: [[3,1]] 
    }).tablesorterPager({container: $("#pager"),size:30,positionFixed: false});;
$("#Requestlst").tablesorter( 
			  {widgets: ['zebra'],sortList: [[3,1]] 
    }).tablesorterPager({container: $("#pager"),size: 30, positionFixed: false});;

   $("#haulerchk").each( function() {
	if (this.checked) {
		 $("#displayh").show();
	 }else {
     $("#displayh").hide();
	 };			   
  });

   $("#haulerchk").click(function() {
	 if (this.checked) {
		 $("#displayh").show("slow");
	 }else {
     $("#displayh").hide("slow");
	 };
   });

//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);


// Comments
$("#commentform").hide();
$(".comment").click(function() {
		 $("#commentform").toggle("slow");

 });

$(".replyform").hide();
$(".replylnk").click(
		function() { $(this).next(".replyform").toggle("slow");	}	 
 );		 
		 
$("#tabs").tabs();


$("#starsfeedback").children().not(":radio, span").hide();
$("#starsfeedback").stars();
		 
// Source State
$("#source_country").change(function(){
var id=$(this).val();
$.ajax({
	type: "POST",
	url: "/manage/state/"+ id,
	cache: false,
	success: function(html) {
		$("#Sourcestate").html(html);
		} 
	});
});
// Dest State
$("#dest_country").change(function(){
var id=$(this).val();
$.ajax({
	type: "POST",
	url: "/manage/state/"+ id,
	cache: false,
	success: function(html) {
		$("#Deststate").html(html);
		} 
	});
});
$("#country").change(function(){
var id=$(this).val();
$.ajax({
	type: "POST",
	url: "/manage/state/"+ id,
	cache: false,
	success: function(html) {
		$("#state").html(html);
		} 
	});
});

//$(".addstate").hide();	
$( "#addstate-form" ).dialog({
			autoOpen: false,
			height: 250,
			width: 460,
			modal: true			
		});
$( ".addstate" ).click(function() {
		    $( "#addstate-form" ).dialog( "open" )
			//,	$( "#presclonefrm").attr({'action': $(this)[0].href });
});	 

// Add State
$('#addstatefrm').submit(function() { 
    // submit the form 
    $(this).ajaxSubmit(); 
    // return false to prevent normal browser submit and page navigation
	$( "#addstate-form" ).dialog( "close" )	
	$("#source_country").trigger('change');
	$("#dest_country").trigger('change');
    return false; 
});
 

$('.addstate').ajaxStart(function() {
$(this).hide();
}).ajaxStop(function() {
$(this).show();
}); 
		 
});// end ready


function submit_search() {	
		$('#searchcri').submit();
	}
