function RelateSelect(rs1,rs2,rs3,varray,lnk,varistext){
	this.L1OnChange = function(){
		if(this.rsobj.length > 1) this.clearOptions(this.rsobj[1]);
		if(this.rsobj.length > 2) this.clearOptions(this.rsobj[2]);
		var select_index = $(this.rsobj[0]).selectedIndex;
		var l1value = $(this.rsobj[0]).options[select_index].value;

		if(this.rsobj.length > 1) this.initL2(l1value);
	}

	this.L2OnChange = function(){
		if(this.rsobj.length > 2) this.clearOptions(this.rsobj[2]);
		var select_index;
		select_index = $(this.rsobj[0]).selectedIndex;
		var l1value = $(this.rsobj[0]).options[select_index].value;
		select_index = $(this.rsobj[1]).selectedIndex;
		var l2value = $(this.rsobj[1]).options[select_index].value;

		if(this.rsobj.length > 2) this.initL3(l1value,l2value);
	}

	this.AddEventHandler = function(oTarget,sEventType,fnHandler){
		if(oTarget.addEventListener)
			oTarget.addEventListener(sEventType,fnHandler,false);
		else if(oTarget.attachEvent)
			oTarget.attachEvent('on'+sEventType,fnHandler);
		else
			oTarget['on'+sEventType] = fnHandler;
	}

	this.initL1 = function(){
		try{
			var url = this.url + "&lv=1";
			this.rsAjax.open("GET", url, true);
			this.rsAjax.onreadystatechange = this.initL1OK.bind(this);
			this.rsAjax.send(null);
		}catch(exception){alert(exception);}
	}

	this.initL1OK = function(){
		if (this.rsAjax.readyState == 4 && this.rsAjax.status == 200) {
			var response = this.rsAjax.responseText;
			
			try{
				this.clearOptions(this.rsobj[0]);
				var i = 0;
				var arr = response.split(",");
				var arrValue = new Array(), arrText = new Array(), arrTemp = new Array();
				for(i=0, arrLen = arr.length; i < arrLen; i++){
					arrTemp = arr[i].split("-");
					arrValue[i] = arrTemp[0];
					arrText[i] = arrTemp[1];
				}

				this.addOptions(this.rsobj[0], arrValue, arrText);
				this.setSelected(this.rsobj[0], this.defval[0]);

				var select_index;
				select_index = $(this.rsobj[0]).selectedIndex;
				var l1value = $(this.rsobj[0]).options[select_index].value;

				if (this.rsobj.length > 1) this.initL2(l1value);
				this.defval[0] = "";
			}catch(exception){alert(exception);}
		}
	}

	this.initL2 = function(l1value){
		try{
			var url = this.url + "&lv=2&val1=" + escape(l1value);
			this.rsAjax.open("GET", url, true);
			this.rsAjax.onreadystatechange = this.initL2Ok.bind(this);
			this.rsAjax.send(null);
		}catch(exception){alert(exception);}	
	}

	this.initL2Ok = function(){
		if (this.rsAjax.readyState == 4 && this.rsAjax.status == 200) {
			var response = this.rsAjax.responseText;

			try{
				this.clearOptions(this.rsobj[1]);
				var i = 0;
				var arr = response.split(",");
				var arrValue = new Array(), arrText = new Array(), arrTemp = new Array();
				for(i=0, arrLen = arr.length; i < arrLen; i++){
					arrTemp = arr[i].split("-");
					arrValue[i] = arrTemp[0];
					arrText[i] = arrTemp[1];
				}

				this.addOptions(this.rsobj[1], arrValue, arrText);
				this.setSelected(this.rsobj[1], this.defval[1]);

				var select_index;
				select_index = $(this.rsobj[0]).selectedIndex;
				var l1value = $(this.rsobj[0]).options[select_index].value;
				select_index = $(this.rsobj[1]).selectedIndex;
				var l2value = $(this.rsobj[1]).options[select_index].value;

				if (this.rsobj.length > 2) this.initL3(l1value,l2value);
				this.defval[1] = "";
			}catch(exception){alert(exception);}
		}
	}

	this.initL3 = function(l1value,l2value){
		try{
			var url = this.url + "&lv=3&val1=" + l1value + "&val2=" + escape(l2value);
			this.rsAjax.open("GET", url, true);
			this.rsAjax.onreadystatechange = this.initL3Ok.bind(this);
			this.rsAjax.send(null);
		}catch(exception){alert(exception);}	
	}

	this.initL3Ok = function(){
		if (this.rsAjax.readyState == 4 && this.rsAjax.status == 200) {
			var response = this.rsAjax.responseText;

			try{
				this.clearOptions(this.rsobj[2]);
				var i = 0;
				var arr = response.split(",");
				var arrValue = new Array(), arrText = new Array(), arrTemp = new Array();
				for(i=0, arrLen = arr.length; i < arrLen; i++){
					arrTemp = arr[i].split("-");
					arrValue[i] = arrTemp[0];
					arrText[i] = arrTemp[1];
				}

				this.addOptions(this.rsobj[2], arrValue, arrText);
				this.setSelected(this.rsobj[2], this.defval[2]);
				this.defval[2] = "";
			}catch(exception){alert(exception);}
		}
	}

	this.addOptions = function(selectId, arrValue, arrText){
		if($(selectId) != undefined){
			for(i = 0, arrLen = arrValue.length; i < arrLen; i++){
				$(selectId).options.add(new Option(arrText[i], arrValue[i]));
			}
		}else{
			return false;
		}
	}

	this.clearOptions = function(selectId){
		if($(selectId) != undefined){
			$(selectId).options.length = 0;
		}else{
			return false;
		}
	}

	this.setSelected = function(selectId, value){
		if($(selectId) != undefined){
			for(var i = 0 ;i < $(selectId).options.length;i++)
				if (($(selectId).options[i].value == value && !this.varistext) || 
					($(selectId).options[i].text == value && this.varistext))
					$(selectId).options[i].selected = true;
		}else{
			return false;
		}
	}

	this.rsAjax = Ajax.getTransport();
	this.rsobj = new Array();

	if (rs1.length > 0 && $(rs1)){
		this.AddEventHandler($(rs1),"change",this.L1OnChange.bind(this));
		this.rsobj[0] = rs1;
	}
	if (rs2.length > 0 && $(rs2)){
		this.AddEventHandler($(rs2),"change",this.L2OnChange.bind(this));
		this.rsobj[1] = rs2;
	}
	if (rs3.length > 0 && $(rs3)){
		this.rsobj[2] = rs3;
	}

	this.defval = varray;
	this.url = lnk
	this.initL1();
	this.varistext = varistext;
}

function DateSelect(y,m,d,arval){
	this.initYear = function(){
		var iYear = this.now.getFullYear();
		this.year.options.length = 0;
		if(this.month) this.month.options.length = 0;
		if(this.day) this.day.options.length = 0;
		this.year.options.add(new Option("",""));
		for(var i = 0;i < 80;i++) this.year.options.add(new Option(iYear - i, iYear - i));
		if(this.defval[0]) this.setSelected(this.year.id,this.defval[0]);
		if(this.month) this.initMonth();
		this.defval[0] = "";
	}

	this.initMonth = function(){
		var y = this.year.options[this.year.selectedIndex].value;
		this.month.options.length = 0;
		if(this.day) this.day.options.length = 0;
		this.month.options.add(new Option("",""));
		if (y.length > 0){
			for(var i = 1;i <= 12;i++) this.month.options.add(new Option(i,i));
			this.setSelected(this.month.id,this.defval[1]);
			if(this.day) this.initDay();
		}
		this.defval[1] = "";
	}

	this.initDay = function(){
		var mday = [0,31,28,31,30,31,30,31,31,30,31,30,31];
		var y = this.year.options[this.year.selectedIndex].value;
		var m = this.month.options[this.month.selectedIndex].value;
		if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) mday[2] ++;
		this.day.options.length = 0;
		this.day.options.add(new Option("",""));
		for(var i = 1;i <= mday[m]; i++) this.day.options.add(new Option(i,i));
		this.setSelected(this.day.id,this.defval[2]);
		this.defval[2] = "";
	}

	this.setSelected = function(selectId, value){
		if($(selectId) != undefined){
			for(var i = 0 ;i < $(selectId).options.length;i++)
				if ($(selectId).options[i].value == value)
					$(selectId).options[i].selected = true;		
		}else{
			return false;
		}
	}

	this.AddEventHandler = function(oTarget,sEventType,fnHandler){
		if(oTarget.addEventListener)
			oTarget.addEventListener(sEventType,fnHandler,false);
		else if(oTarget.attachEvent)
			oTarget.attachEvent('on'+sEventType,fnHandler);
		else oTarget['on'+sEventType] = fnHandler;
	}

	if(y.length > 0 && $(y)){
		this.year = $(y);
		this.AddEventHandler(this.year,"change",this.initMonth.bind(this));
	}
	if(m.length > 0 && $(m)){
		this.month = $(m);
		this.AddEventHandler(this.month,"change",this.initDay.bind(this));
	}
	if(d.length > 0 && $(d)) this.day = $(d);

	this.now = new Date();
	this.defval = arval;
	this.initYear();
}
