function doNothing()
{
}

function resizeWindow(gridWidth, gridHeight)
{
	if (typeof(gridWidth) == 'undefined')
		gridWidth = 700;
	
	if (typeoof(gridHeight) == 'undefined')
		gridHeight = 400;
		
	window.resizeTo(parseInt(gridWidth, 10) + 5, parseInt(gridHeight, 10) + 112);
}

function swapClass(obj, cls, isSelected) 
{
	if (typeof(isSelected) == 'undefined')
		isSelected = false;
		
	if (!isSelected)
		obj.className = cls;
}

function getElement(tagName, elementName)
{
	var elements	=	document.getElementsByTagName(tagName);
	
	for(i = 0; i < elements.length; i++)
	{
		var elem	=	elements.item(i);
		
		if (elem.name == elementName)
			return elem;
	}
	
	return null;
}

function HandleRowSelection(chkElement, gridId)
{
	var selection	=	false;
	
	if (typeof(chkElement) == "object" && typeof(chkElement) != null)
	{
		if(chkElement.checked == false)
			selection	=	false;
		else
			selection	=	true;
	}
	
	var elements	=	document.getElementsByTagName("INPUT");
	
	for(i = 0; i < elements.length; i++)
	{
		var elem	=	elements.item(i);
		var name	=	elem.name;
		var type	=	elem.type;
		
		type		=	type.toLowerCase();
		
		if (elem.type == "checkbox")
		{
			if(name.indexOf(gridId) != -1 && name.indexOf("__SELECTROW") != -1)
			{
				if (elem.checked != selection)
					elem.click();
			}
		}
	}
}

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 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)
	{
		var objRefresher	=	window.opener.document.getElementById(refreshObject);
		
		if (isOpenerRefreshed == true && objRefresher )
			objRefresher.click();
		window.close(); 	
	}
}

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 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 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 SetElementStyle(elem, attribute, value)
{
	switch (attribute.toLowerCase())
	{
	case "backgroundcolor":
		elem.style.backgroundColor = value;
		break;
	default:
		break;
	}
}

function SetElementAttribute(elem, attribute, value)
{
	switch (attribute.toLowerCase())
	{
	case "classname":
		elem.className = value;
		break;
	default:
		break;
	}
}

