var isMozilla;
var objDiv_w = null;
var originalDivHTML_w = "";
var DivID_w = "";
var over1_w = false;
var build = false;
window.onresize = function(){
					if(build){
						var dim = $('jotform').getDimensions();
						var W = (isMozilla)? dim.width-80 : dim.width;
						var H = dim.height+51;
													
						$('dimmer').setStyle({width: W+'px',height: H+'px'});
					}
				  }
function getDocSize(){ // No need, For Now!!!
	var arr = new Array();
	if (parseInt(navigator.appVersion)>3) {
 		if (navigator.appName=="Netscape") {
			arr['W'] = window.innerWidth;
			arr['H'] = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			arr['W'] = document.body.offsetWidth+500;
			arr['H'] = document.body.offsetHeight;
		}
	 }
	 return arr;
}
function buildDimmerDiv(){
	try{
		window.onkeypress = function(e){
			e = (e) ? e : window.event;
			if(e.keyCode == 27)
				hiddenFloatingDiv("windowcontent");
				
		}
		var dim = $('jotform').getDimensions();
		var W = (isMozilla)? dim.width-80 : dim.width;
		var H = dim.height+200;
		//***
		
		var dimmer = document.createElement('div');
		dimmer.style.display = "none";
		dimmer.style.width = W+'px';
		dimmer.style.height = H+'px';
		dimmer.style.zIndex = "10000000";
		dimmer.id = "dimmer";
		dimmer.className = "dimmer";
		$('jotform').appendChild(dimmer);
		
		//***
		var windowcontent = document.createElement('div');
		windowcontent.style.display = "none";
		windowcontent.style.zIndex = "100000000";
		windowcontent.id = "windowcontent";
		$('jotform').appendChild(windowcontent);
		
		build = true;
	}catch(e){
		traceError("Error On buildDimmerDiv",e);
	}
}
function swapImage(elem){
	elem.src = "images/wiz_title_close1.png";
	pngImages(elem.id);
	elem.onmouseout = function(){
							elem.src = "images/wiz_title_close0.png";
							pngImages(elem.id);
						}
}
function displayFloatingDiv(divId, title, width, height, left, top, id) 
{
	DivID_w = divId;
	theDiv = $(divId);
	var addHeader;
	if (!isMozilla){
		var re = RegExp(/^field_/i);
		var thesel = $A( document.getElementsByTagName("select") );
		thesel.each(function(Element){
			if(Element.id.match(re)){
				Element.style.display="none";
			}
		  } );
	}
	//document.getElementById('dimmer').style.display = "block";
	
    theDiv.style.width = width + 'px';
    theDiv.style.left = "20%";
    theDiv.style.top = "25%";

	originalDivHTML_w = theDiv.innerHTML;
	addHeader = '<table style="width:'+ width +'px;" border="0" align="center" cellpadding="0" cellspacing="0">\
      					<tr>\
      						<td width="22" id="wizul" height="10" background="images/wiz_up_left.png"></td>\
        					<td id="wizu" background="images/wiz_up.png"><img src="images/space.gif" width="1" height="1" /></td>\
        				    <td width="22" id="wizur" background="images/wiz_up_right.png"></td>\
      					</tr>\
   				  </table>\
		          <table id="addhead" style="width:'+ width +'px; height:18px" border="0" align="center" cellpadding="0" cellspacing="0">\
					<tr>\
					<td width="11" height="20" id="wiztl" background="images/wiz_title_left.png"></td>\
					<td width="4" id="wizt2l" background="images/wiz_title2_left.png"></td>\
					<td ondblclick="void(0);" onmouseover="over1_w=true;" onmouseout="over1_w=false;" style="cursor:move;height:18px;color:#ffffff" background="images/win_title.gif" class="title_text">' + title + '</td>\
					<td width="38">\
					<img src="images/wiz_title_close0.png"  name="Image2" width="38" height="20" border="0" id="closee"\
					onclick="javascript:hiddenFloatingDiv(\'' + divId + '\');void(0);"\ onmouseover=\"swapImage(this)\"/></td>\
					</tr>\
					</table>';			
	
    // add to your div an header	
	theDiv.innerHTML = addHeader + originalDivHTML_w;
	theDiv.style.height = height + 'px';
	theDiv.className = 'dimming';
	new Effect.Parallel(
		[
			new Effect.Appear('windowcontent'),
			new Effect.Appear('dimmer')
		],{
			duration: 0.3
		});
}

function hiddenFloatingDiv(divId) 
{
	build = false;
	window.onkeypress = null;
	//document.getElementById(divId).style.display = "none";
	if (!isMozilla){
	$A( document.getElementsByTagName("select") ).each(function(Element){
			Element.style.display="inline";
	});
	}
	DivID_w = "";
	new Effect.Parallel(
		[
		 	new Effect.Fade(divId),
			new Effect.Fade('dimmer')
		],{
			duration: 0.3
		});
	$("jotform").removeChild($("windowcontent"))
	$("jotform").removeChild($("dimmer"))
//	document.getElementById(divId).innerHTML = "";
  	document.getElementById('wizcss').href = "css/blank.css";
}

function MouseDown_w(e) 
{
    if (over1_w)
    {
        if (isMozilla) {
            objDiv_w = $(DivID_w);
            X = e.layerX;
            Y = e.layerY;
            return false;
        }
        else {
            objDiv_w = $(DivID_w);
            objDiv_w = objDiv_w.style;
            X = event.offsetX;
            Y = event.offsetY;
        }
    }
}

function MouseMove_w(e) 
{
    if (objDiv_w) {
        if (isMozilla) {
            objDiv_w.style.top = (e.pageY-Y) + 'px';
            objDiv_w.style.left = (e.pageX-X) + 'px';
            return false;
        }
        else 
        {
            objDiv_w.pixelLeft = event.clientX-X + document.body.scrollLeft;
            objDiv_w.pixelTop = event.clientY-Y + document.body.scrollTop;
            return false;
        }
    }
}

function MouseUp_w() 
{
    objDiv_w = null;
}

function init_w()
{
	// check browser
    isMozilla = (/MSIE/.test(navigator.userAgent)) ? 0 : 1;
    document.onmousedown = MouseDown_w;
    document.onmousemove = MouseMove_w;
    document.onmouseup = MouseUp_w;
    // add the div
    // used to dim the page
	//buildDimmerDiv();
}

// call init
init_w();