//------------------------- openWindow ---------------------------
function openWindow(url) {
  popupWin = window.open(url, 'new_page', 'width=500,height=500');
}

function openPopupWindow(url, target, param) {
  popupWin = window.open(url, target, param);
}

//------------------------- checkMandatory ---------------------------
function checkMandatory(inField,inFieldDisplay) 
{ 
    // Check the field in not empty
    //
    if (inField.value.length == 0)
    {
        alert("Please enter a value for the " + inFieldDisplay + ".")
        inField.focus()
        return false
    }
    else
    { return true
    }
}

//------------------------- checkSelectMandatory ---------------------------

function checkSelectMandatory(inField,inFieldDisplay) 
{ 
    // Check the field in not empty
    //
    if (inField.value == 'null')
    {
        alert("Please select a value for the " + inFieldDisplay + ".")
        inField.focus()
        return false
    }
    else
    { return true
    }
}

//------------------------- checkInteger ---------------------------
function checkInteger(field, fieldName, decallowed) 
{
	if (isNaN(field.value) ) {
		// --- That does not appear to be a valid number
		    alert(fieldName+" must be integer.")
			field.focus();
			return false;
	}
	else {
		if ( field.value.indexOf('.') != -1 & decallowed==0 ) {
			// --- That does not appear to be a valid number
			    alert(fieldName+" must be integer.")
				field.focus();
				return false;
		}
		else{
				return true;
		}
		
	}
}

//------------------------- checkNumber ---------------------------
function checkNumber(fieldName, fieldValue, decallowed) 
{
	if (isNaN(fieldValue) ) {
		// --- That does not appear to be a valid number
			fieldName.value = fieldName.value.substr(0, (fieldName.value.length-1));
			fieldName.focus();
			return false;
	}
	else {
		if ( fieldValue.indexOf('.') != -1 & decallowed==0 ) {
			// --- That does not appear to be a valid number
				fieldName.value = fieldName.value.substr(0, (fieldName.value.length-1));
				fieldName.focus();
				return false;
		}
		else{
			if (fieldValue.indexOf('.') == -1) fieldValue += ".";
			dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
		
			if (dectext.length > decallowed)
			{
				//--- a number with up to " + decallowed + " decimal places
				fieldName.value = fieldName.value.substr(0, (fieldName.value.length-1));
				fieldName.focus();
				return false;
			}
			else {
				return true;
			}
		}
	}
}

//------------- labelClick -----------------
// A radio button associated with this label
// use : <INPUT id=RadioButtonid type=radio name=radio1 CHECKED>
//		 <span name='lb_RadioButtonid' onClick='labelClick( this )'> Check One </span>		 
function labelClick ( sentObj )
{
	// What is this guys name
	objName = sentObj.name;

	// Strip off 'lb_'
	objName = objName.substr(3, objName.length);

	// click on the corrosponding check box
	ckObj = eval ( 'document.all.' + objName );
	ckObj.click();
	ckObj.blur();
}

//------------------------- printPage ---------------------------
function printPage() {
	if (window.print) {
		window.print();		
		//closeme();
	}
}

function focusAndSelectAll(inTextElement)
// Gives the focus on the specified text element and selects the whole
// contents.
// DP, 13-aug-2001.
{
	inTextElement.focus();
	inTextElement.select();
}

//------------------------- QueryString ---------------------------
function getQueryStringParam(inParam, inSourceString)
// Private function for the function "QueryString(inParam)"
//
// Extracts the value of the specified param from the specified source
// string. Using this function makes sense only if <inSourceString> is
// either <self.location.search> or <self.location.hash>.
// Returns null if not found.
//
// Note: may return the empty string if the param is found but has an empty value.
//
// DP, 30-aug-2001.
{
	var theValue;
	
	if (inSourceString.length > 1) {
		var theParamPosition = inSourceString.indexOf(inParam);
		
		if (theParamPosition != -1) {
			var begin = theParamPosition + inParam.length + 1;
			
			// Search till the next param or the end of string.
			var end = inSourceString.indexOf("&", begin);
			if (end == -1) {
				end = inSourceString.length;
			}
			
			theValue = inSourceString.substring(begin, end);
		} else {
			// Param not found.
			theValue = null;
		}
	} else {
		// Empty source string ==> can't find the param.
		theValue = null;
	}
	
	//alert(theValue);
	
	return theValue;
}

function QueryString(inParam)
// Extracts the value of the specified param from the query part of the URL of the
// current window.
// Returns null if not found.
//
// Note: may return the empty string if the param is found but has an empty value.
//
// DP, 30-aug-2001.
{
	//alert("inParam = [" + inParam + "], search = [" + self.location.search + "], hash = [" + self.location.hash + "]");
	
	// First try in the <search> property.
	var theValue = getQueryStringParam(inParam, self.location.search);
	
	// If not found, try again in the <hash> property.
	// ### Note from DP: I don't know why we should search there too.
	//     This is a remnant from the old version of this function
	//     ==> commented out.
	/*if (theValue == null) {
		theValue = getQueryStringParam(inParam, self.location.hash);
	}*/
	
	//alert("theValue = " + (theValue == null ? "null" : ("[" + theValue + "]")));
	
	return theValue;
}

