/*	=====================================================================
	Digital Alias Global JavaScript Module
		
	For more information on how Digital Alias can help you, please visit us on the WWW at
	http://www.digitalalias.net
	
	JavaScript portions of this software are available as freeware from Digital Alias.  You must keep this 
	comment unchanged in your code.  For more information contact info@digitalalias.net. 
	
	JavaScript Module, V.1.2.0
	===================================================================== */

/*	---------------------------------------------------------------------
	Global Options
	--------------------------------------------------------------------- */
	var strUri = "";
	
	if(document.URL.indexOf("localhost") != -1) {
		strUri = "/flmedpro";
	}
	
	
/*	---------------------------------------------------------------------
	END Global Options
	--------------------------------------------------------------------- */

	
/*	=====================================================================
	BELOW THIS LINE ARE CUSTOM FUNCTIONS
	===================================================================== */


/*	---------------------------------------------------------------------
	FUNCTION:			Null
	PARAMETERS:		Null
	RETURNS:			Null
	PURPOSE:			Null
	---------------------------------------------------------------------*/
	
/*	---------------------------------------------------------------------
	FUNCTION:			HideItem
	PARAMETERS:		Object name (string)
	RETURNS:			Null
	PURPOSE:			Hide/show object via on Display Style
	---------------------------------------------------------------------*/
	function HideItem(obj) {
		obj = document.getElementById(obj);
		
		if(obj.style.display == "inherit" || obj.style.display == "") {
			obj.style.display = "none";
		} else {
			obj.style.display = "inherit";
		}
	}


/*	---------------------------------------------------------------------
	FUNCTION:			PopUpRet
	PARAMETERS:		Null
	RETURNS:			Null
	PURPOSE:			Null
	---------------------------------------------------------------------*/
	function PopUpRet(strType, strFields) {
		var strThisUri = strUri+"/db/modules/popupret/index.php?typ="+strType+"&flds="+strFields;
		var newWin = window.open(strThisUri, "pop_"+strType, "width=410,height=200,scrollbars,resizable");	
		newWin.focus();
	}
	

/*	---------------------------------------------------------------------
	FUNCTION:			Redirect
	PARAMETERS:		URL to redirect to (string)
	RETURNS:			Null
	PURPOSE:			Redirect the user to a desired page
	---------------------------------------------------------------------*/
function Redirect(strURL) {
	document.location = strUri+"/"+strURL;
}


/*	---------------------------------------------------------------------
	FUNCTION:			SelectAll
	PARAMETERS:		Name of the checkbox set (string)
	RETURNS:			Null
	PURPOSE:			Selects or deselects all checkboxes on the page
	---------------------------------------------------------------------*/
	function SelectAll(strCB) {
		var objEl;						// object/html element
		var blnChecked = false;	// checked status
		var intI = 0;					// loop counter
		
		// check if the checkbox set isSet
		if(strCB != "") {
			// determine the check procedure based on the first checkbox
			objEl = document.getElementById(strCB+"0");
			if(objEl.checked) {
				blnChecked = true;
			}
		
			if(objEl != null) {
				while(objEl != null) {
					objEl.checked = !blnChecked;
				
					intI++;
					objEl = document.getElementById(strCB+intI);
				}
			}
		} else {
			alert("There is no targetted checkbox ID set.  Please recheck the onclick event.");
		}
	}
	
	
/*	---------------------------------------------------------------------
	FUNCTION:		Validate
	PARAMETERS:	Form object (object)
	RETURNS:			Null
	PURPOSE:			Validates the fields on the form for proper data
	---------------------------------------------------------------------*/
	function Validate(frm) {
		strReturn = true;
		strError = strName = strErrorName = "";
		
		for(i = 0; i < frm.elements.length; i++) {
			el = frm.elements[i];
			
			if(el.getAttribute("intReq")) {
				switch(el.type) {
					case "textarea":
					case "text":
						if(el.value == "") {
							strReturn = false;

							strName = el.name.replace(/_/g, " ");							
							strError += strName.toUpperCase()+" - The value cannot be empty.\n";
						}
						break;
					case "select-one":
						if(el.options[el.selectedIndex].value == "") {
							strReturn = false;
							
							strName = el.name.replace(/_/g, " ");							
							strError += strName.toUpperCase()+" - A value must be selected.\n";
						}
						break;
				}
			}
		}
		
		if(!strReturn) {
			alert(strError);
		}
		
		return strReturn;
	}
	
/*	---------------------------------------------------------------------
	Start-up Functions
	--------------------------------------------------------------------- */
	
/*	=====================================================================
	END Digital Alias Global JavaScript Module
	===================================================================== */