function IsSpace (s)
{
  if (s==null)
   return;
  var i;
  for( i = 0; i < s.length; i ++ )
  {
    var oneChar = s.charAt( i );
    if( oneChar != " " )
      return false;
  }
  return true;
}


function IsEmpty(s)
{
  return ((s == null) || (s.length == 0) || (IsSpace(s)) || (s == "") )
}


function alertMessage (strMessage)
{
	if (strMessage != '')
	{
		alert (strMessage);
	}
}

function Expand(obj, imgId)
{
  var expandIcon = "/include/img/subnav/arrowblueopen.gif";
  var collapseIcon = "/include/img/subnav/arrowblue.gif";


  if (obj.style.display == "none")
  {
	obj.style.display = "inline";
	eval ('document.all.' + imgId + '.src = expandIcon');
  }
  else
  {
	obj.style.display = "none";
	eval ('document.all.' + imgId + '.src = collapseIcon;');
  }
  return true;
}

function xore(xork, dat)
{
  if (IsEmpty (dat))
    return null;

	var the_res="";//the result will be here
	for(i=0;i<dat.length;++i)
	{
		the_res += String.fromCharCode(xork^dat.charCodeAt(i));
	}
	return the_res;
}

function xord(xork, dat)
{
  if (IsEmpty (dat))
    return null;

  var the_res="";//the result will be here
	for(i=0;i<dat.length;i++)
	{
		the_res += String.fromCharCode(xork^dat.charCodeAt(i));
	}
  return the_res;
}

function openCenteredWindow (width, height, windowName, scroll, statusbar, toolbar, url, htmlText, focus)
{
  var winName = "" + windowName;
  var winprops = "";
  var scrollbars = scroll;

  var doc_width  = width;
  var doc_height = height;
  var screenHeight = screen.height;

  if (doc_height > (screen.height-100) )
  {
   screenHeight = screenHeight - 100;
   doc_height = screenHeight;
   doc_width  = doc_width + 17;
   scrollbars = 'yes';
  }
  if (doc_width > screen.width)
  {
   doc_width = screen.width - 20;

   alert ('test');
   if (IsEmpty (scrollbars) || scrollbars == 'no' || scrollbars == 'false' || scrollbars == 'FALSE' || scrollbars == '0' || scrollbars == 0)
   {
     doc_height = doc_height + 17;
     scrollbars = 'no';
   }
   else
   {
     scrollbars = 'yes';
   }
  }

  var winl = (screen.width - doc_width) / 2;
  var wint = (screenHeight - doc_height) / 2;

  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;

  winprops = 'height='+doc_height+',width='+doc_width+',top='+wint+',left='+winl+',scrollbars='+scroll+',status='+statusbar+',toolbar='+toolbar+',resizable';

  msgWindow=window.open(url,winName,winprops);

  if (focus == 1)
    msgWindow.focus();
  else
    msgWindow.blur();

  if (!IsEmpty (htmlText))
  {
    msgWindow.document.write (htmlText);
    msgWindow.document.close ();
  }

}

function openDMSLink_old (sLink)
{
   var win;
   var usr;
   var pwd;
   var sSecured;

   sSecured = 'true';

   usr = '';
   pwd = '';
   win = 6;

   if (sSecured == 'true')
   {
      bIsLoggedIn = GetCookie ('DMSLoggedIn');

      if (bIsLoggedIn == null ||  bIsLoggedIn != 'true')   // if not logged in before ...
      {
         // from remember me checkbox
         usr = xord(win, GetCookie ('dmsu'));
         pwd = xord(win, GetCookie ('dmsp'));
         if (IsEmpty (usr) || IsEmpty (pwd) )
         {
            SetCookie ('sLink', sLink, 0, '/', null, false);   // save link for later use
            openCenteredWindow (319, 323, 'win_login', 0, 0,0, '/include/forms/login.htm', '', true);   // get credentials
            return;
         }
      }
   }
   submitDMS (usr, pwd, sLink);   // submit with credentials. if usr/pwd blank, but successfully logged in 1st time (current session), that's fine.

}


function openDMSLink (sLink)
{
   var sUrl;
   
   sUrl = '/include/forms/login.htm?doc=' + escape (sLink);
   openCenteredWindow (319, 323, 'win_login', 0, 0,0, sUrl, '', true); 
}




function submitDMS (usr,pwd,sLink)
{
   var sUrl;

   // sUrl = "http://daytona/cyberdocs/CCIFindDocSecure.asp?__library=DOCSTEST&__formname=BCAA_GENERAL_QBE&DOCNAME=" + escape (sLink) + "&__single_doc=true&__dl=true";
   sUrl = 'http://tr7/cyberdocs/CCIFindDocSecure.asp?__library=DOCSPROD&__formname=BCAA_GENERAL_QBE&DOCNAME=' + escape (sLink) + '&__single_doc=true&__dl=true';
   // alert ('usr/pwd/link = ' + document.dmslink.userid.value+ ' / ' + document.dmslink.password.value + ' / ' + sLink);
   document.dmslink.userid.value = usr;
   document.dmslink.password.value = pwd;
   document.dmslink.action = sUrl;
   document.dmslink.submit();
}


function openLink (sLink)
{
  var sUrl;

  sLink = sLink.toLowerCase();

  if (sLink.toLowerCase().indexOf ("http:") >= 0 || sLink.toLowerCase().indexOf ("file:") >= 0 || sLink.toLowerCase().indexOf ("ftp:") >= 0)
  {
     // external link, non-DMS
	 // open in new window
     var winHeight = screen.height - 100;
	 var winWidth = screen.width - 100;
	 var winTop = 50;
	 var winLeft= 50;
	 var newWindow;

     // winprops = 'status=0,toolbar=0,menubar=0,height='+doc_height+',width='+doc_width+',top='+wint+',left='+winl+',scrollbars='+scrollbars;
	 winprops = 'height=' + winHeight + ',width='+winWidth+',top='+winTop+',left='+winLeft;
     newWindow = window.open(sLink,'',winprops);
	 newWindow.focus();
  }
}

// useful for asp.net apps
function GetElementByPartialID (sFormName, sPartialID)
{
  var elem = document.getElementById(sFormName).elements;

  if (elem == null)
    return null;

  for(var i = 0; i < elem.length; i++)
  {
    if (elem[i].name.indexOf (sPartialID) >= 0)
      return elem[i];
  }
  return null;
}


function CheckAutoForward (sAutoFwd)
{
  // if sAutoFwd isn't empty and doesn't contain '/cms/ioR.asp', then forward to specified url
  if (!IsEmpty (sAutoFwd) && sAutoFwd.toLowerCase().indexOf ('/cms/iord.asp') == -1)  // reddot hack
  {
      document.location.href=sAutoFwd;
     // alert ('forwarding to ' + sAutoFwd);
  }
}


function PopupFlashVideo (src, width, height)
{
 var url;
  if (width==null || width=='')
    width='320';
    
  if (height==null || height=='')
    height='240';
        
  url='/_System/Javascript/playvideo.htm?width='+width+'&height='+height+'&src=' + escape(src);
  
  openCenteredWindow (width, height, 'video', false, false, false, url, '', true);
}


function PopupFlashAudio (src, title)
{
  var url,width,height;

  width='460';
  height='140';
    
  url='/_System/Javascript/playaudio.htm?src=' + escape(src) + '&title=' + escape(title);
  
  openCenteredWindow (width, height, 'audio', false, false, false, url, '', true);
}


function zeroPrefix (nInput,nDigits)
{
  var i,nInputLength, nZeroes;
  var sPrefix = '';
  
  nInputLength = nInput.toString().length;
  
  if (nInputLength >= nDigits)
   return nInput;
   
  nZeroes = nDigits - nInputLength;
   
  for (i=0;i<nZeroes;i++)
  {
    sPrefix = sPrefix + '0';
  } 
  return sPrefix + nInput;
}

function getMonthString (month)
{
   var sMonth = '';

   switch (month) 
   {
    case 1: sMonth = "Jan"; break
    case 2: sMonth = "Feb"; break
    case 3: sMonth = "Mar"; break
    case 4: sMonth = "Apr"; break
    case 5: sMonth = "May"; break
    case 6: sMonth = "Jun"; break
    case 7: sMonth = "Jul"; break
    case 8: sMonth = "Aug"; break
    case 9: sMonth = "Sep"; break
    case 10: sMonth = "Oct"; break
    case 11: sMonth = "Nov"; break
    case 12: sMonth = "Dec"; break
   }
   return sMonth;
}

function getMonthNumber (month)
{
   var nMonth = 0;

   switch (month.substr(0,3).toLowerCase()) 
   {
    case "jan": nMonth = 1; break
    case "feb": nMonth = 2; break
    case "mar": nMonth = 3; break
    case "apr": nMonth = 4; break
    case "may": nMonth = 5; break
    case "jun": nMonth = 6; break
    case "jul": nMonth = 7; break
    case "aug": nMonth = 8; break
    case "sep": nMonth = 9; break
    case "oct": nMonth = 10; break
    case "nov": nMonth = 11; break
    case "dec": nMonth = 12; break
   }
   return nMonth;
}
