﻿function OpenWindow(theURL, W, H,  leftWindow, topWindow, isScroll)
{ 
	var windowW = W;
	var windowH = H;

	var windowX = leftWindow;
	var windowY = topWindow;
	if ((windowX == null) || (windowX == '')) {
		var windowX = 200;
	}
	if ((windowY == null) || (windowY == '')) {
		var windowY = 80;
	}
	s = ",width="+W+",height="+H;
	
	//if ( ! HasNewWin )
	//{
		var NewWin = window.open(theURL, "ModalChild", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+isScroll+",left="+windowX+",top="+windowY+",resizable=0"+s, true);
		NewWin.name = "NewWindow";
		NewWin.focus();
		//HasNewWin = true;
	//}
}

function OpenWindow2(theURL, W, H,  leftWindow, topWindow, isScroll)
{ 
	var windowW = W;
	var windowH = H;

	var windowX = leftWindow;
	var windowY = topWindow;
	if ((windowX == null) || (windowX == '')) {
		var windowX = 200;
	}
	if ((windowY == null) || (windowY == '')) {
		var windowY = 80;
	}
	s = ",width="+W+",height="+H;
	
	//if ( ! HasNewWin )
	//{
		var NewWin = window.open(theURL, "ModalChild2", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+isScroll+",left="+windowX+",top="+windowY+",resizable=0"+s, true);
		NewWin.name = "NewWindow2";
		NewWin.focus();
		//HasNewWin = true;
	//}
}

function EnableNewWin()
{
	alert(HasNewWin);
	HasNewWin = false;
}
function DisableNewWin()
{
	alert(HasNewWin);
	HasNewWin = true;
}
/* 
	Function: 	ClearSEField
	Arguments: 	textFieldName, dataFieldName
	clear search engine fileds
*/
function ClearSEField( textFieldName, dataFieldName )
	{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}		
	var theTextField = eval("theform." + textFieldName );
	theTextField.value = "";
	var theValueField = eval("theform." + dataFieldName );
	theValueField.value="";
}

/* 
	Function: 	ClearDateField
	Arguments: 	dataFieldName
	clear date fileds
*/
function ClearDateField( dataFieldName )
	{
	
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}		

	for (i=0;i<theform.length;i++)
	{
		if ( theform[i].name.indexOf( dataFieldName ) != -1 )
		{
			theform[i].value = "";
		}
	}

}


/* 
	Function: 	myFormSubmit
	Arguments: 	
	Submit the form
*/
function myFormSubmit()
	{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}
	theform.submit();
}


/* 
	Function: 	myFormReset
	Arguments: 	
	Reset the form
*/
function myFormReset()
	{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}
	
	theform.reset();
}

/* 
	Function: 	DeleteConfirm
	Arguments: 	
	return true / false
*/
function DeleteConfirm()
	{
	if ( confirm('Are you sure?') ) {
		return true;
	}
	else {
		return false;
	}
}


/* 
	Function: 	ActivateConfirm
	Arguments: 	
	return true / false
*/
function ActivateConfirm()
	{
	if ( confirm('Are you sure?') ) {
		return true;
	}
	else {
		return false;
	}
}

/* 
	Function: 	deleteSelectedItemsFromList
	Arguments: 	sourceList
*/
function deleteSelectedItemsFromList( sourceList ) 
{
	var maxCnt = sourceList.options.length;
	for(var i = maxCnt - 1; i >= 0; i--) 
	{
		if ((sourceList.options[i] != null) && (sourceList.options[i].selected == true)) 
		{
			sourceList.options[i] = null;
		}
	}
}
/* 
	Function: 	selectList
	Arguments: 	sourceList
*/
function selectList( sourceList ) 
{
	for(var i = 0; i < sourceList.options.length; i++) 
	{
		if (sourceList.options[i] != null)
			sourceList.options[i].selected = true;
	}
return true;
}

function selectItemfromList( sourceList, item ) 
{
	for(var i = 0; i < sourceList.options.length; i++) 
	{
		if (sourceList.options[i] != null && sourceList.options[i].value == item )
			sourceList.options[i].selected = true;
			break;
	}
return true;
}
/* 
	Function: 	addToList
	Arguments: 	sourceList
*/
function addToList( destinationList, itemText, itemValue ) 
{
	var found = false;
	//var destinationList = window.document.forms['MainForm'].CategoryFirm;
	var len = destinationList.length;	
	for(var count = 0; count < len; count++) 
	{
		if (destinationList.options[count] != null) 
		{
			if ( destinationList.options[count].value == itemValue ) 
			{
				found = true;
				break;
			}
		}
	}
	
	if ( found )
		return;	
	
	destinationList.options[len] = new Option( itemText, itemText + '^' + itemValue );
}

/* 
	Function: 	GetCtrlFullName
	Arguments: 	theobject, objectid
*/
function GetCtrlFullName( searchCtrl) 
{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}
	
	try
	{
		for (i=0;i<theform.length;i++)
		{
			if ( theform[i].name.indexOf( searchCtrl ) != -1 )
			{
				return theform[i].id;
			}
		}
	}
	catch (e)
	{
		return "";
	}
}

/* 
	Function: 	myFormSetFocus
	Arguments: 	
	Set focus on the form element
*/
function myFormSetFocus( objid )
	{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms[0];
	}
	else {
		theform = document.MainForm;
	}
	var theObject = eval("theform." + objid );
	if (theObject) theObject.SetFocus();
}
