/* Copyright � 2000-2006 Dennis Bekkering 
 * Comeniusstraat 61 
 * 1065 BH Amsterdam 
 * The Netherlands. 
 * All rights reserved 
 */

function appointmentDataOver(appointmentData,xevent){
	if(window.currentAppointmentData){
		window.currentAppointmentData.style.border='1px solid black';
	}
	appointmentData.style.border='3px solid #DDffDD';


	showAppointmentTooltip(xevent);
}

function showAppointmentTooltip(xevent){

	var appointmentToolTip = get('appointmentToolTip');

	
	
	appointmentToolTip.style.top=xevent.srcElement.offsetTop; 
	if(xevent.srcElement.offsetLeft < 310){
		appointmentToolTip.style.left=xevent.srcElement.offsetLeft + xevent.srcElement.offsetWidth;
	}
	else{
		appointmentToolTip.style.left=xevent.srcElement.offsetLeft - 220;
	}
	
	
	//appointmentToolTip.style.borderTop='3px solid #000033';
	appointmentToolTip.style.borderLeft='';
	appointmentToolTip.style.background='#ffffdd';		
	appointmentToolTip.style.padding=3;
	appointmentToolTip.style.visibility='visible'; 
	appointmentToolTip.style.width='220';				
	appointmentToolTip.innerHTML
	='<i>'+ xevent.srcElement.getAttribute("simpleDateString") +'</i> '+
	 xevent.srcElement.getAttribute("timeString") +'  <br>'
	+xevent.srcElement.getAttribute("shortDescription")+' ';		



}
function appointmentDataOut(appointmentData){
	hideAppointmentTooltip();
	appointmentData.style.border='1px solid black';
	
}


function hideAppointmentTooltip(){
	var appointmentToolTip = get('appointmentToolTip');
	if(appointmentToolTip ){
		appointmentToolTip.style.visibility='hidden'; 
	}
}

function appointmentDataHolderMove(appointmentDataHolder,event){


	var no =  getNoX(20 , appointmentDataHolder,event);
	var hourNo = getNoY(14 , appointmentDataHolder,event);
	no++;	
	hourNo+=3;

	if( event.srcElement.className != 'appointmentDataHolder' 
		&& event.srcElement.className != 'messageDataHolder' ){
		
		if (window.currentDayNo){
			
			
			if(window.currentDayNo.getAttribute('normalBackground')){
				window.currentDayNo.style.background =  "#" + window.currentDayNo.getAttribute('normalBackground');
			}

			if(window.currentDayNo.getAttribute('normalColor')){
				window.currentDayNo.style.color =  "#" + window.currentDayNo.getAttribute('normalColor');
			}
			window.currentDayNo='';
			window.curDayNoInt ='';
		}
		if (window.currentHourNo){

			if(window.currentHourNo.getAttribute('normalBackground')=='none'){
				window.currentHourNo.style.background='';
			}
			else{
				window.currentHourNo.style.background='#'+window.currentHourNo.getAttribute('normalBackground');			
			}
			if(window.currentHourNo.getAttribute('normalColor')=='none'){
				window.currentHourNo.style.color='';
			}
			else{
				window.currentHourNo.style.color='#'+window.currentHourNo.getAttribute('normalColor');			
			}

			window.currentHourNo='';
			window.curHourNoInt='';
		}
		
		return;
	}
	

	
	if (!window.curDayNoInt || window.curDayNoInt != no  ){
		doDayNo(no);
	}
	if(!window.curHourNoInt || window.curHourNoInt != hourNo){
		doHourNo(hourNo);	
	}
	
	window.curDayNoInt = no;
	window.curHourNoInt = hourNo;
}

function getNoX(scale,e,event){
	var node = e;
	return Math.round( (event.offsetX - 10 ) / scale )  ;	
}
function getNoY(scale,e,event){
	var node = e;
	return Math.round( (event.offsetY  - 50) / scale )  ;	
}

function doDayNo(no){
	if (window.currentDayNo){
		
		
		if(window.currentDayNo.getAttribute('normalBackground')){
		window.currentDayNo.style.background =  "#" + window.currentDayNo.getAttribute('normalBackground');
		}

		if(window.currentDayNo.getAttribute('normalColor')){
			window.currentDayNo.style.color =  "#" + window.currentDayNo.getAttribute('normalColor');
		}
	}
	var dayNo = get('day' + no);
	if (dayNo){
		if(dayNo.getAttribute('activeBackground')=="none"){
			dayNo.style.background =  "";
		}
		else if(dayNo.getAttribute('activeBackground') ){

			dayNo.style.background =  "#" + dayNo.getAttribute('activeBackground');
		}
		if(dayNo.getAttribute('activeColor')){
				dayNo.style.color =  "#" + dayNo.getAttribute('activeColor');
		}
		window.currentDayNo = dayNo;
		if (window.currentHourNo)
		{

		}
	}
}
function doHourNo( hourNo ){




	var hourNoEl = get('hourDisplay').getElementsByTagName('DIV')[hourNo];

	if (window.currentHourNo){
		window.currentHourNo.style.background='';
		if(window.currentHourNo.getAttribute('normalBackground')=='none'){
			window.currentHourNo.style.background='';
		}
		else{
			window.currentHourNo.style.background='#'+window.currentHourNo.getAttribute('normalBackground');			
		}
		if(window.currentHourNo.getAttribute('normalColor')=='none'){
			
			window.currentHourNo.style.color='';
		}
		else{
			window.currentHourNo.style.color='#'+window.currentHourNo.getAttribute('normalColor');			
		}
	}

	if (hourNoEl){
	

		if(hourNoEl.getAttribute('activeBackground')=='none'){
			hourNoEl.style.background='';
		}
		else if(hourNoEl.getAttribute('activeBackground')){
			hourNoEl.style.background='#'+hourNoEl.getAttribute('activeBackground');			
		}
		if(hourNoEl.getAttribute('activeColor')=='none'){
			hourNoEl.style.color='';
		}
		else if(hourNoEl.getAttribute('activeColor')){
			hourNoEl.style.color='#'+hourNoEl.getAttribute('activeColor');			
		}
	
	
		
		

		
		window.currentHourNo= hourNoEl;

		if (window.currentDayNo)
		{
			
		}
	}
}


function appointmentDataHolderClick(appointmentDataHolder,event){
	if( event.srcElement.className == 'appointmentDataHolder' ){
		var no =  getNoX(20 , appointmentDataHolder,event);
		var hourNo = getNoY(14 , appointmentDataHolder,event);
		no++;	
		hourNo +=3;
		

		appointmentDataHolder.setAttribute('startHour', hourNo);
		appointmentDataHolder.setAttribute('startDay' ,  no);
		sendComponentValuesDynamic( appointmentDataHolder , 'startHour' , 'startDay' );
	}
	else{
		//alert('not new');
	}
	return;
	
	if(event.srcElement.className == 'chooseHour'){
		return;
	}

	if(!appointmentDataHolder.state){
		zoomDay(appointmentDataHolder);
		return;
	}
	posMinuteChooser();	
}

function messageDataHolderClick(e,event) {
	if(messageDataHolder.editMode) {
		appointmentDataHolderMove(e,event);
		//return;
	}
	if( event.srcElement.className == 'messageDataHolder' ){
		var no =  getNoX(20 , e,event);
		var hourNo = getNoY(14 , e,event);
		no++;	
		hourNo +=3;
		
		e.getElementsByTagName('INPUT')[0].setAttribute('pstartHour', hourNo);
		e.getElementsByTagName('INPUT')[0].setAttribute('pstartDay' , no);
		sendComponentValuesDynamic( e.getElementsByTagName('INPUT')[0] , 'startHour' , 'startDay' );
		e.editMode = 1;
		
		
		
	}
	else{
		//alert('not new');
	}
	return;
}

function messageDataHolderMove(messageDataHolder,event) {

	
	if(messageDataHolder.editMode ) {
		//appointmentDataHolderMove(messageDataHolder,event);
		return;
	}
	appointmentDataHolderMove( messageDataHolder,event );
	if(!window.currentDayNo || !window.currentHourNo) {
		//appointmentDataHolderMove(messageDataHolder,event);
		return;
	}
	
	var messsageCalendarInfo = get('messsageCalendarInfo');
	
	//messsageCalendarInfo.style.display='block';
	messsageCalendarInfo.innerHTML  = (window.currentDayNo.innerHTML < 10 ? '0' + window.currentDayNo.innerHTML : window.currentDayNo.innerHTML )+ ' '
	 + messsageCalendarInfo.getAttribute('month') + ' ' + window.currentHourNo.innerHTML + ' uur' ;
	//messsageCalendarInfo.style.top  = window.currentHourNo.style.top;
	//messsageCalendarInfo.style.left = window.currentDayNo.style.left;
	
}

function messageDataOver(e,xevent){
	
	if(	get('messageDataHolder').editMode){
		return;
	}


	searchComponent(e.getAttribute('dataViewId')).style.display='block';
	e.style.border='1px solid '+ e.getAttribute('activeBorderColor');
	var messsageCalendarInfo = get('messsageCalendarInfo');
	
	//messsageCalendarInfo.style.display='block';
	
	messsageCalendarInfo.innerHTML  = e.getAttribute('dayNo')  + ' '
	 + messsageCalendarInfo.getAttribute('month') + ' ' + e.getAttribute('hourFrom') + '.00 uur' ;	
	
	

	
//	addMessage( window.currentHourNo );
	
		if (window.currentDayNo){
			
			if(window.currentDayNo.getAttribute('normalBackground')){
				window.currentDayNo.style.background =  "#" + window.currentDayNo.getAttribute('normalBackground');
			}
			if(window.currentDayNo.getAttribute('normalColor')){
				window.currentDayNo.style.color =  "#" + window.currentDayNo.getAttribute('normalColor');
			}
			
			
			window.currentDayNo='';
			window.curDayNoInt ='';
		}
		if (window.currentHourNo){

			

			if(window.currentHourNo.getAttribute('normalBackground')=='none'){
				window.currentHourNo.style.background='';
			}
			else{
				window.currentHourNo.style.background='#'+window.currentHourNo.getAttribute('normalBackground');			
			}
			if(window.currentHourNo.getAttribute('normalColor')=='none'){
				window.currentHourNo.style.color='';
			}
			else{
				window.currentHourNo.style.color='#'+window.currentHourNo.getAttribute('normalColor');			
			}

			window.currentHourNo='';
			window.curHourNoInt='';
		}


//	var no =  getNoX(20 , appointmentDataHolder,event);
//	var hourNo = getNoY(14 , appointmentDataHolder,event);

//	doHourNo( hourNo );
//	doDayNo( no );
	
//	messsageCalendarInfo.innerHTML  = e.getAttribute('simpleDateString');

}

function messageDataClick(e,xevent){
	if(e.parentNode.click){
		e.parentNode.click();
	}
	else{
		e.parentNode.onclick();
	}
}

function messageDataOut(e,xevent){
	searchComponent(e.getAttribute('dataViewId')).style.display='none';
	e.style.border='';
}

function messageDataHolderEditModeLoad(e,xevent){
	get('messageDataHolder').editMode='';
}
