var DisplayShow='block';
var DisplayHide='none';
var FloatContainerCounter=0;

function FloatContainer() {
	this.Url;
	this.Container;
	this.Header;
	this.Body;
	this.ContainerClass	='PopUp';
	this.HeaderClass	='PopUpHeader';
	this.BodyClass		='PopUpBody';
	this.BorderWidth;
	this.ContainerID	='';
	this.CURSOR			=0;
	this.CENTER			=1;
	this.IE				=document.all ? true : false;

	this.SetContainerClass=function(className) {
		this.ContainerClass=className;
	};
	this.SetBorderWidth=function(borderWidth) {
		this.BorderWidth=borderWidth;
	};
	this.SetUrl=function(url) {
		this.Url=url;
	};
	this.LoadGraphic=function(url) {
		var image=new Image();
		image.src=url;
	};
	this.Handler=function(response) {
		this.Container.style.display=DisplayShow;
	};
	this.ErrHandler=function(response) {
		this.Container.style.display=DisplayShow;
	};
	this.SetWidth=function(width) {
		this.Container.style.width=width;
	};
	this.SetBodyHTML=function(html) {
		if (!this.Body) {
			this.Body				=document.createElement('div');
			this.Body.className		=this.BodyClass;
			this.Body.title			='Click to close.';
			this.Body.onclick		=function() { 
				var node=this.parentNode;
				node.style.display=DisplayHide;
				node.parentNode.removeChild(node);
				//var win=window.open(''); win.document.write(document.body.innerHTML);
			};
		}
		this.Body.innerHTML=html;
	};
	this.SetHeaderHTML=function(html) {
		if (!this.Header) {
			this.Header				=document.createElement('div');
			this.Header.className	=this.HeaderClass;
			this.Header.onmouseup=function() { dragok=false;};
		}
		this.Header.innerHTML=html;
	};
	this.SetPosition=function(position) {
		switch (position) {
			case this.CURSOR:
				if (this.IE) {
					this.Container.style.top	=((Position.Y-1+1)+(DocPosition.Y-1+1))+'px';
					this.Container.style.left	=((Position.X-1+1)+(DocPosition.X-1+1))+'px';
				} else {
					this.Container.style.top	=((Position.Y-DocPosition.Y)+(DocPosition.Y-1+1))+'px';
					this.Container.style.left	=((Position.X-1+1)+(DocPosition.X-1+1))+'px';
				}
				/*
				if (this.IE) {
					this.Container.style.top	=((Position.Y-1+1)+(DocPosition.Y-1+1))+'px';
					var leftMin					=document.body.clientWidth-this.Container.offsetWidth;
					var leftCursor				=(Position.X-1+1)+(DocPosition.X-1+1);
					window.status				=[leftMin,leftCursor].join(' ');
					this.Container.style.left	=Math.min(leftMin,leftMax)+'px';
				} else {
					this.Container.style.top	=((Position.Y-DocPosition.Y)+(DocPosition.Y-1+1))+'px';
					var leftMin					=window.innerWidth-this.Container.offsetWidth;
					var leftCursor				=(Position.X-1+1)+(DocPosition.X-1+1);
					window.status				=[leftMin,leftCursor].join(' ');
					this.Container.style.left	=Math.min(leftMin,leftCursor)+'px';
				}*/
				/*this.Container.style.zIndex = ZIndex++;
				d = this.Container;
				dx = parseInt(this.Container.style.left+0);
				dy = parseInt(this.Container.style.top+0);
				x = e.clientX;
				y = e.clientY;
				if (IE) {
					d.style.left = Math.max(Math.min(document.body.clientWidth-d.offsetWidth,dx + e.clientX - x), 0) + "px";
					d.style.top  = Math.max(dy + e.clientY - y, 0) + "px";
				}
				else {
					d.style.left = Math.max(Math.min(window.innerWidth-d.offsetWidth,dx + e.clientX - x), 0) + "px";
					d.style.top  = Math.max(dy + e.clientY - y, 0) + "px";
				}*/
				break;
			case this.CENTER:
				if (this.IE) {
					this.Container.style.left = document.body.clientWidth/2-this.Container.offsetWidth/2+'px';
					this.Container.style.top  = document.documentElement.clientHeight/2-this.Container.offsetHeight/2+DocPosition.Y+'px';
				}
				else {
					this.Container.style.left = window.innerWidth/2-this.Container.offsetWidth/2+'px';
					this.Container.style.top  = window.innerHeight/2-this.Container.offsetHeight/2+DocPosition.Y+'px';
				}
				break;
		}
	};
	this.Show=function() {
		this.Container			=document.createElement('div');
		FloatContainerCounter++;
		this.ContainerID		='FloatContainer'+FloatContainerCounter;
		this.Container.id		=this.ContainerID;
		this.Container.className=this.ContainerClass;

		this.Container.appendChild(this.Header);
		this.Container.appendChild(this.Body);
		this.Container.style.zIndex = ZIndex++;

		document.body.appendChild(this.Container);

//		this.Container.style.top	=(DocPosition.Y)+'px';
//		this.Container.style.left	=(DocPosition.X)+'px';
/*
		try {
			var xmlObject=new XmlHttpObject();			
			with (xmlObject) {
				setXmlHttp();
				var handler=this.Handler;
				var errHandler=this.ErrHandler;
				var container=this.Container;
				
				xmlHttp.open('Get', this.Url, true );
				xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8'); 

				xmlHttp.onreadystatechange=function() {
					if (xmlHttp.readyState==4) {
						try {
							var response=xmlHttp.responseText.trim();
							container.innerHTML=response;
							container.style.display=DisplayShow;
							setTimeout(
								function() {
									var position=GetCenteredPosition(container);
									container.style.left=position.Left+'px';
									container.style.top=position.Top+'px';
									//alert(new Array(container.style.left,container.style.top).join('\n'));
								}
								,100
							);
						} catch(e) { alert(e); }
					}
				}
				xmlHttp.send(null);
			}
		} catch(e) { alert(e); };
*/
	};
	this.Hide=function() {
		this.Container.style.display=DisplayHide;
	};	
}
//function Position(left, top) {
//	this.Left=left;
//	this.Top=top;
//	this.toString=function() {
//		return(new Array(this.Left, this.Top).join('\n'));
//	};
//}
function ShowIconLegend() {
	var GraphicUrl='/graphics/productLegendChartBodyOnly.gif';
	var container=new FloatContainer();
	with (container) {
//		LoadGraphic(GraphicUrl);
		SetHeaderHTML('Aquatropic');
		SetBodyHTML(['<img width="100%" src="',GraphicUrl,'"/>'].join(''));
		SetBorderWidth(10);
		Show();
		SetWidth('408px');
		setTimeout(function() { SetPosition(CENTER); },100);
	}
//	Drag.init(container.Header,container.Container);
	return(false);
}
function ShowLargeGraphic(GroupID) {
//	var GraphicUrl=$$('Graphic_'+GroupID).innerHTML;
	var ItemNode;
	ItemNode=$$('Item_'+GroupID);
	ItemNode.Container=new Element('div','Container');
	ItemNode.Body	=new Element('div','Body');
	ItemNode.Name	=new Element('div','Name',getChildElementById(ItemNode,'Name').innerHTML);
	ItemNode.Desc	=new Element('div','Desc',getChildElementById(ItemNode,'Desc').innerHTML);
	ItemNode.Details=new Element('table','Details');
	ItemNode.Details.Row=ItemNode.Details.appendChild(new Element('tr'));
	ItemNode.Ref	=new Element('td','Ref',getChildElementById(ItemNode,'ReferencesDetails').innerHTML);
	if (getChildElementById(ItemNode,'IconsDetails')!=null) {
		ItemNode.Icons	=new Element('td','Icons',getChildElementById(ItemNode,'IconsDetails').innerHTML);
	} 
	else {
		ItemNode.Icons	=new Element('td','Icons','');
	}
	ItemNode.Details.Row.appendChild(ItemNode.Icons);
	ItemNode.Details.Row.appendChild(ItemNode.Ref);
	if (getChildElementById(ItemNode,'LargeGraphic')!=null) {
		ItemNode.Graphic=new Element('img','Graphic');
		ItemNode.Graphic.src=getChildElementById(ItemNode,'LargeGraphic').innerHTML;
		ItemNode.Graphic.style.width='300px';
		ItemNode.Body.appendChild(ItemNode.Graphic);
	}
	ItemNode.Body.appendChild(ItemNode.Name);
	ItemNode.Body.appendChild(ItemNode.Desc);
	ItemNode.Body.appendChild(ItemNode.Details);
	ItemNode.Body.style.width='300px';
	ItemNode.Container.appendChild(ItemNode.Body);
//	alert(ItemNode.Ref.innerHTML);
//	alert([ItemNode.Name,ItemNode.Desc,ItemNode.Graphic,ItemNode.Text].join('\n'));
//	var GraphicName=$$('Name_'+GroupID).innerHTML.replace(/<br\/>/gi,' (').replace(/<br>/gi,' (')+')';
	var container=new FloatContainer();
	with (container) {
//		LoadGraphic(GraphicUrl);
		SetHeaderHTML('Aquatropic');
		SetBodyHTML(ItemNode.Container.innerHTML);
//		SetBorderWidth(10);
		Show();
		setTimeout(function() { SetPosition(CENTER); },100);
	}
//	Drag.init(container.Header,container.Container);
	return(false);

//    var NewPanel=document.createElement('div');
//    var NewPanelName='Item_'+GraphicText.getNumbersOnly();
//    with (NewPanel) {
//		style.position='absolute';
//		style.display='none';
//		style.width='400px';
//		id=NewPanelName;
//    }

    // Setup constants
    /*
	try {
		var Graphic = new Image();
		Graphic.src=GraphicUrl;
		var PanelContainer, LargeGraphicPanel, LargeGraphicPanelBody;
		try {
			var ExistingObj=$$('LargeGraphicPanel');
			ExistingObj.parentNode.removeChild(ExistingObj);
			ExistingObj=$$('LargeGraphicPanel_c');
			ExistingObj.parentNode.removeChild(ExistingObj);
			ExistingObj=null;
		} catch(e) { ; }
		PanelContainer=$$('PanelContainer');
		LargeGraphicPanel=document.createElement('div');
		PanelName='LargeGraphicPanel';
		LargeGraphicPanel.id=PanelName;
		LargeGraphicPanelBody=document.createElement('div');
		LargeGraphicPanelBody.className='bd';
		LargeGraphicPanel.appendChild(LargeGraphicPanelBody);
		PanelContainer.appendChild(LargeGraphicPanel);

		var IE_QUIRKS = (YAHOO.env.ua.ie && document.compatMode == "BackCompat");		// QUIRKS FLAG, FOR BOX MODEL
		var IE_SYNC = (YAHOO.env.ua.ie == 6 || (YAHOO.env.ua.ie == 7 && IE_QUIRKS));	// UNDERLAY/IFRAME SYNC REQUIRED
		var PANEL_BODY_PADDING = (10*2)													// PADDING USED FOR BODY ELEMENT (Hardcoded for example)
		// 10px top/bottom padding applied to Panel body element. The top/bottom border width is 0
		var panel = new YAHOO.widget.Panel(PanelName, {
			 visible: false
			,draggable: true
			,fixedcenter: true
			//,modal: true
			//,constrainintoviewport: true
			,width: '400px'
			,close: true
			,context: ["showbtn", "tl", "bl"]
			,underlay: 'shadow'
		});
		panel.beforeShowEvent.subscribe( function() { ; } );
		panel.beforeRenderEvent.subscribe(
			function() { 
				panel.setBody('<img src="'+GraphicUrl+'" width="400px"/>'); 
				panel.setHeader('<div id="hd">'+GraphicName+'</div>');
			}
		);
		LargeGraphicPanel.style.display='block';
		panel.render();
		panel.show();
	}
	catch(e) { alert(e); }
	*/
	return(false);
}
function CloseContainer(obj) {
	var node=GetParentByClass(obj,'largeImg');
	node.parentNode.removeChild(node);
}
function GetParentByClass(obj,ClassName) {
	var out;
	var parent=obj.parentNode;
	if (parent.className==ClassName) out=parent;
	else out=GetParentByClass(parent,ClassName);
	return(out);
}
function GetCenteredPosition(obj) {
	try {
		var height, width, winHeight, winWidth, scrHeight, scrWidth;

		height		=obj.offsetHeight;
		width		=obj.offsetWidth;
//		try { winHeight=document.body.clientHeight-1+1; } catch(e) { winHeight=window.innerHeight-1+1; }
//		try { winWidth=document.body.clientWidth-1+1; } catch(e) { winWidth=window.innerWidth-1+1; }
		try { winHeight=window.screen.availHeight-1+1; } catch(e) { winHeight=window.innerHeight-1+1; }
		try { winWidth=window.screen.availWidth-1+1; } catch(e) { winWidth=window.innerWidth-1+1; }
		try { srcHeight=document.body.scrollTop-1+1; } catch(e) { srcHeight=window.pageYOffset-1+1; }
		try { scrWidth=document.body.scrollLeft-1+1; } catch(e) { scrWidth=window.pageXOffset-1+1; }
		
//		alert(new Array(height, width, winHeight, winWidth, scrHeight, scrWidth).join('\n'));

		var position	=new Position(winWidth/2-width/2,winHeight/2-height/2-25);
//		alert(position.toString());
	} catch(e) { alert('asdf '+e); }
	return(position);
}
function open_popup(url,name,width,height) {
	window.open(url);
	//$$('showMapBtn').click();
}


//function LocationAssignment(obj) {

//	this.inheritFrom=ResponseHandler;
//	this.inheritFrom();
//	this.batch=new Batch(obj);
//	this.constLoc=0;
//	this.constBatch=1;
//	this.newCode;
//	
//	this.disableUI=function() { ; };

//	this.setDefaultParams=function() {
//		this.setParam(new Parameter('txtAction','update_location'));
//		this.setParam(new Parameter('txtBarcode','L'+this.batch.LocID));
//		this.setParam(new Parameter('txtBatch',this.batch.BatchID));
//		this.setParam(new Parameter('txtFromTrack',this.batch.TrackID));
//		this.setParam(new Parameter('txtFromLocation',this.batch.LocationID));
//	};
//	
//	this.initialize=function() {
//		this.newCode=scan_location();
//		if (this.newCode!=null) {			
//			this.batch.LocID=this.newCode.substring(1,this.newCode.length).toUpperCase();
//			this.setDefaultParams();
//			//alert(this.getParams());
//			//debugObject.Insert(this.param.join('; '));
//			this.run();
//		}
//		else {
//			this.cancelHandler();
//		}
//	};
//	
//	this.handler=function() { insert_debug_msg('Define LocationAssignment.handler() method.'); };
//	
//	this.cancelHandler=function() { ; };

//	this.errHandler=function() {
//		try {
//			server_error_detail_prompt(
//				'LocationAssignment\n'+
//				'There was a problem creating/looking up the barcode.\n'+
//				'Please re-scan a valid barcode or contact the system administrator.'
//				,this.xmlHttp.responseText
//			);
//			Barcode.focus();
//			Barcode.select();
//		}
//		catch(e) { insert_debug_msg('error @ ResponseHandler.errHandler()\n'+e); };
//	};
//}

