
function setFieldValue(oField, strFieldName) {

	with (oField) {
		value = strFieldName;
		form.submit();
	}

	return false;

}

function submitForm(oForm) {
	with (oForm) {

		for (var i = 0; i < elements.length; i++) {
			elements[i].disabled = (elements[i].type == 'button' || elements[i].type == 'submit');
		}
		
		submit();

	}
}

function setFocus(blnFocusWithValue) {

	var blnSet = false;
	var oForms = document.forms;
	var oElems;

	for (var f = 0; f < oForms.length; f++) {
		oElems = oForms[f].elements;
		for (var e = 0; e < oElems.length; e++) {
			with (oElems[e]) {

				if ((type == 'text' || type == 'textarea' || type == 'password') && !blnSet && !readOnly && (blnFocusWithValue || value.length == 0)) {
					try {
						focus();
						blnSet = true;
					} catch (oError) {
						blnSet = false;
					}
				}

			}
		}
	}
	
	if (!blnSet && !blnFocusWithValue) setFocus(true);

}

var oHTTP;
var blnHTTP = false;

function setHTTP() {
	
	try {
		oHTTP = new ActiveXObject('Microsoft.XMLHTTP');
		blnHTTP = true;
	} catch (oError) {
		try {
			oHTTP = new XMLHttpRequest();
			blnHTTP = true;
		} catch (oError) {
			blnHTTP = false;
		}
	}
	
	return blnHTTP;
		
}

function checkHTTP(oField, strError) {

	var blnReturn = true;

	if (blnHTTP) {
		with (oHTTP) {
			open('GET', document.location.protocol + '//' + document.location.host + document.location.pathname.substr(0, document.location.pathname.indexOf('/htm/')) + '/exe/exe_http_field_check.asp?' + oField.name + '|' + oField.value + '|' + oField.form.user_id.value + '|' + Math.random(), false);
			send('');
			blnReturn = (responseText == '1');
		}
	}
	
	if (!blnReturn) {
		alert(strError);
		if (!oField.disabled) oField.focus();
	}

	return blnReturn;

}

function setUserState(blnLoggedIn) {

	var blnActive = true;
	
	if (blnHTTP) {
		with (oHTTP) {
			open('GET', document.location.protocol + '//' + document.location.host + document.location.pathname.substr(0, document.location.pathname.indexOf('/htm/')) + '/exe/exe_http_user_set.asp?' + (blnLoggedIn ? 'true' : 'false') + '|' + Math.random(), false);
			send('');
			blnActive = (responseText == '1');
		}
	}
	
	if (!blnActive) {
		location.reload();
	} else if (blnLoggedIn) {
		window.setTimeout('setUserState(true)', 3000);
	}

}

function roundField(oField, intScale, blnPadToScale) {

	var intPrecision = !isNaN(oField.getAttribute('maxlength')) ? parseInt(oField.getAttribute('maxlength')) - 1 : 0;
	var strTrailingZero = '';
	var intTrailingZero, intUnfilledScale;

	oField.value = oField.value.replace(',', '');
	
	if (oField.value.indexOf('.') > -1) {
		for (var i = oField.value.length - 1; i > 0; i--) {
			if (oField.value.substr(i, 1) == '0' && strTrailingZero.length < intScale && (strTrailingZero.length == 0 || strTrailingZero.substr(strTrailingZero.length - 1, 1) == '0')) {
				strTrailingZero += oField.value.substr(i, 1);
			}
		}
	}
	intTrailingZero = strTrailingZero.length;
		
	if (oField.value.indexOf('.') > -1 && oField.value.indexOf('.') > intPrecision - intScale) {
		oField.value = oField.value.substr(0, intPrecision - intScale) + oField.value.substr(oField.value.indexOf('.'));
	} else if (oField.value.indexOf('.') == -1 && oField.value.length > intPrecision - intScale) {
		oField.value = oField.value.substr(0, intPrecision - intScale);
	}
	
	if (intScale > 0 && oField.value.length > 0 && !isNaN(oField.value) && !isNaN(intScale) && oField.value.indexOf('.') <= oField.value.length - intScale) {

		oField.value = Math.round(oField.value * Math.pow(10, intScale)) / Math.pow(10, intScale);
		

		intUnfilledScale = intScale - (oField.value.length - 1 - oField.value.indexOf('.'));
		if (intUnfilledScale > 0) intTrailingZero = blnPadToScale ? intUnfilledScale : Math.min(intTrailingZero, intUnfilledScale);
			
		if (intTrailingZero > 0) {
			if (oField.value.indexOf('.') == -1) oField.value += '.';
			for (var i = 0; i <= intTrailingZero; i++) {
				if (oField.value.length - 1 - oField.value.indexOf('.') < intScale) oField.value += '0';
			}
		} 
			
	}

}

function setPage(oListForm, intPage) {
	if (oListForm.order_field) oListForm.order_field.value = '';
	return setFieldValue(oListForm.page, intPage);
}

function init() {

	if (document.location.pathname.length > 0 && document.location.pathname.split('/')[document.location.pathname.split('/').length - 1] != 'htm_login.asp' && document.location.pathname.split('/')[document.location.pathname.split('/').length - 1] != 'htm_login_temp.asp' && setHTTP()) {
		setUserState(true);
		document.getElementsByTagName('body')[0].onunload = setUserState;
	}
	
	if (document.forms.length > 0) setFocus(false);
	
	msgStatusAllLinks();	

}




