/* 
 * Copyright (C) 2008 Church of Scientology International.
 * All Rights Reserved.
 */

/**
 * Appends aAppendText to aString if it's not already there.
 * Returns a new string or the original string if no change was needed.
 */
function optionalAppendToString(aString, aAppendText) {
    
    if (!aString) {
        return aString;
    }
    
    if (aString.substr(aString.length - aAppendText.length) == aAppendText) {
        return aString;
    }
    
    return aString + aAppendText;
}

/**
 * Takes an array and makes it into an array of arrays, each single entry in
 * the outer array being an array itself with aColumns entries.  This is used
 * when you want to display a list of something in three columns in a table,
 * generally calling dwr.util.addRows() to affect this.
 */
function makeColumnArray(aArray, aColumns) {
    
    var myRet = [];
    for (var i = 0; i < aArray.length; i += aColumns) {
        
        var mySubAr = [];
        
        for (var j = 0; j < aColumns; j++) {
            var myIndex = i + j;
            if (myIndex < aArray.length) {
                mySubAr.push(aArray[myIndex]);
            }
        }
        
        myRet.push(mySubAr);
    }
    
    return myRet;
}

/**
 * Get the current time.
 */
function getCurrentTimeFormatted() {
    var curDateTime = new Date();
    var curHour = curDateTime.getHours();
    var curMin = curDateTime.getMinutes();
    var curSec = curDateTime.getSeconds();
    var curAMPM = " AM";
    var curTime = "";
    if (curHour >= 12) {
        curHour -= 12;
        curAMPM = " PM";
    }
    if (curHour == 0) curHour = 12;
    curTime = curHour + ":"
        + ((curMin < 10) ? "0" : "") + curMin + ":" 
        + ((curSec < 10) ? "0" : "") + curSec 
        + curAMPM;
    return (curTime);
}

/**
 * Examines and fixes all PNGs on the page so they work properly in IE6
 */
function fixPngs() {
    
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])

    if ((version >= 5.5) && (document.body.filters)) 
    {
       for(var i=0; i<document.images.length; i++)
       {
          var img = document.images[i]
          var imgName = img.src.toUpperCase()
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
          {
             var imgID = (img.id) ? "id='" + img.id + "' " : ""
             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
             var imgStyle = "display:inline-block;" + img.style.cssText 
             if (img.align == "left") imgStyle = "float:left;" + imgStyle
             if (img.align == "right") imgStyle = "float:right;" + imgStyle
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
             var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
             img.outerHTML = strNewHTML
             i = i-1
          }
       }
    }
    
}

//
//var acrobat=new Object();
//
//acrobat.installed=false;
//acrobat.version='0.0';
//
//if (navigator.plugins && navigator.plugins.length)
//{
//for ( var x = 0, l = navigator.plugins.length; x < l; ++x )
//{
//if (navigator.plugins[x].description.indexOf('Adobe Acrobat') != -1)
//{
//acrobat.version=parseFloat(navigator.plugins[x].description.split('Version ')[1]);
//
//if (acrobat.version.toString().length == 1) acrobat.version+='.0';
//
//acrobat.installed=true;
//break;
//}
//}
//}
//else if (window.ActiveXObject)
//{
//for (x=2; x<10; x++)
//{
//try
//{
//oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
//if (oAcro)
//{
//acrobat.installed=true;
//acrobat.version=x+'.0';
//}
//}
//catch(e) {}
//}
//
//try
//{
//oAcro4=new ActiveXObject('PDF.PdfCtrl.1');
//if (oAcro4)
//{
//acrobat.installed=true;
//acrobat.version='4.0';
//}
//}
//catch(e) {}
//
//try
//{
//oAcro7=new ActiveXObject('AcroPDF.PDF.1');
//if (oAcro7)
//{
//acrobat.installed=true;
//acrobat.version='7.0';
//}
//}
//catch(e) {}
//
//}


