﻿// changes the background color of the control to yellow
function ChangeBackgroundColor(controlID){
    if(querySt("Action") == "Edit")
    {
        document.getElementById(controlID).style.backgroundColor = "#FFFF00";
    }
}

function ChangeCss(controlID,className)
{
        document.getElementById(controlID).setAttribute("class",className);
        document.getElementById(controlID).setAttribute("className",className);
}

function TogglePassengers(controlID, idx)
{
    var obj = document.getElementById(controlID);
    var passlbl = document.getElementById("passlabel").firstChild;
    var passtxt = document.getElementById("passtxt").firstChild;
    var van = new RegExp("Van");
    var bus = new RegExp("Bus");
    var selectedText = obj[idx].text;
    if(selectedText.match(van) || selectedText.match(bus))
    {
        passlbl.style.display = 'block';
        passtxt.style.display = 'block';
    }
    else
    {
        passlbl.style.display = 'none';
        passtxt.style.display = 'none';
        passtxt.value = "";
    }
    ChangeBackgroundColor(controlID);
}
function ToggleFields(controlID, idx)
{
    var obj = document.getElementById(controlID);
    var tgllbl = document.getElementById("togglelabel").firstChild;
    var tgltxt = document.getElementById("toggletxt").firstChild;
    var school = new RegExp("School");
    var selectedText = obj[idx].text;
    if(selectedText.match(school))
    {
        tgllbl.style.display = 'block';
        tgltxt.style.display = 'block';
    }
    else
    {
        tgllbl.style.display = 'none';
        tgltxt.style.display = 'none';
        tgltxt.value = "";
    }
    ChangeBackgroundColor(obj.id);
}
function ToggleDate(controlID, selectedIndex)
{
    var label = document.getElementById("toggleLabel").firstChild;
    var datefield = document.getElementById("toggleDate").firstChild;
    var btnCal = document.getElementById("toggleCalendar").firstChild;
    var spacer = document.getElementById("spacer");
    if(selectedIndex)
    {   
        label.style.display = 'block';
        datefield.style.display = 'block';
        btnCal.style.display  = 'block';
        spacer.style.display = 'block';
    }
    else
    {
        label.style.display = 'none';
        datefield.style.display = 'none';
        btnCal.style.display  = 'none';
        spacer.style.display = 'none';
    }
}
function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
    ft = gy[i].split("=");
    if (ft[0] == ji) {
    return ft[1];
}
}
}

var typeAheadInfo =
{
    last:0,
    currentString:"",
    delay:1000,
    timeout:null,
    reset:function()
    {
        this.last=0; this.currentString="";
    }
};  

function typeAhead()
{
    if (window.event && !window.event.ctrlKey)
    {
        var now = new Date();
        if ((now - typeAheadInfo.last < typeAheadInfo.delay) || typeAheadInfo.currentString == "")
        {
            var myEvent = window.event;
            var selectElement = myEvent.srcElement;
            var keyCode = myEvent.keyCode;
  
            // The NumPad returns slightly differant keyCodes then the numbers on the type of the keyboard.  
            // If we subtract 48 it will return the correct keyCode.  
            if (keyCode >= 96 && keyCode <=105)
            {
                keyCode = keyCode - 48;
            }
  
            var newChar = String.fromCharCode(keyCode).toUpperCase();
            typeAheadInfo.currentString += newChar;
            
            var selectOptions = selectElement.options;         
            var txt, nearest;
            
            for(var i = 0; i < selectOptions.length; i++)
            {
                // compare if the selectElement.options[i].value contains the typeAheadInfo.currentString
                // if it does set selected index to that element otherwise check next element
                txt = selectOptions[i].value.toUpperCase();  
                nearest = (typeAheadInfo.currentString > txt.substr(0, typeAheadInfo.currentString.length)) ? i : nearest;  
                if (txt.indexOf(typeAheadInfo.currentString) == 0)
                {
                    clearTimeout(typeAheadInfo.timeout);
                    typeAheadInfo.last = now;
                    typeAheadInfo.timeout = setTimeout("typeAheadInfo.reset()", typeAheadInfo.delay);
                    selectElement.selectedIndex = i;
                    myEvent.cancelBubble = true;  
                    myEvent.returnValue = false;
                    return false;
                }
            }
            if (nearest != null)
            {
                selectElement.selectedIndex = nearest;
            }
        }
        else
        {
            clearTimeout(typeAheadInfo.timeout);
        }
        typeAheadInfo.reset();
    }
    return true;
}

//////////////////////////////////////////////////////////////////
// qTip - CSS Tool Tips - by Craig Erskine
// http://qrayg.com
//
// Multi-tag support by James Crooke
// http://www.cj-design.com
//
// Inspired by code from Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
//////////////////////////////////////////////////////////////////

var qTipTag = "ToolTips"; //Which tag do you want to qTip-ize? Keep it lowercase!//
var qTipX = 0;  //This is qTip's X offset//
var qTipY = 15; //This is qTip's Y offset//

//There's No need to edit anything below this line//
tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null
}

tooltip.init = function () {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "qTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

	var a, sTitle, elements;
	
	var elementList = qTipTag.split(",");
	for(var j = 0; j < elementList.length; j++)
	{	
	
		/*elements = document.getElementsByTagName(elementList[j]);*/
		elements = document.getElementsByName(qTipTag);
		if(elements)
		{
			for (var i = 0; i < elements.length; i ++)
			{
				a = elements[i];
				sTitle = a.getAttribute("title");				
				if(sTitle)
				{
					a.setAttribute("tiptitle", sTitle);
					a.removeAttribute("title");
					a.removeAttribute("alt");
					a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
					a.onmouseout = function() {tooltip.hide()};
				}
			}
		}
	}
}

tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {//IE
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
	}
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
}

tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	this.tip.style.display = "block";
}

tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}

window.onload = function () {
	tooltip.init ();
}
function ClickOnceClicked(controlID)
{
   if (typeof(ValidatorOnSubmit) == 'function' && !ValidatorOnSubmit())
       return ValidatorOnSubmit();
   else 
   { 
       var myCtl = document.getElementById(controlID); 
       myCtl.disabled = true;
   }
}
function valueChangeInEdit(oEdit, oldValue, oEvent) 
{
    if(oEdit.value != oldValue) ChangeBackgroundColor(oEdit.elem.id);
} 
