/*------------------------------------------------------------------------
www.drugeruptiondata.com Global JS

version: 1.1
author: andy windle
email: aw@ama.uk.com
www.ama.uk.com
--------------------------------------------------------------------------*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function confirmRemove() {
    if (!document.getElementsByTagName) return false;
    inputs = document.getElementsByTagName('input');
    
    for (var i=0; i<inputs.length; i++){
        
         if(inputs[i].className.match("button remove")){
            inputs[i].onclick = function() {
                if (!confirm('Are you sure you wish to remove?')) return false;
                
            }
         }
    }
    
    links = document.getElementsByTagName('a');  
    
    for (var i=0; i<links.length; i++){
        
         if(links[i].className.match("buttonLink remove") || links[i].className.match("remove")){
            links[i].onclick = function() {
                if (!confirm('Are you sure you wish to remove?')) return false;
                
            }
         }
    }
} 

function getPopUps() {
    if (!document.getElementsByTagName) return false;

    var popuplinks = document.getElementsByTagName("a");

    for (var i=0; i < popuplinks.length; i++) {    

        if (popuplinks[i].className == "popup" || popuplinks[i].className == "pubmed" || popuplinks[i].className == "printLink") {
            popuplinks[i].onclick = function() {   
                openPopUp(this.getAttribute("href"),640,550);    
                return false;     
            }     
        }
        // and for closing the popup window
        if (popuplinks[i].className == "buttonLink closeWindow") {
            popuplinks[i].onclick = function() {
                window.close(this);
                return false;     
            }     
        }
    } 
} 

// Pop up windows call
function openPopUp(linkURL, width, height, resizable) {
    var popConfigs = "top=5,left=5,scrollbars=1,resizable=1, width="+width+",height="+height;
    window.open(linkURL,"popup",popConfigs)
} 

function searchHint() { 
    if (!document.getElementById) return false;
    if (!document.getElementById("f_search")) return false;
 
    var search = document.getElementById("f_search"); 
    
    //var label = 'search';
    
    //if(productSearch.value == '') productSearch.value = label;

    search.onclick = function() {

        //if(search.value == label)
            search.value = ''; 
           
        return false;   
    }   
}

function toggleTabs() {

    if (!document.getElementById) return false; 
    if (!document.getElementsByTagName) return false; 
    
    var links = document.getElementsByTagName("a"); 
    
    for (var i=0; i < links.length; i++) {  
    
        if (links[i].className == "tabLinkInner") { 
            
            links[i].onclick = function() {   
                id = this.id.substring(8);
                
                var tabContainer = document.getElementById('tabContainer-' + id);
                
                if(tabContainer.style.display = 'none')
                    tabContainer.style.display = 'block';
                else
                    tabContainer.style.display = 'block';
                
                alert(id);
                return false;     
            }
        }
    
    } 

}

$(document).ready(function() { 
       $('.tabLinkClosed').next().css('display', 'none');
});  

$(document).ready(function() {
    $('a.tabLinkInner').click(function() {
        id = this.id.substring(8);   
        
        
        if($('#tabContainer-' + id).css('display') == 'none'){
            $('#tabContainer-' + id).show('fast');   
            
            tabType = $(this).parent().attr('class');
            
            if(tabType == 'tabLink') img = 'tabClose';
            else img = 'tabOpen';  
                    
            
            $(this).parent().css('background-image', 'url(/img/' + img + '.gif)');
            
            
        }
       else { 
            //alert($('.tabLink').css('background-image'));
            tabType = $(this).parent().attr('class');
            
            if(tabType == 'tabLink') img = 'tabOpen';
            else img = 'tabClose';  
            
            $(this).parent().css('background-image', 'url(/img/' + img + '.gif)');
            
            $('#tabContainer-' + id).hide('fast');
       }
      return false;
    });
});

addLoadEvent(searchHint);
//addLoadEvent(toggleTabs);
addLoadEvent(getPopUps);
addLoadEvent(confirmRemove); 
