var settingdiv = false;
var profilediv = false;

function getChoice(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function updateSetting()
{
	var ajax = new sack();
	//hideSetting();
	showProgress("Processing...");
	var form = document.getElementById('settingfrom');	profilefrom
	var pointRad = getChoice(form.pointrep);
	var newsRad = getChoice(form.newsletter);
	var newGameRad = getChoice(form.newgame);
	var winRad = getChoice(form.winnotice);
	var isUPL = getChoice(form.isUpload);
	//alert (pointRad);
	ajax.setVar("userid", form.userid.value);
	ajax.setVar("pointrep", pointRad);
	ajax.setVar("newsletter", newsRad);
	ajax.setVar("newgame", newGameRad);
	ajax.setVar("winnotice", winRad);
	ajax.setVar("isUpload", isUPL);
	ajax.requestFile = "/js/updatesetting.php";
	ajax.method = "POST";
	ajax.onCompletion = function ()
	{
		if (isUPL)
		{
			document.getElementById('uploadlink').style.display='inline';
		}
		else
		{
			document.getElementById('uploadlink').style.display='none';
		}
		//alert("here");
		defaultCompleteAction(ajax);
		if (!ajax.json_data['error'].length)
		{
			// if successed
			//showJSMessage("", ajax.json_data['content']);			
			document.getElementById('settingdiv').style.display="block";
			document.getElementById("goSet").style.display="none";
			document.getElementById("resultLyr").style.display="block";
			//document.getElementById("goSet").innerHTML = ajax.json_data['content'];								
		}
	}
	ajax.runAJAX();
	return false;
}
function updateProfile()
{
	var ajax = new sack();
	//hideSetting();
	showProgress("Processing...");
	var form = document.getElementById('profilefrom');
	var gender = getChoice(form.gender);
	ajax.setVar("sitename", form.sitename.value);
	ajax.setVar("age", form.age.value);
	ajax.setVar("gender", gender);
	ajax.requestFile = "/js/updateprofile.php";
	ajax.method = "POST";
	ajax.onCompletion = function ()
	{		
		//alert("here");
		defaultCompleteAction(ajax);
		if (!ajax.json_data['error'].length)
		{
			// if successed
			//showJSMessage("", ajax.json_data['content']);			
			document.getElementById('profilediv').style.display="block";
			document.getElementById("goSet").style.display="none";
			document.getElementById("resultLyr").style.display="block";
			//document.getElementById("goSet").innerHTML = ajax.json_data['content'];								
		}
	}
	ajax.runAJAX();
	return false;
}

//------------MY POINTS
function mypoint(mbID)
{
	var ajax = new sack();
	showProgress("Please wait...");	
	//alert (pointRad);
	ajax.setVar("userid", mbID);
	ajax.requestFile = "/js/mypoints.php";
	ajax.method = "POST";
	ajax.onCompletion = function ()
	{
		//hideProgress();
		window.location = ajax.response;
		//alert (ajax.response);
	}
	ajax.runAJAX();
	return false;
}
//--------END MY POINTS

function setupSettingForm(div)
{
	var ajax = new sack();
	//showProgress("Loading form...");
	ajax.requestFile = "/js/setting.php";
	ajax.method = "GET";	
	ajax.onCompletion = function() {
		div.innerHTML = ajax.response;
		hideProgress();
	};
	ajax.runAJAX();
	return false;
}
function setupProfileForm(div)
{
	var ajax = new sack();
	//showProgress("Loading form...");
	ajax.requestFile = "/js/profile.php";
	ajax.method = "GET";	
	ajax.onCompletion = function() {
		div.innerHTML = ajax.response;
		hideProgress();
	};
	ajax.runAJAX();
	return false;
}

function prepFormSet()
{
	//alert("Got Over!");
	if (!settingdiv)
	{
		settingdiv = document.createElement('DIV');
		settingdiv.id = 'settingdiv';
		//settingdiv.className = 'floatdiv';
		settingdiv.style.display='none';
		setupSettingForm(settingdiv);
		document.body.appendChild(settingdiv);		
	}	
}
function prepFormProf()
{
	//alert("Got Over!");
	if (!profilediv)
	{
		profilediv = document.createElement('DIV');
		profilediv.id = 'profilediv';
		profilediv.style.display='none';
		setupProfileForm(profilediv);
		document.body.appendChild(profilediv);		
	}	
}

function showSetting(settinglink)
{
	prepFormSet();
	setTimeout("SlideSet()",500);
			
	/*settingdiv.style.left = '790px';
	settingdiv.style.top = '25px';*/
	settingdiv.style.left = getLeftPos(settinglink) - 250 + 'px';
	settingdiv.style.top = getTopPos(settinglink) + settinglink.offsetHeight + 2 + 'px';
	settingdiv.style.position = 'absolute';
	settingdiv.style.zIndex = '1500';
		
	/*if (settingdiv.style.display=='none')
	{		
		var sElmSet = document.getElementById('settingdiv');
		if (sElmSet == null) {
			setTimeout("SlideSet()",1000);
		}
		else {
			SlideSet();
		}
	}*/
}
function showProfile(profilelink)
{
	prepFormProf();
	setTimeout("SlideSet2()",500);
			
	profilediv.style.left = getLeftPos(profilelink) - 250 + 'px';
	profilediv.style.top = getTopPos(profilelink) + profilelink.offsetHeight + 2 + 'px';
	profilediv.style.position = 'absolute';
	profilediv.style.zIndex = '1500';
}

function SlideSet()
{
	var obj = settingdiv;
	
	if (obj.style.display == "block" || obj.style.display == "")
	{
		new Effect.SlideUp(obj);			
	}
	else
	{
		new Effect.BlindDown(obj);			
	}
	
}
function SlideSet2()
{
	var obj = profilediv;
	
	if (obj.style.display == "block" || obj.style.display == "")
	{
		new Effect.SlideUp(obj);			
	}
	else
	{
		new Effect.BlindDown(obj);			
	}
	
}

function hideSetting()
{
	/*var goSet = document.getElementById('goSet')
	if (goSet)
	{
		goSet.style.display='none';		
		//settingdiv.innerHTML = '<img src="/wait.gif" border="0>"';
	}*/
				
		document.getElementById("goSet").style.display="block";
		document.getElementById("resultLyr").style.display="none";
		
	if (settingdiv)
		SlideSet();
		hideProgress();
}
function hideProfile()
{				
	document.getElementById("goSet").style.display="block";
	document.getElementById("resultLyr").style.display="none";
		
	if (profilediv)
		SlideSet2();
		hideProgress();
}