function doLogin() {
    var pass = $("#userpass").val();
	var passmd5 =  MD5(pass);	
	
	$.get("/index.php", {	
								name :  $("#username").val(),
								passwd : passmd5
							},
							function(resdata){
								history.go(0);
							});

}

	function onStart( args ) {
		var type = args[0];
		var index = args[1];

		console.log( "start %s: %s", type, index );
	}

	function onFinish( args ) {
		var type = args[0];
		var index = args[1];

		console.log( "finish %s: %s", type, index );
	}

	function onComplete() {
		console.log( "complete" );
	}
	
function typerCount(source, layerID, limit, countdown) { 
	
	if(typeof layerID=="string")
	{
		layerID=document.getElementById(layerID);
	}

	limit=Math.abs(limit)||0;
	
	if(!limit && countdown/*incompatible setting*/)
	{
		countdown=0;
	}

	if(typeof layerID=="object" && typeof source=="object")
	{
		if(!layerID.childNodes.length)
		{
			layerID.appendChild(document.createTextNode(source.value.length));
		};
		
		if(source.value.length+1>=limit)
		{
			source.value=source.value.substring(0, limit);
		};
		
		layerID.childNodes[0].nodeValue=(!countdown)?source.value.length:limit - source.value.length;
	}
}

function getChat() {
      
 	 $.get("/ajax/chat.php", {	
		   							'mode' : 'getmsg'
							},
							function(resdata){
								document.getElementById('chat').innerHTML = resdata;
								$('div.chatbox').scrollTo('max');
 							});
}

function chat() {


 	 $.get("/ajax/chat.php", {	
		   							'msg' : $("#chatmsg").val()
							},
							function(resdata){
								getChat();
							});
	 
	$("#chatmsg").val("");

}


function disableReturnKey(e)
{
     var key;

     if(window.event)
        key = window.event.keyCode;     //IE
     else
        key = e.which;     //firefox

     if(key == 13) {
		doLogin();
		return false;
	 } else {
     	return true;
	 }
}

function clearField(field, fname) 
{
	$(fname).focus(function() {
	if( this.value == this.defaultValue ) {
		this.value = "";
	}
	}).blur(function() {
	if( !this.value.length ) {
		this.value = this.defaultValue;
	}
});
}
