var W3CDOM = (document.createElement && document.getElementsByTagName);

//This was removed by Gustavo
//window.defaultStatus='American Dynamics: Video Management Solutions';

//this script stops the site from being opened in a frame
if (window != top) 
		{
			top.location.href = document.location;
		}

//for definition show and hide
var onclick = new Array();
var normal = new Array();
window.onload = init;

function init()
{
	if (!W3CDOM) return;	{
	//drop down menu
	var whichSection = null;
	initializeMenu('products', whichSection);
	initializeMenu('applications', whichSection);
	initializeMenu('support', whichSection);
	initializeMenu('whoweare', whichSection);
	
	//IP Primer Menu
	if (document.getElementById('menu-special'))
		{
			var menu = document.getElementById('menu-special');
			var litag = menu.getElementsByTagName('li');
			var menuAnchorTag = menu.getElementsByTagName('a');
			for (var i=0;i<menuAnchorTag.length;i++)
				{
				if (litag[i].id != subsection)
					{
						menuAnchorTag[i].onmouseover = over;
						menuAnchorTag[i].onmouseout = out;
						menuAnchorTag[i].number = i;
					}
				}
		}
		
	//Definition List Drop downs
	if (document.getElementById('hideandshow'))
	 	{
			var hideandshow = document.getElementById('hideandshow');
			var dlAnchorTag = getElementsByClass('hideandshow_link', 'hideandshow', 'a');
			for (var i=0;i<dlAnchorTag.length;i++)
				{
				dlAnchorTag[i].number = i;
				dlAnchorTag[i].onclick = clic;
				normal[i] = new Image;
				normal[i].src = '../images_page/icon_plus.gif';
				onclick[i] = new Image;
				onclick[i].src = '../images_page/icon_minus.gif';
				}
		}
	
	}
}

//-----------------------------------------------
// Definition list show and hide
//------------------------------------------------

function clic()
{		
		
		var hideandshow = document.getElementById('hideandshow');
		var dlAnchorTag = getElementsByClass('hideandshow_link', 'hideandshow', 'a');
		
		if (hideandshow.getElementsByTagName('dd').length > 0) //have to do the if statement because I am using this function in two places - there is most likely a better way to do this but I am very busy right now
			{
				var dlTag = hideandshow.getElementsByTagName('dd');
			}
		else
			{
				var dlTag = hideandshow.getElementsByTagName('div');
			}
		
		var dlImageTag = getElementsByClass('plusMinusIcon', 'hideandshow', 'img');
		
		var i = this.number;
		
		if (dlTag[i].className == 'hide')
			{
				dlTag[i].className = 'show';
				dlImageTag[i].src = onclick[this.number].src;
			}
		else
			{
				dlTag[i].className = 'hide';
				dlImageTag[i].src = normal[this.number].src;
			}
}

function getElementsByClass(classname, parentname, tagname)
{ 
		 var inc=0;
		 var customcollection = new Array();
		 var parent = document.getElementById(parentname); //trying to pass parentname here
		 var alltags = parent.getElementsByTagName(tagname); //trying to pass tagname here
		 //var alltags=document.all? document.all : document.getElementsByTagName("*"); 
		 for (i=0; i<alltags.length; i++){ 
		   if (alltags[i].className==classname)
		   {
			 customcollection[inc++]=alltags[i];
		   }
		 } 
		 return customcollection;
} 


/*
---------------------------------------------------------------
Intellex IP Primer Menu
---------------------------------------------------------------
*/

function over()
{
	var menu = document.getElementById('menu-special');
	var imgtag = menu.getElementsByTagName('img');
	var i = this.number;
	imgtag[i].style.display = 'inline';
}

function out()
{
	var menu = document.getElementById('menu-special');
	var imgtag = menu.getElementsByTagName('img');
	var i = this.number;
	imgtag[i].style.display = 'none';
}

/*
---------------------------------------------------------------
Menu Drop Down 
---------------------------------------------------------------
*/

var currentMenu = null;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(sectionName, sectionLit) {
    var menu = document.getElementById(sectionName + "Menu");
    var actuator = document.getElementById(sectionName + "Actuator");
	var anchorloc = document.getElementById(sectionName + "Anchor");
	var sectionlit = false
	var is = new Is(); //for browser sniffing
    
if (is.ie5||is.ie51) return;
	
    if (menu == null || actuator == null) return;

	if (sectionLit == sectionName) {
		anchorloc.className = "section_button_hover";
    }
	
	//if (window.opera) return; // I'm too tired

    actuator.onmouseover = function() {	
		this.showMenu()
		
		if (anchorloc.className == "section_button_hover") {
			sectionlit = true
		}
		else {
			anchorloc.className = "section_button_hover";
		}			
    }
	
	actuator.onmouseout = function() {
		menu.style.visibility = "hidden"
		if (!sectionlit) {
			anchorloc.className = "section_button_out";
		}
    }
  
    actuator.showMenu = function() {
		menu.style.left = DL_GetElementLeft(anchorloc) + "px";
        menu.style.top = DL_GetElementTop(anchorloc) + anchorloc.offsetHeight + "px";
        menu.style.visibility = "visible";
		currentMenu = menu;
    }

}

function DL_GetElementTop(eElement)
{
    if (!eElement && this)
    {
        eElement = this;
    }

    var nTopPos = eElement.offsetTop;
    var eParElement = eElement.offsetParent;
    while (eParElement != null)
    {
        nTopPos += eParElement.offsetTop;
        eParElement = eParElement.offsetParent;
    }
    return nTopPos;
}

function DL_GetElementLeft(eElementL)
{
    if (!eElementL && this)
    {
        eElementL = this;
    }

    var nTopPos = eElementL.offsetLeft;
    var eParElement = eElementL.offsetParent;
    while (eParElement != null)
    {
        nTopPos += eParElement.offsetLeft;
        eParElement = eParElement.offsetParent;
    }
    return nTopPos;
}

// Browser Sniffer
function Is() {
agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.ns = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1)));
this.ns4 = (this.ns && (this.major == 4));
this.ns6 = (this.ns && (this.major >= 5));
this.ie = (agent.indexOf("msie") != -1);
this.ie3 = (this.ie && (this.major < 4));
this.ie4 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0") == -1));
this.ie5 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0") != -1));
this.ie51 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.01")!=-1) );
this.ie55 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.5") != -1));
this.ie6 = (this.ie && (agent.indexOf("msie 6.0")!=-1) );
}



/*
---------------------------------------------------------------
General Site Functions 
---------------------------------------------------------------
*/

// Hide email addresses from spiders 
function writeEmail (user, domain, display1, display2) {
  var str_name = user
  var str_domain = domain
  var str_display = display1 + display2
  document.write("<a href=" + "mail" + "to:" + str_name + "@" + str_domain + ">" + str_display + "</a>")
}

function toggleDisplay(divId) {
	var toggleDiv = document.getElementById(divId);
	
	if (toggleDiv.className == "hide") {
		toggleDiv.className = "show";
	}
	else {
		toggleDiv.className = "hide";
	}
}

//script for window popup
var newWindow = null;

function popUpWin(url) {

var tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width=720,height=500,top=20,left=20";

	win = window.open("", "image", tools);
	win.document.open();
	win.document.write('<html><head><title>Image</title><meta http-equiv="imagetoolbar" content="false"></head>' +
		  '<body><img src="' + url + '"></body></html>') ;
	win.document.close();

win.focus();
}

function closeWin() {
	if (newWindow != null){
		if (!newWindow.closed) {
			newWindow.close();
		}
	}
}

//submits site search
function fnctSiteSearch() {
	if ( ! document.sitesearch.txtSearchPhrase.value) {
		alert('You did not enter any search criteria.')
		document.sitesearch.txtSearchPhrase.focus();
		}
	else	{
		document.sitesearch.submit();
	}
}


function selectmenulinks(thisselect) {
	var URL = thisselect.options[thisselect.selectedIndex].value
	if(URL!='') {
		//window.open(URL)
		//alert(URL)
		window.location = URL
	}
}
