﻿function maintainRadioButtonGroupFunctioning(checkBox){
    var groupName = checkBox.name.substring(checkBox.name.lastIndexOf("$") + 1);
    //alert(groupName);
    var inputs = document.getElementsByTagName("input");
    for(var i = 0; i < inputs.length; i++){
        //alert(inputs[i].type);
        if(inputs[i].type == "radio"){
            //alert(inputs[i].name.substring(inputs[i].name.lastIndexOf("$") + 1));
            if(inputs[i].name.substring(inputs[i].name.lastIndexOf("$") + 1) == groupName){
                if(inputs[i].name != checkBox.name){
                    inputs[i].checked = false;
                }
            }
        }
    }
    return true;
}

function tripPassengersAssignSelectAll(checkBox){
    var id = checkBox.id;
    var prefix = id.substring(0, id.indexOf("cbSelectAll"));
    
    var inputs = document.getElementsByTagName("input");
    for(var i = 0; i < inputs.length; i++){
        //alert(inputs[i].type);
        if(inputs[i].type == "checkbox"){
            //alert(inputs[i].name.substring(inputs[i].name.lastIndexOf("$") + 1));
            if(inputs[i].id.indexOf(prefix) > -1){
                inputs[i].checked = checkBox.checked;
            }
        }
    }
    return true;
}

function OpenInfoSheet(aircraftIdEncrypted){
    
    window.open("/InfoSheet.aspx?aid=" + aircraftIdEncrypted,"","location=1,status=1,scrollbars=1,width=620,height=700"); 

    return false;
}

function OpenRequestAQuote(tripIdEncrypted){
    
    window.open("/RequestAQuoteUrgently.aspx?tid=" + tripIdEncrypted,"","location=1,status=1,scrollbars=1,width=620,height=560"); 

    return false;
}

function OpenTripItinerary(tripIdEncrypted){
    
    window.open("/TripItinerary.aspx?tid=" + tripIdEncrypted,"","location=1,status=1,scrollbars=1,width=660,height=560"); 

    return false;
}

function OpenPopup(path){
    
    window.open(path,"","location=1,status=1,scrollbars=1,width=620,height=700"); 

    return false;
}

function OpenReportWindow(path){
    
    window.open(path,"","location=1,status=1,scrollbars=1,width=320,height=100"); 

    return false;
}

function SelectAllInputText(input){
    input.focus();
    input.select();
}

var defaultEstimatorLocationValue = "(E.G. London, UK or PostCode)";

function AmendEstimatorLocationStyle(input) {
    if (input.value == defaultEstimatorLocationValue) {
        input.value = "";
        input.className = "field-width";
        input.focus();
        input.select();
    }
    else {
        input.focus();
        input.select();
    }
}


function gridCheckboxSelectAll(gridClientID, checkboxID){
    var gv = document.getElementById(gridClientID);
    var cbs = gv.getElementsByTagName('input');
    if(cbs.length > 0){
        for(var i = 0; i < cbs.length; i++){
            if(cbs[i].id.indexOf(checkboxID) > -1){
                cbs[i].checked = true;
            }
        }
    }
}
function gridCheckboxDeselectAll(gridClientID, checkboxID){
    var gv = document.getElementById(gridClientID);
    var cbs = gv.getElementsByTagName('input');
    if(cbs.length > 0){
        for(var i = 0; i < cbs.length; i++){
            if(cbs[i].id.indexOf(checkboxID) > -1){
                cbs[i].checked = false;
            }
        }
    }
}

function gridCheckboxSelectDeselectAll(gridClientID, checkboxID, state){
    var gv = document.getElementById(gridClientID);
    var cbs = gv.getElementsByTagName('input');
    if(cbs.length > 0){
        for(var i = 0; i < cbs.length; i++){
            if(cbs[i].id.indexOf(checkboxID) > -1){
                cbs[i].checked = !state;
            }
        }
    }
    return !state;
}

function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else 
      window.onload = fnc;
  }
}

//e.g.
//addOnloadEvent(myFunctionName);
//// Or to pass arguments
//addOnloadEvent(function(){ myFunctionName('myArgument') });

