//
//This file contains functions that are used when Video browsing or Image browsing
//

var NO_DATA = -1;

function writeFrame(frm, str)
{
    frm.document.open();
    frm.document.write(str);
    frm.document.close();
}

function loadAds(frm, adData)
{
    if(adData == NO_DATA) return;

    var str = processStr(adsStr);
    writeFrame(frm, str);
}

function addAd(n)
{
    var str = '<A href="' + Ads[n].url + '" target="_blank"><IMG border="0" src="' + Ads[n].src + '" width="' + Ads[n].wd + '" height="' + Ads[n].ht + '" alt="' + Ads[n].caption + '"></A>';
    return str;
}

function processStr(aspStr)
{
    var i,j;
    var str = aspStr;
    var strOut = code = tmp = "";

    while((i = str.indexOf("<%")) != -1){
        strOut += str.substring(0,i);
        j = str.indexOf("%>");
        code = str.substring(i+2, j);
        strOut+= processCode(code);
        tmp = str.substring(j+2, str.length);
        str = tmp;
    }
    strOut+= str;	// add the end piece on
    return strOut;
}

function processCode(code)
{
    var str = tmp = "";

    if(code.charAt(0) == "="){
        tmp = code.substring(1, code.length);
        str = "" + eval(tmp);
    }else{
        str = eval(code);
    }
 
    return str;
}

// For restricted access files, call this before file loads
function checkRegistration(fn)
{
	setupUserCode();	// check args and set if there

	if(top.UserCode != 0) return;

	// No usercode in args, not set at top, so check cookies
	var args= getArgs(location.href);
	var path= updateArgValue("../asp/checkCookies.asp", "args", escape(args));
	path= updateArgValue(path, "fn", fn);
	location.href= path;
}

