/*
Date Created : 22nd May 2003
Function : CheckExistsElement
Input : 
strTypeByPass - a list of element type for by passing
strType - a element type for comparing

Output:
return true is match with the item for by passing else return false
*/
function CheckExistsElement(strTypeByPass, strType){
	var arrTypeByPass;
	if ( strTypeByPass != "" ){
		arrTypeByPass	=	_Split(strTypeByPass, ",");
		for(var j=0; j < arrTypeByPass.length; j++){
			if (strType == arrTypeByPass[j]){
				return true;
				break;
			}
		}
	}
	return false;
}


/*
Date Created : 22nd May 2003
Function : CountNonEmptyFormElement
Input :
strFormName - form name
strTypeByPass - Element type for not counting

Output:
return number of non empty field 
*/

function CountNonEmptyFormElement(strFormName, strTypeByPass){
	var objForm	= eval("document." + strFormName);
	var lngLength = objForm.length;
	var lngCounter = 0;
	var strValue;
	var strType;
	var strEmptyValue;
	
	for (var i=0; i < lngLength; ++i)
	{
		strType = objForm.elements[i].type;
		strEmptyValue = GetEmptyValueFormElementType(strType);
		strValue = objForm.elements[i].value;
		if (strValue != strEmptyValue){
			if (!CheckExistsElement(strTypeByPass, strType)){
				lngCounter = lngCounter + 1;
			}
		}
		
	}
	return lngCounter;
}


// function to get form element type 
// return Form Element Type 
function GetFormElementType(strFormName, strFieldName){
	var objForm = eval('document.' + strFormName);
	var objField = eval('objForm.' + strFieldName)
	var strFormElementType = objField.type;
}

// function to return empty value based on Form Element Type 
function GetEmptyValueFormElementType(strFormElementType){
	var strEmptyValue;
	if ( (strFormElementType == "radio") || (strFormElementType == "checkbox") ){
		strEmptyValue	=	false;
	}
	// Text field or TextArea 
	else if ( (strFormElementType == "text") || (strFormElementType == "textarea") || (strFormElementType == "password") ) {
		strEmptyValue	=	"";
	}
	// Selection - one
	else if ( strFormElementType == "select-one" ){
		strEmptyValue	=	0;
	}
	// Selection - multiple 
	else if ( strFormElementType == "select-multiple" ){
		strEmptyValue	=	-1;
	}
	return strEmptyValue;
}


// ValueComparator - check value if fullfill the condition, return false. 
// intMode - 
// 1 = Equal, 
// 2 = Not Equal, 
// 3 = GreaterThan, 
// 4 = GreaterThanEqual, 
// 5 = Less Than,
// 6 = LessThanEqual
function ValueComparator(strFieldValue, strCompareValue, strErrorMessage, intMode){
	strFieldValue		=	parseFloat(strFieldValue);
	strCompareValue		=	parseFloat(strCompareValue);
	
	if (intMode == 1){
		if (strFieldValue == strCompareValue){
			alert(strErrorMessage);
			return false;
		}
	}else if(intMode == 2){
		if (strFieldValue != strCompareValue){
			alert(strErrorMessage);
			return false;
		}
	}else if(intMode == 3){
		if (strFieldValue > strCompareValue){
			alert(strErrorMessage);
			return false;
		}
	}else if(intMode == 4){
		if (strFieldValue >= strCompareValue){
			alert(strErrorMessage);
			return false;
		}
	}else if(intMode == 5){
		if (strFieldValue < strCompareValue){
			alert(strErrorMessage);
			return false;
		}
	}else if(intMode == 6){
		if (strFieldValue <= strCompareValue){
			alert(strErrorMessage);
			return false;
		}
	}
	return true;
}

// Compare String
function StringValueComparator(strFieldValue, strCompareValue, strErrorMessage, intMode){
	if (intMode == 1){
		if (strFieldValue == strCompareValue){
			alert(strErrorMessage);
			return false;
		}
	}else if(intMode == 2){
		if (strFieldValue != strCompareValue){
			alert(strErrorMessage);
			return false;
		}
	}
	return true;
}


// function to close the opener
function BackAndClose () {
	if (!opener.close) {
		opener.focus ();
	}
	// closing self in 0.25 seconds
	setTimeout ('self.close ();', 250);
}

// Function to set checkbox to false 
// mode 1 - true
// else false 
function SetCheckbox(strFormName, strFieldName, intMode, strErrorMessage){
	var objForm		= eval( "document." + strFormName );
	var objField	= eval( "objForm." + strFieldName );
	
	if (strErrorMessage != ""){
		alert(strErrorMessage);
	}
	
	var blnCheckbox;
	if ( intMode	== 1 ){
		blnCheckbox = true;
	}else{
		blnCheckbox = false;
	}
	
	var intLengthOfCheckbox	=	objField.length;
	var intCounter;
	if ( intLengthOfCheckbox > 0 ) {
		for ( intCounter = 0; intCounter < intLengthOfCheckbox; intCounter++ ) {
			objCheckboxField = eval( "objForm." + strFieldName + "[" + intCounter + "]");
			objCheckboxField.checked	=	blnCheckbox;
		}
	}else{
		objField.checked	=	blnCheckbox;
	}
}

// Function Name : onLoadFocus
// Objective : Function to focus the selected field after the webpage finishes loading.
function onLoadFocus(objField){
	_FocusElement(objField);
}



