﻿
function ClickingLFC(radioID, tdDateID)
{
    var radio = document.getElementById(radioID);
    if (radio != null && radio.checked == false)
    {
        var tdDate =  document.getElementById(tdDateID);
        if (tdDate != null)
        {
            var table = GetParentObjectByTag(tdDate, 'table');
            if (table != null)
            {
                ClearRadios(table);
                radio.checked = true;
            }
            tdDate.style.border = '1px solid #cc0000';
		    tdDate.style.background = '#ffcccc';
        }
//	    if (!e) e=window.event;
//    	
//	    var sourceElement;
//	    if (e.srcElement) sourceElement = e.srcElement;
//	    else if (e.target) sourceElement = e.target;

//	    var sourceCell = GetParentObjectByTag(sourceElement, 'td');
//	    if (sourceCell != null && (sourceCell.className == 'tdDate' || sourceCell.className == 'tdDateLowestFareClass' ))
//	    {
//		    sourceCell.style.border = '1px solid #cc0000';
//		    sourceCell.style.background = '#ffcccc';
//	    }
	}
}
function ClickingLFC2(radioID, tdDateID)
{
    var radio = document.getElementById(radioID);
    if (radio != null)
    {
        var tdDate =  document.getElementById(tdDateID);
        if (tdDate != null)
        {
            var table = GetParentObjectByTag(tdDate, 'table');
            if (table != null)
            {
                ClearRadios(table);
                radio.checked = true;
            }
            tdDate.style.border = '1px solid #cc0000';
		    tdDate.style.background = '#ffcccc';
        }
	}
}


function EnteringLFC(radioID, tdDateID)
{
    var radio = document.getElementById(radioID);
    if (radio != null && radio.checked == false)
    {
        var tdDate =  document.getElementById(tdDateID);
        if (tdDate != null) {
            $.data(tdDate, 'prevColor', tdDate.style.backgroundColor);

            tdDate.style.border = '1px solid #669933';
            tdDate.style.background = '#ccffcc';

              /*  tdDate.style.border = '1px solid #ffe900';
                tdDate.style.background = '#ffe900';*/
              
          
        }
//	    if (!e) e=window.event;
//    	
//	    var sourceElement;
//	    if (e.srcElement) sourceElement = e.srcElement;
//	    else if (e.target) sourceElement = e.target;

//	    var sourceCell = GetParentObjectByTag(sourceElement, 'td');
//	    if (sourceCell != null && (sourceCell.className == 'tdDate' || sourceCell.className == 'tdDateLowestFareClass' ))
//	    {
//		    sourceCell.style.border = '1px solid #669933';
//		    sourceCell.style.background = '#ccffcc';
//	    }
	}
}

function LeavingLFC(radioID, tdDateID) {
    var radio = document.getElementById(radioID);
    if (radio != null && radio.checked == false) {
        var tdDate = document.getElementById(tdDateID);
        if (tdDate != null) {
            tdDate.style.backgroundColor = $.data(tdDate, 'prevColor');
            /*
            if (tdDate.style.background == '#ccffcc') {
                
                tdDate.style.background = '#ffffff';
            }
            else {
                tdDate.style.border = '1px solid #D2BC02';
                tdDate.style.background = '#FFF9C5';
            }*/

            tdDate.style.border = '1px solid #cccccc';
        }
        else {


        }
        //	    if (!e) e=window.event;
        //    	
        //	    var sourceElement;
        //	    if (e.srcElement) sourceElement = e.srcElement;
        //	    else if (e.target) sourceElement = e.target;

        //	    var sourceCell = GetParentObjectByTag(sourceElement, 'td');
        //	    if (sourceCell != null && (sourceCell.className == 'tdDate' || sourceCell.className == 'tdDateLowestFareClass' ))
        //	    {
        //		    sourceCell.style.border = '1px solid #cccccc';
        //		    sourceCell.style.background = '#ffffff';
        //	    }
    }
}

function GetParentObjectByTag(sourceObject, parentTagName)
{
	parentTagName = parentTagName.toLowerCase();
	
	while (sourceObject.tagName.toLowerCase() != parentTagName)
	{
		sourceObject = sourceObject.parentNode;
		if (sourceObject.tagName.toLowerCase() == 'body')
		{
			break;
		}
	}
	
	if (sourceObject.tagName.toLowerCase() == parentTagName)
	{
		return sourceObject;
	}
	else
	{
		return null;
	}
}

function ClearRadios(table)
{
    var radios = table.getElementsByTagName('input');
    if (radios != null)
    {
        for (var i = 0; i < radios.length; i++)
        {
	        var tdDate = GetParentObjectByTag(radios[i], 'td');
            if (tdDate != null && (tdDate.className == 'tdDate' || tdDate.className == 'tdDateLowestFareClass' )) {

                if ($("#" + tdDate.id).attr("corporate") == "true") {
                    tdDate.style.border = '1px solid #D2BC02';
                    tdDate.style.background = '#FFF9C5';
                }
                else {
                    tdDate.style.border = '1px solid #cccccc';
                    tdDate.style.background = '#ffffff';
                }
            }
        }
    }
}



