var IE = document.all?true:false;

var mouse_x = 0;
var mouse_y = 0;


function bodyOnload(){
	//setScrollbarStyles(document.getElementById("pagecontent"));
	//initScrollbar();
}
function bodyOnloadCRM(){
	/*
	var vp = getViewport();
	var div = document.getElementById("right_content");
	
	div.style.width = (vp["width"] - 75 - 180 - 46) + "px";
	
	var div= document.getElementById("menu");
	div.style.width = (vp["width"] - 75) + "px";
	*/
}
function initScrollbar(){
	if(document.getElementById("right_content").clientHeight>=373){
		jQuery("#pagecontent").css({overflow:"visible", maxHeight:"1500px", height:"373px"});
		jQuery('.scroll_projects_list').jScrollPane();
	}
}
function getMouseXY(e){
	if(IE){
		mouse_x = event.clientX + document.body.scrollLeft;
		mouse_y = event.clientY + document.body.scrollTop;
	}
	else{
		mouse_x = e.pageX;
		mouse_y = e.pageY;
	}
	if(mouse_x<0) mouse_x = 0;
	if(mouse_y<0) mouse_y = 0;
}
function getPosition(obj){
	var finalvalue = [];
    var topValue= 0,leftValue= 0;
    while(obj){
		leftValue+= obj.offsetLeft;
		topValue+= obj.offsetTop;
		obj= obj.offsetParent;
    }
    finalvalue["left"] = leftValue;
	finalvalue["top"] = topValue;
    return finalvalue;
}

function getViewport() {
	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;
	}
	var size = [];
	size["width"] = myWidth;
	size["height"] = myHeight;
	return size;
}

function dutchdate(year,month,day){
	return parseInt(day,10) + " " + getDutchMonth(month) + " " + parseInt(year,10);
}
function getDutchMonth(month){
	var m = "";
	if(parseInt(month,10)==1 || month=="01")		{m = "Januari";}
	else if(parseInt(month,10)==2 || month=="02")	{m = "Februari";}
	else if(parseInt(month,10)==3 || month=="03")	{m = "Maart";}
	else if(parseInt(month,10)==4 || month=="04")	{m = "April";}
	else if(parseInt(month,10)==5 || month=="05")	{m = "Mei";}
	else if(parseInt(month,10)==6 || month=="06")	{m = "Juni";}
	else if(parseInt(month,10)==7 || month=="07")	{m = "Juli";}
	else if(parseInt(month,10)==8 || month=="08")	{m = "Augustus";}
	else if(parseInt(month,10)==9 || month=="09")	{m = "September";}
	else if(parseInt(month,10)==10 || month=="10")	{m = "Oktober";}
	else if(parseInt(month,10)==11 || month=="11")	{m = "November";}
	else if(parseInt(month,10)==12 || month=="12")	{m = "December";}
	else										{m = "Unknown: " + month;}
	return m;
}

function openImageWindow(obj,width,height){
	var href = "";
	
	if(typeof(obj) == "string") href = obj;
	else if(obj.href) href = obj.href;
	else if(obj.src) href = obj.src;
	
    window.open(href,'','width='+width+',height='+height+',resizable=1,scrollbars=1');
}
function openPopupWindow(obj,width){
	window.open(obj.href,'','width='+width+',resizable=1,scrollbars=1');
}

function ouputFriendlyDate(obj){
	var id = obj.id;
	var date = obj.value.split("-");
	document.getElementById("f-calendar-customeroutput"+id).innerHTML = dutchdate(date[0],date[1],date[2]);
}

function hookEvent(element, eventName, callback){
	if(typeof(element) == "string")
		element = document.getElementById(element);
	if(element == null)
		return;
	if(element.addEventListener){
		if(eventName == 'mousewheel')
			element.addEventListener('DOMMouseScroll', callback, false);  
		element.addEventListener(eventName, callback, false);
	}
	else if(element.attachEvent)
		element.attachEvent("on" + eventName, callback);
}

function unhookEvent(element, eventName, callback){
	if(typeof(element) == "string")
		element = document.getElementById(element);
	if(element == null)
		return;
	if(element.removeEventListener){
		if(eventName == 'mousewheel')
			element.removeEventListener('DOMMouseScroll', callback, false);  
		element.removeEventListener(eventName, callback, false);
	}
	else if(element.detachEvent)
		element.detachEvent("on" + eventName, callback);
}

function ScrollElement(e,obj){
	
	e = e ? e : window.event;
	var delta = e.detail ? e.detail * -5 : e.wheelDelta / 5;
	
	if(typeof(obj)=="string") obj = document.getElementById(obj);
	
	if(obj) obj.scrollTop -= delta;
	
	cancelEvent(e);
}

function cancelEvent(e)
{
  e = e ? e : window.event;
  if(e.stopPropagation)
    e.stopPropagation();
  if(e.preventDefault)
    e.preventDefault();
  e.cancelBubble = true;
  e.cancel = true;
  e.returnValue = false;
  return false;
}

