function doNothing()
{
}

function swapClass(obj, cls, isSelected) 
{
	if (typeof(isSelected) == 'undefined')
		isSelected = false;
		
	if (!isSelected)
		obj.className = cls;
}

function getElement(tagName, elementName, matchType)
{
	if ((typeof(matchType) == 'undefined') || (matchType == null))
		matchType = 'EQUAL';
		
	var elements	=	document.getElementsByTagName(tagName);
	
	for(i = 0; i < elements.length; i++)
	{
		var elem	=	elements.item(i);
		
		switch (matchType)
		{
		case 'EQUAL':
			if (elem.name == elementName)
				return elem;
			break;
		case 'LIKE':
			var elemName = elem.name;
			
			if ((elemName != null) && (elemName != ""))
			{
				if (elemName.indexOf(elementName) != -1)
					return elem;
			}
			break;
		default:
			break;
		}
	}
	
	return null;
}

function ShowHideModule(divElement, appPath, imgElement, minImage, maxImage, minColor, maxColor)
{
	if (divElement != null && typeof(divElement) == "object")
	{
		// get the current status
		var currentStatus	=	divElement.style.display;

		if (currentStatus == null || currentStatus == "" || currentStatus == "block")
		{
			//set it to minimized
			divElement.style.display	=	"none";
			divElement.parentElement.parentElement.style.display	=	"none";
			imgElement.src				=	appPath + minImage;
			imgElement.title			=	"Maximize";
			divElement.parentElement.parentElement.previousSibling.firstChild.style.backgroundColor = minColor;
		}
		else
		{
			// set it to maximized");
			divElement.style.display	=	"block";
			divElement.parentElement.parentElement.style.display	=	"block";
			imgElement.src				=	appPath  + maxImage ;
			imgElement.title			=	"Minimize";
			divElement.parentElement.parentElement.previousSibling.firstChild.style.backgroundColor = maxColor;
		}
	}
}

function ShowHideRelation(divElemName, appPath, imgElement, minImage, maxImage, minColor, maxColor)
{
	var divElement	=	getElement("DIV", divElemName);
	var hrefElement	=	getElement("A", "MinMaxButton__" + divElemName);
	
	if (typeof(divElement) == 'object')
	{
		// get the current status
		var currentStatus	=	divElement.style.display;
		var cell1Element	=	hrefElement.parentElement
		var cell2Element	=	cell1Element.previousSibling;
		
		if (currentStatus == null || currentStatus == "" || currentStatus == "block")
		{
			//set it to minimized
			divElement.style.display			=	"none";
			imgElement.src						=	appPath + minImage;
			imgElement.title					=	"Maximize";
			cell2Element.style.filter			=	"progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr='#FF808080', EndColorStr='#FFD3D3D3');";
			cell1Element.style.backgroundColor	=	"#D3D3D3";
		}
		else
		{
			// set it to maximized");
			divElement.style.display			=	"block";
			imgElement.src						=	appPath  + maxImage ;
			imgElement.title					=	"Minimize";
			cell2Element.style.filter			=	"progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr='#FF003399', EndColorStr='#FF6699CC');";
			cell1Element.style.backgroundColor	=	"#6699CC";
		}
	}
}

function openWindowwithURL(fullURL, targetLocation, height, width, showConfirmation, confirmText, features)
{

	var isConfirmed		=	true;
	var basicFeatures	=	"";
	
	if (fullURL == null || fullURL == "")
		fullURL	=	"#";

	if (targetLocation == null || targetLocation == "")
		targetLocation	=	"_blank";

	if (typeof(showConfirmation) == 'undefined' || showConfirmation == null || showConfirmation == "")
		showConfirmation	=	false;

	if (typeof(confirmText) == 'undefined' || confirmText == null || confirmText == "")
		confirmText	=	"Are you sure?";

	if (height == null || height == "" || height == "0")
		height	=	"650";

	if (width == null || width == ""  || width == "0")
		width	=	"850";

	// initialize basic features
	basicFeatures	=	"resizable=yes,toolbar=no,directories=no,scrollbars=yes,left=0,top=0,width=" + width + ",height=" + height;
	
	if (typeof(features) == 'undefined' || features == null || features == '')
	{
		features	=	basicFeatures;
	}
	else
	{
		// replace the items we have in the argument
		var arrBaseFeatureList = basicFeatures.split(",");
		var baseFeatureIndex;
		var baseFeature;
		
		for(baseFeatureIndex in arrBaseFeatureList)
		{
			baseFeature		=	arrBaseFeatureList[baseFeatureIndex];
			var sepIndex	=	baseFeature.indexOf("=");
			var featureName	=	baseFeature.substring(0, sepIndex);
			var featureValue=	baseFeature.substr(sepIndex + 1);
			
			if (features.indexOf(featureName + "=") != -1)
			{
				var nfLength = featureName.length + 1;
				var nfIndex1 = features.indexOf(featureName + "=");
				var nfIndex2 = features.indexOf(",", nfIndex1);
				
				if (nfIndex2 == -1)
					nfIndex2 = features.length;
					
				var nfValue	= features.substring(nfIndex1 + nfLength, nfIndex2);
				
				if (nfValue != '')
				{
					arrBaseFeatureList[baseFeatureIndex] = featureName + '=' + nfValue;
				}
			}
		}
		
		// combine the values
		features	=	arrBaseFeatureList.join(",");
	}
	
	// add width and heigth to feature list
	features = features + ",width=" + width + ",height=" + height;
	
	if (showConfirmation == true)
	{
		isConfirmed = window.confirm(confirmText);
	}

	if (isConfirmed == true)
	{
		if (targetLocation == '_self')
		{
			if (window.event.srcElement.tagName	== 'A' || window.event.srcElement.tagName	== 'a')
			{
				window.event.srcElement.href	= fullURL;
			}
			else
			{			
				if (window.event.srcElement.tagName	== 'INPUT' || window.event.srcElement.tagName	== 'input')
				{
					window.event.returnValue	=	false;
				}
				else
				{
					window.open(fullURL, targetLocation, features);
				}
			}
		}
		else
		{
			window.open(fullURL, targetLocation, features);
		}
	}
}

function openWindow(target, appPath, targetLocation, arguments, title, height, width, showConfirmation, confirmText, features)
{
	var isConfirmed	=	true;

	if (typeof(title) == 'undefined' || title == null)
		title	=	"";
	
	if (targetLocation == null || targetLocation == "")
		targetLocation	=	"_blank";

	if (typeof(showConfirmation) == 'undefined' || showConfirmation == null || showConfirmation == "")
		showConfirmation	=	false;

	if (typeof(confirmText) == 'undefined' || confirmText == null || confirmText == "")
		confirmText	=	"Are you sure?";

	if (height == null || height == "" || height == "0")
		height	=	"650";

	if (width == null || width == ""  || width == "0")
		width	=	"850";

	if (arguments == null)
		arguments = "";

	if (arguments.length > 0)
		target = target + "?" + arguments;


	// finallly add the apppath
	if (appPath == null || typeof(appPath) == 'undefined')
		appPath	=	"";
		
	target	=	appPath + target;
	
	openWindowwithURL(target, targetLocation, height, width, showConfirmation, confirmText, features);
	
	return false;
}

function openLookupWindow(target, appPath, targetLocation, arguments, title, height, width, showConfirmation, confirmText)
{
	openWindow(target, appPath, "_blank", targetLocation, arguments + "", "Lookup Window", "600", "800", false, "");
}

function openPopupWindow(target, appPath, targetLocation, arguments, title, height, width, showConfirmation, confirmText)
{
	openWindow(target, appPath, "_blank", arguments + "" + "&isPopup=1", title, height, width, showConfirmation, confirmText)
}

function openProcessWindow(target, appPath, targetLocation, arguments, title, height, width, showConfirmation, confirmText)
{
	// call up openwindow with fixed size attributes
	openWindow(target, appPath, targetLocation, arguments + "", title, "275", "550", showConfirmation, confirmText);
}

function openReportWindow(target, appPath, targetLocation, arguments, title)
{
	// call up openwindow with fixed size attributes
	openWindow(target, appPath, targetLocation, arguments, title, '800', '875', false, null, 'scrollbars=no');
}

function closeWindow(isConfirmReqd, isOpenerRefreshed, refreshObject, confirmText)
{
	isOpenerRefreshed	=	true;
	isConfirmReqd		=	false;

	var isConfirmed		=	false;
		
	if ( (typeof(refreshObject) == 'undefined') || (refreshObject == null))
		refreshObject	=	'btnRefresh';

	if ( (typeof(confirmText) == 'undefined') || (confirmText == null))
		confirmText		=	'Do you want to discard all entries and close this window?';

	if (isConfirmReqd)
	{
		if (!confirm(confirmText))
			isConfirmed = false;				
	}
	else
		isConfirmed = true;
			
	if (isConfirmed)
	{
		if (isOpenerRefreshed == true && window.opener.document.all.item(refreshObject) )
			window.opener.document.all.item(refreshObject).click();
		window.close(); 	
	}
}

function refreshWindow(windowType)
{
	if ( (typeof(windowType) == 'undefined') || (windowType == null))
		windowType	=	'SELF';

	var linkURL;
			
	switch (windowType.toUpperCase())
	{
	case 'OPENER':
		linkURL						= window.opener.location.href;
		window.opener.location.href = setQuerystringItem(linkURL, "_myrand_", Math.random());
		break;
	case 'TOP':
		break;
	default:
		// SELF
		linkURL			=	window.location.href;
		window.location	=	setQuerystringItem(linkURL, "_myrand_", Math.random());
		break;
	}
}

function getDetails()
{
	alert("Width  is :" + window.document.body.clientWidth);
	alert("Height is :" + window.document.body.clientHeight);
}

function setQuerystringItem(url, item, value)
{
	try
	{
		// find out whether we have that item
		var nextItemPos	=	url.length;
		var prefixValue	=	'';
		var suffixValue	=	'';
		
		if ( (typeof(value) == 'undefined') || (value == null))
			value	=	'';
			
		var itemValue	=	item + '=' + value;

		var itemPos		=	url.indexOf(item + '=');

		if (itemPos > -1)
		{
			// get the portion before the current item
			prefixValue	=	url.substr(0, itemPos);

			// are there anymore items beyond this?
			nextItemPos	=	url.indexOf('&', itemPos);

			if (nextItemPos > -1)
				suffixValue	=	url.substr(nextItemPos);
		}
		else
		{
			prefixValue	=	url;
			
			if (url.indexOf('?') > -1)
				prefixValue	=	prefixValue + "&";
			else
				prefixValue	=	prefixValue + "?";
		}
		
		return prefixValue + itemValue + suffixValue;
	}
	catch(e)
	{
		return url;
	}
}

function refreshCurrentWindow()
{
	var href		=	window.location.href;
	window.location	=	setQuerystringItem(href, "_myrand_", Math.random());
}

function SwitchtoTab(newIndex)
{
	var href				=	document.location.href;
	href					=	setQuerystringItem(href, "__TABPOS__", newIndex);
	window.location			=	href;
}

function GetElementStyle(elem, attribute, defaultValue)
{
	var retValue	=	"";
	
	switch (attribute.toLowerCase())
	{
	case "backgroundcolor":
		retValue	=	elem.style.backgroundColor;
		break;
	case "display":
		retValue	=	elem.style.display;	
		break;
	default:
		break;
	}
	
	if (typeof(retValue) == 'undefined' || retValue == null)
	{
		if (defaultValue != null)
			retValue = defaultValue;
	}
	
	return retValue;	
}

function SetElementStyle(elem, attribute, value)
{
	switch (attribute.toLowerCase())
	{
	case "backgroundcolor":
		elem.style.backgroundColor = value;
		break;
	case "display":
		elem.style.display	=	value;
		break;
	default:
		break;
	}
}

function ShowItems(sTagName, sElementId)
{
	var cElems = document.all.tags(sTagName);
	var iNumElems = cElems.length;
	
	if ((typeof(sElementId) == 'undefined') || (sElementId == null))
		sElementId	=	"";
		
	for (var i=1;i<iNumElems;i++) 
	{	
		var actonItem	=	true;
		var elemId		=	cElems[i].id;
		
		if (sElementId != "")
		{
			if (elemId.toUpperCase() != sElementId.toUpperCase())
				actonItem =	false;
		}
			
		if (actonItem)
			cElems[i].style.display = "block";
	}
}

function HideItems(sTagName, sElementId)
{
	var cElems = document.all.tags(sTagName);
	var iNumElems = cElems.length;

	if ((typeof(sElementId) == 'undefined') || (sElementId == null))
		sElementId	=	"";
	
	for (var i=1;i<iNumElems;i++) 
	{
		var actonItem	=	true;
		var elemId		=	cElems[i].id;
		
		if (sElementId != "")
		{
			if (elemId.toUpperCase() != sElementId.toUpperCase())
				actonItem =	false;
		}

		if (actonItem)	
			cElems[i].style.display = "none";
	}
}

function toggleItem(tagName, elemName)
{
	// get reference to the element
	var element	=	document.all.item(elemName);
	
	if (GetElementStyle(element, 'display') == 'none')
		ShowItems(tagName, elemName);
	else
		HideItems(tagName, elemName);
}

function toggleImage(pElement, pOpenImage, pCloseImage)
{
	var imageSrc	=	new String(pElement.src);
	
	imageSrc	=	imageSrc.toLowerCase();
	pOpenImage	=	new String(pOpenImage);
	pCloseImage	=	new String(pCloseImage);
	
	if (imageSrc.indexOf(pOpenImage) != -1)
		pElement.src = imageSrc.replace(new RegExp(pOpenImage, "igm"), pCloseImage);
	else
		pElement.src = imageSrc.replace(new RegExp(pCloseImage, "igm"), pOpenImage);
}

function SetElementAttribute(elem, attribute, value)
{
	switch (attribute.toLowerCase())
	{
	case "classname":
		elem.className = value;
		break;
	default:
		break;
	}
}

function encodetoValidXML(datatoEncode, onlyExtended)
{
	/* we'll do a find and replace of the following characters
		& ' " < > */
	var objRegExp	;
	var result		=	new String("");
	var strObj		;
	
	if (typeof(onlyExtended) == 'undefined' || onlyExtended == null || onlyExtended == "")
		onlyExtended = false;
	else
		onlyExtended = true;
		
	if (typeof(datatoEncode) != 'undefined' && datatoEncode != null && datatoEncode != "")
	{
		strObj		=	new String(datatoEncode);
		
		if (!onlyExtended)
		{
			// &
			objRegExp	=	new RegExp("&", "igm");
			result		=	strObj.replace(objRegExp, "&amp;");
			
			// '
			objRegExp	=	new RegExp("'", "igm");
			result		=	result.replace(objRegExp, "&apos;");

			// ""
			objRegExp	=	new RegExp("\"", "igm");
			result		=	result.replace(objRegExp, "&quot;");

			// <
			objRegExp	=	new RegExp("<", "igm");
			result		=	result.replace(objRegExp, "&lt;");
			
			// >
			objRegExp	=	new RegExp(">", "igm");
			result		=	result.replace(objRegExp, "&gt;");
		}
		else
		{
			result		=	strObj;
		}
				
		// match other non-printable characters and replace them with their unicode equivalent
		objRegExp	=	new RegExp("[^\u0020-\u00FF]", "igm");
		var arr		;
		
		while( (arr = objRegExp.exec(result)) != null)
		{
			var index 		= arr.index;
			var splChar		= "&#" + result.charCodeAt(index) + ";";
			
			result = result.substring(0, index) + splChar + result.substr(index + 1);
		}
	}

	return result;
}
