// JavaScript Document

//this determines if Firefox is being use and if so set var ie=0. Var ie is set to 1 otherwise
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		}
		]
};
BrowserDetect.init();
var ie = 1;
if (BrowserDetect.browser=="Firefox") {
	ie = 0;
}

$(document).ready(function(){
// This script controls the accordion effect - other accordion files must be include via HTML - these links have been added to the footer and should be available to every page

	$('#accord1').accordion({
		header: 'h3',
		collapsible: true,
		active: false
	});
	$('#accord2').accordion({
		header: 'h3',
		collapsible: true,
		active: false
	});
	$('#accord3').accordion({
		header: 'h3',
		collapsible: true,
		active: false
	});
	$('#accord4').accordion({
		header: 'h3',
		collapsible: true,
		active: false
	});
	$('#accord5').accordion({
		header: 'h3',
		collapsible: true,
		active: false
	});
	$('#accord6').accordion({
		header: 'h3',
		collapsible: true,
		active: false
	});
		$('#accord7').accordion({
		header: 'h3',
		collapsible: true,
		active: false
	});

// This function controls the height of the four boxes on the index page
//compare box 1 and box 2 set both to longest
    if($('div.box1of4box').height() > $('div.box2of4box').height())
    {
        $('div.box2of4box').css({
            'height':$('div.box1of4box').height()
        });
    }
    else if($('div.box2of4box').height() > $('div.box1of4box').height())
    {
        $('div.box1of4box').css({
            'height':$('div.box2of4box').height()
        });
    }
		//compare box 3 and box 4 set both to longest
	if($('div.box3of4box').height() > $('div.box4of4box').height())
    {
        $('div.box4of4box').css({
            'height':$('div.box3of4box').height()
        });
    }
    else if($('div.box4of4box').height() > $('div.box3of4box').height())
    {
        $('div.box3of4box').css({
            'height':$('div.box4of4box').height()
        });
    }
	//compare box 3 (now longest of 3 and 4) to box 2 (now longest of 1 and 2) and set either to longest
	if($('div.box3of4box').height() > $('div.box2of4box').height())
    {
        $('div.box2of4box').css({
            'height':$('div.box3of4box').height()
        });
		$('div.box1of4box').css({
            'height':$('div.box3of4box').height()
        });
    }
    else if($('div.box2of4box').height() > $('div.box3of4box').height())
    {
        $('div.box3of4box').css({
            'height':$('div.box2of4box').height()
        });
		$('div.box4of4box').css({
            'height':$('div.box2of4box').height()
        });
    }
// end of function controlling height of four boxes on index page
// this assists the drop down menu
	 $('.dropdown-item').hover (function (){
		Parent=$(this).parents();
		Parent.siblings('h3').children().children().css('color' , '#000');
										 },
		function (){
		Parent=$(this).parents();
		Parent.siblings('h3').children().children().css('color' , '#FFF');
		});
	 $('.dir').hover (function (){
		$(this).css('color' , '#000')			 
		},
		function (){
			$(this).css('color' , '#FFF')
		});
// end assist of drop down menu	 
//this function makes the boxes in the two box layout the same size (actually there are four boxes - but it is called the two box layout)
 // this is for the two box gray box divs (left and right) - sets them to the longest
    if($('div.lgraybox2box').height() > $('div.rgraybox2box').height())
    {
        $('div.rgraybox2box').css({
            'height':$('div.lgraybox2box').height()
        });
	}
    else if($('div.rgraybox2box').height() > $('div.lgraybox2box').height())
    {
        $('div.lgraybox2box').css({
            'height':$('div.rgraybox2box').height()
        });
    }
	//this is for the internal divs
	//makes left internal divs the same height on the left box
	    if($('div.dashedbox1').height() > $('div.dashedboxcontain1').height())
    {
        $('div.dashedboxcontain1').css({
            'height':$('div.dashedbox1').height()
        });
    }
    else if($('div.dashedboxcontain1').height() > $('div.dashedbox1').height())
    {
        $('div.dashedbox1').css({
            'height':$('div.dashedboxcontain1').height()
        });
    }
	//this makes the right internal divs the same height
		    if($('div.dashedbox2').height() > $('div.dashedboxcontain2').height())
    {
        $('div.dashedboxcontain2').css({
            'height':$('div.dashedbox2').height()
        });
    }
    else if($('div.dashedboxcontain2').height() > $('div.dashedbox2').height())
    {
        $('div.dashedbox2').css({
            'height':$('div.dashedboxcontain2').height()
        });
    }
	//this compare the hieght of the dashedbox1 and dashedboxcontain2 and sets hieght equal to longest div
			    if($('div.dashedbox1').height() > $('div.dashedboxcontain2').height())
    {
        $('div.dashedboxcontain2').css({
            'height':$('div.dashedbox1').height()
        });
			//this makes the right internal divs the same height
		    if($('div.dashedbox2').height() > $('div.dashedboxcontain2').height())
    {
        $('div.dashedboxcontain2').css({
            'height':$('div.dashedbox2').height()
        });
    }
    else if($('div.dashedboxcontain2').height() > $('div.dashedbox2').height())
    {
        $('div.dashedbox2').css({
            'height':$('div.dashedboxcontain2').height()
        });
    }
    }
    else if($('div.dashedboxcontain2').height() > $('div.dashedbox1').height())
    {
        $('div.dashedbox1').css({
            'height':$('div.dashedboxcontain2').height()
        });
			//makes left internal divs the same height
	    if($('div.dashedbox1').height() > $('div.dashedboxcontain1').height())
    {
        $('div.dashedboxcontain1').css({
            'height':$('div.dashedbox1').height()
        });
    }
    else if($('div.dashedboxcontain1').height() > $('div.dashedbox1').height())
    {
        $('div.dashedbox1').css({
            'height':$('div.dashedboxcontain1').height()
        });
    }
    }
// end two box script	
// This is for the three box layout
// compare box 1 to box 2 - set each to longest
if($('div.box1of3box').height() > $('div.box2of3box').height())
    {
        $('div.box2of3box').css({
            'height':$('div.box1of3box').height()
        });
    }
    else if($('div.box2of3box').height() > $('div.box1of3box').height())
    {
        $('div.box1of3box').css({
            'height':$('div.box2of3box').height()
        });
    }
	//compare box 2 to box 3 - set each to longest
	if($('div.box3of3box').height() > $('div.box2of3box').height())
    {
        $('div.box2of3box').css({
            'height':$('div.box3of3box').height()
        });
    }
    else if($('div.box2of3box').height() > $('div.box3of3box').height())
    {
        $('div.box3of3box').css({
            'height':$('div.box2of3box').height()
        });
    }
	//recompare box 1 ro box 3 - set each to longest (this is in case box three is longest)
	    if($('div.box1of3box').height() > $('div.box2of3box').height())
    {
        $('div.box2of3box').css({
            'height':$('div.box1of3box').height()
        });
    }
    else if($('div.box2of3box').height() > $('div.box1of3box').height())
    {
        $('div.box1of3box').css({
            'height':$('div.box2of3box').height()
        });
    }
// end three box script
// set scrollbar to appear on ever page to fix layout jumping issues on accordion pages
if(!ie){
	$('body').css("overflow-y", "scroll");
	}
// add datepicker to resubmit form
	$("#enddate").datepicker();
});
// end accordion script
var namesVec = new Array("plus_button.png", "minus_button.png");
var root ='images/';
function swapImg(ima){
// divides the path
nr = ima.getAttribute('src').split('/');
// gets the last part of path, ie name
nr = nr[nr.length-1]
// former was .split('.')[0];
 
if(nr==namesVec[0]){ima.setAttribute('src',root+namesVec[1]);}
else{ima.setAttribute('src',root+namesVec[0]);}

}
// This function does the roll-over buttons on the index page and other pages with similar type roll-over buttons (downloads.shtml)
function changeImage(button_name, button_hover)
{
document.images[button_name].src= button_hover;
return true;
}
function changeImageBack(button_name, button_up)
{
 document.images[button_name].src = button_up;
 return true;
 
}
// end rool-over function

// These functions control the pop-up box that appears in the header.

// Moves the box object to be directly beneath an object.
// the ff denotes that this function is for Firefox
function move_box_ff(an, box)
{
    var ctop = -88;
	var cleft = 439;
	var obj = an;
    while (obj.offsetParent)
    {
        cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }

    box.style.left = cleft + 'px';

    ctop += an.offsetHeight + 8;

    // Handle Internet Explorer body margins,
    // which affect normal document, but not
    // absolute-positioned stuff.
    if (document.body.currentStyle &&
        document.body.currentStyle['marginTop'])
    {
        ctop += parseInt(
            document.body.currentStyle['marginTop']);
    }

    box.style.top = ctop + 'px';
}
// the ie denotes that this function is for ie
function move_box_ie(an, box)
{
    var ctop = -64;
	var obj = an;
	
    box.style.left = 592 + 'px';

    ctop += an.offsetHeight + 8;

    // Handle Internet Explorer body margins,
    // which affect normal document, but not
    // absolute-positioned stuff.
    if (document.body.currentStyle &&
        document.body.currentStyle['marginTop'])
    {
        ctop += parseInt(
            document.body.currentStyle['marginTop']);
    }

    box.style.top = ctop + 'px';
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_box(an, width, height, borderStyle)
{
    var href = an.href;
    var boxdiv = document.getElementById(href);

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            // Show existing box, move it
            // if document changed layout
			if (ie)
			{
            move_box_ie(an, boxdiv);
			}
			else
			{
			move_box_ff(an, boxdiv);
			}
            boxdiv.style.display='block';

            bringToFront(boxdiv);

            // Workaround for Konqueror/Safari
            if (!boxdiv.contents.contentWindow)
                boxdiv.contents.src = href;
        }
        else
            // Hide currently shown box.
            boxdiv.style.display='none';
        return false;
    }

    // Create box object through DOM
    boxdiv = document.createElement('div');

    // Assign id equalling to the document it will show
    boxdiv.setAttribute('id', href);

    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.textAlign = 'right';
    boxdiv.style.padding = '4px';
    boxdiv.style.background = '#FFFFFF';
    document.body.appendChild(boxdiv);

    var offset = 0;

    var contents = document.createElement('iframe');
	
    contents.scrolling = 'no';
    contents.overflowX = 'hidden';
    contents.overflowY = 'scroll';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';

    boxdiv.contents = contents;
    boxdiv.appendChild(contents);

	if (ie)
	{
        move_box_ie(an, boxdiv);
	}
	else
	{
		move_box_ff(an, boxdiv);
	}

    contents.src = "http://ecmps.pqa.com/popup_description.html"; // this has the full address so that the popup would be available to the search template. 

    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    return false;
}

function hide_box(an)
{
    var href = an.href;
    var boxdiv = document.getElementById(href);
	boxdiv.style.display='none';
}

function getAbsoluteDivs()
{
    var arr = new Array();
    var all_divs = document.body.getElementsByTagName("DIV");
    var j = 0;

    for (i = 0; i < all_divs.length; i++)
        if (all_divs.item(i).style.position=='absolute')
        {
            arr[j] = all_divs.item(i);
            j++;
        }

    return arr;
}

function bringToFront(obj)
{
    if (!document.getElementsByTagName)
        return;

    var divs = getAbsoluteDivs();
    var max_index = 0;
    var cur_index;

    // Compute the maximal z-index of
    // other absolute-positioned divs
    for (i = 0; i < divs.length; i++)
    {
        var item = divs[i];
        if (item == obj ||
            item.style.zIndex == '')
            continue;

        cur_index = parseInt(item.style.zIndex);
        if (max_index < cur_index)
        {
            max_index = cur_index;
        }
    }

    obj.style.zIndex = max_index + 1;
}
