/*  Open a new window or replace the window content with desired specifications
 *  ****************************************************************************
 *  Needs TWO parameters;
 *  anchorHref = The script to be called.
 *  anchorRel  = All the needed parameters in one Array delimited by "|"
 *    anchorSplit[ 0 ] = Type of Call
 *                       External = Opens a New window
 *                       NewPopUp = Opens a window with special Needs
 *                                  depending on anchorSplit[ 1 ]
 *    anchorSplit[ 1 ] = Sub Type of Call
 *                       Album   = Replaces the window content with a Photo Album
 *                       Console = Opens a Console Window
 *                       Elastic = Opens a Window with Scrollbars
 *                       Fixed   = Opens a window at position 0,0 and
 *                                 all the options available ON
 *                       Format  = Opens a new window with the given options
 *                       Normal  = Opens a window at with all the options
 *                                 available ON
 *                       PopUp   = Calls the Js_callAnotherScript
 *    anchorSplit[ 2 ] = Windows name when a New Window is opened.
 *    anchorSplit[ 3 ] = New Windows's options
 *    anchorSplit[ 4 ] = Special Parameters for Specific Scripts
 *                       in one Array delimited by '@@'
 *      for ShowAlbumsIndex.php the values are;
 *          albumOptions[ 0 ] = Album Group
 *          albumOptions[ 1 ] = Album Group's Name
 *          albumOptions[ 2 ] = Path to the Script
 *          albumOptions[ 3 ] = The Script to be Executed
 *          albumOptions[ 4 ] = Script that made the call
 *          albumOptions[ 5 ] = GET Parameters
 *  ****************************************************************************
 */
function acpopup( anchorHref, anchorRel ) {
    anchorSplit   = anchorRel.split( '|' );
    anchorType    = ( anchorSplit[ 0 ] ? anchorSplit[ 0 ] : '' );
    anchorSubType = ( anchorSplit[ 1 ] ? anchorSplit[ 1 ] : '' );
    anchorWinName = ( anchorSplit[ 2 ] ? anchorSplit[ 2 ] : '' );
    anchorOptions = ( anchorSplit[ 3 ] ? anchorSplit[ 3 ] : '' );
    if  ( anchorOptions == '' ) {
        anchorOptions = 'hotkeys=0,location=0,menubar=0,scrollbars=1,height=20,width=20,screenX=0,screenY=0';
    } //if
    if  ( anchorType == 'NewPopUp' ) {
        if  ( anchorSubType == 'PopUp' ) {
            Js_callAnotherScript( anchorHref,         // theLink
                                  'LinkInternalOpen', // theType
                                  '',                 // theParams
                                  anchorOptions,      // theOptions
                                  anchorWinName,      // theName
                                  'Normal'            // theForm
                                );
            return false;
        } else if  ( anchorSubType == 'Submit' ) {
            submitOptions = anchorSplit[ 4 ].split( '@@' );
            Params = submitOptions[ 1 ];
            document.getElementById( 'MyForm' ).Update.value = 'Start';
            document.getElementById( 'MyForm' ).fromPath.value = submitOptions[ 2 ];
            document.getElementById( 'MyForm' ).fromProg.value = submitOptions[ 3 ];
            document.getElementById( 'MyForm' ).method = 'post';
            document.getElementById( 'MyForm' ).action = submitOptions[ 0 ] + submitOptions[ 1 ];
            document.getElementById( 'MyForm' ).submit( );
            return false;
        } else {
            albumOptions = anchorSplit[ 4 ].split( '@@' );
            document.getElementById( 'MyForm' ).AlbumGroup.value     = albumOptions[ 0 ];
            document.getElementById( 'MyForm' ).AlbumGroupName.value = albumOptions[ 1 ];
            document.getElementById( 'MyForm' ).fromPath.value       = 'linkPath';
            document.getElementById( 'MyForm' ).fromProg.value       = albumOptions[ 4 ];
            mainClassParams = ( albumOptions[ 5 ] ? '?' + albumOptions[ 5 ] : '' );
            mainClassWindow = albumOptions[ 2 ] + albumOptions[ 3 ] + mainClassParams;
            document.getElementById( 'MyForm' ).method = 'post';
            document.getElementById( 'MyForm' ).action = mainClassWindow;
            document.getElementById( 'MyForm' ).submit( );
            return false;
        } //if
    } else {
        switch ( anchorSubType ) {
            case 'Console': //  Popup like a Console Window
                anchorOptions = 'hotkeys=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no';
                break;
            case 'Elastic': //  Popup like a Console Window and Scrollbars
                anchorOptions = 'hotkeys=no,location=no,menubar=no,resizable=no,scrollbars=1,status=no';
                break;
            case 'Fixed':   //  Popup like a Normal Window and positioned Top Left
                anchorOptions = 'left=0,top=0,hotkeys=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1';
                break;
            case 'Normal':  //  Popup like a Normal Window
                anchorOptions = 'hotkeys=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1';
                break;
        } //switch
        window.open( anchorHref, anchorWinName, anchorOptions );
    } //if
} // End of the function acpopup


/*  External links creation
 *  ****************************************************************************
 *  To comply with the W3C standards thru this function, you avoid the use of
 *  DEPRECATED HTML attribute TARGET.
 *  This is MY version, adaptted to MY needs.
 *  To se the original script go to http://www.sitepoint.com/article/1041.
 *  ****************************************************************************
 */
function windowLinks( ) {
    if  ( !document.getElementsByTagName ) {
        return;
    } //if
    var theAnchors = document.getElementsByTagName( 'a' );
    for ( idx = 0; idx < theAnchors.length; idx++ ) {
        thisAnchor     = theAnchors[ idx ];
        thisAnchorId   = theAnchors[ idx ].id;
        thisAnchorHref = theAnchors[ idx ].href;
        if  ( theAnchors[ idx ].rel == 'undefined' ||
              theAnchors[ idx ].rel == ''             ) {
            continue;
        } //if
        thisAnchorRel = theAnchors[ idx ].rel;
        anchorSplit   = thisAnchorRel.split( '|' );
        if  ( anchorSplit[ 0 ] == 'No' ||
              anchorSplit[ 0 ] == ''      ) {
            continue;
        } //if
        if  ( anchorSplit[ 0 ] == 'External' ||
              anchorSplit[ 0 ] == 'NewPopUp'    ) { // XHTML compliant target attribute
            theAnchors[ idx ].target  = '_blank';
            theAnchors[ idx ].title   = '';
            theAnchors[ idx ].onclick = function() { acpopup( this.href, this.rel ); return false; };
            continue;
        } else if ( anchorSplit[ 0 ] == 'NoTitles' ) { // Just get rid of the Title of the anchor
            theAnchors[ idx ].title  = '';
            continue;
        } //if
    } //for
    var forms = document.getElementsByTagName( 'form' );
    for ( var i = 0; i < forms.length; i++ ) {
        var thisForm = forms[ i ];
        if  ( thisForm.getAttribute( 'rel' ) == 'External' ) {
            thisForm.target = '_blank';
        } //if
    } //for
    return false;
} // End of the function windowLinks


var BlinkTimers  = 2000;
var BlinkSwitch  = 1;
var BlinkHowMany = 0;
var BlinkArray   = new Array( );


function InitTheBlinking( ThisBrowser ) {
    if  ( !document.getElementsByTagName ) {
        return;
    } //if
    var AllThePar = document.getElementsByTagName( 'td' );                      // GET all the Table Cells within the page //
    for ( var i = 0; i < AllThePar.length; i++ ) {
        var ThisPar       = AllThePar[ i ];                                     // GET this Table Cells //
        var ThisClassAttr = ThisPar.attributes;                                 // GET this Table Cells class //
        for ( var j = 0; j < ThisClassAttr.length; j++ ) {
            var ThisClassAttrName = ThisClassAttr[j].nodeName;
            if  ( ThisClassAttrName && ( ThisClassAttrName == 'class' ) ) {     // IF this Table Cells HAS a class //
                ThisClassValue = ThisClassAttr[j].value;
                HasMakeItBlink = false;
                var ThisClassValueSplit = ThisClassValue.split( ' ' );          // SPLIT this Table Cells class to get their Values //
                for ( var k = 0; k < ThisClassValueSplit.length; k++ ) {
                    if  ( ThisClassValueSplit[ k ] == 'txtBlink' ) {            // Is this class Value txtBlink //
                        HasMakeItBlink = true;
                        if  ( ThisBrowser != 'FI' ) {                           // IExplorer DOES NOT accept blink specification //
                            BlinkName                  = 'BlinkThis' + BlinkHowMany;
                            BlinkArray[ BlinkHowMany ] = BlinkName;
                            ThisPar.id                 = BlinkName;
                            BlinkHowMany++;
                        } else {
                            ThisClassValueSplit[ k ] = 'BlinkText';             // Change to BlinkText (Defined in User's CSS) //
                        } //if
                    } //if
                } //for
                if  ( HasMakeItBlink ) {
                    var ThisClass = '';
                    for ( var k = 0; k < ThisClassValueSplit.length; k++ ) {    // Rebuild the Table Cells class values //
                        ThisClass = ThisClass + ThisClassValueSplit[ k ] + ' ';
                    } //for
                    ThisClassAttr[j].value = ThisClass;
                } //if
            } //if
        } //for
    } //for
    var AllThePar = document.getElementsByTagName( 'p' );                       // GET all the Paragraph within the page //
    for ( var i = 0; i < AllThePar.length; i++ ) {
        var ThisPar       = AllThePar[ i ];                                     // GET this Paragraph //
        var ThisClassAttr = ThisPar.attributes;                                 // GET this Paragraph class //
        for ( var j = 0; j < ThisClassAttr.length; j++ ) {
            var ThisClassAttrName = ThisClassAttr[j].nodeName;
            if  ( ThisClassAttrName && ( ThisClassAttrName == 'class' ) ) {     // IF this Paragraph HAS a class //
                ThisClassValue = ThisClassAttr[j].value;
                HasMakeItBlink = false;
                var ThisClassValueSplit = ThisClassValue.split( ' ' );          // SPLIT this Paragraph class to get their Values //
                for ( var k = 0; k < ThisClassValueSplit.length; k++ ) {
                    if  ( ThisClassValueSplit[ k ] == 'txtBlink' ) {            // Is this class Value txtBlink //
                        HasMakeItBlink = true;
                        if  ( ThisBrowser != 'FI' ) {                           // IExplorer DOES NOT accept blink specification //
                            BlinkName                  = 'BlinkThis' + BlinkHowMany;
                            BlinkArray[ BlinkHowMany ] = BlinkName;
                            ThisPar.id                 = BlinkName;
                            BlinkHowMany++;
                        } else {
                            ThisClassValueSplit[ k ] = 'BlinkText';             // Change to BlinkText (Defined in User's CSS) //
                        } //if
                    } //if
                } //for
                if  ( HasMakeItBlink ) {
                    var ThisClass = '';
                    for ( var k = 0; k < ThisClassValueSplit.length; k++ ) {    // Rebuild the Paragraph class values //
                        ThisClass = ThisClass + ThisClassValueSplit[ k ] + ' ';
                    } //for
                    ThisClassAttr[j].value = ThisClass;
                } //if
            } //if
        } //for
    } //for
} // End of the function InitTheBlinking


function MakeItBlink( ) {
    for ( var i = 0; i < BlinkHowMany; i++ ) {
        if  ( BlinkSwitch == 1 ) {
            document.getElementById( BlinkArray[ i ] ).style.visibility = 'visible';
        } else {
            document.getElementById( BlinkArray[ i ] ).style.visibility = 'hidden';
        } //if
    } //for
    if  ( BlinkSwitch == 1 ) {
        BlinkSwitch = 0;
    } else {
        BlinkSwitch = 1;
    } //if
    setTimeout( 'MakeItBlink( )', BlinkTimers );
} // End of the function MakeItBlink


/*  Standarize Autocomplete Attribute.
 *  ****************************************************************************
 *  To comply with the W3C standards thru this function, you avoid the use of
 *  DEPRECATED HTML attribute Autocomplete.
 *  This is MY version, adaptted to MY needs.
 *  ****************************************************************************
 */
function makeAutocomplete( ) {
    if  ( !document.getElementsByTagName ) {
        return;
    } //if
    var theInputs = document.getElementsByTagName( 'input' );
    var theAutoCount = 0;
    for ( idx = 0; idx < theInputs.length; idx++ ) {
        thisInput     = theInputs[ idx ];
        if  ( theInputs[ idx ].alt == 'AUTO' ) {
            theInputs[ idx ].autocomplete = 'off';
            theAutoCount                  = theAutoCount + 1;
        } //if
    } //for
    return false;
} // End of the function makeAutocomplete
