/*
    Suckerfish drop downs
*/
sfHover = function() {
    var sfEls = document.getElementById("navigation").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : 
    oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}
/* function to show tooltip */
function showTooltip(objTipContainer) {
    
    var arrTooltips = getElementsByClassName(objTipContainer, "div", "infotext");
    var arrImage = getElementsByClassName(objTipContainer, "img", "imgicon");;
    var intTipCount = arrTooltips.length;
    var intX;
    var intY;
    var intTipWidth;
    
    for (i=0; i<intTipCount;i++)
    { 
        
         it = arrTooltips[i];
    
        
        intTipWidth = it.offsetWidth;
        
        
        if ((it.style.top == '' || it.style.top == 0) 
            && (it.style.left == '' || it.style.left == 0))
        {
            
            arrPos = findPos(arrImage[i]);
            
            intX = arrPos[0];
            intY = arrPos[1];
            
            img = arrImage[i];            
            if (intX + intTipWidth > window.innerWidth)
            {
                it.style.left = '-340px';
            }
            it.style.top = '5px';
            
        }
        it.style.display = "block";
        
        
        
        
        
        
        
    
    }
    
}
/* function to hide tooltip */
function hideTooltip(objTipContainer) {
    
    var arrTooltips = getElementsByClassName(objTipContainer, "div", "infotext");
    var intTipCount = arrTooltips.length;
    
    for (i=0; i<intTipCount;i++)
    {         
    
        arrTooltips[i].style.display = "none";        
    }
    
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}
/* change active tab area on homepage */
function changeTab(theTab, thesection)
{
    // turn off all tabs for the current section
    if (thesection == "areaone") {
        document.getElementById("researchtab").src = document.getElementById("researchtab").src.replace(/_r(\.[^.]+)$/, '$1');
        document.getElementById("eventstab").src = document.getElementById("eventstab").src.replace(/_r(\.[^.]+)$/, '$1');
        
    } else {
        document.getElementById("presstab").src = document.getElementById("presstab").src.replace(/_r(\.[^.]+)$/, '$1');
        document.getElementById("coveragetab").src = document.getElementById("coveragetab").src.replace(/_r(\.[^.]+)$/, '$1');
    }
    // turn on current tab image
    var theImageID = theTab + "tab";
    var theImage = document.getElementById(theImageID);
    
    if (theImage.src.indexOf('_r.') == -1) {
        theImage.src = theImage.src.replace(/(\.[^.]+)$/, '_r$1');
    } 
    // turn off all tab areas for section
    // turn off all tabs for the current section
    if (thesection == "areaone") {
        document.getElementById("researchtabarea").style.display  = "none";
        document.getElementById("eventstabarea").style.display  = "none";
        
    } else {
        document.getElementById("presstabarea").style.display  = "none";
        document.getElementById("coveragetabarea").style.display  = "none";
    }
    
    
    
    // swap visible tab content areas
    var theTabAreaID = theTab + "tabarea";
    var theTabArea = document.getElementById(theTabAreaID);
    theTabArea.style.display = "block";
}

/*
    print function
*/
function printit(){
    if (window.print) {
        window.print() ;
    } else {
        alert('Please use the print feature of your browser.');
    }
} 
/*
    Empty form fields
*/
function clearText(objField){
    if (objField.defaultValue==objField.value)
    objField.value = ""
}

/*
    initialize pagenav areas
*/
function initPageNav(blnClear, strDefaultID)
{
    
    var arrPageAreas = getElementsByClassName(document.getElementById("primary"), "div", "pageblock");
    var intPageCount = arrPageAreas.length;
    for (i=0; i<intPageCount;i++)
    {         
        arrPageAreas[i].style.display = "none";        
    }
    
    if (blnClear == false && strDefaultID)
    {
        document.getElementById(strDefaultID).style.display = "block";    
    }
}
/*
    initialize report description page
*/
function showDetail(strArea)
{
    
    initPageNav();
    document.getElementById(strArea).style.display = "block";    
                        
}



function validate(theForm)
    {
    var returnFlag;
    var frmLength;
    var firstBlank;
    var strEmailAddress;
    var strMessage;
        
    var arrReqFields = getElementsByClassName(document.getElementById(theForm.id), "*", "required");
    
    strMessage = "Please complete all required fields.";
    firstBlank = -1;
    
    // loop through fields to clear out default values
    frmLength = arrReqFields.length;
    
    for (i=0; i<frmLength;i++){ 
        if(arrReqFields[i].value == "")
        {
            
            arrReqFields[i].className = "required warning";
            returnFlag = false;
            if(firstBlank == -1) {
                firstBlank = i;
            }
        }
        else if(arrReqFields[i].name == "email") {
            strEmailAddress = arrReqFields[i].value;
            intAtPosition = strEmailAddress.indexOf("@");
            intLastDotPosition = strEmailAddress.lastIndexOf(".");
            if((strEmailAddress=="") || (intAtPosition == 0) || (intAtPosition == 1) || (intLastDotPosition == -1) || (intAtPosition > intLastDotPosition) || (intLastDotPosition+1 == strEmailAddress.length)){
                arrReqFields[i].className = "required warning";
                returnFlag = false;
                if(firstBlank == -1) {
                    firstBlank = i;
                    strMessage = "Please enter a valid email address";
                    
                }
            }
        }
        else {
            arrReqFields[i].className = "required";
        }
    }
        
    var arrReqSelect = getElementsByClassName(document.getElementById(theForm.id), "*", "requiredselect");
    // loop through fields to clear out default values
    frmLength = arrReqSelect.length;    
    for (i=0; i<frmLength;i++){     
         if(arrReqSelect[i].value == "") {
             if((arrReqSelect[i].options[arrReqSelect[i].selectedIndex].text == "") || arrReqSelect[i].options[arrReqSelect[i].selectedIndex].text.indexOf("--") >= 0) {
                 arrReqSelect[i].className = "requiredselect warning";
                if(firstBlank == -1) {
                    firstBlank = 0;
                }
                returnFlag = false;
             } else {
                 arrReqSelect[i].className = "requiredselect";
             }
         }    
    }

    if(returnFlag == false)
        {
            alert(strMessage);
            arrReqFields[firstBlank].focus()
        }
        
    return returnFlag;
    }
 

function validatelogin(theForm)
    {
    var returnFlag;
    var frmLength;
    var firstBlank;
    var strEmailAddress;
    var strMessage;
        
    var arrReqFields = getElementsByClassName(document.getElementById(theForm.id), "*", "requiredlogin");
    
    strMessage = "Please complete all required fields."
    firstBlank = -1;
    
    // loop through fields to clear out default values
    frmLength = arrReqFields.length;
    
    for (i=0; i<frmLength;i++){ 
        if(arrReqFields[i].value == "")
        {
            
            arrReqFields[i].className = "requiredlogin warning";
            returnFlag = false;
            if(firstBlank == -1) {
                firstBlank = i
            }
        }
        else if(arrReqFields[i].name == "email") {
            strEmailAddress = arrReqFields[i].value;
            intAtPosition = strEmailAddress.indexOf("@");
            intLastDotPosition = strEmailAddress.lastIndexOf(".");
            if((strEmailAddress=="") || (intAtPosition == 0) || (intAtPosition == 1) || (intLastDotPosition == -1) || (intAtPosition > intLastDotPosition) || (intLastDotPosition+1 == strEmailAddress.length)){
                arrReqFields[i].className = "required warning";
                returnFlag = false;
                if(firstBlank == -1) {
                    firstBlank = i;
                    strMessage = "Please enter a valid email address";
                    
                }
            }
        }
        else {
            arrReqFields[i].className = "requiredlogin";
        }
    }
                
    if(returnFlag == false)
        {
            alert(strMessage);
            arrReqFields[firstBlank].focus()
        }
        
    return returnFlag;
    }

/* my displaysearch report display */

function collapseReportsAll(strOpenClosed)
{
    var arrDivs = getElementsByClassName(document.getElementById("primary"), "div", "collapsearea");
    var intDivCount = arrDivs.length;
    for (i=0; i<intDivCount;i++)
    {         
        if (strOpenClosed.indexOf("open") >= 0)
        {
            arrDivs[i].className = "collapsearea collapseopen"; 
        } else
        {
            arrDivs[i].className = "collapsearea collapseclosed"; 
        }
    }
    
}
function collapseReports(theLink)
{
    var theDiv = theLink.parentNode.parentNode;
    
    
    if (theDiv.className.indexOf("open") >= 0)
    {
        theDiv.className = "collapsearea collapseclosed";
    } else {
        theDiv.className = "collapsearea collapseopen";
    }
}
