




// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false;

/**
 * TEMPORARY STORAGE VARIABLES, needed as callMetaData does not pass variables to the callback functions
 */
var takenText;
var availableText;

if(window.Event) 
{
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = getCursorXY;

function getCursorXY(e) {
	if(document.getElementById('cursorX') != null && document.getElementById('cursorY').value != null){
		document.getElementById('cursorX').value = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		document.getElementById('cursorY').value = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	}
}

function  randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 10;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function showHelpText(name, text, elementOfOnMouseOver, posX, posY)
{
	var divHelp = document.getElementById('divHelp_' + name);
	//alert("x: " + document.getElementById('cursorX').value + ", y: " + document.getElementById('cursorY').value);
	
	//divHelp.style.top = ;
	//divHelp.style.left = (document.getElementById('cursorX').value - 100) + "px";
	
	var posXcoord = null;
	var posYcoord = null;
	
	if(posX)
	{
		posXcoord = parseInt(posX);	
	}
	else
	{
		posXcoord = document.getElementById('cursorX').value - 175;
	}
	if(posY)
	{
		posYcoord = parseInt(posY);	
	}
	else
	{
		posYcoord = document.getElementById('cursorY').value - 125;
	}
	divHelp.style.top = posYcoord + "px";
	divHelp.style.left = posXcoord + "px";

	divHelp.style.position = "absolute";
	divHelp.style.visibility = "visible";
	divHelp.style.display = "block";
	
	var divHelpText = document.getElementById('divHelpText');
	divHelpText.style.visibility = "visible";
	divHelpText.style.display = "block";
	divHelpText.innerHTML = text;
}


/***
 * Hides the helptext bubble, usually onmouseout
 * @param text
 * @return
 */
function hideHelpText(name)
{
	var divHelp = document.getElementById('divHelp_' + name);
	divHelp.style.visibility = "hidden";
	divHelp.style.display = "none";
	
	var divHelpText = document.getElementById('divHelpText');
	divHelpText.style.visibility = "hidden";
	divHelpText.style.display = "none";
}	

function getMouseXY(e) 
{
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0;}
  if (tempY > 0){tempY = 0;}  
  return true;
}

function hasAgreedToTC()
{
	var cbTC = document.getElementById('cbTC');
	if(!cbTC.checked)
	{
		alert('You have to agree to the T&C\'s');
		return false;
	}
	return true;
}

function showHideSubmit()
{
	var showHideSubmitElement = document.getElementById("showHideSubmit");
	showHideSubmitElement.display = "none";
	showHideSubmitElement.style.visibility = "hidden";		

	var submitTextElement = document.getElementById("submitText");
	submitTextElement.style.visibility = "visible";
	
	return true;
}

var sessionDayRenderer = function(workingDate, cell) 
{
	var date = new Date(); 
	var difference = date - workingDate;
	var days = Math.round(difference / (1000*60*60*24));

	//we need to remove the "today"-style from the calendar to display booked sessions today
	if(days == 0)
	{
		YAHOO.util.Dom.removeClass(cell, "today");
	}
   	YAHOO.util.Dom.addClass(cell, "sessionDay");
}

var multipleBookingsDayRenderer = function(workingDate, cell) { 
	YAHOO.util.Dom.addClass(cell, "multipleBookingsDay");
};

var holidayRenderer = function(workingDate, cell) { 
   	YAHOO.util.Dom.addClass(cell, "calendarHoliday");
}

var availableDayRenderer = function(workingDate, cell) { 
	//YAHOO.util.Dom.addClass(cell, "availableDay");
}
    
function selectHandler(type, args, obj) {
	var selected = new String(args[0]);
	selected = selected.replace(/,/g, "/");
	window.location.href = "/student/sessionsRedirect.html?date=" + selected;
};
  
var weekendsStop = function(workingDate, cell) { 
	YAHOO.util.Dom.addClass(cell, "calendarWeekend");
  	return null; 
} 
	    
function selectHandlerAdmin(type, args, obj) 
{
	var filter = '';
	var selected = args[0];
	
	if(filter == "compras_new")
	{
		window.location.href = "/admin/tienda/list.html?date=" + selected;
	}
	else
	{	
		window.location.href = "/admin/students/sessions.html?date=" + selected;
	}				
};
			
var monthChangeNavigationHandler = function(type,args,obj) 
{
       var nextMonthDate = new Date(args[1]);
       var year = nextMonthDate.getFullYear();
       var month = nextMonthDate.getMonth() + 1;
       var day = nextMonthDate.getDay() + 1;
       var dateString = month + "/" + day + "/" + year;
       
       window.location.href = "/admin/index.html?date=" + dateString;
   	
};
			
function markWallPostRead(which)
{
	var readDate = new Date();
	WallService.markRead(which, readDate, callbackMarkWallPostRead);
	var deleteDiv = document.getElementById("wallPost" + which);
	var parent = deleteDiv.parentNode;
	parent.removeChild(deleteDiv);
}

function callbackMarkWallPostRead(data) 
{
	
}
