// Version of EPiServers Date handler

function onGetDate2(root,obj,title,noTime)
	{
		var ret = null;
		
		try
		{
			ret = window.showModalDialog(root + 'Util/DateBrowser.aspx?value=' + escape(obj.value),'DateBrowser','status:no; resizable:yes; help:no; dialogWidth:240px; dialogHeight:300px; center:yes;scroll:no;');
		
			if(ret!=null)
			{
				obj.value=ret;
				obj.fireEvent("onchange");
			}			
		}
		catch (ex)
		{
			ShowPopupBlockedInfo();
		}
		
		return false;
	}

function ReloadParent()
{
	var xWin=window.dialogArguments;
	//xWin.location.replace(xWin.location);
	xWin.location.reload(true); 
	//alert(xWin.location.href)
}

function fShowModalAndReloadParent(sUrl, vArguments, sFeatures){
	var returnValue = showModalDialog(sUrl, vArguments, sFeatures);
	if(returnValue == 'reload'){
		window.location.reload(true);
	}
}

function Validate(  )
{
	var mode = document.all['SearchMode'].value;
	// var locale = document.all['SearchLocale'].value;// divOffices
	var drplocale = document.all['divOffices'].childNodes[0];
	var locale = drplocale.options[ drplocale.options.selectedIndex ].value;
	var searchtext = document.all['SearchText'].value;
	

	// Validate input
	if( searchtext.length > 0 )
	{
		// Redirect to search
		window.location.href = "/Sites/WM-Data/Booking/search.aspx?search=" + searchtext + "&mode=" + mode + "&locale=" + locale;			
	}
	else
	{			
		alert('Input saknas');
	}				
}

function submitIfEnter()
{
	if( window.event.keyCode == 13 )
	{
		Validate( );
	}
}

var currColor = "";
var glowColor = "#CDFF67";
// tr.BookingListOdd , tr.BookingListEven , tr.BookingListOver
function mouseOverEvenRow( tr , id )
{
	var oDiv = document.getElementById("EventID_" + id );
	
	if( tr.className == 'BookingListEven')
	{
		tr.className = 'BookingListOver';
		if( oDiv != null )
		{
			currColor = oDiv.style.backgroundColor;
			oDiv.style.backgroundColor = glowColor;
		}
	}
	else
	{
		tr.className = 'BookingListEven';
		if( oDiv != null )		
			oDiv.style.backgroundColor = currColor;
	}
}
function mouseOverOddRow( tr , id )
{
	var oDiv = document.getElementById("EventID_" + id );
	
	
	
	if( tr.className == 'BookingListOdd')
	{
		tr.className = 'BookingListOver';
		if( oDiv != null )
		{
			currColor = oDiv.style.backgroundColor;
			oDiv.style.backgroundColor = glowColor;
		}
	}
	else
	{
		tr.className = 'BookingListOdd';
		if( oDiv != null )		
			oDiv.style.backgroundColor = currColor;
	}

}
// tblVisible tblHidden tblTodayEvents tblFutureEvents tblPastEvents
function ShowHideEvents( tblID , id )
{	
	switch( tblID )
	{
		case 'tblTodayEvents':
			document.getElementById(tblID).className = 'tblVisible'; 			
//			document.getElementById('tblFutureEvents').className = 'tblHidden';
//			document.getElementById('tblPastEvents').className = 'tblHidden';		
		break;
		case 'tblFutureEvents':
			document.getElementById(tblID).className = 'tblVisible'; 			
			document.getElementById('tblTodayEvents').className = 'tblHidden';
			document.getElementById('tblPastEvents').className = 'tblHidden';		
		break;
		case 'tblPastEvents':
			document.getElementById(tblID).className = 'tblVisible'; 			
			document.getElementById('tblTodayEvents').className = 'tblHidden';
			document.getElementById('tblFutureEvents').className = 'tblHidden';		
		break;
	}
}


var IsResOn = false;
var InfoDiv;
var InfoToDisplay;
var leftOffset = 15;
var topOffset = 125

var PopupDiv;
var iLeftOffset;
var iTopOffset;
var IsActive = false;

function ShowResInfo2(oDiv,oDivID)
{
	var IE = document.all?true:false;
	
	iLeftOffset = parseInt( oDiv.style.left ,10);
	iTopOffset = parseInt( oDiv.style.top ,10);	
	PopupDiv = document.getElementById( oDivID );//oDiv.children[1];
	if( PopupDiv != null && window.navigator.appVersion.indexOf("MSIE") > 0)
	{
		// Gömmer dropdown för start-/stopptid
/*		document.getElementById('defaultframework_Content2__ctl0_drpStartHour').style.visibility = 'hidden';
		document.getElementById('defaultframework_Content2__ctl0_drpStartMinute').style.visibility = 'hidden';
		document.getElementById('defaultframework_Content2__ctl0_drpStopHour').style.visibility = 'hidden';
		document.getElementById('defaultframework_Content2__ctl0_drpStopMinute').style.visibility = 'hidden';*/
		PopupDiv.style.left = event.clientX + leftOffset;// - iLeftOffset ;
		PopupDiv.style.top = event.clientY + document.documentElement.scrollTop - topOffset;
		PopupDiv.style.display = "block";
		//PopupDiv.style.visibility = "visible";
	}
	else if(PopupDiv != null)
	{
		PopupDiv.style.position = "absolute";
		PopupDiv.style.left = (window.pageYOffset + 400) + "px"; //- iLeftOffset ;
		PopupDiv.style.top = "600px";//- iTopOffset;
		PopupDiv.style.display = "block";
	}
}

function HideResInfo2()
{
	if(PopupDiv != null)
		PopupDiv.style.display = "none";

	if (PopupDiv != null && window.navigator.appVersion.indexOf("MSIE") > 0)
	{		
		// Visa dropdowns för start-/stopptid
/*		document.getElementById('defaultframework_Content2__ctl0_drpStartHour').style.visibility = 'visible';
		document.getElementById('defaultframework_Content2__ctl0_drpStartMinute').style.visibility = 'visible';
		document.getElementById('defaultframework_Content2__ctl0_drpStopHour').style.visibility = 'visible';
		document.getElementById('defaultframework_Content2__ctl0_drpStopMinute').style.visibility = 'visible';*/

		//PopupDiv.style.visibility = "hidden";
	}
		
	IsActive = false;
}

//iMinTopOffset iTimeResolution iGifHeight iLengthMax iOneHourOffset


function ResInfoMove2(oDiv)
{
	//iMinTopOffset = 10;
	//window.status = oDiv.style.height + " --- " + currentY;
	//oDiv.innerHTML = event.clientY + topOffset - iTopOffset;
	//window.status = event.clientY + topOffset - iTopOffset + "----" ;
	oDivHeight = parseInt( oDiv.style.height , 10 );
	oDivTopOffset = parseInt( oDiv.style.top , 10 );
	
	currentY = 100; //event.clientY - oDivHeight /2;
	
	iMaxTopSum = 10;//iMinTopOffset + iLengthMax - 2 * iOneHourOffset - oDivHeight;
	
	iCurrentTopSum = oDivTopOffset + oDivHeight;
	
	//window.status = oDivTopOffset + " --- " + iMaxTopSum + "--" ;
	
	if( IsActive )
	{	
		if( oDivTopOffset > iMaxTopSum )			
			oDiv.style.top = iMaxTopSum;	
		else if( currentY < iMinTopOffset )		
			oDiv.style.top = iMinTopOffset;
		else
			oDiv.style.top = currentY;
			
	}
	
	if( PopupDiv != null && window.navigator.appVersion.indexOf("MSIE") > 0)
	{
		PopupDiv.style.left = event.clientX + leftOffset; //- iLeftOffset ;
		PopupDiv.style.top = event.clientY + document.documentElement.scrollTop - topOffset;
	}
	else if( PopupDiv != null)
	{
		PopupDiv.style.position = "absolute";
		PopupDiv.style.left = "700px"; //- iLeftOffset ;
		PopupDiv.style.top = (window.pageYOffset + 400) +"px";//- iTopOffset;
	}

}
function Activate(oDiv)
{
	// IsActive = true;
	//alert(IsActive);
}
function Deactivate(oDiv)
{
	IsActive = false;
	//confirm('Vill du ändra tid?')
}


// , resType , resName , startHour , startMinute , stopHour , stopMinute , comment
function setControlGUI( id  )
{
	var hidBookingID =  document.getElementById('defaultframework_Content2_hidBookingID');
	
	hidBookingID.value = id;
	document.__aspnetForm.submit();
	
	/*
	
	var drpResType = document.getElementById('defaultframework_Content2_drpResourceType'); 
	var drpResName = document.getElementById('defaultframework_Content2_drpResource');
	var drpStartHour = document.getElementById('defaultframework_Content2_drpStartHour');
	var drpStartMinute = document.getElementById('defaultframework_Content2_drpStartMinute');
	var drpStopHour = document.getElementById('defaultframework_Content2_drpStopHour');
	var drpStopMinute =  document.getElementById('defaultframework_Content2_drpStopMinute');
	var tbComment = document.getElementById('defaultframework_Content2_tbComment');
	var btnEdit = document.getElementById('defaultframework_Content2_btnEdit');
	var btnDelete = document.getElementById('defaultframework_Content2_btnDelete');
	
	// Set resource type
	for( i = 0;i < drpResType.length; i = i + 1 )
	{
		if( resType == drpResType.options[ i ].value )
			drpResType.options[ i ].selected = true;
	}
	
	// Set resource type
	drpResName.disabled = true;
	drpResName.remove(0);
	var oOption = document.createElement("OPTION");
	drpResName.options.add(oOption);
	oOption.innerText = resName;
	oOption.value = resName;
	oOption.selected = true;

	// Set StartHour
	for( i = 0;i < drpStartHour.length; i = i + 1 )
	{
		if( startHour == drpStartHour.options[ i ].value )
			drpStartHour.options[ i ].selected = true;
	}	
	// Set StartMinute
	for( i = 0;i < drpStartMinute.length; i = i + 1 )
	{
		if( startMinute == drpStartMinute.options[ i ].value )
			drpStartMinute.options[ i ].selected = true;
	}	
	// Set StopHour
	for( i = 0;i < drpStopHour.length; i = i + 1 )
	{
		if( stopHour == drpStopHour.options[ i ].value )
			drpStopHour.options[ i ].selected = true;
	}
	// Set StopMinute
	for( i = 0;i < drpStopMinute.length; i = i + 1 )
	{
		if( stopMinute == drpStopMinute.options[ i ].value )
			drpStopMinute.options[ i ].selected = true;
	}
	// Set comment
	tbComment.innerText = comment;
	
	// Set buttons
	btnDelete.disabled = false;
	btnEdit.disabled = false;
	*/

}











