/* register plus specific javascript*/

 $(document).ready(function() {

    initExpandable();

    });


function expandContent(element) {
 var boxHeight = element.scrollHeight;
   if (navigator.userAgent.indexOf('Safari') != -1  //safari
       || (document.all && !(navigator.userAgent.indexOf( 'Opera' ) != -1))) { //ie
      boxHeight -= 2;
   }

   $(element)[0].style.height = boxHeight+"px";
}

function initExpandable(){

   var prefix = getPage();

      $(".expandable").blur(function() {
          if (trim(this) == "")
             removeSessionAttr(prefix + $(this).attr("name"));
           else
             setSessionAttr(prefix + $(this).attr("name"), trim(this));
      });

      $(".expandable").each(function() {
         if (trim(this) == "" ) {
              $(this).val(getSessionAttr(prefix + $(this).attr("name")));
              expandContent(this);
         }
      });

}

function resetSearchForm() {
  $("div.formElement > span.text > input, textarea").each(function() {
    $(this).val("");
    removeSessionAttr(getPage() + $(this).attr("name"));
  });
}

function resetReportForm() {
  $("input:text, textarea, #category, input:radio:checked").each(function() {
    if ($(this).attr("id") != "publicationNumber" && $(this).attr("id") != "url") {
      $(this).val("");
    }
    if ($(this).attr("name") == "subcategory") {
      $(this).removeAttr("checked");
    }
    removeSessionAttr(getPage() + $(this).attr("name"));
  });
}

function removeReportFromSession() {
  removeSessionAttr("reportname");
  removeSessionAttr("reportsurname");
  removeSessionAttr("reportcompany");
  removeSessionAttr("reportcountry");
  removeSessionAttr("reportemail");
  removeSessionAttr("reportphone");
  removeSessionAttr("reportcategory");
  removeSessionAttr("reportsubcategory");
  removeSessionAttr("reportdescription");
}

function setSessionAttr(name, value) {
  $.session(name, value);
}

function getSessionAttr(name) {
  return $.session(name);
}

function removeSessionAttr(name) {
  return $.session(name, "", "true");
}

  function selectAllDocuments(){
      var checkboxes = document.getElementsByName("identivier");
      for (var i = 0; i < checkboxes.length; i++) {
         if(document.getElementById("selectAllCheckbox").checked) checkboxes[i].checked = true;
         else checkboxes[i].checked = false;
      }
   }

   function NewPDFWindow(mypage, winname) {
      sAl=screen.availLeft;
      if (sAl = 'undefined') sAl=0;
      sAt=screen.availTop;
      if (sAt = 'undefined') sAt=0;
      var iever = getInternetExplorerVersion();
      var offset = 0;
      switch (iever) {
         case -1: offset=368; break;
         case 6: offset=368; break;
         case 7: offset=368; break;
         case 8: offset=258; break;
      }
      h=screen.availHeight-0;
      w=screen.availWidth*0.6;
        if (w<600) w=600;

      t=sAt;
      l=screen.availWidth-w-15-sAl;
      var winnameNoSpaces = escape(winname.split(' ').join(''));
        win = window.open(mypage, winnameNoSpaces, 'height='+h+',width='+w+',top='+t+',left='+l+','+'scrollbars=yes,resizable');
   }


