var ie  = document.all;
var nn6 = document.getElementById&&!document.all;

var in_drag;
var x_pos,y_pos;
var drag_obj;
var tx,ty;


function get(id)
{
    return document.getElementById(id);
}

function dark()
{
    var mist = get('mist');
    mist.style.width = document.body.scrollWidth + "px";
    mist.style.height = document.body.scrollHeight + "px";
    mist.style.visibility = "visible";
    window.onresize = dark;
}

function tt(html_body, o, e, width, noborder , customhandler)
{

    if(!customhandler) customhandler='';

    var html ='';

    html+='<table border="0" cellspacing="0" cellpadding="0" width="100%">';
    html+='  <tr style="cursor:move">';                             
    html+='   <td>';    
    html+='    <table border="0" cellspacing="0" cellpadding="0" width="100%">';
    html+='         <tr style="cursor:move">';
    html+='             <td width="80%" style="background:#000;color:white;padding:4px">Inovasi.Net : <b>LOGIN</b></td>';
    html+='             <td width="20%" align="right" style="height:30px;background:#000">';
    html+='                 <a href="javascript:void(0)" onclick="'+  customhandler  +';hidetip();light();unmask();return false;"><img src="plugins/tooltips/winclose.gif" style="height:28px;border:none"/></a>';
    html+='              </td>';
    html+='         </tr>';
    html+='     </table>';
    html+='  </td>';
    html+='  </tr>';
    html+='  <tr>';
    html+='        <td align="center">';
    html+=              '<table border="0" cellspacing="7" cellpadding="0" id="fxholder" width="100%"><tr><td>';
    html+=                   html_body;
    html+=              '</td></tr></table>';
    html+='        </td>';
    html+='    </tr>';
    html+='</table>';


    var d = get_win_rect();
    if (!d)
    {
        fixedtooltip(html, o, e, width);
        return;
    }
    if (window.event) 
        event.cancelBubble=true;
    else if (e.stopPropagation) 
        e.stopPropagation();

    clearhidetip();
    dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv;
    dropmenuobj.innerHTML=html;


    dropmenuobj.style.backgroundColor = "transparent";
    dropmenuobj.style.borderTop       = "0px";
    dropmenuobj.style.borderLeft      = "0px";
    dropmenuobj.style.borderRight     = "0px";
    dropmenuobj.style.borderBottom    = "0px";



    dropm  = get('fxholder');
    dropm.style.backgroundColor = '#ffffff';


    if (noborder)
        dropm.style.border = 'none';
    else
    {
        dropm.style.borderTop    = '0px solid gray';
        dropm.style.borderLeft   = '1px solid gray';
        dropm.style.borderRight  = '1px solid gray';
        dropm.style.borderBottom = '1px solid gray';

    }


    if (ie4||ns6)
    {
        showhide(dropmenuobj.style, e, "visible", "hidden", width);
        var eh = dropmenuobj.offsetHeight;
        var ew = dropmenuobj.offsetWidth;
        dropmenuobj.style.left=d[0] + Math.ceil((d[1] - d[0] - ew) / 2) + 'px';
        dropmenuobj.style.top=d[2] + Math.ceil((d[3] - d[2] - eh) / 2) + 'px';
        dropmenuobj.style.zIndex = 10001;
    }
}

function get_win_rect() 
{
    try
    {
        var ver=navigator.appVersion;
        var dom=document.getElementById?1:0;
        var ie6=(ver.indexOf("MSIE 6")>-1 && dom)?1:0;
        var ie7=(ver.indexOf("MSIE 7")>-1 && dom)?1:0;
        var opera5=navigator.userAgent.indexOf("Opera")>-1;

        var w, h, sx, sx; 

        if (ns6 || opera5) 
        { 
            w  = self.innerWidth; 
            h  = self.innerHeight; 
            sx = window.pageXOffset; 
            sy = window.pageYOffset; 
        } 
        else if (ie6 || ie7) 
        { 
            w = document.documentElement.clientWidth; 
            h = document.documentElement.clientHeight; 
            if (w==0) 
            { 
                w = document.body.clientWidth; 
                h = document.body.clientHeight; 
            } 
            sx = document.body.scrollLeft + document.documentElement.scrollLeft; 
            sy = document.body.scrollTop + document.documentElement.scrollTop; 
        } else if (ie4) 
        { 
            w = document.body.clientWidth; 
            h = document.body.clientHeight; 
            sx = document.body.scrollLeft; 
            sy = document.body.scrollTop; 
        } 
        if (isNaN(sx) || isNaN(sy) || isNaN(w) || isNaN(h))
            return null;
        return [sx, w + sx, sy, h + sy];
    }
    catch (err)
    {
        return null;
    }
} 


function popup_login1()
{
    dark();

    mask();

    var html = '';
    html+='            <form action=\'index.php?class=login&act=login\' method=post name=frmLogin><table border="0">';
    html+='                <tr>';
    html+='                    <td>Username:</td>';
    html+='                    <td><input type="text" id="lb_user" name="username" style="width:200px"/></td>';
    html+='                </tr>';
    html+='                <tr>';
    html+='                    <td>Password:</td>';
    html+='                    <td><input type="password" id="lb_pass" name="passwd" style="width:200px"></td>';
    html+='                </tr>';
    html+='            </table></form>';
    html+='            <div style="text-align:center">';
    html+='                <a href="javascript:void(0)" onclick="frmLogin.submit()"><img src="plugins/tooltips/login.gif" style="width:56px;height:23x;border:none" alt="Login" title="Login"/></a>';
    html+='            </div>';
    var e = {type:'click'};
    tt(html, document.body, e, '300px', false);
    get('lb_user').focus();
}

function light()
{
    get('mist').style.visibility = "hidden";
    window.onresize = null;
}

function dodrag(e)
{
    if (in_drag)
    {
        drag_obj.style.left = (nn6 ? tx + e.clientX - x_pos : tx + event.clientX - x_pos) + 'px';
        drag_obj.style.top  = (nn6 ? ty + e.clientY - y_pos : ty + event.clientY - y_pos) + 'px';
        return false;
    }
}

function startdrag(e) 
{
    var fobj = nn6 ? e.target : event.srcElement;
    if (!fobj || fobj.tagName == 'TEXTAREA' || fobj.tagName == 'INPUT' || fobj.tagName == 'SELECT' || fobj.tagName == 'OPTION')
        return true;
    while (fobj && fobj.id != 'fixedtipdiv')
        fobj = nn6 ? fobj.parentNode : fobj.parentElement;

    if (fobj && fobj.id=="fixedtipdiv")
    {
        in_drag = true;
        drag_obj = fobj;
        tx = parseInt(drag_obj.style.left+0);
        ty = parseInt(drag_obj.style.top+0);
        x_pos = nn6 ? e.clientX : event.clientX;
        y_pos = nn6 ? e.clientY : event.clientY;
        document.onmousemove=dodrag;
        return false;
    }
}

function mask()
{
    var o = get('showplayer');
    if (o)
        o.style.display = 'none';
    o = get('fastsmalladdiv');
    if (o)
        o.style.display = 'none';

    var o = get('yieldaddiv');
    if (o)
        o.style.visibility = 'hidden';
    o = get('ymaddiv');
    if (o)
        o.style.visibility = 'hidden';
    o = get('resizeoptions');
    if (o)
        o.style.visibility = 'hidden';
}

function unmask()
{
    var o = get('lb_user');
    if (o)
        o.style.display = 'none';
    o = get('lb_pass');
    if (o)
        o.style.display = 'none';
    o = get('showplayer');
    if (o)
        o.style.display = '';
    o = get('fastsmalladdiv');
    if (o)
        o.style.display = '';
    o = get('yieldaddiv');
    if (o)
        o.style.visibility = 'visible';
    o = get('ymaddiv');
    if (o)
        o.style.visibility = 'visible';
    o = get('resizeoptions');
    if (o)
        o.style.visibility = 'visible';

}

//document.onmousedown = startdrag;
//document.onmouseup=function () {in_drag=false};

function popup_login()
{
	raf_dark();
	raf_pop();	
	get('lb_user').focus();
}

function raf_dark() {
	var ie = document.all;
	var obj = get('raf_dark');
	if(!obj) {
	   var obj = document.createElement('div');
	   obj.setAttribute('id','raf_dark');
	   document.body.appendChild(obj);
	}
	obj.style.zIndex = 100;
	obj.style.left = '0px';
	obj.style.top = '0px';
	obj.style.position = 'absolute';
	obj.style.background = 'black';
	obj.style.width = document.body.scrollWidth + "px";
	obj.style.height = document.body.scrollHeight + "px";
	if(ie) {
		obj.style.filter='alpha(opacity=50)';
	} else {
		obj.style.MozOpacity=0.50;
	}
	obj.style.display = '';
	window.onresize = raf_dark;
}

function raf_pop() {
	var html ='';
	var w = 300;
	var h = 160;

	html+='<table border="0" cellspacing="0" cellpadding="0" width="100%">';
	html+='<tr style="cursor:move" onmousedown="raf_drag(event)" onmouseup="raf_undrag(event)" class=raf_dragObj>';                             
    html+='	 <td class=raf_dragObj>';    
    html+='	   <table border="0" cellspacing="0" cellpadding="0" width="100%" class=raf_dragObj>';
    html+='	   <tr style="cursor:move" class=raf_dragObj>';
    html+='      <td width="80%" style="background:#000;color:white;padding:4px" class=raf_dragObj>Inovasi.Net : <b>LOGIN</b></td>';
    html+='      <td width="20%" align="right" style="height:30px;background:#000;">';
    html+='        <a href="javascript:void(0)" onclick="raf_unpop();raf_undark()" style="cursor:pointer"><img src="plugins/tooltips/winclose.gif" style="height:28px;border:none"/></a>';
    html+='      </td>';
    html+='    </tr>';
    html+='    </table>';
    html+='  </td>';
    html+='</tr>';
    html+='<tr>';
    html+='  <td align="center">';
	html+='    <form action=\'index.php?class=login&act=login\' method=post name=frmLogin><table border="0">';
    html+='    <table border="0" cellspacing="7" cellpadding="0" id="fxholder" width="100%"><tr><td>';
    html+='    <tr>';
    html+='      <td>Username:</td>';
    html+='      <td><input type="text" id="lb_user" name="username" style="width:200px"/></td>';
    html+='    </tr>';
    html+='    <tr>';
    html+='      <td>Password:</td>';
    html+='      <td><input type="password" id="lb_pass" name="passwd" style="width:200px"></td>';
    html+='    </tr>';
    html+='    </table>'
	html+='	   </form>';
    html+='    <div style="text-align:center">';
    html+='      <a href="javascript:void(0)" onclick="frmLogin.submit()"><img src="plugins/tooltips/login.gif" style="width:56px;height:23x;border:none" alt="Login" title="Login"/></a>';
    html+='    </div>';
    html+='  </td>';
	html+='</tr>';
	html+='</table>';

	var obj = get('raf_pop');
	if(!obj) {
	   var obj = document.createElement('div');
	   obj.setAttribute('id','raf_pop');
	   document.body.appendChild(obj);
	}
	obj.style.zIndex = 101;
	obj.style.width =  w + "px";
	obj.style.height = h + "px";
	obj.style.position = 'absolute';
	obj.style.left = Math.round((document.body.scrollWidth - w)/2) + 'px';
	obj.style.top = '200px';

	obj.style.background = 'white';
	obj.innerHTML = html;
	obj.style.display = '';
}

function raf_unpop() {
	var obj = get('raf_pop');
	if(obj) {
		obj.style.display = 'none';
	}
}

function raf_undark() {
	var obj = get('raf_dark');
	if(obj) {
		obj.style.display = 'none';
	}
}

function raf_drag(e) {
	var ie = document.all;
	e = ie? window.event : e;
	var obj = ie ? e.srcElement : e.target;
	if(obj.className=='raf_dragObj') {
		obj.className = "raf_dragObj_enalble";
	}
	var xt =  e.clientX;
	var yt =  e.clientY;
	window.onmousemove = function(e) {
		var ie = document.all;
		e = ie? window.event : e;
		var name = ie ? e.srcElement.className : e.target.className;
		if(name=='raf_dragObj_enalble') {
			
			var obj = get('raf_pop');
			if(obj) {
				var xco = getposOffset(obj,'left') + e.clientX - xt ;
				var yco = getposOffset(obj,'top') + e.clientY - yt ;
				obj.style.left = xco+'px';
				obj.style.top = yco+'px';
				xt =  e.clientX;
				yt =  e.clientY;
			}
		}
	};
	obj.onmouseout = function () {
		window.onmousemove = null;
	}
}

function raf_undrag(e) {
	var ie = document.all;
	e = ie? window.event : e;
	var obj = ie ? e.srcElement : e.target;
	if(obj.className=='raf_dragObj_enalble') {
		obj.className = "raf_dragObj";
	}
	window.onmousemove = null;
}

function raf_dodrag(e) {
	var ie = document.all;
	e = ie? window.event : e;
	var name = ie ? e.srcElement.className : e.target.className;
	if(name=='raf_dragObj_enalble') {
		
		var obj = get('raf_pop');
		if(obj) {
			var xco = e.clientX - 10;
			var yco = e.clientY - 10;
			obj.style.left = xco+'px';
			obj.style.top = yco+'px';
		}
	}
}

