// Defining browser type.
IExplorer = (document.all)            ? true : false;
Mozilla   = (document.getElementById) ? true : false;
Netscape4 = (document.layers)         ? true : false;
/*********************************************************************/

function writetoLyr(id, sImageSRC)
{
	var HTML = '';
	var sImageTag = '<' + 'img src="' + sImageSRC + '" alt="" border="0"' + '/' + '>';
	HTML += '<table width="120" border="0" cellspacing="0" cellpadding="0">'; 
	//HTML += "<tr onmousedown=\"if (document.getElementById && !document.all) {start(\\'"+id+"\\');}\" onMouseOver=\"if (!IExplorer){dragObj=\\'"+id+"\\'}else{dragObj="+id+"}; drag=1;\" onMouseOut=\"drag=0;\">";
	HTML += "<tr>";
	HTML += '<td class="MainTDHeader" colspan="3" align="right" height="19">';
	HTML += '<'+'a href="javascript:HidePictureLayer(\''+id+'\')"'+'>';
	HTML +=  '<'+'img src="/images/x.gif" alt="" width="17" height="11" border="0"'+'/><'+'/a>';
	HTML += '</td>';
	HTML += '</tr>';
	HTML += '<tr>';
	HTML += '<' + 'td class="MainTDHeader" width="3"'+'><'+'img src="/images/dot_trns.gif" alt="" width="3" height="45" border="0"'+'/></'+'td><td'+' style="background:#EEEEEE;"'+'>'+sImageTag+'</'+'td><td class="MainTDHeader" width="2"'+'><'+'img src="/images/dot_trns.gif" alt="" width="2" height="1" border="0"'+'/></'+'td>';
	HTML += '</tr>';
	HTML += '<tr>';
	HTML += "<td colspan=\"3\" class=\"MainTDHeader\">";
	HTML += '<' + 'img src="/images/dot_trns.gif" alt="" width="1" height="3" border="0"' + '/>';
	HTML += '</td>';
	HTML += '</tr>';
	HTML += '</table>';

	document.getElementById(id).innerHTML = HTML;

	ShowPictureLayer(id);
}

/*********************************************************************/

function ShowPictureLayer(id)
{
	try {
	var objPictureDIV = document.getElementById(id);
	objPictureDIV.style.visibility = 'visible';
	objPictureDIV.style.left = '150px';


	if (document.documentElement && document.documentElement.scrollTop) {
		objPictureDIV.style.top = (document.documentElement.scrollTop + 10) + 'px';
	}
	else {
		//document.all[id].style.height = (Height * document.body.clientHeight)/100 + 'px';document.all[id].style.top = document.body.scrollTop + (Top * document.body.clientHeight)/100 + 'px';
		objPictureDIV.style.top = document.body.scrollTop + (document.body.clientHeight)/100 + 'px';
	}

	PictureTopLocation = (parseInt(objPictureDIV.style.top) - 5);
	//scrollTo(0,PictureTopLocation);
	}
	catch(e) {
		alert(e);
	}
}
/*********************************************************************/
function HidePictureLayer(id)
{
	try {
		document.getElementById(id).style.visibility = 'hidden';
	}
	catch(e){}
}
/*********************************************************************/

// Drag Layers part
/********************  IE CODE ********************************/
if (IExplorer){
		drag = 0
		move = 0
		
		function init() {
			window.document.onmousemove = mouseMove
			window.document.onmousedown = mouseDown
			window.document.onmouseup = mouseUp
			window.document.ondragstart = mouseStop
		}
		
		function mouseDown() {
			if (drag) {
				clickleft = window.event.x - parseInt(dragObj.style.left)
				clicktop = window.event.y - parseInt(dragObj.style.top)
				dragObj.style.zIndex += 1
				move = 1
			}
		}
		
		function mouseStop() {
			window.event.returnValue = false
		}
		
		function mouseMove() {
			/*if (move) {
				dragObj.style.left = window.event.x - clickleft
				dragObj.style.top = window.event.y - clicktop
			}*/
			if (move) {
				//window.status = " X:"+dragObj.style.left+"   Y:"+dragObj.style.top;
				if (window.event.x > 20){
					dragObj.style.left = window.event.x - clickleft
				
				}
				else{
					dragObj.style.left = 5;
				}
				if (window.event.y > 2){
					dragObj.style.top = window.event.y - clicktop
				}
				else{
					dragObj.style.top = 7;
					move = 0;
				}
			}
		}
		
		function mouseUp() {
			move = 0
		}
		init();
	
/***************  /IE CODE   *****************************/		
}

// Mozilla / Browser with DOM supoort
if (document.getElementById && !document.all){
		var active = 0;
		
		function start(LayerName)
		{
			dragWind = document.getElementById(LayerName);
			y = coordsY-parseInt(dragWind.style.top);
			x = coordsX-parseInt(dragWind.style.left);
			active=1;
			//return dragWind;
		}
		function drag(e)
		{
			//if (!document.getElementById(dragWind)){
			//	if (document.getElementById("PictureLayer")){
					//dragWind = document.getElementById("PictureLayer");
			//	}
			//}
			

			coordsY = e.clientY;
			coordsX = e.clientX;
			if(active){
				dragWind.style.top = coordsY-y;
				dragWind.style.left = coordsX-x;
			}
			if (coordsX <125){
				active = 0;
				dragWind.style.left = 99;
				return false;
			}
			if (coordsY <1){
				active = 0;
				dragWind.style.top = 95;
				return false;
			}
		}

		document.onmousemove = drag;
		document.onmouseup = new Function("active=0");
		document.onselectstart = new Function("return false");
}

