﻿// SingingFool.com Core Javascript File

// Core

function include(file) {
    var script  = document.createElement('script');
    script.src  = file;
    script.type = 'text/javascript';
    document.getElementsByTagName('head')[0].appendChild(script);
}

function includeHere(file, name) {
    var script  = document.createElement('script');
    script.src  = file;
    script.type = 'text/javascript';
    document.getElementById(name).appendChild(script);
}

// Menu

function clickHandler(sender, eventArgs) {
    //Checks which item is clicked
    if (eventArgs.get_item().get_value() == "ArtistUploads") {
        window.open('http://betamediamanager.internetvideoarchive.com/customupload/music.aspx?mediaid=3&amp;showmediatype=false&amp;customerid=25599', 'upload','width=560,height=500,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes')

        //Cancel the postback
        eventArgs.set_cancel(true);
    }
}

// ComboBox

function OnClientItemsRequesting(sender, eventArgs) {
    if (eventArgs.get_text().length < 3)
        eventArgs.set_cancel(true)
    else
        eventArgs.set_cancel(false);
}

function OnClientItemsRequestedHandler(sender, eventArgs)
{
    //set the max allowed height of the combo
    var MAX_ALLOWED_HEIGHT = 400;
    //this is the single item's height
    var SINGLE_ITEM_HEIGHT = 25;
    var calculatedHeight = sender.get_items().get_count() * SINGLE_ITEM_HEIGHT;
    var dropDownDiv = sender.get_dropDownElement();

    if (calculatedHeight > MAX_ALLOWED_HEIGHT)
    {
        setTimeout (
            function () {
                dropDownDiv.firstChild.style.height = MAX_ALLOWED_HEIGHT + "px";
            }, 100
        );
    }
    else
    {
        setTimeout (
            function () {
                dropDownDiv.firstChild.style.height = calculatedHeight + "px";
            }, 100
        );
    }
}

// JW Player

//function sendEvent(swf,typ,prm) {
//    thisMovie(swf).sendEvent(typ,prm);
//};

//function getUpdate(typ,pr1,pr2,swf) {};

//function thisMovie(swf) {
//    if(navigator.appName.indexOf("Microsoft") != -1) {
//        if (window[swf]) {
//            return window[swf];
//        } else {
//            return document[swf];
//        }
//    } else {
//        return document[swf];
//    }
//};

//function loadFile(swf,obj) {
//    thisMovie(swf).loadFile(obj);
//};

function loadFile(Url) {
    var player = document.getElementById('title_player_obj');
    player.sendEvent("LOAD", Url);
}

// ToolTip

function CloseToolTipSplash(id, pid) {
    document.getElementById('RadToolTipWrapper_ctl00_ContentPlaceHolder1_ToolTip_Splash').style.visibility = 'hidden';
    document.getElementById('RadToolTipWrapper_ctl00_ContentPlaceHolder1_ToolTip_Splash').style.display = 'none';
    document.getElementById('title_player_savenow').style.display = 'block';
    document.getElementById('title_player_savenow').innerHTML = '<a href=\"#\" onclick=\"OpenConfirmation(\'' + id + '\', \'' + pid + '\'); return false;\">Click here to save</a>';
}

function OpenConfirmation(id, pid) {
    document.getElementById('RadToolTipWrapper_ctl00_ContentPlaceHolder1_ToolTip_Splash').style.display = 'block';
    document.getElementById('RadToolTipWrapper_ctl00_ContentPlaceHolder1_ToolTip_Splash').style.visibility = 'visible';
    document.getElementById('title_tooltip_splash').innerHTML = '<b>Are you sure this is the one you want?</b><br /><br />It\'s what you’ll get whenever you search for this title.<br /><br />(You can go back and watch the other choices before you choose.)<br /><br /><a href=\"Title.aspx?publishedid=' + pid + '&yt=' + id + '\">Click here to confirm your choice.</a>';
}

// Players

// For AdShowClose link at bottom of site
var ShowCloseType = 1;
 
function includeBrightcove(vid, vref, lineupid, playertag, autostart, preloadbgcolor, w, h, playerid)
{
    var config = new Array();
    
    config["videoId"] = vid; //the default video loaded into the player
    config["videoRef"] = vref; //the default video loaded into the player by ref id specified in console
    config["lineupId"] = lineupid; //the default lineup loaded into the player
    config["playerTag"] = playertag; //player tag used for identifying this page in brightcove reporting
    config["autoStart"] = autostart; //tells the player to start playing video on load
    config["preloadBackColor"] = preloadbgcolor; //background color while loading the player
    config["width"] = w;
    config["height"] = h;
    config["wmode"] = "transparent"; 
    
    /* do not edit these config items */
    if (playerid == 4) {                // Sony Player
        config["playerId"] = "AI82cd35YlC5T%2BRk5pFs%2FLAlu%2FCoC33ov";
    } else if (playerid == 5) {         // Warner Player
        config["playerId"] = "APUsSsPTeYRQZHnVZLY9tS%2BbmqdmBGdVQ";
        config["externalAds"] = true;
        
        ShowCloseType = 2;
    } else if (playerid == 10) {        // UMG Player
        config["playerId"] = "A9mmoNQM1VTZ0cmokNyIAZ9fT3iNic77a";
        
        ShowCloseType = 3;
    }
 
    createExperience(config, 8);
}

function includeIva(FileId) {
    // Following line is for SwfObject v2.0+
    //swfobject.embedSWF("http://www.videodetective.net/flash/sfbetaplayer.swf", "title_player", "468", "371", "9.0.0", "expressInstall.swf", {id:" + FileId + ",c:"25599",playerid:"70",kbrate:"750",sub:"SfBetaV9"}, {allowfullscreen:"true",wmode:"transparent",allowscriptaccess:"always"});

    // SwfObject v1.5 (3.16 Player)
//    var swfobject = new SWFObject('http://www.videodetective.net/flash/sfbetaplayer.swf', 'title_player_obj', '468', '371', '8.0.0');
//    swfobject.addParam('AllowScriptAccess', 'Always');
//    swfobject.addParam('AllowFullScreen', 'True');
//    swfobject.addParam('WMode', 'Transparent');
//    swfobject.addVariable('c', '25599');
//    swfobject.addVariable('id', '' + FileId + '');
//    swfobject.addVariable('playerid', '70');
//    swfobject.addVariable('kbrate', '750');
//    swfobject.addVariable('sub', 'SfBetaV9');
//    swfobject.write('title_player');
//    window.title_player_obj = document.forms[0].title_player_obj;
    
    // SwfObject v1.5 (4.x Player)    
    var swfobject = new SWFObject('http://videodetective.net/flash/players/?publishedid=' + FileId + '&customerid=25599&pversion=4&playerid=7&videokbrate=750&sub=sfTitlePage', 'title_player_obj', '468', '371', '8.0.0');
    swfobject.addParam('AllowScriptAccess', 'Always');
    swfobject.addParam('AllowFullScreen', 'True');
    swfobject.addParam('AllowNetworking', 'All');
    swfobject.addParam('WMode', 'opaque');
    swfobject.addParam('type', 'application/x-shockwave-flash');
    swfobject.write('adaptvDiv');
    window.title_player_obj = document.forms[0].title_player_obj;
}

function includeBrightcoveCompanion() {
    var so = new SWFObject("http://vsyndication.wmg.com/wmgdigividplayer/expanded_banner.swf", "expanded_banner", "300", "250", "8.0.0");
    so.addParam("swliveconnect", "true");
    so.addParam("allowScriptAccess", "always");
    so.addParam("wmode", "transparent");
    so.write("WarnerAd");
}

function loadAd(Xml) {
    var so = new SWFObject("http://www.videodetective.net/flash/general_ad_player.swf", "SwfAd", "400", "300", "8.0.0");
    var AdPath = "AD_PAGENAME=XmlAdParser.aspx?asid=" + aj_acid + "%26src=" + Xml + "%26";
    if (Xml.indexOf("http") >= 0) {
        AdPath = "AD_PAGENAME=" + escape(Xml);
    } 
    // alert(AdPath);
    so.addParam("swliveconnect", "true");
    so.addParam("allowScriptAccess", "always");
    so.addParam("flashvars", AdPath);
    
    // so.addParam("flashvars", "AD_PAGENAME=" + Xml);
    so.write("title_player_ad");
    	
}

function includeIvaWmv(VideoUrl) {
    document.getElementById("adaptvDiv").innerHTML = "<object id=\"MediaPlayer\" width=\"468\" height=\"371\" style=\"filter: progid:DXImageTransform.Microsoft.BasicImage (Grayscale=1);\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" standby=\"Loading Windows Media Player components...\" type=\"application/x-oleobject\"><param name=\"URL\" value=\"" + VideoUrl + "&sub=sfTitlePage\"><param name=\"stretchToFit\" value=\"true\"><param name=\"fullscreen\" value=\"false\"><param name=\"AutoSize\" value=\"false\"><embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" id=\"mediaPlayer\" name=\"mediaPlayer\" autosize=\"0\" bgcolor=\"darkblue\" showcontrols=\"1\" showtracker=\"1\" showdisplay=\"0\" showstatusbar=\"0\" videoborder3d=\"0\" width=\"468\" height=\"371\" src=\"" + VideoUrl + "&sub=sfTitlePage\" autostart=\"1\" designtimesp=\"5311\" loop=\"0\"></embed></object>";
}

// Ad Implementation

var PublishedId;
var WmvUrl;
var a = 0; // AdDone
var b = 0; // LoadCompanionByUrl

function includeIvaAd() {
    aj_server = 'http://rotator.adjuggler.com/servlet/ajrotator/';
    aj_tagver = '1.0';
    aj_zone = 'video';
    aj_adspot = '368570';
    aj_page = '0';
    aj_dim ='368573';
    aj_ch = '';
    aj_ct = '';
    aj_kw = '';
    aj_pv = true;
    aj_click = '';
    aj_acid = '368571';

    // Show blank player as background if flash
    //if (videoType == 'iva') { includeIva(0000); }
    //if (videoType == 'ivawmv') { includeIvaWmv(0000); }
    
    document.getElementById("title_player_ad").style.display = 'block';
}

function AdDone() {
    a++;

    if (a == 1) {
    	document.getElementById("title_player_ad").style.display = 'none';
    	document.getElementById("title_player_ad_companion").style.display = 'none';
	    document.getElementById("companion").style.display = 'none';
	    document.getElementById("AdShowClose").innerHTML = "<a href=\"#\" onclick=\"ToggleAd(); return false;\">Show Ad</a>";

	    document.getElementById("adaptvDiv").innerHTML = '';
	
	    if (videoType == 'iva') { includeIva(FileId); }
	    if (videoType == 'ivawmv') { includeIvaWmv(WmvUrl); }
	}
}

function FLA_HandleEmbedBanner(bannerHTML) {
	// takes html that needs to be inserted into page
}

function FLA_HandlePlaybackComplete() {
    // Same as AdDone. Some Ad netorks needed this function
	AdDone();
}

function FLA_HandleAdPlaybackComplete() {
	// Same as AdDone. Some Ad netorks needed this function
	AdDone();
}

function LoadCompanionByUrl(sUrl) {
    // takes a full url to load the companion.
	// this works in new RadWindow or loading an iFrame
	// Be careful. For some reason this gets called twice from flash player

    document.getElementById("AdShowClose").style.visibility = "visible";

    b++;

    if (b == 1) {
        CreateCompanion(sUrl, "companion");
        document.getElementById("title_player_ad_companion").style.display = "block";
        document.getElementById("companion").style.display = "block";
        document.getElementById("AdShowClose").style.display = "block";
        document.getElementById("AdShowClose").innerHTML = "<a href=\"#\" onclick=\"ToggleAd(); return false;\">Hide Ad</a>";
    }
}

function ToggleAd()
{
    if (document.getElementById("title_player_ad_companion").style.display == "block") {
        document.getElementById("title_player_ad_companion").style.display = 'none';

	    if (ShowCloseType == 2) {
	        document.getElementById("WarnerAd").style.zIndex = '-1';
	    } else if (ShowCloseType == 3) {
	        document.getElementById("expandedBanner").style.zIndex = '-1';
	    } else {
	        document.getElementById("companion").style.display = 'none';
	    }

        document.getElementById("AdShowClose").innerHTML = "<a href=\"#\" onclick=\"ToggleAd(); return false;\">Show Ad</a>";
    } else {
        document.getElementById("title_player_ad_companion").style.display = 'block';

	    if (ShowCloseType == 2) {
	        document.getElementById("WarnerAd").style.zIndex = '21';
	    } else if (ShowCloseType == 3) {
	        document.getElementById("expandedBanner").style.zIndex = '21';
	    } else {
	        document.getElementById("companion").style.display = 'block';
	    }

        document.getElementById("AdShowClose").innerHTML = "<a href=\"#\" onclick=\"ToggleAd(); return false;\">Hide Ad</a>";
    }
}

function WriteToCompanion(sCompanionHTML, Div)
{
    var bannerHTML = sCompanionHTML
	var adFrame = document.createElement("iframe");

	adFrame.setAttribute("src", "about:blank");
	adFrame.setAttribute("frameborder", 0);
	adFrame.id = "bannerIFrame";
	adFrame.frameBorder = 0;
	adFrame.scrolling = "no";
	adFrame.width = "300px";
	adFrame.height = "250px";
	adFrame.className = "BannerWindow";

	try
	{
	    document.getElementById(Div).innerHTML = "";
		document.getElementById(Div).appendChild(adFrame,0);
	}
	catch (err)
	{
	    window.status = 'error loading companion.';
	}

	document.getElementById("bannerIFrame").contentWindow.document.open();
	document.getElementById("bannerIFrame").contentWindow.document.write("<html><body style='background-color:#FFF;padding:0px;overflow:hidden;margin:0'>"+bannerHTML+"</body></html>");
	document.getElementById("bannerIFrame").contentWindow.document.close();
}

function CreateCompanion(sUrl, CompanionElementName) {
    var bannerUrl = sUrl;
	var adFrame = document.createElement("iframe");

	adFrame.setAttribute("src", bannerUrl);
	adFrame.setAttribute("frameborder", 0);
	adFrame.id = "bannerIFrame";
	adFrame.frameBorder = 0;
	adFrame.scrolling = "no";
	adFrame.width = "320px";
	adFrame.height = "270px";
	//adFrame.className = "BannerWindow";

	try {
	    document.getElementById(CompanionElementName).innerHTML = "";
		document.getElementById(CompanionElementName).appendChild(adFrame, 0);
	}
	catch (err) {
	    window.status = 'error loading companion.';
	}
}