﻿///////////////////////////////////////////////////////////////////////
/////////////////////JAVA SCRIPT FORM INTERACTIONS/////////////////////
///////////////////////////////////////////////////////////////////////
/////////////////////functions/////////////////////////////////////////
//addToList(ItemID, ItemTitle, obj)
//show_hide(table)
///////////////////////////////////////////////////////////////////////
//this function should add items to list box
//parameter:
// itemID : (string) option value
//itemTitle : (string) option text
//obj : (object) reference to drop down list box
//selectAll (optional): (boolean) if true make all items in list box selected after adding new items
function addToList(ItemID, ItemTitle, obj){
	obj.options.length++;
	obj.options[obj.options.length-1].text = ItemTitle;
	obj.options[obj.options.length-1].value = ItemID;
	if (addToList.arguments.length >= 4){
		if (addToList.arguments[3] == true){
			if (obj.multiple){
				obj.item(obj.length - 1).selected = true;
			}//if (objListName.multiple)
		}//if (addToList.arguments[3] == true)
	}//if (addToList.arguments.length == 4)
}
//////////////////////////////////////////////////////////////////////
//this function should delete selected items from list box
//parameter:
//obj : (object) reference to drop down list box
//selectAll (optional): (boolean) if true make all items in list box selected after adding new items
function RemoveSelected(obj){
	for(i=0 ; i<obj.options.length ; i++)
	{
		if (obj.options[i].selected)
		{
			obj.options.remove(i);
		}//end of if
	}//end of for
	if (RemoveSelected.arguments.length >= 2){
		if (RemoveSelected.arguments[1] == true){
			if (obj.multiple){
				obj.item(obj.length - 1).selected = true;
			}//if (objListName.multiple)
		}//if (addToList.arguments[3] == true)
	}//if (addToList.arguments.length == 4)
}
/////////////////////////////////////////////////////////////////////////
//select all item in a multiple selection list
//////////////////////////////////////////////////////////////////////////
function SelectAllListItem(obj)
{
	if (obj.multiple &&  obj.length>=1){
		obj.item(obj.length - 1).selected = true;
	}//if (objListName.multiple)
}
///////////////////////////////////////////////////////////////////////
//this function should delete an item from list box
//parameter:
//obj : (object) reference to drop down list box
//nIndex : (int) index of item that should be deleted
//selectAll (optional): (boolean) if true make all items in list box selected after adding new items
function RemoveItemFromList(obj,nIndex)
{
	obj.options.remove(nIndex);
	if (RemoveItemFromList.arguments.length >= 2){
		if (RemoveItemFromList.arguments[1] == true){
			if (objListName.multiple){
				obj.item(obj.length - 1).selected = true;
			}//if (objListName.multiple)
		}//if (addToList.arguments[3] == true)
	}//if (addToList.arguments.length == 4)
}
///////////////////////////////////////////////////////////////////
//show_hide form objects
function show_hide(table)
{

	if(eval("document.all."+table+".style.display =='none'"))
	{
			eval("document.all."+table+".style.display=''");
	}
	else if(eval("document.all."+table+".style.display ==''"))
	{
		eval("document.all."+table+".style.display='none'");
	}
}
//////////////////////////////////////////////////////////////
//show_hide objects
function ShowHideObjects(obj){
	if(obj.style.display == 'none')
	{
			obj.style.display = '';
	}
	else if(obj.style.display == '')
	{
		obj.style.display = 'none';
	}
}
////////////////////////////////////////////////////////////
//show objects
function Show(obj){
			obj.style.display = '';
}
////////////////////////////////////////////////////////////
//show_hide objects
function Hide(obj){
		obj.style.display = 'none';
}
/////////////////////////////////////////////////////////////

//enable object
function Enable(obj){
	obj.disabled = false;
}
////////////////////////////////////////////////////////////
//enable many objects at a time
//parameters:
//objArray : (array of objects) objects that will be enabled
function MultipleEnable(objArray){
	for(i=0;i<objArray.length;i++)
	{
		Enable(objArray[i]); 
	}
}
////////////////////////////////////////////////////////////
//disable object
function Disable(obj){
	obj.disabled = true;
}
////////////////////////////////////////////////////
//disable many objects at a time
function MultipleDisable(objArray){
	for(i=0;i<objArray.length;i++)
	{
		Disable(objArray[i]); 
	}
}
///////////////////////////////////////////////////
//Enable/Disable users detail according to selected userType
//(mainly called from userControls/adUserForm.ascx and userControl/ModifyUserForm.ascx)
//parameters:
//DropListObject : (object) reference to ComboBox object
//StartIndex : (int) start index of details that will take the effect
function EnableDisableDetails(DropListObject,StartIndex){
	if(DropListObject != null)
	{
		//the starting index of dynamic details
		var formIndex = StartIndex;
		//in this loop we check if detail UserTypeID equals the selected UserType
		//if true: enable the field
		//otherwise : disable the field
		//NOTE:"UserTypeArray" is made dynamically from ASP.NET code
		for(ArrayIndex=0;ArrayIndex<UserTypeArray.length;ArrayIndex++)
		{
			if (DropListObject.value == UserTypeArray[ArrayIndex]  || UserTypeArray[ArrayIndex] == "0")
			{
				Enable(document.forms.item(0).item(formIndex));
			}
			else
			{
				Disable(document.forms.item(0).item(formIndex));
			}//end of if
			//increase the "formIndex" to goto next field
			formIndex++;
		}  //end of for
	}//end of if
}
//////////////////////////////////////////////////////////////////////////////////
function SetValueToParentField( FormField , strValue){
	try{
		FormField.value = strValue;
	}
	catch(e){}
}
///////////////////////////////////////////////////////////////////////////////////
function OpenBrowseWindow(objTextBox,TreeTypeID,objLabel,ReturnFullPath){
	window.open('default.aspx?action=NEST&TreeTypeID='+TreeTypeID+'&ReturnFullPath='+ReturnFullPath+'&ShowInterface=FALSE&ReturnTo='+objTextBox+'&ReturnToLabel='+objLabel,null,"height=250,width=400,status=yes,toolbar=no,scrollbars=yes ,menubar=no,location=no");
}
////////////////////////////////////////////////////////////////////////////////////
function OpenBrowseWindowWithoutRetuningTheName(objTextBox,TreeTypeID,ReturnFullPath){
	window.open('default.aspx?action=NEST&TreeTypeID='+TreeTypeID+'&ReturnFullPath='+ReturnFullPath+'&ShowInterface=FALSE&ReturnTo='+objTextBox,null,"height=250,width=400,status=yes,toolbar=no,scrollbars=yes ,menubar=no,location=no");
}
///////////////////////////////////////////////////////
function OpenBrowseWindowToReturnValueAndText(objTextBox,TreeTypeID,objLabel,ReturnFullPath){
	window.open('default.aspx?action=NEST&TreeTypeID='+TreeTypeID+'&ReturnFullPath='+ReturnFullPath+'&ShowInterface=FALSE&ReturnTo='+objTextBox+'&ReturnToLabel='+objLabel,null,"height=250,width=400,status=yes,toolbar=no,scrollbars=yes ,menubar=no,location=no");
}
////////////////////////////////////
function OpenChildWindow( URL ){
try{
	window.open( URL  ,null,"height=400,width=500,status=yes,toolbar=no,scrollbars=yes ,menubar=no,location=no");
	}
catch(e){}	
}