var separator = "|";


function beforeSubmitValidator(txtboxArray)
{
	var tbox = txtboxArray.split('|');
	for(var i=0; i<tbox.length; i++)
	{
		//alert(tbox[i] + "  " + i );
		var tname = tbox[i]
		var tboxOj = document.all[tname]
		tboxOj.value = tboxOj.value.replace(/&/gi, '&amp;').replace(/\"/gi, '&quot;').replace(/</gi, '&lt;').replace(/>/gi, '&gt;');
		//alert(tboxOj.value);

	}
}




function DL_Add()
{
	
	var targetList = document.all["DoubleList1_targetList"];
	var sourceList = document.all["DoubleList1_sourceList"];
	
	var hidValues  = document.all["DoubleList1_hidValues"];
	var hidText  = document.all["DoubleList1_hidText"];
	
	for (var i=0;i<sourceList.length;i++)
	{
		if (sourceList.options[i].selected)
		{
			if (targetList.length == 0)
			{
				hidValues.value += sourceList.options[i].value;
				hidText.value += sourceList.options[i].text;	
			}
			else
			{
				hidValues.value += separator + sourceList.options[i].value;
				hidText.value += separator + sourceList.options[i].text;	
			}
			targetList.options[targetList.length] = new Option(sourceList.options[i].text, sourceList.options[i].value);
		}
	}
	
	for (var i=sourceList.length-1;i>=0;i--)
	{
		if (sourceList.options[i].selected)
		{
			sourceList.options[i] = null;
		}
	}
}

function DL_Remove()
{
	var targetList = document.all["DoubleList1_targetList"];
	var sourceList = document.all["DoubleList1_sourceList"];
	
	var hidValues  = document.all["DoubleList1_hidValues"];
	var hidText  = document.all["DoubleList1_hidText"];
	
	var values = hidValues.value.split(separator);
	var text = hidText.value.split(separator);
	
	for (var i=targetList.length-1;i>=0;i--)
	{
		if (targetList.options[i].selected) 
		{	

			sourceList.options[sourceList.length] = new Option(text[i],values[i]);
			values.splice(i,1);	
			text.splice(i,1);
			targetList.options[i] = null;
		}
	}

	hidValues.value = myToString(values,separator);
	hidText.value =  myToString(text,separator); 
	
}

function DL_AddAll()
{
	var targetList = document.all["DoubleList1_targetList"];
	var sourceList = document.all["DoubleList1_sourceList"];
	
	var hidValues  = document.all["DoubleList1_hidValues"];
	var hidText  = document.all["DoubleList1_hidText"];
	
	for (var i=0;i<sourceList.length;i++)
	{
		if (targetList.length == 0)
		{
			hidValues.value += sourceList.options[i].value;
			hidText.value += sourceList.options[i].text;	
		}
		else
		{
			hidValues.value += separator + sourceList.options[i].value;
			hidText.value += separator + sourceList.options[i].text;	
		}
		targetList.options[targetList.length] = new Option(sourceList.options[i].text, sourceList.options[i].value);
	}
	
	for (var i=sourceList.length-1;i>=0;i--)
	{
		sourceList.options[i] = null;
	}
}

function DL_RemoveAll()
{
	var targetList = document.all["DoubleList1_targetList"];
	var sourceList = document.all["DoubleList1_sourceList"];
	
	var hidValues  = document.all["DoubleList1_hidValues"];
	var hidText  = document.all["DoubleList1_hidText"];
	
	for (var i=0;i<targetList.length;i++)
	{
	
		 var targetText = targetList.options[i].text
		 sourceList.options[sourceList.length] = new Option(targetText, targetList.options[i].value);
	}
	for (var i=targetList.length-1;i>=0;i--)
	{	// remove all the items from the target list
		targetList.options[i] = null;
	}
	hidValues.value = "";
	hidText.value = "";
}

function myToString(theArray,separator)
{
	var result = ""
	for (var i=0; i<theArray.length; i++)
	{
	  result += theArray[i] + separator;
	}
	result = result.substr(0,result.length - separator.length); 
	return result;
}

function searchActDir()
{
	var email = document.all.txtUserEmail.value;
	if (email == "")
	{
		alert("A Valid Email required to look up user login");
		document.all.txtUserEmail.focus();
	}
	else
	{
		document.all.hidAction.value = "searchActDir";
		document.forms[0].submit();
	}
}

function veiwThumbnail()
{
	document.all.imgUserImage.src = document.all.staffFile.value;
}

function GoAdmin()
{
	document.location = "StaffIndexAdmin.aspx";
}

function DeleteUser()
{
	var user  = document.all.ddUsername.value;
	
	if (user == "[Add New User]")
		alert(" There is no user selected. Action Aborted. ");
	else
	if(confirm("Are you sure wish to delete this User?"))
	{
		document.all.hidAction.value = "deleteUser";
		document.forms[0].submit();
	}
}

function InstVisible(id,imgID)
{
	try
	{
		if (document.all[id].style.display == "none") // if closed then open
		{
			document.all[id].style.display = "inline"
			document.all[imgID].src = "images/minus.gif"; 

		}
		else  // if open then close
		{
			document.all[id].style.display = "none"
			document.all[imgID].src = "images/plus.gif"; 
			
		}

	}
	catch(e)
	{
		alert(e.message);
		document.location.href = document.location.href;
	}
}

function NewUser()
{
	document.location = "StaffIndexAdmin.aspx?login=[Add New User]";
}