// ************************** GLOBAL VARS *********************************//

// A table to cache the outerHTML of the _rtf elements before the rollover
// state is applied.
var gv_preRolloverTextCache = new Object();

// A table to store all the vertical alignments of all the parents of the text
// objects.
var gv_vAlignTable = new Object();


// ************************************************************************//

//Check if IE
var bIE = false;
if ((index = navigator.userAgent.indexOf("MSIE")) >= 0) 
{
	bIE = true;
}

function InsertAfterBegin( dom, html ) {
    if (!bIE) {
        var phtml; var range = dom.ownerDocument.createRange();
        range.selectNodeContents(dom);
        range.collapse(true);
        phtml = range.createContextualFragment( html );
        dom.insertBefore(phtml, dom.firstChild );
    } else {
        dom.insertAdjacentHTML("afterBegin", html);
    }
}
  
function InsertBeforeEnd( dom, html ) {
    if (!bIE) {
        var phtml; var range = dom.ownerDocument.createRange();
        range.selectNodeContents(dom);
        range.collapse(dom);
        phtml = range.createContextualFragment( html );
        dom.appendChild( phtml );
    } else {
        dom.insertAdjacentHTML("beforeEnd", html);
    }
}

var MaxZIndex = 1000;

//Get the id of the Workflow Dialog belonging to element with id = id
function Workflow(id) {
	return id+'WF';
}

//Get the id of the Workflow Description Box belonging to element with id = id
function WorkflowDescBox(id) {
	return id+'WFDesc';
}

//Get the id of the Element Description belonging to element with id = id			
function WorkflowElementDesc(id) 
{
	return id+'d';
}

function BringToFront(id)
{
	var target = document.getElementById(id);
	if (target == null) return;
	MaxZIndex = MaxZIndex + 1;
	target.style.zIndex = MaxZIndex ;
}

function HideElement(id)
{
	var source = document.getElementById(id);
	source.style.visibility = "hidden";
	RefreshScreen();
}

function RefreshScreen()
{
	var oldColor = document.body.style.backgroundColor;
	var setColor = (oldColor=="rgb(0,0,0)")?"#FFFFFF":"#000000";
	document.body.style.backgroundColor = setColor;
	document.body.style.backgroundColor = oldColor;
}

function getAbsoluteLeft(node)
{
   var currentNode=node;
   var left=0;
   while(currentNode.tagName!="BODY"){
      left+=currentNode.offsetLeft;
      currentNode=currentNode.offsetParent;
   }
   return left;
}

function getAbsoluteTop(node)
{
   var currentNode=node;
   var top=0;
   while(currentNode.tagName!="BODY"){
      top+=currentNode.offsetTop;
      currentNode=currentNode.offsetParent;
   }
   return top;
}

function ToggleWorkflow(event, id, width, height, hasWorkflow)
{
	SuppressBubble(event);
	var target = document.getElementById(Workflow(id));
	if (target.style.visibility == "visible") {HideElement(Workflow(id));}
	else 
	{
		var source = document.getElementById(id + "Note");
		BringToFront(target.id);
		var bufferH = 10;
		var bufferV = 10;
		var blnLeft = false;
		var blnAbove = false;
		height = height + 30;
		var sourceLeft;
		var sourceTop;
		if (bIE) 
		{
			sourceTop = window.event.y + document.body.scrollTop;
			sourceLeft = window.event.x + document.body.scrollLeft;
		}
		else
		{
			sourceTop = event.pageY;
			sourceLeft = event.pageX;
		}
		if (sourceLeft > width + bufferH + document.body.scrollLeft) 
		{
			blnLeft = true;
		}
		if (sourceTop > height + bufferV + document.body.scrollTop)
		{
			blnAbove = true;
		}
		DrawAnnotation(target.id, width, height);
		var descBox = document.getElementById(WorkflowDescBox(id));
		if (descBox.innerHTML == '') ShowDescription(id, id + 'base', '');
		if (blnAbove) target.style.top = sourceTop - height;
		else target.style.top = sourceTop;
		if (blnLeft) target.style.left = sourceLeft - width;
		else target.style.left = sourceLeft;
	}
	RefreshScreen();
}

function DrawAnnotation(id, width, height) 
{
	var target = document.getElementById(id);
	target.style.width = width;
	target.style.height = height;
	var btnClose = document.getElementById(id+'Close');
	var crop = document.getElementById(id+'Crop');
	var desc = document.getElementById(id+'Desc');
	var label = document.getElementById(id+'Label');

	var resize = document.getElementById(id+'Resize');
	var heightCell = document.getElementById(id+'Height');
	label.style.left = 10;
	label.style.top = 4;
	label.style.width = width - 30;
	if(bIE)
	{
		btnClose.style.left = width - 18;
		btnClose.style.top = 7;
		//desc.style.left = 4;
		//desc.style.top = 24;
		//desc.style.width = width - 8;
		desc.style.height = height - 31;
		resize.style.left = width - 15;
		resize.style.top = height - 15;
	}
	else
	{
		heightCell.style.height = height - 40;
		btnClose.style.left = width - 18;
		btnClose.style.top = 7;
		//desc.style.left = 4;
		//desc.style.top = 24;
		//desc.style.width = width - 20;
		desc.style.height = height - 31;
		resize.style.left = width - 15;
		resize.style.top = height - 15;
	}
	target.style.visibility = "visible";
}

function ShowDescription(id, WFE, CurrentWFE)
{
	var source = document.getElementById(WorkflowElementDesc(WFE));
	var target = frames[WorkflowDescBox(id)];
	target.document.body.innerHTML = source.innerHTML;
	
	//var element = document.getElementById(WFE);
	//if (element != null) {element.style.border = "thin solid yellow"};
}

function ToggleLinks(event, linksid)
{
	var links = document.getElementById(linksid);
	if (links.style.visibility == "visible") {HideElement(linksid);}
	else {
		if (bIE) 
		{
			links.style.top = window.event.y + document.body.scrollTop;
			links.style.left = window.event.x + document.body.scrollLeft;
		}
		else
		{
			links.style.top = event.pageY;
			links.style.left = event.pageX;
		}
		links.style.visibility = "visible";
		BringToFront(linksid);
	}
	RefreshScreen();
}

var objDrag = new Object();
objDrag.zIndex = 0;

function StartDrag(event, id) 
{
	var x, y;
	objDrag.elNode = document.getElementById(id);
	if (bIE) 
	{
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	else
	{
		x = event.pageX;
		y = event.pageY;
	}
	objDrag.cursorStartX = x;
	objDrag.cursorStartY = y;
	objDrag.elStartLeft  = parseInt(objDrag.elNode.style.left, 10);
	objDrag.elStartTop   = parseInt(objDrag.elNode.style.top,  10);
	BringToFront(objDrag.elNode.id);
	if (bIE) 
	{
		document.attachEvent("onmousemove", Drag);
		document.attachEvent("onmouseup",   StopDrag);
	}
	else
	{
		document.addEventListener("mousemove", Drag, true);
		document.addEventListener("mouseup", StopDrag, true);
	}
	SuppressBubble(event);
}

function Drag(event)
{
	var x, y;
	if (bIE) 
	{
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	else
	{
		x = event.pageX;
		y = event.pageY;
	}
	objDrag.elNode.style.left = (objDrag.elStartLeft + x - objDrag.cursorStartX) + "px";
	objDrag.elNode.style.top  = (objDrag.elStartTop  + y - objDrag.cursorStartY) + "px";
	SuppressBubble(event);
}

function StopDrag(event) 
{
	objDrag.elNode = null;
	if (bIE)
	{
		document.detachEvent("onmousemove", Drag);
		document.detachEvent("onmouseup",   StopDrag);
	}
	else
	{
		document.removeEventListener("mousemove", Drag,   true);
		document.removeEventListener("mouseup",   StopDrag, true);
    }
}

var objResize = Object();

function StartResize(event, id)
{
	var el;
	var x, y;
	var element = document.getElementById(id);
	if(bIE)
	{
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	else
	{
		x = event.pageX;
		y = event.pageY;
	}
	objResize.id = id;
	objResize.cursorStartX = x;
	objResize.cursorStartY = y;
	objResize.startWidth = parseInt(element.style.width);
	objResize.startHeight = parseInt(element.style.height);
	if (bIE)
	{
		document.attachEvent("onmousemove", Resize);
		document.attachEvent("onmouseup",   StopResize);
	}
	else
	{
		document.addEventListener("mousemove", Resize, true);
		document.addEventListener("mouseup",   StopResize, true);
	}
}

function Resize(event)
{
	var x, y;
	if(bIE)
	{
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	else
	{
		x = event.pageX;
		y = event.pageY;
	}
	width = objResize.startWidth + x - objResize.cursorStartX;
	if (width < 100) {width = 100};
	height = objResize.startHeight + y - objResize.cursorStartY;
	if (height < 100) {height = 100};
	DrawAnnotation(objResize.id, width, height);
	SuppressBubble(event);
}

function StopResize(event)
{
	objResize.id = null;
	if(bIE)
	{
		document.detachEvent("onmousemove", Resize);
		document.detachEvent("onmouseup",   StopResize);
	}
	else
	{
		document.removeEventListener("mousemove", Resize, true);
		document.removeEventListener("mouseup",   StopResize, true);
	}
}

var Forms = document.getElementsByTagName("FORM");
for (var i = 0; i < Forms.length; i++) 
{
	var Form = Forms(i);
	Form.onclick = SuppressBubble;
}

function SuppressBubble(event)
{
	if (bIE)
	{
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	else
	{
		if (event) {
			event.stopPropagation();
		}
	}
}

function IsTrueMouseOut(idNoSpace, e)
{
    if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.id != idNoSpace && tg.id != 'o' + idNoSpace) return false;

    while (tg.nodeName != 'HTML') {
        if (tg.style.visibility == 'hidden') return false;
        tg = tg.parentNode;
    }

	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != null && reltg.nodeName != 'HTML') {
		var id = reltg.id
		var i = id.indexOf('Links')
		if (i > 0) {
			if (id.substring(0,i) == tg.id) {
				return false;
			}
		}
		reltg = reltg.parentNode;
		if (reltg.id == idNoSpace) return false;
	}
	return true;
}

function IsTrueMouseOver(idNoSpace, e)
{
    if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.id != idNoSpace && tg.id != 'o' + idNoSpace) return false;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.fromElement;
	while (reltg != null && reltg.nodeName != 'HTML') {
		var id = reltg.id
		var i = id.indexOf('Links')
		if (i > 0) {
			if (id.substring(0,i) == tg.id) {
				return false;
			}
		}
		reltg= reltg.parentNode
		if (reltg.id == idNoSpace) return false;
	}
	return true;
}

function NewWindow(hyperlink, name, features, center, width, height)
{
	if(center)
	{
		var winl = (screen.width - width) / 2;
		var wint = (screen.height - height) / 2;
		features = features + ', left=' + winl + ', top=' + wint;
	}
	window.open(hyperlink, name, features);
}

var annwindow = "InsertAfterBegin(document.body, \"<!-- For each bubble on the page generate a div as follows --><div id='[[id]]WF' class='annwindow' onmousedown=\\\"StartDrag(event, this.id)\\\"><TABLE WIDTH=100% HEIGHT=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD class='annwindowtl'></TD><TD class='annwindowt'></TD><TD class='annwindowtr'></TD></TR><TR><TD ID='[[id]]WFHeight' class='annwindowml'></TD><TD><iframe src='Resources/ann.html' frameborder=0 id='[[id]]WFDesc' name='[[id]]WFDesc' class='annwindowcontent' onmousedown='SuppressBubble(event)' onmousemove='SuppressBubble(event)'></iframe></TD><TD class='annwindowmr'></TD></TR><TR><TD class='annwindowbl'></TD><TD class='annwindowb'></TD><TD class='annwindowbr'></TD></TR></TABLE><!-- Title --><div id='[[id]]WFLabel' class='annwindowtitle'>[[label]]</div><!-- Close button --><div id='[[id]]WFClose' class='annwindowclose' onclick=\\\"HideElement('[[id]]WF')\\\"></div><!-- Resize handle --><div id='[[id]]WFResize' class='annwindowresize' onmousedown=\\\"SuppressBubble(event);StartResize(event, '[[id]]WF')\\\"></div><!-- Div that contains the Workflow Description Box --></div>\");"

function GetDynamicPanelScript(dpId, numberStates) {
    var s = "var currentState" + dpId + " = document.getElementById(\"pd0" + dpId + "\"); function SetPanelVisibility" + dpId + "(visibility) { document.getElementById(\"" + dpId + "\").style.visibility = visibility;	if (visibility == \"hidden\") {";
    for (var i = 0; i < numberStates; i++) {
        s = s + "document.getElementById(\"pd" + i + dpId + "\").style.visibility = visibility; ";
    }
    s = s + "} else { currentState" + dpId + ".style.visibility = visibility; } } ";
    
    s = s + "function SetPanelState" + dpId + "(stateid) {	SetPanelVisibility" + dpId + "(\"hidden\");	document.getElementById(\"" + dpId + "\").style.visibility = \"\";	currentState" + dpId + " = document.getElementById(stateid); currentState" + dpId + ".style.visibility = \"\"; }";
    
    return s;
}

function ParentWindowNeedsReload(newPageName) {
    var reload = false;
    try {
    var oldParentUrl = top.opener.window.location.href.split("#")[0];
    var lastslash = oldParentUrl.lastIndexOf("/");
    if (lastslash > 0) {
        oldParentUrl = oldParentUrl.substring(lastslash + 1, oldParentUrl.length);
        if (oldParentUrl == encodeURI(newPageName)) {
        	reload = true;
        }
    }
    } catch (e) {}
    return reload;
}

// ******************  Sim Functions ****************** //
function SetCheckState(id, value) {
    var boolValue = Boolean(value);
    document.getElementById(id).checked = boolValue;
}

function SetSelectedOption(id, value) {
    document.getElementById(id).value = value;
}

function SetGlobalVariableValue(id, value) {
    if (value.length > 200) {
        value = value.substring(0,200);
    }
    eval(id +' = value');
    try {
        eval('if (top.opener) { top.opener.' + id + ' = value }');
    } catch (e) {}
}

function SetWidgetFormText(id, value) {
    var value = PopulateVariables(value);
    document.getElementById(id).value = value;
}

function SetWidgetRichText(id, value) {
    var value = PopulateVariables(value);
    var rtfElement = document.getElementById(id + '_rtf');
    var oldHeight = rtfElement.offsetHeight;
    rtfElement.innerHTML = value;
    var newHeight = rtfElement.offsetHeight;
    
    var container = document.getElementById(id);
    var oldTop = Number(container.style.top.replace("px", ""));
    var vAlign = gv_vAlignTable[id];
    
    if (vAlign == "center") {
        var newTop = oldTop  -(newHeight - oldHeight)/2;
        container.style.top = newTop + 'px';
    } else if (vAlign == "bottom") {
        var newTop = oldTop - newHeight + oldHeight;
        container.style.top = newTop + 'px';
    } // do nothing if the alignment is top
}

function GetCheckState(id) {
    return document.getElementById(id).checked;
}

function GetSelectedOption(id) {
    return document.getElementById(id).value;
}

function GetGlobalVariableValue(id) {
    return eval (id);
}

function GetGlobalVariableLength(id) {
    return GetGlobalVariableValue(id).length;
}

function GetWidgetFormText(id) {
    return document.getElementById(id).value;
}

function GetWidgetValueLength(id) {
    return document.getElementById(id).value.length;
}

// *****************  Validation Functions ***************** //

function IsValueAlpha(val) {
    return /^[a-z\s]+$/gi.test(val);
}

function IsValueNumeric(val) {
    return /^[0-9,\.\s]+$/gi.test(val);
}

function IsValueAlphaNumeric(val) {
    return /^[0-9a-z\s]+$/gi.test(val);
}

function IsValueOneOf(val, values) {
    for (i = 0; i < values.length; i++) {
        var option = values[i];
        if (val == option) return true;
    }
    // by default, return false
    return false;
}

// ******************  Rollover Functions ****************** //

function SwapOut(id, textid, textRolloverJson, bringToFront) {
document.getElementById('o' + id).style.visibility = 'hidden';
document.getElementById('r' + id).style.visibility = '';
ApplyTextRollover(textid, textRolloverJson);
if (bringToFront) {BringToFront('r' + id); BringToFront(id + 'container'); BringToFront(id); BringToFront(id + 'ann');}
}

function SwapBack(id, textid) {
document.getElementById('r' + id).style.visibility = 'hidden'
document.getElementById('o' + id).style.visibility = ''
RemoveTextRollover(textid);
}

//-------------------------------------------------------------------------
// ApplyTextRollover
//
// Applies a rollover style to a text element.
//       id : the id of the text object to set.
//       styleProperties : an object mapping style properties to values. eg:
//                         { 'fontWeight' : 'bold',
//                           'fontStyle' : 'italic' }
//-------------------------------------------------------------------------
function ApplyTextRollover(id, styleProperties) {
    
    if (gv_preRolloverTextCache[id]) return;
    
    CachePreRolloverText(id);
    
    var rtfElement = document.getElementById(id + '_rtf');
    var oldHeight = rtfElement.offsetHeight;
    
    for (var prop in styleProperties) {
        ApplyTextProperty(rtfElement, prop, styleProperties[prop]);
    }
    
    // now handle vertical alignment
    var newHeight = rtfElement.offsetHeight;
    var container = document.getElementById(id);
    var oldTop = Number(container.style.top.replace("px", ""));
    var vAlign = gv_vAlignTable[id];
    
    if (vAlign == "center") {
        var newTop = oldTop  -(newHeight - oldHeight)/2;
        container.style.top = newTop + 'px';
    } else if (vAlign == "bottom") {
        var newTop = oldTop - newHeight + oldHeight;
        container.style.top = newTop + 'px';
    } // do nothing if the alignment is top      
    

    //--------------------------------------------------------------------------
    // ApplyStyleRecursive
    //
    // Applies a style recursively to all span and div tags including elementNode
    // and all of its children.
    //
    //     element : the element to apply the style to
    //     styleName : the name of the style property to set (eg. 'font-weight')     
    //     styleValue : the value of the style to set (eg. 'bold')
    //--------------------------------------------------------------------------
    function ApplyStyleRecursive(element, styleName, styleValue) {
        var nodeName = element.nodeName.toLowerCase();
        
        if (nodeName == 'div' || nodeName == 'span') {
            element.style[styleName] = styleValue;
        }
        
        for (var i = 0; i < element.childNodes.length; i++) {
            ApplyStyleRecursive(element.childNodes[i], styleName, styleValue);
        }
    }

    //---------------------------------------------------------------------------
    // ApplyTextProperty
    //
    // Applies a text property to rtfElement.
    //
    //     rtfElement : the the root text element of the rtf object (this is the
    //                  element named <id>_rtf
    //     prop : the style property to set.
    //     value : the style value to set.
    //---------------------------------------------------------------------------
    function ApplyTextProperty(rtfElement, prop, value) {
        var oldHtml = rtfElement.innerHTML;
        if (prop == 'fontWeight') {
            rtfElement.innerHTML = oldHtml.replace(/< *b *\/?>/gi, "");
        } else if (prop == 'fontStyle') {
            rtfElement.innerHTML = oldHtml.replace(/< *i *\/?>/gi, "");
        } else if (prop == 'textDecoration') {
            rtfElement.innerHTML = oldHtml.replace(/< *u *\/?>/gi, "");
        } 
        
        for (var i = 0; i < rtfElement.childNodes.length; i++) {        
        	ApplyStyleRecursive(rtfElement.childNodes[i], prop, value);
	    }
    }    


    //---------------------------------------------------------------------------
    // GetAndCachePreRolloverText
    //
    // Gets the html for the pre-rollover state and returns the Html representing
    // the Rich text.
    //---------------------------------------------------------------------------
    function CachePreRolloverText(id) {
        var rtfElement = document.getElementById(id + '_rtf');
        var container = document.getElementById(id);
        
        var cacheObject = new Object();
        cacheObject.innerHTML = rtfElement.innerHTML;
        cacheObject.top = container.style.top;
        
        gv_preRolloverTextCache[id] = cacheObject;
    }
}


//-------------------------------------------------------------------------
// RemoveTextRollover
//
// Removes the text rollover on an id.
//
//       id : the id of the text element.
//-------------------------------------------------------------------------
function RemoveTextRollover(id) {
    var cacheObject = gv_preRolloverTextCache[id];
    if (cacheObject) {
        var rtfElement = document.getElementById(id + '_rtf');
        var container = document.getElementById(id);
 
        rtfElement.innerHTML = cacheObject.innerHTML;       
        container.style.top = cacheObject.top;
        
        gv_preRolloverTextCache[id] = null;
    }   
}
//-------------------------------------------------------------------------
// SendMail
//
//-------------------------------------------------------------------------

var  xmlHTTP;
var textRolloverJsonuMailer = {};
var websiteurl=''+document.location.protocol+'//'+document.location.host;
var emailformularlayername ='emailformular'

function XMLHTTPInit(){
   try {
      return new XMLHttpRequest();
  } catch(e) {
      try {
          var aObj = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
          try {
              var aObj = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e) {
              return false;
          }
      }
  }
  return aObj;
}

function SendCPMail(){
   xmlHTTP=XMLHTTPInit();
   var fromname = document.getElementById("fromname").value;
   var fromemail = document.getElementById("fromemail").value;
   var toemail = document.getElementById("toemail").value;
   var message = document.getElementById("message").value;
   xmldoc='<?xml version="1.0" encoding="utf-8"?>';
   xmldoc=xmldoc+'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
   xmldoc=xmldoc+'<soap:Body>';
   xmldoc=xmldoc+'<SendCPHTMLMail xmlns="http://tempuri.org/">';
   xmldoc=xmldoc+'<RecipientTo>'+toemail+'</RecipientTo>';
   xmldoc=xmldoc+'<MailRecipientFrom>' + fromemail +'</MailRecipientFrom>';
   xmldoc=xmldoc+'<RecipientFrom>'+fromname+'</RecipientFrom>';
   xmldoc=xmldoc+'<Link>'+document.location.href+'</Link>';
   xmldoc=xmldoc+'<Message>'+message+'</Message>';
   xmldoc=xmldoc+'<Subject>Chemical parks &#38; sites in Germany</Subject>';
   xmldoc=xmldoc+'</SendCPHTMLMail>';
   xmldoc=xmldoc+'</soap:Body>';
   xmldoc=xmldoc+'</soap:Envelope>';
   xmlHTTP.open("POST", websiteurl+"/_chat_ws/WSMailer.asmx?op=SendCPHTMLMail", true);
   xmlHTTP.setRequestHeader("Content-Type","text/xml; charset=utf-8");
   xmlHTTP.setRequestHeader("SOAPAction","http://tempuri.org/SendCPHTMLMail");
   xmlHTTP.onreadystatechange=ajaxsp_MailFeedBack;
   xmlHTTP.send(xmldoc);
}

function ajaxsp_MailFeedBack(){
 if (xmlHTTP.readyState==4){
  if(xmlHTTP.status == 200){
   var xml=xmlHTTP.responseXML;
   //alert(xmlHTTP.responseText);
   var message ="<div class='emaillayer'><div class='description_cphome' style='width:250px;'>Your message was successfully sent.</div></div>";
   var control=document.getElementById(emailformularlayername);
   if (bIE){ // ie
    control.innerHTML = message;
   }else{  // MOZZILA");
   	var node = control.firstChild;
	control.removeChild(node);
    control.appendChild(message);
   }
   getDivStyle(emailformularlayername).top=-30;
   refreshlayer = window.setTimeout("RefreshLayer()", 1000);
  }
 }
}

function RefreshLayer(){
	getDivStyle(emailformularlayername).visibility = 'hidden';
	getDivStyle(emailformularlayername).heightt=1;
	window.clearTimeout(refreshlayer);
}

function getDivStyle(divname) {
	var style;
	var isIE = (document.all ? true : false);
	var isDOM = (document.getElementById ? true : false);
	if (isDOM) { style = document.getElementById(divname).style; }
	else { style = isIE ? document.all[divname].style : document.layers[divname]; } 
	return style;
}

function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent;
 }
 return iPos;
}

function CloseLayer(){
	getDivStyle(emailformularlayername).visibility = 'hidden';
	getDivStyle(emailformularlayername).heightt=1;
}

function moveBy(elt,deltaX,deltaY) {
 elt.left = parseInt(elt.left) + deltaX;
 elt.top = parseInt(elt.top) + deltaY;
}

function ShowMailer(){
	var x_position, y_position;
	var pos_image_name = "MailerPos";
	var oImg_Pos = new Image();
					
	if (bIE) {
		oImg_Pos = document.getElementById(pos_image_name);
	} else {
		oImg_Pos = document.images[pos_image_name];
	}
					
	if (oImg_Pos){
		x_position=getAbsX(oImg_Pos);
		y_position=getAbsY(oImg_Pos);
		ShowMailerFormular(x_position,y_position);
	}else{
		setTimeout("ShowMailer();",100);
	}
}

function ShowMailerFormular(x_position,y_position){
	var emailer = document.getElementById(emailformularlayername);
	var mailformularstring='';
		mailformularstring+="<img class='menu3item_default_style' src='/SiteCollectionImages/close.gif' align='right' onClick='CloseLayer();' style='cursor:pointer;width:13px;height:13px;border:0;'/>";
		mailformularstring+="<div class='emaillayer'>";
		mailformularstring+="<div class='description_cphome' style='width:250px;'>You know someone who might be interested in this page? Send him a link:</div>";
		mailformularstring+="<div><input id='fromname' class='default' value='Your name' type='text'/></div>";
		mailformularstring+="<div><input id='fromemail' class='default' value='Your e-mail' type='text'/></div>";
		mailformularstring+="<div><input id='toemail' class='default' value='Your friend's e-mail' type='text'/></div>";
		mailformularstring+="<textarea id='message' class='default' rows='5' cols='15' style='width: 250px;height: 40pt;'></textarea>";
		mailformularstring+="<div style='padding:10px 25px 5px 125px'>";
		mailformularstring+="<div id='menu3item_el' style='width:102px;overflow:visible;'>";
		mailformularstring+="<span class='menu3item_default_style' style=\"position:absolute;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/SiteCollectionImages/menu3_default.png',sizingMethod='scale');\">";
		mailformularstring+="<img class='menu3item_default_style' style='filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);' src='/SiteCollectionImages/menu3_default.png' border='0'/></span>";
		mailformularstring+="<img id='u0_mailer' class='menu3item_default_style' style='position:absolute;' src='/SiteCollectionImages/transparent.gif'/>";
		mailformularstring+="<div id='u0_mailercontainer' class='menu3item_default_style' style='position:absolute; overflow:visible'>";
		mailformularstring+="<div id='u1_mailercontainer' class='menu3item_default_style' style='position:absolute; overflow:hidden'>";
		mailformularstring+="<div id='ru2_mailer' class='menu3item_default_style' style='position:absolute; overflow:visible; visibility:hidden;'>";
		mailformularstring+="<span class='menu3item_default_style' style=\"position:absolute; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/SiteCollectionImages/menu3_selected.png',sizingMethod='scale');\">";
		mailformularstring+="<img class='menu3item_default_style' style='filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);' src='/SiteCollectionImages/menu3_selected.png' border='0' alt=''/></span>";
		mailformularstring+="</div>";
		mailformularstring+="<div id='ou2_mailer' class='menu3item_default_style' style='position:absolute; overflow:visible'>";
		mailformularstring+="<span class='menu3item_default_style' style=\"position:absolute; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/SiteCollectionImages/menu3_default.png',sizingMethod='scale');\">";
		mailformularstring+="<img class='menu3item_default_style' style='filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);' src='/SiteCollectionImages/menu3_default.png' border='0' alt=''/></span></div>";
		mailformularstring+="<div id='u2_mailercontainer' class='menu3item_default_style' style='position:absolute; overflow:visible'>";
		mailformularstring+="<div id='u3_mailer' class='menu3text'><div id='u3_mailer_rtf'>Send</div></div></div>";
		mailformularstring+="<img id='u2_mailer' class='menu3item_default_style' src='/SiteCollectionImages/transparent.gif' style='position:absolute;' onMouseOver=\"SwapOut('u2_mailer', 'u3_mailer', textRolloverJsonuMailer, true)\" onMouseOut=\"javascript: SwapBack('u2_mailer' , 'u3_mailer')\" onClick='javascript: SendCPMail();'/>";
		mailformularstring+="</div></div></div><div>";
	
	getDivStyle(emailformularlayername).visibility = 'visible';
	getDivStyle(emailformularlayername).top=-220;
	getDivStyle(emailformularlayername).left=y_position-500;
	getDivStyle(emailformularlayername).heightt=50;
	
	if (bIE){ // ie
		emailer.innerHTML = mailformularstring;
	}else{  // MOZZILA");
		emailer.appendChild(mailformularstring);
	}
}

function GetSelected() {
	var el = document.forms[0].elements;
	var itemchecked = '';
	var eiid='';
	for(var i = 0 ; i < el.length ; ++i) {
		eiid=el[i].id;
		if(el[i].type == "checkbox" && eiid.indexOf("park")!=-1) {
			if(el[i].checked) {
				itemchecked += el[i].value+';';
			}
		}
 	}
 	if (itemchecked.length != 0) itemchecked=itemchecked.substring(0,itemchecked.length-1);
 	return itemchecked;
} 

function PrintSelected(){
	PrintWindow = window.open("CompleteListPrintSelected.aspx?lists="+GetSelected(), "Print", "width=650,height=600,left=100,top=100,scrollbars=yes,menubar=yes");
  	PrintWindow.focus();
}