
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];
	   
	   }
 }
}


//change opacity
function changeOpac(opacity, HTMLElement) { 
    var object = HTMLElement;
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 


function hideObject( ElementID ) {
	
		var o =  getObj( ElementID );
		if ( o != null ) {
			o.style.display 	= 'none';
			
		}	
			
}

function fadeObjectOut ( ElementID ) {
	
		var o =  getObj( ElementID );
		var opacity = 100;
		
		if ( o != null ) {
			
			for (opacity=0;opacity<=100;opacity++){
			 	changeOpac(opacity, o)	;
			}
			o.style.display 	= 'none';
			
		}	
}


function showObject( ElementID ) {
	
		var o =  getObj( ElementID );
		if ( o != null ) {
			o.style.display 	= '';
			//o.style.position	= 'relative';
		}	
			
}



function WindowLocation( LocationURL, WindowName ) {
			getObj( WindowName ).src = LocationURL;
}


function CreateElement(ParentElement, TagName, Attribs ) {


    var element 		= document.createElement( TagName );
	var Attributes		= Attribs.split(',');
	
	//set attributes
	
	if ( ParentElement != null ) {
		var firstChild = ParentElement.firstChild;
		ParentElement.insertBefore(element, firstChild); 
 	}
	
	for (var x = 0; x <= Attributes.length - 1; x++) {
		
		var Attribute 		=   Attributes[x].split('=');
		element.setAttribute(Attribute[0], Attribute[1]);
		
	}
	

    return element;
	

}



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);
	

}
