
		/* 
		  IframeWindow_Open:
			 url: the location of the content
			 windowName: the name of the outerdiv used to control visibility
			 windowOptions: a style string for windowName div
			 subWindowName: the name of the div that content is inserted
			 subWindowOptions: a style string for subWindowName div
			 titleBarName: the name of the div used to display title
			 titleText: the text that goes in the titleBarName div
			 backgroundProtect: if true turns on background greyness
    */
    function IframeWindow_Open(url, windowName, windowOptions, subWindowName, subWindowOptions, titleBarName, titleText, backgroundProtect){
      //should we close all open windows ... we can
			closeAllWindows();
			if (backgroundProtect == true) {
				document.getElementById("BlackFrost").style.height="3000px";
				showHideLayers('BlackFrost', '', 'show');
			}
     
			setTitle(titleBarName,titleText);  
 
     
      if(!testWindowCacheIdentifier(windowName,url)){
        var iframeHtml = "";
 iframeHtml = "<iframe id=\"iframe_id_0504\" src=\""+url+"\" style=\""+subWindowOptions+"\" frameborder=\"0\"></iframe>";
        document.getElementById(subWindowName).innerHTML=iframeHtml;
	  document.getElementById("iframe_id_0504").src=url;
        saveWindowCacheIdentifier(windowName, url);

      }
      
      showDiv(windowName);
      applyStyle(windowName, windowOptions);
      
      return false;
    }
    
    /* 
			AjaxWindow_Open:
			 url: the location of the content
			 windowName: the name of the outerdiv used to control visibility
			 windowOptions: a style string for windowName div
			 subWindowName: the name of the div that content is inserted
			 titleBarName: the name of the div used to display title
			 titleText: the text that goes in the titleBarName div
			 backgroundProtect: if true turns on background greyness
    */
    function AjaxWindow_Open(url, windowName, windowOptions, subWindowName, titleBarName, titleText, backgroundProtect){
			//should we close all open windows ... we can
			closeAllWindows();
			if(backgroundProtect==true) showHideLayers('BlackFrost','','show');
			setTitle(titleBarName,titleText);
			 
			if(!testWindowCacheIdentifier(windowName,url)){
				ajaxWindowRequestObject = createRequestObject();
				ajaxWindowRequestObject.open('get', url); 
				ajaxWindowRequestObject.onreadystatechange = handleResponse; //how to handle
				//ajaxWindowRequestObject["subWindowName"] = subWindowName;
				ajaxSubWindowName = subWindowName;
				ajaxWindowRequestObject.send(null); 
				saveWindowCacheIdentifier(windowName, url);
			}
					
			showDiv(windowName);
			applyStyle(windowName, windowOptions);

			return false;
    }
    
     /* 
			InPageWindow_Open:
			 contentName: the name of the div that contains the content
			 windowName: the name of the outerdiv used to control visibility
			 windowOptions: a style string for windowName div
			 subWindowName: the name of the div that content is inserted
			 titleBarName: the name of the div used to display title
			 titleText: the text that goes in the titleBarName div
			 backgroundProtect: if true turns on background greyness
    */
    function InPageWindow_Open(contentName, windowName, windowOptions, subWindowName, titleBarName, titleText, backgroundProtect){
			//should we close all open windows ... we can
			closeAllWindows();
			if(backgroundProtect==true){
				document.getElementById("BlackFrost").style.height = "3000px";
				showHideLayers('BlackFrost','','show');
			}
			
			setTitle(titleBarName,titleText);
			 
			if(!testWindowCacheIdentifier(windowName,contentName)){
				document.getElementById(subWindowName).innerHTML=document.getElementById(contentName).innerHTML;
				saveWindowCacheIdentifier(windowName, contentName);
			}
					
			showDiv(windowName);
			applyStyle(windowName, windowOptions);

			return false;
    }
    
    
    
    //hides the div specified by divName
    function OverlayWindow_Close(windowName){
    
      hideDiv(windowName);
      return false;
    }


//// AJAX HELPER CODE
		var ajaxWindowRequestObject;
		var ajaxSubWindowName;
		
    function createRequestObject() { 
			 var req; 
			 if(window.XMLHttpRequest){ 
					req = new XMLHttpRequest(); 					// Firefox, Safari, Opera... 
			 } else if(window.ActiveXObject) { 
					req = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer 5+ 
			 } else { 
					alert('Problem creating the XMLHttpRequest object'); //SORRY NO LUCK
			 } 
			 return req; 
		} 
				
		function handleResponse() { 
			 if(ajaxWindowRequestObject.readyState == 4 && ajaxWindowRequestObject.status == 200){ 

					var response = ajaxWindowRequestObject.responseText; 
					if(response) { 
						//document.getElementById(ajaxWindowRequestObject["subWindowName"]).innerHTML = response; 
						document.getElementById(ajaxSubWindowName).innerHTML = response;
					} 
				http_done = true;
			 }   
		} 
//// END AJAX HELPER COXE


//// CODE TO KEEP TRACK OF CONTENT
    //windowCacheIdentifier is used to see if the last window loaded for  
    //window name is the same as the current request
		var windowCacheIdentifier = new Array;
		var windowNames = new Array;

    function saveWindowCacheIdentifier(windowName, url){
    		
			windowCacheIdentifier[windowName]=url;
			if(containsValue(windowNames,windowName)==false)
				windowNames[windowNames.length]=windowName;
			
			return false;
    }
    
    function testWindowCacheIdentifier(windowName, url){
    		
			return (windowCacheIdentifier[windowName]==url);
    }

//// END CODE TO KEEP TRACK OF CONTENT        

//// CODE TO HIDE AND DISPLAY AND APPLY STYLES FOR DIVS
    
    function hideDiv(divName){
    
      eval("document.getElementById(\""+divName+"\").style.position=\"absolute\";");
      eval("document.getElementById(\""+divName+"\").style.display=\"none\";");
      eval("document.getElementById(\""+divName+"\").style.visibility=\"hidden\";");          
    }
    
    function showDiv(divName){
      eval("document.getElementById(\""+divName+"\").style.position=\"absolute\";");
      eval("document.getElementById(\""+divName+"\").style.display=\"block\";");
      eval("document.getElementById(\""+divName+"\").style.visibility=\"visible\";");    
    }
    
    function closeAllWindows(){
		
	
	for(x=0;x<windowNames.length;x++){
	
        OverlayWindow_Close(windowNames[x]);
       }
       return false;
    }
    
    function applyStyle(divName, options){
      
      options=options.toLowerCase();
      
      var styles = new Array;
      styles = options.split(";");
      for(x=0;x<styles.length;x++){
        if(styles[x]!=""){
          var style = new Array;
          style = styles[x].split(":");
          if(style[1]!="" && style.length==2){
							if(style[0]=="top"||style[0]=="left"){
								style[1] = adjustForScrollOffset(style[0], style[1]);
							}
						
              eval("if(document.getElementById(\""+divName+"\").style."+style[0]+"!=null) " + 
								"document.getElementById(\""+divName+"\").style."+style[0]+"=\""+style[1]+"\";");
          }
        }
      }//end for
    }
    
    //show and hide layers .. from TOM's CODE
    function showHideLayers() { //v9.0
			var i,p,v,obj,args=showHideLayers.arguments;
			for (i=0; i<(args.length-2); i+=3) 
			with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
				if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
				obj.visibility=v; }
		}    
		
		function setTitle(titleBarName, titleText){
			if(titleBarName!=null && titleBarName!=""){
				if(document.getElementById(titleBarName)!=null)
					document.getElementById(titleBarName).innerHTML=titleText;
			}
		}
//// END CODE TO HIDE AND DISPLAY AND APPLY STYLES FOR DIVS
    
//// UTILITY FUNCTIONS
    
		function containsValue(arr, str){

			var testString = arr.join("|");
			testString = "|" + testString + "|";
			str = "|" + str + "|";
			return (testString.indexOf(str)>=0);
			
		}
		
		function adjustForScrollOffset(name, value){
			//String(Number(window.screenTop)+Number(style[1].toString().replace("px","")))+"px";
			var numericValue = Number(value.toString().replace("px",""));
			var scrollOffset = 0;
			var documentRoot;
			if (document.documentElement && document.documentElement.scrollTop){
				documentRoot = document.documentElement;
			}
			else if (document.body){
				documentRoot = document.body;
			}
			if (name=="top"){
				scrollOffset = Number(documentRoot.scrollTop);
			}
			else if(name=="left"){
				scrollOffset = Number(documentRoot.scrollLeft);
			}
			
			return String(numericValue+scrollOffset)+"px";
			//
		}
//// END UTILITY FUNCTIONS
    
    
    
/// -------------------------------------------------------------------------- ///
/// -------------------------------------------------------------------------- ///
/// -------------------   PAGE DISPLAY & SIMPLIFICATION  FUNCTIONS    -------- ///
/// -------------------------------------------------------------------------- ///
/// -------------------------------------------------------------------------- ///

function Window_Close()
{
	closeAllWindows();
	//OverlayWindow_Close('overlay_container_window'); //USE THIS IF closeAllWindows() really is broken
	
	showHideLayers('BlackFrost','','hide');
	document.getElementById("BlackFrost").style.height="";
	
	if (window.dropDownVisibility&&(typeof window.dropDownVisibility=="function")) 
		dropDownVisibility('show');
}


function writeOverlayContainer()
{
	var container = '<div id=\"BlackFrost\" style=\"cursor: not-allowed;\"></div>' +
		'<div class=\"overlayLogin\" id=\"overlay_container_window" style=\"display: none; visibility: hidden;\">' +
		'<div><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">' +
		'<tr><td>' +
		'<table class=\"moduleHeaderLogin\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">' + 
		'<tr><td width=\"99%\" style=\"cursor: move;\" id=\"draggerLogin\">' +
		'<div id=\"overlay_title\" style=\"font-weight:bold;font-size:15px;\"></div></td>' +
    '<td valign=\"middle\" align=\"right\">' +
    '<a id=\"owCloseBtn\" onclick=\"javascript:Window_Close()\" href=\"javascript:void(0)\">' +
    '<img src=\"/images/X.gif\" border=\"0\" alt=\"close\"/></a>&nbsp;</td>' +
    '<td>&nbsp;</td></tr></table>' +
    '</td></tr><tr><td>' +
    '<div id=\"overlay_content_window\"></div>' +
    '</td></tr></table></div></div>';
	
	window.document.write(container);
	Drag.init(document.getElementById("draggerLogin"), document.getElementById("overlay_container_window"));
}

function Window_OpenV2(URL, Params, Title, Type, ShowClose)
{
	var validTypes = "iframe|inpage|ajax";
		
		Type = Type.toLowerCase();
		
		if(validTypes.indexOf(Type) < 0)
		{
			alert('Valid Window_Open type not specified');
			return;
		}
		
		if(ShowClose == "N") {
			var o = document.getElementById('owCloseBtn');
			if (o != null)
				o.style.display = "none";
		}
		else {
			var o = document.getElementById('owCloseBtn');
			if (o != null)
				o.style.display = "inline";
		}
		
		// run dropDownVisibility if it exists
		if (window.dropDownVisibility && (typeof window.dropDownVisibility=="function")) 
			dropDownVisibility('hide');
		
		var width = '550px';
		var height = '550px';
		var top = '10px';
		var left = '200px';
		var border = 'solid black 1px';
		
		// parse params to build the following styles- 
		// valid params:  top=number&left=number&height=number&width=number&border=type color size
		if (Params != null && Params.length > 0) {
			var parts = Params.split('&');
	    
			for (i=0; i<parts.length; i++) {
	            var item = parts[i].split(':');
				
				if (item.length == 2) {
					var name = item[0].replace(/^\s+|\s+$/g,"").toLowerCase();
					var value = item[1].replace(/^\s+|\s+$/g,"");
					
					switch (name) {
						case 'width':
							width = fixValue(value);
							break;
						case 'height':
							height = fixValue(value);
							break;
						case 'top':
							top = fixValue(value);
							break;
						case 'left':
							left = fixValue(value);
							break;
						case 'border':
							//DONT EVER FIX THIS VALUE
							border = value;
							break;
					}
				}
			}
		}
	
		// assemble the two style strings
		var container_window_style = 'width:'+width+';top:'+top+';left:'+left+';border:'+border+';';	
		var content_window_style = 'width:'+width+';height:'+height+';';	
		
		switch (Type)
		{
			case 'iframe' :
				IframeWindow_Open(URL, 'overlay_container_window', container_window_style, 'overlay_content_window', content_window_style, 'overlay_title', Title, true);     
				break;
			case 'inpage' :
				InPageWindow_Open(URL, 'overlay_container_window', container_window_style, 'overlay_content_window', 'overlay_title', Title, true)
				break;
			case 'ajax' :
				AjaxWindow_Open(URL, 'overlay_container_window', container_window_style, 'overlay_content_window', 'overlay_title', Title, true)
				break;
	}	
}


function Window_Open(URL, Params, Title, Type)
{
	var validTypes = "iframe|inpage|ajax";
	
	Type = Type.toLowerCase();
	
	if(validTypes.indexOf(Type) < 0)
	{
		alert('Valid Window_Open type not specified');
		return;
	}
	
	
	// run dropDownVisibility if it exists
	if (window.dropDownVisibility && (typeof window.dropDownVisibility=="function")) 
		dropDownVisibility('hide');
	
	var width = '550px';
	var height = '550px';
	var top = '10px';
	var left = '200px';
	var border = 'solid black 1px';
	
	// parse params to build the following styles- 
	// valid params:  top=number&left=number&height=number&width=number&border=type color size
	if (Params != null && Params.length > 0) {
		var parts = Params.split('&');
    
		for (i=0; i<parts.length; i++) {
            var item = parts[i].split(':');
			
			if (item.length == 2) {
				var name = item[0].replace(/^\s+|\s+$/g,"").toLowerCase();
				var value = item[1].replace(/^\s+|\s+$/g,"");
				
				switch (name) {
					case 'width':
						width = fixValue(value);
						break;
					case 'height':
						height = fixValue(value);
						break;
					case 'top':
						top = fixValue(value);
						break;
					case 'left':
						left = fixValue(value);
						break;
					case 'border':
						//DONT EVER FIX THIS VALUE
						border = value;
						break;
				}
			}
		}
	}

	// assemble the two style strings
	var container_window_style = 'width:'+width+';top:'+top+';left:'+left+';border:'+border+';';	
	var content_window_style = 'width:'+width+';height:'+height+';';	
	
	switch (Type)
	{
		case 'iframe' :
			IframeWindow_Open(URL, 'overlay_container_window', container_window_style, 'overlay_content_window', content_window_style, 'overlay_title', Title, true);     
			break;
		case 'inpage' :
			InPageWindow_Open(URL, 'overlay_container_window', container_window_style, 'overlay_content_window', 'overlay_title', Title, true)
			break;
		case 'ajax' :
			AjaxWindow_Open(URL, 'overlay_container_window', container_window_style, 'overlay_content_window', 'overlay_title', Title, true)
			break;
	}	
}

function fixValue(size)
{
	size = size.toLowerCase();
	size = size.replace(/[^0-9]+/g,''); //get rid of non-numeric charachters
	size = size + 'px'; //add the px at the end
	return size;	
}	

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};


writeOverlayContainer();
