function RedirectTo(url) {
	if (url == -1){
		history.go(-1);
	}
	else if (url == -2){
		history.go(-2);
	}
	else{
		window.location = url;
	}
}

function UpdateSelectBG(mySelect)
{
    mySelect.style.backgroundColor = mySelect.options[mySelect.selectedIndex].style.backgroundColor;
    mySelect.style.color = mySelect.options[mySelect.selectedIndex].style.color;
    mySelect.style.borderColor =  mySelect.options[mySelect.selectedIndex].style.backgroundColor;
}

function isEmpty(aValue, aDefault)
{
	var aEmpty;
	aEmpty = false;
	if (aValue == "" || aValue == aDefault)
	{ aEmpty = true; }   	
	return aEmpty;
}

function isBadEmail(aEmail)
{
   var badEmail;
   var count;
   var pos;
   badEmail = false;
   count	= 0;
   pos		= 0

   <!-- a@b.c should be the shortest an address could be -->
   badEmail = (aEmail.length < 5);

   <!-- chk format has at least one "@" -->
   if (!badEmail && aEmail.indexOf("@") < 0) { badEmail = true; };

   <!-- chk format has only one "@" -->
   if (!badEmail)
   {
		pos		= aEmail.indexOf("@");
		while ( pos != -1 ) {
		   count++;
		   pos = aEmail.indexOf("@",pos+1);
		}
		badEmail = (count > 1);
	}
   
   <!-- chk format  has at least one "." -->
   if (!badEmail && aEmail.indexOf(".") < 0) { badEmail = true; };

   <!-- has no more than 3 chars after last "." -->
   if (!badEmail && (aEmail.length - aEmail.indexOf(".")) > 4) { badEmail = true; };

   return badEmail;
}   


function fieldValidate(aPane)
{
	var isValid;
	isValid = true;
	if (aPane == 2)
	{
		if (isValid && isEmpty(document.getElementById("dlgFirstName").value, "Enter first name."))
		{ alert("Please enter a firstname"); isValid = false; }   	
		if (isValid && isEmpty(document.getElementById("dlgLastName").value, "Enter last name."))
		{ alert("Please enter a lastname"); isValid = false; }   	
		if (isValid && isBadEmail(document.getElementById("dlgEmail").value))
		{ alert("Please enter an email address"); isValid = false; }
	}

	return isValid;
}

function DaysInMonth(month, year){
	var monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	if ((month != 2) || (year % 4 != 0) || ((year % 100 == 0) && (year % 400 != 0))){
		// regular year
		return monthDays[month - 1];
	}
	else{
		// leap year
		return monthDays[month - 1] + 1;
	}
}

function ShowHint() {
	// fill the hint from the title
	if (!this.hint) {
		this.hint = this.title;
		this.title = "";
	}
	// if no hint then return nothing
	if (this.hint == ""){
		return;
	}
	
	//at first time we have to create div for our hint
	if (window.hintcontainer==null) {
		window.hintcontainer = document.createElement("div");
		window.hintcontainer.className = "hint";
		document.body.appendChild(hintcontainer);
	}
	this.onmouseout = HideHint;
	this.onmousemove = MoveHint;
	
	hintcontainer.innerHTML = this.hint;
}

function HintView(link){
	HideHint();
	RedirectTo(link);
}

function PopupHint(element, hint, link){
	// fill the hint from the title
	if (!element.hint) {
		element.hint = hint;
	}
	// if no hint then return nothing
	if (element.hint == ""){
		return;
	}
	
	//at first time we have to create div for our hint
	if (window.hintcontainer==null) {
		window.hintcontainer = document.createElement("div");
		window.hintcontainer.className = "hint";
		document.body.appendChild(hintcontainer);
	}
	if (link != ""){
		hintcontainer.innerHTML = "<div style='width:50%;text-align:left;background-color:FFD;float:left;'> <a href='javascript:HintView(\"" + link + "\");'>View Event</a></div>" +
																						"<div style='width:49%;text-align:right;background-color:FFD;float:left;'><a href='javascript:HideHint()'>Close</a> </div>" +
																						"<div style='clear:both;' onclick='HideHint()'>" + element.hint + "</div>";
	}
	else{
		hintcontainer.innerHTML = "<div style='width:100%;text-align:right;background-color:FFD;float:left;'><a href='javascript:HideHint()'>Close</a> </div>" +
																						"<div style='clear:both;' onclick='HideHint()'>" + element.hint + "</div>";
	}
																						
	if (IsMobile){
		hintcontainer.style.left = ((screen.width / 2) - 100) + "px";
	}
	else{
		hintcontainer.style.left = element.offsetLeft - 100 + "px"
	}
	
	// add together all the offsets
	offsetTopTotal = 0;
	while (element){
		offsetTopTotal += element.offsetTop;
		element = element.offsetParent;
	}
	hintcontainer.style.top = offsetTopTotal - 20 + 'px';
	hintcontainer.style.display = "";
}

function MoveHint(e) {
	var isIE = false;
	if (!e){
		e = window.event;
		isIE = true;
	}
	
	if ((e.clientX + document.documentElement.scrollLeft + 10 + 220) > document.body.clientWidth){
		hintcontainer.style.left = document.body.clientWidth - 220 + "px";
	}
	else{
		hintcontainer.style.left = e.clientX + document.documentElement.scrollLeft + 10 + "px";
	}
	if (e.target) {
		hintcontainer.style.top = e.target.offsetTop + 20 + 'px';
	}
	else {
		// add together all the offsets
		offsetTopTotal = 0;
		element = e.srcElement;
		while (element){
			offsetTopTotal += element.offsetTop;
			element = element.offsetParent;
		}
		hintcontainer.style.top = offsetTopTotal + 20 + 'px';
	}
	if (isIE){
		hintcontainer.style.width = "220px";
	}
	hintcontainer.style.display = "";
}

function HideHint() {
	hintcontainer.style.display = "none";
}

function CheckDates(form){
	var	monthStartDays = DaysInMonth(form.MonthStart.options[form.MonthStart.selectedIndex].value, form.YearStart.options[form.YearStart.selectedIndex].value);
	var monthEndDays = DaysInMonth(form.MonthEnd.options[form.MonthEnd.selectedIndex].value, form.YearEnd.options[form.YearEnd.selectedIndex].value);		

	if (form.DayStart.options[form.DayStart.selectedIndex].value > monthStartDays){
		form.DayStart.selectedIndex = monthStartDays - 1;
	}
	
	if (form.DayEnd.options[form.DayEnd.selectedIndex].value > monthEndDays){
		form.DayEnd.selectedIndex = monthEndDays - 1;
	}
}

function compareOptionText(a,b) {
  /*
   * return >0 if a>b
   *         0 if a=b
   *        <0 if a<b
   */
  // textual comparison
  return a.text!=b.text ? a.text<b.text ? -1 : 1 : 0;
  // numerical comparison
//  return a.text - b.text;
 
}
 
function SortSelectBox(list) {
  var items = list.options.length;
  var selectedItem = list.options[list.selectedIndex].value
  var j;
  
  j = 0;
  
  // create array and make copies of options in list
  var tmpArray = new Array(items);
  for ( i=0; i<items; i++ )
    tmpArray[i] = new
Option(list.options[i].text,list.options[i].value);
  // sort options using given function
  tmpArray.sort(compareOptionText);
  // make copies of sorted options back to list
  for ( i=1; i<items; i++ )
  {		
		if (tmpArray[j].value == "ALL")
		{
			j++;
		}
		
		list.options[i] = new Option(tmpArray[j].text, tmpArray[j].value);
		
		j++;
  }
    
  for (i = 0; i < items; i++)
	{
		if (list.options[i].value == selectedItem)
		{
			list.selectedIndex = i;
			break;
		}
	}
}

//--></script> 
