//var test="/assets/images/horse.gif";
function imageFun(imagePath,obj)
{
  //$('#horseimage156').attr("src", imagePath);
  $("#"+obj).attr("src", imagePath);	
}
function noLocation(error) {
      switch(error.code) {
        case error.TIMEOUT:
          var necdnumber = $('#necdnumber').val();  
			$.ajax({  
				type: "POST",  
				url: "/necdcheck.php",  
				data: "source=computer&necdnumber="+ necdnumber,  
				success: function(msg){
					$("#necdsearchresults").html(msg);
					$("#necdsearchresults").fadeIn("fast");
				}
			});
          break;
      };
    }
    function callSuccessFunction()
	{
		alert('');
	}
	$(document).ready(function() {
							   
	// Try and protect images being right-clicked
	
$('img').mousedown(function(event) {
    
	switch (event.which) {
        case 1:
        break;
        
		case 2:
			alert("Copyright NECD");
        return false;
        break;
        
		case 3:
			alert("Copyright NECD");
		return false;
        break;
        
		default:
        return false;
		break;
    }
	
});


// Works with startup.css to stop the my equestrian estate looking ugly :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#estate").fadeIn("fast");
	
	// Home ticker :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("div#scrollingText").smoothDivScroll({autoScroll: "always", autoScrollDirection: "endlessloop", pauseAutoScroll: "mouseover", autoScrollInterval: 0});
	
	// Home news :::::::::::::::::::::::::::::::::::::::::::::::::
	
	 // $("#slideshow").fadeTransition({pauseTime: 8000, transitionTime: 2000, ignore: "#introslide", delayStart: 500, pauseNavigation: false});
	 
	//http://www.ezjquery.com/cgi-bin/webapp.rb?r=access#
	
	var newsoption = {
		firstname: "mynews",
		secondname: "showhere",
		thirdname:"news_display",
		fourthname:"news_button",
		newsspeed:'12000'
	}
	$.init_plus(newsoption);
	
	if ($("#news_button").length > 0){
    
	var myoffset=$('#news_button').offset();
	var mytop=myoffset.top-1;
	
	$('#news_button').css({top:mytop});
	}
	 	
	// Detect Caps lock :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('#password-password').keypress(function(e){
        var w = e.which ? e.which : (e.keyCode ? e.keyCode : -1);
        var s = e.shiftKey ? e.shiftKey : (e.modifiers ? !!(e.modifiers & 4) : false);
        var c = ((w >= 65 && w <= 90) && !s) || ((w >= 97 && w <= 122) && s);
        $("#capslock").val(c);
    });

	
	// News Search :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#searchnews").submit(function() {  
			$("#searchresults").slideUp("slow", function(){
				$.ajax({  
				type: "POST",  
				url: "/search.php",  
				data: "type=news&q="+$('#q').val(),  
				success: function(msg){
					$("#searchresults").html(msg);
					$("#searchresults").slideDown("slow");
				}
			});										 
		});
		return false;
     });
	
	
	// Press Search :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#searchpress").submit(function() {  
			$("#searchresults").slideUp("slow", function(){
				$.ajax({  
				type: "POST",  
				url: "/search.php",  
				data: "type=press&q="+$('#q').val(),  
				success: function(msg){
					$("#searchresults").html(msg);
					$("#searchresults").slideDown("slow");
				}
			});										 
		});
		return false;
     });
	
	// Seach reports :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#showreportsearch").click(function(){
		$("#reportsearch").slideToggle();							 
	 });
	
	
	$("#searchreports").submit(function() {  
			$("#searchresults").slideUp("slow", function(){
				$.ajax({  
				type: "POST",  
				url: "/search.php",  
				data: "type=reports&q="+$('#q').val()+"&county="+$('#county').val()+"&oldestyear="+$('#oldestyear').val()+"&oldestmonth="+$('#oldestmonth').val()+"&oldestday="+$('#oldestday').val()+"&nearestyear="+$('#nearestyear').val()+"&nearestmonth="+$('#nearestmonth').val()+"&nearestday="+$('#nearestday').val()+"&horses="+$('#horses:checked').val()+"&tack="+$('#tack:checked').val()+"&other="+$('#other:checked').val(),  
				success: function(msg){
					$("#searchresults").html(msg);
					$("#searchresults").slideDown("slow");
				}
			});										 
		});
		return false;
     });
	// NECD Search :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#necdsearch").submit(function() {  
		//if(navigator.geolocation == null){ // Share Location denied !!!!!! SWITCHED OFF GEOLOCATION FOR NOW. TO BRING IT BACK UNCOMMENT THIS LINE AND THE ELSE BELOW
			var necdnumber = $('#necdnumber').val();
			
			//if (necdnumber.length > 4){
			$.ajax({  
				type: "POST",  
				url: "/necdcheck.php",  
				data: "source=computer&necdnumber="+ necdnumber,  
				success: function(msg){
					$("#necdsearchresults").html(msg);
					$("#necdsearchresults").fadeIn("fast");
				}
			});
			//}
			//else {
			//	$("#necdsearchresults").html('<div id="ok"><h1>Please enter at least 5 characters</h1><p>This will provide you with more accurate results when searching the database.</p></div>');
			//	$("#necdsearchresults").fadeIn("fast");
			//}
			
			/*}
		else {
			navigator.geolocation.getCurrentPosition(function(position){ // Share Location allowed
					var lat = position.coords.latitude;
					var long = position.coords.longitude;
					var accuracy = position.coords.accuracy;
					// alert(lat+","+long);
					var necdnumber = $('#necdnumber').val();  
					$.ajax({  
						type: "POST",  
						url: "necdcheck.php",  
						data: "source=computer&necdnumber="+necdnumber+"&long="+long+"&lat="+lat+"&accuracy="+accuracy,  
						success: function(msg){
							$("#necdsearchresults").html(msg);
							$("#necdsearchresults").fadeIn("fast");
						}
					});
			
			}, noLocation, {timeout: 100}) 
		}*/
	
     return false;
  
     });
	
	// NECD Search: Confirm the horse you want to check  :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('.confirmhorse').live('click', function() {
		var horseid = $(this).attr('rel');
		var necdnumber = $('#necdnumber').val();
		$.ajax({  
			type: "POST",  
			url: "/necdcheck.php",  
			data: "source=computer&horseid="+horseid+"&necdnumber="+necdnumber,  
			success: function(msg){
				$("#necdsearchresults").html(msg);
				$("#necdsearchresults").fadeIn("fast");
			}
		});
	});

	// NECD Search: Confirm the tack you want to check  :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('.confirmtack').live('click', function() {
		var tackid = $(this).attr('rel');
		var necdnumber = $('#necdnumber').val();
		$.ajax({  
			type: "POST",  
			url: "/necdcheck.php",  
			data: "source=computer&tackid="+tackid+"&necdnumber="+necdnumber,  
			success: function(msg){
				$("#necdsearchresults").html(msg);
				$("#necdsearchresults").fadeIn("fast");
			}
		});
	});
	
	// NECD Search: Confirm the other you want to check  :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('.confirmother').live('click', function() {
		var tackid = $(this).attr('rel');
		var necdnumber = $('#necdnumber').val();
		$.ajax({  
			type: "POST",  
			url: "/necdcheck.php",  
			data: "source=computer&otherid="+otherid+"&necdnumber="+necdnumber,  
			success: function(msg){
				$("#necdsearchresults").html(msg);
				$("#necdsearchresults").fadeIn("fast");
			}
		});
	});
	
	// Suggest boxes :::::::::::::::::::::::::::::::::::::::::::::::::
	
	function log(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}
	
	function formatItem(row) {
		return row[0] + " (<strong>id: " + row[1] + "</strong>)";
	}
	function formatResult(row) {
		return row[0].replace(/(<.+?>)/gi, '');
	}
	
	/*
	$(".horseserial").autocomplete("suggest.php", {
		matchContains: true,
		minChars: 0,
		extraParams: {
			suggestType: 'horseserial'
			}
	});
	*/
	
	// Tack type select switch  :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".tacktype").change(function() {
		  
		  var typeid = $(this).closest('form').find("select.tacktype").attr('id');
		  var manufacturerid = $(this).closest('form').find("select.tackmanufacturer").attr('id');
		  var modelid = $(this).closest('form').find("select.tackmodel").attr('id');
		  
		  var str = $("select#"+typeid+" option:selected").text();
		  
		  var typename = $("select#"+typeid).attr("name");
		  var manufacturername = $("select#"+manufacturerid).attr("name");
		  var modelname = $("select#"+modelid).attr("name");
		  		  
		  if(str == "Other"){
			  $('<input type="text" class="typeclear validate[required] disabled" name="'+typename+'" id="'+typeid+'" value="Please enter a type" />').insertAfter("select#"+typeid).show();
			  $("select#"+typeid).remove();
			  
			  $('<input type="text" class="manclear validate[required] disabled" name="'+manufacturername+'" id="'+manufacturerid+'" value="Please enter a manufacturer" />').insertAfter("select#"+manufacturerid).show();
			  $("select#"+manufacturerid).remove();
			  
			  $('<input type="text" class="modelclear validate[required] disabled" name="'+modelname+'" id="'+modelid+'" value="Please enter a model" />').insertAfter("select#"+modelid).show();
			  $("select#"+modelid).remove();
		  }
		  else{
			  $("select#"+manufacturerid).attr('disabled', false);
			  $("select#"+modelid).attr('disabled', true);
			  $("select#"+modelid).val('');
			  $.ajax({  
				type: "POST",  
				url: "/select.php",  
				data: "type=tackmanufacturers&category="+$("select#"+typeid+" option:selected").val()+"&",
				success: function(msg){
					$("select#"+manufacturerid).html(msg);

				}
			
			});
				
			  
		  }
        });
	
	$(".tackmanufacturer").change(function() {
		  
		  var typeid = $(this).closest('form').find("select.tacktype").attr('id');
		  var manufacturerid = $(this).closest('form').find("select.tackmanufacturer").attr('id');
		  var modelid = $(this).closest('form').find("select.tackmodel").attr('id');
		  
		  var str = $("select#"+manufacturerid+" option:selected").text();
		  
		  var typename = $("select#"+typeid).attr("name");
		  var manufacturername = $("select#"+manufacturerid).attr("name");
		  var modelname = $("select#"+modelid).attr("name");
		  
		  if(str == "Other"){
			  		  
			  $('<input type="text" class="manclear validate[required] disabled" name="'+manufacturername+'" id="'+manufacturerid+'" value="Please enter a manufacturer" />').insertAfter("select#"+manufacturerid).show();
			  $("select#"+manufacturerid).remove();
			  
			  $('<input type="text" class="modelclear validate[required] disabled" name="'+modelname+'" id="'+modelid+'" value="Please enter a model" />').insertAfter("select#"+modelid).show();
			  $("select#"+modelid).remove();
		  }
		  else{
			  $("select#"+modelid).attr('disabled', false);
			  $.ajax({  
				type: "POST",  
				url: "/select.php",  
				data: "type=tackmodels&category="+$("select#"+typeid+" option:selected").val()+"&manufacturer="+$("select#"+manufacturerid+" option:selected").val()+"&",
				success: function(msg){
					$("select#"+modelid).html(msg);

				}
			
			});
				
			  
		  }
        });
	
	$(".tackmodel").change(function() {
		  
		  var typeid = $(this).closest('form').find("select.tacktype").attr('id');
		  var manufacturerid = $(this).closest('form').find("select.tackmanufacturer").attr('id');
		  var modelid = $(this).closest('form').find("select.tackmodel").attr('id');
		  
		  var str = $("select#"+modelid+" option:selected").text();
		  
		  var typename = $("select#"+typeid).attr("name");
		  var manufacturername = $("select#"+manufacturerid).attr("name");
		  var modelname = $("select#"+modelid).attr("name");
		  
		  if(str == "Other"){
			  
			  $('<input type="text" class="modelclear validate[required] disabled" name="'+modelname+'" id="'+modelid+'" value="Please enter a model" />').insertAfter("select#"+modelid).show();
			  $("select#"+modelid).remove();
		  }
		  
        });
	
	$('.typeclear').live('focus', function() {
		if($(this).val() == 'Please enter a type'){
			$(this).val("");
		}
	});
	
	$('.manclear').live('focus', function() {
		if($(this).val() == 'Please enter a manufacturer'){
			$(this).val("");
		}
	});
	
	$('.modelclear').live('focus', function() {
		if($(this).val() == 'Please enter a model'){
			$(this).val("");
		}
	});
	
	// Other type select switch For address  :::::::::::::::::::::::::::::::::::::::::::::::::
	$("#keptat").change(function()
    {
		if(this.value=="newAddress")
		{
			var temp = '<caption>County</caption>';
    		temp += '<select name="county" id="county" class="validate[required]">';
			temp += '<option value="">Please select</option>';
			temp += '<option value="1" >Avon</option>';
			temp += '<option value="2" >Bedfordshire</option>';
			temp += '<option value="3" >Berkshire</option>';
			temp += '<option value="4" >Borders</option>';
			temp += '<option value="5" >Buckinghamshire</option>';
			temp += '<option value="6" >Cambridgeshire</option>';
			
			temp += '<option value="8" >Cheshire</option>';
			temp += '<option value="9" >Cleveland</option>';
			temp += '<option value="10" >Clwyd</option>';
			temp += '<option value="11" >Cornwall</option>';
			temp += '<option value="12" >County Antrim</option>';
			temp += '<option value="13" >County Armagh</option>';
			temp += '<option value="14" >County Down</option>';
			temp += '<option value="15" >County Fermanagh</option>';
			temp += '<option value="16" >County Londonderry</option>';
			
			temp += '<option value="17" >County Tyrone</option>';
			temp += '<option value="18" >Cumbria</option>';
			temp += '<option value="19" >Derbyshire</option>';
			temp += '<option value="20" >Devon</option>';
			temp += '<option value="21" >Dorset</option>';
			temp += '<option value="22" >Dumfries and Galloway</option>';
			temp += '<option value="23" >Durham</option>';
			temp += '<option value="24" >Dyfed</option>';
			temp += '<option value="25" >East Sussex</option>';
			
			temp += '<option value="26" >Essex</option>';
			temp += '<option value="27" >Fife</option>';
			temp += '<option value="28" >Gloucestershire</option>';
			temp += '<option value="29" >Grampian</option>';
			temp += '<option value="75" >Greater London</option>';
			temp += '<option value="30" >Greater Manchester</option>';
			temp += '<option value="31" >Gwent</option>';
			temp += '<option value="32" >Gwynedd County</option>';
			temp += '<option value="33" >Hampshire</option>';
			
			temp += '<option value="34" >Herefordshire</option>';
			temp += '<option value="35" >Hertfordshire</option>';
			temp += '<option value="36" >Highlands and Islands</option>';
			temp += '<option value="37" >Humberside</option>';
			temp += '<option value="38" >Isle of Wight</option>';
			temp += '<option value="39" >Kent</option>';
			temp += '<option value="40" >Lancashire</option>';
			temp += '<option value="41" >Leicestershire</option>';
			temp += '<option value="42" >Lincolnshire</option>';
			
			temp += '<option value="71" >London</option>';
			temp += '<option value="43" >Lothian</option>';
			temp += '<option value="73" >Manchester</option>';
			temp += '<option value="44" >Merseyside</option>';
			temp += '<option value="45" >Mid Glamorgan</option>';
			temp += '<option value="46" >Norfolk</option>';
			temp += '<option value="47" >North Yorkshire</option>';
			temp += '<option value="48" >Northamptonshire</option>';
			temp += '<option value="49" >Northumberland</option>';
			
			temp += '<option value="50" >Nottinghamshire</option>';
			temp += '<option value="51" >Oxfordshire</option>';
			temp += '<option value="52" >Powys</option>';
			temp += '<option value="74" >Rutland</option>';
			temp += '<option value="54" >Shropshire</option>';
			temp += '<option value="55" >Somerset</option>';
			temp += '<option value="56" >South Glamorgan</option>';
			temp += '<option value="57" >South Yorkshire</option>';
			temp += '<option value="58" >Staffordshire</option>';
			
			temp += '<option value="59" >Strathclyde</option>';
			temp += '<option value="60" >Suffolk</option>';
			temp += '<option value="61" >Surrey</option>';
			temp += '<option value="62" >Tayside</option>';
			temp += '<option value="63" >Tyne and Wear</option>';
			temp += '<option value="64" >Warwickshire</option>';
			temp += '<option value="65" >West Glamorgan</option>';
			temp += '<option value="66" >West Midlands</option>';
			temp += '<option value="67" >West Sussex</option>';
			
			temp += '<option value="68" >West Yorkshire</option>';
			temp += '<option value="69" >Wiltshire</option>';
			temp += '<option value="70" >Worcestershire</option>';
			temp += '</select>'
			
			
			
			var newAddress = '<ul><li>Name (e.g. Stables)<input name="identity" id="identity" class="validate[required]"  type="text"  /></li>';
newAddress += '<li>Address line 1<input name="housenumber" id="housenumber" class="validate[required]" type="text" /></li>';
newAddress+='<li>Address line 2<input name="address1" id="address1" type="text" /></li>';
newAddress+='<li>Address line 3<input name="address2" id="address2" type="text" /></li>';
newAddress+='<li>Town/city<input name="town" id="town" class="validate[required]"  type="text" /></li>';
newAddress+='<li>'+temp+'</li></ul>';
newAddress+='<li>Postcode<input type="text" name="postcode" id="postcode" class="validate[required]" /></li>';

         $("#newAddresses").html(newAddress);
		}
		else
		  $("#newAddresses").html('');
	});
	// Other type select switch For Insurance :::::::::::::::::::::::::::::::::::::::::::::::::
	$("#insurance").change(function()
    {
		if(this.value=="newInsurance")
		{
			var insurance = '<ul><li>Insurance company<input name="company" id="company" type="text" class="validate[required]" /></li>';
insurance += '<li>Policy number<input name="policynumber" id="policynumber"  type="text" class="validate[required]" /></li>';
insurance+='<li>Phone number<input name="phonenumber" id="phonenumber" class="" type="text"  /></li>';


         $("#newInsurance").html(insurance);
		}
		else
		  $("#newInsurance").html('');
	});
	
	
	
	$(".locat").change(function()
    {
		if(this.value=="newAddress")
		{
			var temp = '<caption>County</caption>';
    		temp += '<select name="county" id="county" class="validate[required]">';
			temp += '<option value="">Please select</option>';
			temp += '<option value="1" >Avon</option>';
			temp += '<option value="2" >Bedfordshire</option>';
			temp += '<option value="3" >Berkshire</option>';
			temp += '<option value="4" >Borders</option>';
			temp += '<option value="5" >Buckinghamshire</option>';
			temp += '<option value="6" >Cambridgeshire</option>';
			
			temp += '<option value="8" >Cheshire</option>';
			temp += '<option value="9" >Cleveland</option>';
			temp += '<option value="10" >Clwyd</option>';
			temp += '<option value="11" >Cornwall</option>';
			temp += '<option value="12" >County Antrim</option>';
			temp += '<option value="13" >County Armagh</option>';
			temp += '<option value="14" >County Down</option>';
			temp += '<option value="15" >County Fermanagh</option>';
			temp += '<option value="16" >County Londonderry</option>';
			
			temp += '<option value="17" >County Tyrone</option>';
			temp += '<option value="18" >Cumbria</option>';
			temp += '<option value="19" >Derbyshire</option>';
			temp += '<option value="20" >Devon</option>';
			temp += '<option value="21" >Dorset</option>';
			temp += '<option value="22" >Dumfries and Galloway</option>';
			temp += '<option value="23" >Durham</option>';
			temp += '<option value="24" >Dyfed</option>';
			temp += '<option value="25" >East Sussex</option>';
			
			temp += '<option value="26" >Essex</option>';
			temp += '<option value="27" >Fife</option>';
			temp += '<option value="28" >Gloucestershire</option>';
			temp += '<option value="29" >Grampian</option>';
			temp += '<option value="75" >Greater London</option>';
			temp += '<option value="30" >Greater Manchester</option>';
			temp += '<option value="31" >Gwent</option>';
			temp += '<option value="32" >Gwynedd County</option>';
			temp += '<option value="33" >Hampshire</option>';
			
			temp += '<option value="34" >Herefordshire</option>';
			temp += '<option value="35" >Hertfordshire</option>';
			temp += '<option value="36" >Highlands and Islands</option>';
			temp += '<option value="37" >Humberside</option>';
			temp += '<option value="38" >Isle of Wight</option>';
			temp += '<option value="39" >Kent</option>';
			temp += '<option value="40" >Lancashire</option>';
			temp += '<option value="41" >Leicestershire</option>';
			temp += '<option value="42" >Lincolnshire</option>';
			
			temp += '<option value="71" >London</option>';
			temp += '<option value="43" >Lothian</option>';
			temp += '<option value="73" >Manchester</option>';
			temp += '<option value="44" >Merseyside</option>';
			temp += '<option value="45" >Mid Glamorgan</option>';
			temp += '<option value="46" >Norfolk</option>';
			temp += '<option value="47" >North Yorkshire</option>';
			temp += '<option value="48" >Northamptonshire</option>';
			temp += '<option value="49" >Northumberland</option>';
			
			temp += '<option value="50" >Nottinghamshire</option>';
			temp += '<option value="51" >Oxfordshire</option>';
			temp += '<option value="52" >Powys</option>';
			temp += '<option value="74" >Rutland</option>';
			temp += '<option value="54" >Shropshire</option>';
			temp += '<option value="55" >Somerset</option>';
			temp += '<option value="56" >South Glamorgan</option>';
			temp += '<option value="57" >South Yorkshire</option>';
			temp += '<option value="58" >Staffordshire</option>';
			
			temp += '<option value="59" >Strathclyde</option>';
			temp += '<option value="60" >Suffolk</option>';
			temp += '<option value="61" >Surrey</option>';
			temp += '<option value="62" >Tayside</option>';
			temp += '<option value="63" >Tyne and Wear</option>';
			temp += '<option value="64" >Warwickshire</option>';
			temp += '<option value="65" >West Glamorgan</option>';
			temp += '<option value="66" >West Midlands</option>';
			temp += '<option value="67" >West Sussex</option>';
			
			temp += '<option value="68" >West Yorkshire</option>';
			temp += '<option value="69" >Wiltshire</option>';
			temp += '<option value="70" >Worcestershire</option>';
			temp += '</select>'
			
			
			
			var newAddress = '<ul><li>Name (e.g. Stables)<input name="identity" id="identity" class="validate[required]"  type="text"  /></li>';
newAddress += '<li>Address line 1<input name="housenumber" id="housenumber" class="validate[required]" type="text" /></li>';
newAddress+='<li>Address line 2<input name="address1" id="address1" type="text"/></li>';
newAddress+='<li>Address line 3<input name="address2" id="address2" type="text" /></li>';
newAddress+='<li>Town/city<input name="town" id="town" class="validate[required]"  type="text" /></li>';
newAddress+='<li>'+temp+'</li></ul>';
newAddress+='<li>Postcode<input type="text" name="postcode" id="postcode" class="validate[required]" /></li>';

         $("#newAddresses").html(newAddress);
		}
		else
		  $("#newAddresses").html('');
	});
	
	// Other type select switch  :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".othertype").change(function() {
		  
		  var typeid = $(this).closest('form').find("select.othertype").attr('id');
		  var manufacturerid = $(this).closest('form').find("select.othermanufacturer").attr('id');
		  var modelid = $(this).closest('form').find("select.othermodel").attr('id');
		  
		  var str = $("select#"+typeid+" option:selected").text();
		  
		  var typename = $("select#"+typeid).attr("name");
		  var manufacturername = $("select#"+manufacturerid).attr("name");
		  var modelname = $("select#"+modelid).attr("name");
		  		  
		  if(str == "Other"){
			  $('<input type="text" class="typeclear validate[required] disabled" name="'+typename+'" id="'+typeid+'" value="Please enter a type" />').insertAfter("select#"+typeid).show();
			  $("select#"+typeid).remove();
			  
			  $('<input type="text" class="manclear validate[required] disabled" name="'+manufacturername+'" id="'+manufacturerid+'" value="Please enter a manufacturer" />').insertAfter("select#"+manufacturerid).show();
			  $("select#"+manufacturerid).remove();
			  
			  $('<input type="text" class="modelclear validate[required] disabled" name="'+modelname+'" id="'+modelid+'" value="Please enter a model" />').insertAfter("select#"+modelid).show();
			  $("select#"+modelid).remove();
		  }
		  else{
			  $("select#"+manufacturerid).attr('disabled', false);
			  $("select#"+modelid).attr('disabled', true);
			  $("select#"+modelid).val('');
			  
			  $.ajax({  
				type: "POST",  
				url: "/select.php",  
				data: "type=othermanufacturers&category="+$("select#"+typeid+" option:selected").val()+"&",
				success: function(msg){
					$("select#"+manufacturerid).html(msg);

				}
			
			});
				
			  
		  }
        });
	
	$(".othermanufacturer").change(function() {
		  
		  var typeid = $(this).closest('form').find("select.othertype").attr('id');
		  var manufacturerid = $(this).closest('form').find("select.othermanufacturer").attr('id');
		  var modelid = $(this).closest('form').find("select.othermodel").attr('id');
		  
		  var str = $("select#"+manufacturerid+" option:selected").text();
		  
		  var typename = $("select#"+typeid).attr("name");
		  var manufacturername = $("select#"+manufacturerid).attr("name");
		  var modelname = $("select#"+modelid).attr("name");
		  
		  if(str == "Other"){
			  		  
			  $('<input type="text" class="manclear validate[required] disabled" name="'+manufacturername+'" id="'+manufacturerid+'" value="Please enter a manufacturer" />').insertAfter("select#"+manufacturerid).show();
			  $("select#"+manufacturerid).remove();
			  
			  $('<input type="text" class="modelclear validate[required] disabled" name="'+modelname+'" id="'+modelid+'" value="Please enter a model" />').insertAfter("select#"+modelid).show();
			  $("select#"+modelid).remove();
		  }
		  else{
			  $("select#"+modelid).attr('disabled', false);
			  $.ajax({  
				type: "POST",  
				url: "/select.php",  
				data: "type=othermodels&category="+$("select#"+typeid+" option:selected").val()+"&manufacturer="+$("select#"+manufacturerid+" option:selected").val()+"&",
				success: function(msg){
					$("select#"+modelid).html(msg);

				}
			
			});
				
			  
		  }
        });
	
	$(".othermodel").change(function() {
		  
		  var typeid = $(this).closest('form').find("select.othertype").attr('id');
		  var manufacturerid = $(this).closest('form').find("select.othermanufacturer").attr('id');
		  var modelid = $(this).closest('form').find("select.othermodel").attr('id');
		  
		  var str = $("select#"+modelid+" option:selected").text();
		  
		  var typename = $("select#"+typeid).attr("name");
		  var manufacturername = $("select#"+manufacturerid).attr("name");
		  var modelname = $("select#"+modelid).attr("name");
		  
		  if(str == "Other"){
			  
			  $('<input type="text" class="modelclear validate[required] disabled" name="'+modelname+'" id="'+modelid+'" value="Please enter a model" />').insertAfter("select#"+modelid).show();
			  $("select#"+modelid).remove();
		  }
		  
        });
	
	$('.typeclear').live('focus', function() {
		if($(this).val() == 'Please enter a type'){
			$(this).val("");
		}
	});
	
	$('.manclear').live('focus', function() {
		if($(this).val() == 'Please enter a manufacturer'){
			$(this).val("");
		}
	});
	
	$('.modelclear').live('focus', function() {
		if($(this).val() == 'Please enter a model'){
			$(this).val("");
		}
	});
	
	// Horse serial switch from select to input :::::::::::::::::::::::::::::::::::::::::::::::::

	$(".horseserial").change(function() {
          var id = $(this).attr("id");
		  var name = $(this).attr("name");
		  var str = $("#"+id+" option:selected").text();
		  if(str == "Other"){
			  $('<input type="text" class="disabled horseclear" name="'+name+'" id="'+id+'" value="Please enter a name" />').insertAfter("#"+id).show();
			  $("#"+id).hide();
		  }
        });
	
	$('.horseclear').live('focus', function() {
		if($(this).val() == 'Please enter a name'){
			$(this).val("");
		}
	});
	

	/*
	$(".tackserial").autocomplete("suggest.php", {
		matchContains: true,
		minChars: 0,
		extraParams: {
			suggestType: 'tackserial'
			}
	});
	
	*/
	
	// Tack serial switch from select to input :::::::::::::::::::::::::::::::::::::::::::::::::

	$(".tackserial").change(function() {
          var id = $(this).attr("id");
		  var name = $(this).attr("name");
		  var str = $("#"+id+" option:selected").text();
		  if(str == "Other"){
			  $('<input type="text" class="disabled tackclear" name="'+name+'" id="'+id+'" value="Please enter a name" />').insertAfter("#"+id).show();
			  $("#"+id).hide();
		  }
        });
	
	$('.tackclear').live('focus', function() {
		if($(this).val() == 'Please enter a name'){
			$(this).val("");
		}
	});


	/*
	$(".otherserial").autocomplete("suggest.php", {
		matchContains: true,
		minChars: 0,
		extraParams: {
			suggestType: 'otherserial'
			}
	});
	*/
	
	// Other serial switch from select to input :::::::::::::::::::::::::::::::::::::::::::::::::

	$(".otherserial").change(function() {
		  var id = $(this).attr("id");
		  var name = $(this).attr("name");
		  var str = $("#"+id+" option:selected").text();
		  if(str == "Other"){
			  $('<input type="text" class="disabled otherclear" name="'+name+'" id="'+id+'" value="Please enter a name" />').insertAfter("#"+id).show();
			  $("#"+id).hide();
		  }
        });
	
	$('.otherclear').live('focus', function() {
		if($(this).val() == 'Please enter a name'){
			$(this).val("");
		}
	});
	
	/*
	$(".tacktype").autocomplete("/suggest.php", {
		matchContains: true,
		minChars: 0,
		extraParams: {
			suggestType: 'tack'
			}
	});

	$(".tackmanufacturer").autocomplete("/suggest.php", {
		matchContains: true,
		minChars: 0,
		extraParams: {
			suggestType: 'tackmanufacturer',
			tacktype: function() { 
				return  $(".tackmanufacturer").closest('form').find('.tacktype').val(); // $(".tacktype").val();
			}
   		}
	});
	
	$(".tackmodel").autocomplete("/suggest.php", {
		matchContains: true,
		minChars: 0,
		extraParams: {
			suggestType: 'tackmodel',
			manufacturer: function() { 
				return $(".tackmodel").closest('form').find('.tackmanufacturer').val(); // $(".manufacturer").val();
			}
   		}
	});
	
	
	$(".othertype").autocomplete("/suggest.php", {
		matchContains: true,
		minChars: 0,
		extraParams: {
			suggestType: 'other'
			}
	});
	
	$(".othermanufacturer").autocomplete("/suggest.php", {
		matchContains: true,
		minChars: 0,
		extraParams: {
			suggestType: 'othermanufacturer',
			othertype: function() { 
				return  $(".othermanufacturer").closest('form').find('.othertype').val(); // $(".tacktype").val();
			}
   		}
	});
	
	$(".othermodel").autocomplete("/suggest.php", {
		matchContains: true,
		minChars: 0,
		extraParams: {
			suggestType: 'othermodel',
			othermanufacturer: function() { 
				return $(".othermodel").closest('form').find('.othermanufacturer').val(); // $(".manufacturer").val();
			}
   		}
	});
	*/
	
	// Switches 'Password' field for a real password field in body form :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('#password-clear').show();
	$('#password-password').hide();
 
	$('#password-clear').focus(function() {
		$('#password-clear').hide();
		$('#password-password').show();
		$('#password-password').focus();
	});
	$('#password-password').blur(function() {
		if($('#password-password').val() == '') {
			$('#password-clear').show();
			$('#password-password').hide();
		}
	});
 
 
 	// Switches 'Password' field for a real password field in mini form :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('#minipassword-clear').show();
	$('#minipassword-password').hide();
 
	$('#minipassword-clear').focus(function() {
		$('#minipassword-clear').hide();
		$('#minipassword-password').show();
		$('#minipassword-password').focus();
	});
	$('#minipassword-password').blur(function() {
		if($('#minipassword-password').val() == '') {
			$('#minipassword-clear').show();
			$('#minipassword-password').hide();
		}
	});
	
	
	// Switches clears input field if focussed and default :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('.default-value').each(function() {
		var default_value = this.value;
		$(this).focus(function() {
			if(this.value == default_value) {
				this.value = '';
				this.className +=" inputfocus";
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
				this.value = default_value;
			}
		});
	});
	
	
		// Button (.login)  click to login at home page
	 $(".login").click(function() {
		$.cookie("allowcookies", "allowcookies", { expires: 1 });
		$iscookie = $.cookie('allowcookies');
		if( $iscookie != null ) {

		} else {
		$.fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 200,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/nocookies.php',
			'onClosed'	: function() {
					
			}

		});
}
});
	
	// Header login panel :::::::::::::::::::::::::::::::::::::::::::::::::
		
		$('#minilogin').click(function() {	
			$('#loginpop').toggle();
			$('#phonenumber').toggle();
			$('#email').toggle();
		});
	
	
	// Refer a friend :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#referform").validationEngine({
				ajaxSubmit: true,
				ajaxSubmitFile: "/refer.php",
				ajaxSubmitMessage: "",
				success :  function() {
					$("#friendemail").html("Thankyou, you can tell another friend");
				},
				failure : function() {
				}
			});
	
	// Login script body :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#loginform input").focus(function(){
		$('.formError').fadeOut("100");
	});
	
	$("#loginform").validationEngine({
				ajaxSubmit: true,
				ajaxSubmitFile: "/login.php",
				ajaxSubmitMessage: "",
				success :  function() { 
							$('#loginpop').fadeOut("fast");
							$("#loginform").closest('.inner').find('h3').hide();
							$("#loginform").closest('.inner').find('p').hide();
							$('#publicboxes').fadeOut("slow", function() {
								$('#memberboxes').load('/member.php?show=true',function() {
									$('#memberboxes').fadeIn("slow");
								})
							}),
							
							$('#publictop').fadeOut("slow", function() {
								$('#membertop').load('/logged.php?show=true',function() {
									$('#membertop').fadeIn("slow");
								})
							}),
							
							$('#column').fadeOut("slow", function() {
								$('#column').load('/columnislogged.php?show=true',function() {
									$('#column').fadeIn("slow");
								})
							}),
							
							$('#aboutsummary .inner').fadeOut("slow", function() {
								$('#aboutsummary .inner').load('/homeislogged.php',function() {
									$('#aboutsummary .inner').fadeIn("slow");
								})
							})
							
							
						},
				failure : function() {
					}
			});
	
	// Login script mini:::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#miniloginform input").focus(function(){
		$('.formError').fadeOut("100");
	});
	
	$("#miniloginform").validationEngine({
				ajaxSubmit: true,
					ajaxSubmitFile: "/login.php",
					ajaxSubmitMessage: "",
				success :  function() { 
							$('#loginpop').fadeOut("fast");
							$('#publicboxes').fadeOut("slow", function() {
								$('#memberboxes').load('/member.php?show=true',function() {
									$('#memberboxes').fadeIn("slow");
								})
							}),
							
							$('#publictop').fadeOut("slow", function() {
								$('#membertop').load('/logged.php?show=true',function() {
									$('#membertop').fadeIn("slow");
								})
							}),
							
							$('#column').fadeOut("slow", function() {
								$('#column').load('/columnislogged.php?show=true',function() {
									$('#column').fadeIn("slow");
								})
							})
						},
				failure : function() {
					}
			});
	
	// Registration script :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#registration").validationEngine({
				ajaxSubmit: false,
				success :  false,
				failure : function() {
					}
			});

	$("#registration input").keypress(function(evt){
     if (evt.keyCode == 13) {
		$(this).focusout(); // blur wasn't quite working in IE, focusout does the same job, bit works in IE.
		var focusables = $(":focusable");
		var current = focusables.index(this),
		next = focusables.eq(current+1).length ? focusables.eq(current+1) : focusables.eq(0);
		next.focus();
		return false;
     }
	
	 });
	
	$("#registration select").keypress(function(evt){
     if (evt.keyCode == 13) {
		$(this).focusout(); // blur wasn't quite working in IE, focusout does the same job, bit works in IE.
		var focusables = $(":focusable");
		var current = focusables.index(this),
		next = focusables.eq(current+1).length ? focusables.eq(current+1) : focusables.eq(0);
		next.focus();
		return false;
     }
	
	 }); 

	// Copy email address to username :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#useemail").click(function(){
		$("#username").val($("#email").val());	
		$("#username").focus();
		$("#usernamequestion").slideUp();
	});
	
	// Suggest usernames based on entered username :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".userexamples").live('click',function(){
		$("#usernamequestion").slideUp(function(){
					
			$.ajax({  
				type: "POST",  
				url: "/suggestusers.php",  
				data: "username="+$("#username").val()+"&",
				success: function(msg){
					$("#usernamequestion").html("<p><b>Suggested usernames</b> (click one to select it)</p>"+msg+"<br />&nbsp;");	
					$("#usernamequestion").slideDown();

				}
			});
			
												
		});
	});
	
	// Choose suggested username :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".suggestion").live('click',function(){
			$newusername = $(this).attr('title');
			$("#usernamequestion").slideUp(function(){
				$("#username").val($newusername);
				$("#username").focus();									
		});
	});
	
	// Profile tabs :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#tabs").tabs();
	
	// Tack accordion :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('.accordion h3').click(function() {		
		$(this).next().slideToggle('slow');
		return false;
	}).next(); // .hide()
	
	
	$('.accordion .hideall').click(function() {		
		//$(this).hide();
		$(this).closest('div.accordion').find('.accbody').slideUp('slow');
		return false;
	});
	
	$('.accordion .showall').click(function() {	
		//$(this).hide();
		$(this).closest('div.accordion').find('.accbody').slideDown('slow');
		return false;
	});
		
	// Report suspicious activity :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".accordion input.report").click(function() {
		window.location="reportatheft.html?item="+$(this).closest('div.eachone').find('.itemid').val()+'&itemtype='+$(this).closest('div.eachone').find('.itemkind').val();
	});
	
	// Update report :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".accordion input.update").click(function() {
		// window.location.href="my-equestrian-estate.html#my-reports";
		$("#tabs").tabs('select', 4);
    	return false;

	});
	
	// Column links :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".quicktab1").click(function() {
		$("#tabs").tabs('select', 0);
		return false;

	});
	
	$(".quicktab2").click(function() {
		$("#tabs").tabs('select', 1);
		return false;

	});
	
	$(".quicktab3").click(function() {
		$("#tabs").tabs('select', 2);
		return false;

	});
	
	$(".quicktab4").click(function() {
		$("#tabs").tabs('select', 4);
		return false;

	});
	
	$(".quicktab5").click(function() {
		$("#tabs").tabs('select', 5);
		return false;

	});
	
	// Report form :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#report").validationEngine({
				ajaxSubmit: false,
				success :  false,
				failure : function() {}
			});
	
	// Count Characters on brief description
	
	$('textarea#brief').keyup(function() {
		var len = this.value.length;
		if (len >= 100) {
			this.value = this.value.substring(0, 100);
		}
		$('#briefleft').text(100 - len + ' characters left');
	});
	
	// Count Characters on detailed description
	
	$('textarea#detailed').keyup(function() {
		var len = (this.value.split(' ').length) -1;
		if (len >= 250) {
			this.value = this.value.substring(0, 250);
		}
		$('#detailedleft').text(250 - len + ' words left');
	});
	
	// Fix IEs Select Menu
	
	if($.browser.msie){
			// $("select").selecteSizer();
		}
	
	if(($.browser.safari)&&(window.location == "http://www.necd.org.uk/")){ // nasty hack to stop news box on the home page adding a scollbar for no reason
			$('body').css('overflow-x','hidden');
		}
		
	// Print items :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#horsebuttons input.print").click(function() {
		var horseid = $(this).attr('title');
		window.open("/printable.php?type=horse&id="+horseid);								  
	});
	
	$("#tackbuttons input.print").click(function() {
		var tackid = $(this).attr('title');
		window.open("/printable.php?type=tack&id="+tackid);								  
	});
	
	$("#otherbuttons input.print").click(function() {
		var otherid = $(this).attr('title');
		window.open("/printable.php?type=other&id="+otherid);								  
	});
	
	$("#detailsbutton input.print").click(function() {
		window.open("/printable.php?type=estate");								  
	});
	
	
	$(".accordion h3 input").click(function(){
		return false;
	});
	
	// Make Editable :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".accordion input.edit").click(function() {
				
		// $(this).closest('div.accbody').find('a.edit').show();
		// $(this).closest('div.eachone').find('a.images').show();
		$(this).closest('div.eachone').find('.tacklarge img.horse').attr("src", "/assets/images/edithorse.gif");
		$(this).closest('div.eachone').find('.tacklarge img.tack').attr("src", "/assets/images/edittack.gif");
		$(this).closest('div.eachone').find('.tacklarge img.other').attr("src", "/assets/images/editother.gif");
		$(this).closest('div.eachone').find('.tackthumbs').hide();
		$(this).closest('div.eachone').find('.editthumbs').show();
		$(this).closest('div.eachone').find('input.edit').hide();
		$(this).closest('div.eachone').find('input.save').show();

		$(this).closest('div.eachone').find('label').hide();
		$(this).closest('div.eachone').find('.disabled').show();
		$(this).closest('div.eachone').find('.horseclear').hide();
		$(this).closest('div.eachone').find('.tackclear').hide();
		$(this).closest('div.eachone').find('.otherclear').hide();
		$(this).closest('div.eachone').find('.tackimages').addClass('absolute');
		documentDirty = 1;
	
		});
	
	// Update Images
	
	var id = 1;

	$('.thumb').each(
	   function() { 

		new AjaxUpload($(this).attr('id'), {
		action: '/process.php?fieldname=image'+$(this).attr('id')+'&imageid='+$(this).attr('title')+'&imageposition='+$(this).attr('alt')+'&imagetype='+$(this).parent().attr('title'),
		name: 'image'+$(this).attr('id'), // name: 'image'+$(this).attr('id'),
		onSubmit: function(file, extension) {
		
			var targetid = this._settings.name.replace("imagethumb", "");
		
			if (!(extension && /^(jpg|png|jpeg|gif)$/i.test(extension))){
                        // extension is not allowed
                        alert('Error: invalid file extension');
                        // cancel upload
                        return false;
                }
			else {
				
				$('img#thumb'+targetid).closest('div.preview').addClass('loading');
			}
		},
		onComplete: function(file, response) {

			var targetid = this._settings.name.replace("imagethumb", "");
			
			$('img#thumb'+targetid).load(function(){
			$('img#thumb'+targetid).closest('div.preview').removeClass('loading');
			$('img#thumb'+targetid).unbind();
			});
			$('img#thumb'+targetid).attr('src', response);
			$('input#imagefield'+targetid).remove();
			$('img#thumb'+targetid).after('<input class="thumbfield" type="hidden" name="imagefield'+targetid+'" id="imagefield'+targetid+'" value="'+response+'" />');

		}
	});
});	
			
	// Stop member moving if there are unsaved forms :::::::::::::::::::::::::::::::::::::::::::::::::
	
	var documentDirty = 0;
	
	window.onbeforeunload = function () {
		if(documentDirty == 1){
			return ('Any changes will be lost if you proceed.'); //false;
		}
		else {
			//return true;
		}
	}
	
	$('#new input').change(function(e){
		documentDirty = 1;
	});
	
	$('#report input').change(function(e){
		documentDirty = 1;
	});
	
	$('.continue').click(function(){
		documentDirty = 0;
    });
		
	// Save new information :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#new").validationEngine({
		liveEvent: true,
		ajaxSubmit: false,
		success :  false,
		failure : function() {}
	});
	
		
	// Password reminder :::::::::::::::::::::::::::::::::::::::::::::::::
		
		$(".loginreminder").fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/loginreminder.php?',
			'onClosed'	: function() {
					
			}

		});


	// Remove an address :::::::::::::::::::::::::::::::::::::::::::::::::
		
		$(".address .remove").fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/remove.php?type=address&addressid=',
			'onClosed'	: function() {
					
			}
				
				
		});
		
	// Remove insurance :::::::::::::::::::::::::::::::::::::::::::::::::
		
		$(".insurance .remove").fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/remove.php?type=insurance&insuranceid=',
			'onClosed'	: function() {
					
			}
				
				
		});
		
	// Remove a horse :::::::::::::::::::::::::::::::::::::::::::::::::
		$("#horsebuttons1 .remove").fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/remove.php?type=necdnumshorses&necdnumid=',
			'onClosed'	: function() {
					
			}
	
});
		$("#tackbuttons1 .remove").fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/remove.php?type=necdnumstack&necdnumid=',
			'onClosed'	: function() {
					
			}
	
});
		$("#otherbuttons1 .remove").fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/remove.php?type=necdnumsother&necdnumid=',
			'onClosed'	: function() {
					
			}
	
});
		
		$("#horsebuttons .remove").fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/remove.php?type=horse&horseid=',
			'onClosed'	: function() {
					
			}
				
				
		});

	// Remove tack :::::::::::::::::::::::::::::::::::::::::::::::::
		
		$("#tackbuttons .remove").fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/remove.php?type=tack&tackid=',
			'onClosed'	: function() {
					
			}
				
		});
		
	// Remove other items :::::::::::::::::::::::::::::::::::::::::::::::::
		
		$("#otherbuttons .remove").fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/remove.php?type=other&otherid=',
			'onClosed'	: function() {
					
			}
				
		});

///////////////////////////// Fancy Box for Links on the My equ. My details page for NECD numbers.


//////////////////////////////////////////////////////////////////////////////////////////



	// Swap images
	     test = "";
		$(".tackthumbs img").click(function() {
			$(this).closest('div.eachone').find('.tacklarge img').attr("src", $(this).attr("src"));
		//alert(test);	
		///assets/images/tmpRedirect/horse/18753245_33372220_82902976.jpg
		///assets/images/tmpRedirect/horse/43789052_11373093_47145182.jpg
		//$(this).closest('div.eachone').find
		//$(this).closest('div.eachone').find('.tacklarge img').attr("src", "http://development.necd.org.uk/assets/images/tmpRedirect/horse/77961502_78864684_54656032.jpg");					
		//$(this).closest('div.eachone').find('.tacklarge img').attr("src", view_largeimg($(this).attr("src"),$('#itype').val()));
		
		});
	
	

// Update tack details and hide inputs :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".accordion input.save").click(function() {
				
		var months = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

		// $(this).closest('div.accbody').find('a.edit').hide();
		//$(this).closest('div.eachone').find('a.images').hide();
		$(this).closest('div.eachone').find('.tacklarge img').attr("src", $(this).closest('div.eachone').find('.editthumbs img').first().attr("src"));
		$(this).closest('div.eachone').find('.tackthumbs img').eq(0).attr("src", $(this).closest('div.eachone').find('.editthumbs img').eq(0).attr("src"));
		$(this).closest('div.eachone').find('.tackthumbs img').eq(1).attr("src", $(this).closest('div.eachone').find('.editthumbs img').eq(1).attr("src"));
		$(this).closest('div.eachone').find('.tackthumbs img').eq(2).attr("src", $(this).closest('div.eachone').find('.editthumbs img').eq(2).attr("src"));
		$(this).closest('div.eachone').find('.tackthumbs img').eq(3).attr("src", $(this).closest('div.eachone').find('.editthumbs img').eq(3).attr("src"));
		$(this).closest('div.eachone').find('.tackthumbs').show();
		$(this).closest('div.eachone').find('.editthumbs').hide();
		$(this).closest('div.eachone').find('input.edit').show();
		$(this).closest('div.eachone').find('input.save').hide();
		$(this).closest('div.eachone').find('.tackimages').removeClass('absolute');
		documentDirty = 0;
		
		// Horse specific
		$(".horseserial option[value='other']").remove();
		//$(".horseserial option[value='']").remove();
		if($(this).closest('div.eachone').find('input[name=identifier1name]').val()){
			$(this).closest('div#my-horses').find('.horseserial').append('<option value="'+$(this).closest('div.eachone').find('input[name=identifier1name]').val()+'">'+$(this).closest('div.eachone').find('input[name=identifier1name]').val()+'</option>');
			$(this).closest('div.eachone').find('select[name=identifier1name]').val($(this).closest('div.eachone').find('input[name=identifier1name]').val());
		}
		if($(this).closest('div.eachone').find('input[name=identifier2name]').val()){
			$(this).closest('div#my-horses').find('.horseserial').append('<option value="'+$(this).closest('div.eachone').find('input[name=identifier2name]').val()+'">'+$(this).closest('div.eachone').find('input[name=identifier2name]').val()+'</option>');
			$(this).closest('div.eachone').find('select[name=identifier2name]').val($(this).closest('div.eachone').find('input[name=identifier2name]').val());
		}
		if($(this).closest('div.eachone').find('input[name=identifier3name]').val()){
			$(this).closest('div#my-horses').find('.horseserial').append('<option value="'+$(this).closest('div.eachone').find('input[name=identifier3name]').val()+'">'+$(this).closest('div.eachone').find('input[name=identifier3name]').val()+'</option>');
			$(this).closest('div.eachone').find('select[name=identifier3name]').val($(this).closest('div.eachone').find('input[name=identifier3name]').val());
		}
		$('.horseserial').live('each', function(i){
			sortValues(this.id);
		});
		$('.horseserial').append('<option value="other">Other</option>');
		
		// Tack specific
		$(".tackserial option[value='other']").remove();
		//$(".tackserial option[value='']").remove();
		if($(this).closest('div.eachone').find('input[name=identifier1name]').val()){
			$(this).closest('div#my-tack').find('.tackserial').append('<option value="'+$(this).closest('div.eachone').find('input[name=identifier1name]').val()+'">'+$(this).closest('div.eachone').find('input[name=identifier1name]').val()+'</option>');
			$(this).closest('div.eachone').find('select[name=identifier1name]').val($(this).closest('div.eachone').find('input[name=identifier1name]').val());
		}
		if($(this).closest('div.eachone').find('input[name=identifier2name]').val()){
			$(this).closest('div#my-tack').find('.tackserial').append('<option value="'+$(this).closest('div.eachone').find('input[name=identifier2name]').val()+'">'+$(this).closest('div.eachone').find('input[name=identifier2name]').val()+'</option>');
			$(this).closest('div.eachone').find('select[name=identifier2name]').val($(this).closest('div.eachone').find('input[name=identifier2name]').val());
		}
		if($(this).closest('div.eachone').find('input[name=identifier3name]').val()){
			$(this).closest('div#my-tack').find('.tackserial').append('<option value="'+$(this).closest('div.eachone').find('input[name=identifier3name]').val()+'">'+$(this).closest('div.eachone').find('input[name=identifier3name]').val()+'</option>');
			$(this).closest('div.eachone').find('select[name=identifier3name]').val($(this).closest('div.eachone').find('input[name=identifier3name]').val());
		}
		$('.tackserial').live('each', function(i){
			sortValues(this.id);
		});
		$('.tackserial').append('<option value="other">Other</option>');
		
		// Other specific
		$(".otherserial option[value='other']").remove();
		//$(".otherserial option[value='']").remove();
		if($(this).closest('div.eachone').find('input[name=identifier1name]').val()){
			$(this).closest('div#my-other').find('.otherserial').append('<option value="'+$(this).closest('div.eachone').find('input[name=identifier1name]').val()+'">'+$(this).closest('div.eachone').find('input[name=identifier1name]').val()+'</option>');
			$(this).closest('div.eachone').find('select[name=identifier1name]').val($(this).closest('div.eachone').find('input[name=identifier1name]').val());
		}
		if($(this).closest('div.eachone').find('input[name=identifier2name]').val()){
			$(this).closest('div#my-other').find('.otherserial').append('<option value="'+$(this).closest('div.eachone').find('input[name=identifier2name]').val()+'">'+$(this).closest('div.eachone').find('input[name=identifier2name]').val()+'</option>');
			$(this).closest('div.eachone').find('select[name=identifier2name]').val($(this).closest('div.eachone').find('input[name=identifier2name]').val());
		}
		if($(this).closest('div.eachone').find('input[name=identifier3name]').val()){
			$(this).closest('div#my-other').find('.otherserial').append('<option value="'+$(this).closest('div.eachone').find('input[name=identifier3name]').val()+'">'+$(this).closest('div.eachone').find('input[name=identifier3name]').val()+'</option>');
			$(this).closest('div.eachone').find('select[name=identifier3name]').val($(this).closest('div.eachone').find('input[name=identifier3name]').val());
		}
		$('.otherserial').live('each', function(i){
			sortValues(this.id);
		});
		$('.otherserial').append('<option value="other">Other</option>');	
		
		$(this).closest('div.eachone').find('.disabled').show();
		
		var dataString = '';
		
		$(this).closest('div.eachone').find('.disabled').each(function() { 
			
			dataString += $(this).attr('name')+'='+$(this).val()+'&';
			
			if($(this).hasClass('date')){
				var thismonth = $(this).closest('li').find('.jmonth option:selected').val();
				$(this).closest('li').find('label').text($(this).closest('li').find('.jday option:selected').val()+' '+$(this).closest('li').find('.jmonth option:selected').text()+' '+$(this).closest('li').find('.jyear option:selected').val());
				$(this).closest('li').find('label').show();
				//$(this).parent().find('label').css({'background-color': '#ffe'});
				//alert($(this).closest('li').find('.jday option:selected').val()+' '+$(this).closest('li').find('.jmonth option:selected').text()+' '+$(this).closest('li').find('.jyear option:selected').val());
			}
			else{
				$(this).parent().find('label').text($(this).val());
				$(this).parent().find('label').show();
			}
						
			// $('.horseclear').remove();
			$(this).hide();
			$(this).parent().find('label').show();
		});
		
		dataString += 'itemid='+$(this).closest('div.eachone').find('.itemid').val()+'&';
		dataString += 'kind='+$(this).closest('div.eachone').find('.itemkind').val();
				
		$.ajax({  
			type: "POST",  
			url: "/update.php",  
			data: dataString,  
			success: function() {}  
		 });
		
		return false;

						
		});
	
	// Add new item  :::::::::::::::::::::::::::::::::::::::::::::::::
	
		$.get('/newtack.php', function(data){
				var content = data;
			});
		
		$("input.add").click(function() {
			$('div.accordion').prepend(content);
		});
		
	// Captcha script  :::::::::::::::::::::::::::::::::::::::::::::::::
		
		$('#captcha1')
		  .bind('loaded.simpleCaptcha', function() {
			// do something when loaded
		  })
  		.simpleCaptcha();
		
		$('.captchaImage').live('mouseup', function(){
										  
			$('#simpleCaptcha_0').focus(function(){
					
					//$('#captcha1').focus(function(){
												  
												 // alert("test");
												  
												 // });
					
						
				});						  
		});
		
	// Show home go button and number message  :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#necdnumber").click(function() {
				
		$('#necdsearch input.go').show();
		$("#necdsearchresults").hide();
		$('#alsosearch').show();
				
		});
	
	var flag1 = 0;
	$("#report_msg").hide();
    $("#backBt").click(function()
	{
			
		if($("#crimeref").val() == "" && flag1 == 1)
		{
			$("#report_msg").hide();
			setTimeout("document.getElementById('crimeref').focus()", 1);
		   	flag1=3;
			return false;
		}
		else			
		{ 		
		  //$("#report_msg").show();
		  // flag1 = 0;
		  // $("#crimeref").focus();
		}
    });
    var flag = 1;
    $(".continue").click(function()
	{
		if($("#crimeref").val() == "" && flag == 0)
		{
		  $("#report_msg").show();
		  flag = 1;
		  flag1=1;
		  $("#crimeref").focus();
		  return false;
		}
		else
		{
			$("#report_msg").hide();
		    flag = 0;
		}
     });
	// Mark message as read  :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".unreadhead").one('click', function() {
		$(this).closest('div.eachone').find('.reported').fadeOut();
		$(this).removeClass('unreadhead');
		// $(this).unbind("click.unreadhead", function(e) { alert("3"); }); 
		var unread = parseInt($(".messagecount").html())-1;
		
		if(unread != 0){
			$(".messagecount").html(unread);
		}
		else{
			$(".messagecount").closest('ul').find('.message').fadeOut();	
		}
			
		var dataString = '';
		dataString += 'messageid='+$(this).closest('div.eachone').find('.messageid').val()+'&';
		dataString += 'kind=messageread';
		
		$.ajax({  
			type: "POST",  
			url: "/update.php",  
			data: dataString,  
			success: function() {}  
		 });  
		return false;
				
	});
	
	// Show total price after selecting extras :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#fee").change(function() {
		var charitydonation = parseInt($('#charityamount').val().replace(/[^0-9\.^0-9]/g, '').toString()).toFixed(2);
		if (isNaN(charitydonation))
		{
		charitydonation = 0;
		}

  		//$("#total").html((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
		//$("#a3").val((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
		//$("#grandtotal").val((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
		
		var totaltopay = parseInt($("#membershipprice").val())-parseInt($('#promoamount').val());//+parseInt($("#fee").val()) was included
				
		if(totaltopay <= 0){
			totaltopay = 0;
		}
		
		totaltopay = (parseInt(charitydonation)+totaltopay).toFixed(2);
		
		$("#total").html(totaltopay);
		$("#a3").val(totaltopay);
		$("#grandtotal").val(totaltopay);
						
						
		var allowance = $("#fee option:selected").text().split(" ");
		if (!isNaN(allowance[0])) {
			$("#extraitems").val(allowance[0]);
		}
		else{
			$("#extraitems").val(0);
		}
		
		if($("#grandtotal").val() == "0.00"){
			$(".paymentelement").fadeOut("slow");
			$("#paybutton").val("Next");		
		}
	});
	
	$("#upgradefee").change(function() {
		$("#total").html($("#upgradefee :selected").val());
	});
	
	
	// Show total price after entering a donation amount :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#charityamount").blur(function() {
		var charitydonation = parseInt($('#charityamount').val().replace(/[^0-9\.^0-9]/g, '').toString()).toFixed(2);
		if (isNaN(charitydonation))
		{
		charitydonation = 0;
		}

  		//$("#total").html((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
		//$("#a3").val((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
		//$("#grandtotal").val((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
		
		var totaltopay = parseInt($("#membershipprice").val())-parseInt($('#promoamount').val());////+parseInt($("#fee").val()) was included
		
		if(totaltopay <= 0){
			totaltopay = 0;
		}
		
		totaltopay = (parseInt(charitydonation)+totaltopay).toFixed(2);

		$("#total").html(totaltopay);
		$("#a3").val(totaltopay);
		$("#grandtotal").val(totaltopay);
		
	
		var allowance = $("#fee option:selected").text().split(" ");
		if (!isNaN(allowance[0])) {
			$("#extraitems").val(allowance[0]);
		}
		else{
			$("#extraitems").val(0);
		}
		
		if($("#grandtotal").val() == "0.00"){
			$(".paymentelement").fadeOut("slow");
			$("#paybutton").val("Next");
		}
	});
	
	// Check for offer code  :::::::::::::::::::::::::::::::::::::::::::::::::
		
	$("#promo").focus(function() {
			//$("#checkcode").fadeIn("fast");
			$('#discount').hide();
	});
	
	$("#promo").blur(function() {
  		if($("#promo").val() == ""){
			
			//$("#checkcode").fadeOut("fast");
			}
			
	});


	$('#checkcode').click(function() {
		var promo = $('#promo').val();
		$.ajax({  
			type: "POST",  
			url: "/promocheck.php",  
			data: "code="+promo,  
			success: function(msg){
				var charitydonation = parseInt($('#charityamount').val().replace(/[^0-9\.^0-9]/g, '').toString()).toFixed(2);
				if (isNaN(charitydonation))
				{
				charitydonation = 0;
				}
				var parts = msg.split("|");
					$("#checkcode").hide();
					$('#discount').show();
					$('#discount').html(parts[0]);
					$('#promomessage').val(parts[0]);
					$('#promotitle').val(parts[1]);
					$('#promoamount').val(parts[2]);
					if(isNaN($('#promoamount').val())){
						var fixedreduction = $('#promoamount').val().replace("£", "");
						fixedreduction = fixedreduction.replace("-", "");
						//$("#total").html((parseInt(charitydonation)+((parseInt($("#fee").val())-parseInt($('#promoamount').val())+parseInt($("#membershipprice").val())))).toFixed(2));
						//$("#grandtotal").val((parseInt(charitydonation)+((parseInt($("#fee").val())-parseInt($('#promoamount').val())+parseInt($("#membershipprice").val())))).toFixed(2));
						
						//alert((parseInt($("#charityamount").val())+parseInt($("#membershipprice").val())+parseInt($("#fee").val())-parseInt($('#promoamount').val())).toFixed(2)); // NHW2010070
						
						var totaltopay = parseInt($("#membershipprice").val())-parseInt($('#promoamount').val());////+parseInt($("#fee").val()) was included
						
					if(totaltopay <= 0){
						totaltopay = 0;
					}
					
					totaltopay = (parseInt(charitydonation)+totaltopay).toFixed(2);

						
		$("#total").html(totaltopay);
						$("#grandtotal").val(totaltopay);
					}
					else {
						//alert($('#promoamount').val()); // NHW2010070
												
						//$("#total").html((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
						//$("#grandtotal").val((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
						
						//alert((parseInt($("#charityamount").val())+parseInt($("#membershipprice").val())+parseInt($("#fee").val())-parseInt($('#promoamount').val())).toFixed(2));
						
						var totaltopay = parseInt($("#membershipprice").val())-parseInt($('#promoamount').val());//+parseInt($("#fee").val()) was included
						
						if(totaltopay <= 0){
							totaltopay = 0;
						}
						
						totaltopay = (parseInt(charitydonation)+totaltopay).toFixed(2);

						
						$("#total").html(totaltopay);
						$("#grandtotal").val(totaltopay);
					}
							
							
							if($("#grandtotal").val() == "0.00"){
								 $(".paymentelement").fadeOut("slow");
								 $("#paybutton").val("Next");
							}
			}
		});
	});
	
	$('input#promo').blur(function() {
		var promo = $('#promo').val();
		$.ajax({  
			type: "POST",  
			url: "/promocheck.php",  
			data: "code="+promo,  
			success: function(msg){
				var charitydonation = parseInt($('#charityamount').val().replace(/[^0-9\.^0-9]/g, '').toString()).toFixed(2);
				if (isNaN(charitydonation))
				{
				charitydonation = 0;
				}

				var parts = msg.split("|");
					$("#checkcode").hide();
					$('#discount').show();
					$('#discount').html(parts[0]);
					$('#promomessage').val(parts[0]);
					$('#promotitle').val(parts[1]);
					$('#promoamount').val(parts[2]);
					if(isNaN($('#promoamount').val())){
						var fixedreduction = $('#promoamount').val().replace("£", "");
						fixedreduction = fixedreduction.replace("-", "");
						//$("#total").html((parseInt(charitydonation)+((parseInt($("#fee").val())-parseInt($('#promoamount').val())+parseInt($("#membershipprice").val())))).toFixed(2));
						//$("#grandtotal").val((parseInt(charitydonation)+((parseInt($("#fee").val())-parseInt($('#promoamount').val())+parseInt($("#membershipprice").val())))).toFixed(2));
						
						//alert((parseInt($("#charityamount").val())+parseInt($("#membershipprice").val())+parseInt($("#fee").val())-parseInt($('#promoamount').val())).toFixed(2)); // NHW2010070
						
						var totaltopay = parseInt($("#membershipprice").val())-parseInt($('#promoamount').val());//+parseInt($("#fee").val()) was included
						
						if(totaltopay <= 0){
							totaltopay = 0;
						}
						
						totaltopay = (parseInt(charitydonation)+totaltopay).toFixed(2);

						
						$("#total").html(totaltopay);
						$("#grandtotal").val(totaltopay);
					}
					else {
						//alert($('#promoamount').val()); // NHW2010070
												
						//$("#total").html((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
						//$("#grandtotal").val((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
						
						//alert((parseInt($("#charityamount").val())+parseInt($("#membershipprice").val())+parseInt($("#fee").val())-parseInt($('#promoamount').val())).toFixed(2));
						
						var totaltopay = parseInt($("#membershipprice").val())-parseInt($('#promoamount').val());//+parseInt($("#fee").val()) was included
						
						if(totaltopay <= 0){
							totaltopay = 0;
						}
						
						totaltopay = (parseInt(charitydonation)+totaltopay).toFixed(2);
				
						
						$("#total").html(totaltopay);
						$("#grandtotal").val(totaltopay);
					}
							
							
							if($("#grandtotal").val() == "0.00"){
								 $(".paymentelement").fadeOut("slow");
								 $("#paybutton").val("Next");
							}
			}
		});
	});



	// Update password :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#newpassword").validationEngine({
				ajaxSubmit: true,
				ajaxSubmitFile: "/newpassword.php",
				ajaxSubmitMessage: "",
				success: function(msg){
					$('#newpassword').fadeOut("fast", function(){
						$("#passwordconfirm").fadeIn("slow");
					 })
				},
				failure : function() {}
			});
	
	// Delete message :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".accordion input.delete").click(function() {
				
		$(this).closest('div.eachone').find('.messagehead').fadeOut();
		$(this).closest('div.eachone').find('.messagebody').fadeOut();
						
		var dataString;
		dataString = 'messageid='+$(this).closest('div.eachone').find('.messageid').val()+'&';
		dataString += 'kind=deletemessage';
				
		$.ajax({  
			type: "POST",  
			url: "/update.php",  
			data: dataString,  
			success: function() {}  
		 });  
		return false;

		});
	
	// Home click register to navigate
	
	// $(".registerthirdbox").click(function(){
	//		window.location.href="/register.html";								  
	//  });
	 
	// Home click register to navigate registerbox
	 /*$(".registerthirdbox").click(function() {
		$.cookie("allowcookies", "allowcookies", { expires: 1 });
		$iscookie = $.cookie('allowcookies');
		if( $iscookie != null ) {
		window.location.href="/register.html";	
		} else {
		$.fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 200,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/nocookies.php',
			'onClosed'	: function() {
					
			}

		});
}
}); */


	// Subpage click register to navigate registerbox
	 $(".registerbox").click(function() {
		$.cookie("allowcookies", "allowcookies", { expires: 1 });
		$iscookie = $.cookie('allowcookies');
		if( $iscookie != null ) {
		window.location.href="/register.html";	
		} else {
		$.fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 200,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/nocookies.php',
			'onClosed'	: function() {
					
			}

		});
}
});


	// Username click to login at home page
	 $("#username").focus(function() {
		$.cookie("allowcookies", "allowcookies", { expires: 1 });
		$iscookie = $.cookie('allowcookies');
		if( $iscookie != null ) {

		} else {
		$.fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 200,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/nocookies.php',
			'onClosed'	: function() {
					
			}

		});
}
});


	
	// Home click why to navigate
	
	$(".why").click(function(){
			window.location.href="/";								  
	 });
	
	// Update report :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#recovered").click(function(){
		if($(this).attr('checked')){
			 $(this).closest('div.reportdetails').find('.recoveredhorse').attr('checked','checked');
			 $(this).closest('div.reportdetails').find('.recoveredtack').attr('checked','checked');
			 $(this).closest('div.reportdetails').find('.recoveredother').attr('checked','checked');
			 }
		
	});
	
	$(".recoveredhorse").click(function(){
		if(!$(this).attr('checked')){
			 $(this).closest('div.reportdetails').find('#recovered').removeAttr('checked')
			 }
	});
	
	$(".recoveredother").click(function(){
		if(!$(this).attr('checked')){
			 $(this).closest('div.reportdetails').find('#recovered').removeAttr('checked')
			 }
	});
	
	$(".recoveredtack").click(function(){
		if(!$(this).attr('checked')){
			 $(this).closest('div.reportdetails').find('#recovered').removeAttr('checked')
			 }
	});
	
	
	$(".updatereport").click(function() {
					
		documentDirty = 0;
		
		var additionalmessage = '';
		
		if($(this).closest('div.reportdetails').find('#recovered:checked').val()){
			
				$(this).closest('#report').fadeOut();
				var additionalmessage = 'Closed';
				var unread = parseInt($(".reportcount").html())-1;
				$(".reportcount").html(unread);
		}
		
		var dataString;
		dataString = 'reportid='+$(this).closest('div.reportdetails').find('#reportid').val()+'&';
		dataString += 'kind=updatereport&';
		
		$(this).closest('.reportdetails').find(".additionals").append('<div class="report"><h4>Additional comments made by '+$("#commenttitle").val()+'</h4><ul><li>'+$(this).closest("#report").find("#comments").val()+' '+additionalmessage+'</li></ul><div class="cl"></div></div><div class="cl"></div>');
		
		$(this).closest('div.reportdetails').find('.newmessage').html($(this).closest('#report').find('#comments').val());
		
		$(this).closest('div.reportdetails').find('.crime').html($(this).closest('#report').find('#crimeref').val());
		if($(this).closest('#report').find('#crimeref').val()){
			$(this).closest('#report').find('#crimerefrow').slideUp();
			dataString += 'crimeref='+$(this).closest('div.reportdetails').find('#crimeref').val()+'&';
		}
		
		if($(this).closest('#report').find('#constab option:selected').val() != "-"){
			$(this).closest('div.reportdetails').find('.police').html($(this).closest('#report').find('#constab option:selected').text());
			$(this).closest('#report').find('#constabrow').slideUp();
			dataString += 'constab='+$(this).closest('div.reportdetails').find('#constab').val()+'&';
		}
		
		$(this).closest('div.reportdetails').find('.officer').html($(this).closest('#report').find('#officer').val());
		if($(this).closest('#report').find('#officer').val()){
			$(this).closest('#report').find('#officerrow').slideUp();
			dataString += 'officer='+$(this).closest('div.reportdetails').find('#officer').val()+'&';
		}
		
		$(this).closest('div.reportdetails').find('.number').html($(this).closest('#report').find('#contact').val());
		if($(this).closest('#report').find('#contact').val()){
			$(this).closest('#report').find('#contactrow').slideUp();
			dataString += 'contact='+$(this).closest('div.reportdetails').find('#contact').val()+'&';
		}
		
		dataString += 'comments='+$(this).closest('div.reportdetails').find('#comments').val()+'\n'+additionalmessage+'&';
		$(this).closest('#report').find('#comments').val('');
		
		if($(this).closest('div.reportdetails').find('#recovered:checked').val()){
			
				$(this).closest('#report').fadeOut();
			
		}
		
		dataString += 'recovered='+$(this).closest('div.reportdetails').find('#recovered:checked').val()+'&';
		
		dataString += 'recovered='+$(this).closest('div.reportdetails').find('#recovered:checked').val()+'&';
		dataString += 'status='+$(this).closest('div.reportdetails').find('#status').val()+'&';
		
		var recoveredhorses = "";
		$(this).closest('div.reportdetails').find('.recoveredhorse[checked]').each(function(){
				recoveredhorses += $(this).val()+",";
				$(this).closest('li').fadeOut();
		});
																				   
		
		var recoveredtack = "";
		$(this).closest('div.reportdetails').find('.recoveredtack[checked]').each(function(){
				recoveredtack += $(this).val()+",";
				$(this).closest('li').fadeOut();
		});
																				   
		
		var recoveredother = "";
		$(this).closest('div.reportdetails').find('.recoveredother[checked]').each(function(){
				recoveredother += $(this).val()+",";
				$(this).closest('li').fadeOut();
		});
		
		dataString += 'horses='+recoveredhorses+'&';
		dataString += 'tack='+recoveredtack+'&';
		dataString += 'other='+recoveredother+'&';
		
		
		$.ajax({  
			type: "POST",  
			url: "/update.php",  
			data: dataString,  
			success: function() {}  
		 });
			
		return false;

	});
	
	
	// Populate Police information  :::::::::::::::::::::::::::::::::::::::::::::::::

	$("#constab").change(function() {
			  var str = $("#constab option:selected").val();
			  
			  $.ajax({  
					type: "POST",  
					url: "/getpoliceinfo.php",  
					data: "selectedconstab="+str,  
					success: function(msg){
						var policeinfo = msg.split("|");
						$("#officer").val(policeinfo[0]);
						$("#contact").val(policeinfo[1]);
					}
				});
			});	
	
	// Update profile :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".updateprofile").click(function() {
		var dataString;
		dataString = 'kind=updateprofile&';
		dataString += 'title='+$('#title option:selected').val()+'&';
		dataString += 'firstname='+$('#firstname').val()+'&';
		dataString += 'lastname='+$('#lastname').val()+'&';
		dataString += 'email='+$('#emailaddress').val()+'&';
		dataString += 'dobyear='+$('.dob #dobyear option:selected').val()+'&';
		dataString += 'dobmonth='+$('.dob #dobmonth option:selected').val()+'&';
		dataString += 'dobday='+$('.dob #dobday option:selected').val()+'&';
		dataString += 'verifyquestion='+$('#verifyquestion option:selected').val()+'&';
		dataString += 'verifyanswer='+$('#verifyanswer').val()+'&';
		dataString += 'homephone='+$('#homephone').val()+'&';
		dataString += 'mobilephone='+$('#mobilephone').val()+'&';
		dataString += 'workphone='+$('#workphone').val()+'&';
						
		$('div#profileupdated').fadeIn("slow");
				
		$.ajax({  
			type: "POST",  
			url: "/update.php",  
			data: dataString, 
			success: function() { }
			
		});
		return false;

	});
	
	// Update alerts :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$(".updatealerts").click(function() {
					
		var dataString;
		dataString = 'kind=updatealerts&';
		dataString += 'necdemail='+$('#necdemail:checked').val()+'&';
		dataString += 'necdsms='+$('#necdsms:checked').val()+'&';
						
		$('div#alertsupdated').fadeIn("slow");
						
		$.ajax({  
			type: "POST",  
			url: "/update.php",  
			data: dataString,  
			success: function() {}  
		 });

		return false;

	});
	
	// Search for handed down items (including horses) :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$("#retrieve").submit(function() {  
     
			var necdnumber = $('#necdnumberretrieve').val();
			var necdtype = $('#necdtype').val();
			
			$.ajax({  
				type: "POST",  
				url: "/necdretrieve.php",  
				data: "necdnumber="+necdnumber+"&necdtype="+necdtype,  
				success: function(msg){
					$("#answer").html(msg);
					$("#answer").fadeIn("slow");
				}
			});
			
     return false;
  
     });

// Add handed down item  :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('.add').live('click', function() {
		$.fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : '/addtoestate.php?type='+$(this).attr("id")+'&id=',
			'onClosed'	: function() {
					
			}		
		});
		
	});
	

/*
// Give report horse update  :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('.reporthorse').live('click', function() {
		$.fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : 'reportupdate.php?type=horse&id='+$(this).attr("id")+'&id=',
			'onClosed'	: function() {
					
			}		
		});
		
	});
	

// Give report tack update  :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('.reporttack').live('click', function() {
		$.fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : 'reportupdate.php?type=tack&id='+$(this).attr("id")+'&id=',
			'onClosed'	: function() {
					
			}		
		});
		
	});

// Give report tack update  :::::::::::::::::::::::::::::::::::::::::::::::::
	
	$('.reportother').live('click', function() {
		$.fancybox({
			'type'	: 'iframe',
			'width'	: 500,
			'height' : 320,
			'titleShow'	: false,
			'title' : this.title,
			'href' : 'reportupdate.php?type=tack&id='+$(this).attr("id")+'&id=',
			'onClosed'	: function() {
					
			}		
		});
		
	});
	
*/

// Populate Police information  :::::::::::::::::::::::::::::::::::::::::::::::::

$("#location").change(function() {
		  var str = $("#location option:selected").val();
		  
		  $.ajax({  
				type: "POST",  
				url: "/getpoliceinfo.php",  
				data: "incidentaddress="+str,  
				success: function(msg){
					var policeinfo = msg.split("|");
					$("#constab").val(policeinfo[3]);
					$("#officer").val(policeinfo[1]);
					$("#contact").val(policeinfo[2]);
				}
			});
        });

$("#addtopad").click(function() {
		
		$.ajax({  
				type: "POST",  
				url: "/update.php",  
				data: "kind=scratch&scratchtitle="+$("#scratchtitle").val()+"&scratchdesc="+$("#scratchdesc").val()+"&scratchlocation="+$("#scratchlocation").val()+"&",
				success: function(msg){
					
					$('tbody').prepend('<tr><td>'+$("#scratchtitle").val()+'</td><td>'+$("#scratchdesc").val()+'</td><td>'+$("#scratchlocation option:selected").val()+'</td><td><input type="button" title="remove" class="deletefrompad" id="'+msg+'" value="Delete" /></td></tr>');
		
					$("#scratchtitle").val('');
					$("#scratchdesc").val('');
					$("#scratchlocation option:eq(0)").attr("selected","selected");

				}
			});
		});

$(".deletefrompad").live('click', function() {
	
		var scratchid = $(this).attr('id');
		
		$.ajax({  
				type: "POST",  
				url: "/update.php",  
				data: "kind=removescratch&scratchid="+scratchid+"&",
				success: function(msg){
					$("#"+scratchid).closest('tr').remove();

				}
			});
		
								   
	});

// open reports  :::::::::::::::::::::::::::::::::::::::::::::::::

$('.reportlink').live('click', function(){ $(this).fancybox({
			"type"	: "iframe",
			"width"	: 700,
			"height" : 530,
			"titleShow"	: false,
			"title" : this.title,
			"href" : "/reportdetails.php?reportid=",
			"onClosed"	: function() {
				$("#passwordresetfunction").remove();
				}
			}) });


$(".reportlink").fancybox({
			"type"	: "iframe",
			"width"	: 700,
			"height" : 530,
			"titleShow"	: false,
			"title" : this.title,
			"href" : "reportdetails.php?reportid=",
			"onClosed"	: function() {
				$("#passwordresetfunction").remove();
				}
			});

$("#payment").validationEngine({
		liveEvent: true,
		ajaxSubmit: false,
		success :  function() {
		var promo = $('#promo').val();
		$.ajax({  
			type: "POST",  
			url: "/promocheck.php",  
			data: "code="+promo,  
			success: function(msg){
				var charitydonation = parseInt($('#charityamount').val().replace(/[^0-9\.^0-9]/g, '').toString()).toFixed(2);
				if (isNaN(charitydonation))
				{
				charitydonation = 0;
				}

				var parts = msg.split("|");
					$("#checkcode").hide();
					$('#discount').show();
					$('#discount').html(parts[0]);
					$('#promomessage').val(parts[0]);
					$('#promotitle').val(parts[1]);
					$('#promoamount').val(parts[2]);
					if(isNaN($('#promoamount').val())){
						var fixedreduction = $('#promoamount').val().replace("£", "");
						fixedreduction = fixedreduction.replace("-", "");
						//$("#total").html((parseInt(charitydonation)+((parseInt($("#fee").val())-parseInt($('#promoamount').val())+parseInt($("#membershipprice").val())))).toFixed(2));
						//$("#grandtotal").val((parseInt(charitydonation)+((parseInt($("#fee").val())-parseInt($('#promoamount').val())+parseInt($("#membershipprice").val())))).toFixed(2));
						
						//alert((parseInt($("#charityamount").val())+parseInt($("#membershipprice").val())+parseInt($("#fee").val())-parseInt($('#promoamount').val())).toFixed(2)); // NHW2010070
						
						var totaltopay = parseInt($("#membershipprice").val())-parseInt($('#promoamount').val());//+parseInt($("#fee").val()) was included
						
						if(totaltopay <= 0){
							totaltopay = 0;
						}
						
						totaltopay = (parseInt(charitydonation)+totaltopay).toFixed(2);

						
						$("#total").html(totaltopay);
						$("#grandtotal").val(totaltopay);
					}
					else {
						//alert($('#promoamount').val()); // NHW2010070
												
						//$("#total").html((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
						//$("#grandtotal").val((parseInt(charitydonation)+$('#promoamount').val()*((parseInt($("#fee").val())+parseInt($("#membershipprice").val())))).toFixed(2));
						
						//alert((parseInt($("#charityamount").val())+parseInt($("#membershipprice").val())+parseInt($("#fee").val())-parseInt($('#promoamount').val())).toFixed(2));
						
						var totaltopay = parseInt($("#membershipprice").val())-parseInt($('#promoamount').val());//+parseInt($("#fee").val()) was included
						
						if(totaltopay <= 0){
							totaltopay = 0;
						}
						
						totaltopay = (parseInt(charitydonation)+totaltopay).toFixed(2);
				
						
						$("#total").html(totaltopay);
						$("#grandtotal").val(totaltopay);
					}
							
							
							if($("#grandtotal").val() == "0.00"){
								 $(".paymentelement").fadeOut("slow");
								 $("#paybutton").val("Next");
							}
			}
		});
	},
		failure : function() {
			
			}
	});

$("#payment").submit(function(){
	

	
	
	$("#paybutton").attr('disabled');
	$("#paybutton").fadeTo('fast', 0.3);
	$("#paybutton").css('cursor','default');
	

});



// open reports  :::::::::::::::::::::::::::::::::::::::::::::::::

$(".reportlist").tablesorter({
		// sortList: [[2,1]]
	 });

$(".newslist").tablesorter();

// Show charity information  :::::::::::::::::::::::::::::::::::::::::::::::::

	$("#charity").change(function() {
		  var str = $("#charity option:selected").text();
		  $("#charityinformation").slideUp(function(){
													
			$.ajax({  
				type: "POST",  
				url: "/charity.php",  
				data: "charityname="+$("#charity option:selected").text()+"&",
				success: function(msg){
					if(msg == 'none'){
						$(".donationrow").slideUp();
					}
				else {
					$("#charityinformation").html(msg);
					$("#charityinformation").slideDown();
					$(".donationrow").slideDown();
				}
				}
			});
			
		});
		  
        });

	
// Show form help boxes  :::::::::::::::::::::::::::::::::::::::::::::::::

$(".help").mouseover(function(){
	var message;
	switch ($(this).attr('title')) {
        case "Address help":
		message = "<p><strong>How to add more addresses</strong></p>\n<ol>\n\t<li>To add another address, please complete this form with the default billing address selected.</li>\n\t<li>Please then visit the 'My Details' tab where you can add and change more addresses.</li>\n\t<li>Go to and edit 'My Horses', 'My Tack' and 'My Other Items' to allocate the new addresses to your items.</li>\n</ol>\n"
        break;
        
		case "Insurance help":
		message = "<p><strong>How to add more insurance policies</strong></p>\n<ol>\n\t<li>To add another insurance policy, please complete this form with the default 'uninsured' option selected.</li>\n\t<li>Please then visit the 'My Details' tab where you can add and change more insurance policy details. </li>\n\t<li>Go to and edit 'My Horses', 'My Tack' and 'My Other Items' to allocate the new insurance policies to your items.</li>\n</ol>\n"
        break;
    }
	
	$("#helpmessage").html(message);
});

$(".help").mouseout(function(){
	$("#helpmessage").html('');
});
	
	
// Show cvv help  :::::::::::::::::::::::::::::::::::::::::::::::::

$("#cvvlink").click(function(){
	$("#cvvhelp").slideToggle();
});
	
	
// Open accordions if option is a parameter in the url  :::::::::::::::::::::::::::::::::::::::::::::::::

var option = $.url.param("option");

if(option){
	// $('.accordion h3.'+option).click();
}

// Force the emlements to open on a failed payment - so the user can still see their donation

/*
if(($("#charity option:selected").text() != "I do not want to donate to charity")&&($("#charity option:selected").text() != "")){
	$("#charity").change();
																													   
}
*/

//alert("test"+$("#charity option:selected").text());
												
//alert("test 2");

// End of document ready  :::::::::::::::::::::::::::::::::::::::::::::::::

});

// Remove deleted item  :::::::::::::::::::::::::::::::::::::::::::::::::

function hideDeleted(identifier){
	$("#"+identifier).fadeOut("slow");
}


// Sort select menus  :::::::::::::::::::::::::::::::::::::::::::::::::

function sortValues(which){
	var sortedVals = $.makeArray($('#'+which+' option')).sort(function(a,b){
		return $(a).text() > $(b).text() ? 1: -1;
	});
	//alert(sortedVals);
	$('#'+which).empty().html(sortedVals);
};




