// -------------------------------------------------------------------- function make_app_url( url, for_snippet ) { // generate a URL that accesses this webapp var base_url = window.location.origin ; if ( for_snippet && gAppConfig.ALTERNATE_WEBAPP_BASE_URL ) base_url = gAppConfig.ALTERNATE_WEBAPP_BASE_URL ; return base_url + url ; } function get_nationality_display_name( nat_id ) { // get the nationality's display name if ( ! gTemplatePack.nationalities || ! gTemplatePack.nationalities[nat_id] ) return null ; return gTemplatePack.nationalities[ nat_id ].display_name ; } function get_player_nat( player_no ) { // get the player's nationality if ( player_no === null ) return null ; return $( "select[name='PLAYER_" + player_no + "']" ).val() ; } function get_sorted_nats() { // sort the nationalities by display name var nats = Object.keys( gTemplatePack.nationalities ) ; nats.sort( function( lhs, rhs ) { lhs = gTemplatePack.nationalities[lhs].display_name.toUpperCase() ; rhs = gTemplatePack.nationalities[rhs].display_name.toUpperCase() ; if ( lhs < rhs ) return -1 ; else if ( lhs > rhs ) return +1 ; else return 0 ; } ) ; return nats ; } function get_player_colors( player_no ) { // get the colors for the specified player // NOTE: The returned color array holds the following values: // [ background, hover background, border ] var player_nat = get_player_nat( player_no ) ; return gTemplatePack.nationalities[ player_nat ].ob_colors ; } function get_player_colors_for_element( $elem ) { // get the player colors (if any) for the specified element if ( $elem.attr( "id" ).substr( 0, 18 ) === "ob_notes-sortable_" ) return null ; var player_no = get_player_no_for_element( $elem ) ; if ( player_no === null ) return null ; return get_player_colors( player_no ) ; } function make_player_flag_url( nat, for_snippet, force_local_image ) { if ( ! gTemplatePack.nationalities ) return null ; if ( for_snippet && gUserSettings["scenario-images-source"] == SCENARIO_IMAGES_SOURCE_INTERNET && !force_local_image ) return gAppConfig.ONLINE_IMAGES_URL_BASE + "/flags/" + nat + ".png" ; else { var url = "/flags/" + nat ; return make_app_url( url, for_snippet ) ; } } function get_player_no_for_element( $elem ) { // get the player that owns the specified element if ( $.contains( $("#tabs-ob1")[0], $elem[0] ) ) return 1 ; if ( $.contains( $("#tabs-ob2")[0], $elem[0] ) ) return 2 ; return null ; } function get_scenario_date() { // get the scenario date var scenario_date = $("input[name='SCENARIO_DATE']").datepicker( "getDate" ) ; if ( ! scenario_date ) return null ; // NOTE: Returning a Javascript Date object creates massive headaches since it is adjusted // for the current timezone, so we avoid problems by extracting the date fields here, and // discarding the time fields. var date=scenario_date.getDate(), month=1+scenario_date.getMonth(), year=scenario_date.getFullYear() ; return [ date, month, year, year + "-" + pad(month,2,"0") + "-" + pad(date,2,"0"), date + " " + get_month_name(month) + ", " + year ] ; } function is_template_available( template_id ) { // check if the specified template is available if ( template_id.match( /^ob_(vehicles|ordnance).*_[12]$/ ) ) template_id = template_id.substring( 0, template_id.length-2 ) ; else if ( template_id === "nat_caps_1" || template_id === "nat_caps_2" ) template_id = "nat_caps" ; return gTemplatePack.templates[ template_id ] !== undefined ; } // -------------------------------------------------------------------- function copyToClipboard( val ) { if ( getUrlParam( "store_clipboard" ) ) { // store the value where the tests can retrieve it $("#_clipboard_").text( val ) ; return ; } // IE-specific code path to prevent textarea being shown while dialog is visible if ( window.clipboardData && window.clipboardData.setData ) { clipboardData.setData( "Text", val ) ; return ; } // FUDGE! If a dialog is open, the overlay will stop the copy command from working, // so we attach the