﻿
var dialogHandler = null;

// beware when accessing opener window:  
// showModalDialog does not have an opener, so passing window in as 
// dialogArguments window.open has no dialogArguments, so use 
// window.opener
function ShowDialog(url,width,height,handler)
{
	if ( window.document.all )
	{
		var result = showModalDialog( 
			url, 
			window, 
			"dialogWidth:"+width+"px;dialogHeight:"+height+"px;status:no;");
		if ( typeof(handler)!='undefined' && handler!=null ) 
			handler(result);
	}
	else
	{
		dialogHandler=handler;
		var w = window.open(
			url,
			"_blank",
			"width="+width+",height="+height+",modal=yes,dialog=yes,"+
			"directories=no,menubar=no,toolbar=no,location=no,scrollbars=no,"+
			"status:no,resizable=yes");
	}
}

function DialogDone(result)
{
	if ( window.document.all )
	{
		window.returnValue = result;
		window.close();
	}
	else
	{
		var topFrame = window.top;
		var opener = topFrame.opener;
		if ( typeof(opener.dialogHandler)!='undefined' && opener.dialogHandler!=null ) 
		{		
			opener.dialogHandler(result);
			opener.dialogHandler=null;
		}
		topFrame.close();
	}
}

function GetCookie(name)
{
  var search = name + "=";

  if (window.document.cookie.length > 0)   // if there are any cookies
  {
    offset = window.document.cookie.indexOf(search)
    if (offset != -1)               // if cookie exists
    {
      offset += search.length;
      end = window.document.cookie.indexOf(";", offset);  // set index of beginning of value
      if (end == -1) end = window.document.cookie.length; // set index of end of cookie value
      return decodeURIComponent( document.cookie.substring(offset,end) );
    }
  }
  return null;
}

function SetCookie(name, value)
{
  window.document.cookie = name + "=" + encodeURIComponent(value) + "; path=/;";
}
	        
function HideToolTip(lay) 
{
    var el = document.getElementById([lay]);
    el.style.display = "none";
}
        
function ShowToolTip(lay)
{
    var el = document.getElementById(lay);
    el.style.display = "block";
    el.style.opacity = "0.9";
    el.style.filter = "alpha(opacity=90)";
}

// Return the y coordinate of an element relative to the page.
function getElementTop(el)
{
  if ( el==null) return 0;
  var y = el.offsetTop;
  if (el.offsetParent != null)
    y += getElementTop(el.offsetParent);

  return y;
}

// Return the x coordinate of an element relative to the page.
function getElementLeft(el)
{

  var x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getElementLeft(el.offsetParent);

  return x;
}

function ShowToolTip2(elID,overTT)
{
  if ( overTT )
    eval("overTT"+elID+"=true");
  else
    eval("overEL"+elID+"=true");
  
  // where is the EL?
  var ttID = "tooltip"+elID;
  var el = document.getElementById("content"+elID);
  var tt = document.getElementById(ttID);
  var left = getElementLeft(el);
  var top = getElementTop(el);
  
  // position and show TT
  tt.style.left = ""+(10+left)+"px";
  tt.style.top = ""+(10+top)+"px";
  tt.style.display = "block";
  tt.style.opacity = "0.90";
  tt.style.filter = "alpha(opacity=90)";  
}

function HideToolTip2(elID,outTT) 
{
  if ( outTT )
    eval("overTT"+elID+"=false");
  else
    eval("overEL"+elID+"=false");

//  if ( outTT )
//    alert("out TT");
//  else
//    alert("out EL");
//    
//  alert( eval("overEL"+elID)+" "+eval("overTT"+elID));

  // hide TT
  if (  !eval("overTT"+elID) && !eval("overEL"+elID) );
  {
    var ttID = "tooltip"+elID;
    var tt = document.getElementById(ttID);
    tt.style.display = "none";
  }
}
        
function measureWidth(el)
{
  var GuinneaPig = document.getElementById("GuinneaPig");
  
  if ( el==null || GuinneaPig==null ) { alert("eek!"); return 0; }
  
  GuinneaPig.innerHTML=el.innerHTML;
  GuinneaPig.className=el.className;

  if ( document.all )
    return parseInt(GuinneaPig.offsetHeight);
  else
    return parseInt(GuinneaPig.clientHeight);
}

function ellipsis(prefix)
{
  var outerEL = document.getElementById(prefix+"_outside");
  var innerEL = document.getElementById(prefix+"_inside");
	var ell = document.getElementById(prefix+"_ellipsis");
  if ( outerEL==null || innerEL==null || ell==null ) return;
  
	if ( measureWidth(innerEL) >= measureWidth(outerEL) )
		ell.style.display="block";
	else
		ell.style.display="none";
}


function show(html)
{
  var w = window.open("","_blank","status=yes,resizable=yes,scrollbars=yes,width=400,height=300");
  w.document.write("<html><body>"+html+"</body></html>\n");
  w.document.close();
}

function examine(obj)
{      
  var simple = true;
        if ( obj )
        {
          var rpt = "";
          for (var item in obj)
          {
            if ( item )
            {
              try
              {
                if ( obj[item] )
                {
                  if ( simple )
                    rpt += item+" = "+obj[item]+"\n";
                  else
                    rpt += "<span style='font-weight:bold;'>"+item+" = "+obj[item]+"\n";
                }
                else
                {
                  if ( simple )
                    rpt += item+" = null\n";
                  else
                    rpt += "<span style='font-weight:bold;'>"+item+" = <span style='color:blue;'>null</span>\n";
                }
              }
              catch( e )
              {
                if ( simple )
                  rpt += item+" = error\n";
                else
                  rpt += "<span style='font-weight:bold;'>"+item+" = <span style='color:red;'>error</span>\n";
              }
            }
            else
            {
              if ( simple )
                rpt += "invalid member\n";
              else
                rpt += "<span style='color:red;'>invalid member</span>\n";
            }
          }
        }
        else
        {
          if ( simple )
            rpt = "null";
          else
            rpt = "<span style='color:red;'>null</span>\n";
        }
        if ( false )
          alert(rpt);
        else
        {
          var w = window.open("","_blank","status=yes,resizable=yes,scrollbars=yes,width=400,height=300");
          w.document.write("<html><body><pre>"+rpt+"</pre></body></html>\n");
          w.document.close();
        }
}

function addLoadEvent(fn)
{
  var oldonload = window.onload;
  if( typeof window.onload != "function" )
  	window.onload = fn; 
	else
		Window.onload = function() { oldonload(); fn(); }
}

function textboxMultilineMaxNumber(txt,maxLen){  
  try{  
    if(txt.value.length >= (maxLen)) {
      txt.value = txt.value.substring(0, maxLen);
      alert('Please limit to ' + maxLen + ' characters or less.');
      return false;
    }
  }catch(e){  
  }  
}  

function showhideTextArea(targetId, hiddenId, isPostBack, regEx) { 
  if (document.getElementById(targetId) != null) {
    var temp = document.getElementById(hiddenId).value;
    //alert(temp);
    //alert(isPostBack);
    if (isPostBack == 'yes') {
      temp = temp == 'none' ? '' : 'none';
    }
    document.getElementById(targetId).style.display = temp;
    if (temp == 'none') {
      document.getElementById(targetId).value = '';
      document.getElementById(regEx).style.display = temp;
    }
    temp = temp == 'none' ? '' : 'none';
    document.getElementById(hiddenId).value = temp; 
  }
}

function showHideTextByRadio(flag, targetId, regEx, hiddenF) {
  var temp = document.getElementById(targetId);
  if (temp != null) {
    document.getElementById(targetId).style.display = flag; 
    document.getElementById(hiddenF).value = flag;
    if (flag == 'none') {
      document.getElementById(targetId).value = '';
      document.getElementById(regEx).style.display = flag;
    }
  }
}

function keyPressDectect(id) {
    if(event.which || event.keyCode) {
      if ((event.which == 13) || (event.keyCode == 13)) {
        document.getElementById(id).click();
        return false;
      }
    } else {
      return true;
    }
  }
  
/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12; //Customize x offset of tooltip
var offsetfromcursorY=10; //Customize y offset of tooltip

var offsetdivfrompointerX=10; //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=13; //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="theToolTip"></div>'); //write out tooltip DIV
document.write('<img id="ToolTipPointer" src="/img/tooltiparrow.gif">'); //write out pointer image

var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;
if (ie||ns6)
{
  var tipobj=document.all? document.all["theToolTip"] : document.getElementById? document.getElementById("theToolTip") : "";
}
var pointerobj=document.all? document.all["ToolTipPointer"] : document.getElementById? document.getElementById("ToolTipPointer") : "";

function ietruebody()
{
  return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function ddrivetip(thetext, thewidth, thecolor)
{
  if (ns6||ie)
  {
    if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
    if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
    tipobj.innerHTML=thetext;
    enabletip=true;
    return false;
  }
}

function positiontip(e)
{
  if (enabletip)
  {
    var nondefaultpos=false;
    var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
    var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
    //Find out how close the mouse is to the corner of the window
    var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20;
    var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20;
    var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX;
    var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY;
    var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000;

    //if the horizontal distance isn't enough to accomodate the width of the context menu
    if (rightedge<tipobj.offsetWidth)
    {
      //move the horizontal position of the menu to the left by it's width
      tipobj.style.left=curX-tipobj.offsetWidth+"px";
      nondefaultpos=true;
    }
    else if (curX<leftedge)
    {
      tipobj.style.left="5px";
    }
    else
    {
      //position the horizontal position of the menu where the mouse is positioned
      tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px";
      pointerobj.style.left=curX+offsetfromcursorX+"px";
    }

    //same concept with the vertical position
    if (bottomedge<tipobj.offsetHeight)
    {
      tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px";
      nondefaultpos=true;
    }
    else
    {
      tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px";
      pointerobj.style.top=curY+offsetfromcursorY+"px";
    }
    tipobj.style.visibility="visible";
    if (!nondefaultpos) 
    {
      pointerobj.style.visibility="visible";
    } 
    else 
    {
      pointerobj.style.visibility="hidden";
    }
  }
}

function hideddrivetip()
{
  if (ns6||ie)
  {
    enabletip=false;
    tipobj.style.visibility="hidden";
    pointerobj.style.visibility="hidden";
    tipobj.style.left="-1000px";
    tipobj.style.backgroundColor='';
    tipobj.style.width='';
  }
}

document.onmousemove=positiontip;

$(document).ready(function(){
	
	$(".toggle_container").hide();

	$("span.trigger").toggle(function(){
		$(this).addClass("active"); 
		}, function () {
		$(this).removeClass("active");
	});
	
	$("span.trigger").click(function(){
		$(this).next(".toggle_container").slideToggle("slow,");
	});

});

