//var _MEMBERURL='http://localhost/pph/';
//var _VALIDATEURL='http://localhost/pph/';
//var _MEMBERURL='http://Tracks005.ehost-services150.com/';
//var _VALIDATEURL = 'http://Tracks005.ehost-services150.com/';
var spath = document.location.href
spath = spath.substring(0, spath.indexOf("/", 10) + 1);
var _MEMBERURL = spath ;
var _VALIDATEURL = spath ;

var _HIDELOGIN=false;
var _CONTENT='';
with(document){
	_CONTENT+=('<style>');
	_CONTENT+=('	#lbox{');
	_CONTENT+=('		position: absolute;');
	_CONTENT+=('		width: 161px;');
	_CONTENT+=('		height: 96px;');
	_CONTENT+=('		font-family:Trebuchet, Arial, Helvetica, sans-serif;');
	_CONTENT+=('		font-size: 10px;');
	_CONTENT+=('		background-image: url('+_ROOTPATH+'images/loginbox.gif);');
	_CONTENT+=('		background-repeat: no-repeat;');
	_CONTENT+=('		background-position: left top;');
	_CONTENT+=('		padding:0px 0px 10px 0px;');
	_CONTENT+=('		z-index: 1000;');
	_CONTENT+=('	}');
	_CONTENT+=('	#lbox input{');
	_CONTENT+=('		height: 20px;');
	_CONTENT+=('		border: solid 1px silver;');
	_CONTENT+=('		width: 115px;');
	_CONTENT+=('		font-family:Trebuchet, Arial, Helvetica, sans-serif;');
	_CONTENT+=('		font-size: 10px;');
	_CONTENT+=('		color:#5d5d5d;');
	_CONTENT+=('	}');
	_CONTENT+=('	#lbox .clink{');
	_CONTENT+=('		height: 16px;');
	_CONTENT+=('		display: block;');
	_CONTENT+=('		width: 161px;');
	_CONTENT+=('	}');
	_CONTENT+=('</style>');
	_CONTENT+=('<div id="lbox">');
	_CONTENT+=('	<a href="javascript:setPosition(true);" class="clink"></a>');
	_CONTENT+=('	<div style="padding-left:10px;" id="lboxcontent">');
	_CONTENT+=('		Username:<br>');
	_CONTENT+=('		<input type=text value="" name="txtUser" id="txtUser" onkeyup="javascript:dologin(event);" /><br>');
	_CONTENT+=('		Password:<br>');
	_CONTENT+=('		<input type=password value="" name="txtPass" id="txtPass" onkeyup="javascript:dologin(event);" />');
	_CONTENT+=('		<a href="javascript:login();"><img src="'+_ROOTPATH+'images/go.gif" border=0 align=absmiddle alt="Login" /></a>');
	_CONTENT+=('	</div>');
	_CONTENT+=('</div>');
	write(_CONTENT);
}

function getAbsolutePosition(element) {
	var r = { x: element.offsetLeft, y: element.offsetTop };
	if (element.offsetParent) {
		var tmp = getAbsolutePosition(element.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}				
	return r;
}

function setPosition(noresize){
	var fl=document.getElementById('flashcontent');
	var pos=getAbsolutePosition(fl);
	var lbx=document.getElementById('lbox');
	if(fl){
		if(lbox){
			pos.x+=(fl.offsetWidth-lbox.offsetWidth);
			pos.x-=29;
			lbox.style.left=pos.x+'px';
			if(noresize==true){
				_HIDELOGIN=(!_HIDELOGIN);
			}
			if(_HIDELOGIN){
				pos.y+=31;
				lbox.style.top=pos.y+'px';
				lbox.style.height='96px';
				lbox.style.paddingTop='2px';
				lbox.style.paddingBottom='10px';
				document.getElementById("lboxcontent").style.display='';
				document.getElementById("txtUser").focus();
			}else{
				pos.y+=111;
				lbox.style.top=pos.y+'px';
				lbox.style.height='16px';
				lbox.style.paddingTop='0px';
				lbox.style.paddingBottom='0px';
				document.getElementById("lboxcontent").style.display='none';
			}
		}
	}
}

function login(){
	var user=document.getElementById("txtUser").value;
	var pass=document.getElementById("txtPass").value;
	var result=false;
	
	if(user==''){
		alert("Username is required!");
		return;
	}
	
	if(pass==''){
		alert("Password is required!");
		return
	}
	
	var ajax=new AJAX();
	ajax.setEventHandler("_login", "'" + user + "','" + pass + "'");
	ajax.getAJAX(_VALIDATEURL+"validatelogin.aspx?user="+user+"&pass="+pass);
}

function _login(res, success, user, pass) {
	if(success){
		var result=res.response;
		if(result.substr(0,1)=='S'){
			//location.href=_MEMBERURL+result.substr(1);
			location.href=_MEMBERURL+"defaultlogin.aspx?formaction=login&username="+user+"&password="+pass;
		}else{
			alert(result.substr(1));
		}
	}else{
		alert(res.response);
	}
}

function dologin(e){
	kcode=(window.event)?window.event.keyCode:e.which;
	if(kcode==13){
		login();
	}
}

setPosition();
window.onresize=setPosition;