/*
+--------------------------------------
|   Wiccle v1.00
|   ==================================
|   by Markus Loponen & Keith Killilea
|   (c) 2009-2010 Wiccle Ltd.
|   http://www.www.wiccle.com
|   Email: info@wiccle.com
|   ==================================
|   Time: 2010-04-16 | File version: 1.00
+-------------------------------------
|  	Please read the Wiccle license 
|   Available at docs/license.txt
+-------------------------------------
*/





function goTo(targetUrl) 
{

	if (targetUrl.substr(0,9) == "index.php")
	{
		if (document.getElementsByTagName('base') && document.getElementsByTagName('base')[0])
		{
			var baseHref = document.getElementsByTagName('base')[0].href;
			targetUrl = baseHref + targetUrl;
		}
	}
	
	document.location.href = targetUrl;
	return;
}


function refreshPage(reload) 
{
	
	
	var url = parent.window.location.toString();
	var anchor_index = url.indexOf('#');
    if (anchor_index != -1) {
    	url = url.substring(0, anchor_index);
    }
	var urlAppend = '';
	if (reload && url.indexOf('=')>0) var urlAppend = '&reload=1';
	else if (reload) var url = 'index.php?reload=1';

	
	goTo(url + urlAppend);
	return;
}


function bookmarkPage() {

var title = siteName; 
var url = baseURL;

if (window.sidebar) { // Mozilla Firefox Bookmark
	window.sidebar.addPanel(title, url,"");
} else if( window.external ) { // IE Favorite
	window.external.AddFavorite( url, title); }
else if(window.opera && window.print) { // Opera Hotlist
	return true; }
	
}



function getPosition(e) 
{
	
	if (!e)
		e = window.event;
		
	if (IE) { // grab the x-y pos.s if browser is IE
	
		// sometimes IE forgets that this variable is actually provided by the browser =) so here's the fix
		if (!document.body) 
		{
			var leftScroll = 0;
			var topScroll = 0;
		}
		else 
		{	
			var leftScroll =  document.body.scrollLeft;
			var topScroll =  document.body.scrollTop;
		}
		tempX = e.clientX + leftScroll;
		tempY = e.clientY + topScroll;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}
	
	// tempX = e.pageX;
	// tempY = e.pageY;
	
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	
	window.resize_x = tempX;	
}










function getViewSize()
{
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return yWithScroll; //arrayPageSizeWithScroll;
}




function startDrag(thisBox, thisToolbar) 
{
	if (!window.dragActive)
	{
		var group
		var coordinates = ToolMan.coordinates()
		var drag = ToolMan.drag()

		var boxHandle = document.getElementById(thisBox)
		group = drag.createSimpleGroup(boxHandle, document.getElementById(thisToolbar))
		
		if (window.verticalOnly)
		{
			group.verticalOnly()
		}
		
		window.dragActive = true;
	}
	else
	{
		window.dragActive = false;
	}
}




function reloadPage (pageId, targetPage) {
	var target = document.getElementById(pageId);
	target.src = targetPage;
}


function reloadThisPage()
{
	var url = window.location.toString();
	//Remove anchor from url
	var anchor_index = url.indexOf('#');
    if (anchor_index != -1) {
    	url = url.substring(0, anchor_index);
    }
	window.location.href = url;
		
}




function disableEnterKey(e)
{
     var key;
	 
	 //onkeypress="return disableEnterKey(event)"


     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}





