/**
 *
 */
function modal(url, w, h)
{
    if (!w) w = 400;
    if (!h) h = 400;
    url = HOMEDIR +'/'+ url;
    var w = W.showModelessDialog(url, top.window, 'dialogHeight: '+h+'px; dialogWidth: '+w+'px; center: yes; dialogHide: no; edge: sunken; help: off; resizable: on; status: no; unordered: off;');
}
/**
 *
 */
function perm_modal(url, w, h)
{
    if (!w) w = 400;
    if (!h) h = 400;
    url = HOMEDIR +'/'+ url;
    var w = W.showModelessDialog(url, top.window, 'dialogHeight: '+h+'px; dialogWidth: '+w+'px; center: yes; dialogHide: no; edge: sunken; help: off; resizable: on; status: no; unordered: off; scroll: no;');
}
/**
 *
 */
function dsize(w, h)
{
    if (!w || !h) return;
    W.dialogWidth = w+'px';
    W.dialogHeight = h+'px';
}
/**
 *
 */
function wsize(w, h)
{
    if (!w || !h) return;
    W.resizeTo(w, h);
    wcenter(w, h);
}
/**
 *
 */
function wcenter(w, h)
{
    if (!w || !h) return;
    var aw = screen.availWidth;
    var ah = screen.availHeight;
    if (w > aw) w = aw;
    if (h > ah) h = ah;
    var l = (aw - w)/2;
    var t = (ah - h)/2
    W.moveTo(l, t);
}
/**
 *
 */
function wait(key)
{
    if (key) {
        W.D.wait_div.style.display = "none";
        return;
    }
    W.D.wait_div.style.display = "block";
}
/**
 *
 */
function wopen(url, target, w, h, asize, title, res)
{
    if (!url) {
        event.cancelBubble = true;
        event.returnValue = false;
        return;
    }
    if (!target) target = '_blank';
    if (!w) w = 500;
    if (!h) h = 400
    if (!title) title = '';

    w = parseInt(w, 10);
    h = parseInt(h, 10);
    if (asize) asize = true;
    else asize = false;

    var aw = screen.availWidth;
    var ah = screen.availHeight;
    if (w > aw) w = aw;
    if (h > ah) h = ah;

    if (res)r = 0;
    else r = 1;

    var left = Math.round((aw - w)/2);
    var top = Math.round((ah - h)/2);

    var wd = window.open(url, target, 'channelmode= 0, directories=0, fullscreen=0, height='+h+'px, width='+w+'px, location=0, menubar=0, resizable='+r+', scrollbars=1, status=0, toolbar=0, top='+top+'px, left='+left+'px');
    if (!asize) {
        return;
    }
    if (url.indexOf(window.location.host) != -1 || url.indexOf('http://') == -1) {
        wd.attachEvent("onload", function() {resize_new_win( wd, asize, title )} );
    }
}
/**
 *
 */
function resize_new_win(win, asize, title)
{
    if (win.document.body == null) {
        win.document.createElement("body");
    }
    var wb = win.document.body;

    wb.style.padding = "0px";
    wb.style.margin = "0px";
    wb.style.overflow="auto";

    if (asize) {
        var ofw = wb.scrollWidth - wb.clientWidth;
        var ofh = wb.scrollHeight - wb.clientHeight;

        var eflag = false;

        if ((wb.clientWidth + ofw) > (screen.availWidth - 40)) {
            ofw =  screen.availWidth - wb.clientWidth - 50 ;
            eflag = true;
        }
        if (wb.clientHeight + ofh > screen.availHeight - 60) {
            ofh = screen.availHeight - wb.clientHeight - 60;
            eflag = true;
        }
        win.resizeBy(ofw, ofh);

        var left = 2;
        if (eflag == false) {
            win.resizeBy(wb.scrollWidth - wb.clientWidth,  wb.scrollHeight - wb.clientHeight);
            left = Math.round((screen.availWidth - wb.clientWidth+20)/2);
        }

        win.moveTo(left, 10);
        if (title) {
            win.document.title = title;
        }
    }
}
/**
 *
 */
function winfull(url, target)
{
    if (!url) {
        return false;
    }
    if (!target) {
        target = '_blank';
    }
    var wd = window.open(url, target, 'fullscreen=1, scrollbars=0, toolbar=0');
}
/**
 *
 */
function contextfalse() {
    if (event) {
        event.cancelBubble = true;
        event.returnValue = false;
    }
    return false;
}
/**
 *
 */
function go(url)
{
    if (url) {
        window.location.assign(url);
    }
}
/**
 * Replace double spaces and trailing spaces
 */
function replace( obj ) {
    var r1 = /^( )+/g;
    var r2 = /( )+$/g;
    var r3 = /( {2})+/;

    obj.value = obj.value.replace( r1, '' );
    obj.value = obj.value.replace( r2, '' );
    obj.value = obj.value.replace( r3, ' ' );
}
/**
 * Check correct email format
 */
function em_ch( obj ) {
    if ( !obj ) { return false; }

    var ch = /^[._a-z0-9-]+@[.a-z0-9-]+\.[a-z]{2,4}$/i;

    if ( !ch.test( obj.value ) ) { return false; }

    return true;
}

/**
 *
 *
 */
function hlmnu(id1, id2) {
    if (!id1 || !id2) { return false; }
    var o1 = document.getElementById(id1);
    var o2 = document.getElementById(id2);
    if (!o1 || !o2) { return false; }
    o1.style.display = "none";
    o2.style.display = "block";
}

function hlmnu2(obj) {
    if (!obj) {return false;}
    obj.filters[0].Opacity = 90;
}

function dhlmnu2(obj) {
    if (!obj) {return false;}
    obj.filters[0].Opacity = 70;
}

function flashObj(src, w, h, bgcolor, base, wmode) {
	if (!src) return false;
	w = parseInt(w);
	h = parseInt(h);
	if (!w || !h) return false;
	if (!bgcolor) bgcolor = '#ffffff';
	if (!base) base = '';
	if (!wmode) wmode = 'window';

	var tag = '';
	tag += '<object width="'+w+'" height="'+h+'" codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
	tag += '<param name="FlashVars" value="">';
	tag += '<param name="Movie" value="'+src+'">';
	tag += '<param name="Src" value="'+src+'">';
	tag += '<param name="wmode" value="'+wmode+'">';
	tag += '<param name="Play" value="1">';
	tag += '<param name="Loop" value="-1">';
	tag += '<param name="Quality" value="High">';
	tag += '<param name="Menu" value="0">';
	tag += '<param name="Base" value="'+base+'">';
	tag += '<param name="Scale" value="ShowAll">';
	tag += '<param name="DeviceFont" value="-1">';
	tag += '<param name="EmbedMovie" value="0">';
	tag += '<param name="BGColor" value="'+bgcolor+'">';
	tag += '<embed src="'+src+'" menu="false" quality="high" bgcolor="'+bgcolor+'" width="'+w+'" height="'+h+'" wmode="'+wmode+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
	tag += '</object>';

	document.write(tag);
}
