﻿//  *****************************************************************
//  *   addLoadEvent                                                *
//  *****************************************************************
//  *   Version .01                                                 *
//  *   Ralph Garcia 3/14/06                                        *
//  *****************************************************************
//  *   allows multiple ON LOAD functions to be called              *
//  *   DO NOT DELETE ------                                        *
//  *****************************************************************
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
  	window.onload = func;
  } else {
  	window.onload = function () {
		oldonload();
		func();
	}
  }
}

//  *****************************************************************
//  *   addClass                                                    *
//  *****************************************************************
//  *   Version .01                                                 *
//  *   Ralph Garcia 3/14/06                                        *
//  *****************************************************************
//  *   Lorem Ipsum.........                                        *
//  *   this function allows you to add a class to an html selector *
//  *****************************************************************
function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

//  *****************************************************************
//  *   highlightPage                                               *
//  *****************************************************************
//  *   Version .01                                                 *
//  *   Ralph Garcia 3/14/06                                        *
//  *****************************************************************
//  *   Lorem Ipsum.........                                        *
//  *   Hilights Section Navigation on click : Behavior has been    *
//  *   completely seperated from content and presentation          *
//  *   uses function addClass created above                        *
//  *****************************************************************
addLoadEvent(highlightPage);
function highlightPage() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("nav-section")) return false;
  var nav = document.getElementById("nav-section");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++) {
    var linkurl = links[i].getAttribute("href");
    var currenturl = window.location.href;
    if (currenturl.indexOf(linkurl) != -1) {
      links[i].className = "selected";
      var linktext = links[i].lastChild.nodeValue.toLowerCase();
      document.body.setAttribute("id",linktext);
    }
  }
}

//  *****************************************************************
//  *   prepare_parent_links                                        *
//  *****************************************************************
//  *   Version .01                                                 *
//  *****************************************************************
//  *   Standards-friendly pop up window                            *
//  *   Get links that match class="open_in_child" and on click     *
//  *   open the link in a new window.                              *
//  *****************************************************************
function prepare_parent_links() {
if( !document.getElementsByTagName ) return false;
	var links = document.getElementsByTagName( 'a' );
	for( var i = 0; i < links.length; i++ ) {
		if ( links[i].className.match( 'open_in_child' ) ) { 
			links[i].onclick = function() {
				open_in_child( this.getAttribute( 'href' ) );
				return false;
			}
		}
	}
}

//  ****************************************************************
//  *   open_in_parent                                              *
//  *****************************************************************
//  *   Version .01                                                 *
//  *****************************************************************
//  *   Lorem Ipsum...                                              *
//  *****************************************************************
function open_in_parent( url ) {
	opener.location.href = url;
	if ( window.focus ) {
		opener.focus();
	}
	return false;
}

//  *****************************************************************
//  *   open_in_child                                               *
//  *****************************************************************
//  *   Version .01                                                 *
//  *****************************************************************
//  *   Lorem Ipsum...                                              *
//  *****************************************************************
function open_in_child( url ) {
	window.name = 'parent';
	newwindow = window.open( url, 'child' );
	if ( window.focus ) {
		newwindow.focus();
	}
	return false;
}


//  *****************************************************************
//  *   prepare_child_links                                         *
//  *****************************************************************
//  *   Version .01                                                 *
//  *****************************************************************
//  *   Load in parent window and close current window              *
//  *   Get links that match class="open_in_parent" and on click    *
//  *   open the link in the parent window and close itself.        *
//  *****************************************************************
function prepare_child_links() {
if( !document.getElementsByTagName ) return false;
	var links = document.getElementsByTagName( 'a' );
	for( var i = 0; i < links.length; i++ ) {
		if ( links[i].className.match( 'open_in_parent' ) ) { 
			links[i].onclick = function() {
				open_in_parent( this.getAttribute( 'href' ) );
				return false;
			}
		}
	}
}

//  *****************************************************************
//  *   Toggle                                                      *
//  *****************************************************************
//  *   Version .01                                                 *
//  *****************************************************************
//  *   Generic toggle function.  Pass element ID and off it goes!  *
//  *****************************************************************
function toggle(obj) 
{
    // Virus detail page patch.
    // We had to toggle all cards off before displaying any of the cards.
    // Otherwise they would overlap eachother.

 if (obj == "threat-type" || obj == "threat-subtype" || obj == "threat-date" || obj == "threat-length" || obj == "threat-minimum-dat" || obj == "threat-update-dat" || obj == "threat-minimum-engine" || obj == "threat-description-added" || obj == "threat-description-modified" || obj == "glossary-type" || obj == "glossary-impact" || obj == "glossary-user-interaction" || obj == "glossary-attack-vendor" || obj == "glossary-rating" || obj == "glossary-cve" || obj == "glossary-vendor-status" || obj == "glossary-systems"|| obj == "glossary-summary")

 {
        closeCards(obj);
    }   
    if ( obj == "threat1" || obj == "threat2" || obj == "threat3" || obj == "threat4" || obj == "threat5")
    {
        document.getElementById("legend").style.display="none";
        document.getElementById("legend-outbreak").style.display="none";
        document.getElementById("legend-vulnerability").style.display="none";
        document.getElementById("legend-pups").style.display="none";
		document.getElementById("legend-learnmore").style.display="none";
    }
    var el = document.getElementById(obj);

	el.style.display = (el.style.display != 'none' ? 'none' : 'block' );
}



function closeCards(obj)

{

/*if(obj.substring(0,6)=="threat")
{
    var myCards = new Array("threat-type","threat-subtype","threat-date","threat-length","threat-minimum-dat","threat-update-dat","threat-minimum-engine","threat-description-added","threat-description-modified");

}
else
{
var myCards= new Array( "glossary-type","glossary-impact","glossary-user-interaction", "glossary-attack-vendor","glossary-rating","glossary-cve","glossary-vendor-status","glossary-systems", "glossary-summary");	

}

var x,y;
    for ( x in myCards)
    {
        document.getElementById(myCards[x]).style.display="none";
    }*/

document.getElementById(obj).style.display="none";
}


//  *****************************************************************
//  *   Toggle                                                      *
//  *****************************************************************
//  *   Version .01                                                 *
//  *****************************************************************
//  *   Get links that match class="toggle" and on click call       *
//  *   function toggleElement().                                   *
//  *   This function is executed on the pageload event.            *
//  ***************************************************************** 
addLoadEvent(prepareToggle)
function prepareToggle() {
if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
	if (links[i].className.match("toggle")) {
			links[i].onmouseover = function() {
			var eD = this.getAttribute("href").split("#")[1];
			var t = GetTop(this) + 15 + 'px';
			//alert(t);
			moveY(eD, t);
			toggleElement(this);
			return false;
			}
			links[i].onmouseout = function() {
			closeCards(toggleElement1(this));
			return false;
			}
		}
	}
}

//  *****************************************************************
//  *   oggleElement                                                *
//  *****************************************************************
//  *   Version .01                                                 *
//  *****************************************************************
//  *   Toggle wrapper.                                             *
//  *****************************************************************
function toggleElement(link) {
	var elementID = link.getAttribute("href").split("#")[1];
    toggle(elementID);
}

function toggleElement1(link) {
	var elementID = link.getAttribute("href").split("#")[1];
return elementID;
}

function moveY(obj, pos){
    if(document.getElementById){
        var elem = document.getElementById(obj);
        elem.style.top = pos;
    }
}
function GetTop(ele)
{
	if (ele.offsetParent)
		return (ele.offsetTop + GetTop(ele.offsetParent));
	else
		return (ele.offsetTop);
}
	
function GetLeft(ele)
{
	if (ele.offsetParent)
		return ele.offsetLeft + GetLeft(ele.offsetParent);
	else
		return ele.offsetLeft;
}