function hide_display(t,d){
	tt=document.getElementById(t);
	if(d==1){
		tt.style.display='none';
	} else {
		if(tt.style.display=='none'){
			tt.style.display='block';
		}else{
			tt.style.display='none';
		}
	}
}

function hide_personal_display_g(){
	document.getElementById('my_invoices').style.display = 'none';
	document.getElementById('my_sales').style.display = 'none';
	document.getElementById('my_referred_organisations').style.display = 'none';
}

var activeDisplayed = null;

function toggleExample(thisId) {

	//Toggle Object
	obj = document.getElementById(thisId);
	obj.style.position = 'absolute';
	if(obj.style.display == 'none'){

		//Unhide Object
		obj.style.zIndex = 2;
		obj.style.display = '';
		obj.style.left = ((windowSize().x - obj.offsetWidth) / 2) + getScrollXY().x;
		obj.style.top = ((windowSize().y - obj.offsetHeight) / 2) + getScrollXY().y;
		document.body.onmouseup = new Function("toggleExample('"+thisId+"');");
	} else {
		obj.style.display = 'none';
		activeDisplayed = null;
		document.body.onmouseup = '';
	}

}


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return {x:scrOfX, y:scrOfY};
}

//Get Y absolute co-ords if object is relative
function objPos (obj) { 
	var cY = obj.offsetTop;
	var cX = obj.offsetLeft;
	while((obj = obj.offsetParent) != null) { 
		cY += obj.offsetTop;
		cX += obj.offsetLeft;
	}
	return {x:cX, y:cY};
}

function windowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return {x:myWidth, y:myHeight};
}

function doPop(url, features) {
	//features = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=300"
	var id = url;
		id = id.replace(/[^a-zA-Z0-9]/gi, "");
		id = id.replace(/\s*/gi, "");
	window.open(url, id, features);
}

function compsTabToggle() {

	var obj = document.getElementById('xmasPanel');

	if (obj.style.display == 'none') {
		obj.style.display = '';
	} else {
		setTimeout("compsTabHide();", 100);
	}

}

var compsTabHideDo = true;
function compsTabHide() {
	var obj = document.getElementById('xmasPanel');
	if (compsTabHideDo === true) {
		obj.style.display = 'none';
	}
}

//----------------------------------------------------------------
// Add Event (without putting anything into the markup)
//----------------------------------------------------------------

	function addEvent(obj, evType, fn){ 
		if (obj.addEventListener){ 
			obj.addEventListener(evType, fn, false); 
			return true; 
		} else if (obj.attachEvent){ 
			var r = obj.attachEvent("on"+evType, fn); 
			return r; 
		} else { 
			return false; 
		} 
	}

//My Favourites
function toggleFavTooltip(objCheckBox) {
	if (objCheckBox) {
		var set=1;
	} else {
		var set="";
	}
	pstr = '/inc/modules/my_favourites/rpc.php?action=toggleTooltip&set='+set;
	makePOSTRequest(pstr, "post=true");

}

//Cross browser show/hide, toggle() seems to not work in Firefox
function toggleObj(id) {
	var obj = document.getElementById(id);
	if (obj.style.display == "none") {
		obj.style.display = "";
	} else {
		obj.style.display = "none";
	}
}

//----------------------------------------------------------------
// Favourites function
//----------------------------------------------------------------

function createBookmark(obj) {

    var title = 'easyfundraising.org.uk - So easy...so why not?';
    var url = document.location;

    if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) { // Chrome
        obj.innerHTML = "As you're using Google Chrome, please press<br />CTRL + D on your keyboard to add us to your bookmarks.";
    } else 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
        obj.innerHTML = "As you're using Opera, please press CTRL + D on your keyboard to add us to your bookmarks.";
    } else {
        obj.innerHTML = "You'll need to press<br />CTRL + D on your keyboard to add us to your favourites. If that does not work, please follow your Browser's help documentation.";
    }

    return false;

}
