function xForm( eFORM, sOptions ){
	this.eForm = eFORM;
	this.eForm.hControl = new Array();
	var asInput = [ 'input', 'textarea', 'select' ], i, ii, j, aeInput, sValue;
	for( i in asInput ){
		if( asInput.constructor.prototype[i] ) continue;
		aeInput = this.eForm.getElementsByTagName( asInput[i] );
		for( ii = 0 ; ii < aeInput.length ; ii++ ){
			j = aeInput[ii].id;
			this.eForm.hControl[j] = aeInput[ii];
			if( !aeInput[ii].type.match( /^(radio|checkbox)$/ ) ){
				sValue = xGet_input_value( location.search, aeInput[ii].name );
				if( sValue ){
					aeInput[ii].value = sValue;
				}
			}
			x_Get_accompanied_elements( this.eForm.hControl[j] );
			x_Add_events( this.eForm.hControl[j] );
		}
	}

	this.eForm.onsubmit = x_Check_form;

}
function x_Add_events( eInput ){
	var sClass_name = eInput.className;
	if( sClass_name ){
		sClass_name = sClass_name.replace( /x_(min|max|default)_(\S*)/g, function( s, p1, p2 ){
			eInput[ "x_" + p1 ] = p2;
			return "";
		} );
		var asClass = sClass_name.split( /\s+/ );
		var bRequired = false;
		var bRequiredGroup = false;
		var aHandler = new Array();
		
		for( var i = 0, j ; i < asClass.length ; i++ ){
			switch( asClass[i] ){
				case "required":
				case "required-ok":
					bRequired = true;
					break;
				case "required-group":
					bRequiredGroup = true;
					break;
				case "x_email":
//					aHandler[aHandler.length] = xFormat_email;
					if( !eInput.x_mask ){
						eInput.x_mask = new RegExp( "[a-zA-Z0-9][a-zA-Z0-9\\.\\-\\_\\~]*\\@[a-zA-Z0-9\\.\\-\\_]+\\.[a-zA-Z]{2,4}(\\?[a-zA-Z0-9][^\\x20\\t]*)?" );
					}
					break;
				case "x_phone":
					aHandler[aHandler.length] = xFormat_phone;
					if( !eInput.x_mask ){
						eInput.x_mask = new RegExp( "^(\\(?\\+\\d{1,3}\\x20?)?(\\d{3,4}\\x20?|\\(?\\d{3,4}\\)\\x20?)?\\d{2,3}\\-?\\d\\d\\-?\\d\\d(\\s[\\d\\s\(\)]*)?(,\\s(\\(?\\+\\d{1,3}\\x20?)?(\\d{3,4}\\x20?|\\(?\\d{3,4}\\)\\x20?)?\\d{2,3}\\-?\\d\\d\\-?\\d\\d(\\s[\\d\\s\(\)]*)?)*$" );
					}
					break;
				case "x_date":
//					if( !eInput.eCalendar ){

						x_Make_calendar( eInput, true, true, true );
						function change_date(){								
							var dtDate = new Date( eInput.eCalendar.childNodes[2].value, eInput.eCalendar.childNodes[1].value - 1, eInput.eCalendar.childNodes[0].value );
							var sDate = dtDate.getFullYear() + '-' + ( dtDate.getMonth() + 1 ) + '-' + dtDate.getDate();
							var sDate1 = eInput.eCalendar.childNodes[2].value + '-' + eInput.eCalendar.childNodes[1].value * 1 + '-' + eInput.eCalendar.childNodes[0].value * 1;
							if( sDate == sDate1 ){
								Common.Class.replace( eInput.eCalendar, "invalid", "valid" );
								eInput.value = sDate;
							}else{
								Common.Class.replace( eInput.eCalendar, "valid", "invalid" );
								eInput.value = '';
							}
							eInput.onkeyup();			
						}
						for( var j = 0 ; j < eInput.eCalendar.childNodes.length ; j++ ){
							eInput.eCalendar.childNodes[j].onchange = change_date;
							eInput.eCalendar.childNodes[j].onblur = change_date;
							eInput.eCalendar.childNodes[j].onkeyup = change_date;
						}
						aHandler[aHandler.length] = xFormat_date;
						if( !eInput.x_mask ){
							//eInput.x_mask = new RegExp( "^([12][0-9]|3[01]|0?[1-9])([\\.\\-/])(1[012]|0?[1-9])\\2(1\\d\\d\\d|2[01]\\d\\d)$" );
						}
//					}
					break;
				case "x_datetime":
					//aHandler[aHandler.length] = xFormat_datetime;
					if( !eInput.x_mask ){
						eInput.x_mask = new RegExp( "^([12][0-9]|3[01]|0?[1-9])([\\.\\-/])(1[012]|0?[1-9])\\2(1\\d\\d\\d|2[01]\\d\\d)\s+([01]?\\d|2[0-3]):[0-5]?\\d$" );
					}
					break;
				case "x_datemonth":
					//aHandler[aHandler.length] = xFormat_datemonth;
					/*if( !eInput.x_mask ){
						eInput.x_mask = new RegExp( "^(1[012]|0?[1-9])([\\.\\-/])(1\\d\\d\\d|2[01]\\d\\d)$" );
					}*/
					
					if( !eInput.eCalendar ){
						x_Make_calendar( eInput, true, true, false );
						
						function change_date_month(){
							var dtDate = new Date( eInput.eCalendar.childNodes[1].value, eInput.eCalendar.childNodes[0].value - 1, 1 );
							var sDate = ( dtDate.getMonth() + 1 ) + '.' + dtDate.getFullYear();
							eInput.value = sDate == eInput.eCalendar.childNodes[0].value * 1 + '.' + eInput.eCalendar.childNodes[1].value ? sDate : '';
							eInput.onkeyup();
						}
						for( var j = 0 ; j < eInput.eCalendar.childNodes.length ; j++ ){
							eInput.eCalendar.childNodes[j].onchange = change_date_month;
							eInput.eCalendar.childNodes[j].onblur = change_date_month;
							eInput.eCalendar.childNodes[j].onkeyup = change_date_month;
						}
						aHandler[aHandler.length] = xFormat_date;
						if( !eInput.x_mask ){
							eInput.x_mask = new RegExp( "^(1[012]|0?[1-9])([\\.\\-/])(1\\d\\d\\d|2[01]\\d\\d)$" );
						}
					}
					break;
				case "x_integer": aHandler[aHandler.length] = xFormat_integer; break;
				case "x_decimal": aHandler[aHandler.length] = xFormat_decimal; break;
				case "x_no_white_spaces": aHandler[aHandler.length] = xFormat_no_white_spaces; break;
				case "x_only_roman": aHandler[aHandler.length] = xFormat_only_roman; break;
			}
		}
		if( bRequired ){
			aHandler[aHandler.length] = xRequired;
		}
		if( bRequiredGroup ){				
			aHandler[aHandler.length] = xRequiredGroup;
		}
	}
	if( eInput.x_mask ){
		aHandler[aHandler.length] = xCheck_mask;
		eInput.onblur = function(){
			xCheck_mask( this );
		}
		eInput.onfocus = function(){
			Common.Class.remove( this, "(in)?valid" );
		}
	}
	if( aHandler && aHandler.length > 0 ){					
		
		eInput.onkeyup = function(){
			for( var i in aHandler ){
				if( aHandler.constructor.prototype[i] ) continue;
				aHandler[i]( eInput );
			}
		}
		eInput.onclick = eInput.onkeyup;
		eInput.onchange = eInput.onkeyup;
		eInput.onblur = eInput.onkeyup;
		eInput.onkeyup();
	}
}

function x_Get_accompanied_elements( eInput ){
	eInput.eRow = x_Get_row_element( eInput );
	if( eInput.eRow ){
		var aeLabel = eInput.eRow.getElementsByTagName( "LABEL" );
		for( var i = 0; i < aeLabel.length ; i++ ){
			if( eInput.id == aeLabel[i].htmlFor ){
				eInput.eLabel = aeLabel[i];
			}
		}
	}
}

function x_Get_row_element( eInput ){
	var eParent = eInput.parentNode;
	while( eParent ){			
		if( Common.Class.match( eParent, "row" ) ){
			return eParent;
		}
		eParent = eParent.parentNode;
	}
	return false;
}

function x_Check_form(){
	var eWrong = false;
	for( var i in this.hControl ){
		if( this.hControl.constructor.prototype[i] ) continue;
		if( !this.hControl[i].disabled
			&& ( Common.Class.match( this.hControl[i], "required" )
				|| ( this.hControl[i].value != ''
					&& Common.Class.match( this.hControl[i], "invalid" ) ) ) ){
			if( !eWrong ){
				eWrong = this.hControl[i];
			}
			//if( this.hControl[i].eLabel ){
				var eDIV = document.createElement( "INS" );
				eDIV.className = "warning";
				if( Common.Class.match( this.hControl[i], "required" ) ){
					if( this.hControl[i].x_required ){
						eDIV.innerHTML = this.hControl[i].x_required;
						this.hControl[i].x_required = false;
					}
				}else if( this.hControl[i].x_format ){
					eDIV.innerHTML = this.hControl[i].x_format;
					this.hControl[i].x_format = false;
				}
				if( eDIV.innerHTML ){
					//this.hControl[i].parentNode.insertBefore( eDIV, this.hControl[i].eLabel );
					this.hControl[i].parentNode.appendChild( document.createTextNode( ' ' ) );
					this.hControl[i].parentNode.appendChild( eDIV );
				}
			//}
		}
	}
	if( eWrong ){
		eWrong.focus();
		return false;
	}
	return true;
}

function xRequired( eInput ){
	var aeInput = eInput.aeFrom ? eInput.aeFrom : new Array( eInput );
	var bRequired = eInput.disabled ? false : true;
	for( var i = 0 ; i < aeInput.length ; i++ ){
		if( !aeInput[i].disabled && ( aeInput[i].getAttribute( 'type' ) != 'checkbox' && aeInput[i].value || aeInput[i].checked ) ){
			bRequired = false;
			break;
		}
	}
	for( i = 0 ; i < aeInput.length ; i++ ){
		if( bRequired ){
			Common.Class.replace( aeInput[i], "required-ok", "required" );
			Common.Class.replace( aeInput[i].eRow, "required-ok", "required" );
			Common.Class.replace( aeInput[i].eLabel, "required-ok", "required" );
		}else{
			Common.Class.replace( aeInput[i], "required", "required-ok" );
			Common.Class.replace( aeInput[i].eRow, "required", "required-ok" );
			Common.Class.replace( aeInput[i].eLabel, "required", "required-ok" );
		}
	}
}

function xRequiredGroup( eInput ){
	var aeInput = eInput.aeFrom ? eInput.aeFrom : new Array( eInput );
	var bRequired = eInput.disabled ? false : true;
	for( var i = 0 ; i < aeInput.length ; i++ ){
		if( !aeInput[i].disabled && ( aeInput[i].getAttribute( 'type' ) != 'checkbox' && aeInput[i].value || aeInput[i].checked ) ){
			bRequired = false;
			break;
		}
	}
	for( i = 0 ; i < aeInput.length ; i++ ){
		if( bRequired ){
			Common.Class.replace( aeInput[i], "required-ok", "required" );
			Common.Class.replace( aeInput[i].eRow, "required-ok", "required" );
			Common.Class.replace( aeInput[i].eLabel, "required-ok", "required" );
		}else{
			Common.Class.replace( aeInput[i], "required", "required-ok" );
			Common.Class.replace( aeInput[i].eRow, "required", "required-ok" );
			Common.Class.replace( aeInput[i].eLabel, "required", "required-ok" );
		}
	}
}

function xFormat_email( eInput ){
	var sValue = eInput.value.replace( /^[^a-z\d]/i, "" );
	sValue = sValue.replace( /(@.*)@/g, "$1" );
	sValue = sValue.replace( /@\./, "@" );
	sValue = sValue.replace( /[^\w\d\-\.@\?\=\%\&]/g, "" );
	if( eInput.value != sValue ) eInput.value = sValue;
}

function xFormat_phone( eInput ){
	var sValue = eInput.value.replace( /[^\+\d\(\)\x20\-\,]/g, "" );
	if( eInput.value != sValue ) eInput.value = sValue;
}

function xCheck_mask( eInput ){
	if( eInput.value.match( eInput.x_mask ) ){
		Common.Class.replace( eInput, "invalid", "valid" );
		if( eInput.eRow ){
			Common.Class.replace( eInput.eRow, "invalid", "valid" );
		}
	}else{
		Common.Class.replace( eInput, "valid", "invalid" );
		if( eInput.eRow ){
			Common.Class.replace( eInput.eRow, "valid", "invalid" );
		}
	}
}

function xFormat_date( eInput ){
	var sValue = eInput.value.replace( /\d+(\:\d+)+/g, '' ).replace( /[^\d\.\-\/]/g, "" );
	if( eInput.value != sValue ) eInput.value = sValue;
}

function xFormat_integer( eInput ){
	var sValue = parseInt( eInput.value );
	sValue = isNaN( sValue ) ? '' : Math.round( sValue );
/*
	var sValue = eInput.value.replace( /(.)\-/g, "$1" );
	sValue = sValue.replace( /[^\d\-]+/g, "" );
	if( eInput.x_min > 0 ){
		sValue = sValue.replace( /^[\-0]{1,2}/, "" )
	}else if( eInput.x_min == 0 ){
		sValue = sValue.replace( /^\-/, "" )
	}else if( eInput.x_max < 0 ){
		sValue = sValue.replace( /^(\-)/, "-$1" );
	}else if( eInput.x_max == 0 ){
		sValue = sValue.replace( /^[^\-0]/, "0" )
	}
*/
	if( eInput.value != sValue + '' ) eInput.value = sValue;
}
function xFormat_decimal( eInput ){
	var sValue = eInput.value.replace( /(.)\-/g, "$1" );
	sValue = sValue.replace( /\,+/g, "." );
	sValue = sValue.replace( /(\..*)\./g, "$1" );
	sValue = sValue.replace( /[^\d\-\.]+/g, "" );
	if( eInput.x_min > 0 ){
		sValue = sValue.replace( /^[\-0]{1,2}/, "" )
	}else if( eInput.x_min == 0 ){
		sValue = sValue.replace( /^\-/, "" )
	}else if( eInput.x_max < 0 ){
		sValue = sValue.replace( /^(\-)/, "-$1" );
	}else if( eInput.x_max == 0 ){
		sValue = sValue.replace( /^[^\-0]/, "0" )
	}
	if( eInput.value != sValue ) eInput.value = sValue;
}

function xFormat_no_white_spaces( eInput ){
	var sValue = eInput.value.replace( /\s*/g, "" );
	if( eInput.value != sValue ) eInput.value = sValue;
}

function xFormat_only_roman( eInput ){
	var sValue = eInput.value.replace( /[^a-z]*/gi, "" );
	if( eInput.value != sValue ) eInput.value = sValue;
}

function x_Make_dependence( sID, sFromID, aValue, bInverse ){
	var eFrom = document.getElementById( sFromID + "_i0" );
	eFrom = eFrom ? eFrom : document.getElementById( sFromID );
	var eThis = document.getElementById( sID );
	if( eThis && eFrom ){
		if( eFrom.tagName.toUpperCase() == 'SELECT' ){
			x_Make_select_dependence( eThis, eFrom, aValue, bInverse );
		}else if( eFrom.getAttribute( "type" ) == "radio" ){
			var i = 0, j, bDepended;
			while( eFrom ){
				bDepended = false;
				for( j = 0 ; j < aValue.length ; j++ ){
					if( eFrom.value == aValue[j] ){
						bDepended = true;
						break;
					}
				}
				x_Make_radio_dependence( eThis, eFrom, bDepended, bInverse );
				i++;
				eFrom = document.getElementById( sFromID + "_i" + i );
			}
		}else if( eFrom.getAttribute( "type" ) == "checkbox" ){
			var i = 0, j;
			while( eFrom ){
				for( j = 0 ; j < aValue.length ; j++ ){
					if( eFrom.value == aValue[j] ){
						x_Make_checkbox_dependence( eThis, eFrom, bInverse );
						break;
					}
				}
				i++;
				eFrom = document.getElementById( sFromID + "_i" + i );
			}
		}else{
			x_Make_text_dependence( eThis, eFrom, bInverse );
		}

	}
}

function x_Make_text_dependence( eThis, eFrom, bInverse ){
	if( !eThis.aFrom ){
		eThis.aFrom = new Array();
		eThis.on_text_depended_changed = x_Text_depended_changed;
	}
	eThis.aFrom[eThis.aFrom.length] = { eFrom: eFrom, bInverse: bInverse };
	Common.Event.add( eFrom, "blur", function(){ eThis.on_text_depended_changed(); } );
	Common.Event.add( eFrom, "keyup", function(){ eThis.on_text_depended_changed(); } );
	Common.Event.add( eFrom, "change", function(){ eThis.on_text_depended_changed(); } );
	eThis.on_text_depended_changed();
}

function x_Text_depended_changed(){
	x_Disable( this, true );
	for( var i = 0, bDisabled ; i < this.aFrom.length ; i++ ){
		bDisabled = this.aFrom[i].eFrom.value.replace( /\s+/g, '' ) ? false : true;
		bDisabled = this.aFrom[i].bInverse ? !bDisabled : bDisabled;
		if( !bDisabled ){
			x_Disable( this, false );
		}
	}
}

function x_Make_select_dependence( eThis, eFrom, aValue, bInverse ){
	function change_depended(){
		eThis.disabled = ( eFrom.options[eFrom.selectedIndex].value == aValue[0] ? false : true );
		x_Disable( eThis, bInverse ? !eThis.disabled : eThis.disabled );
		if( !eThis.disabled ) eThis.focus();
		if( eThis.onkeyup ){ eThis.onkeyup(); }
		if( eThis.onclick ){ eThis.onclick(); }
	}
	Common.Event.add( eFrom, "change", change_depended );
	change_depended();
}

function x_Make_radio_dependence( eThis, eFrom, bDepended, bInverse ){
	function change_depended(){
		eThis.disabled = ( bDepended && eFrom.checked ) || ( !bDepended && !eFrom.checked ) ? false : true;
		x_Disable( eThis, bInverse ? !eThis.disabled : eThis.disabled );
		if( eThis.onkeyup ){ eThis.onkeyup(); }
		if( eThis.onclick ){ eThis.onclick(); }
	}
	Common.Event.add( eFrom, "click", change_depended );
	if( eFrom.checked ){ change_depended(); }
}

function x_Make_checkbox_dependence( eThis, eFrom, bInverse ){
	function change_depended(){
		eThis.disabled = eFrom.checked ? false : true;
		x_Disable( eThis, bInverse ? !eThis.disabled : eThis.disabled );
		if( eThis.onkeyup ){ eThis.onkeyup(); }
		if( eThis.onclick ){ eThis.onclick(); }
	}
	Common.Event.add( eFrom, "click", change_depended );
	change_depended();
}

function x_Disable( eThis, bDisabled ){
	eThis.disabled = bDisabled;
	if( eThis.disabled ){
		if( eThis.parentNode ){
			Common.Class.add( eThis.parentNode, "disabled" );
		}
	}else{
		if( eThis.parentNode ){
			Common.Class.remove( eThis.parentNode, "disabled" );
		}
	}
	if( eThis.eLabel ){
		eThis.eLabel.setAttribute( "disabled", eThis.disabled );
		eThis.eLabel.parentNode.parentNode.setAttribute( "disabled", eThis.disabled );
	}
}

function x_Make_depended_select( sID, sFromID, aValue ){
	var eFrom = document.getElementById( sFromID + "_i0" );
	eFrom = eFrom ? eFrom : document.getElementById( sFromID );
	var eThis = document.getElementById( sID );
	if( eThis && eFrom ){
		eThis.sSelected = eThis.selectedIndex >= 0 ? eThis.options[eThis.selectedIndex].value : '';
		eThis.aOption = new Array();
		for( var i = 0 ; i < eThis.options.length ; i++ ){
			eThis.aOption[i] = new Array();
			eThis.aOption[i].parent_value = aValue[i];
			eThis.aOption[i].value = eThis.options[i].value;
			eThis.aOption[i].text = eThis.options[i].text;
			eThis.aOption[i].selected = ( eThis.selectedIndex == i );
		}
		if( eFrom.tagName.toUpperCase() == 'SELECT' ){
			function change_depended(){
				var sValue = eFrom.options[eFrom.selectedIndex].value;
				eThis.options.length = 0;
				for( var i = 0, eTmp ; i < eThis.aOption.length ; i++ ){
					if( !eThis.aOption[i].parent_value || eThis.aOption[i].parent_value == sValue ){
						eTmp = new Option( eThis.aOption[i].text, eThis.aOption[i].value );
						eThis.options[eThis.options.length] = eTmp;
					}
				}
				for( i = 0 ; i < eThis.options.length ; i++ ){
					if( eThis.options[i].value == eThis.sSelected ) eThis.options[i].selected = true;
				}
				if( !i ){
					for( var i = 0, eTmp ; i < eThis.aOption.length ; i++ ){
						eTmp = new Option( eThis.aOption[i].text, eThis.aOption[i].value );
						eThis.options[eThis.options.length] = eTmp;
					}
				}
				if( eThis.fChange_depended ){
					eThis.fChange_depended();
				}
			}
			eFrom.fChange_depended = change_depended;
			Common.Event.add( eFrom, "change", change_depended );
			change_depended();
		}else{
			// for radio
		}
	}
}

function x_Make_warning( asID, sType, sHTML, oOptions ){
	if( sType && sHTML ){
		for( var i = 0, eThis, eDepended ; i < asID.length ; i ++ ){
			eThis = document.getElementById( asID[i] );
			if( eThis ){
				eThis.oOptions = oOptions;
				if( !i || eThis.getAttribute( 'type' ) == 'checkbox' ){ eThis['x_' + sType] = sHTML; }
				if( sType == 'required' ){
					eThis['aeFrom'] = new Array();
					for( var j = 0 ; j < asID.length ; j++ ){
						eDepended = document.getElementById( asID[j] );
						if( eDepended ){
							eThis['aeFrom'][eThis['aeFrom'].length] = eDepended;
						}
					}
				}
			}
		}
	}
}

function x_Make_mask( sID, sMask ){
	if( sID && sMask ){
		var eThis = document.getElementById( sID );
		if( eThis ){
			eThis.x_mask = new RegExp( sMask );
		}
		
	}
}

var x_hL = new Array();
x_hL['B8']='\¸';x_hL['E9']='é';x_hL['F6']='\ö';x_hL['F3']='ó';x_hL['EA']='ê';x_hL['E5']='å';x_hL['ED']='í';x_hL['E3']='\ã';x_hL['F8']='ø';x_hL['F9']='ù';x_hL['E7']='ç';x_hL['F5']='õ';x_hL['FA']='ú';x_hL['F4']='ô';x_hL['FB']='û';x_hL['E2']='â';x_hL['E0']='à';x_hL['EF']='ï';x_hL['F0']='ð';x_hL['EE']='î';x_hL['EB']='ë';x_hL['E4']='ä';x_hL['E6']='æ';x_hL['FD']='ý';x_hL['FF']='\ÿ';x_hL['F7']='÷';x_hL['F1']='ñ';x_hL['EC']='ì';x_hL['E8']='è';x_hL['F2']='ò';x_hL['FC']='ü';x_hL['E1']='á';x_hL['FE']='þ';x_hL['A8']='\¨';x_hL['C9']='É';x_hL['D6']='\Ö';x_hL['D3']='Ó';x_hL['CA']='Ê';x_hL['C5']='Å';x_hL['CD']='Í';x_hL['C3']='\Ã';x_hL['D8']='Ø';x_hL['D9']='Ù';x_hL['C7']='Ç';x_hL['D5']='Õ';x_hL['DA']='Ú';x_hL['D4']='Ô';x_hL['DB']='Û';x_hL['C2']='Â';x_hL['C0']='À';x_hL['CF']='Ï';x_hL['D0']='Ð';x_hL['CE']='Î';x_hL['CB']='Ë';x_hL['C4']='Ä';x_hL['C6']='Æ';x_hL['DD']='Ý';x_hL['DF']='\ß';x_hL['D7']='×';x_hL['D1']='Ñ';x_hL['CC']='Ì';x_hL['C8']='È';x_hL['D2']='Ò';x_hL['DC']='Ü';x_hL['C1']='Á';x_hL['DE']='Þ';
var x_hA = new Array();

function xGet_input_value( sURL, sName ){
	var rPattern = new RegExp( '.*[\\?\\&]' + sName + '=([^\\&]+).*' );
	if( sURL.match( rPattern ) ){
		sURL = sURL.replace( rPattern, '$1' ).replace( /\+/g, '%20' );
		if( sURL.indexOf( '%' ) > -1 ){
			for( var i in x_hL ){
				if( x_hL.constructor.prototype[i] ) continue;
				sURL = sURL.replace( new RegExp( '%' + i, 'gi' ), x_hL[i] );
			}
			sURL = unescape( sURL );
		}
		return sURL.replace( /&nbsp;/g, ' ' );
	}else{
		return false;
	}
}

var x_hLabels = new Array();
x_hLabels.ru = {
	month_1:	{ s: '\ßíâàðü', g: '\ÿíâàð\ÿ' },
	month_2:	{ s: 'Ôåâðàëü', g: 'ôåâðàë\ÿ' },
	month_3:	{ s: 'Ìàðò', g: 'ìàðòà' },
	month_4:	{ s: 'Àïðåëü', g: 'àïðåë\ÿ' },
	month_5:	{ s: 'Ìàé', g: 'ìà\ÿ' },
	month_6:	{ s: 'Èþíü', g: 'èþí\ÿ' },
	month_7:	{ s: 'Èþëü', g: 'èþë\ÿ' },
	month_8:	{ s: 'Àâãóñò', g: 'àâãóñòà' },
	month_9:	{ s: 'Ñåíò\ÿáðü', g: 'ñåíò\ÿáð\ÿ' },
	month_10:	{ s: 'Îêò\ÿáðü', g: 'îêò\ÿáð\ÿ' },
	month_11:	{ s: 'Íî\ÿáðü', g: 'íî\ÿáð\ÿ' },
	month_12:	{ s: 'Äåêàáðü', g: 'äåêàáð\ÿ' }
};


function get_date_from_string( sFrom ){
	if( sFrom ){
		if( sFrom.match( /\d{4,4}([\-\.\/])\d{1,2}\1/ ) ){ // YYYY.MM.DD
			sFrom = sFrom.replace( /.*(\d{4,4})([\-\.\/])(\d{1,2})\2(\d{1,2}).*/, '$1 $3 $4' );
		}else if( sFrom.match( /\d{1,2}([\-\.\/])\d{4,4}/ ) ){ // DD.MM.YYYY
			sFrom = sFrom.replace( /.*(\d{1,2})([\-\.\/])(\d{1,2})\2(\d{4,4}).*/, '$4 $3 $1' );
		}else{
			/* YY? */
		}
		var asFrom = ( sFrom.split( ' ' ) );
		return new Date( asFrom[0], asFrom[1] - 1, asFrom[2] );
	}else{
		return false;
	}
}


function x_Make_calendar( eInput, bYear, bMonth, bDay ){
	if( !Common.Class.match( eInput, 'inited' ) ){
		eInput.eCalendar = document.createElement( 'span' );
		var sDay = '', iMonth = 1, sYear = '';
		var dtValue = get_date_from_string( eInput.value );
		if( dtValue ){
			sDay = dtValue.getDate();
			iMonth = dtValue.getMonth() + 1;
			sYear = dtValue.getFullYear();
		}
		var sHTML = '';
		if( bDay ){ sHTML = '<input type="text" size="2" maxlength="2" value="' + sDay + '" />'; }
		if( bMonth ){
				sHTML += '<select class="month">';
			var sCase = bDay ? 'g' : 's';
			for( var i = 1 ; i < 13 ; i++ ){
				sHTML += '<option value="' + i + ( iMonth == i ? '" selected="true' : '' ) + '">' + x_hLabels['ru']['month_' + i][sCase] + '</option>';
			}
			sHTML += '</select>';
		}
		if( bYear ){ sHTML += '<input type="text" size="4" maxlength="4" value="' + sYear + '" />'; }
		eInput.eCalendar.innerHTML += sHTML;
		eInput.parentNode.insertBefore( eInput.eCalendar, eInput );
		eInput.style.visibility = 'hidden';
		eInput.style.position = 'absolute';
		Common.Class.add( eInput, 'inited' );
	}{
		eInput.eCalendar = eInput.previousSibling;
	}
}
// alpha	

function x_Make_combobox(
	sInputId,
	sSelectId
	) {
	
	var oComboBox = new ComboBox(
		document.getElementById(sInputId),
		document.getElementById(sSelectId)
		);	

}

function x_Make_multiply(
	sElementId,
	sButtonAddId,
	sButtonRemoveId,
	iCountAddFields,
	fFunction
	) {
	
	var oXCloner = new x_Cloner(
		sElementId,
		sButtonAddId,
		sButtonRemoveId,
		iCountAddFields,
		fFunction
		);

}

function x_Cloner(
	sElementId,
	sButtonAddId,
	sButtonRemoveId,
	iCountAddFields,
	fFunction
	) {
		
	this.sElementId = sElementId;
	this.oSourceElement = document.getElementById(sElementId);	
	this.oBaseElement = this.oSourceElement.cloneNode(true);
	this.iPostfix = 1;
	this.iFirstElementPostfix = this.iPostfix;
	this.iCounter = 1;	
	this.oObjectInsertBefore = null;
	this.sButtonAddId = sButtonAddId;
	this.sButtonRemoveId = sButtonRemoveId;
	this.oButtonRemove = null;
	this.oButtonAdd = null;
	this.fFunction = fFunction;
	
	var oThis = this;
		
	var oButtonAdd = document.getElementById(sButtonAddId);			
	
	oButtonAdd.onclick = function() {
	
		var oNewElement = oThis.add(0);
		
		if(oThis.fFunction) {
			oThis.fFunction(oNewElement);
		}
	
	};	

	Common.Class.add(oButtonAdd, "first");		
	
	var oButtonRemove = document.getElementById(sButtonRemoveId);				
	
	oButtonRemove.onclick = function() {
	
		oThis.remove(0);
	
	};				
	
	this.aElements = [{oElement : this.oSourceElement, oButtonRemove : oButtonRemove, oButtonAdd : oButtonAdd}];
	
	if(iCountAddFields > 0) {	
		this.processAddFields(iCountAddFields);		
	}
	
	this.checkForDisable();

}

x_Cloner.prototype = {
	
	processAddFields : function(iCountAddFields) {
	
		this.iPostfix += iCountAddFields;	
		this.iCounter += iCountAddFields;
		
		var
			oButtonAdd,
			oButtonRemove,
			oThis = this,
			iCurrentPostfix = this.iPostfix,
			oNewElement
			;
				
		for(var i = 1; i <= iCountAddFields; i++) {
		
			oNewElement = document.getElementById(this.sElementId + '_' + i);
			
			oButtonAdd = document.getElementById(this.sButtonAddId + '_' + i);
			
			if(oButtonAdd) {
			
				oButtonAdd.iPostfix = i;
			
				oButtonAdd.onclick = function() {
							
					var oNewElement = oThis.add(this.iPostfix);
							
					if(oThis.fFunction) {
						oThis.fFunction(oNewElement);
					}
					
				}
			
			}
			
			oButtonRemove = document.getElementById(this.sButtonRemoveId + '_' + i);
			
			if(oButtonRemove) {
			
				oButtonRemove.iPostfix = i;
			
				 oButtonRemove.onclick = function() {
							
					oThis.remove(this.iPostfix);											
					
				}
			
			}
			
			this.aElements[i] = {oElement : oNewElement, oButtonAdd : oButtonAdd, oButtonRemove : oButtonRemove};
			
		}
	
	},
	
	add : function(iPostfix) {
		
		var			
			oNewElement = this.oBaseElement.cloneNode(true),								
			oButtonRemove,
			oButtonAdd
			;				

		if(oNewElement.id) {
			oNewElement.id += '_' + this.iPostfix;
		}
		
		if(oNewElement.name) {
			oNewElement.name += '_' + this.iPostfix;
		}
		
		this.changeAttributes(oNewElement);
		
		var oElement = this.aElements[iPostfix].oElement;
		
		if(oElement.nextSibling) {
			oElement.parentNode.insertBefore(oNewElement, oElement.nextSibling);					
		}
		else {
			oElement.parentNode.appendChild(oNewElement);
		}
		
		this.aElements[this.iPostfix] = {oElement : oNewElement, oButtonRemove : this.oButtonRemove, oButtonAdd : this.oButtonAdd};
		
		this.iPostfix++;
		this.iCounter++;				
		
		this.reindexNames(oNewElement.parentNode, oNewElement.tagName.toLowerCase());
		this.checkForDisable();
		
		//fix ie bug
		document.body.className += '';
		
		return oNewElement;
		
	},
	
	reindexNames : function(
		oElement,
		sParentTagName
		) {
	
		var
			oElements = oElement.getElementsByTagName(sParentTagName);
			iCounter = 0,
			aInputsChildren = null,
			aTagNames = ['input', 'select', 'textarea'],
			sBaseName = ''
			;
		
		for(var i = 0; i < oElements.length; i++) {
			
			if(oElements[i].id.indexOf(this.sElementId) > -1) {
				
				for(var j = 0; j < aTagNames.length; j++) {
				
					aInputsChildren = oElements[i].getElementsByTagName(aTagNames[j]);
					
					for(var k = 0; k < aInputsChildren.length; k++) {
						
						if(aInputsChildren[k].name) {
							
							sBaseName = aInputsChildren[k].name.match(/^(.+)_(\d+)$/);
							
							if(sBaseName) {
								aInputsChildren[k].name = sBaseName[1] + (iCounter > 0? '_' + iCounter : '');
							}
							
						}
					
					}
					
				}										
				
				iCounter++;
			
			}
		
		}
	
	},
	
	changeAttributes : function(oElement) {
	
		var
			oThis = this,			
			aNodes = oElement.childNodes,
			iCurrentPostfix = this.iPostfix
			;
		
		for(var i = 0; i < aNodes.length; i++) {
		
			if(aNodes[i].nodeType == 1) {
			
				if(aNodes[i].name) {						
									
					aNodes[i].name += '_' + iCurrentPostfix;										
					
				}
				
				if(aNodes[i].id) {				
				
					if(aNodes[i].id == this.sButtonAddId) {
							
						this.oButtonAdd = aNodes[i];
							
						this.oButtonAdd.onclick = function() {
							
							var oNewElement = oThis.add(iCurrentPostfix);
							
							if(oThis.fFunction) {
								oThis.fFunction(oNewElement);
							}
						
						}
							
					}
					else if (aNodes[i].id == this.sButtonRemoveId){
						
						this.oButtonRemove = aNodes[i];
							
						this.oButtonRemove.onclick = function() {
							
							oThis.remove(iCurrentPostfix);
						
						}
						
					}									
				
					aNodes[i].id += '_' + iCurrentPostfix;										
					
				}
				
				if(aNodes[i].htmlFor) {				
					aNodes[i].htmlFor += '_' + iCurrentPostfix;
				}
				
				if((aNodes[i].tagName.toLowerCase() == 'input' && aNodes[i].type == 'text') || aNodes[i].tagName.toLowerCase() == 'textarea') {
					aNodes[i].value = '';
				}
				
				if( aNodes[i].tagName.toLowerCase() == 'input' || aNodes[i].tagName.toLowerCase() == 'textarea' || aNodes[i].tagName.toLowerCase() == 'select' ) {
					x_Get_accompanied_elements( aNodes[i] );
					x_Add_events( aNodes[i] );
				}
				
				if(aNodes[i].childNodes.length > 0) {					
					this.changeAttributes(aNodes[i]);
				}
				
			}
			
				
		}					
	
	},
	
	remove : function(iPostfix) {
	
		var oElementForRemove = this.aElements[iPostfix];
		
		if(oElementForRemove) {				
			
			if(this.iFirstElementPostfix == iPostfix) {
							
				for(var i = iPostfix + 1, bFounded = false; i < this.aElements.length && !bFounded; i++) {
				
					if(this.aElements[i]) {
					
						bFounded = true;
						
						this.iFirstElementPostfix = i;
						Common.Class.add(this.aElements[i].oButtonAdd, "first");
						
					}
				
				}
			
			}
		
			oElementForRemove.oElement.parentNode.removeChild(oElementForRemove.oElement);
			oElementForRemove = null;						
		
		}
	
		this.iCounter--;
		
		this.checkForDisable();				
	
	},
	
	checkForDisable : function() {
	
		var bDisable = this.iCounter == 1? true : false;
		
		for(var i in this.aElements) {
			if( this.aElements.constructor.prototype[i] ) continue;
		
			if(this.aElements[i]) {
			
				this.aElements[i].oButtonRemove.disabled = bDisable;
				
				bDisable? Common.Class.add(this.aElements[i].oButtonRemove, "disabled") : Common.Class.remove(this.aElements[i].oButtonRemove, "disabled");
			
			}
		
		}
	
	
	}

};
