function toggleInfo(toggleID) {
    if (document.getElementById(toggleID)) {
        if (document.getElementById(toggleID+'-show').style.display != 'none') 
	{
            document.getElementById(toggleID+'-show').style.display = 'none';
            document.getElementById(toggleID).style.display = 'block';
        }
        else 
	{
            document.getElementById(toggleID+'-show').style.display = 'inline';
            document.getElementById(toggleID).style.display = 'none';
        }
    }
}

function popupwindow(urlID) {
	testwindow = window.open(urlID,'mywindow','location=0,status=0,scrollbars=1,width=500,height=500');
	testwindow.moveTo(150,150);
}

var browserName=navigator.appName;
if (browserName=="Netscape") {
	function closepopupwindow()
	{
		window.open('','_parent','');
		window.close();
	}
}
else {
	if (browserName=="Microsoft Internet Explorer") {
		function closepopupwindow()
		{
		window.opener = "x";
		window.close();
		}
	}
}

function ShowPopup(hoveritem,text) {
	hp = document.getElementById("mypopup");
	var topvalue = hoveritem.offsetTop;
	var leftvalue = hoveritem.offsetLeft;
	if (browserName == "Microsoft Internet Explorer") {
		topvalue += 0;
		leftvalue += 0;
		// topvalue += 160;
		// leftvalue += 360;
	}
	// hp.style.top = (topvalue - 25) + "px";
	// hp.style.left = (leftvalue + 90) + "px";
	hp.style.top = max(topvalue + 225,450) + "px";
	hp.style.left = (leftvalue + 440) + "px";
	hp.innerHTML = text;
	hp.style.visibility = "Visible";
}

function HidePopup() {
	hp = document.getElementById("mypopup");
	hp.style.visibility = "Hidden";
}

function ShowTicket(hoveritem,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) {
	hp = document.getElementById("ticketpop");
	var topvalue = hoveritem.offsetTop;
	var leftvalue = hoveritem.offsetLeft;
	if (browserName == "Microsoft Internet Explorer") {
		topvalue += 0;
		leftvalue += 0;
		// topvalue += 160;
		// leftvalue += 360;
	}
	// hp.style.top = (topvalue - 25) + "px";
	// hp.style.left = (leftvalue + 90) + "px";
	hp.style.top = (topvalue + 225) + "px";
	hp.style.left = (leftvalue + 440) + "px";
        text = "<TABLE>";
        text += "<TR><TH>Ticket&nbsp;No.</TH><TD>" + p1 + "</TD></TR>";
        text += "<TR><TH>Type</TH><TD>" + p2 + "</TD></TR>";
        text += "<TR><TH>Reported&nbsp;on</TH><TD>" + p3 + "</TD></TR>";
        text += "<TR><TH>Reported&nbsp;by</TH><TD>" + p4 + "</TD></TR>";
        text += "<TR><TH>Priority</TH><TD>" + p5 + "</TD></TR>";
        // Added decode function and style: IG, 23-12-09 
        text += "<TR><TH  style=\"vertical-align: top;\">Description</TH><TD>" + decodeURIComponent(p6) + "</TD></TR>";
        text += "<TR><TH>Status</TH><TD>" + p7 + "</TD></TR>";
        text += "<TR><TH>Closed on</TH><TD>" + p8 + "</TD></TR>";
        text += "<TR><TH>Asset&nbsp;Make</TH><TD>" + p9 + "</TD></TR>";
        text += "<TR><TH>Asset&nbsp;Model</TH><TD>" + p10 + "</TD></TR>";
        text += "</TABLE>";
        hp.innerHTML = text;
	hp.style.visibility = "Visible";
}

function HideTicket() {
	hp = document.getElementById("ticketpop");
	hp.style.visibility = "Hidden";
}


/* Rotating Phone Number */
var links = ['javascript:popupwindow(\'popup-request.php?cb=1\')','javascript:popupwindow(\'popup-request.php?cb=1\')','javascript:popupwindow(\'popup-request.php?cb=1\')','javascript:popupwindow(\'popup-request.php?cb=1\')'];
var phonetext = ['Call Us On','01242 807817','Call Back Service','01242 807817'];
var speed = 3000; /*this is the time in milliseconds adjust to suit*/
var c;
var fixedtextarray = ['<a href="#" onclick="javascript:popupwindow(\'popup-request.php?cb=1\')">Call Us On<\/a>','<a href="#" onclick="javascript:popupwindow(\'popup-request.php?cb=1\')">01242 807817<\/a>','<a href="#" onclick="javascript:popupwindow(\'popup-request.php?cb=1\')">Call Back Service<\/a>','<a href="#" onclick="javascript:popupwindow(\'popup-request.php?cb=1\')">01242 807817<\/a>']; /*Use for IE version only*/

function init() {
	if (browserName=="Netscape") {
		l=document.createElement('a');
		l.id = 'link';
		i=document.createElement('img');
		i.id = 'link_img';
		l.appendChild(i);
		document.getElementById('phonebanner').appendChild(l);
		obj0=document.getElementById('link');
		obj1=document.getElementById('link_img');
		num=Math.floor(Math.random()*links.length);
		obj0.href=links[num];
		obj1.innerHTML=phonetext[num];
		c=num;
		showlink();
	} else {
		num=Math.floor(Math.random()*fixedtextarray.length);
		ieVar = document.getElementById('phonebanner');
		ieVar.innerHTML = fixedtextarray[num];
		c=num;
		showlinkie();
	}
}

function showlink() {
	obj0.href=links[c];
	obj1.innerHTML=phonetext[c];
	c++;
	if(c==links.length) {
		c=0;
	}
	setTimeout(function(){showlink()},speed);
}

function showlinkie() {
	ieVar.innerHTML=fixedtextarray[c];
	c++;
	if(c==fixedtextarray.length) {
		c=0;
	}
	setTimeout(function(){showlinkie()},speed);
}

if(window.addEventListener){
	window.addEventListener('load',init,false);
} else {
	if(window.attachEvent){
		window.attachEvent('onload',init);
	}
}

/* Sliding Menus */
var lit_slideSpeed = 15;	// Higher value = faster
var lit_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var lit_activeId = false;
var lit_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(lit_slideInProgress)return;
	lit_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('lit_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(lit_activeId &&  lit_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(lit_activeId,(lit_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,lit_slideSpeed);
		}
	}else{
		slideContent(numericId,(lit_slideSpeed*-1));
		lit_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('lit_a' + inputId);
	var contentObj = document.getElementById('lit_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',lit_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('lit_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('lit_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,lit_slideSpeed);				
			}else{
				lit_slideInProgress = false;
			}
		}else{
			lit_activeId = inputId;
			lit_slideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='lit_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'lit_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'lit_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='lit_answer_content';
			contentDiv.id = 'lit_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}
window.onload = initShowHideDivs;
