var HTMLWindow; if (!HTMLWindow)
HTMLWindow = function(ele)
{

	this.$=HTMLWindow.$;
	this.show=HTMLWindow.show;
	this.close=HTMLWindow.close;
	this.bgWidth=HTMLWindow.bgWidth;
	this.addDiv=HTMLWindow.addDiv;
	this.allDivToContainer=HTMLWindow.allDivToContainer;
	this.getEleByIdContainer=HTMLWindow.getEleByIdContainer;
	this.messageBox=HTMLWindow.messageBox;
	this.showMessage=HTMLWindow.showMessage;
	this.closeMessage=HTMLWindow.closeMessage;
	this.setImagePath=HTMLWindow.setImagePath;
	this.butCap= new HTMLWindow.buttonCaption;
	this.imagePath=HTMLWindow.imagePath;
	this.messagesInnerHTML=HTMLWindow.messagesInnerHTML;
	this.setButtonCaption=HTMLWindow.setButtonCaption;
	this.onClose=HTMLWindow.onClose;

	HTMLWindow.Notifier.call(this);
	this.element =HTMLWindow.$(ele);

	this.pendingRequest=null;
	this.result=false;
	this.container=document.createElement("div");
	this.messages=document.createElement("div");
	this.messages.innerHTML=HTMLWindow.messagesInnerHTML();
};
HTMLWindow.$=function(ele){
	if(ele && typeof ele=="string")
		return document.getElementById(ele);
	return ele;
};
HTMLWindow.imagePath='img/';
HTMLWindow.setImagePath=function(ele){	if(ele){		this.imagePath=ele;
		this.messages.innerHTML=this.messagesInnerHTML();
	}
};
HTMLWindow.messagesInnerHTML=function(){	str='';
	if(this.butCap){	str='<div id="yesno">'+
			'<div id="caption" class="htmlwindowcaption"></div>'+
			'<table id="tableText" style="margin:0;padding:0;">'+
				'<td width="25px"><img src="'+this.imagePath+'question.gif"></td>'+
				'<td><div id="text" style="float:left;">&nbsp;</div></td>'+
			'</tr><tr>'+
				'<td colspan="2" style="padding: 0px;"><center><input class="buttonwindow" type="button" value=" '+this.butCap.bYes+' " name="yes" onclick="HTMLWindow.result=true;HTMLWindow.closeMessage();">&nbsp;&nbsp;'+
				'<input class="buttonwindow" type="button" value=" '+this.butCap.bNo+' " name="no" onclick="HTMLWindow.result=false;HTMLWindow.closeMessage();"></center></td>'+
			'</tr></table>'+
		'</div>';
	str=str+'<div id="error">'+
				'<div id="caption" class="htmlwindowcaption"></div>'+
				'<table id="tableText" style="margin:0;padding:0;">'+
					'<td width="25px"><img src="'+this.imagePath+'error.gif"></td>'+
					'<td><div id="text" style="float:left;">&nbsp;</div></td>'+
				'</tr><tr>'+
					'<td colspan="2" style="padding: 0px;"><center><input class="buttonwindow" type="button" value=" '+this.butCap.bOk+' " name="yes" onclick="HTMLWindow.closeMessage();"></center></td>'+
				'</tr></table>'+
			'</div>';
	str=str+'<div id="warning">'+
				'<div id="caption" class="htmlwindowcaption">Warning!</div>'+
				'<table id="tableText" style="margin:0;padding:0;">'+
					'<td width="25px"><img src="'+this.imagePath+'warning.gif"></td>'+
					'<td><div id="text" style="float:left;">&nbsp;</div></td>'+
				'</tr><tr>'+
					'<td colspan="2" style="padding: 0px;"><center><input class="buttonwindow" type="button" value=" '+this.butCap.bOk+' " name="yes" onclick="HTMLWindow.closeMessage();"></center></td>'+
				'</tr></table>'+
			'</div>';
	str=str+'<div id="question">'+
				'<div id="caption" class="htmlwindowcaption"></div>'+
				'<table id="tableText" style="margin:0;padding:0;">'+
					'<td width="25px"><img src="'+this.imagePath+'question.gif"></td>'+
					'<td><div id="text" style="float:left;">&nbsp;</div></td>'+
				'</tr><tr>'+
					'<td colspan="2" style="padding: 0px;"><center><input class="buttonwindow" type="button" value=" '+this.butCap.bYes+' " name="yes" onclick="'+this.element.id+'.closeMessage();"></center></td>'+
				'</tr></table>'+
			'</div>';
	str=str+'<div id="success">'+
				'<div id="caption" class="htmlwindowcaption">Success!</div>'+
				'<table id="tableText" style="margin:0;padding:0;">'+
					'<td width="25px"><img src="'+this.imagePath+'success.gif"></td>'+
					'<td><div id="text" style="float:left;">&nbsp;</div></td>'+
				'</tr><tr>'+
					'<td colspan="2" style="padding: 0px;"><center><input class="buttonwindow" type="button" value=" '+this.butCap.bOk+' " name="yes" onclick="HTMLWindow.closeMessage();"></center></td>'+
				'</tr></table>'+
			'</div>';
	};
	return str;
};
HTMLWindow.Notifier = function()
{
	this.observers=[];
	this.suppressNotifications=0;
};
HTMLWindow.Notifier.prototype.addObserver=function(observer)
{
	if(!observer)
		return;

	var len=this.observers.length;
	for(var i=0; i<len; i++){
		if(this.observers[i]==observer)
			return;
	}
	this.observers[len]=observer;
};
HTMLWindow.hasClassName=function(ele,className)
{
	ele=this.$(ele);
	if(!ele || !className || !ele.className || ele.className.search(new RegExp("\\b" + className + "\\b")) == -1)
		return false;
	return true;
};
HTMLWindow.removeClassName = function(ele, className)
{
	ele=this.$(ele);
	if(HTMLWindow.hasClassName(ele, className))
		ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};

HTMLWindow.removeAndExtractContent = function(ele, className)
{
	var d=document.createElement("div");
	if(ele){
		d.appendChild(ele);
		if(className)
			HTMLWindow.removeClassName(ele, className);
	}
	return d.innerHTML;
};
//************************************************************************//
HTMLWindow.close=function(){
	this.element.style.display='none';
	this.$('HTMLWindowbg').className='HTMLWindowbghidden';
	if(this.container)
		this.allDivToContainer(this.element,this.container);
}
HTMLWindow.getEleByIdContainer=function(ele,fromContainer){	if(fromContainer){cont=fromContainer}else{cont=this.container}	for(ind in cont.childNodes){		if(cont.childNodes[ind].id==ele){			return cont.childNodes[ind];
		}	}}
HTMLWindow.allDivToContainer=function(fromDiv,toDiv){

	if(fromDiv&&toDiv){
		if(fromDiv.childNodes.length>0){
			for(ind in fromDiv.childNodes){
				if(fromDiv.childNodes[ind].tagName=='DIV'){
					toDiv.appendChild(fromDiv.childNodes[ind]);
				}
			}
		}
	}
}
HTMLWindow.addDiv=function(ele){
	if (ele){
		if(this.element.childNodes.length>0)
			this.allDivToContainer(this.element,this.container);
		this.element.appendChild(ele);
		ele.style.display='block';
		return true;
	}else return false;
}
HTMLWindow.bgWidth=function(width){	this.$('HTMLWindowbg').style.width=document.body.scrollWidth;
	this.$('HTMLWindowbg').style.height=document.body.scrollHeight;
	this.$('HTMLWindowbg').className='HTMLWindowbgvisible';
	if(width){
		this.element.style.width=width;
		if(width.substr(width.length-1,1)=='%'){
			this.element.style.left=parseInt((100-parseInt(width))/2)+'%';
		}
		if(width.substr(width.length-2,2)=='px'){
			this.element.style.left=parseInt((screen.width-parseInt(width))/2)+'px';
		}
		if(width=='auto'){
			this.element.style.width=this.element.clientWidth+5;		}
		this.element.style.left=parseInt((document.body.clientWidth-this.element.clientWidth)/2)+'px';
		this.element.style.top=(parseInt((document.body.clientHeight-this.element.clientHeight)/2)+document.body.scrollTop)+'px';

	}
}
HTMLWindow.show=function(idDiv,width){
	if(this.element){
	this.element.style.display='block';
		if(!this.addDiv(this.$(idDiv))){			this.addDiv(this.getEleByIdContainer(idDiv));
		}
		this.bgWidth(width);
	}
}
HTMLWindow.showMessage=function(width,type){
	this.element.style.display='block';
	this.bgWidth(width);
}
HTMLWindow.closeMessage=function(){
	this.onClose(this.result);
	this.onClose=function(){};
	this.result=false;
	this.element.style.display='none';
	this.$('HTMLWindowbg').className='HTMLWindowbghidden';
	if(this.messages)
		this.allDivToContainer(this.element,this.messages);
}
HTMLWindow.messageBox=function(lpText,lpCaption,ele){
	res=false;
	if((lpText&&typeof lpText=="string")&&(typeof lpCaption=="string")&&(ele&&typeof ele=="string")){
		ele=ele.toUpperCase();
		switch (ele){
		case "YESNO":
			ele=this.element.appendChild(this.getEleByIdContainer('yesno',this.messages));
			ele.style.width='auto';
			if(lpCaption)this.getEleByIdContainer('caption',ele).innerHTML=lpCaption;
			table=this.getEleByIdContainer('tableText',ele);
			this.getEleByIdContainer('text',table.rows[0].cells[1]).innerHTML=lpText;
			this.showMessage('auto');
		break;
		case "QUESTION":
			ele=this.element.appendChild(this.getEleByIdContainer('question',this.messages));
			ele.style.width='auto';
			if(lpCaption)this.getEleByIdContainer('caption',ele).innerHTML=lpCaption;
			table=this.getEleByIdContainer('tableText',ele);
			this.getEleByIdContainer('text',table.rows[0].cells[1]).innerHTML=lpText;
			this.showMessage('auto');
		break;
		case "WARNING":
			ele=this.element.appendChild(this.getEleByIdContainer('warning',this.messages));
			ele.style.width='auto';
			if(lpCaption)this.getEleByIdContainer('caption',ele).innerHTML=lpCaption;
			table=this.getEleByIdContainer('tableText',ele);
			this.getEleByIdContainer('text',table.rows[0].cells[1]).innerHTML=lpText;
			this.showMessage('auto');
		break;
		case "ERROR":
			ele=this.element.appendChild(this.getEleByIdContainer('error',this.messages));
			ele.style.width='auto';
			if(lpCaption)this.getEleByIdContainer('caption',ele).innerHTML=lpCaption;
			table=this.getEleByIdContainer('tableText',ele);
			this.getEleByIdContainer('text',table.rows[0].cells[1]).innerHTML=lpText;
			this.showMessage('auto');
		break;
		case "SUCCESS":
			ele=this.element.appendChild(this.getEleByIdContainer('success',this.messages));
			ele.style.width='auto';
			if(lpCaption)this.getEleByIdContainer('caption',ele).innerHTML=lpCaption;
			table=this.getEleByIdContainer('tableText',ele);
			this.getEleByIdContainer('text',table.rows[0].cells[1]).innerHTML=lpText;
			this.showMessage('auto');
		break;
		default:
			ele=this.element.appendChild(this.getEleByIdContainer('question',this.messages));
			if(lpCaption)this.getEleByIdContainer('caption',ele).innerHTML=lpCaption;
			this.getEleByIdContainer('text',ele).innerHTML=lpText;
			this.showMessage('auto');
		}
	}
	return res;
}

HTMLWindow.buttonCaption=function(){
	this.bOk='Ok';
	this.bYes='Yes';
	this.bNo='No';
}

HTMLWindow.setButtonCaption=function(eleOk,eleYes,eleNo){	if(this.butCap){		if(eleOk)this.butCap.bOk=eleOk;
		if(eleYes)this.butCap.bYes=eleYes;
		if(eleNo)this.butCap.bNo=eleNo;
	}
	if(eleOk||eleYes||eleNo)
		this.messages.innerHTML=this.messagesInnerHTML();};

HTMLWindow.onClose=function(result){
	this.result=result;
}


