function logOffRedirect()
     {

            var port = window.location.port;
            var hostname = window.location.hostname;
            if (port == "443") {
                  window.location.href="https://" + hostname + "/pkmslogout?filename=logout.html";
            } else {
                  window.location.href="https://" + hostname + ":" + port + "/pkmslogout?filename=logout.html";
            }
     }

function trimText(str)
{
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;

}

function searchRedirect(){
	
	if(validateSearch())
	{	
		document.getElementById('id_searchQueryForm').submit();
	}
}
function validateSearch()
{
	var qTxt = document.getElementById('id_search_query').value;
	
	if(trimText(qTxt).length == 0 )
	{
		alertMessage('Message from Search','Search box is empty!');
		return false;
	}
	else
	{
		return true;
	}
}
function applyClass()
{
	var tds = dojo.query('[width="220"]:first-child');
	for(var i=0;i<tds.length;i++)
	{
		dojo.addClass(tds[i],'lhs');
	}
}
		
		function updateFlag(flag)
		{
			var xmlhtttp = null;
			
			if (window.XMLHttpRequest)
			{
			// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			}
			else
			{
			// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			var url = document.getElementById("addflagurl").href;
			xmlhttp.open("GET",url+"?msgshown="+flag,false);
			xmlhttp.send(null);
		}
		
		function addTime()
		{
			currentTime = currentTime + 1000;
			if(currentTime >reportTime)
			{
				if(!msgShown)
				{
					var diff = (offTime - reportTime);
					diff = (diff - (diff % 1000))/1000;
					diff = (diff - (diff % 60))/60;
					updateFlag(true);
					if(hasReportingAccess == 'true')
					{
						alertMessage("WARNING","After "+diff+" minutes reports will not be available.");
					}
				}
				
			}
			else{
				
				setTimeout('addTime()',1000);
			}
				
		}
		
		function reportRefresh(){
			
			currentTime = currentTime + 1000;
			
				if(currentTime >= offTime && currentTime <= offTime+2000)
				{
					
					window.location.reload();
				}
				else{
					
					setTimeout('reportRefresh()',1000);
				}
			
		}
		
		function startTimer()
		{
			if(checkTimer){
			
					if(currentTime<reportTime)
					{
						addTime();
					}
					else if(currentTime < offTime)
					{
						if(!msgShown)
						{
							var diff = (offTime - currentTime);
							diff = (diff - (diff % 1000))/1000;
							diff = (diff - (diff % 60))/60;
							updateFlag(true);
							
							if(hasReportingAccess == 'true')
							{	
								alertMessage("WARNING","After "+diff+" minutes reports will not be available.");
							}
						}
					}
			}
		}
		function alertMessage(title,message)
		{
			document.getElementById('theme-pop-up-title').innerHTML = title;
			document.getElementById('theme-pop-up-content').innerHTML = message;
			document.getElementById('theme-pop-up').style.display='block';
			document.getElementById('theme-fade').style.display='block';
			document.getElementById('theme-pop-up-button').focus();
			
		}
		dojo.addOnLoad(startTimer);
		dojo.addOnLoad(applyClass);
