function doLogin( pForm )
{
	var req = new GAjax();
	req.inintLoading( 'wait' , true );
	req.send( 'member/chklogin.php' , req.getRequestBody( pForm ) , function(xhr){
		var datas = req.toJSON( xhr.responseText );
		if ( datas[0].error != '' )
		{
			alert( datas[0].error );
			document.getElementById( datas[0].input ).focus();
			new Highlight( datas[0].input ).play();
		}
		else
		{
			var el = $( 'login-div' ).elem;
			el.innerHTML = decodeURIComponent(datas[0].form);
		};
	});
	return false;
};

function doLogout()
{
	var req = new GAjax();
	req.inintLoading( 'wait' , true );
	req.send( 'member/chklogout.php' , 'action=logout' , function(xhr){
		var datas = req.toJSON( xhr.responseText );
		if ( datas[0].error != '' )
		{
			alert( datas[0].error );
		}
		else
		{
			var el = $( 'login-div' ).elem;
			el.innerHTML = decodeURIComponent(datas[0].form);
		}
	});
	return false;
};

function doForgotSuibmit( pForm )
{
	var req = new GAjax();
	req.inintLoading( 'wait' , true )
	req.send( 'member/recover.php' , req.getRequestBody( pForm ) , function(xhr){
		var ret = req.toJSON( xhr.responseText );
		for (var prop in ret[0] )
		{
			if ( prop == 'alert' )
			{
				alert( ret[0][prop] );
			}
			else if ( document.getElementById( prop ) )
			{ 
				if ( ret[0][prop] == 'focus' )
				{
					$( prop ).focus();
					new Highlight( prop ).play();
				}
				else
				{
					document.getElementById( prop ).value = ret[0][prop];
					new Highlight( prop ).play();
				};
			};
		};
	});
	return false;
};

function doRegisterSubmit( pForm )
{
	var req = new GForm( pForm );
	req.inintLoading( 'wait' , true );
	req.submit(function(xhr) {
		var ret = req.toJSON( xhr.responseText );
		for (var prop in ret[0] )
		{
			val = ret[0][prop];
			if ( prop == 'alert' )
			{
				alert( val );
			}
			else if ( prop == 'module' )
			{
				document.location = val;
			}
			else
			{
				elem = document.getElementById( prop );
				if (elem.tagName.toLowerCase() == 'img')
				{
					elem.src = val;
				}
				else
				{
					elem.innerHTML = val;
					elem.className = ( val == '' ) ? '' : 'incorrect';
				};
			};
		};
	});
	return true;
};

function pngfix( element )
{
	var arVersion = navigator.appVersion.split( "MSIE" );
	var version = parseFloat( arVersion[1] );
	if( ( version >= 5.5 ) && ( document.body.filters ) )
	{
		for( var i = 0 ; i < element.images.length ; i++ )
		{
			var img = element.images[i];
			var imgName = img.src.toUpperCase();
			if( imgName.substring( imgName.length - 3 , imgName.length ) == "PNG" )
			{
				var imgID =( img.id ) ? "id='" + img.id + "' " : "";
				var imgClass = ( img.className ) ? "class='" + img.className + "' ":"";
				var imgTitle = ( img.title ) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
				var imgStyle = "display:inline-block;" + img.style.cssText;
				if( img.align == "left" ) imgStyle = "float:left;" + imgStyle;
				if( img.align == "right" ) imgStyle = "float:right;" + imgStyle;
				if( img.parentElement.href ) imgStyle = "cursor:hand;" + imgStyle;
				var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\',sizingMethod='scale');\"></span>";
				img.outerHTML = strNewHTML;
				i = i - 1;
			};
		};
	};
};

var loader;
new Element(window).addEvent('load' , function(){
	loader = new GLoader( 'xhr' , function(xhr){
		var data = xhr.responseText;
		var content = document.getElementById( 'content' );
		content.innerHTML = data;
		Object.evalScript(data);
	});
	loader.inintLoading( 'wait' , true );
	pngfix(document);
});

function add2head( modules )
{
	var listsrc = modules.split( ',' );
	var head = document.getElementsByTagName( "head" )[0];
	for( i = 0 ; i < listsrc.length ; i++ )
	{
		var src = listsrc[i];
		var srctype = ( src.split( '.' )[1] == 'js' ) ? 'script' : 'link';
		var patt = new RegExp( srctype );
		var srcexists = false;
		var srcs = document.getElementsByTagName( srctype );
		var n = 0;
		while ( !srcexists && n < srcs.length )
		{
			srcexists = ( srctype == 'script' ) ? patt.test( srcs[n].src ) : patt.test( srcs[n].href );
			n++;
		};
		if ( !srcexists )
		{
			var newobj = document.createElement( srctype );
			if ( srctype == 'script' )
			{
				newobj.src = src;
				newobj.language = "JavaScript";
				newobj.type = "text/javascript";
			}
			else
			{
				newobj.href = src;
				newobj.rel = "stylesheet";
				newobj.type = "text/css";
			};
			head.appendChild( newobj );
		};
	};
};

var mtooltip;

function mTooltipShow( id , elem )
{
	if ( Object.isNull( mtooltip ) )
	{
		mtooltip = new gTooltip( {'className':'member-tooltip','fade':true} );
		mtooltip.setArrow( 'skin/img/arrow-l.gif' , 'skin/img/arrow-r.gif' );
	};
	mtooltip.showAjax( elem , 'member/view.php' , 'id=' + id );
};

function mTooltipHide()
{
	mtooltip.delayHide();
};
