// www.theradioplaylist.com -- client config file
// (c) 2008 EventCentrics LLC.
//-----------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------
// -- begin client config section -- insert config lines from admin screen here
var CMD_PLAYLIST = "SThBMkNMSUVOVF9JRD1LQ0JYJk1FTlVfU1RBVEU9Q1VSUkVOVA%3D%3D";
var CMD_SCHEDULE = "SThBMkNMSUVOVF9JRD1LQ0JYJk1FTlVfU1RBVEU9UFJPR1JBTV9TQ0hFRFVMRQ%3D%3D";
var CMD_PROGRAM_LIST = "SThBMkNMSUVOVF9JRD1LQ0JYJk1FTlVfU1RBVEU9UFJPR1JBTV9MSVNU";
var CMD_LOGIN = "SThBMkNMSUVOVF9JRD1LQ0JYJk1FTlVfU1RBVEU9TE9HSU4%3D";

var xCMD_PLAYLIST = "SThBMkNMSUVOVF9JRD1URVNUJk1FTlVfU1RBVEU9Q1VSUkVOVA%3D%3D";
var xCMD_SCHEDULE = "SThBMkNMSUVOVF9JRD1URVNUJk1FTlVfU1RBVEU9UFJPR1JBTV9TQ0hFRFVMRQ%3D%3D";
var xCMD_PROGRAM_LIST = "SThBMkNMSUVOVF9JRD1URVNUJk1FTlVfU1RBVEU9UFJPR1JBTV9MSVNU";
var xCMD_LOGIN = "SThBMkNMSUVOVF9JRD1URVNUJk1FTlVfU1RBVEU9TE9HSU4%3D";

// -- end client config section -- do not change anything below this line!!!
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------


function loadPlaylist() {
    // passes the client pages CMD parameter down to the iframe url
    //
    // looks at the window location URL and parses out the CMD parameter
    // and then sets it in the iframe src attribute
    var params = window.location.search.substring( 1 ).split( '&' );
    var CMD = CMD_PLAYLIST;
    var TEST = 0;

    var SRC_URL = escape(window.location.href.substring(0, window.location.href.lastIndexOf('/')));
    //var SRC_PAGE_URL = escape(window.location.href.substring(0, window.location.href.lastIndexOf('?')));
    var SRC_PAGE_URL = window.location.href;

    if (SRC_PAGE_URL.search(/\?/gi) != -1)
        SRC_PAGE_URL = SRC_PAGE_URL.substring(0, SRC_PAGE_URL.lastIndexOf('?'))
    SRC_PAGE_URL = escape(SRC_PAGE_URL);

    var MENU_STATE = '';
    var ID_PROGRAM = '';

    for( var i = 0, l = params.length; i < l; ++i ) {
      var parts = params[i].split( '=' );
      switch( parts[0] ) {
      case 'CMD':
        CMD = parts[1];
        break;
      case 'MENU_STATE':
        MENU_STATE = parts[1];
        break;
      case 'ID_PROGRAM':
        ID_PROGRAM = parts[1];
        break;
      case 'TEST':
        TEST = 1;
        break;
      }
    }



    if (CMD == 'PLAYLIST')
        CMD = CMD_PLAYLIST;
    else if (CMD == 'SCHEDULE')
        CMD = CMD_SCHEDULE;
    else if (CMD == 'PROGRAM_LIST')
        CMD = CMD_PROGRAM_LIST;
    else if (CMD == 'LOGIN')
        CMD = CMD_LOGIN;

    var iframe = document.getElementById( 'PLAYLISTFRAME' );
    var URL = '';
    l = '' + window.location;

    if (l.search(/localhost/gi) && l.search(/localhost/gi) != -1)
        URL = "http://localhost";
    else
        URL = "http://www.theradioplaylist.com";

    if (TEST)
        URL = URL + "/playlist_test";
    else
        URL = URL + "/playlist";

    URL = URL + "/App_PlayList.php?"

    URL = URL + "CMD=" + CMD;
    if (ID_PROGRAM != '')
       URL = URL + "&ID_PROGRAM=" + ID_PROGRAM;


    URL = URL + "&SRC_URL=" + SRC_URL;
    URL = URL + "&SRC_PAGE_URL=" + SRC_PAGE_URL;
    iframe.src = URL;
}

    /*
    - An Iframe within the hosted app calls back to an iframe from the client server
    to enable the main page to change the size of the cross domain iframe
    - taken from ideas presented here:  
    http://blog.johnmckerrell.com/2006/10/22/resizing-iframes-across-domains/
    */ 

  function updateIFrame( height ) {
    //alert( 'Updating IFrame height to '+height );
    var iframe = document.getElementById( 'PLAYLISTFRAME' ); 
    iframe.setAttribute( 'height', height + 100 );
  }
  
      
