
// <script> 

var Offset = 20

function findPosX(obj)
{
	var curleft = 0 ; //( 0 - obj.style.width );
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft + Offset ;
}

function findPosY(obj)
{
	var curtop =  0; //( 0 - obj.style.height );
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop + Offset;
}


function getObj(name)
{
 if (document.getElementById)
 {
	   return  document.getElementById(name);
	 
 }
 else if (document.all)
 {
	   return document.all[name];
	  
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	return  document.layers[name];
	   
	   }
 }
}

function deleteObject( ElementID ) {
			getObj( ElementID ).parentNode.removeChild(el);
}

function hideObject( ElementID ) {
	
		var o =  getObj( ElementID );
		if ( o != null ) {
			o.style.visibility 	= 'hidden';
			//o.style.position	= 'absolute';
		}	
			
}

function hideObject_( Object ) {
// SAME AS 	hideObject() but pass OBJECT instead of ID NAME
		
		if ( Object != null ) {
			Object.style.visibility 	= 'hidden';
		}	
			
}

function showObject( ElementID ) {
	
		var o =  getObj( ElementID );
		if ( o != null ) {
			o.style.visibility 	= 'visible';
			//o.style.position	= 'relative';
		}	
			
}

function showObject_( Object ) {
// SAME AS 	showObject() but pass OBJECT instead of ID NAME	
		if ( Object != null ) {
			Object.style.visibility 	= 'visible';
		}	
			
}

function WindowLocation( LocationURL, WindowName ) {
			getObj( WindowName ).src = LocationURL;
}

function ShowMessage( text ) {

	alert( text ) ;

}

function CreateElement(ParentElement, TagName, Attribs ) {


    var element 		= document.createElement( TagName );
	var Attributes		= Attribs.split(',');
	
	//set attributes
	
	if ( ParentElement != null ) {
	
		ParentElement.appendChild(element);
	
	}
	
	for (var x = 0; x <= Attributes.length - 1; x++) {
		
		var Attribute 		=   Attributes[x].split('=');
		element.setAttribute(Attribute[0], Attribute[1]);
		
	}
	

    return element;
	

}

function CopyStyle( Source , Target ) {


	Target.style.height		= Source.offsetHeight;
	Target.style.width		= Source.offsetWidth;
	Target.style.visibility	= Source.style.visibility;
	
	Target.style.position	= 'absolute';
	Target.style.top 		= Source.offsetTop;
	Target.style.left 		= Source.offsetLeft;


}

function CopyStyle_( Source_ , Target_ ) {
	
	var Source = getObj( Source_ );
	var Target = getObj( Target_ );

	Target.style.height		= Source.offsetHeight;
	Target.style.width		= Source.offsetWidth;
		
	Target.style.position	= 'absolute';
	Target.style.top 		= Source.offsetTop;
	Target.style.left 		= Source.offsetLeft;
	



}

function DivToTextarea( DivID ) {


	var div = getObj( DivID );
	var container = div.parentNode 
	
	//hide object
	hideObject_( div );
	//create object
	var editor = CreateElement( container, 'textarea', 'id=t12,value=hello world' );
	//get dimensions of source div
	CopyStyle( div, editor );
	//set the inner text
	editor.innerHTML 			= div.innerHTML.replace(/<br \/>/gi, '\n');
	editor.style.border 		= 'solid 0px #000000';
	//editor.style.font			= 'Arial';
	editor.style.fontSize		= '10px';
	editor.style.overflow   	= 'hidden';
	editor.style.wordSpacing	= '-2px';
	editor.style.letterSpacing	= '-1px';
	editor.style.margin			= '0px';
	//hook key press
	editor.onkeypress 			= function foo(){ div.innerHTML = editor.innerHTML.replace(/\n/gi, '<br />'); editor.style.height = div.offsetHeight;}
	editor.onblur 				= function foo(){ div.innerHTML = editor.innerHTML.replace(/\n/gi, '<br />'); editor.style.height = div.offsetHeight;}
	editor.onchange 			= function foo(){ div.innerHTML = editor.innerHTML.replace(/\n/gi, '<br />'); editor.style.height = div.offsetHeight;}
	//get dimensions of source div
	
	
	showObject_(editor);
	

}