﻿var rowHeights=new Array();
var currentSlide=1;
var timeOut=5000; //used to hold the time lapse for the timer function
var timer; //variable to be used for the setTimeout call
var timerToggle="off"; //used for toggle between start/stop (on/off) for timer function

function showMenu(currentMenu)
{
	var page=parseURLPage();
	
	switch (page)
	{
		case "aboutus": 
			document.getElementById("liAboutUs").className="selected"
			break;
		case "professional":
		case "hostedmanaged":
		case "cabling":
		case "services": 
			document.getElementById("liServices").className="selected"
			break;
		case "ciscoservices":
		case "partners": 
			document.getElementById("liPartners").className="selected"
			break;
		case "pressreleases":
		case "pressreleasedetails":
		case "pressreleasesedit":
		case "events":
		case "eventdetails":
		case "eventedit":
		case "news":
			document.getElementById("liNews").className="selected"
			break;
		case "supportticket": 
		case "supportticketattachment": 
		case "supportticketconfirmation": 
		case "support": 
			document.getElementById("liSupport").className="selected"
			break;
		case "careers":
		case "uploadresume":
		case "contactus":
			document.getElementById("liContactUs").className="selected"
			break;
		default:
			document.getElementById("liHome").className="selected"
			break;
	}
	showSubMenu(currentMenu);
}

function showSubMenu(currentMenu)
{
	var page=parseURLPage();
	var subMenu=document.getElementById('subMenu');
	var baseURL="";
	
	if (window.location.pathname.toLowerCase().indexOf("admin/")>0 || window.location.pathname.toLowerCase().indexOf("isitpossible/")>0)
		baseURL="../";
	if (window.location.pathname.toLowerCase().indexOf("training/voip/")>0)
		baseURL="../../";
	if (currentMenu!=null) 
		page=currentMenu;
	switch (page)
	{
		case "professional":
		case "hostedmanaged":
		case "cabling":
		case "services": 
			subMenu.innerHTML="<li style=\"padding-left: 263px\" id=\"liProfessional\"><a href=\""+baseURL+"Professional.aspx\">PROFESSIONAL</a></li>";
			subMenu.innerHTML+="<li id=\"liHostedManaged\"><a href=\""+baseURL+"HostedManaged.aspx\">HOSTED AND MANAGED</a></li>";
			subMenu.innerHTML+="<li id=\"liCabling\"><a href=\""+baseURL+"Cabling.aspx\">CABLING</a></li>";
			highlightSubMenu(currentMenu);
			break;
		case "webmail":
		case "support":
			subMenu.innerHTML="<li style=\"padding-left: 541px\" id=\"liWebmail\"><a href=\"http://mail.varay.net\" target=\"_blank\">WEB MAIL LOGIN</a></li>";
			highlightSubMenu(currentMenu);
			break;
		case "careers":
		case "contactus":
			subMenu.innerHTML="<li style=\"padding-left: 637px\" id=\"liCareers\"><a href=\""+baseURL+"Careers.aspx\">CAREERS</a></li>";
			highlightSubMenu(currentMenu);
			break;
		default:
			subMenu.innerHTML="";
	}
}

function highlightSubMenu(currentMenu)
{
	var page=parseURLPage();
	var subMenu=document.getElementById('subMenu');
	
	if (currentMenu!=null) 
		page=currentMenu;
	switch (page)
	{
		case "professional":
			document.getElementById("liProfessional").className="selected";
			break;
		case "hostedmanaged":
			document.getElementById("liHostedManaged").className="selected";
			break;
		case "cabling":
			document.getElementById("liCabling").className="selected";
			break;
		case "pressreleasedetails":
		case "pressreleaseedit":
		case "pressreleases":
			document.getElementById("liPressReleases").className="selected";
			break;
		case "eventdetails":
		case "eventedit":
		case "events":
			document.getElementById("liEvents").className="selected";
			break;
		case "careers":
			document.getElementById("liCareers").className="selected";
			break;
	}
	
}

function parseURLPage()
{
	var url;
	var urlArray;
	
	urlArray=window.location.pathname.split(".aspx");
	url=urlArray[0];
	if (url.toLowerCase().indexOf("isitpossible")>0)
		return "hostedmanaged";
	if (url.toLowerCase().indexOf("voip")>0)
		return "services";
	urlArray=url.split("/");
	url=urlArray[urlArray.length-1];
	return url.toLowerCase();
}

function startSlideShow()
{
	if (navigator.appName=="Microsoft Internet Explorer")
	  	document.getElementById("image").style.filter="alpha(opacity=0";
	if (navigator.appName=="Netscape")
	   document.getElementById("image").style.MozOpacity=0;
	imageRotator();
}

/************************************************************
	randomImageGenerator()
		- helper function that generates a cateory and image number
	Preconditions:
		- Make sure to have a number>0 as a random category
		- make sure to have a number-1 as a random number within category
	Postconditions:
		- create a random number within the categories available
		- within that category, create a number within that particular category
		- When both gotten, run randomImage(randCat, randNum)
************************************************************/ 
function imageRotator()
{
	var imageSlide=document.getElementById("imageSlide");
	
	if (currentSlide==3)
		currentSlide=1;
	else
  		currentSlide++;
  	imageSlide.src="Images/PartnerLogos"+currentSlide+".jpg";
}

/************************************************************
	faceImage(i, direction)
  		- fade an image in and out
  	Parameters:
  		- i
    		- amount of frames to fade an image
			- starts at 20 and decrements for fade out
			- starts at 0 and increments for face in
  	Preconditions:
  		- Assuming that browser is only IE, Mozilla, or Netscape
    	- 0<i<(determined amount of frames)
  	Postconditions:
  		- if started fadeOutImage loop
			- fade out image i-- at a time until i=0
			- if i==0, call randomImgeGenerator()
		- if started fadeInImage loop
			- fade in image i++ at a time until i=20
			- if i==20, put a 3	zsec delay, then call fadeOutImage
************************************************************/
function fadeImage(i, direction)
{
	var delay;
	var fadeDelay=3000;
	var fadeSpeed=2;
	var numFrames=40;

	if (navigator.appName=="Microsoft Internet Explorer")
	  	document.getElementById("imageSlide").style.filter="alpha(opacity="+(i/numFrames)*100+")";
	if (navigator.appName=="Netscape")
	   document.getElementById("imageSlide").style.MozOpacity=i/(numFrames+".001");
	if (direction=="out")
	{
		if (i==0)
			imageRotator();
		else
			delay=setTimeout("fadeImage("+(i-1)+", 'out')", fadeSpeed);
	}
	if (direction=="in")
	{	
		if (i==numFrames)
			timer=setTimeout("fadeImage("+numFrames+", 'out')", fadeDelay);
		else
			delay=setTimeout("fadeImage("+(i+1)+", 'in')", fadeSpeed);
	}
}

function setLoginCursor(usernameID, passwordID)
{
	var username=document.getElementById(usernameID);
	var password=document.getElementById(passwordID);
	if (username.value.length>0)
		password.focus();
	else
		username.focus();
}

function setHeight()
{
	var row;
	
	for(var i=0; i<arguments.length; i++)
	{
		row=document.getElementById(arguments[i]);
		row.style.display="block";
		row.style.overflow="hidden";
		rowHeights[arguments[i]]=row.offsetHeight;
		row.style.height=1+"px";
	}
}

function dud()
{
	return;
}

function expandRow(documentID, direction, height)
{
	var row=document.getElementById(documentID);
	
	switch (direction)
	{
		case "show":
			height+=10;
			row.style.height=height+"px";
			if (height<=rowHeights[documentID])
				setTimeout("expandRow('"+documentID+"', '"+direction+"', "+height+")", 15);
			else
			{
				row.style.height=rowHeights[documentID]+"px";
				return;
			}
			break;
		case "hide":
			height-=10;
			row.style.height=height+"px";
			if (height>10)
				setTimeout("expandRow('"+documentID+"', '"+direction+"', "+height+")", 15);
			else
			{
				row.style.height=1+"px";
				return;
			}
			break;
	}
}

function toggleDetails(documentID, type)
{
	var showDocument=document.getElementById(documentID);
	
	if (arguments.length>1)
	{
		if (arguments[1]=="expand")
		{
			if (showDocument.style.display=="none")
				setHeight(documentID);
			if (showDocument.style.height=="1px")
				expandRow(documentID, "show", 0);
			else
				expandRow(documentID, "hide", rowHeights[documentID]);
		}
	}
	else
	{
		if (showDocument.style.display=="none")
			showDocument.style.display="block";
		else
			showDocument.style.display="none";
	}
}

/**function toggleDetails(documentID)
{
	var showDocument=document.getElementById(documentID);;
	
	if (showDocument.style.display=="none")
		showDocument.style.display="block";
	else
		showDocument.style.display="none";
}*/

function showMore(documentID, linkID)
{
	var showDocument=document.getElementById(documentID);;
	var moreLink;
	
	showDocument.style.display="block";
	if (linkID!=null)
	{
		moreLink=document.getElementById(linkID);
		moreLink.style.display="none";
	}
}

function hideMore(documentID, linkID)
{
	var showDocument=document.getElementById(documentID);
	var moreLink;
	
	
	showDocument.style.display="none";
	if (linkID!=null)
	{
		moreLink=document.getElementById(linkID);
		moreLink.style.display="block";
	}
}