// Module version: 4.05.21

// This Software is Copyright Electronic Publication Solutions Ltd. All Rights Reserved.
// Unauthorised use without permission is strictly prohibited.


 var version4 = (navigator.appVersion.charAt(0) == "4"); 
 var popupHandle;

 // Browser / OS detector vars
 var detect,OS,browser,version,total,thestring;

 var gASPJSDELIM = "|";



function showError(ErrorMess) {
 alert( ErrorMess );
}

function closePopup() {
 if( popupHandle != null && !popupHandle.closed ) popupHandle.close()
}


function displayMaxPopup(wantsbars,wantsizeable,wantdirectories,wantstatusbar,wantmenubar,wanttoolbar,wantlocation,url,name,evnt)
{

	// Show a popup to the max width of the users resolution. Start the window at the top-left.

	var properties	=	 "directories="+wantdirectories+",menubar="+wantmenubar+",status="+wantstatusbar;
	properties			+= ",toolbar=" + wanttoolbar + ",location="+wantlocation;
	properties			+= ",scrollbars="+wantsbars+",resizable="+wantsizeable;


	// How wide and high can this popup be in the users resolution?
	var scrWidth, scrHeight;
	scrWidth			= screen.availWidth;
	scrHeight			= screen.availHeight;

	// Allowance for borders (10) and Taskbar (50)
	scrWidth			-= 10;
	scrHeight			-= 57;
	properties			+= ",height="+scrHeight+",width="+scrWidth;


	// Location
	var left=0,top=0;
	properties			+= ",left="+left+",top="+top;

	closePopup();
	popupHandle = open(url,name,properties);

	// This interferes with Google's popup killer!
	// popupHandle.focus();


}



function displayPopup(sbars,sizeable,position,url,name,height,width,evnt)
{

 // position=1 POPUP: makes screen display up and/or left, 
 //    down and/or right
 // depending on where cursor falls and size of window to open
 // position=2 CENTER: makes screen fall in center

 var properties = "toolbar=0,location=0,height="+height
 properties     = properties+",width="+width
 properties     = properties+",scrollbars="+sbars+",resizable="+sizeable

 var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt

 if(navigator.appName == "Microsoft Internet Explorer") 
 {
	screenY = document.body.offsetHeight
	screenX = window.screen.availWidth
 }
  else
      { // Navigator coordinates
		screenY = screen.height;
		screenX = screen.width;
      }

 if(position == 1)	// if POPUP not CENTER
 {
	cursorX = evnt.screenX  
	cursorY = evnt.screenY 
	padAmtX = 10
	padAmtY = 10
	
	if((cursorY + height + padAmtY) > screenY)	
	// make sizes a negative number to move left/up
	{
		padAmtY = (-30) + (height*-1);	
		// if up or to left, make 30 as padding amount
	}

	if((cursorX + width + padAmtX) > screenX)
	{
		padAmtX = (-30) + (width*-1);	
		// if up or to left, make 30 as padding amount
	}

	if(navigator.appName == "Microsoft Internet Explorer") 
	{
		leftprop = cursorX + padAmtX
		topprop = cursorY + padAmtY
	}
 	 else
	 { // adjust Netscape coordinates for scrolling
		leftprop = (cursorX - pageXOffset + padAmtX)
		topprop = (cursorY - pageYOffset + padAmtY)
	 }
 }
  else	// CENTER
  {
	leftvar = (screenX - width) / 2
	rightvar = (screenY - height) / 2
		
	if(navigator.appName == "Microsoft Internet Explorer") 
	{
		leftprop = leftvar
		topprop = rightvar
	}
	else
 	 { // adjust Netscape coordinates for scrolling
		leftprop = (leftvar - pageXOffset)
		topprop = (rightvar - pageYOffset)
	 }
  }

 if(evnt != null)
 {
  properties = properties+",left="+leftprop
  properties = properties+",top="+topprop
 }
 
 closePopup()
 popupHandle = open(url,name,properties)

}



function displayPopupWithSBar(sbars,sizeable,position,url,name,height,width,evnt)
{

 // position=1 POPUP: makes screen display up and/or left, 
 //    down and/or right
 // depending on where cursor falls and size of window to open
 // position=2 CENTER: makes screen fall in center

 var properties = "toolbar=0,location=0,status=1,height="+height
 properties     = properties+",width="+width
 properties     = properties+",scrollbars="+sbars+",resizable="+sizeable


 var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt

 self.name="main";


 if(navigator.appName == "Microsoft Internet Explorer") 
 {
	screenY = document.body.offsetHeight
	screenX = window.screen.availWidth
 }
  else
      { // Navigator coordinates
		screenY = screen.height;
		screenX = screen.width;
      }

 if(position == 1)	// if POPUP not CENTER
 {
	cursorX = evnt.screenX  
	cursorY = evnt.screenY 
	padAmtX = 10
	padAmtY = 10
	
	if((cursorY + height + padAmtY) > screenY)	
	// make sizes a negative number to move left/up
	{
		padAmtY = (-30) + (height*-1);	
		// if up or to left, make 30 as padding amount
	}

	if((cursorX + width + padAmtX) > screenX)
	{
		padAmtX = (-30) + (width*-1);	
		// if up or to left, make 30 as padding amount
	}

	if(navigator.appName == "Microsoft Internet Explorer") 
	{
		leftprop = cursorX + padAmtX
		topprop = cursorY + padAmtY
	}
 	 else
	 { // adjust Netscape coordinates for scrolling
		leftprop = (cursorX - pageXOffset + padAmtX)
		topprop = (cursorY - pageYOffset + padAmtY)
	 }
 }
  else	// CENTER
  {
	leftvar = (screenX - width) / 2
	rightvar = (screenY - height) / 2
		
	if(navigator.appName == "Microsoft Internet Explorer") 
	{
		leftprop = leftvar
		topprop = rightvar
	}
	else
 	 { // adjust Netscape coordinates for scrolling
		leftprop = (leftvar - pageXOffset)
		topprop = (rightvar - pageYOffset)
	 }
  }

 if(evnt != null)
 {
  properties = properties+",left="+leftprop
  properties = properties+",top="+topprop
 }
 

 closePopup()
 popupHandle = window.open(url,name,properties)

}


function closePopupUpdateMainWnd( url ) {
 window.opener.top.location.href        = url;
 window.close();
}



function listboxAddOneItem(contextandControlName, txtVal, val) {
 var oOption   = document.createElement("OPTION");

 oOption.text  = txtVal;
 oOption.value = val;

 contextandControlName.add(oOption)
 return true;
}




function listboxRemoveOneItem(contextandControlName, val) {
 for ( var m=0; m < contextandControlName.options.length; m++ ) {
   // first we have to retrieve the index
   if ( contextandControlName.options[m].value == val ) { 
      contextandControlName.options.remove( m );
   }
 } 
}

function listboxRemoveAll(contextandControlName) {
  while ( contextandControlName.options.length != 0 ) {
    for ( var i=0; i<=contextandControlName.options.length; i++ ) {
     if ( contextandControlName.options.length != 0 ) { contextandControlName.options.remove(i); }    
    }
  }
}


function listboxSelectAll(contextandControlName) {

 if ( contextandControlName.options.length != 0 ) {

  for (var i = contextandControlName.options.length-1; i >= 0; i--) {
   contextandControlName.options[i].selected = true; 
  }

 }

}



function listboxMoveOption(selectObj, direction)
{
	
  // Moves a selected item in a list up or down: 
  // direction param = -1 for Up and +1 for down
	
        if(selectObj.selectedIndex != -1)
        {
          if(direction < 0)
          {
            for(i = 0; i < selectObj.options.length; i++)
            {
              swapValue = (i == 0 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].value;
              swapText = (i == 0 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].text;
              if(selectObj.options[i].selected && swapValue != null && swapText != null)
              {
                thisValue = selectObj.options[i].value;
                thisText = selectObj.options[i].text;
                selectObj.options[i].value = swapValue;
                selectObj.options[i].text = swapText;
                selectObj.options[i + direction].value = thisValue;
                selectObj.options[i + direction].text = thisText;
                selectObj.options[i].selected = false;
                selectObj.options[i + direction].selected = true;
              }
            }
          }
          else
          {
            for(i = selectObj.options.length - 1; i >= 0; i--)
            {
              swapValue = (i == selectObj.options.length - 1 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].value;
              swapText = (i == selectObj.options.length - 1 || selectObj.options[i + direction].selected) ? null : selectObj.options[i + direction].text;
              if(selectObj.options[i].selected && swapValue != null && swapText != null)
              {
                thisValue = selectObj.options[i].value;
                thisText = selectObj.options[i].text;
                selectObj.options[i].value = swapValue;
                selectObj.options[i].text = swapText;
                selectObj.options[i + direction].value = thisValue;
                selectObj.options[i + direction].text = thisText;
                selectObj.options[i].selected = false;
                selectObj.options[i + direction].selected = true;
              }
            }
          }
        }

}



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) { //v3.0
  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); 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 getBrowserOrOSInUse(whatsrequired) {

	detect = navigator.userAgent.toLowerCase();


	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser = "Safari"
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab"
	else if (checkIt('msie')) browser = "Internet Explorer"
	else if (!checkIt('compatible'))
	{
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "Unknown";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS)
	{
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "Unknown";
	}

	if ( whatsrequired == "OS" )
	{
		return OS;
	}
	 else {
		return browser;
	 }

}

function checkIt(string)
// Sister function for getBrowserInUse
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

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_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_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];}
}