////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function loadEditor(iPage)
{
	if(parseInt(iPage,10) == 0)
	{
		EnableWebEditor();
	}

}

function loadEditorImage(iPage)
{
	if(parseInt(iPage,10) == 0)
	{
		EnableWebEditor_Img();
	}

}

function openSearchWindow(file)
{
	var iWidth = 500, iHeight = 500;
	window.open(file,"Search" ,"toolbar=no,scrollbars=yes,resizable=yes,width=" +iWidth + ",height=" + iHeight).focus();
}

function openCustomWindow(file, iWidth, iHeight)
{
	window.open(file,"Search" ,"toolbar=no,scrollbars=yes,resizable=yes,width=" +iWidth + ",height=" + iHeight).focus();
}
function openNewWindow(file, Title)
{
	var iWidth = 500, iHeight = 600;
	window.open(file,Title ,"toolbar=no,scrollbars=yes,resizable=yes,width=" +iWidth + ",height=" + iHeight).focus();
}

function openCalendarWindow(file, Title)
{
	var iWidth = 500, iHeight = 600;
	window.open(file,Title ,"toolbar=no,scrollbars=yes,resizable=yes,width=" +iWidth + ",height=" + iHeight).focus();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function resetNumberTextBox(target, defaultValue)
{
	if(isNaN(target.value))
	{
		target.value = defaultValue;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function changeComboBox(target, queryKey, queryValue, strUrl)
{	
	var strAppend = "?";
	if(strUrl.indexOf("?") > 0)
	{
		strAppend = "&";
	}
	if(strUrl.indexOf(queryKey + "=") > 0)
	{

		strUrl = strUrl.replace(queryKey + "=" + queryValue, queryKey + "=" + target.value);
				
	}
	else
	{
		strUrl = strUrl + strAppend + queryKey + "=" + target.value;
		
	}
	window.location.href=strUrl;
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Check All function
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function checkAll(coltrolName, target)
	{
		var iIndex = 1;
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if ((e.name == coltrolName) && (e.disabled == false))
			{
				e.checked = target.checked;
				var trRow = document.getElementById("trRow" + iIndex);
				if(target.checked)
				{
					trRow.bgColor = "#EFEFEF";
				}
				else
				{
					trRow.bgColor = "#FFFFFF";
				}
			}
			if ((e.name == coltrolName))
			{
				iIndex++;
			}
		}
	}
	
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function checkSelect(target, iIndex)
	{
		var trRow = document.getElementById("trRow" + iIndex);
		if(target.checked)
		{
			trRow.bgColor = "#EFEFEF";
		}
		else
		{
			trRow.bgColor = "#FFFFFF";
		}
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Check All function
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function checkAllEx(coltrolName, target, checkColor, normalColor)
	{
		var iIndex = 1;
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if ((e.name == coltrolName) && (e.disabled == false))
			{
				e.checked = target.checked;
				var trRow = document.getElementById("trRow" + iIndex);
				if(target.checked)
				{
					trRow.bgColor = checkColor;
				}
				else
				{
					trRow.bgColor = normalColor;
				}
			}
			if ((e.name == coltrolName))
			{
				iIndex++;
			}
		}
	}
	
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function checkSelectEx(target, iIndex, checkColor, normalColor)
	{
		var trRow = document.getElementById("trRow" + iIndex);
		if(target.checked)
		{
			trRow.bgColor = checkColor;
		}
		else
		{
			trRow.bgColor = normalColor;
		}
	}
		
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function linkMessage(strMessage, strUrl)
	{
		if(confirm(strMessage))
		{
			window.location.href=strUrl;
		}
	}
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function checkSelectIScore(target, iIndex, controlID)
	{
		var textbox = document.getElementById(controlID + iIndex);
		if(target.checked)
		{
			//textbox.disabled = false;
		}
		else
		{
			//textbox.disabled = true;
		}
	}
	
	function changeProgramSubmit()
								{
									document.frmForm.hSubmit.value = "Submit";
									document.frmForm.submit();
								}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function URLEncode(str)
	{
		var ms = "%25#23 20?3F<3C>3E{7B}7D[5B]5D|7C^5E~7E`60+2B"
		var msi = 0
		var i,c,rs,ts
		while (msi < ms.length)
		{
			c = ms.charAt(msi)
			rs = ms.substring(++msi, msi +2)
			msi += 2
			i = 0
			while (true)
			{
				i = str.indexOf(c, i)
				if (i == -1) break
				ts = str.substring(0, i)
				str = ts + "%" + rs + str.substring(++i, str.length)
			}
		}
		return str
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function deleteMe(itemTitle, itemTitles)
	{
		var count = 0;
		var strAlert = "";
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if (e.name == "ckSelect[]" && e.checked == true)
			{
				count++;
			}
		}
		if (count > 0)
		    return confirm("You are about to delete " + count + " selected " + itemTitles + ". Do you wish to continue?")				
		else
		{
			alert("You must select at least one " + itemTitle + " to delete!");
			return false;
		}
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function deleteMeWithAlert(itemTitle, itemTitles, itemFieldName, itemCountName, itemTitleSub)
	{
		var count = 0;
		var strAlert = "";
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if (e.name == "ckSelect[]" && e.checked == true)
			{
				var itemCount = document.getElementById(itemCountName + "_" + e.value).value;
				if(parseInt(itemCount,10) > 0)
				{
					var itemName = document.getElementById(itemFieldName + "_" + e.value).value;
					strAlert = strAlert + itemTitle + " (" + itemName + ") already has " + itemTitleSub + ". Please deselect it!\n"
				}
				count++;
			}
		}
		if (count > 0)
			if(strAlert != "")
			{
				alert(strAlert);
				return false;
			}
			else
			{
			    return confirm("You are sure to delete " + count + " selected " + itemTitles + ". Do you wish to continue?")				
			}
		else
		{
			alert("You must select at least one " + itemTitle + " to delete!");
			return false;
		}
	}
	
	
	function deleteMeWithAlertEx(itemTitle, itemTitles, itemFieldName, itemCountName, itemTitleSub)
	{
		var count = 0;
		var strAlert = "";		
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if (e.name == "ckSelect[]" && e.checked == true)
			{				
				var itemCount = document.getElementById(itemCountName + "_" + e.value).value;
				if(parseInt(itemCount,10) > 0)
				{
					var itemName = document.getElementById(itemFieldName + "_" + e.value).value;
					strAlert = strAlert + itemTitle + " (" + itemName + ") already has " + itemTitleSub + ". Please deselect it!\n"
				}
				count++;
			}
		}
		
		if (count > 0)
			if(strAlert != "")
			{
				alert(strAlert);
				return false;
			}
			else
			{
			    return confirm("You are sure to delete " + count + " selected " + itemTitles + ". Do you wish to continue?")				
			}
		else
		{
			alert("You must select at least one " + itemTitle + " to delete!");
			return false;
		}
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function deleteMeWithAlertAttribute(itemTitle, itemTitles, itemFieldName, itemCountName, itemTitleSub)
	{
		var count = 0;
		var strAlert = "";
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if (e.name == "ckSelect[]" && e.checked == true)
			{
				var itemCount = document.getElementById(itemCountName + "_" + e.value).value;
				
				if(parseInt(itemCount,10) > 0)
				{
					var itemName = document.getElementById(itemFieldName + "_" + e.value).value;
					strAlert = strAlert + itemTitle + " (" + itemName + ") is used for " + itemTitleSub + ". Please deselect it!\n"
				}
				count++;
			}
		}
		if (count > 0)
			if(strAlert != "")
			{
				alert(strAlert);
				return false;
			}
			else
			{
			    return confirm("You are about to delete " + count + " selected " + itemTitles + ". Do you wish to continue?")				
			}
		else
		{
			alert("You must select at least one " + itemTitle + " to delete!");
			return false;
		}
	}	
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function changeStatus(statusTitle, itemTitle)
	{
		var count = 0;
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if (e.name == "ckSelect[]" && e.checked == true)
				count++;
		}
		if (count > 0){
			return true;
		}
		else
		{
			alert("You must select at least one " + itemTitle + " to set " + statusTitle + "!");
			return false;
		}
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function changeFeatured(statusTitle, itemTitle)
	{
		var count = 0;
		for (i = 0; i < document.frmForm.elements.length; i++)
		{	
			e = document.frmForm.elements[i];
			if (e.name == "ckSelect[]" && e.checked == true)
				count++;
		}
		if (count > 0){
			return true;
		}
		else
		{
			alert("You must select at least one " + itemTitle + " to " + statusTitle + "!");
			return false;
		}
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
