/**
 * idea_generator.js
 */
include_js("/www_publicradio/idea_generator/scripts/swfobject.js");
/**
 * Returns the parameter value from the URL get params for the name of the parameter specified
 * @param String name the name of the parameter to return
 * @return String value of the parameter requested. Empty string if null
 */ 
function get_param( name ){
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null ) {
        return "";
    } else {
        return results[1];
    }
}
/**
 * Find the location of the idea generator to use for this request
 */
function get_location(){
    return location.protocol + "//" + location.hostname + "/www_publicradio/idea_generator/";
}

//edited by Ari Koinuma to take the 3rd argument, embed_id, to generate an embed tag with custom ID. 
function display_idea_generator( name, div_id, embed_id ) {    
    // <![CDATA[
    var so = new SWFObject("/www_publicradio/idea_generator/main.swf", embed_id, "740", "550", "9,0,0,0", "#ffffff");
    so.addParam("quality", "high");
    so.addParam("menu", "false");
    so.addVariable("data_base_url", get_location());
    so.addVariable("topic_id", name);
    so.addVariable("init_path", "/www_publicradio/idea_generator/");
    so.addVariable("idea_id", get_param( "idea_id" ));
    so.write(div_id);
    // ]]>
}

function include_js(js_url) {
    document.write("\<script type=\"text/javascript\" ");
	document.write("src='" + js_url + "'");
	document.write("\>");
	document.write("\</script\>");
}