
// Show help tooltip
function showWebgainHelp() {
	fieldname = arguments[0];
	text = arguments[1];
	var size = 200

	if (arguments.length == 3) {
		size = arguments[2];
	}
	
	return coolTip(text, RIGHT, WIDTH, size, DELAY, 50, VAUTO, OFFSETX, 0, OFFSETY, 0, CAPTION, fieldname, NOCLOSE, FOLLOWMOUSE,
				   CSSW3C, DIVCLASS, 'webgain-cooltip-div', BODYCLASS, 'webgain-cooltip-body', 
				   CAPTIONCLASS, 'webgain-cooltip-caption', CLOSECLASS, 'webgain-cooltip-close');
}


// Show help tooltip wider
function showWebgainHelpWide(fieldname, text) {
	return coolTip(text, RIGHT, WIDTH, 300, BORDER, DELAY, 50, VAUTO, OFFSETX, 0, OFFSETY, 0, CAPTION, fieldname, NOCLOSE, FOLLOWMOUSE, 
				   CSSW3C, DIVCLASS, 'webgain-cooltip-div', BODYCLASS, 'webgain-cooltip-body', 
				   CAPTIONCLASS, 'webgain-cooltip-caption', CLOSECLASS, 'webgain-cooltip-close');
}

function showWebgainHelpSuperWide(fieldname, text) {
	return coolTip(text, RIGHT, WIDTH, 400, BORDER, DELAY, 50, VAUTO, OFFSETX, 0, OFFSETY, 0, CAPTION, fieldname, NOCLOSE, FOLLOWMOUSE,
				   CSSW3C, DIVCLASS, 'webgain-cooltip-div', BODYCLASS, 'webgain-cooltip-body', 
				   CAPTIONCLASS, 'webgain-cooltip-caption', CLOSECLASS, 'webgain-cooltip-close');
}

// Show help tooltip
function showSelector(fieldname, text) {
	return coolTip(text, RIGHT, WIDTH, 200, DELAY, 50, OFFSETX, 0, OFFSETY, 0, CAPTION, fieldname, NOCLOSE, STICKY, FOLLOWMOUSE,
				   CSSW3C, DIVCLASS, 'webgain-cooltip-div', BODYCLASS, 'webgain-cooltip-body', 
				   CAPTIONCLASS, 'webgain-cooltip-caption', CLOSECLASS, 'webgain-cooltip-close');
}

// Show help tooltip wider
function showSelectorWide(fieldname, text) {
	return coolTip(text, RIGHT, WIDTH, 300, BORDER, DELAY, 50, OFFSETX, 0, OFFSETY, 0, CAPTION, fieldname, NOCLOSE, STICKY, FOLLOWMOUSE,
				   CSSW3C, DIVCLASS, 'webgain-cooltip-div', BODYCLASS, 'webgain-cooltip-body', 
				   CAPTIONCLASS, 'webgain-cooltip-caption', CLOSECLASS, 'webgain-cooltip-close');
}

function showSelectorSuperWide(fieldname, text) {
	return coolTip(text, RIGHT, WIDTH, 400, BORDER, DELAY, 50, OFFSETX, 0, OFFSETY, 0, CAPTION, fieldname, NOCLOSE, STICKY, FOLLOWMOUSE,
				   CSSW3C, DIVCLASS, 'webgain-cooltip-div', BODYCLASS, 'webgain-cooltip-body', 
				   CAPTIONCLASS, 'webgain-cooltip-caption', CLOSECLASS, 'webgain-cooltip-close');
}


// Show help tooltip
function showSiteGubbeInfo() {
	fieldname = arguments[0];
	text = arguments[1];
	var size = 200

	if (arguments.length == 3) {
		size = arguments[2];
	}
	
	return coolTip(text, LEFT, WIDTH, size, DELAY, 50, VAUTO, OFFSETX, 0, OFFSETY, 0, CAPTION, fieldname, NOCLOSE, FOLLOWMOUSE,
				   CSSW3C, DIVCLASS, 'webgain-cooltip-div', BODYCLASS, 'webgain-cooltip-body', 
				   CAPTIONCLASS, 'webgain-cooltip-caption', CLOSECLASS, 'webgain-cooltip-close');
}

function findObjectPosition(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function doTaconite(url) {
  	var ajaxRequest = new AjaxRequest(url); 
    //ajaxRequest.setEchoDebugInfo();
    ajaxRequest.sendRequest();  
}

// Function to show hide layers
// First input is ID of layer you want to make visible
// Second input is ID of layer you want to hide
// Third input is ID to TAB that was selected (become gray selected colour)
// Forth input is ID to TAB that should be unselected (become standard colour)
// Leave input-field empty if you don't want to use current feature: 'layer1','','','button'

function showHideLayer(strShowThis,strHideThis) {
	if(strShowThis != '') {
		oDivDisplay = document.getElementById(strShowThis);
		oDivDisplay.style.display = "block";
		oDivDisplay.style.visibility = "visible";
	}

	if(strHideThis != '') {
		oDivHide = document.getElementById(strHideThis);
		oDivHide.style.display = "none";
		oDivHide.style.visibility = "hidden";
	}else{
		// Get parent div
		oDivParent = oDivDisplay.parentNode;
		
		// Loop and hide all children except the one that should be visible
		for (i=0; i < oDivParent.childNodes.length; i++){
			if(oDivParent.childNodes[i].id != strShowThis && oDivParent.childNodes[i].tagName == 'DIV'){
				oDivParent.childNodes[i].style.display = "none";
				oDivParent.childNodes[i].style.visibility = "hidden";
			}
		}
	}

}

function trim(s) {
	if (!s)	return "";
	return s.replace(/(^\s+)|(\+$)/g, "")
}

function changeVisibility(id) {
	var obj = document.getElementById(id);
	if (obj.style.visibility == "hidden") {
		obj.style.visibility = "visible";
	} else {
		obj.style.visibility = "hidden";
	}
}

function submitEvent(formId, url, eventId, event) {
	var form = document.getElementById(formId);
	form.action = url;
	var eventField = document.getElementById(eventId);
	eventField.value = event;
	form.submit();
	form.action = "Form action invalidated after submit";
}

var alertlok = false;
function webgainConfirm(header, message, buttonConfirmText, buttonCancelText, confirmURI) {
	if (!alertlok) { 
		alertlok = true;
		new StickyWin.Fx({
	  	    content: StickyWin.ui(header, message + '<br/><br/>', {
			    width: '400px',
			    closeButton: false,
			    buttons: [
			      {
			        text: buttonConfirmText, 
			        onClick: function(){
						document.location=confirmURI;
			        }
			      },
			      {
			        text: buttonCancelText, 
			        onClick: function(){ alertlok = false;}
			      }
			    ]
			  })
			});
	 }
  }	

  function webgainAlert(header, message, buttonOkText) {
	if (!alertlok) { 
		alertlok = true;
		new StickyWin.Fx({
	  	    content: StickyWin.ui(header, message + '<br/><br/>', {
			    width: '400px',
			    closeButton: false,
			    buttons: [
			      {
			        text: buttonOkText, 
			        onClick: function(){
			        	alertlok = false;
			        }
			      }
			    ]
			  })
			});
		return ok;
	}
  }	
  
  
  
