/*---------------------------------------------------------------------------------------------
File name		: FormFunctions.js
Purpose			: It comprises of all the javascript functions required for the form controls.
Author			: Manmeet Singh
Created on		: 12/02/2007
Last modified	: 
---------------------------------------------------------------------------------------------

Developed By	: R Systems International Systems Ltd., Noida (INDIA)
---------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
Function Name	: CheckAll
Purpose			: Call this function in the "onClick" event of chkCheckAll checkbox and 
					pass your "Form" name as parameter. 
					It will check/uncheck the chkDelete checkbox(s).
Input			: formname
Return			: values set into hidden controls
------------------------------------------------------------------------------*/
function CheckAll(form)		
{
	var strCheckValue = "";
	var isReport;
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if ((e.name != 'chkCheckAll') && (e.type=='checkbox') && (e.name == 'chkDelete' || e.name == 'chkReport') && (!e.disabled && !e.parentNode.disabled))
		{
			e.checked = eval('form.chkCheckAll').checked;
			if (e.name == 'chkReport')
				isReport = true;
			else if (e.name == 'chkDelete')
				isReport = false;
		}
	}
	//Call to set the Hidden Box Value
	if (isReport)
		setHiddenRbtnValue(form)
	else
		setHiddenBoxValue(form)
}
		
/*----------------------------------------------------------------------------
Function Name	: setHiddenBoxValue
Purpose			: Call this function to set the value of the hidden text
Input			: formname
Return			: none
------------------------------------------------------------------------------*/

function setHiddenBoxValue(form)
{
	var strCheckValue = "";
	for (var i=0;i<form.elements.length;i++)
	{	
		var e = form.elements[i];
		if ((e.name != 'chkCheckAll') && (e.type=='checkbox') && (e.name == 'chkDelete') && (!e.disabled) && (e.checked))
		{
			if (strCheckValue == "")
			{
				strCheckValue = e.id; 
			}
			else
			{
				strCheckValue = strCheckValue + ', ' + e.id;
			}
		}
	}
	form.hdnCheckValue.value = strCheckValue;
}

/*----------------------------------------------------------------------------
Function Name	: CheckSingle
Purpose			: Call this function in the "onClick" event of every chkDelete checkbox and 
					pass your "Form" name as parameter. 
					It will check/uncheck the chkCheckAll checkbox.
Input			: formname
Return			: values set into hidden controls
------------------------------------------------------------------------------*/

function CheckSingle(form)	
{
	var TotalBoxes = 0;
	var TotalCheckedBoxes = 0;
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if ((e.name != 'chkCheckAll') && (e.type=='checkbox') && (e.name == 'chkDelete') && (!e.disabled))
		{
			TotalBoxes++;
			if (e.checked)
			{
				TotalCheckedBoxes++;
			}
		}
	}
	if (TotalBoxes==TotalCheckedBoxes)
	{
		form.chkCheckAll.checked=true;
	}
	else
	{
		form.chkCheckAll.checked=false;
	}
	//Call to set the Hidden Box Value
	setHiddenBoxValue(form);
}
		
/*----------------------------------------------------------------------------
Function Name	: SelectedChk
Purpose			: This function is called when the user clicks on the delete link.
Input			: formname
Return			: True/False
------------------------------------------------------------------------------*/

function SelectedChk()
{
	var jsMsgDoYouWish = document.getElementById('UclDatagrid1_jsMsgDoYouWish').value;
	var jsMsgSelectAtLeast = document.getElementById('UclDatagrid1_jsMsgSelectAtLeast').value;
	if (document.forms[0].hdnCheckValue.value !="")
	{
		return confirm(jsMsgDoYouWish);
	}
	else
	{
		alert(jsMsgSelectAtLeast);
		return false;
	}
}

/*----------------------------------------------------------------------------
Function Name	: SelectedChk
Purpose			: This function is called when the user clicks on the delete link.
Input			: formname
Return			: True/False
------------------------------------------------------------------------------*/

function SelectedComboDatagridChk(varClientID)
{
	var jsMsgDoYouWish = document.getElementById(varClientID + '_jsMsgDoYouWish').value;
	var jsMsgSelectAtLeast = document.getElementById(varClientID + '_jsMsgSelectAtLeast').value;
	if (document.forms[0].hdnCheckValue.value !="")
	{
		return confirm(jsMsgDoYouWish);
	}
	else
	{
		alert(jsMsgSelectAtLeast);
		return false;
	}
}


/*----------------------------------------------------------------------------
Function Name	: ChkLength25
Purpose			: Function to check whether the Value in the field exceeds 25 characters
Input			: source,args
Return			: True/False
------------------------------------------------------------------------------*/

function ChkLength25(source,args)
{
	var iDescLength;
	iDescLength = args.Value.length;
    if(iDescLength > 25)
    {
            args.IsValid=false;
    }
    else
    {
            args.IsValid=true;
    }
}
		
/*----------------------------------------------------------------------------
Function Name	: ChkLength50
Purpose			: Function to check whether the Value in the field exceeds 50 characters
Input			: source,args
Return			: True/False
------------------------------------------------------------------------------*/

function ChkLength50(source,args)
{
	var iDescLength;
	iDescLength = args.Value.length;
    if(iDescLength > 50)
    {
            args.IsValid=false;
    }
    else
    {
            args.IsValid=true;
    }
}
	
/*----------------------------------------------------------------------------
Function Name	: ChkLength120
Purpose			: Function to check whether the Value in the field exceeds 120 characters
Input			: source,args
Return			: True/False
------------------------------------------------------------------------------*/

function ChkLength120(source,args)
{
	var iDescLength;
	iDescLength = args.Value.length;
    if(iDescLength > 120)
    {
            args.IsValid=false;
    }
    else
    {
            args.IsValid=true;
    }
}

/*----------------------------------------------------------------------------
Function Name	: ChkLength500
Purpose			: Function to check whether the Value in the field exceeds 500 characters
Input			: source,args
Return			: True/False
------------------------------------------------------------------------------*/

function ChkLength500(source,args)
{
	var iDescLength;
	iDescLength=args.Value.length;
	
    if(iDescLength > 500)
    {
            args.IsValid=false;
    }
    else
    {
            args.IsValid=true;
    }
}

/*----------------------------------------------------------------------------
Function Name	: ChkLength2000
Purpose			: Function to check whether the Value in the field exceeds 2000 characters
Input			: source,args
Return			: True/False
------------------------------------------------------------------------------*/

function ChkLength2000(source,args)
{
	var iDescLength;
	iDescLength=args.Value.length;
	
    if(iDescLength > 2000)
    {
            args.IsValid=false;
    }
    else
    {
            args.IsValid=true;
    }
}

/*----------------------------------------------------------------------------
Function Name	: ChkLength5000
Purpose			: Function to check whether the Value in the field exceeds 5000 characters
Input			: source,args
Return			: True/False
------------------------------------------------------------------------------*/

function ChkLength5000(source,args)
{
	var iDescLength;
	iDescLength=args.Value.length;
	
    if(iDescLength > 5000)
    {
            args.IsValid=false;
    }
    else
    {
            args.IsValid=true;
    }
}

/*----------------------------------------------------------------------------
Function Name	: ChkLength4000
Purpose			: Function to check whether the Value in the field exceeds 4000 characters
Input			: source,args
Return			: True/False
------------------------------------------------------------------------------*/

function ChkLength4000(source,args)
{
	var iDescLength;
	iDescLength=args.Value.length;
	
    if(iDescLength > 4000)
    {
            args.IsValid=false;
    }
    else
    {
            args.IsValid=true;
    }
}


/*----------------------------------------------------------------------------
Function Name	: ChkLength100
Purpose			: Function to check whether the Value in the field exceeds 100 characters
Input			: source,args
Return			: True/False
------------------------------------------------------------------------------*/

function ChkLength100(source,args)
{
	var iDescLength;
	iDescLength=args.Value.length;
	
    if(iDescLength > 100)
    {
            args.IsValid=false;
    }
    else
    {
            args.IsValid=true;
    }
}

/*----------------------------------------------------------------------------
Function Name	: ChkLength200
Purpose			: Function to check whether the Value in the field exceeds 200 characters
Input			: source,args
Return			: True/False
------------------------------------------------------------------------------*/

function ChkLength200(source,args)
{
	var iDescLength;
	iDescLength=args.Value.length;
	
    if(iDescLength > 200)
    {
            args.IsValid=false;
    }
    else
    {
            args.IsValid=true;
    }
}

/*----------------------------------------------------------------------------
Function Name	: ChkLength160
Purpose			: Function to check whether the Value in the field exceeds 160 characters
Input			: source,args
Return			: True/False
------------------------------------------------------------------------------*/

function ChkLength160(source,args)
{
	var iDescLength;
	iDescLength=args.Value.length;
	
    if(iDescLength > 160)
    {
            args.IsValid=false;
    }
    else
    {
            args.IsValid=true;
    }
}
/*----------------------------------------------------------------------------
Function Name	: ChkLength1024
Purpose			: Function to check whether the Value in the field exceeds 200 characters
Input			: source,args
Return			: True/False
------------------------------------------------------------------------------*/

function ChkLength1024(source,args)
{
	var iDescLength;
	iDescLength=args.Value.length;
	
    if(iDescLength > 1024)
    {
            args.IsValid=false;
    }
    else
    {
            args.IsValid=true;
    }
}
/*----------------------------------------------------------------------------
Function Name	: SelectedChkRpt
Purpose			: This function is called when the user clicks on the view report link.
Input			: formname
Return			: True/False
------------------------------------------------------------------------------*/

function SelectedChkRpt(form)
{
	var jsMsgSelectAtLeast = form.jsMsgSelectAtLeast.value;
	if (form.hdnRbtnValue.value != "")
	{
		return true;
	}
	else
	{
		alert(jsMsgSelectAtLeast);
		return false;
	}
}

/*----------------------------------------------------------------------------
Function Name	: setHiddenRbtnValue
Purpose			: Call this function to set the value of the hidden text
Input			: formname
Return			: none
------------------------------------------------------------------------------*/

function setHiddenRbtnValue(form)
{
	var strCheckValue = "";
	for (var i=0;i<form.elements.length;i++)
	{	
		var e = form.elements[i];
		if ((e.type=='radio') && (e.name == 'rbtnReport') && (!e.disabled) && (e.checked))
		{
			if (strCheckValue == "")
			{
				strCheckValue = e.id; 
			}
			else
			{
				strCheckValue = "";
			}
		}
		else if ((e.type=='checkbox') && (e.name == 'chkReport') && (!e.disabled) && (e.checked))
		{
			if (strCheckValue == "")
			{
				strCheckValue = e.id; 
			}
			else
			{
				strCheckValue = strCheckValue + ', ' + e.id;
			}
		}
	}
	form.hdnRbtnValue.value = strCheckValue;
}

/*----------------------------------------------------------------------------
Function Name	: CheckSingle
Purpose			: Call this function in the "onClick" event of every chkDelete checkbox and 
					pass your "Form" name as parameter. 
					It will check/uncheck the chkCheckAll checkbox.
Input			: formname
Return			: values set into hidden controls
------------------------------------------------------------------------------*/

function CheckRbtn(form)	
{
	var TotalBoxes = 0;
	var TotalCheckedBoxes = 0;
	var isCheckBox;
	isCheckBox = false;
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if ((e.name != 'chkCheckAll') && (e.type=='checkbox') && (e.name == 'chkReport') && (!e.disabled))
		{
			isCheckBox=true;
			TotalBoxes++;
			if (e.checked)
			{
				TotalCheckedBoxes++;
			}
		}
	}
	if (isCheckBox)
	{
		if (TotalBoxes==TotalCheckedBoxes)
		{
			form.chkCheckAll.checked=true;
		}
		else
		{
			form.chkCheckAll.checked=false;
		}
	}
	//Call to set the hidden value
	setHiddenRbtnValue(form);	
}

/*----------------------------------------------------------------------------
Function Name	: popUpComboValue
Purpose			: This will display a Pop Up Menu
Input			: the Control
Return			: PopUp Box
------------------------------------------------------------------------------*/
var oPopup = window.createPopup();
function popUpComboValue(objValue)
{
    x= window.event.clientX;
    y= window.event.clientY;
    
    var oPopBody = oPopup.document.body;
    var iMaxLength;
    var iMaxHeight;
    var iXDisplacement;
    var iLen;
    var iCount;
    var strText;
    var finalCount;
    iLen = objValue.options[objValue.selectedIndex].innerText.length
    //objValue.options[objValue.selectedIndex].innerText = '01234567890123456789012340123456789012345678901234'
    //
    iCount = 0
    iMaxHeight = 0
    strText = ""
    finalCount = (iLen/25)
//    alert(objValue.options[objValue.selectedIndex].innerText)
	while(finalCount > 0)
    {
		if (strText == '')
			strText = objValue.options[objValue.selectedIndex].innerText.substring(iCount, iCount+25)
		else
			strText = strText + ' ..\n ' + objValue.options[objValue.selectedIndex].innerText.substring(iCount, iCount+25)
		iMaxHeight = iMaxHeight + 15
		finalCount = finalCount - 1
		iCount = iCount + 25
	}
    
    /*
    if (iLen <= 25)
    {
    		iMaxLength = 160;
			iMaxHeight= 16;
			iXDisplacement = 150;
	}
    else if (iLen >= 25 && iLen <= 50)
    {
		
    		iMaxLength = 160;
			iMaxHeight= 48;
			iXDisplacement = 150;
	}
	else if (iLen >= 50 && iLen <= 200)
    {
			iMaxLength = 505;
			iMaxHeight = 29;
			iXDisplacement = 250;
	}
	else if (iLen >= 200 && iLen <= 500)
    {
			iMaxLength = 505;
			iMaxHeight = 50;
			iXDisplacement = 250;
	}*/
	
	iMaxLength  = 140
	iXDisplacement = 80
    oPopBody.style.backgroundColor = "#E1E1F1";
    oPopBody.style.border = "solid black 1px";
    oPopBody.style.margin = "0 0 0 3px;"
    if(objValue.disabled == false && objValue.length>0)
    {
		//alert(strText)
		oPopBody.innerHTML = strText
		oPopBody.style.fontSize = "11px";
		oPopBody.style.fontFamily = "Arial";
		oPopup.show(x-iXDisplacement , y+15, iMaxLength , iMaxHeight, document.body);
    }
}
function hidePopUp()
{
	oPopup.hide();
}

/*----------------------------------------------------------------------------
Function Name	: PageReload
Purpose			: This will reload the page after searching for the specified criteria
Input			: None
Return			: None
------------------------------------------------------------------------------*/
function PageReload()
{
	window.location.reload() ;
}


/*----------------------------------------------------------------------------
Function Name	: OpenSearchWindow
Purpose			: This function opens the Search window
Input			: strPageName
Return			: False
------------------------------------------------------------------------------*/
var SearchWindow;
function OpenSearchWindow(strSearchPath)
{
	var intWidth;
	var intHeight;
	
	var scrWidth;
	var scrHeight;
	
	intWidth = 750;
	intHeight = 505;
	
	scrWidth = parseInt((screen.width)/2) - parseInt((intWidth)/2)
	scrHeight = parseInt((screen.height)/2) - parseInt((intHeight)/2)
	
	if (SearchWindow && SearchWindow.open && !SearchWindow.closed)
	{
		if (confirm('Note that you already have a Search Window Open.\nThe Previous window would be closed.'))
		{
			SearchWindow.close()
			
			strSearchPath = '../' + strSearchPath
			SearchWindow = window.open(strSearchPath,'','scrollbars=1, width=750, height=505, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
		}
		else
			SearchWindow.focus();
	}
	else
	{
		strSearchPath = '../' + strSearchPath
		SearchWindow = window.open(strSearchPath,'','scrollbars=1, width=750, height=505, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
	}
	return false;
}
/*----------------------------------------------------------------------------
Function Name	: OpenExportWindow
Purpose			: This function opens the Export window
Input			: strPageName
Return			: False
------------------------------------------------------------------------------*/
var ExportWindow;
function OpenExportDataWindow(strExportPath)
{
	var intWidth;
	var intHeight;
	
	var scrWidth;
	var scrHeight;
	
	intWidth = 600;
	intHeight = 450;
	
	scrWidth = parseInt((screen.width)/2) - parseInt((intWidth)/2)
	scrHeight = parseInt((screen.height)/2) - parseInt((intHeight)/2)
	
	if (ExportWindow && ExportWindow.open && !ExportWindow.closed)
	{
		if (confirm('Please note that you already have a Export Window Open.\nThe Previous window would be closed.'))
		{
			ExportWindow.close()
			
			strExportPath = '../' + strExportPath
			ExportWindow = window.open(strExportPath,'','scrollbars=1, width=600, height=450, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
		}
		else
			ExportWindow.focus();
	}
	else
	{
		strExportPath = '../' + strExportPath
		ExportWindow = window.open(strExportPath,'','scrollbars=1, width=600, height=450, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
	}
	return false;
}

/*----------------------------------------------------------------------------
Function Name	: OpenImportWindow
Purpose			: This function opens the Export window
Input			: strPageName
Return			: False
------------------------------------------------------------------------------*/
var ImportWindow;
function OpenImportWindow(strImportPath)
{
	var intWidth;
	var intHeight;
	
	var scrWidth;
	var scrHeight;
	
	intWidth = 550;
	intHeight = 250;
	
	scrWidth = parseInt((screen.width)/2) - parseInt((intWidth)/2)
	scrHeight = parseInt((screen.height)/2) - parseInt((intHeight)/2)
	
	
	if (ImportWindow && ImportWindow.open && !ImportWindow.closed)
	{
		if (confirm('Please note that you already have a Import Window Open.\nThe Previous window would be closed.'))
		{
			ImportWindow.close()
			
			strImportPath = '../' + strImportPath
			ImportWindow = window.open(strImportPath,'','scrollbars=1, width=550, height=250, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
		}
		else
			ImportWindow.focus();
	}
	else
	{
		strImportPath = '../' + strImportPath
		ImportWindow = window.open(strImportPath,'','scrollbars=1, width=550, height=250, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
	}
	return false;
}
/*----------------------------------------------------------------------------
Function Name	: OpenComboSelectWindow
Purpose			: This function opens the Select window instead of a Combobox
Input			: strPageName
Return			: False
------------------------------------------------------------------------------*/
var ComboSelectWindow;
function OpenComboSelectWindow(strComboSelectPath)
{
	var intWidth;
	var intHeight;
	
	var scrWidth;
	var scrHeight;
	intWidth = 650;
	intHeight = 452;
	
	scrWidth = parseInt((screen.width)/2) - parseInt((intWidth)/2)
	scrHeight = parseInt((screen.height)/2) - parseInt((intHeight)/2)
	if (ComboSelectWindow && ComboSelectWindow.open && !ComboSelectWindow.closed)
	{
		if (confirm('Note that you already have a Combo Window Open.\nThe Previous window would be closed.'))
		{
			ComboSelectWindow.close()
			
			strComboSelectPath = '../' + strComboSelectPath
			ComboSelectWindow = window.open(strComboSelectPath,'','scrollbars=yes, width=650, height=452, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
		}
		else
			ComboSelectWindow.focus();
	}
	else
	{
		strComboSelectPath = '../' + strComboSelectPath
		ComboSelectWindow = window.open(strComboSelectPath,'','scrollbars=yes, width=650, height=452, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
	}
	return false;
}

/*----------------------------------------------------------------------------
Function Name	: OpenPASScheduleWindow
Purpose			: This function opens schedule window for PAS Module
Input			: strPageName
Return			: False
------------------------------------------------------------------------------*/
var PASWindow;
function OpenPASScheduleWindow(strComboSelectPath)
{
	var intWidth;
	var intHeight;
	
	var scrWidth;
	var scrHeight;
	
	intWidth = 950;
	intHeight = 652;
	
	scrWidth = parseInt((screen.width)/2) - parseInt((intWidth)/2)
	scrHeight = parseInt((screen.height)/2) - parseInt((intHeight)/2)
	
	
	if (PASWindow && PASWindow.open && !PASWindow.closed)
	{
		if (confirm('Please note that you already have a PAS Schedule View Window Open.\nThe Previous window would be closed.'))
		{
			PASWindow.close()
			
			strComboSelectPath = strComboSelectPath
			PASWindow = window.open(strComboSelectPath,'','scrollbars=yes, status=yes, width=950, height=652, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
		}
		else
			PASWindow.focus();
	}
	else
	{
		strComboSelectPath =  strComboSelectPath
		PASWindow = window.open(strComboSelectPath,'PortSchedule','scrollbars=yes, status=yes, width=950, height=652, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
	}
	return false;
}

/*----------------------------------------------------------------------------
Function Name	: OpenListCntrlWindow
Purpose			: This function opens the Select window instead of a List Control
Input			: strPageName
Return			: False
------------------------------------------------------------------------------*/
var ListCntrlWindow;
function OpenListCntrlWindow(strListCntrlPath)
{
	var intWidth;
	var intHeight;
	
	var scrWidth;
	var scrHeight;
	
	intWidth = 650;
	intHeight = 455;
	
	scrWidth = parseInt((screen.width)/2) - parseInt((intWidth)/2)
	scrHeight = parseInt((screen.height)/2) - parseInt((intHeight)/2)
	
	if (ListCntrlWindow && ListCntrlWindow.open && !ListCntrlWindow.closed)
	{
		if (confirm('Please note that you already have a List Control Window Open.\nThe Previous window would be closed.'))
		{
			ListCntrlWindow.close()
			
			strListCntrlPath = '../' + strListCntrlPath 
			ListCntrlWindow = window.open(strListCntrlPath,'','scrollbars=yes, width=650, height=455, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
		}
		else
			ListCntrlWindow.focus();
	}
	else
	{
		strListCntrlPath = '../' + strListCntrlPath 
		ListCntrlWindow = window.open(strListCntrlPath,'','scrollbars=yes, width=650, height=455, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
	}
	return false;
}

/*----------------------------------------------------------------------------
Function Name	: OpenPageHelp_Collapse
Purpose			: This function opens the Help Page pop up menu
Input			: strPageName
Return			: False
------------------------------------------------------------------------------*/
var PageHelp_CollapseWindow;
function OpenPageHelp_Collapse(strHelpPagePath)
{
	var intWidth;
	var intHeight;
	
	var scrWidth;
	var scrHeight;
	
	intWidth = 650;
	intHeight = 455;
	
	scrWidth = parseInt((screen.width)/2) - parseInt((intWidth)/2)
	scrHeight = parseInt((screen.height)/2) - parseInt((intHeight)/2)
	if (PageHelp_CollapseWindow && PageHelp_CollapseWindow.open && !PageHelp_CollapseWindow.closed)
	{
		if (confirm('Please note that you already have a Help Window Open.\nThe Previous window would be closed.'))
		{
			PageHelp_CollapseWindow.close()
			
			strHelpPagePath = '../' + strHelpPagePath 
			PageHelp_CollapseWindow = window.open(strHelpPagePath,'','scrollbars=yes, width=650, height=495, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
		}
		else
			PageHelp_CollapseWindow.focus();
	}
	else
	{
		strHelpPagePath = '../' + strHelpPagePath 
		PageHelp_CollapseWindow = window.open(strHelpPagePath,'','scrollbars=yes, width=650, height=495, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
	}
	return false;
}

/*----------------------------------------------------------------------------
Function Name	: OpenExportWindow
Purpose			: This function opens the Export Page pop up menu
Input			: strPageName
Return			: False
------------------------------------------------------------------------------*/
var ExportWindow;
function OpenExportWindow(strExportWindowPath)
{
	var intWidth;
	var intHeight;
	
	var scrWidth;
	var scrHeight;
	
	intWidth = 600;
	intHeight = 455;
	
	scrWidth = parseInt((screen.width)/2) - parseInt((intWidth)/2)
	scrHeight = parseInt((screen.height)/2) - parseInt((intHeight)/2)
	
	if (ExportWindow && ExportWindow.open && !ExportWindow.closed)
	{
		if (confirm('Please note that you already have a Export Window Open.\nThe Previous window would be closed.'))
		{
			ExportWindow.close()
			
			strExportWindowPath = '../' + strExportWindowPath 
			ExportWindow = window.open(strExportWindowPath,'','scrollbars=yes, width=600, height=455, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
		}
		else
			ExportWindow.focus();
	}
	else
	{
		strExportWindowPath = '../' + strExportWindowPath 
		ExportWindow = window.open(strExportWindowPath,'','scrollbars=yes, width=600, height=455, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
	}
	return false;
}

/*----------------------------------------------------------------------------
Function Name	: OpenDGPopUpWindow
Purpose			: This function opens the Export Page pop up menu
Input			: strPageName
Return			: False
------------------------------------------------------------------------------*/
var DGPopUpWindow;
function OpenDGBufferingPopUpWindow(strDGPopUpWindowPath)
{
	var intWidth;
	var intHeight;
	
	var scrWidth;
	var scrHeight;
	intWidth = 700;
	intHeight = 610;
	
	scrWidth = parseInt((screen.width)/2) - parseInt((intWidth)/2)
	scrHeight = parseInt((screen.height)/2) - parseInt((intHeight)/2)
	
	if (DGPopUpWindow && DGPopUpWindow.open && !DGPopUpWindow.closed)
	{
		if (confirm('Please note that you already have a Export Window Open.\nThe Previous window would be closed.'))
		{
			DGPopUpWindow.close()
			
			strDGPopUpWindowPath = '../' + strDGPopUpWindowPath 
			DGPopUpWindow = window.open(strDGPopUpWindowPath,'','scrollbars=yes, width=700, height=610, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
		}
		else
			DGPopUpWindow.focus();
	}
	else
	{
		strDGPopUpWindowPath = '../' + strDGPopUpWindowPath 
		DGPopUpWindow = window.open(strDGPopUpWindowPath,'','scrollbars=yes, width=700, height=610, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
	}
	return false;
}

/*----------------------------------------------------------------------------
Function Name	: OpenDGPopUpWindow
Purpose			: This function opens the Export Page pop up menu
Input			: strPageName
Return			: False
------------------------------------------------------------------------------*/
var DGPopUpWindow;
function OpenDGPopUpWindow(strDGPopUpWindowPath)
{
	var intWidth;
	var intHeight;
	
	var scrWidth;
	var scrHeight;
	
	intWidth = 600;
	intHeight = 455;
	
	scrWidth = parseInt((screen.width)/2) - parseInt((intWidth)/2)
	scrHeight = parseInt((screen.height)/2) - parseInt((intHeight)/2)
	
	if (DGPopUpWindow && DGPopUpWindow.open && !DGPopUpWindow.closed)
	{
		if (confirm('Please note that you already have a Export Window Open.\nThe Previous window would be closed.'))
		{
			DGPopUpWindow.close()
			
			strDGPopUpWindowPath = '../' + strDGPopUpWindowPath 
			DGPopUpWindow = window.open(strDGPopUpWindowPath,'','scrollbars=yes, width=600, height=455, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
		}
		else
			DGPopUpWindow.focus();
	}
	else
	{
		strDGPopUpWindowPath = '../' + strDGPopUpWindowPath 
		DGPopUpWindow = window.open(strDGPopUpWindowPath,'','scrollbars=yes, width=600, height=455, left=' + scrWidth + ', top=' + scrHeight + ', resizable=no');
	}
	return false;
}
//This function trims off the white spaces
function Trim(strTrimValue)
{
	if(strTrimValue.length < 1)
	{
		return"";
	}
	strTrimValue = RTrim(strTrimValue);
	strTrimValue = LTrim(strTrimValue);
	if(strTrimValue=="")
	{
		return "";
	}
	else
	{
		return strTrimValue;
	}
} 

//This function trims off the trailing white spaces
function RTrim(strValue)
{
	var w_space = String.fromCharCode(32);
	var v_length = strValue.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;
	while(iTemp > -1)
	{
		if(strValue.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = strValue.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} 
	return strTemp;
} 

//To trim off the leading white spaces
function LTrim(strValue)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = strValue.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length){
	if(strValue.charAt(iTemp) == w_space)
	{
	}
	else
	{
		strTemp = strValue.substring(iTemp,v_length);
		break;
	}
	iTemp = iTemp + 1;
	} 
	return strTemp;
} 

//This function restrains the user from using mouse right button

//Currently only enabled for ../Maintenance/frmHelpSectionValues.aspx page
function stopthief(ie) 
{
	var warning = "Right clicking this page is not allowed.";
	var strURLValue = window.document.location.toString();
	if (navigator.appName == 'Netscape' && ie.which == 3) 
	{
		alert(warning);
		return false;
	}
	else
		if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2 && strURLValue.match("HelpSectionValue") == null) 
		{
			alert(warning);
			return false;
		}
	return true;
}

//Function to Read the Value of the Cookie from the Client Machine
function getCookies(name) 
{
	var prefix = name + '=';
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if (cookieStartIndex == -1)
	{
		return 'None';
	}
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1)
	{
		cookieEndIndex = document.cookie.length;
	}
	return document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex);
}

//Drop Down Functionality
function clear_value()
        {
			obj = window.event.srcElement;
			obj.setAttribute("persistValue","");
        }

function divert_entry()
{
	obj = window.event.srcElement;
    //debugger;
    if  (obj.getAttribute("persistValue") == null)
            obj.setAttribute("persistValue","");                           
    var iKey;
    var eAny_Event = window.event;
    iKey = eAny_Event.keyCode;
    var sChr = String.fromCharCode(iKey);
    if (iKey == 13)
    {
			obj.setAttribute("persistValue","");
            return true;
    }
    if (iKey == 27)
    {
            sDelete_Chr = obj.getAttribute("persistValue");
            obj.setAttribute("persistValue", sDelete_Chr.substring(0,sDelete_Chr.length - 1));
            sChr = '';
    }
    obj.setAttribute("persistValue",obj.getAttribute("persistValue") + sChr);
    lookupItem(obj);
    if ((((iKey > 33) && (iKey < 255)) || (iKey == 8)) && (iKey != 40) && (iKey != 38))
            eAny_Event.returnValue = false;
}

function lookupItem(obj)
{
		var sCurValue = obj.getAttribute("persistValue").toLowerCase();
        var bFound = false;
        var iIndex = obj.selectedIndex;
        var iNumOptions = obj.options.length;
        var iPos = 0;
        // Repeat until found or end of list is reached
        while ((!bFound) && (iPos < iNumOptions))
        {
                // Do comparisons in lowercase
                bFound = (obj.options[iPos].text.toLowerCase().indexOf(sCurValue)==0) ;
                if (bFound)
                        iIndex = iPos;
                iPos++;
        }
        if (bFound)
                // Updated listbox
                obj.selectedIndex = iIndex;
}

/*Datagrid Specific Delete Check Box Values and Validations*/
/*----------------------------------------------------------------------------
Function Name	: DG_CheckAll
Purpose			: Call this function in the "onClick" event of chkCheckAll checkbox and 
					pass your "Form" name as parameter. 
					It will check/uncheck the chkDelete checkbox(s).
Input			: formname
Return			: values set into hidden controls
------------------------------------------------------------------------------*/
function DG_CheckAll(form,ControlName)		
{
	var strCheckValue = "";
	var isReport;
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if ((e.name != ControlName + '_chkCheckAll') && (e.type=='checkbox') && (e.name == ControlName + '_chkDelete' || e.name == 'chkReport') && (!e.disabled && !e.parentNode.disabled))
		{
			e.checked = eval('form.' + ControlName + '_chkCheckAll').checked;
			if (e.name == 'chkReport')
				isReport = true;
			else if (e.name == ControlName + '_chkDelete')
				isReport = false;
		}
	}
	//Call to set the Hidden Box Value
	if (isReport)
		setHiddenRbtnValue(form)
	else
		DG_setHiddenBoxValue(form,ControlName);
}
		
/*----------------------------------------------------------------------------
Function Name	: DG_setHiddenBoxValue
Purpose			: Call this function to set the value of the hidden text
Input			: formname
Return			: none
------------------------------------------------------------------------------*/

function DG_setHiddenBoxValue(form,ControlName)
{
	var strCheckValue = "";
	for (var i=0;i<form.elements.length;i++)
	{	
		var e = form.elements[i];
		if ((e.name != ControlName + '_chkCheckAll') && (e.type=='checkbox') && (e.name == ControlName + '_chkDelete') && (!e.disabled) && (e.checked))
		{
			if (strCheckValue == "")
			{
				strCheckValue = e.id; 
			}
			else
			{
				strCheckValue = strCheckValue + ', ' + e.id;
			}
		}
	}
	eval('document.forms[0].' + ControlName + '_hdnCheckValue').value = strCheckValue;
}

/*----------------------------------------------------------------------------
Function Name	: DG_CheckSingle
Purpose			: Call this function in the "onClick" event of every chkDelete checkbox and 
					pass your "Form" name as parameter. 
					It will check/uncheck the chkCheckAll checkbox.
Input			: formname
Return			: values set into hidden controls
------------------------------------------------------------------------------*/

function DG_CheckSingle(form,ControlName)	
{
	var TotalBoxes = 0;
	var TotalCheckedBoxes = 0;
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if ((e.name != ControlName + '_chkCheckAll') && (e.type=='checkbox') && (e.name == ControlName + '_chkDelete') && (!e.disabled))
		{
			TotalBoxes++;
			if (e.checked)
			{
				TotalCheckedBoxes++;
			}
		}
	}
	if (TotalBoxes==TotalCheckedBoxes)
	{
		eval('form.' + ControlName + '_chkCheckAll').checked=true;
	}
	else
	{
		eval('form.' + ControlName + '_chkCheckAll').checked=false;
	}
	//Call to set the Hidden Box Value
	DG_setHiddenBoxValue(form,ControlName);
}
		
/*----------------------------------------------------------------------------
Function Name	: DG_SelectedChk
Purpose			: This function is called when the user clicks on the delete link.
Input			: formname
Return			: True/False
------------------------------------------------------------------------------*/

function DG_SelectedChk(ControlName)
{
	var jsMsgDoYouWish = document.getElementById(ControlName + '_jsMsgDoYouWish').value;
	var jsMsgSelectAtLeast = document.getElementById(ControlName + '_jsMsgSelectAtLeast').value;
	if (eval('document.forms[0].' + ControlName + '_hdnCheckValue').value !="")
	{
		return confirm(jsMsgDoYouWish);
	}
	else
	{
		alert(jsMsgSelectAtLeast);
		return false;
	}
}

/*----------------------------------------------------------------------------
Function Name	: DG_SelectedChk
Purpose			: This function is called when the user clicks on the delete link.
Input			: formname
Return			: True/False
------------------------------------------------------------------------------*/

function DG_SelectedChkReport(ControlName)
{
	var jsMsgDoYouWish = document.getElementById(ControlName + '_jsMsgDoYouWish').value;
	var jsMsgSelectAtLeast = document.getElementById(ControlName + '_jsMsgSelectAtLeast').value;
	if (eval('document.forms[0].' + ControlName + '_hdnCheckValue').value !="")
	{
		//return confirm(jsMsgDoYouWish);
		return true;
	}
	else
	{
		alert(jsMsgSelectAtLeast);
		return false;
	}
}
/*----------------------------------------------------------------------------
Function Name	: ToggleDetails
Purpose			: Toggle The Details
Input			: inputElement, imgName
Return			: Nothing
------------------------------------------------------------------------------*/
function ToggleDetails(inputElement, imgName)		
{
	if (document.getElementById(inputElement).style.display == "none")
	{
		document.getElementById(imgName).src = "../images/collapse_Details.gif"
		document.getElementById(inputElement).style.display = "block";
	}
	else
	{
		document.getElementById(imgName).src = "../images/Expand_Details.gif"
		document.getElementById(inputElement).style.display = "none";
	}
}
/*----------------------------------------------------------------------------
Function Name	: ToggleDetailsNew
Purpose			: Toggle The Details
Input			: inputElement, imgName
Return			: Nothing
Author			: Manmeet Singh
Created On		: 12/02/2007
This function is used in frmNominationFormMasterDetails
------------------------------------------------------------------------------*/
function ToggleDetailsNew(inputElement, imgName)		
{
	if (document.getElementById(inputElement).style.display == "none")
	{
		document.getElementById(imgName).src = "../images/collapse_Details.gif"
		document.getElementById(inputElement).style.display = "block";
	}
	else
	{
		document.getElementById(imgName).src = "../images/Expand_Details.gif"
		document.getElementById(inputElement).style.display = "none";
	}
}