// JavaScript Document
//Not saved warning
var needToConfirm = false;
function setDirtyFlag() {
	needToConfirm = true; //Call this function if some changes is made to the web page and requires an alert
	// Of-course you could call this is Keypress event of a text box or so...
}
function releaseDirtyFlag() {
	needToConfirm = false; //Call this function if dosent requires an alert.
	//this could be called when save button is clicked 
}
window.onbeforeunload = confirmExit;
function confirmExit() {
	if (needToConfirm)
	return "If you continue, you will leave the event booking system and your event booking may be lost.  To keep your booking, click cancel to close this warning then continue with the booking process. Are you sure you want to exit this page?";
}
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
var popUpWin=0;
var toolTipsControlOn = false;
offsetX = 0;
offsetY = 20;
var toolTipSTYLE="";
function initToolTips()
{
  if(ns4||ns6||ie4)
  {
    if(ns4) toolTipSTYLE = document.toolTipLayer;
    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
    if(ns4) document.captureEvents(Event.MOUSEMOVE);
    else
    {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
    }
    document.onmousemove = moveToMouseLoc;
  }
}
function toolTipToggle()
{
	toolTipsControlOn = !toolTipsControlOn;
	//shutdown();
	if (toolTipsControlOn == true) {
		document.getElementById("printArea").style.cursor = "help";
	} else {
		document.getElementById("printArea").style.cursor = "default";
	}	
}
function toolTip(msg, fg, bg)
{
  if((toolTip.arguments.length < 1)|| (toolTipsControlOn == false)) // hide
  {
    if(ns4) toolTipSTYLE.visibility = "hidden";
    else toolTipSTYLE.display = "none";
  }
  else // show
  {
    if(!fg) fg = "#777777";
    if(!bg) bg = "#FFFFFF";
    var content =
    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + fg + '"><td>' +
    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + bg + 
    '"><td align="center"><font face="sans-serif" color="' + fg +
    '" size="-2">&nbsp\;' + msg +
    '&nbsp\;</font></td></table></td></table>';
    if(ns4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
    if(ie4)
    {
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
    }
  }
}

function mFlip(obj, mClass) {
	obj.className = mClass;
}
function moveToMouseLoc(e)
{
  if(ns4||ns6)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else
  {
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
  }
  toolTipSTYLE.left = x + offsetX;
  toolTipSTYLE.top = y + offsetY;
  return true;
}
/*******************
  Element focus function FUNCTION
********************/
function set_focus(field_id) {
	field_element = document.getElementById(field_id)
	field_element.focus();
}
/*******************
  Find Object FUNCTION
********************/
//cross browser object locator (Macromedia)
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

/*******************
  Tab group functions
********************/
function selectTabGroup(tabId) {
	var cssRules; 
	if (document.all) { 
		cssRules = 'rules'; 
	} else if (document.getElementById) { 
		cssRules = 'cssRules'; 
	} 

	//get class tags to be made visible
	var show_class_tags = new Array();
	var hide_class_tags = new Array();
	for (i = 0; i < tabGroup.length; i++) {
		el_id = document.getElementById('tab'+tabGroup[i].id);
		if (tabGroup[i].id == tabId) {
			show_class_tags = tabGroup[i].showclasses;
			hide_class_tags = tabGroup[i].hideclasses;
			//el_id.className = 'tabItemOn';
			el_id.className = 'selected';
		} else {
			//el_id.className = 'tabItemOff';
			el_id.className = '';
		}
	}
	
	if (show_class_tags.length > 0) {
		for (var S = 0; S < document.styleSheets.length; S++){ 
			for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) { 
				for (var T = 0; T < hide_class_tags.length; T++) { 
					if (document.styleSheets[S][cssRules][R].selectorText == '.'+hide_class_tags[T]) { //needs . in front of name to match
						document.styleSheets[S][cssRules][R].style['visibility'] = 'hidden'; 
						document.styleSheets[S][cssRules][R].style['display'] = 'none'; 
					} 
				}
				for (var T = 0; T < show_class_tags.length; T++) { 
					if (document.styleSheets[S][cssRules][R].selectorText == '.'+show_class_tags[T]) { 
						document.styleSheets[S][cssRules][R].style['visibility'] = 'visible'; 
						document.styleSheets[S][cssRules][R].style['display'] = 'block'; 
					} 
				}
			} 
		}
	}
}
function changecss(theclass,element,value) { 
	//documentation for this script at http://www.shawnolson.net/a/503/ 
	var cssRules; 
	if (document.all) { 
		cssRules = 'rules'; 
	} else if (document.getElementById) { 
		cssRules = 'cssRules'; 
	} 
	for (var S = 0; S < document.styleSheets.length; S++){ 
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) { 
			if (document.styleSheets[S][cssRules][R].selectorText == theclass) { 
				document.styleSheets[S][cssRules][R].style[element] = value; 
			} 
		} 
	} 
} /*******************
  Print Friendly FUNCTIONS
********************/
function printDetail(specialStyle)
{
	print();
}

/*******************
   FORM UTILITIES
********************/
function focusElementById(elemId) {
	var elem = document.getElementById(elemId);
	if (elem) {
		switch (elem.type) {
			case "text":
			case "textarea":
				elem.focus();
				elem.select();
				break;
			case "radio":
				if (elem.name) {
					var radioNames = document.getElementsByName(elem.name);
					radioNames[0].focus();
				}
				break;
			case "checkbox":
				elem.focus();
				break;
			case "select-one":
			case "select-multiple":
				elem.focus();
				break;
		}
	}
}
function elemSetDisplay(controlElem, boundElem, showVal) {
	if(document.getElementById) {
		var src = document.getElementById(controlElem);
		var targ = document.getElementById(boundElem);
		if ((src.value) && (targ) && (showVal)) {
			if (src.value == showVal) {
				elType = targ.tagName.toLowerCase();
				switch (elType) {
				case 'tr':
					try { targ.style.display = 'table-row';	}
					catch(err) { targ.style.display = 'inline';	}
					break;
				case 'table':
					try { targ.style.display = 'table';	}
					catch(err) { targ.style.display = 'inline';	}
					break;
				case 'td':
					try { targ.style.display = 'table-cell';	}
					catch(err) { targ.style.display = 'inline';	}
					break;
				default:
					targ.style.display = 'inline';
				}
				targ.style.visibility = 'visible';
			} else {
				targ.style.visibility = 'hidden';
				targ.style.display = 'none';
			}
		}
	}
}
