// general bigcontact javascript utilities, included by every page

/** Register an onload function. */
function WindowOnload(f)
{
  var prev=window.onload;
  window.onload=function(){ if(prev)prev(); f(); }
}

/*
 * Edit another channel from the header dropdown.
 *
 */
function edit_other_channel(dropdown, url) {    
    var tag = dropdown.options[dropdown.selectedIndex].value;
    var info = tag.split("-");

    // tags should be encoded in the format 'bc-569' or 'ext-969'
    var type = info[0];
    var chid = info[1];

    if (!type || !chid || chid.length == 0) {
	return false;
    }
    
    if (type === 'ext') {
	// external channels can only navigate to a few pages
	var valid = false;
	if (url.indexOf('myfeedplayers.php') > -1) {
	    valid = true;
	}
	else if (url.indexOf('channel.php') > -1) {
	    valid = true;
	}
	else if (url.indexOf('stats-crunched.php') > -1) {
	    valid = true;
	}

	if (!valid) {
	    // reset the url to a valid default for external channels
	    url = '/myfeedplayers.php';
	}
    }
    else if (type === 'bc') {
	// bc channels can't navigate to a few pages, but most of them work.
	var valid = true;
	if (url.indexOf('subscription-list.php') > -1) {
	    valid = false;
	}

	if (!valid) {
	    // reset the url to a valid default for bc channels
	    url = '/publish.php';
	}
    }

    document.location = url + '?chid=' + chid;    
}
