function ProcessTimestamp(pstrData)
{
   var START = "[TIMESTAMP]";
   var STOP = "[/TIMESTAMP]";
   
   // retrieve the error info
   if(pstrData.indexOf(START) > -1)
   {
      // strip the info
      var iPosStart = pstrData.indexOf(START) + START.length;
      var strMsg = pstrData.substring(iPosStart, pstrData.indexOf(STOP));
      
      // remove tags from string
      pstrData = pstrData.replace(/\[TIMESTAMP\].*\[\/TIMESTAMP\]/g, "");
      
      return {data:pstrData,timestamp:strMsg};
   }
   
   return {data:pstrData,timestamp:null};
}

function GetMessage(pstrMessage, pstrColor)
{
   var strMessage = "<span style=\"color:"+pstrColor+";\">"+pstrMessage+"</span>";
   return strMessage;
}

function DisplayNoRefreshMessage(pstrId,pstrColor,piPosition)
{
	var strMessage = 'Automatic content update is temporarily unavailable';
	var objId = document.getElementById(pstrId);
   var objNoRefresh = document.getElementById(pstrId+"NoRefresh");
   var objNode = document.createElement("span");
   
   if(objNoRefresh != null) { return false;}

	// message settings
   objNode.id=pstrId+"NoRefresh";
   objNode.style.fontSize = "10px";
   objNode.style.color = pstrColor;

	// -2 before with <br/>, -1 before, 1 after id, 2 after id with <br/>
	if(objId != null)
	{
		switch (piPosition)
		{
			case -2:
				strMessage = strMessage+"<br/>";
				break;
			case -1:
				strMessage = strMessage+"&nbsp;";
				break;
			case 1:
				strMessage = "&nbsp;" + strMessage;
				break;
			case 2:
				strMessage = "<br/>"+strMessage;
				break;
		}
		
		// set the message and attach
		objNode.innerHTML = strMessage;
		if(piPosition < 0)
		{objId.parentNode.insertBefore(objNode,objId);}
		else if(piPosition > 0)
		{objId.parentNode.appendChild(objNode);}
   }
}

function ClearNoRefreshMessage(pstrId)
{
   var objNoRefresh = document.getElementById(pstrId+"NoRefresh");
   if(objNoRefresh != null) { objNoRefresh.parentNode.removeChild(objNoRefresh); }
}

function StripEncoding(pstrValue)
{
	// replace all encoded characters with empty string
	return pstrValue.replace(/\s/g, '').replace(/&amp;/gi,'').replace(/&quot;/gi,'').replace(/&apos;/gi,'').replace(/&lt;/gi,'').replace(/&gt;/gi,'');
}

function RemoveClassName(pstrClass,pstrValue)
{
	// locate classname and remove it if found
	// return the rest of the class
	var iPos = pstrClass.indexOf(pstrValue);
	if(iPos > -1)
	{
		return pstrClass.replace(pstrClass.substring(iPos, iPos + pstrValue.length),'');
	}
	
	return pstrClass;
}

function CompareValues(pstrValue1, pstrValue2)
{
	// clean by removing spaces,tabs,and carriage returns
	var strClean1 = pstrValue1.replace(/\r|\n|\r\n|\s|\t/g,'');
	var strClean2 = pstrValue2.replace(/\r|\n|\r\n|\s|\t/g,'');

	if(strClean1 == strClean2)
	{ return true; }
	
	return false;
}

function SetHighlight(pstrId,pstrBackColor,pstrForeColor,piTimeInSeconds)
{
	var itemId = document.getElementById(pstrId);
	if(itemId != null)
	{
		var strBackColor = itemId.style.backgroundColor;
		var strForeColor = itemId.style.color;
		pstrBackColor != '' ? itemId.style.backgroundColor = pstrBackColor : '';
		pstrForeColor != '' ? itemId.style.color = pstrForeColor : '';
		setTimeout("ClearHighlight('"+pstrId+"','"+strBackColor+"','"+strForeColor+"')", piTimeInSeconds*1000);
	}
}

function ClearHighlight(pstrId,pstrBackColor,pstrForeColor)
{
	var itemId = document.getElementById(pstrId);
	if(itemId != null) 
	{
		itemId.style.backgroundColor = pstrBackColor;
		itemId.style.color = pstrForeColor;
	}
}

function DelayedShowHide(pstrHideId, pstrShowId, piTimeInSeconds)
{
	var itemId = document.getElementById(pstrHideId);
	var itemShowId = document.getElementById(pstrShowId);
	if(itemId != null && itemShowId != null)
	{
		itemId.style.display = 'none';
		itemShowId.style.display = '';
		
		setTimeout("ClearDelayedShowHide('"+pstrHideId+"','"+pstrShowId+"')", piTimeInSeconds*1000);
	}
}

function ClearDelayedShowHide(pstrShowId,pstrHideId)
{
	var itemId = document.getElementById(pstrShowId);
	var itemShowId = document.getElementById(pstrHideId);
	if(itemId != null && itemShowId != null)
	{
		itemId.style.display = '';
		itemShowId.style.display = 'none';
	}
}

function GetTime()
{
   var d = new Date();
   var hours = d.getHours();
   var mins = d.getMinutes();
   var secs = d.getSeconds();
   var ampm = "am";
   
   if(hours>=12 && hours <=23) { ampm="pm"; }
   if(hours>12 && hours<=23) { hours=hours-12; }
   if(hours >0 && hours <10) { hours="0"+hours; }
   if(mins==0) { mins="00"; }
   if(mins>0 && mins<10) { mins="0"+mins; }
   if(secs==0) { secs="00"; }
   if(secs>0 && secs<10) { secs="0"+secs; }
   
   return hours+":"+mins+":"+secs+" "+ampm;
}