/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

function Trim(str)
{
   return RTrim(LTrim(str));
}

function launchSizableWin(page,w,h) {
	var puWin = window.open(page,null,"dependent,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,titlebar=yes,screenX=150,screenY=150,top=150,left=150, width=" + w + ",height=" + h );
	puWin.focus();
}
function getWinWidth(win){
    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            return win.window.innerWidth;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) {
            return win.document.body.offsetWidth;
        }
    }
    return null;
}
function getWinHeight(win){
    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            return win.window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) {
            return win.document.body.offsetHeight;
        }
    }
    return null;
}

var puWin;
function checkHeight(h){
    if (puWin.document.body==null) {
        window.setTimeout('checkHeight('+h+')', 333);
        return;
    }
    puWinWidth = getWinWidth(puWin); if (puWinWidth==null) return;
    offsetH = getWinHeight(puWin)-h;

    return;
    
    //TODO: PENDING CODE - IGNORE FOR NOW

    switch(offsetH){
        case 1:
            puWin.resizeTo(puWinWidth,offsetH);
            break;
        default: //4 is ok for IE+intranet
            break;
    }
}

function launchFixedWin(page,w,h) {
//alert(h);
	puWin = window.open(page,null,"dependent,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,titlebar=no,width=" + w + ",height=" + h );
	puWin.focus();
}
function launch(cUrl,w,h){
	if (logged){
		msg = "You are about to view a sample module for demonstration purposes only. This module contains copyrighted material which may not be reused in any manner. \r\r" 
			+ "If you understand and accept these conditions please select “OK” to continue. To quit select “Cancel”."
		if (confirm(msg)) launchFixedWin(cUrl, w, h);
	}
	else{
		//alert("To login, type your email and password in the boxes at the top right corner of this page, \rthen press the ENTER key.");
		var url = document.location.href;
		var i = url.lastIndexOf("/") + 1;
		var page=url.substring(i, url.length);
		document.location.href="../login.asp?r=" + escape(page) + "&js=" + escape("launch('" + cUrl + "'," + w + "," + h + ");");
	}
	
}

function insertFlashFile(file, width, height, oName, flVars){
	var nameAttr = null;
	if (oName==null || oName=="") {
		nameAttr = "";}
	else{
		nameAttr = "name=\"" + oName + "\" id=\"" + oName + "\"";
	}
	htm ='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH=' + width + ' HEIGHT=' + height + ' ' + nameAttr + '>';
	htm+='<PARAM NAME=movie VALUE="' + file + '">';
	htm+='<PARAM NAME=menu VALUE=false>';
	htm+='<PARAM NAME=allowScriptAccess VALUE=always>';
	htm+='<PARAM NAME=quality VALUE=high>';
	htm+='<param name="wmode" value="transparent">';
	if (flVars!=null) htm+='<PARAM NAME=FlashVars VALUE=' + flVars + '>';
	htm+='<EMBED ' + nameAttr + ' src="' + file + '" swliveconnect="true" allowScriptAccess="always" quality=high MENU=false WIDTH=' + width + ' HEIGHT=' + height + ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>';
	htm+='</OBJECT>';
	document.write(htm);
}