﻿


//onerror = report;
var Selected = 1;


function OnOffPost(e)
{

   if ( !e ) e = window.event;
   var target = e.target ? e.target : e.srcElement;
   

if (!target) return;
   
 while (target.id.indexOf('LinkTrigger')<0)
 {
	//alert(target.id + target.id.indexOf('LinkTrigger')+target.parentNode);
	
     target = target.parentNode;
     if (target.id ==null) return;
     }
  if ( target.id.indexOf('LinkTrigger')<0 )
   return;
   

   if (Selected)
   {
      var body = document.getElementById(Selected + "ON");
      if (body)
         body.style.display = 'none';
      var head = document.getElementById(Selected + "OFF");
      if (head)
         head.bgColor = '#EDF8F4';
   }

   if (Selected == target.name) // just collapse
      Selected="";
   else
   {
      Selected = target.name;
      var body = document.getElementById(Selected + "ON");
      if (body)
      {
         if (body.style.display=='none')
            body.style.display='';
         else
            body.style.display = 'none';
      }
      var head = document.getElementById(Selected + "OFF");
      if (head)
         head.bgColor = '#B7DFD5';

      if ( body && head && body.style.display != 'none' )
      {
         document.body.scrollTop = FindPosition(head, "Top") - document.body.clientHeight/10;
         OpenMessage(target.name, true);
      }
   }

   if ( e.preventDefault )
      e.preventDefault();
   else
      e.returnValue = false;
   return false;
}

// does its best to make a message visible on-screen (vs. scrolled off somewhere).
function OpenMessage(msgID, bShowTop) {
   var msgHeader = document.getElementById(msgID + "OFF");
   var msgBody = document.getElementById(msgID + "ON");

   // determine scroll position of top and bottom
   var MyBody = document.body;
   var top = FindPosition(msgHeader, 'Top');
   var bottom = FindPosition(msgBody, 'Top') + msgBody.offsetHeight;

   // if not already visible, scroll to make it so
   if ( MyBody.scrollTop > top && !bShowTop)
      MyBody.scrollTop = top - document.body.clientHeight/10;
   if ( MyBody.scrollTop+MyBody.clientHeight < bottom )
      MyBody.scrollTop = bottom-MyBody.clientHeight;
   if ( MyBody.scrollTop > top && bShowTop)
      MyBody.scrollTop = top - document.body.clientHeight/10;
}

// utility
function FindPosition(i,which)
{
   iPos = 0
   while (i!=null)
   {
      iPos += i["offset" + which];
      i = i.offsetParent;
   }
   return iPos
}

function report(message,url,line) {
    alert('Error : ' + message + ' at line ' + line + ' in ' + url);
}


function closeReplyDialog() {
    $(".simplemodal-overlay").hide();
    $(".simplemodal-container").hide();
}



function showReply(src, wi, he) {


    if (typeof (wi) != "undefined") {

        $.modal('<iframe id="main_content" name="main_content" src="' + src + '" height="' + he + '" width="' + wi + '" style="border:none" frameBorder="0" scrolling="0">',

    {
        containerCss: {
            backgroundColor: "#fff",            
            height: (he),
            padding: 0,
            width: wi
        },
        overlayClose: false,
        modal: true
    });
    }
    else {
        $.modal('<iframe id="main_content" name="main_content" src="' + src + '" height="500px" width="100%" style="border:none" frameBorder="0" scrolling="0">', {
            containerCss: {
                backgroundColor: "#fff",                             
                height: 500,
                padding: 0,
                width: 500
            },
            overlayClose: false,
            modal: true
        });

    }

   
}


 
function lockMessage(id, lock) {
    $(document).ready(function () {
        var url = $(location).attr('href');
        var pos = url.indexOf('?');

        if (pos > -1)
            url = url.substr(0,pos);

        $(location).attr('href', url + '?lockMessageId=' + id + '&lockMessage=' + lock);
    });
}

function approveMessage(id,status) {
    $(document).ready(function () {
        var url = $(location).attr('href');
        var pos = url.indexOf('?');

        if (pos > -1)
            url = url.substr(0, pos);

        $(location).attr('href', url + '?approveMessageId=' + id + '&Status=' + status);
    });
}

function commonMessage(id,common) {
    $(document).ready(function () {
        var url = $(location).attr('href');
        var pos = url.indexOf('?');

        if (pos > -1)
            url = url.substr(0, pos);

        $(location).attr('href', url + '?commonMessageId=' + id + '&isCommon=' + common);
    });
}


