﻿var targetTextBox;

function RegisterTargetControl(element) {
    targetTextBox = element;
}

function GetTargetControl() {
    return targetTextBox;
}

function ClosePicker() {

    targetTextBox = null;

    var mydiv = $get('AirportPickerWizard');

    mydiv.style.display = 'none';
}

function SetCoordinates(targetControl, targetdiv) {

    var offset = $(targetControl).offset();
    
    var topOffset = offset.top;
    
    var leftOffset = offset.left - targetControl.offsetLeft;
    
    if (navigator.appName == "Microsoft Internet Explorer") {
        if (navigator.appVersion.indexOf('7.0') > 0) {
            targetdiv.style.top = topOffset + 18;

            targetdiv.style.left = leftOffset;
        }
        else {
            targetdiv.style.top = topOffset + 8;

            targetdiv.style.left = leftOffset;
        }      
    }
    else {

        targetdiv.style.top = topOffset + 12 + "px";

        targetdiv.style.left = leftOffset + "px";
    }
}

function TogglePicker(clientid) {
    //get wizard div
    var mydiv = $get('AirportPickerWizard');

    //if div is open
    if (mydiv.style.display == '') {
        //get target textbox
        var targetControl = $get(clientid);

        //if picker is opened on same target control, picker must close
        if (targetTextBox == targetControl) {
            //close picker
            ClosePicker();
        }
        //if picker is opened on different target control, picker must change target control and must move to target control
        else {
            //register target control
            RegisterTargetControl(targetControl);

            //set picker position
            SetCoordinates(targetControl, mydiv);
        }
    }
    else {
        //get target textbox
        var targetControl = $get(clientid);

        //register target control
        RegisterTargetControl(targetControl);

        //set picker position
        SetCoordinates(targetControl, mydiv);

        //open picker
        mydiv.style.display = '';
    }

    return false;
}
