function MM_preloadImages() { //v3.0
   var d = document; if (d.images) {
      if (!d.MM_p) d.MM_p = new Array();
      var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
         if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
   }
}
function MM_swapImgRestore() { //v3.0
   var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_findObj(n, d) { //v4.01
   var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
      d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
   }
   if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
   for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
   if (!x && d.getElementById) x = d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
   var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
      if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function MM_swapMenu() {//v1.0
   var i = 0, j = 0, x, a = MM_swapMenu.arguments;
   document.MM_sr = new Array;
   x = document.getElementById(a[i]);
   x.className = a[i + 1];
   for (i = 2; i < (a.length - 2); i += 3)
      if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function MM_swapClass() {//v1.0
   var i = 0, j = 0, x, a = MM_swapClass.arguments; document.MM_swc = new Array;
   x = document.getElementById(a[i]);
   document.MM_swc[j++] = x;
   document.MM_swc[j++] = x.className;
   x.className = a[i + 1];
}
function MM_swapClassRestore() {//v1.0
   var i, x, a = document.MM_swc;
   for (i = 0; a && i < a.length && (x = a[i]); i++) x.className = a[++i];
}
function MM_redirect() {
   var a = MM_redirect.arguments;
   window.location = a[0];
}
function MM_toggleClass() { //v1.0
   var i = 0, j = 0, x, a = MM_toggleClass.arguments;
   var tc = document.MM_tc;
   if (!tc) {
      document.MM_tc = new Array;
      x = document.getElementById(a[i]);
      document.MM_tc[j++] = x;
      document.MM_tc[j++] = x.className;
      x.className = a[i + 1];
   }
   else {
      for (i = 0; i < tc.length; i++) {
         x = document.getElementById(a[i]);
         if (tc[i] == x) {
            var csname = x.className;
            x.className = tc[i + 1];
            tc[i + 1] = csname;
         }
      }
   }
}
function pageLoad() {
   setSavePanelPosition();
   var PS_LocalTimeClientTimeOffset = document.getElementById("ctl00_ClientTimeOffset").innerHTML;
   if (PS_LocalTimeClientTimeOffset == "") {
      try {
         var clientype = document.getElementById("PS_InterfaceClientType").innerHTML;
         if (clientype == "admin") {
            PlumSoftware.PS_AdminWebInterface.Timeout = 100;
            PlumSoftware.PS_AdminWebInterface.GetSessionString("ClientTimeOffset", PS_LocalTimeGetSessionString, PS_LocalTimeOnServiceError);
         }
         else if (clientype == "customer") {
            PlumSoftware.PS_CustomerWebInterface.Timeout = 100;
            PlumSoftware.PS_CustomerWebInterface.GetSessionString("ClientTimeOffset", PS_LocalTimeGetSessionString, PS_LocalTimeOnServiceError);
         }
         else {
            PlumSoftware.PS_WebInterface.Timeout = 100;
            PlumSoftware.PS_WebInterface.GetSessionString("ClientTimeOffset", PS_LocalTimeGetSessionString, PS_LocalTimeOnServiceError);
         }
      }
      catch (err) {
      }
   }
}
function PS_LocalTimeGetSessionString(result) {
   var PS_LocalTimetimeoffset = result[1];
   if (PS_LocalTimetimeoffset == "") {
      var currentTime = new Date();
      var currentOffset = currentTime.getTimezoneOffset();
      __doPostBack('ctl00$GetLocalTimeIt', currentOffset.toString());
   }
}
function PS_LocalTimeOnServiceError(error) {
}
function checkDescription() {
   var desholder = $get('ctl00_thePopups_ctl00_ctl00_DescriptionClientID');
   if (desholder.value == "")
      return;
   var description = $get(desholder.value);
   if (description.value == "")
      alert("Description not filled in Upload File(s) will fail");
}
function loadhelp(HelpId, CompanyID, Menu) {
   var loadhelp = window.open('http://www.plum.co.nz/PS_Help/Default.aspx?HelpID=' + HelpId + '&CompanyID=' + CompanyID + "&Menu=" + Menu,'Help','scrollbars=yes,menubar=no,height=600,width=470,resizable=yes,toolbar=no,location=no,status=no');
}

function setSavePanelPosition() {
   // call the savePanelPosition when the panel is moved
   var pp = $get("ctl00_theDragPopup_PopupBehaviourID");
   if (pp == null)
      return;
   if (pp.value == "")
      return;
   var popbehav = $find(pp.value);
   if (popbehav)
      popbehav.add_move(savePanelPosition);
   var elem = $get("ctl00_theDragPopup_SaveLocation");
   if (elem == null)
      return;
   if (elem.value != "0") {
      var temp = new Array();
      temp = elem.value.split(';');
      // set the position of the panel manually with the retrieve value
      $find(pp.value).set_location(new Sys.UI.Point(parseInt(temp[0]), parseInt(temp[1])));
   }
}

function savePanelPosition() {
   var pp = $get("ctl00_theDragPopup_PopupBehaviourID");
   if (pp == null)
      return;
   if (pp.value == "")
      return;
   var popbehav = $find(pp.value);
   var elem = $find(pp.value).get_element();
   if (elem == null)
      return;
   var loc = $common.getLocation(elem);
   var elem1 = $get("ctl00_theDragPopup_SaveLocation");
   // store the value in the hidden field
   elem1.value = loc.x + ';' + loc.y;
}
