var _security = "";
var _security = "";
var _src = "";

function validate(security)
{
   _security = security;
   showProgress("Authenticating user...");
   window.setTimeout("validateUser();",10);
}

function logout(security)
{
   _security = security;
	showProgress("Logging out user...");
   window.setTimeout("logoutUser();",10);
}

function resetProgress()
{
	fsl = document.getElementById("loginfieldset");
	fsm = document.getElementById("progressfieldset");
	pm = document.getElementById("progressmessage");
	
	if (fsm!=null) fsm.style.display = "none";	
	if (fsl!=null) fsl.style.display = "block";
	if (pm!=null) pm.innerHTML = "";
}


function showProgress(msg)
{
	fsl = document.getElementById("loginfieldset");
	fsm = document.getElementById("progressfieldset");
	pm = document.getElementById("progressmessage");
	
	if (fsl!=null) fsl.style.display = "none";
	if (pm!=null) pm.innerHTML = msg;
	if (fsm!=null) fsm.style.display = "block";	
}

function validateUser()
{
   var sw = document.getElementById("userlogin");
   if (sw==null)
   {
      initUserLogin();
	  window.setTimeout("validateUser();",50);
	  return;
   }   
   if (sw.asLogin==null)
   {
	  window.setTimeout("validateUser();",50);
	  return;
   }
   sw.asLogin(_security);
   return;  
}

function logoutUser()
{  
   var sw = document.getElementById("userlogin");
   if (sw==null)
   {
      initUserLogin();
	  window.setTimeout("logoutUser();",50);
	  return;
   }   
   if (sw.asLogout==null)
   {
	  window.setTimeout("logoutUser();",50);
	  return;
   }
   sw.asLogout();
   return;  
}

function getLogin()
{
   var fo = document.forms["fvalidation"];
   if (fo!=null)
   {      
      var obj = new Object();
	  obj["username"] = fo["username"].value;
	  obj["password"] = fo["password"].value;
	  obj["remember"] = ""+fo["remember"].checked;
	  return obj;
   }
   return;
}

function phpSession()
{  
  var results = document.cookie.match ( '(^|;) ?PHPSESSID=([^;]*)(;|$)' );
  if ( results )
  {  
    return ( unescape ( results[2] ) );
  }
  else
    return null;
}

function addFL(id,width,height,src,flashvars,dest,bgcolor)
{

	AC_Generateobj = function(objAttrs, params, embedAttrs) 
	{ 
		var str = '';
		if (isIE && isWin && !isOpera)
		{
			str += '<object ';
			for (var i in objAttrs)
				str += i + '="' + objAttrs[i] + '" ';
			str += '>';
			for (var i in params)
				str += '<param name="' + i + '" value="' + params[i] + '" /> ';
			str += '</object>';
		} else {
			str += '<embed ';
			for (var i in embedAttrs)
				str += i + '="' + embedAttrs[i] + '" ';
			str += '> </embed>';
		}
		if (dest!=null || dest=="")
		{
		  var div = document.getElementById(dest);
		  if (div!=null) 
		  {
		    div.innerHTML = str;
		  }
		}
		else
		{
		  document.write(str);
		}
	};

	wmode = "";
	if (bgcolor==null) bgcolor = "#0a3343";
	if (bgcolor=="transparent")
	{
		bgcolor = "#000000";
		wmode = "transparent";
	}

	if ( hasProductInstall && !hasRequestedVersion ) {
		// DO NOT MODIFY THE FOLLOWING FOUR LINES
		// Location visited after installation is complete if installation is required
		var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
		var MMredirectURL = window.location;
		document.title = document.title.slice(0, 47) + " - Flash Player Installation";
		var MMdoctitle = document.title;

		AC_FL_RunContent(
			"src", "/playerProductInstall",
			"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
			"width", width,
			"height", height,
			"align", "middle",
			"wmode", wmode,
			"id", id,
			"quality", "high",
			"bgcolor", "#869ca7",
			"name", id,
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
		);
	} else if (hasRequestedVersion) {
		// if we've detected an acceptable version
		// embed the Flash Content SWF when all tests are passed
		AC_FL_RunContent(
				"src", "/"+src,
				"width", width,
				"height", height,
				"wmode", wmode,
				"align", "middle",
				"id", id,
				"quality", "high",
				"bgcolor", bgcolor,
				"name", id,
				"allowScriptAccess","sameDomain",
				"allowFullScreen","true",
				"type", "application/x-shockwave-flash",
				"pluginspage", "http://www.adobe.com/go/getflashplayer",
				"flashvars" , flashvars
		);
	  } else {  // flash is too old or we can't detect the plugin
		var alternateContent = ''
		+ 'This content requires the Adobe Flash Player. '
		+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
		document.write(alternateContent);  // insert non-flash content
	  }
}


function initUserLogin()
{
	addFL("userlogin",10,10,"userlogin","","divuserlogin","transparent");
}

function fromXML(xml,node)
{
	try
	{
	   var value = xml.split("<"+node+">")[1];
	   value = value.split("</"+node+">")[0];
	   return value;
	}
	catch(e)
	{
	  return "";
	}
}

function  visibleXY()
{
	var pos = new Object();
	if (window.pageYOffset!=null)
	{
		pos.x = window.pageXOffset;
		pos.y = window.pageYOffset;
	}
	else
	{
		pos.x = document.body.scrollLeft + document.documentElement.scrollLeft;
		pos.y = document.body.scrollTop + document.documentElement.scrollTop;
	}
	return pos;
}

function loadDocument()
{
   addFL("MYFGCore",10,10,"MYFGCore","","divCore","transparent");
   
   pos = visibleXY();   
   var divCore = document.getElementById("divCore");
   if (divCore!=null) 
   {
	  divCore.style.left = ""+(pos.x+100)+"px";
	  divCore.style.top = ""+(pos.y+100)+"px";
   }      
   if (window.pageStart!=null) 
   {
		if (window.pageStart.constructor == Array)
		{
			for (s=0; s<window.pageStart.length; s++)
			{
				var f = window.pageStart[s];
				f();
			}
		}
		else
		  window.pageStart();   
   }
}

function addToStart(f)
{
	if (window.pageStart==null)
		window.pageStart = new Array();
	window.pageStart.push(f);	
}

function fullScreen(url,id)
{
	window.open(url,id,"fullscreen");
}


function maxWidth()
{
	return $("body").width();
}

function maxHeight()
{
	return $("body").height();
}

function scrollX()
{
	var ScrollLeft = document.body.scrollLeft;	 
	if (ScrollLeft == 0)
	{
		if (window.pageXOffset)
			ScrollLeft = window.pageXOffset;
		else
			ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
	}
	return ScrollLeft;
}

function scrollY()
{
	var ScrollTop = document.body.scrollTop;	 
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	return ScrollTop;
}

function scrollW()
{
	return $("body").width();
}

function scrollH()
{
	h = $("#wrapper").height();
	if (h==null || h==0) h = $("#page").height();
	if (h==null || h==0) h = $("#container").height();
	return h+75;
	
}

function disable()
{
	var dp = document.getElementById("disabledpanel");
	if (dp!=null)
	{
		$("#disabledpanel").css('left', "0px");
		$("#disabledpanel").css('top', "0px");
		$("#disabledpanel").css('width', scrollW()+"px");
		$("#disabledpanel").css('height', scrollH()+"px");
		$("#disabledpanel").show();
	}
}

var inPop  = false;
function pop(src,w,h)
{
	
	if (w==null) w = scrollW()-20;
	if (h==null) h = $("body").height()-20;

	inPop = true;
	
	$("#pop").css('width', w+"px");
	$("#pop").css('height', h+"px");
	$("#pop").html("<iframe id=\"popiframe\" frameborder=\"0\" scrolling=\"no\" style=\"display:none; overflow-y:hidden\" src=\""+src+"\" ></iframe>");
	$("#popiframe").css('width', (w-2)+"px");
	$("#popiframe").css('height', (h)+"px");
	$("#popiframe").show();

	popPosition();	
	$("#pop").show();
		
	window.setTimeout("popPosition()",100);	
}

function popClose()
{	
	$("#pop").hide();
	$("#disabledpanel").hide();
	inPop = false;
}

function popPosition()
{
	if (inPop)
	{
		w = $("#pop").width();
		h = $("#pop").height();
		$("#pop").css('left', ((scrollW()-w)/2)-2+"px");
		$("#pop").css('top', ((scrollY()+($("body").height()-h)/2)-2)+"px");
		window.setTimeout("popPosition()",100);	
	}
}

function alertError(msg)
{
  alert("Error : "+msg);
}

function register()
{
	window.location = "http://community.makeyourflashgame.com/ucp.php?mode=register";
}

function download(type,what)
{
	window.open("http://content.makeyourflashgame.com/download.php?type="+type+"&what="+what,"_blank");
}

