/*
 * written by ThiHa ZAN
 * core functions
 * release 2.0 : WIP
 */



// @desc: void <b>chBorder</b> (HTMLelement, string color) <br />change border color to specified;
// @param: HTMLobject, string - color;
// @return: void;
function chBorder(o,color)
{
    o.style.borderColor = color;
}


// @desc: change (swap) image (default _0 image with _1 image);
// @param: HTMLobject - image, [string - image uri (optional)];
// @return: void;
function chImg()
{
    var a = chImg.arguments;
    o = a[0];

    if (a.length == 1) { // replace _0 with _1 or _1 with _0
        o.src = (o.src.indexOf("_0") != -1) ? o.src.replace(/_0/i, "_1") : o.src.replace(/_1/i, "_0");
    } else { // replace any image provided
        o.src = a[1];
    }
}



// @desc: get the object for the given name (not for frame); 
// @param: string - name of the object;
// @return: HTML object;
function getObj(n)
{
    var i, x=null, d=document;
    if (!(x=d[n]) && d.all) {
        x = d.all[n];
    }
    for (i=0; !x&&i<d.forms.length; i++) {
        x = d.forms[i][n];
    }
    if (!x && d.getElementById) {
        x = d.getElementById(n);
    }
    return x;
}



// @desc: go to url; 
// @param: str- url;
// @return: void;
function goURL(url)
{
    window.location = url;
}



// @desc: preload images;
// @param: str - image location
// @return: void;
function preloadImg() {
    if(document.images) { 
        if(!document.preloadImg) {
            document.preloadImg = new Array();
        }
        var i,j=document.preloadImg.length,a=preloadImg.arguments; 
        for(i=0; i<a.length; i++) {
            if (a[i].indexOf("#")!= 0) { 
                document.preloadImg[j] = new Image; 
                document.preloadImg[j++].src = a[i];
            }
        }
    }
}


function eCardSelect(obj,mod)
{
    if (mod == 1) {
        obj.style.borderColor='#ff9900';
        obj.style.borderWidth='2px';
    } else {
        obj.style.borderColor='#666666';
        obj.style.borderWidth='1px';
    }
}

function eCardEdit(o,n) {
    if (o == 'MSG') {
        getObj(o).innerHTML = n.replace(/\r\n/g,"<br />");
    } else {
        getObj(o).innerHTML = "<em>"+n+"</em>";
    }  
}


function viewInThePress(img)
{
    win = window.open("/news/inthepress/show.asp?i="+img,"POP","left=25,top=50,height=500,width=650,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,titlebar=yes");
    win.close();
    win = window.open("/news/inthepress/show.asp?i="+img,"POP","left=25,top=50,height=500,width=650,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,titlebar=yes");

}