var ie = /MSIE/.test(navigator.userAgent);
var moz = !ie && navigator.product == "Gecko";

if (moz){// set up ie environment for Moz
	extendEventObject();
	emulateEventHandlers(["click","dblclick","mouseover","mouseout","mousedown","mouseup","mousemove","keydown","keypress","keyup"]);
}


//for PostalCodes
function hlPostalCode_OnClick(zipCode,company,address,city,type){
	var opener=window.opener;
	re=/:/gi;
	if (type == 'recipient'){
		var postCodeName='ihShip_to_zipUID';
		var companyName='ihShip_to_companyUID';
		var addressName='ihShip_to_address1UID';
		var cityName='ihShip_to_cityUID';
	}
	var tbPostCode=opener.document.getElementById(opener.document.getElementById(postCodeName).value.replace(re,"_"));
	tbPostCode.value=zipCode;
	var tbCompany=opener.document.getElementById(opener.document.getElementById(companyName).value.replace(re,"_"));
	tbCompany.value=company;
	var tbAddress=opener.document.getElementById(opener.document.getElementById(addressName).value.replace(re,"_"));
	tbAddress.value=address;
	var tbCity=opener.document.getElementById(opener.document.getElementById(cityName).value.replace(re,"_"));
	tbCity.value=city;
	window.close();
}

//open pop-up window
function openPopupWindow(sURL, iWidth, iHeight){
	var retval = ""
	retval = window.open(sURL, "wndPopUpHandle", "width="+ iWidth +", height=" + iHeight + ", menubar=no, top=0, left=0, status=no, location=no, toolbar=no, scrollbars=yes, resizable=no");
	return retval;
}

//set value for style
function setStyle(objElement,strAttribute,strValue){
	if (objElement == null) 
		return false;
	objElement.style[strAttribute] = strValue;
	return true;
}

//get style-value
function getStyle(objElement,strAttribute){
	if (objElement == null)
		return null;
	var strValue = objElement.style[strAttribute];
	if (!strValue){
		if(document.defaultView)
			strValue = document.defaultView.getComputedStyle(objElement,"").getPropertyValue(strAttribute);
		else if (objElement.currentStyle)
			strValue = objElement.currentStyle[strAttribute];
	}
	return strValue;
}


function CheckAndPostZipCode(object, zipCodeWarning){
	if (object.value == "")	{
		window.alert(zipCodeWarning);
		return false;
	}
	return true;
}

function CheckLeaveSite(){
	if (window.confirm(question)){
		return true;
	}else{
		window.location="deliveryregions.aspx";
		return false;
	}
}

function GetMajor(bname, agent){
	bpos = agent.indexOf(bname) + bname.length + 1;
	return parseInt(agent.substr(bpos));
}

function GetMinor(bname, agent){
	bpos = agent.indexOf(bname) + bname.length + 1;
	return parseFloat(agent.substr(bpos));
}

function CheckAgent(bname, agent){
	return agent.indexOf(bname) > -1;
}

function Is(){
	var agent = navigator.userAgent.toLowerCase();

	this.ie = CheckAgent("msie", agent);
	this.ns = CheckAgent("mozilla", agent);
	this.op3 = CheckAgent("opera", agent);

	this.major = GetMajor("msie", agent);
	this.minor = GetMinor("msie", agent);
	this.nmajor = GetMajor("mozilla", agent);
	this.nminor = GetMinor("mozilla", agent);
	this.omajor = GetMajor("opera", agent);
	this.ominor = GetMinor("opera", agent);


	this.ns2 = (this.ns && this.nmajor == 2);
	this.ns3 = (this.ns && this.nmajor == 3);
	this.ns4b = (this.ns && this.nminor < 4.04);
	this.ns4 = (this.ns && this.nmajor >= 4);

	this.ie3  = (this.ie && this.major == 2);
	this.ie4  = (this.ie && this.major >= 4);
	this.ie5  = (this.ie && this.major >= 5);
	this.ie6  = (this.ie && this.major >= 6);

	this.win   = CheckAgent("win", agent);
	this.mac   = CheckAgent("mac", agent);
	this.unix  = CheckAgent("x11", agent);
}

function SetCookie(cookieName,cookieValue,nDays){
	var today = new Date();
	var expire = new Date();
	var expireString = "";
	if (!(typeof(nDays) == 'undefined' || nDays == null || nDays == 0)){
		expire.setTime(today.getTime() + 3600000*24*nDays);
		expireString = ";expires="+expire.toGMTString()
	}
	document.cookie = cookieName+"="+escape(cookieValue) + expireString;
}

function GetCookie(name){
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if (!start && (name != document.cookie.substring(0, name.length)))
		return null;
	if (start == -1)
		return null;
	var end = document.cookie.indexOf( ";", len );
	if (end == -1)
		end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function DeleteCookie(name, path, domain ){
	if (GetCookie(name))
		document.cookie = name + "=" + (path ? ";path=" + path : "") + (domain ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function DetectFlash(){
	var bdetect = new Is();
	insns = false;
	ins4=false;
	ins5=false;
	ins6=false;
	ins7=false;
	if ((!bdetect.ie4) || (bdetect.op3)) {
		MM_PluginVersion = 0;
		if(navigator.plugins["Shockwave Flash"] != null){
			var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			MM_PluginVersion = parseInt(words[2]);
		}
		if(MM_PluginVersion >= 4){
			insns = true;
		}else{
			insns = false;
		}
	}else if (bdetect.ie4 && bdetect.win) {
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('on error resume next \n');
		document.write('ins4 = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & 4)))\n');
		document.write('ins5 = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & 5)))\n');
		document.write('ins6 = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & 6)))\n');
		document.write('ins7 = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & 7)))\n');
		document.write('</SCR' + 'IPT\> \n');
	}
	//alert(ins4 || ins5 || ins6);
	return ins4 || ins5 || ins6 || ins7 || insns;
}

function SetInputFocus(vObject){
	var is = new Is();
	if( is.ie4)
		vObject.focus();
	delete is;
}

function ChangeAnchor(strAnchorID, strUrl, x, y, width, height){
	var theAnchor = (document.layers) || ! (document.getElementById) ? "['" + strAnchorID + "']" : "('" + strAnchorID + "')";
	var strFunction = (document.getElementById) ? "document.getElementById" : "document.anchors";
	var obj = eval(strFunction+theAnchor);

	if( obj)
	{
		obj.href = "javascript:void(0);";
		obj.target = "";
		obj.onclick = new Function( "changelink( '" + strUrl + "', " + x + ", " + y + ", " + width + ", " + height + ")");
	}
}

function changelink(strUrl, x, y, width, height){
	window.open( strUrl, "popup_msg", "scrollbars=no,resizable=no,screenX=" + x + ",screenY=" + y + ",width=" + width + ",height=" + height + "");
}

function IsNetscapeOnMac(){
	var agent = window.navigator.userAgent;
	//Is the user running Netscape browser?
	if ( ( agent.indexOf('Mozilla') != -1 ) && ( agent.indexOf('compatible')== -1 ) )
	{
		//Yes. Are they using a Macintosh?
		if ( agent.indexOf('Macintosh') != -1 ){
			return true;//Yes.
		}else{
			return false;//No.
		}
	} else {
		return false;//No
	}
}

function IsExplorerOnMac(){
	var agent = window.navigator.userAgent;
	//Is the user running Internet Explorer?
	if (agent.indexOf('Mozilla') != -1 && agent.indexOf('compatible') != -1 && agent.indexOf('MSIE')!= -1)
	{
		//Yes.
		//Are they using a Macintosh?
		if ( agent.indexOf('Mac_PowerPC') != -1 ){
			//Yes.
			return true;
		}else{
			//No.
			return false;
		}
	}else{
		//No
		return false;
	}
}

function IsNetscape6(){
	return ( navigator.appName == "Netscape" && navigator.appVersion.charAt(0) == "5" );
}

function IsAOL6O( agent){
	//Is the user running AOL 6.0?
	if (agent.indexOf('Mozilla') != -1 && agent.indexOf('compatible') != -1	&& agent.indexOf('MSIE')!= -1	&& agent.indexOf('AOL ')!= -1){
		//Yes.
		return true;
	}else{
		//No
		return false;
	}
}

function launchCenter( agent, url, name, height, width, extraspec){
	var str = "height=" + height;
	str += ",width=" + width;
	if (window.screen)
	{
/*
		 var ah = screen.availHeight - 30;
		 var aw = screen.availWidth - 10;

		 var xc = (aw - width) / 2;
		 var yc = (ah - height) / 2;
*/
		var xc = 100;
		var yc = 100;

		str += ",screenX=" + xc;
		str += ",screenY=" + yc;
		if(!IsAOL6O( agent)){
			str += ",top=" + yc;
			str += ",left=" + xc;
		}
		str += "," + extraspec;
	}
	return window.open(url, name, str);
}

function On3DSecureLoadEvent( agent, strFormName, strAction){
	var ThreeDSecureChildwin;
	var ThreeDSecurePopupName;

	window.name = 'FIPaymentPage';

	//Make sure window has a name //NOT USED
	//if (window.name == "" || window.name == null) {
	//                window.name = "OpeningWindow";
	//}

	ThreeDSecurePopupName = window.name + "Popup";

	ThreeDSecureChildwin = launchCenter( agent, 'about:blank', ThreeDSecurePopupName, 400, 390, 'status=yes,dependent=no,scrollbars=yes,resizable=no');
	ThreeDSecureChildwin.focus();

	var objForm = getFormObject( strFormName);

	objForm.target = ThreeDSecurePopupName;
	objForm.action = strAction;
	objForm.submit();
	//location.replace(document.referrer);
	//history.back();
}

function On3DSecureCloseLoad( strFormName, intPageMode){
	window.opener.focus();

	var objForm = getFormObject( strFormName);

	objForm.action =  'Payment.aspx?mode=' + intPageMode; //See Notes in OpenAuthenticationWindow about this..
	objForm.target =  'FIPaymentPage'; //See Notes in OpenAuthenticationWindow about this..

	// change the name and id of the viewstate input field so aspnet will not recognise it anymore
	objForm.elements[0].name = "VS";
	objForm.elements[0].id = "VS";

	objForm.submit();

	// close the popup but
	// delay the        self.close() by 1 second
	// because some browsers on Macintosh need time for the
	// submit to execute
	if ( IsNetscape6() || IsNetscapeOnMac() || IsExplorerOnMac() ){
		setTimeout('self.close()',1000);
	}else{
		self.close();
	}
}

function On3DSecurePopupClosedLoad( strFormName){
	var objForm = getFormObject( strFormName);
	objForm.action =  'Payment.aspx?mode=2'; //See Notes in OpenAuthenticationWindow about this..
	objForm.submit();
}

function getFormObject( strFormName){
	var strForm = (document.layers) || ! (document.getElementsByName) ? "['" + strFormName + "']" : "('" + strFormName + "')[0]";
	var funcName = (document.getElementsByName) ? "document.getElementsByName" : ((document.layers) ? "document.forms" : "document.all");

	return eval( funcName + strForm);
}

function TieButton(buttonName){
	if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)){
		var obj = document.getElementById(buttonName);
		if (obj != null){
			if (obj.href != undefined){
				document.location.href = obj.href;
				eval(obj.href);
			}else{
				obj.click();
			}
			return false;
		}
	}
	return true;
}

function checkInstructionsField(objectID){
	fld=document.forms[0][objectID];

	if (fld.value.length > 200)
		fld.value = fld.value.substring(0,200);

	for (var j=0; j<fld.value.length;j++){
		if (fld.value.charCodeAt(j) > 128){
			fld.value = fld.value.substring(0,j) + fld.value.substring(j+1, fld.value.length);
			j--;
		}
	}
}

function UpdateCounter(field, objectID, objectWarning, allow, cntrID){
	if (!allow)
		checkChars(objectID, objectWarning)
	var count = document.forms[0][objectID].value.length;
	document.forms[0][cntrID].value = 248 - count;
	if (count > 248 ){
		field.value = field.value.substring(0,field.value.length-1);
		UpdateCounter(field, objectID, objectWarning, allow, cntrID);
	}
}


function checkChars(objectID, strWarning){
	var blnAlerted = false
	var textfield = document.getElementById(objectID);
	var allowedChars = '%339%338%8217%8230%';
	var text = "";

	if (textfield)
		text = textfield.value;

	for (var i = 0; i < text.length; i++){
		if (text.charCodeAt(i) > 255 && allowedChars.indexOf('%' + text.charCodeAt(i) + '%') == -1){
			if (!blnAlerted)
				alert(strWarning + text.charCodeAt(i))
			blnAlerted = true
			text = text.substring(0, i) + text.substring(i + 1, text.length)
		}
	}

	if (textfield)
		textfield.value = text;
}


function otherGenderChange(objectID, objectOtherID){
	if (document.forms[0][objectOtherID].value.length > 0)
		document.forms[0][objectID].selectedIndex =  document.forms[0][objectID].length -1
	return true
}

function GenderChange(objectID, objectOtherID, objectNameID){
	if (null != objectID && document.forms[0][objectID].selectedIndex != document.forms[0][objectID].length -1){
		if(null != objectOtherID)
			document.forms[0][objectOtherID].value = ''
		if(null != objectNameID)
		SetInputFocus(document.forms[0][objectNameID])
	}else{
		if(null != objectOtherID)
			SetInputFocus(document.forms[0][objectOtherID])
	}
	return true
}

function selText(keyval, ca_mode, objectID, strWarning, allow, cntrID){
	if (ca_mode){
		var strText;
		eval("strText = text_" + keyval + ";");

		if( strText.length > 248)
			strText = strText.substr( 0, 230) + " [...more text]";
		document.forms[0][objectID].value = strText;
	}else{
		eval("document.forms[0][objectID].value = text_" + keyval + ";");
	}
	UpdateCounter(this, objectID, strWarning, allow, cntrID);
}

var xPos,yPos;
var isNS = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4);

function pos(object, largeimage){
	xPos = 0;
	yPos = 0;
	if (object == null)
		return;

	if(object.offsetParent){
		while (object.offsetParent){
			xPos += object.offsetLeft;
			yPos += object.offsetTop;
			object = object.offsetParent;
		}
	}else if (object.x && object.y){
		xPos += object.x
		yPos += object.y;
	}
}

function cbCardMessageRequired_onClick(){
	var cbCardMessageRequiredID=document.getElementById('cbCardMessageRequiredID');
	if (cbCardMessageRequiredID != null){
		if (cbCardMessageRequiredID.checked)
			document.forms[0][tbShip_to_text2ID].disabled=true;
		else
			document.forms[0][tbShip_to_text2ID].disabled=false;
	}
}

//show all properties of choosen object - good to inspect them
function show_props(obj, objName){
	var result = "";
	for (var i in obj)
		result += objName + "." + i + " = " + obj[i] + "\n";

	return result;
}


function ShowLoginBlock(){
	if(divLoginBlock == undefined || divLoginBlock == null)
		return;

	if(rblOrder != undefined || rblOrder != null){
		if(rblOrder.checked == true){
			divLoginBlock.style.visibility = "hidden";
			setStyle(divLoginBlock, 'display', 'none');
		}else{
			divLoginBlock.style.visibility = "visible";
			setStyle(divLoginBlock, 'display', 'inline');
		}
	}
}

InputIntControl = function(t){
	var tValue = t.value;
	if(IsDecimalSeparatorDefined)
		tValue = tValue.replace(rExpFormLocale, '.');
	var dotIndex=tValue.indexOf(".");
	if (dotIndex != -1)
		tValue = tValue.substring(0,dotIndex);

	if(/\D/.test(tValue)){
		t.value=t.defaultValue;
	}else{
		if(tValue == "")
			tValue = "1";
		t.defaultValue=tValue;
	}
	return tValue;
}

/***** methods to make available window.event for FireFox ***********/
/*
 * This function binds the event object passed along in an
 * event to window.event
 */
function emulateEventHandlers(eventNames){
	for (var i = 0; i < eventNames.length; i++) {
		document.addEventListener(eventNames[i], 
			function (e){
				window.event = e;
			}, 
			true); // using capture
	}
}

function extendEventObject(){
	Event.prototype.__defineSetter__("returnValue", 
		function (b){
			if (!b)
				this.preventDefault();
				return b;
		});

	Event.prototype.__defineSetter__("cancelBubble", 
		function (b){
			if (b)
				this.stopPropagation();
			return b;
		});

//	Event.prototype.__defineGetter__("srcElement", 
//		function (){
//			var node = this.target;
//			while (node.nodeType != 1)
//				node = node.parentNode;
//			return node;
//		});

	Event.prototype.__defineGetter__("fromElement", 
		function (){
			var node;
			if (this.type == "mouseover")
				node = this.relatedTarget;
			else if (this.type == "mouseout")
				node = this.target;
			if (!node) 
				return;
			while (node.nodeType != 1) 
				node = node.parentNode;
			return node;
		});

	Event.prototype.__defineGetter__("toElement", 
		function (){
			var node;
			if (this.type == "mouseout")
				node = this.relatedTarget;
			else if (this.type == "mouseover")
				node = this.target;
			if (!node)
				return;
			while (node.nodeType != 1) 
				node = node.parentNode;
			return node;
		});

	Event.prototype.__defineGetter__("offsetX", 
		function (){
			return this.layerX;
		});
	
	Event.prototype.__defineGetter__("offsetY", 
		function (){
			return this.layerY;
		});
}
/******************************************************************/

function RemoveSpecialCharacters(text){
	var newText = '';
	if (text.length > 0){
		for (var i=0; i<text.length; i++){
			if (text.charCodeAt(i) > 31 || text.charCodeAt(i) == 10 || text.charCodeAt(i) == 13){
				newText += String.fromCharCode(text.charCodeAt(i));
			}
		}
	}
	return newText;
}

function showPartnerInformation(ltID, text, divInfo){
	var info = document.getElementById(divInfo);
	var lt = document.getElementById(ltID);
	if(info.style.visibility == "visible"){
		info.style.visibility = "hidden";
		info.innerHTML = '';
		lt.innerHTML = ">";
	}
	else{
		info.style.visibility = "visible";
		info.innerHTML = text;
		lt.innerHTML = "";
	}
}

// ------------------------------- Text field validator ---------------------------------------

FLEUROP = {};

FLEUROP.attachTextFieldValidator = function(textField, maxLength, allowedChars, maxLengthErrorMessage, allowedCharsErrorMessage, counter){
	if (!textField || textField.validator)
		return;
	var validator = new FLEUROP.TextFieldValidator(textField, maxLength, allowedChars, maxLengthErrorMessage, allowedCharsErrorMessage, counter);
	FLEUROP.attachValidator(textField, validator);
}

FLEUROP.attachDecimalTextFieldValidator = function (textField, decimalSeparator, minValue, maxValue, minValueCallback, maxValueCallback, checkingFinishedCallback)
{
	if (!textField || textField.validator)
		return;
	var validator = new FLEUROP.DecimalTextFieldValidator(textField, decimalSeparator, minValue, maxValue, minValueCallback, maxValueCallback, checkingFinishedCallback);
	FLEUROP.attachValidator(textField, validator);
}

FLEUROP.attachValidator = function (textField, validator)
{
	if (!textField || !validator || textField.validator)
		return;
	textField.validator = validator;
	if (textField.addEventListener){
		textField.addEventListener('focus', function(){textField.validator.startMonitoring.call(textField.validator, event)}, false);
		textField.addEventListener('blur', function(){textField.validator.stopMonitoring.call(textField.validator, event)}, false);
		textField.addEventListener('keypress', function(){return textField.validator.isInputAllowed.call(textField.validator, event)}, false);
	}
	else if (textField.attachEvent){
		textField.attachEvent('onfocus', function(){textField.validator.startMonitoring.call(textField.validator, event)});
		textField.attachEvent('onblur', function(){textField.validator.stopMonitoring.call(textField.validator, event)});
		textField.attachEvent('onkeypress', function(){return textField.validator.isInputAllowed.call(textField.validator, event)});
	}
}

FLEUROP.TextFieldValidator = function (textField, maxLength, allowedChars, maxLengthErrorMessage, allowedCharsErrorMessage, counter){
	var _textField = textField;
	var _maxLength = maxLength;
	var _allowedCharRanges = new Array();
	var _maxLengthErrorMessage = maxLengthErrorMessage;
	var _allowedCharsErrorMessage = allowedCharsErrorMessage;
	var _counter = counter;
	var _interval;

	if (_counter)
		_counter.value = _maxLength - fixNewLines(_textField.value).length;

	var ranges = (allowedChars && allowedChars.split(",")) || new Array();

	for (var k = 0; k < ranges.length; ++k){
		var range = ranges[k].split("-");
		var start = range[0];
		var end = range[1] || start;

		_allowedCharRanges.push({start: start, end: end});
	}

	function isAllowedChar(charCode){
		if (!_allowedCharRanges)
			return false;

		for (var i = 0; i < _allowedCharRanges.length; ++i){
			if (charCode >= _allowedCharRanges[i].start && charCode <= _allowedCharRanges[i].end)
				return true;
		}

		return false;
	}

	function fixNewLines(val){
		if (val.indexOf('\r\n')!=-1)
		{}
		else if (val.indexOf('\r')!=-1){
			val = val.replace ( /\r/g, "\r\n" );
		}
		else if (val.indexOf('\n')!=-1){
			val = val.replace ( /\n/g, "\r\n" );
		}
		return val;
	}

	this.getTextField = function(){
		return _textField;
	}

	this.checkField = function(){
		var text = (_textField && _textField.value) || "";
		var correctText = fixNewLines(text);
		var alerted = false;

		for (var i = 0; i < text.length; i++){
			if (!isAllowedChar(text.charCodeAt(i))){
				if (!alerted){
					_allowedCharsErrorMessage && alert(_allowedCharsErrorMessage)
					alerted = true;
				}
				text = text.substring(0, i) + text.substring(i + 1, text.length)
				--i;
			}
		}

		if (_maxLength && correctText.length > _maxLength){
			text = correctText.substring(0, maxLength);
			_maxLengthErrorMessage && alert(_maxLengthErrorMessage);
		}

		if (_textField && _textField.value.length != text.length){
			_textField.value = text;
			_textField.scrollTop = _textField.scrollHeight;
		}

		if (_counter)
			_counter.value = _maxLength - correctText.length;
	}

	this.isInputAllowed = function (event){
		var text = (_textField && _textField.value) || "";
		var correctText = fixNewLines(text);

		var keyCode        = event.which;

		if (keyCode === undefined)
			keyCode = event.keyCode;

		var result = true;

		if(!(event.altKey || event.ctrlKey || event.shiftKey || event.metaKey) && 
		   keyCode != 0 && keyCode != 9 && keyCode != 8 && keyCode != 27 && keyCode != 35 && keyCode != 36 && keyCode != 37 && keyCode != 38 && keyCode != 39 && keyCode != 40){
			if (_maxLength && _textField && correctText.length >= _maxLength){
				if (_maxLengthErrorMessage){
					_textField && _textField.blur();
					alert(_maxLengthErrorMessage);
					_textField && _textField.focus();
				}
				result = false;
			}
			if (result){
				if (!isAllowedChar(keyCode)){
					if (_allowedCharsErrorMessage){
						_textField && _textField.blur();
						alert(_allowedCharsErrorMessage);
						_textField && _textField.focus();
					}

					result = false;
				}
			}
		}

		if (!result){
			event.cancelBubble = true;
			event.stopPropagation && event.stopPropagation();
			event.preventDefault && event.preventDefault();
		}

		return result;
	}

	this.startMonitoring = function (){
		if (!_interval)
			_interval = setInterval(this.checkField, 20);
	}

	this.stopMonitoring =  function (){
		clearInterval(_interval);
		_interval = undefined;
	}
}

FLEUROP.DecimalTextFieldValidator = function(decimalTextField, decimalSeparator, minValue, maxValue, minValueCallback, maxValueCallback, checkingFinishedCallback)
{
	var _decimalSeparator = decimalSeparator || ".";
	var _minValue = minValue;
	var _maxValue = maxValue;
	var _minValueCallback = minValueCallback;
	var _maxValueCallback = maxValueCallback;
	var _checkingFinishedCallback = checkingFinishedCallback;

	var base = new FLEUROP.TextFieldValidator(decimalTextField, null, "48-57, " + _decimalSeparator.charCodeAt(0));
	var baseCheckField = base.checkField;
	var baseStopMonitoring = base.stopMonitoring;
	var baseIsInputAllowed = base.isInputAllowed;

	base.getMinValue = function(){
		if (minValueCallback)
			return minValueCallback();

		return _minValue;
	}

	base.getMaxValue = function(){
		if (maxValueCallback)
			return maxValueCallback();

		return _maxValue;
	}

	base.checkField = function(){
		baseCheckField();

		var text = (base.getTextField() && base.getTextField().value) || "";

		while (text.lastIndexOf(_decimalSeparator) != text.indexOf(_decimalSeparator))
			text = text.substr(0, text.lastIndexOf(_decimalSeparator)) + text.substr(text.lastIndexOf(_decimalSeparator) + 1);

		while (text.length > 0 && isNaN(parseFloat(text.replace(_decimalSeparator, "."))))
			text = text.substr(0, text.length - 1);

		if (base.getTextField() && (base.getTextField().value.length != text.length))
			base.getTextField().value = text;
	}

	base.stopMonitoring = function(){
		setTimeout(
			function(){
				baseStopMonitoring();
				base.checkFieldForMaxAndMinValue();

				if (_checkingFinishedCallback)
					_checkingFinishedCallback(base.getTextField());
			},
			300);
	}

	base.checkFieldForMaxAndMinValue = function (){
		base.checkField ( );

		var minValue = base.getMinValue();
		var maxValue = base.getMaxValue();
		var text = ( base.getTextField ( ) && base.getTextField ( ).value ) || "";
		var value = minValue;
		var parsedText = parseFloat ( text.replace ( _decimalSeparator, "." ) );

		if (!isNaN(parsedText))
			value = parsedText;

		if (minValue && value < minValue )
			value = minValue;

		if (maxValue && value > maxValue )
			value = maxValue;

		if (!value)
			value = 0;

		base.getTextField ( ).value = value.toFixed ( 2 ).toString ( ).replace ( ".", _decimalSeparator );
	};

	base.isInputAllowed = function(event){
		var result = false;

		if (baseIsInputAllowed(event)){
			if ( event.charCode == 0 && event.keyCode > 0 ){
				result = true;
			}
			else{
				var keyCode = event.which || event.keyCode;
				var text = (base.getTextField() && base.getTextField().value) || "";

				if((text.lastIndexOf(_decimalSeparator) < 0 || (keyCode != _decimalSeparator.charCodeAt(0))) &&
				   !isNaN(parseFloat(text.replace(_decimalSeparator, ".") + String.fromCharCode(keyCode)))){
					result = true;
				}
			};
		}

		if (!result){
			event.cancelBubble = true;
			event.stopPropagation && event.stopPropagation();
			event.preventDefault && event.preventDefault();
		}

		return result;
	}

	return base;
}

// ---------------------------------------------------------------------------------------------


function getElementsByTagNameAndAttribute(tagName, attributeName){
	var elements = document.getElementsByTagName(tagName);
	var result = new Array();

	for (var i = 0; i < elements.length; ++i){
		if (elements[i].attributes[attributeName])
			result.push(elements[i]);
	}

	return result;
}

function ShowFlashPlayer(path, width, height){
	widthW = width + 20;
	heightW = height + 20;
	var flashWin = window.open("","", "height= " + heightW +",width=" + widthW + ",menubar=no, top=150, left=150, status=no, location=no, toolbar=no, scrollbars=no, resizable=no");
	var content = "<html><head><title></title></head><body><div style= style=\"margin:0px;padding:0px\">";
	content += "<object width='" + width + "' height='" + height + "' id='Object2'>";
	content += "<param name='movie' value='" + path + "'/>";
	content += "<embed src='" + path + "' width='" + width + "' height='" + height + "' type='application/x-shockwave-flash'>";
	content += "</object></div></body></html>";
	flashWin.document.write(content);
}