// for checking if we've been srced
var caspian_util = {};

var __UTIL__saveRows = null;

function resizeFrameHeight(frameObj, newHeight) {
    var p = frameObj.parent;
    // e.g. '50,*,30', possibly contains spaces
    var r = p.document.body.rows;
    var frameIndex;

    for (var i=0; i<p.frames.length; i++) {
        if (p.frames[i] == frameObj) { 
            frameIndex = i;
            break;
        } else {
            //return;
            continue;
        }
    }

    //is this right?
    var re = / +/g;
    r.replace(re,"");
    var a = r.split(",");

    var oldHeight = a[frameIndex];
    //a[frameIndex] *= coef;
    a[frameIndex] = newHeight;
    var newRows = a.join(",");
    //alert(newRows);

    p.document.body.rows = newRows;
}


function show_e(e, d) {
    if (!d) d='block';
    e.style.display = d;
}

function showOnlyFrame(frameObj) {
    var p = frameObj.parent;
    // e.g. '50,*,30', possibly contains spaces
    var r = p.document.body.rows;

    __UTIL__saveRows = r;

    //is this right?
    var re = / +/g;
    r.replace(re,"");
    var a = r.split(",");

    var frameIndex;

    for (var i=0; i<p.frames.length; i++) {
        if (p.frames[i] == frameObj) { 
        } else {
            a[i] = 1;
        }
    }

    var newRows = a.join(",");

    p.document.body.rows = newRows;
}

// takes arg cuz we gotta know parent
function restoreFrames(frameObj) {
    frameObj.parent.document.body.rows = __UTIL__saveRows;
}
                
// document is in context of caller
function hide(id) {
    var i = document.getElementById(id);
    var d = i.style.display;
    i.style.display = 'none';
}

function hide_e (e) {
    var d = e.style.display;
    e.style.display = 'none';
}

function log(s) {
    if (typeof(console) == 'object') {
        console.log(s);
    }
    else if (typeof(opera) == 'object') {
        opera.postError(s);
    }
}

function popup(url, param) {
    var width;
    var height;
    if (param) {
        width = param.width;
        height = param.height;
    }
    if (! width) width = 300;
    if (! height) height = 300;
    window.open(
        url,
        "popup", 
        'status=false, resize=true, toolbar=false, scrollbars=false,' + 
        'width=' + width + ',' +
        'height=' + height 
        );
    }


function myScrollTo(win, id, yAdj) {
    var e = $(id);
    if (yAdj == undefined) yAdj = 0;
    if (e) win.scroll(0, e.getCoordinates()['top'] + yAdj)
}

// return rand int x := i <= x <= j
function rand(i, j) {
    return Math.floor(Math.random() * (j - i + 1)) + i;
}


