﻿// Collection of basic JavaScript functions for RBW web.
// Copies text to the clipboard.
// Taken from http://www.dynamic-tools.net/toolbox/copyToClipboard/.
function CopyToClipboard(s)
{
	if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", s);
	}
} // End CopyToClipboard.

function TestAlert(s)
{
    alert(s);
}

function AddSlashes(str) {
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\0/g,'\\0');
return str;
}
function StripSlashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}

// Creates a random string of characters.
// Taken from http://bytes.com/topic/javascript/answers/523253-how-create-guid-javascript
function CreateRandomString() 
{
	return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
} // End CreateRandomString.

// Creates code to embed a WMV file into a page.
function WMVEmbedGenerator()
{
    var fileName = prompt("What is the name of the WMV file you wish to embed (including the .WMV extension)?", ".wmv");
    if (fileName == null) return false;
    var embedText = "<embed src=\"Videos\\" + fileName + "\" autostart=\"false\" />";
    CopyToClipboard(embedText);
    alert('The following text has been sent to the clipboard: \n ' + embedText);
} // End WMVEmbedGenerator.

// Creates code to embed a FLV file into a page.
function FLVEmbedGenerator()
{
    var fileName = prompt("What is the name of the FLV file you wish to embed (including the .FLV extension)?", ".flv");
    if (fileName == null) return false;
	fileName = AddSlashes(fileName);
	var guid = CreateRandomString();
    var embedText = "<p id=\"" + guid + "\">The player will show in this paragraph</p> "
        + "<script type='text/javascript' src='swfobject.js'></script>" 
        + "<script type='text/javascript'>"
        + "var s1 = new SWFObject('player.swf','player','400','300','9');"
        + "s1.addParam('allowfullscreen','true');"
        + "s1.addParam('allowscriptaccess','always');"
        + "s1.addParam('flashvars','file=Videos\\\\" + fileName + "');"
        + "s1.write('" + guid + "');"
        + "</script>"
    CopyToClipboard(embedText);
    alert("The following text has been sent to the clipboard: \n " + embedText);
} // End FLVEmbedGenerator.

