modalwindow = function(obj, src, argmnts, screenopacity){
	this.parent = obj;
	this.screen = new solidscreen(screenopacity ? screenopacity : null);
	this.screen.parent = this;

	this.buffer = new htmlbuffer(this);
	this.buffer.setSrc(src);

//	window.open(src, null, null);

	this.close = function(){
		this.screen.clickEnable = true;
		this.screen.clear();
	}

	this.onDone = function(result){
		this.screen.clickEnable = false;

		var odiv = document.createElement("DIV");
		odiv.parent = this;
		odiv.style.visibility = 'hidden';

		odiv.className = 'windowpopup';
		this.screen.element.appendChild(odiv);

		var oWidth = odiv.offsetWidth;
		var oHeight = odiv.offsetHeight;

		var oLeft = document.body.scrollLeft + (document.body.clientWidth - oWidth) / 2;
		var oTop = document.body.scrollTop + (document.body.clientHeight - oHeight) / 2;

		var cdiv = document.createElement("DIV");
		cdiv.className = 'container';
		odiv.appendChild(cdiv);

		if(result.title){
			var d = document.createElement("DIV");
			d.className = 'tableHeader';
			cdiv.appendChild(d);
			var dd = document.createElement("DIV");
			d.appendChild(dd);

			var tdiv = document.createElement("DIV");
			tdiv.className = 'title';
			tdiv.innerHTML = result.title;
			cdiv.appendChild(tdiv);

			if(result.subtitle){
					var stdiv = document.createElement("DIV");
					stdiv.className = 'sub';
					tdiv.appendChild(stdiv);
					stdiv.innerHTML = result.subtitle;
			}
		}

		var cntnt = document.createElement("DIV");
		cntnt.className = 'content';
		cdiv.appendChild(cntnt);
		cntnt.style.height = 377 - cntnt.offsetTop;

		var cntntDiv = document.createElement("DIV");
		cntntDiv.className = 'div';
		cntnt.appendChild(cntntDiv);

		cntntDiv.innerHTML = result.content;

		with(odiv.style){
			top			= oTop;
			left		= oLeft;
			visibility	= 'visible';
		}

		var formbtns = $("div.buttons", cntntDiv);
		if(formbtns.length > 0){
				var $cntnt = $(cntnt);
				var obtn = $(formbtns[0]);

				var ofrm = obtn.prev();

				$(cntntDiv).css('padding', '0');
				ofrm.css('overflow-Y', 'auto');
				ofrm.css('padding-top', '10px');

				$cntnt.css('overflow', 'hidden');



				ofrm.height($cntnt.height() - obtn.height());
		}


		var odivClose = document.createElement("DIV");
		odivClose.parent = this;
		odivClose.className = 'close';
		cdiv.appendChild(odivClose);

		odivClose.style.right = '0px';
			
		// cdiv.offsetWidth - odivClose.offsetWidth;

		odivClose.onclick = function(){
			this.parent.close();
		}
	}
}

function getMyWindow(obj){
	while(obj){
		if(obj.className.indexOf('windowpopup') != -1){
			return obj;
		}
		obj = obj.parentNode;
	}
	return false;
}

function windowSubmit(obj){
	var winobj = getMyWindow(obj);
	if(!obj) return;

	var inputs = winobj.getElementsByTagName("INPUT");
	if(!inputs) return;

	var result = {};
	for(var i = 0; i < inputs.length; i++){
		var cinput = inputs[i];
		switch(cinput.type){
			case 'checkbox':
			case 'radio':
				if(!cinput.checked) continue;
				break;
			default:
				if(!cinput.value) continue;
				break;
		}


		if(cinput.result || cinput.getAttribute('result')){
			var cresult = cinput.result || cinput.getAttribute('result');
			cvalue = typeof(cresult) == 'string' ? eval(cresult) : cresult;
			cvalue.value = cinput.value;
		}else{
			cvalue = cinput.value;
		}

		if(result[cinput.name]){
			result[cinput.name] = Array(result[cinput.name]);
			result[cinput.name].push(cvalue);
		}else{
			result[cinput.name] = cvalue;
		}
	}
	winobj.parent.onSubmitWindow(result);
}
