$(document).ready( function (){
  $("#regDownloadButton").hover(
    function () {
      $(this).css("border-style", "inset").css("cursor", "pointer");
    },
    function () {
      $(this).css("border-style", "outset").css("cursor", "default");
    }
  );
  $("#regDownloadButton").click(function (){
    if(!$("input[name=doc]:checked").length){
      alert("Please select a report type.");
    } else {
      var url = "";
      switch($("input[name=doc]:checked").val()){
        case "reg":
          window.open("reg_pub_dsp.show_rsl_reg_details?pi_search_id=" + $("#searchId").val());
          break;
        case "dir":
          window.open("reg_pub_dsp.show_rsl_directory?pi_search_id=" + $("#searchId").val());
          break;
        case "mail":
          $("#mailing").show();
      }
    }
  });
	 $(".regButton").hover(
	    function () {
		   $(this).css("border-style", "inset").css("cursor", "pointer");
		},
	    function () {
		   $(this).css("border-style", "outset").css("cursor", "default");
		}
	 );
	 $("#mailCancel").click(function (){
	   $(".regMultiDoc").hide();
	 });
	 $("#mailOK").click(function (){
    if(!$("input[name=mailing]:checked").length){
      alert("Please select a report type.");
    } else {
      var url = "";
      switch($("input[name=mailing]:checked").val()){
        case "list":
           url="reg_enhanced.show_mailing_list?pi_search_id=" + $("#searchId").val();
           window.location = url;
           break;
        case "label":
           url="reg_pub_dsp.show_address_labels?pi_search_id=" + $("#searchId").val();
           window.open(url);
      }
      $("#mailing").hide();
    }
	 });
  $("#msgArea").css("margin-left", (3 + $(".resultName").width()) +"px");
  var defaultMessage = $("#msgArea").html();
  $(".msgHover").hover(
    function (){
      $(this).css("cursor", "pointer");
      var msg;
      var id = $(this).attr("id");
      switch(id){
        case "details":
          msg = "You can view details of an RSL's registered address, contact details, legal status, associated organisations and the local authority areas in which they have housing.";
          break;
        case "accounts":
          msg = "The audited accounts are available covering the last five years where appropriate, and show detailed information on an RSL's income &amp; expenditure, balance sheet, cashflow and operating costs.";
          break;
        case "alloc":
          msg = "The Allocation Policy details how an RSL lets its housing stock, administers its housing list and its application assessment process.<br/><br/>";
          break;
        case "apsr":
          msg = "The APSR shows a detailed report of an RSL's performance in year and key statistical data such as information about stock owned.<br/><br/>";
          break;
        case "inspect":
          msg = "The Inspection Report details the findings of the most recent inspection carried out and the grade awarded to an RSL (for those where inspections have taken place).";
          break;
        case "perf":
          msg = "The Performance Profile shows statistics on an RSL's lettings and voids, rents and arrears, housing stock and management costs.<br/><br/>";
          break;
        case "rules":
          msg = "The Rules/Memoranda shows detail on how an RSL operates and carries out its business.<br/><br/>";
          break;
        default:
          msg = "";
      }
		   $("#msgArea").html(msg);
    },
    function () {
      $(this).css("cursor", "default");
      $("#msgArea").html(defaultMessage);
    }
  );
  $(".regAccount").click(function (){
    var url = "/register/reg_enhanced.pop_accounts_popup";
    var params = "pi_reg_no=" +  $(this).attr("id").split("_")[1] + "&r=1301172220";
    $("#yrAccountYrs").html("<img src='regadmin.cntsample.download?p_file=ajax_loader_big.gif' style='margin-top:25px;'/>");
    $("#yrAccount").css("top", (0 + $(window).scrollTop()) + "px").show();
    $("#yrAccountYrs").load(url, params);
  });
  $(".regAPSR").click(function (){
    var url = "/register/reg_enhanced.pop_apsr_popup";
    var params = "pi_reg_no=" +  $(this).attr("id").split("_")[1] + "&r=661176786";
    $("#yrAPSRYrs").html("<img src='regadmin.cntsample.download?p_file=ajax_loader_big.gif' style='margin-top:25px;'/>");
    $("#yrAPSR").css("top", (0 + $(window).scrollTop()) + "px").show();
    $("#yrAPSRYrs").load(url, params);
  });
  $(".regPerf").click(function (){
    var url = "/register/reg_enhanced.show_perf_popup";
    var params = "pi_reg_no=" +  $(this).attr("id").split("_")[1] + "&r=1891165897";
    $("#yrPerf").load(url, params, function(){ $("#yrPerf").show() });
  });
});

