var sHiddenElements = '';
var sTagPrefixPH = 'PageHeader1_';
//kng - Military Time Change
var BookRide_TimeSetting = 'C';

function IsIE() {
	var	ie = document.all;
	if (ie) {
		return true;
	}
	else {
		return false;
	}
}
			
function ShowLocalDateTimeString() {
	var dLocal = new Date();
	var sDateTime = '';
	var oLabel = document.getElementById('lblCurrentTime');
	var oTimeSetting = document.getElementById(sTagPrefixPH + 'txtTimeSetting');
	
	var iPos = 0;
	var iLen = 0;
	var sLabel = '';

	if (oTimeSetting.value=='M')
	{
		var hour = dLocal.getHours();

      if (hour < 10)
            hour = '0' + hour;

      var min = dLocal.getMinutes();

      if (min < 10)
            min = '0' + min;

      if (oLabel != null) {

            sDateTime = dLocal.toLocaleString();

            iPos = sDateTime.indexOf(':');

            iLen = sDateTime.length;

            sLabel = sDateTime.substr(0, iPos-2);

            sLabel = sLabel + ' ' + hour + ':' + min

            oLabel.innerHTML = sLabel;

		}
	
	}
	else
	{
	if (oLabel != null) {
		sDateTime = dLocal.toLocaleString();
		iPos = sDateTime.lastIndexOf(':');
		iLen = sDateTime.length;
		
		sLabel = sDateTime.substr(0, iPos);
		if ((iPos + 3) < iLen) {
			sLabel += sDateTime.substr(iPos + 3);
		}
		
		oLabel.innerHTML = sLabel;
	}
	}
}

function SelectMenuTab(sName) {
	var sIndex = '-1';
	var oMenuTop;
	var oMenuCell;
	var oMenuSpan;
	var oMenuLink;

	switch (sName) {
		case 'Dashboard':
			sIndex = '0';
			break;
		case 'BookRide':
			sIndex = '1';
			break;
		case 'UpcomingRides':
			sIndex = '2';
			break;
		case 'PastRides':
			sIndex = '3';
			break;
		case 'Weather':
			sIndex = '4';
			break;
		case 'Traffic':
			sIndex = '5';
			break;
		case 'Profile':
			sIndex = '8';
			break;
	}
	
	if (sIndex != '-1') {
		oMenuTop  = document.getElementById('idMenuTop'  + sIndex);
		oMenuCell = document.getElementById('idMenuCell' + sIndex);
		oMenuSpan = document.getElementById('idMenuSpan' + sIndex);
		oMenuLink = document.getElementById('idMenuLink' + sIndex);
	}
	
	//oMenuTop.className = 'MenuTabSelTop';
	//oMenuCell.className = 'MenuTabSel';
	//oMenuSpan.className = 'MenuTabSel';
	//oMenuLink.className = 'MenuTabSel';
}

function GetAbsoluteLeft(oObject) {
	if (oObject.tagName == 'BODY') return 0;
	else return oObject.offsetLeft + GetAbsoluteLeft(oObject.offsetParent);
}

function GetAbsoluteTop(oObject) {
	if (oObject.tagName == 'BODY') return 0;
	else return oObject.offsetTop + GetAbsoluteTop(oObject.offsetParent);
}
// OLD FUNCTIONS			
/*function ChangeRide(sResNo, sBookingResNo) {
	var sLoc = 'BookRide.aspx?TT=CR&RN=' + sResNo + '&BRN=' + sBookingResNo;
	window.location = sLoc;
}

function CancelRide(sResNo, sBookingResNo) {
	window.location = 'BookRide.aspx?TT=XL&RN=' + sResNo + '&BRN=' + sBookingResNo;
}*/

function ChangeRide(sResNo, sBookingResNo, routeName, mstrId) {
	if (routeName =='')
	{
		var sLoc = 'BookRide.aspx?TT=CR&RID=&MRID=&RN=' + sResNo + '&BRN=' + sBookingResNo;
	}
	else
	{
		var sLoc = 'BookRide.aspx?TT=CR&RID=' + routeName + '&RN=' + sResNo + '&BRN=' + sBookingResNo + '&MRID=' + mstrId;
	}
	window.location = sLoc;
}

function CancelRide(sResNo, sBookingResNo, routeName, mstrId) {
	if (routeName =='')
	{
		window.location = 'BookRide.aspx?TT=XL&RID=&MRID=&RN=' + sResNo + '&BRN=' + sBookingResNo;
	}
	else
	{
		window.location = 'BookRide.aspx?TT=XL&RID=' + routeName + '&RN=' + sResNo + '&BRN=' + sBookingResNo + '&MRID=' + mstrId;
	}
}

function HideOverlappedSelects(oFloatingDiv) {
    var oSelect;
    var i;
    var iSelectTop;
    var iSelectLeft;
    var iSelectWidth;
    var iSelectHeight;
    var aSelects;
    
    if (IsIE()) {
		//alert(oFloatingDiv.id + ': Left=' + oFloatingDiv.offsetLeft + ': Top=' + oFloatingDiv.offsetTop + ', Width=' + oFloatingDiv.offsetWidth + ', Height=' + oFloatingDiv.offsetHeight);

		aSelects = document.getElementsByTagName('SELECT');
		for (i=0; i<aSelects.length; i++) {
			oSelect = aSelects[i];
			if (!oSelect || !oSelect.offsetParent) {
				continue;
			}
	    
			iSelectTop = GetAbsoluteTop(oSelect);
			iSelectLeft = GetAbsoluteLeft(oSelect);
			iSelectWidth = oSelect.offsetWidth;
			iSelectHeight = oSelect.offsetHeight;
			
			//alert(oSelect.id + ': Left=' + iSelectLeft + ': Top=' + iSelectTop + ', Width=' + iSelectWidth + ', Height=' + iSelectHeight);
	    
			if ((oFloatingDiv.offsetLeft + oFloatingDiv.offsetWidth) <= iSelectLeft);
			else if ((oFloatingDiv.offsetTop + oFloatingDiv.offsetHeight) <= iSelectTop);
			else if (oFloatingDiv.offsetTop >= (iSelectTop + iSelectHeight));
			else if (oFloatingDiv.offsetLeft >= (iSelectLeft + iSelectWidth));
			else {
				oSelect.style.visibility = 'hidden';
			}
		}
    }
}
    
function ShowHiddenSelects() {
	var i;
	var oSelect;
	var aSelects;

    if (IsIE()) {
		aSelects = document.getElementsByTagName('SELECT');
		for (i=0; i<aSelects.length; i++) {
			oSelect = aSelects[i];
			if (!oSelect || !oSelect.offsetParent) {
				continue;
			}
			oSelect.style.visibility = '';
		}
    }
}

function SetInputTextValue(sInputID, sValue) {
	var oInput = document.getElementById(sInputID);
	if (oInput != null) {
		oInput.value = sValue;
	}
}

function GetInputTextValue(sInputID) {
	var sValue = '';
	var oInput = document.getElementById(sInputID);
	if (oInput != null) {
		sValue = oInput.value;
	}
	return sValue;
}

function CopyInputTextValue(sFromID, sToID) {
	var sValue = '';
	var oFrom = document.getElementById(sFromID);
	var oTo = document.getElementById(sToID);
	if ((oFrom != null) && (oTo != null)) {
		oTo.value = oFrom.value;
	}
}

function SetInputTextMaxLength(sInputID, sMaxLen) {
	var oInput = document.getElementById(sInputID);
	if (oInput != null) {
		oInput.maxLength = sMaxLen;
	}
}

function SetInputTextReadOnly(sInputID) {
	var oInput = document.getElementById(sInputID);
	if (oInput != null) {
		oInput.readOnly= true;
	}
}

function ResetInputTextReadOnly(sInputID) {
	var oInput = document.getElementById(sInputID);
	if (oInput != null) {
		oInput.readOnly= false;
	}
}

function GetSelectValue(oSelectID) {
	var oSelect = document.getElementById(oSelectID);
	var iIndex = oSelect.selectedIndex;
	var sValue = '';
	if (iIndex > -1) {
		sValue = oSelect.options[oSelect.selectedIndex].value;
	}	
	return sValue;
}

function GetSelectText(oSelectID) {
	var oSelect = document.getElementById(oSelectID);
	var iIndex = oSelect.selectedIndex;
	var sValue = '';
	if (iIndex > -1) {
		sValue = oSelect.options[oSelect.selectedIndex].innerHTML;
	}	
	return sValue;
}

function SetSelectByValue(sSelectID, sValue, iIndex) {
	var oSelect = document.getElementById(sSelectID);
	var i;
	var iSelIndex = 0;
	var sData;
	var aData;
		
	if (oSelect != null) {
		for (i=0; i<oSelect.options.length; i++) {
			if (iIndex >= 0) {
				sData = oSelect.options[i].value;
				aData = sData.split('|');
				if (aData.length > iIndex) {
					if (aData[iIndex] == sValue) {
						iSelIndex = i;
						break;
					}
				}
			}
			else {
				if (oSelect.options[i].value == sValue) {
					iSelIndex = i;
					break;
				}
			}
		}
		oSelect.selectedIndex = iSelIndex;
	}
}


function SetSelectByText(sSelectID, sText) {
	var oSelect = document.getElementById(sSelectID);
	var i;
	var iIndex = 0;
	var sData;
	var aData;
		
	if (oSelect != null) {
		for (i=0; i<oSelect.options.length; i++) {
			if (oSelect.options[i].innerHTML == sText) {
				iIndex = i;
				break;
			}
		}
		oSelect.selectedIndex = iIndex;
	}
}

function SetInputCheckboxValue(sInputID, bValue) {
	var oInput = document.getElementById(sInputID);
	if (oInput != null) {
		oInput.checked = bValue;
	}
}

function GetInputCheckboxValue(sInputID) {
	var oInput = document.getElementById(sInputID);
	if (oInput.checked == true)
		return true;			
	else
		return false;
}

function SetClassName(sTagID, sClassName) {
	var oTag = document.getElementById(sTagID);
	if (oTag != null) {
		oTag.className = sClassName;
	}
}

function SetDisplay(sTagID, sDisplay) {
	var oTag = document.getElementById(sTagID);
	if (oTag != null) {
		oTag.style.display = sDisplay;
	}
}

function SetVisibility(sTagID, sVisibility) {
	var oTag = document.getElementById(sTagID);
	if (oTag != null) {
		oTag.style.visibility = sVisibility;
	}
}

function GetLabelText(sLabelID) {
	var oLabel = document.getElementById(sLabelID);
	var sText = '';
	if (oLabel != null) {
		sText = oLabel.innerHTML;
	}
	return sText;
}

function SetLabelText(sLabelID, sText) {
	var oLabel = document.getElementById(sLabelID);
	if (oLabel != null) {
		oLabel.innerHTML = sText;
	}
}

function GetLocationDesc(sData) {
	var sDesc = '';
	var sData2 = sData + '||||||||||||||||||||||||||||||';
	var aData;
	var sTemp = '';
	
	
	aData = sData2.split('|');
	sType = aData[1];
	if (sType == 'P') {
		sType = aData[2];
	}
	switch (sType) {
		case 'A': 
			sDesc = aData[16] + ': ' + aData[11] + ', ' + aData[12]; 
			break;
		case 'L': 
			sDesc = aData[4] + ', ' + aData[5] + ' ' + aData[6]; 
			sTemp = aData[7];
			if (sTemp.length > 0) {
				sDesc += ', ' + aData[7];
			}
			sDesc += ', ' + aData[11] + ', ' + aData[12]; 
			sTemp = aData[13];
			if (sTemp.length >= 5) {
				sDesc += ' ' + aData[13]; 
			}
			break;
		case 'O': 
			sDesc = aData[5] + ' ' + aData[6] + ', ';
			sTemp = aData[7];
			if (sTemp.length > 0) {
				sDesc += aData[7];
			}
			sDesc += aData[11] + ', ' + aData[12] + ' ' + aData[13]; 
			break;
	}				
	return sDesc;
}

function CCNoInit(sEntryID, sValueID) {
	var oEntry = document.getElementById(sEntryID);
	var oValue = document.getElementById(sValueID);
	oEntry.value = GetCCMaskedValue(oValue.value);
}

function CCNoEntry(oEntry, sValueID) {
	var oValue = document.getElementById(sValueID);
	oEntry.value = oValue.value;
	oEntry.select();
}

function CCNoExit(oEntry, sValueID) {
	var oValue = document.getElementById(sValueID);
	oValue.value = oEntry.value;
	oEntry.value = GetCCMaskedValue(oValue.value);
}

function GetCCMaskedValue(sValue) {
	var sMask = 'xxxxxxxxxxxxxxxxxxxx';
	var iLen = sValue.length;
	var iPos = 0;
	var sEntry = '';

	if (iLen > 4) {
		iPos = iLen - 4;
		sEntry = sMask.substr(0, iPos) + sValue.substr(iPos, 4);
	} 
	else {
		sEntry = sValue;
	}
	return sEntry;
}

function BookRide() {
	window.location = 'BookRide.aspx';
}

function EditProfile() {
	window.location = 'EditProfile.aspx';
}

function ShowCVVHelp() {
	var sMsg = '';

	sMsg = 'What is Security Code (CVV)?\r';
	sMsg += 'CVV is a card verification system that verifies that a\r';
	sMsg += 'cardholder is in possession of a credit card by verifying\r';
	sMsg += 'a set of numbers that is printed or embossed on the credit\r';
	sMsg += 'card and not encoded in the magnetic strip. This way even\r';
	sMsg += 'if the card number is stolen, a transaction cannot be\r';
	sMsg += 'processed if the purchaser cannot verify the CVV number on\r';
	sMsg += 'the card.\r';
	sMsg += '\rWhere to find CVV?\r';
	sMsg += 'Each card issuer has a different name for the CVV system,\r';
	sMsg += 'but all are essentially the same thing.  Visa refers to it\r';
	sMsg += 'as CVV2, Mastercard as CVC2 and Amex as CID. For most cards,\r';
	sMsg += 'the CVV number is the last 3 digits in the signature panel\r';
	sMsg += 'on the back of the card. Amex uses a 4-digit code on the front\r';
	sMsg += 'of the card above the card number.';
	
	alert(sMsg);
}

function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
	 }
   return IsNumber;   
}

// kng added for setting stylesheet path
function setStyleSheetPath(path)
{
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1	&& a.getAttribute("href"))
		{
			a.href = path + a.href;
		}
	}
}
