function CheckValue(iTypeChecked) {
    var CurrentOriginName = getEl(oOrigin).options[getEl(oOrigin).selectedIndex].text.toLowerCase();
    var CurrentDestinationName = getEl(oDestination).options[getEl(oDestination).selectedIndex].text.toLowerCase();
    if (!isnull(CurrentOriginName) && !isnull(CurrentDestinationName)) {
        if ((CurrentOriginName == CurrentDestinationName) || (CurrentOriginName == "0" || CurrentDestinationName == "0")) {
            NotPrice();
            return false;
        }
        else {
            BuildPriceTables();
        }
    }
} //CheckValue(oObj,iType)


function returnOperation(iPrivate, iOneWay) {
    var sResult;

    if (iPrivate == "1" && iOneWay == "0") {
        sResult = "1";
    }
    else if (iPrivate == "0" && iOneWay == "0") {
        sResult = "2";
    }
    else if (iPrivate == "1" && iOneWay == "1") {
        sResult = "3";
    }
    else if (iPrivate == "0" && iOneWay == "1") {
        sResult = "4";
    }
    if (isNaN(sResult)) {
        sResult = 0;
    }
    return sResult;
    /*
    1 Round Trip Private
    2 Round Trip Sahred
    3 One Way Private
    4 One Way Shared
    return sResult;
    */
} //end function returnOperation

function createXMLDoc() {
    if (window.XMLHttpRequest) {
        var request = new XMLHttpRequest();
        request.open("GET", "xml/price.xml", false);
        request.send(null);
        return request.responseXML;

    } else if (window.ActiveXObject) {
        var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
        xmldoc.async = false;
        xmldoc.load("Xml/price.xml");
        return xmldoc;
    }
    return null;
} //end function createXMLDoc


function CheckForm() {
    hideAllErrors();
    if (isnull(getEl(oCurrentPrice).value) || getEl(oCurrentPrice).value <= "0") {
        ShowError(20);
        return false;
    }

    var iOrigin = getEl(oOrigin).value;
    var iDestination = getEl(oDestination).value;
    var iOneWay = getEl(oOneWay).checked == true ? 1 : 0;
    var iTypeTrip = getEl("hType").value == "sh" ? 0 : 1;
    var iType = returnOperation(iTypeTrip, iOneWay);
    if (iOrigin > 0 && iDestination > 0 && iType > 0) {
        getEl(oXPath).value = "d" + iOrigin + "d" + iDestination + "d" + iType;
        document.forms[0].submit();
    }
} //end function CheckForm


function BuildPriceTables() {
    hideAllErrors();
    CleanPriceTables();
    var iOrigin = getEl(oOrigin).value;
    var iDestination = getEl(oDestination).value;

    if (isnull(iOrigin) || iOrigin == "0" || isnull(iDestination) || iDestination == "0") {
        ShowError(21);
        CleanPriceTables();
        return false;
    }
    else {
        var iOneWay = getEl(oOneWay).checked == true ? 1 : 0;
        var iType = returnOperation(0, iOneWay);
        BuildPriceTable('sh', iOrigin, iDestination, iOneWay, iType);
        iType = returnOperation(1, iOneWay);
        BuildPriceTable('pr', iOrigin, iDestination, iOneWay, iType);
        var sOrigin = getEl(oOrigin).options[getEl(oOrigin).selectedIndex].text;
        var sDestination = getEl(oDestination).options[getEl(oDestination).selectedIndex].text;
        getEl('prTitle').innerHTML = sOrigin + ' >> ' + sDestination;
        getEl('shTitle').innerHTML = sOrigin + ' >> ' + sDestination;
        if (iOneWay) {
            getEl('spTitleRound').innerHTML = "(One way)";
            getEl('spTitleRound2').innerHTML = "(One way)";
        }
        else {
            getEl('spTitleRound').innerHTML = "(And back)";
            getEl('spTitleRound2').innerHTML = "(And back)";
        }
    }
} //end function BuildPriceTables


function CleanStylePassengersTables() {
    var i;
    var x = 0;
    for (i = 2; i <= 20; i++) {
        x = i + 20;

        if (!isnull(getEl('p' + i))) {
            getEl('p' + i).className = "none";
        }
        if (!isnull(getEl('p' + x))) {

            getEl('p' + x).style.color = "white";
        }
    }
} //end function CleanStylePassengersTables

function CleanSelects(sType) {
//    getEl(sType + "9").innerHTML = "";
//    getEl("d" + sType).value = "";
    //    getEl("h" + sType + "9").value = "0";

} //end function CleanSelects
function CleanPriceTable(sType) {
    for (i = 1; i < 10; i++) {
        if (!isnull(getEl(sType + i))) {
            getEl(sType + i).innerHTML = "";
        }
    }
    CleanSelects(sType);
} //end function CleanPriceTable

function CleanRadioButtons() {
    for (i = 0; i < document.getElementsByName('radio').length; i++) {
        document.getElementsByName('radio')[i].checked = false;
    }
} //end function CleanRadioButtons

function SetLastActive(iValue) {
    getEl("hSelect").value = iValue;
} // end function SetLastActive



function PrintPrice(iPrice) {
    getEl('euroPrice').innerHTML = iPrice + " " + "&euro;";
    getEl(oCurrentPrice).value = iPrice;
} // end function PrintPrice

function NotPrice() {
    hideAllErrors();
    ShowError(22);
    if (getEl("hSelect").value == "1") {
        getEl(oOrigin).value = "0";
    }
    else {
        getEl(oDestination).value = "0";
    }
    getEl(oCurrentPrice).value = "0";
    getEl(oCurrentDiscount).value = "0";
    getEl(oPassengers).value = "0";
    getEl(oXPath).value = "";
    CleanPriceTables();
    //    getEl("euroPrice").innerHTML = "0 &euro;";
} //end function NotPrice

