isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;
//For dragging the Object
function ddInit(e,lyrMain,layerSub,iframeid)
{
	try
	{	   
		topDog=isIE ? "BODY" : "HTML";
		whichDog=document.getElementById(lyrMain);
		whichFrame=document.getElementById(iframeid);
		hotDog=isIE ? event.srcElement : e.target;
				
		if(typeof hotDog.id == "undefined") return; 
		
		while (hotDog.id!=layerSub&&hotDog.tagName!=topDog)
		{
			hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
		}  
		if (hotDog.id==layerSub)
		{
			offsetx=isIE ? event.clientX : e.clientX;
			offsety=isIE ? event.clientY : e.clientY;
			nowX=parseInt(whichDog.style.left);
			nowY=parseInt(whichDog.style.top);
			
			ddEnabled=true;
			document.onmousemove=dd;
		}
	}
	
	catch(e)
	{
		alert(e.description);
	}
}
//Positioning the Object dragged.
function dd(e)
{
	try
	{
		if (!ddEnabled) return;
		var newLeft=isIE ? nowX+event.clientX - offsetx : (nowX + e.clientX - offsetx) + "px";
		var newTop=isIE ? nowY+event.clientY - offsety : (nowY + e.clientY - offsety) + "px";
		whichDog.style.left=newLeft; 
		whichDog.style.top=newTop;
		whichFrame.style.left=newLeft;
		whichFrame.style.top=newTop;
		return false;  
	}
	catch(e)
	{
		alert(e.description);
	}
}

function cancel(objId,iframeid)
{
	var lay=document.getElementById(objId);
	var iframeObj = document.getElementById(iframeid);
	
	lay.style.visibility = 'hidden';
	iframeObj.style.visibility = 'hidden';
}
//Function to display the layer on click of the button,
//Need to pass the layerId as a parameter to the function
//iframeWidthAdjustment parameter is optional
// * (IE & Firefox don't size IFRAMEs true to to their set styles when RAD controls are in the pop-ups:
//   iframeWidthAdjustment is hack to comensate for this).
//var showcalled=0;
function show(layerId,iframeid,iframeWidthAdjustment)
{

	try
	{
	    var hidLayId = document.getElementById("hidLayID");
		if (hidLayId != null && typeof(hidLayId.value) == "string")
		{
			if (hidLayId.value != "")
			{
			    var hidLay = document.getElementById(hidLayId.value);
			    if (hidLay != null)
			    {
				    hidLay.style.visibility = "hidden";
				}
			}
			document.getElementById("hidLayID").value = layerId;
		}

        if (iframeWidthAdjustment == null || typeof(iframeWidthAdjustment) != "number")
        {
            iframeWidthAdjustment = 0;
        }
		
		//var iframeid = "iframe1";
		var iframeStyleObj = document.getElementById(iframeid).style;
		var temp = new Array();
		temp = getSize();//Get the size of the browser window
		var layerObj = document.getElementById(layerId);
		var layerStyleObj = document.getElementById(layerId).style;
		var layerW = layerObj.offsetWidth;
		var layerH = layerObj.offsetHeight;
		//alert("Layer Height & width" +layerObj.offsetHeight + "......" + layerObj.offsetWidth);
		var AdjustedWidth = parseInt(layerW) + iframeWidthAdjustment;
		if(AdjustedWidth < 0) AdjustedWidth = 0; // If negative, it breaks in IE
		iframeStyleObj.width =  AdjustedWidth + "px";
		iframeStyleObj.height = parseInt(layerH) + "px";
		//alert("Layer Height & width" +iframeStyleObj.height + "......" + iframeStyleObj.width);
		var scrollXY = new Array();
		scrollXY = getScrollXY();
		var _pTop = parseInt((temp[1]/2)- (parseInt(layerH)/2) + parseInt(scrollXY[1]));
		// This will make sure top position starts from 0px if it has Negative value.
		if (_pTop < 0)
		{
		    layerStyleObj.top = "0px";
		    iframeStyleObj.top = "0px";
		}
		else
		{
		    layerStyleObj.top = _pTop + "px";
		    iframeStyleObj.top = _pTop + "px";
		}
		layerStyleObj.left = parseInt((temp[0]/2)- (parseInt(layerW)/2) + parseInt(scrollXY[0])) + "px";
		iframeStyleObj.left = parseInt((temp[0]/2)- (parseInt(layerW)/2) + parseInt(scrollXY[0])) + "px";
		
		
		
		if(document.getElementById('popUpCoOrdinatesLeft') != null)
		{
		   document.getElementById('popUpCoOrdinatesLeft').value =  layerStyleObj.left ;
		}
		if(document.getElementById('popUpCoOrdinatesTop') != null)
		{
		   document.getElementById('popUpCoOrdinatesTop').value =  layerStyleObj.top ;
		}
				/*layerStyleObj.display = 'inline';
		iframeStyleObj.display = 'inline';
		if(showcalled<2)
		{
		showcalled++;
		show(layerId,iframeid,iframeWidthAdjustment);
		}
		else
		{
		showcalled=1;
		}
		//iframeStyleObj.zIndex = layerStyleObj.zIndex-1;*/
		layerStyleObj.visibility = 'inherit';
		iframeStyleObj.visibility = 'inherit';
		iframeStyleObj.zIndex = layerStyleObj.zIndex;
		return true;
	}
	catch(e)
	{
		alert(e.description);
	}
}
//Function to obtain the Height & Width of the Browser window.
function getSize() 
{
	try
	{
		var myWidth = 0, myHeight = 0;
		if(typeof(window.innerWidth) == 'number') 
		{
		//MoZilla & Safari
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		}
		else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
		{
		//IE 6+ in 
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		}
		else if(document.body && (document.body.clientWidth || document.body.clientHeight)) 
		{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		}
		//Returns Height & Width
		return [myWidth, myHeight];
	}
	catch(e)
	{
		alert(e.description);
	}
}
// determine height for <div> element
function getHeight(divObj)
{
	try
	{
		var divHeight = 0;
		if(divObj.offsetHeight) 
		{
			divHeight = divObj.offsetHeight;
		}
		else if(divObj.style.pixelHeight)
		{
			divHeight = divObj.style.pixelHeight; 
		}
		return divHeight;
	}
	catch(e)
	{
		alert(e.description);
	}
}

//To get the Scroll Height & Width
function getScrollXY() 
{
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) 
  {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } 
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } 
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  
    var ObjPrevScrollPosX = document.getElementById("__SCROLLPOSITIONX");
    var ObjPrevScrollPosY = document.getElementById("__SCROLLPOSITIONY");
    var PrevoffSetX=0;
    var PrevoffSetY=0;
    
    if (ObjPrevScrollPosX != null && typeof(ObjPrevScrollPosX.value) == "string")
        PrevoffSetX = ObjPrevScrollPosX.value;
    if (ObjPrevScrollPosY != null && typeof(ObjPrevScrollPosY.value) == "string")
        PrevoffSetY = ObjPrevScrollPosY.value;
  
  return [ scrOfX+parseInt(PrevoffSetX), scrOfY+parseInt(PrevoffSetY) ];
}

function cancel1(objId,objId1,objId2,objId3)
{
	var lay=document.getElementById(objId);
	var lay1=document.getElementById(objId1);
	var lay2=document.getElementById(objId2);
		var lay3=document.getElementById(objId3);
	lay.style.visibility='hidden';
	lay2.style.visibility='hidden';
	lay1.style.visibility='hidden';
		lay3.style.visibility='hidden';
}

//document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");