//########SETTINGS################
//Set orientation; 2=horizontal (Top Nav); 1=vertical (Side Nav);
var iNavOrientation = 2;   
//set total number of nav elements
var NavCount = 6
//########################

var img1;
var img2;
var timerID = null;
var timerOn = false;
var tTimerID = null;
var tTimerOn = false;
var timecount = 1000;
var agent = navigator.userAgent.toLowerCase();
var isIE = false;
var isFF = false;
var isSF = false;
var iCurrPageID = "";

if (agent.indexOf('ie') > 0)
{
    isIE = true;
}
else if(agent.indexOf('firefox') > 0)
{
    isFF = true
}
else if(agent.indexOf('safari') > 0)
{
    isSF = true
}

function preloadImgs()
{
//	img1 = new Image();
//	img2 = new Image();
//	img1.src = "images/nav_yellow.gif";
//	img2.src = "images/nav_blue.gif"
}

function showNav(myObj,subID)
{
	var collRect,CollLen,coordRight,coordLeft,coordTop,coordBottom
	var subNavID = ('subNav'+subID);
	var iNavShim = 36;
	var iNavWidth = (210-iNavShim);  //width is 210 - then subtract for desired effect
    var iDiff = 0;
    var iTop = 0;
    var oDiv;
    var iShimTop = 0;
    var outsideEdge = 0;

	//change this for horiz
	if (iNavOrientation == 2)
	{
		iNavWidth=0;
		iShimTop = 25;	
	}

    iCurrPageID = document.getElementById("cNav").value;
    oDiv = document.getElementById(subNavID);

    if (isIE)
    {
	    //get coordinates of the nav
	    if(document.documentElement.scrollTop > 0)
	    {
	        //need to add
	        iShimTop = (iShimTop + document.documentElement.scrollTop);
	    }
	    collRect = myObj.getClientRects();
	    coordRight = collRect[0].right; 
	    coordLeft = collRect[0].left; 
	    coordTop = collRect[0].top; 
	    coordBottom = collRect[0].bottom; 
	    //alert("right:" + coordRight + "left:" + coordLeft + "top:" + coordTop + "bottom:" + coordBottom);
    	
	    //show the subnav to the right of the nav
	    iDiff = (coordRight-coordLeft);

	    //document.getElementById(subNavID).style.pixelLeft = (coordRight+100);
	    //need to take into acct that the text are diff lengths
	    //document.getElementById(subNavID).style.pixelLeft = (coordRight+(iNavWidth-iDiff));
	    //document.getElementById(subNavID).style.pixelTop = coordTop;
	    oDiv.style.pixelLeft = coordLeft; //(coordRight+(iNavWidth-iDiff));
	    oDiv.style.pixelTop = (coordTop+iShimTop);
    }	
    else if(isFF)
    {
        collRect = document.getBoxObjectFor(myObj);
        coordLeft = collRect.x;
        coordTop = collRect.y;
        coordRight = (coordLeft + collRect.width);
        iDiff = (coordRight-coordLeft);
        coordBottom = (coordTop + collRect.height);
               
        //coordLeft = myObj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.offsetLeft;
        
        oDiv = document.getElementById(subNavID);
        //change this for horiz
		if (iNavOrientation == 2)
		{
			oDiv.style.left = (coordLeft + "px");
			oDiv.style.top = ((coordTop + iShimTop) + "px");
		}
		else
		{
			oDiv.style.left = (((coordRight+(iNavWidth-iDiff)) + "px"));
			oDiv.style.top = (coordTop + "px");
		}
    }
    else if(isSF)
    {
        iTop = myObj.offsetParent.offsetParent.offsetParent.offsetTop
        coordLeft = (myObj.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft);
        coordRight = (myObj.offsetParent.offsetParent.offsetParent.offsetParent.offsetRight);
        coordTop = (myObj.offsetParent.offsetTop + iTop);
        iDiff = (coordRight-coordLeft);
        //document.getElementById(subNavID).style.pixelLeft = ((coordLeft+iNavWidth+iNavShim)-10);
        //document.getElementById(subNavID).style.pixelTop = coordTop;
        //change this for horiz
		if (iNavOrientation == 2)
		{
		    //coordLeft only gives me outside table to edge - need inside too
            outsideEdge = myObj.offsetParent.offsetLeft;   		
			oDiv.style.pixelLeft = (coordLeft+outsideEdge);
			oDiv.style.pixelTop = (coordTop+iShimTop);
		}
		else
		{
			oDiv.style.pixelLeft = ((coordLeft+iNavWidth+iNavShim)-10);
			oDiv.style.pixelTop = coordTop;
		}
    }    
    else
    {
        try
        {
            var iTop = myObj.offsetParent.offsetParent.offsetParent.offsetTop
            coordLeft = (myObj.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft);
            coordRight = (myObj.offsetParent.offsetParent.offsetParent.offsetParent.offsetRight);
            coordTop = (myObj.offsetParent.offsetTop + iTop);
            iDiff = (coordRight-coordLeft);
            oDiv.style.pixelLeft = ((coordLeft+iNavWidth+iNavShim)-10);
            oDiv.style.pixelTop = coordTop;
        }
        catch(err)
        {
            alert("you are using:" + agent + ", which is not currently supported");
        }
    }
	document.getElementById(subNavID).style.display = 'inline';
	//swap the nav bg
	//document.getElementById('navBg'+subID).style.background = "url(images/nav_yellow.gif)";
}

function hideNav()
{
	var subNavID;
	
	for(i=1;i<=NavCount;i++)
	{
		document.getElementById('subNav'+i).style.display = 'none';
		if(i != iCurrPageID) 
		{ 
		    //document.getElementById('navBg'+i).style.background = "url(images/nav_blue.gif)";	
	    }
	}
}

function hideSubNav(subnavID)
{
	document.getElementById('subNav'+subnavID).style.display = 'none';
	if(subnavID != iCurrPageID) 
	{ 
	    //document.getElementById('navBg'+subnavID).style.background = "url(images/nav_blue.gif)";	
    }
}

function timerSet(objID)
{
	//set timer to hide div
	if (timerOn == false) 
	{
		timerID = setTimeout("hideSubNav("+objID+")",timecount);
		timerOn = true;
	}
}

function timerReset(objID)
{
	//cancel timer to hide div
	if (timerOn) 
	{
    	clearTimeout(timerID);
        timerID = null;
        timerOn = false;
	}
}

function subOn(subID)
{
	document.getElementById('subText'+subID).className='subNavTextHot';
}

function subOff(subID)
{
	document.getElementById('subText'+subID).className='subNavText';
}

//ask experts verify
function verifyContact(){
	var errList = '';
	var bErr = false;
	var errIntro = 'Please complete the following required field(s):\n\n';
	

	if (document.getElementById("txtName").value == ''){
		errList = errList + 'Name\n';
	}
	if (document.getElementById("txtEmail").value == ''){
		errList = errList + 'E-mail\n';
	}
	if (document.getElementById("txtComments").value == ''){
		errList = errList + 'Comments\n';
	}
	//process results
	if (errList != '')
	{
		alert(errIntro + errList);
		return false;
	}
	else
	{
		document.getElementById("frmSucceed").submit();
		return true;
	}	
}

//ask experts verify
function verifyRequest(){
	var errList = '';
	var bErr = false;
	var errIntro = 'Please complete the following required field(s):\n\n';
	
	if (document.getElementById("txtName").value == ''){
		errList = errList + 'Name\n';
	}
	if (document.getElementById("txtEmail").value == ''){
		errList = errList + 'E-mail\n';
	}
	//if (document.getElementById("txtComments").value == ''){
	//	errList = errList + 'Comments\n';
	//}
	//process results
	if (errList != '')
	{
		alert(errIntro + errList);
		return false;
	}
	else
	{
		document.getElementById("frmSucceed").submit();
		return true;
	}	
}


////////////////////////
///////////////////////
function showSubNav(myObj,subID)
{
	var collRect,CollLen,coordRight,coordLeft,coordTop,coordBottom
	var subNavID = ('subTier'+subID);
	var iNavShim = 36;
	var iNavWidth = (210-iNavShim);  //width is 210 - then subtract for desired effect
    var iDiff = 0;
    var iTop = 0;
    var oDiv;
    var iShimTop = 0;
    var outsideEdge = 0;
  
    iCurrPageID = document.getElementById("cNav").value;
    oDiv = document.getElementById(subNavID);

    if (isIE)
    {
	    //get coordinates of the nav
	    if(document.documentElement.scrollTop > 0)
	    {
	        //need to add
	        iShimTop = (iShimTop + document.documentElement.scrollTop);
	    }
	    collRect = myObj.getClientRects();
	    coordRight = collRect[0].right; 
	    coordLeft = collRect[0].left; 
	    coordTop = collRect[0].top; 
	    coordBottom = collRect[0].bottom; 
	    //alert("right:" + coordRight + "left:" + coordLeft + "top:" + coordTop + "bottom:" + coordBottom);
    	
	    //show the subnav to the right of the nav
	    iDiff = (coordRight-coordLeft);

	    oDiv.style.pixelLeft = coordRight;
	    oDiv.style.pixelTop = (coordTop+iShimTop);
    }	
    else if(isFF)
    {
        collRect = document.getBoxObjectFor(myObj);
        coordLeft = collRect.x;
        coordTop = collRect.y;
        coordRight = (coordLeft + collRect.width);
        iDiff = (coordRight-coordLeft);
        coordBottom = (coordTop + collRect.height);
               
        //coordLeft = myObj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.offsetLeft;
        
        oDiv = document.getElementById(subNavID);

		oDiv.style.left = (coordRight + "px");
		oDiv.style.top = ((coordTop + iShimTop) + "px");
    }
    else if(isSF)
    {
        iTop = myObj.offsetParent.offsetParent.offsetParent.offsetTop
        coordLeft = (myObj.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft);
        coordRight = (myObj.offsetParent.offsetParent.offsetParent.offsetParent.offsetRight);
        coordTop = (myObj.offsetParent.offsetTop + iTop);
        iDiff = (coordRight-coordLeft);
	    //coordLeft only gives me outside table to edge - need inside too
        outsideEdge = myObj.offsetParent.offsetParent.offsetParent.offsetLeft;   		
        //alert(outsideEdge);
		oDiv.style.pixelLeft = (coordLeft+outsideEdge+165);
		oDiv.style.pixelTop = (coordTop+iShimTop);
    }    
    else
    {
        try
        {
            var iTop = myObj.offsetParent.offsetParent.offsetParent.offsetTop
            coordLeft = (myObj.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft);
            coordRight = (myObj.offsetParent.offsetParent.offsetParent.offsetParent.offsetRight);
            coordTop = (myObj.offsetParent.offsetTop + iTop);
            iDiff = (coordRight-coordLeft);
            oDiv.style.pixelLeft = ((coordLeft+iNavWidth+iNavShim)-10);
            oDiv.style.pixelTop = coordTop;
        }
        catch(err)
        {
            alert("you are using:" + agent + ", which is not currently supported");
        }
    }
	document.getElementById(subNavID).style.display = 'inline';
	//swap the nav bg
	//document.getElementById('navBg'+subID).style.background = "url(images/nav_yellow.gif)";
}

function tierTimerSet(objID)
{
	//set timer to hide div
	if (tTimerOn == false) 
	{
		tTimerID = setTimeout("hideTier("+objID+")",timecount);
		tTimerOn = true;
	}
}

function tierTimerReset(objID)
{
	//cancel timer to hide div
	if (tTimerOn) 
	{
    	clearTimeout(tTimerID);
        tTimerID = null;
        tTimerOn = false;
	}
}

function hideTier(subnavID)
{
	document.getElementById('subTier'+subnavID).style.display = 'none';
}



function placeScreen()
{
	var oScreen;
	oScreen = document.getElementById("movieScreen");
	oScreen.style.top = '110px';
	oScreen.style.left = (((document.getElementById("bodyID").parentNode.offsetWidth - 535) / 2) + 'px');
	oScreen.style.display = 'inline';
}

function closeScreen()
{
	var oScreen;
	oScreen = document.getElementById("movieScreen");
	oScreen.style.display = 'none';
}

function htRegister()
{
	var errList = '';
	var bErr = false;
	var errIntro = 'Please complete the following required field(s):\n\n';
	
	if (document.getElementById("txtName").value == ''){
		errList = errList + 'Name\n';
	}
	if (document.getElementById("txtEmail").value == ''){
		errList = errList + 'E-mail\n';
	}
	//process results
	if (errList != '')
	{
		alert(errIntro + errList);
		return false;
	}
	else
	{
		document.getElementById("frmSucceed").submit();
		return true;
	}	
}

function setReq()
{
	var test;
	test = 1;
}
