var nB = false;

function testExists(imagepath) 
	{
    req = getreq();
    req.onreadystatechange = file_exists;
    req.open("head", imagepath, false);
    req.send(null);     
	}
	
function file_exists() 
	{
    if(req.readyState == 4) 
		{
        if(req.status == 200)
        	{
            // image exists
            nB=false;
        	}
        else
        	{
            // image doesn't exist
            nB=true;
        	}
    	}
	}

function getreq() 
	{ // returns false if exists
	if(window.ActiveXObject) 
		{ // if IE
		try 
			{
			return new ActiveXObject("Msxml2.XMLHTTP");
			} 
		catch(e) 
			{
			try 
				{
				return new ActiveXObject("Microsoft.XMLHTTP");
				} 
			catch(e) 
				{
				return;
				}
			}
		} 
	else if(window.XMLHttpRequest) 
		{ // if Mozilla, Safari, etc.
		return new XMLHttpRequest();
		}
	}

$(function() {
  	$("#btn_pay_single_invoice").live("click",function() { 
		document.getElementById('papyal_return').value=window.location.href;
		document.getElementById('papyal_cancel_return').value=window.location.href;
		document.make_payments.submit();
	});  
});
$(function() {
  	$("#btn_animal_srch").live("click",function() { 
		//alert("#srch_val="+$("#srch_val").val());
		var srch_val = jQuery.trim(document.getElementById('srch_val').value);
		//alert("srch_val="+srch_val);
		if(srch_val!='')
			{
			document.frm_a_search.action='animal/list.php';
			//document.getElementById('srch_val_m').value=srch_val;  
			document.frm_a_search.submit();
			}
		else
			{
			return false;
			}
	});  
});

$(function() {
  	$("#btn_member_srch").live("click",function() { 
		//alert("#srch_val="+$("#srch_val").val());
		var srch_val = jQuery.trim(document.getElementById('srch_val').value);
		alert("btn_member_srch");
		if(srch_val!='')
			{
			document.frm_a_search.action='profile/list.php';
			//document.getElementById('srch_val_m').value=srch_val;  
			document.frm_a_search.submit();
			}
		else
			{
			return false;
			}
	});  
});

$(function() {
	$("#btn_submit_note").live("click",function() {
		var comment = document.getElementById('comment').value;
		$.mobile.showPageLoadingMsg();
		// first hide any error messages
		var strData = "t_type=note";
		strData = strData + "&reg_no=" + document.getElementById('reg_no').value;
		strData = strData + "&member_id=" + document.getElementById('member_id').value;
		strData = strData + "&comment=" + comment;
		$.ajax({
      type: "POST",
      url: "save_data.php",
      data: strData,
      success: function(msg) {
		if(msg=='true')
		  	{
			$('#comment_form').html("<div id='message' align='center'></div>");
			$('#message').html("<h3>Comment Added!</h3>")
			.hide()
			.fadeIn(500, function() {
			  $('#message').append("<img id='checkmark' src='http://www.int-brangus.org/mobile/images/check.png' /><p>To return to the animal's detail<br/>view, click the 'Back' button.</p>");
			});
			}
		else
			{
			alert("Could not save data");
			}
      }
     });
	$.mobile.hidePageLoadingMsg();
		//*/
    return false;
	});  
});

$(function() {
	$("#btn_submit_ai").live("click",function() {
		var bull = document.getElementById('bull').value;
		var idx_aim = document.getElementById('ai-month').selectedIndex;
		var idx_aid = document.getElementById('ai-day').selectedIndex;
		var idx_aiy = document.getElementById('ai-year').selectedIndex;
		var aid = document.getElementById('ai-month').options[idx_aim].value+'/'+document.getElementById('ai-day').options[idx_aid].value+'/'+document.getElementById('ai-year').options[idx_aiy].value;
		//var aid = document.getElementById('ai_date').value;
		$.mobile.showPageLoadingMsg();
		// first hide any error messages
		var strData = "t_type=ai";
		strData = strData + "&reg_no=" + document.getElementById('reg_no').value;
		strData = strData + "&member_id=" + document.getElementById('member_id').value;
		strData = strData + "&bull=" + bull;
		strData = strData + "&aid=" + aid;
		$.ajax({
      type: "POST",
      url: "save_data.php",
      data: strData,
      success: function(msg) {
		if(msg=='true')
		  	{
			$('#comment_form').html("<div id='message' align='center'></div>");
			$('#message').html("<h3>AI Breeding Added!</h3>")
			.hide()
			.fadeIn(500, function() {
			  $('#message').append("<img id='checkmark' src='http://www.int-brangus.org/mobile/images/check.png' /><p>To return to the animal's detail<br/>view, click the 'Back' button.</p>");
			});
			}
		else
			{
			alert("Could not find a bull with the registration # entered.");
			}
      }
     });
	$.mobile.hidePageLoadingMsg();
		//*/
    return false;
	});  
});


$(function() {
	$("#btn_submit_disposal").live("click",function() {
		var disposal_code = "0";
        var x = document.getElementById('x').value;
		for(var i = 0; i<x; i++)
			{
			if(document.getElementById('disposal-'+i).checked)
				{
				disposal_code = document.getElementById('disposal-'+i).value;
				}
			}
         if (disposal_code == "0") {  
			   //$("label#name_error").show();  
			  alert("you did not select a disposal");
			   return false;  
			 } 
		
		$.mobile.showPageLoadingMsg();
		// first hide any error messages
		var strData = "t_type=disposal";
		strData = strData + "&reg_no=" + document.getElementById('reg_no').value;
		strData = strData + "&member_id=" + document.getElementById('member_id').value;
		strData = strData + "&disposal_code=" + disposal_code;
		$.ajax({
      type: "POST",
      url: "save_data.php",
      data: strData,
      success: function(msg) {
		if(msg=='true')
		  	{
			$('#disposal_form').html("<div id='message' align='center'></div>");
			$('#message').html("<h3>Disposal Processed!</h3>")
			.hide()
			.fadeIn(1500, function() {
			  $('#message').append("<img id='checkmark' src='http://www.int-brangus.org/mobile/images/check.png' /><p>To return to the animal's detail<br/>view, click the 'Back' button.</p>");
			});
			}
		else
			{
			alert("Could not save data");
			}
      }
     });
	$.mobile.hidePageLoadingMsg();
		//*/
    return false;
	});  
});
												
													
$(function() {

  $("#btn_submit_transfer").live("click",function() {
		//alert("button clicked");
		var loc = window.location.href;
		//alert(loc);
		// validate and process form# $('.error').hide();  
        var transfer_date = document.getElementById('transfer_date').value;  
         if (transfer_date == "") {  
			   //$("label#name_error").show();  
			  alert("Transfer Date cannot be blank");
			  document.getElementById('transfer_date').focus();  
			   return false;  
			 } 
		
		$.mobile.showPageLoadingMsg();
		// first hide any error messages
		var strData = "t_type=transfer";
		strData = strData + "&reg_no=" + document.getElementById('reg_no').value;
		strData = strData + "&member_id=" + document.getElementById('member_id').value;
		strData = strData + "&transfer_date=" + document.getElementById('transfer_date').value;
		strData = strData + "&transfer_amount=" + document.getElementById('transfer_amount').value;
		strData = strData + "&new_owner=" + document.getElementById('new_owner').value;
		$.ajax({
      type: "POST",
      url: "save_data.php",
      data: strData,
      success: function(msg) {
		if(msg=='true')
		  	{
			$('#weaning_form').html("<div id='message' align='center'></div>");
			$('#message').html("<h3>Transfer Processed!</h3>")
			.hide()
			.fadeIn(1500, function() {
			  $('#message').append("<img id='checkmark' src='http://www.int-brangus.org/mobile/images/check.png' /><p>To return to the animal's detail<br/>view, click the 'Back' button.</p>");
			});
			}
		else
			{
			alert("Could not save data");
			}
      }
     });
	$.mobile.hidePageLoadingMsg();
		//*/
    return false;
	});  
});

$(function() {

  $("#btn_submit_calf").live("click",function() {
		//alert("button clicked");
		var loc = window.location.href;
		//alert(loc);
		// validate and process form# $('.error').hide();  
        $.mobile.showPageLoadingMsg();
		// first hide any error messages
		var strData = "t_type=birth";
		strData = strData + "&reg_no=" + document.getElementById('reg_no').value;
		strData = strData + "&member_id=" + document.getElementById('member_id').value;
		var idx_bm = document.getElementById('birth-month').selectedIndex;
		var idx_bd = document.getElementById('birth-day').selectedIndex;
		var idx_by = document.getElementById('birth-year').selectedIndex;
		strData = strData + "&birth_date=" + document.getElementById('birth-month').options[idx_bm].value+'/'+document.getElementById('birth-day').options[idx_bd].value+'/'+document.getElementById('birth-year').options[idx_by].value;
		strData = strData + "&birth_weight=" + document.getElementById('birth_weight').value;
		if(document.getElementById('birth_sex-1').checked) strData = strData + "&birth_sex=B";
		if(document.getElementById('birth_sex-2').checked) strData = strData + "&birth_sex=C";
		if(document.getElementById('scurs_score-1').checked) strData = strData + "&scurs_score=P";
		if(document.getElementById('scurs_score-2').checked) strData = strData + "&scurs_score=S";
		if(document.getElementById('scurs_score-3').checked) strData = strData + "&scurs_score=H";
		var idx = document.getElementById('color_score').selectedIndex
		strData = strData + "&color_score=" + document.getElementById('color_score').options[idx].value;
		strData = strData + "&phn=" + document.getElementById('phn').value;
		var idx = document.getElementById('phn_location').selectedIndex
		strData = strData + "&phn_location=" + document.getElementById('phn_location').options[idx].value;
		strData = strData + "&animal_name=" + document.getElementById('animal_name').value;	
		if(document.getElementById('service_type-1').checked) strData = strData + "&service_type=N";
		if(document.getElementById('service_type-2').checked) strData = strData + "&service_type=A";
		if(document.getElementById('service_type-3').checked) strData = strData + "&service_type=E";	
		var idx = document.getElementById('birth_type').selectedIndex
		strData = strData + "&birth_type=" + document.getElementById('birth_type').options[idx].value;		
		strData = strData + "&dam=" + document.getElementById('dam').value;
		strData = strData + "&sire=" + document.getElementById('sire').value;		
		var idx = document.getElementById('calving_ease').selectedIndex
		strData = strData + "&calving_ease=" + document.getElementById('calving_ease').options[idx].value;		
		strData = strData + "&birth_cg=" + document.getElementById('birth_cg').value;
		strData = strData + "&birth_premise=" + document.getElementById('birth_premise').value;
		strData = strData + "&birth_pasture=" + document.getElementById('birth_pasture').value;
		var idx = document.getElementById('birth_status').selectedIndex
		strData = strData + "&birth_status=" + document.getElementById('birth_status').options[idx].value;				
		var idx = document.getElementById('suspension').selectedIndex
		strData = strData + "&suspension=" + document.getElementById('suspension').options[idx].value;
		var idx = document.getElementById('teat_size').selectedIndex
		strData = strData + "&teat_size=" + document.getElementById('teat_size').options[idx].value;
		//alert (strData);
		//return false;
		
		///*
		$.ajax({
      type: "POST",
      url: "save_data.php",
      data: strData,
      success: function(msg) {
		if(msg=='true')
		  	{
			$('#calving_form').html("<div id='message' align='center'></div>");
			$('#message').html("<h3>Calf Data Submitted!</h3>")
			.hide()
			.fadeIn(1500, function() {
			  $('#message').append("<img id='checkmark' src='http://www.int-brangus.org/mobile/images/check.png' /><p>To return to the animal's detail<br/>view, click the 'Back' button.</p><p>You will need to complete the<br/>data entry from the birth queue.</p>");
			});
			}
		else
			{
			alert("Could not save data");
			}
      }
     });
	$.mobile.hidePageLoadingMsg();
		//*/
    return false;
	});  
});
//  ENTER WEANING DATA TO THE QUEUE
$(function() {

  $("#btn_submit_weaning").live("click",function() {
		//alert("button clicked");
		var loc = window.location.href;
		//alert(loc);
		// validate and process form# $('.error').hide();  
        var wean_date = document.getElementById('wean_date').value;  
         if (wean_date == "") {  
			   //$("label#name_error").show();  
			  alert("Wean Date cannot be blank");
			  document.getElementById('wean_date').focus();  
			   return false;  
			 }  
         var wean_weight = document.getElementById('wean_weight').value;  
         if (wean_weight == "") {  
			  // $("label#email_error").show();  
			  alert("Wean Weight cannot be blank");
			  document.getElementById('wean_weight').focus();  
			   return false;  
			 } 
		
		$.mobile.showPageLoadingMsg();
		// first hide any error messages
		var strData = "t_type=wean";
		strData = strData + "&reg_no=" + document.getElementById('reg_no').value;
		strData = strData + "&member_id=" + document.getElementById('member_id').value;
		strData = strData + "&wean_premise=" + document.getElementById('wean_premise').value;
		strData = strData + "&wean_pasture=" + document.getElementById('wean_pasture').value;
		var idx_wm = document.getElementById('wean-month').selectedIndex;
		var idx_wd = document.getElementById('wean-day').selectedIndex;
		var idx_wy = document.getElementById('wean-year').selectedIndex;
		strData = strData + "&wean_date=" + document.getElementById('wean-month').options[idx_wm].value+'/'+document.getElementById('wean-day').options[idx_wd].value+'/'+document.getElementById('wean-year').options[idx_wy].value;
		//strData = strData + "&wean_date=" + document.getElementById('wean_date').value;
		strData = strData + "&wean_weight=" + document.getElementById('wean_weight').value;
		strData = strData + "&wean_cg=" + document.getElementById('wean_cg').value;
		var idx = document.getElementById('wean_mgmt').selectedIndex
		strData = strData + "&wean_mgmt=" + document.getElementById('wean_mgmt').options[idx].value;
		var idx = document.getElementById('wean_temper').selectedIndex
		strData = strData + "&wean_temper=" + document.getElementById('wean_temper').options[idx].value;
		if(document.getElementById('wean_navel'))
			{
			strData = strData + "&wean_sex=C";
			var idx = document.getElementById('wean_navel').selectedIndex
			strData = strData + "&wean_navel=" + document.getElementById('wean_navel').options[idx].value;
			}
		else
			{
			if(document.getElementById('wean_sex-1').checked) strData = strData + "&wean_sex=B";
			if(document.getElementById('wean_sex-2').checked) strData = strData + "&wean_sex=S";
			var idx = document.getElementById('wean_sheath').selectedIndex
			strData = strData + "&wean_sheath=" + document.getElementById('wean_sheath').options[idx].value;
			strData = strData + "&wean_scrotal=" + document.getElementById('wean_scrotal').value;
			}
		strData = strData + "&wean_height=" + document.getElementById('wean_height').value;
		var idx = document.getElementById('wean_status').selectedIndex
		strData = strData + "&wean_status=" + document.getElementById('wean_status').options[idx].value;
		strData = strData + "&dam_height=" + document.getElementById('dam_height').value;
		strData = strData + "&dam_weight=" + document.getElementById('dam_weight').value;
		var idx = document.getElementById('dam_bcs').selectedIndex
		strData = strData + "&dam_bcs=" + document.getElementById('dam_bcs').options[idx].value;
		var idx = document.getElementById('dam_status').selectedIndex
		strData = strData + "&dam_status=" + document.getElementById('dam_status').options[idx].value;
		//alert (strData);
		//return false;
		
		///*
		$.ajax({
      type: "POST",
      url: "save_data.php",
      data: strData,
      success: function(msg) {
        if(msg=='true')
		  	{
			$('#weaning_form').html("<div id='message' align='center'></div>");
			$('#message').html("<h3>Weaning Data Submitted!</h3>")
			.hide()
			.fadeIn(1500, function() {
			  $('#message').append("<img id='checkmark' src='http://www.int-brangus.org/mobile/images/check.png' /><p>To return to the animal's detail<br/>view, click the 'Back' button.</p><p>You will need to complete the<br/>data entry from the weaning queue.</p>");
			});
			}
		else
			{
			alert("Could not save data");
			}
      }
     });
	$.mobile.hidePageLoadingMsg();
		//*/
    return false;
	});  
});

$(function() {

  $("#btn_submit_yearling").live("click",function() {
		//alert("button clicked");
		var loc = window.location.href;
		//alert(loc);
		// validate and process form# $('.error').hide();  
        var year_weight = document.getElementById('year_weight').value;  
        if (year_weight == "") {  
			  // $("label#email_error").show();  
			  alert("Year Weight cannot be blank");
			  document.getElementById('year_weight').focus();  
			   return false;  
			 } 
		
		
		// first hide any error messages
		var strData = "t_type=year";
		strData = strData + "&reg_no=" + document.getElementById('reg_no').value;
		strData = strData + "&member_id=" + document.getElementById('member_id').value;
		strData = strData + "&year_premise=" + document.getElementById('year_premise').value;
		strData = strData + "&year_pasture=" + document.getElementById('year_pasture').value;
		var idx_ym = document.getElementById('year-month').selectedIndex;
		var idx_yd = document.getElementById('year-day').selectedIndex;
		var idx_yy = document.getElementById('year-year').selectedIndex;
		strData = strData + "&year_date=" + document.getElementById('year-month').options[idx_ym].value+'/'+document.getElementById('year-day').options[idx_yd].value+'/'+document.getElementById('year-year').options[idx_yy].value;
		//strData = strData + "&year_date=" + document.getElementById('year_date').value;
		strData = strData + "&year_weight=" + document.getElementById('year_weight').value;
		strData = strData + "&year_cg=" + document.getElementById('year_cg').value;
		var idx = document.getElementById('year_mgmt').selectedIndex
		strData = strData + "&year_mgmt=" + document.getElementById('year_mgmt').options[idx].value;
		var idx = document.getElementById('year_temper').selectedIndex
		strData = strData + "&year_temper=" + document.getElementById('year_temper').options[idx].value;
		if(document.getElementById('year_navel'))
			{ 
			strData = strData + "&year_sex=C";
			var idx = document.getElementById('year_navel').selectedIndex
			strData = strData + "&year_navel=" + document.getElementById('year_navel').options[idx].value;
			}
		else
			{
			if(document.getElementById('year_sex-1').checked) strData = strData + "&year_sex=B";
			if(document.getElementById('year_sex-2').checked) strData = strData + "&year_sex=S";
			//var idx = document.getElementById('year_sex').selectedIndex
			//strData = strData + "&year_sex=" + document.getElementById('year_sex').options[idx].value;
			var idx = document.getElementById('year_sheath').selectedIndex
			strData = strData + "&year_sheath=" + document.getElementById('year_sheath').options[idx].value;
			strData = strData + "&year_scrotal=" + document.getElementById('year_scrotal').value;
			}
		strData = strData + "&year_height=" + document.getElementById('year_height').value;
		var idx = document.getElementById('year_status').selectedIndex
		strData = strData + "&year_status=" + document.getElementById('year_status').options[idx].value;
		/*
		alert(strData);
		return false;
		//*/
		$.ajax({
      type: "POST",
      url: "save_data.php",
      data: strData,
      success: function(msg) {
        if(msg=='true')
		  	{
			$('#yearling_form').html("<div id='message' align='center'></div>");
			$('#message').html("<h3>Yearling Data Submitted!</h3>")
			.hide()
			.fadeIn(1500, function() {
			  $('#message').append("<img id='checkmark' src='http://www.int-brangus.org/mobile/images/check.png' /><p>To return to the animal's detail<br/>view, click the 'Back' button.</p><p>You will need to complete the<br/>data entry from the yearling queue.</p>");
			});
			}
		else
			{
			alert("Could not save data");
			}
      }
     });
	return false;
	});
});
$('.page-map').live("pagecreate", function() 
					{ 
					if($("#google_map"))
						{
						if($("#map_canvas")) $("#map_canvas").remove();
						var lat = $("#latitude").val();
						var lon = $("#longitude").val();
						if((lat - 0) == lat && lat.length > 0)
							{
							if((lon - 0) == lon && lon.length > 0)
								{
								$('.google_map').load($("#m_url").val());
								}
							else
								{
								//alert("lon="+lon);
								}
							}
						else
							{
							//alert("lat="+lat);
							}
						}
					}
				); 
//  GENETIC TRENDS 
$('.page-trend').live("pagecreate", function() 
					{ 
					if($("#trend_canvas")) $("#trend_canvas").remove();					
					var idx = document.getElementById('trait').selectedIndex;
					var trait= document.getElementById('trait').options[idx].value;
					var member_id = $("#member_id").val();
					var req_time = new Date(); //$("#graph_time").val();
					//$('.trend_graph').load("trend.php?trait="+trait+"&member_id="+member_id+"&t="+req_time.getTime());
					$.get("trend.php?trait="+trait+"&member_id="+member_id+"&nb="+nB+"&t="+req_time.getTime(), function(data){
   						$('.trend_graph').html(data);
						 });
					}
				);
$('#trait').live("change",function()
					{ 
					document.getElementById('trend_canvas').style.display='none';		
					document.getElementById('building_chart').style.display='block';
					var idx = $('#trait')[0].selectedIndex;
					var trait= $('#trait').val();
					var member_id = $("#member_id").val();
					var req_time = new Date(); //$("#graph_time").val();
					testExists("trends/trend2.php");
					if(!nB)
						{
						$.get("trends/trend2.php?trait="+trait+"&member_id="+member_id+"&nb=0&t="+req_time.getTime(), function(data){
							$('#trend_canvas').html(data);
							document.getElementById('trend_canvas').style.display='block';	
							document.getElementById('building_chart').style.display='none';
							 });
						}
					else
						{
						$.get("trend2.php?trait="+trait+"&member_id="+member_id+"&nb=1&t="+req_time.getTime(), function(data){
							$('#trend_canvas').html(data);
							document.getElementById('trend_canvas').style.display='block';	
							document.getElementById('building_chart').style.display='none';
							 });
						}
					}
				);
//  PERCENTILE RANKS 
$('.page-percentile-ranks').live("pagecreate", function() 
					{ 
					if($("#trait_canvas")) $("#trait_canvas").remove();					
					var idx = document.getElementById('trait2').selectedIndex;
					var trait= document.getElementById('trait2').options[idx].value;
					var req_time = new Date(); //$("#graph_time").val();
					$.get("ranks.php?trait="+trait+"&t="+req_time.getTime(), function(data){
   						$('.trait_container').html(data);
						 });
					}
				);
$('#trait2').live("change",function()
					{ 
					var idx = $('#trait2')[0].selectedIndex;
					var trait= $('#trait2').val();
					var req_time = new Date(); //$("#graph_time").val();
					$.get("ranks.php?trait="+trait+"&t="+req_time.getTime(), function(data){
   						$('.trait_container').html(data);
						 });
					}
				);
 
//  PASTURE GROUPS 
$('.page-pasture').live("pagecreate", function() 
					{ 
					if($("#pasture_canvas")) $("#pasture_canvas").remove();					
					var idx = document.getElementById('pasture_id').selectedIndex;
					var pasture_id= document.getElementById('pasture_id').options[idx].value;
					var member_id = $("#member_id").val();
					var req_time = new Date();
					$('.pasture_occupants').load("occupants.php?member_id="+member_id+"&pasture_id="+escape(pasture_id)+"&t="+req_time.getTime());
					}
				);
$('#pasture_id').live("change",function()
					{ 
					//if($("#pasture_canvas")) $("#pasture_canvas").remove();	
					if($("#pasture_canvas")) $("#pasture_canvas").remove();					
					var idx = document.getElementById('pasture_id').selectedIndex;
					var pasture_id= document.getElementById('pasture_id').options[idx].value;
					var member_id = $("#member_id").val();
					var req_time = new Date();
					$('.pasture_occupants').load("occupants.php?member_id="+member_id+"&pasture_id="+escape(pasture_id)+"&t="+req_time.getTime());
					}
				);

//  EPD DISPLAY ON ANIMAL SCREEN
/*
$('.page-animal').live("pageshow", function() 
					{ 
					if($("#epd_canvas")) $("#epd_canvas").remove();					
					var reg_no = document.getElementById('reg_no').value; //$("#reg_no").val();
					var req_time = new Date();					
					$('.epd_display').load("epd_view.php?vtype=chart&reg_no="+reg_no+"&t="+req_time.getTime());
					}
				);
$('#epd_view').live("change",function()
					{ 
					if($("#epd_canvas")) $("#epd_canvas").remove();					
					var idx = document.getElementById('epd_view').selectedIndex;
					var vType= document.getElementById('epd_view').options[idx].value;
					//alert(vType);
					var reg_no = document.getElementById('reg_no').value; //$("#reg_no").val();
					var req_time = new Date();
					//alert(req_time);
					$('.epd_display').load("epd_view.php?vtype="+vType+"&reg_no="+reg_no+"&t="+req_time.getTime());
					}
				);
*/
$('#more-animals').live("click",function()
					{ 
					if($("#more-canvas")) $("#more-canvas").remove();					
					//var srch_val = document.getElementById('srch_val_a').selectedIndex;
					//var vType= document.getElementById('srch_type').options[idx].value;
					//alert(vType);
					var more_qty = document.getElementById('list-more-qty').value;
					var srch_val = document.getElementById('srch_val').value;
					var vType = document.getElementById('type').value;
					var req_time = new Date();
					document.getElementById('list-more-qty').value = (more_qty+1);
					$("#load-more"+more_qty).load("list-more.php?type="+vType+"&srch_val="+srch_val+"&mqty="+(more_qty+1)+"&t="+req_time.getTime());
					}
				);


$('#service_type').live("change",function(){
	var idx = document.getElementById('service_type').selectedIndex
	var sType= document.getElementById('service_type').options[idx].value;
	//alert(sType);
	if(sType == 'E')
		{
		$('#dam_type').html("Recipient Dam Registration:");
		}
	else
		{
		$('#dam_type').html("Dam Registration:");
		}
 });
$('#do_gestation_calc').live("click",function()
					{ 
					so_clearInnerHTML(document.getElementById("dDueDate"));
					so_clearInnerHTML(document.getElementById("dNextHeat"));
					so_clearInnerHTML(document.getElementById("dConception"));
					so_clearInnerHTML(document.getElementById("dWean"));
					so_clearInnerHTML(document.getElementById("dYear1"));
					so_clearInnerHTML(document.getElementById("dYear2"));
					so_clearInnerHTML(document.getElementById("dYear3"));
					so_clearInnerHTML(document.getElementById("dUltrasound"));
				
					var this_date = document.getElementById('this_date').value;
					var today_date = document.getElementById('todays_date').value;
					
					//alert(this_date);
					var due_date = dateAdd('d',282,this_date);
					var conception_date = dateAdd('d',-282,this_date);
					var next_heat = dateAdd('d',21,this_date);
					var begin_wean = dateAdd('d',160,this_date);
					var end_wean = dateAdd('d',250,this_date);
					var begin_365 = dateAdd('d',320,this_date);
					var end_365 = dateAdd('d',410,this_date);
					var begin_452 = dateAdd('d',411,this_date);
					var end_452 = dateAdd('d',501,this_date);
					var begin_550 = dateAdd('d',502,this_date);
					var end_550 = dateAdd('d',600,this_date);
					var begin_us = dateAdd('d',320,this_date);
					var end_us = dateAdd('d',440,this_date);
					var age_in_days = dateDiff('d',this_date,today_date);
					document.getElementById("dDueDate").appendChild(document.createTextNode("A cow bred on the date entered should calve "+datePart('m',due_date)+'/'+datePart('d',due_date)+'/'+datePart('yyyy',due_date)+"."));
					document.getElementById("dNextHeat").appendChild(document.createTextNode("A cow in heat on the date entered would have her Next Heat on "+datePart('m',next_heat)+'/'+datePart('d',next_heat)+'/'+datePart('yyyy',next_heat)+"."));
					document.getElementById("dConception").appendChild(document.createTextNode("A cow calving on the date entered would have been bred on "+datePart('m',conception_date)+'/'+datePart('d',conception_date)+'/'+datePart('yyyy',conception_date)+" (and is "+age_in_days+" days old today)."));
					document.getElementById("dWean").appendChild(document.createTextNode(datePart('m',begin_wean)+'/'+datePart('d',begin_wean)+'/'+datePart('yyyy',begin_wean)+" - thru -  "+datePart('m',end_wean)+'/'+datePart('d',end_wean)+'/'+datePart('yyyy',end_wean)));
					document.getElementById("dYear1").appendChild(document.createTextNode(datePart('m',begin_365)+'/'+datePart('d',begin_365)+'/'+datePart('yyyy',begin_365)+" - thru -  "+datePart('m',end_365)+'/'+datePart('d',end_365)+'/'+datePart('yyyy',end_365)));
					document.getElementById("dYear2").appendChild(document.createTextNode(datePart('m',begin_452)+'/'+datePart('d',begin_452)+'/'+datePart('yyyy',begin_452)+" - thru -  "+datePart('m',end_452)+'/'+datePart('d',end_452)+'/'+datePart('yyyy',end_452)));
					document.getElementById("dYear3").appendChild(document.createTextNode(datePart('m',begin_550)+'/'+datePart('d',begin_550)+'/'+datePart('yyyy',begin_550)+" - thru -  "+datePart('m',end_550)+'/'+datePart('d',end_550)+'/'+datePart('yyyy',end_550)));
					document.getElementById("dUltrasound").appendChild(document.createTextNode(datePart('m',begin_us)+'/'+datePart('d',begin_us)+'/'+datePart('yyyy',begin_us)+" - thru -  "+datePart('m',end_us)+'/'+datePart('d',end_us)+'/'+datePart('yyyy',end_us)));
					document.getElementById('datCalculator').style.display='block';
					}
				);
