/*
 Open new popup window
*/
function openNewWindow(page)
{
	window.open(page, "NewWindow", "height=450,width=600,resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,location=no", true);	
}

/*
 Open new popup window
*/
function openNewPopupWindow(page)
{
	window.open(page, "NewWindow", "height=550,width=750,resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,location=no", true);	
}

/*
 Open a modal dialog
*/
function openModalDialog(page)
{
	window.showModalDialog(page, null, "resizable=yes;status=no");
}

/*
 Load a page into current window
*/
function load(page)
{
	window.location = page;
}

/*
	Clear the clipboard data.
*/
function clearClipboard()
{
  if (window.clipboardData)
  {
		clipboardData.clearData("Text");
		clipboardData.clearData("URL");
		clipboardData.clearData("HTML");
	}
}


/*
	Smart Navigation
*/
function smartNavigationHandler()
{
	var position;
	var scrollPosition = document.getElementById("scrollPosition");
	
	if (document.body != null && document.body.scrollTop)
	{
		position = document.body.scrollTop;
	}
	else
	{
		position = window.pageYOffset;
	}
	
	if (position != null && scrollPosition != null)
	{
		scrollPosition.value = position;
	}
}

/*
	Restore the last scroll position.
*/
function restoreScrollPosition()
{
	var scrollPosition = document.getElementById("scrollPosition");
	
	if (scrollPosition != null && scrollPosition.value != null && scrollPosition.value.length > 0)
	{
		window.scrollTo(0, scrollPosition.value);
	}
	else
	{
		window.setTimeout("restoreScrollPosition()", 150);
	}
}



/*
	max selection for reason to apply
*/
function handleReasonToApplySelection(maxOptions,chkBoxName,message)
{	
	var	reasonListBox = top.window.document.getElementById(chkBoxName);																													
															
	if (reasonListBox != null)
	{		
		var	selectedItems = "";		
		var options = reasonListBox.options != null ? reasonListBox.options : reasonListBox.getElementsByTagName("input");

		for (i = 0; i < options.length; i++)
		{
			var option = options[i];
			if (option != null && (option.selected || option.checked))
			{
				// Get the label node
				var value = option.nextSibling != null ? option.nextSibling.innerHTML : "";
				
				if (value.length > 0)
				{
					selectedItems += value.replace(",","cma;") + ",";
				}
			}
		}
		// Remove the trailing comma.
		selectedItems = selectedItems.substring(0, selectedItems.length - 1);
							
				
		if (selectedItems.length > 0 && selectedItems.split(",").length > maxOptions) 
		{
			alert(message);
			return false;	
		}			
		
		return false;	
	}			
}

/*
	Limit characters reason to apply free text
*/

function limitTextArea(txt,lblTxtCounter, minLen)
{
	var textarea = document.getElementById(txt);
	var lblCounter = document.getElementById(lblTxtCounter);
	
	if (textarea != null)
	{		
		/*for (j=0;j < countryArray.length; j++)
		{
			if (countryArray[j] == countryCode)
			{
				defaultTxtLen = charLimitArray[j];
				break;
			}
		}*/
		
		if (lblCounter != null)
		{
			var charLeft = textarea.value.length;
			lblCounter.innerText = "("+ charLeft + ")";			
		}		
	}
}
