﻿/*  
Author : Thierry Sinassamy
Objet : WP Optimization Project
Date : August 31 2009
Purpose : To inject, dynamically, the events (onclick) related to the search for pages and the synonyms 
NB: See new CSS and HTML
*/
function insertDynamicText() {

    //Support document model
    if (document.getElementsByTagName) {

    //Variables Declaration
    
    var imgPlus = '<img src="http://images.technologyevaluation.com/whitepapers/Plus.gif" class="expand-linkSF" title="Try more searches related to this white paper !"/>';
    var imgMinus = '<img src="http://images.technologyevaluation.com/whitepapers/Minus.gif" class="expand-linkSF" title="Minimize the searches related to this white paper !"/>';
    var imgPlus1 = '<img src="http://images.technologyevaluation.com/whitepapers/Plus.gif" class="expand-link2" title="Try more searches related to this white paper !"/>';
    var imgMinus1 = '<img src="http://images.technologyevaluation.com/whitepapers/Minus.gif" class="expand-link2" title="Minimize the searches related to this white paper !"/>';
    /* Look for element div and construct an array */
    var divs = document.getElementsByTagName("div");
    var divsLength = divs.length;
    
        /*Search all the divs in the page*/
        for (var i = 0; i < divsLength; i++) {
    
        var div = divs[i];
        
        /* Enable expand /collapse only for div's tagged for this purpose : Search for hyperlinks*/
            if (div.className == "expandSearchFor") {
            
            div.className = "collapseSearchFor";
            /* Add the clickable image to expandFrame */
            var anchorTag = document.createElement("a");
            anchorTag.className = "expand-linkSF";
            /*anchorTag.href = "javascript:void(0);";*/
            anchorTag.href = "_self";
            anchorTag.innerHTML = imgPlus;

            div.parentNode.insertBefore(anchorTag, div);
            
            /*Add the event click on the image*/
            anchorTag.onclick = function() {
               
                var thisDiv = this.parentNode.getElementsByTagName("div")[0];
                if(thisDiv.className == "expandSearchFor"){
                
                    this.innerHTML = imgPlus;
                    anchorTag.title = 'Expand the frame' + div.title;
                    thisDiv.className = "collapseSearchFor";
                
                }
                else if(thisDiv.className == "collapseSearchFor"){
                
                    this.innerHTML = imgMinus;
                    anchorTag.title = 'Expand the frame' + div.title;
                    thisDiv.className = "expandSearchFor";
                }
            
            }; /* End anchorTag.onclick  */
            
            }
            
            /* Enable expand /collapse only for div's tagged for this purpose : Synonyms */
            if (div.className == "expandSynonym") {
            
            div.className = "collapseSynonym";
            /* Add the clickable image to expandFrame */
            var anchorTag = document.createElement("a");
            anchorTag.className = "expand-link2";
            /*anchorTag.href = "javascript:void(0);";*/
            anchorTag.href = "_self";
            anchorTag.innerHTML = imgPlus1;

            div.parentNode.insertBefore(anchorTag, div);
            
            /*Add the event click on the image*/
            anchorTag.onclick = function() {
               
                var thisDiv = this.parentNode.getElementsByTagName("div")[0];
                if(thisDiv.className == "expandSynonym"){
                
                    this.innerHTML = imgPlus1;
                    anchorTag.title = 'Expand the frame' + div.title;
                    thisDiv.className = "collapseSynonym";
                
                }
                else if(thisDiv.className == "collapseSynonym"){
                
                    this.innerHTML = imgMinus1;
                    anchorTag.title = 'Expand the frame' + div.title;
                    thisDiv.className = "expandSynonym";
                }
            
            }; /* End anchorTag.onclick  */
            
            
            }
        }

    }

}//End insertDynamicText

//Call function insertDynamicText
//window.onload = insertDynamicText;
insertDynamicText();

