// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}

function promo(base,title,x,y){
    if (Get_Cookie( 'hidePopUp' ) == 'true') {
	   return true;
	}
    var win=null;
	var w = "620px";
	var h = "437px";
	var myname = "video";
	myleft=x;
	mytop=y;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	base = URLEncode(base);
	title = URLEncode(title);
	mypage = base + ".html";
	win=window.open(mypage,myname,settings);
	win.focus();
}



function newVideo(base,title){
	var win=null;
	var w = "340px";
	var h = "416px";
	var myname = "video";

	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	base = URLEncode(base);
	title = URLEncode(title);
	mypage = "/scripts/media/loadVideo.pl?base=" + base + "&title=" + title;
	win=window.open(mypage,myname,settings);
	win.focus();
}

function newGoogle(id,title){
	var win=null;
	var w = "415px";
	var h = "340px";
	var myname = "gvideo";

	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	googleid = URLEncode(id);
	title = URLEncode(title);
	mypage = "/scripts/media/loadGoogle.pl?googleid=" + googleid + "&title=" + title;
	win=window.open(mypage,myname,settings);
	win.focus();
}





function newAudio(base,title){
	var win=null;
	var w = "340px";
	var h = "416px";
	var myname = "audio";

	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	base = URLEncode(base);
	title = URLEncode(title);
	mypage = "/scripts/media/loadAudio.pl?base=" + base + "&title=" + title;
	win=window.open(mypage,myname,settings);
	win.focus();
}

function newSlideShow(base,title,transition){
	var win=null;
	var w = "420px";
	var h = "430px";
	var myname = "slideShow";

	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	base = URLEncode(base);
	title = URLEncode(title);
	mypage = "/scripts/media/loadSlideShow.pl?base=" + base + "&title=" + title + "&transition=" + transition;
	win=window.open(mypage,myname,settings);
	win.focus();
}

function jumpToSpeed(base,title){
	base = URLEncode(base);
	title = URLEncode(title);
    location.href = "/scripts/media/jumpConfig.pl?base=" + base + "&title=" + title;
}

function URLEncode( plaintext )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '"
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};
