function makeRequest(url) {

	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			// http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html; charset=utf-8');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = function() { alertContents(http_request); };
	http_request.open('GET', url, true);
	http_request.send(null);

}

function alertContents(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			//alert(http_request.responseText);
			var result = http_request.responseText;
			
			document.getElementById("wok_server").innerHTML = result;
			
		} else {
			//alert('There was a problem with the request.');
		}
	}
}

function CloseSmallDiv(){
	parent.document.getElementById("main_content").style.display = "";
	if(parent.document.getElementById('toHide').style.visibility!='hidden'){
		parent.document.getElementById("toHide").style.visibility = "hidden";
		parent.document.getElementById("div_content").style.visibility = "hidden";
		window.location.href = "wait.html";
		parent.document.getElementById("div_header").style.display = "";
		parent.document.getElementById("div_games").style.display = "";
		
		if(parent.document.frames['login'].document.getElementById("div_latest_chi")){
			parent.document.frames['login'].document.getElementById("div_latest_chi").style.display = "";
		}else if(parent.document.frames['login'].document.getElementById("div_latest_eng")){
			parent.document.frames['login'].document.getElementById("div_latest_eng").style.display = "";
		}
		parent.document.frames["login"].location.href = "main.php?sec=login";
	}
}

function Main(){
	//alert(parent.document.forms["frmID"]);
	//if(!parent.document.forms["frmID"]){
	if(!parent.document.frmID){
		window.location = 'index.php';
	}else{
		//var id = parent.document.forms["frmID"].ID.value;
		var id = parent.document.frmID.ID.value;
		if(id!='MyCNX'){
			window.location = 'index.php';
		}
	}	
}

function Main2(){
	//if(!parent.parent.document.forms["frmID"]){
	if(!parent.parent.document.frmID){
		window.location = 'main.php?sec=shutdown';
	}else{
		//var id = parent.parent.document.forms["frmID"].ID.value;
		var id = parent.parent.document.frmID.ID.value;
		if(id!='MyCNX'){
			window.location = 'main.php?sec=shutdown';
		}
	}	
}

function ShowNews(id){
	var url = 'news.php?nid='+id;
	PopUP(url,'500','600','yes');
}

function SHOW(){
	var pagesize    = new parent.getPageSize();
	var page_width  = pagesize.width;
	var page_height = pagesize.height;
	
	var div_content_height = 560;
	var div_content_height = 567;
	
	parent.document.getElementById('div_content').style.top  = ((page_height-div_content_height)/2)+'px';
	parent.document.getElementById('div_content').style.left  = ((page_width-div_content_height)/2)+'px';
	parent.document.getElementById("div_content").style.visibility = "";
	parent.document.getElementById("div_loading").style.visibility = "hidden";
}

function MyCNX(){
	window.status=''; 
}

function frmLogout(){
	frmlogout.action_task.value = 'Logout';
	document.frmlogout.submit();
}

function frmCart(){
	document.getElementByID('cart_div').style.display="block";
}

function BPRedeem(id){
	openDiv('BPRedeemItem&itemid='+id);	
}

function frmBPRedeemConfirm(id){
	frmBPRedeem.itemid.value = id;
	frmBPRedeem.action_task.value = 'BPRedeem';
	//document.forms['frmBPRedeem'].submit();
	document.frmBPRedeem.submit();
}

function openDiv(sec){
	var pagesize    = new parent.getPageSize();
	var page_width  = pagesize.width;
	var page_height = pagesize.height;
	var div_content_height = 560;
	var div_content_height = 567;

	if(parent.document.getElementById('toHide').style.visibility=='hidden'){
		parent.document.getElementById("div_loading").style.visibility = "";
		parent.document.getElementById('div_loading').style.top  = ((page_height-div_content_height)/2)+'px';
		parent.document.getElementById('div_loading').style.left  = ((page_width-div_content_height)/2)+'px';

                var ibox_op_level = 8;
		setIboxOpacity = setOpacity;
		for (var i=0;i<=ibox_op_level;i++) { setTimeout("setIboxOpacity("+i+")",40*i); }
		parent.document.getElementById("frm").src = "main.php?sec="+sec;

		parent.document.getElementById('table1').style.width  = (page_width)+'px';
		parent.document.getElementById("toHide").style.visibility = "";
		parent.document.getElementById("div_header").style.display = "none";
		parent.document.getElementById("div_games").style.display = "none";
		//if(parent.document.frames['login'].document.getElementById("div_latest_chi")){
		if(parent.document.login.document.getElementById("div_latest_chi")){
			//parent.document.frames['login'].document.getElementById("div_latest_chi").style.display = "none";
			parent.document.login.document.getElementById("div_latest_chi").style.display = "none";
		//}else if(parent.document.frames['login'].document.getElementById("div_latest_eng")){
		}else if(parent.document.login.document.getElementById("div_latest_eng")){
			//parent.document.frames['login'].document.getElementById("div_latest_eng").style.display = "none";
			parent.document.login.document.getElementById("div_latest_eng").style.display = "none";
		}
		parent.document.getElementById("div_content").style.visibility = "";
		
		parent.document.getElementById("main_content").style.display = "none";
		
	}

}

setOpacity = function (value)	{
		var e = parent.document.getElementById('toHide');
		e.style.opacity = value/10;  
		e.style.filter = 'alpha(opacity=' + value*10 + ')';
}

function ProfileUpdate(){
	frmProfile.action_task.value = 'Profile_Update';
	frmProfile.submit();	
}

function AddGameAcc(id){
	window.location = 'main.php?sec=game_account&GameID='+id+'&task=add';
}

function GameAccAdd(id){
	frmGameAccAdd.action_task.value = 'GameAccount_Add';
	frmGameAccAdd.gameid.value = id;
	frmGameAccAdd.submit();	
}

function GameActivate(id){
	window.location = 'main.php?sec=games_activate&GameID='+id;
}

function GameActivate2(id){
	frmGameActivation.action_task.value = 'GameActivation';
	frmGameActivation.gameid.value = id;
	frmGameActivation.submit();
}

function CheckGameAccount(user,id,lang){
	if(user && id && lang){
		var url = 'info_account/ajax_check_game_account.php?username='+user+'&gameid='+id+'&lang='+lang;
		makeRequest(url);
	}
}

function GameRedeem(id){
	window.location = 'main.php?sec=games_redeem&GameID='+id;	
}

function ItemRedeem(id){
	frmItemRedeem.action_task.value = 'ItemRedeem';
	frmItemRedeem.GameID.value = id;
	frmItemRedeem.submit();
}

function Change_Password(){
	window.location = 'main.php?sec=profile_pass';
}

function PasswordUpdate(){
	frmPassword.action_task.value = 'Password_Update';
	frmPassword.submit();
}

function AddToCart(itemid){
	if(itemid){
		frmShopCart.ItemID.value = itemid;
		frmShopCart.action_task.value = 'AddToCart';
		frmShopCart.submit();
	}
}

function RemoveFrmCart(frm,itemid){
	if(itemid){
		var res= confirm('Remove ?');
		if(res){
			frm.ItemID.value = itemid;
			frm.action_task.value = 'RemoveFrmCart';
			frm.submit();
		}
	}
}

function CartCalculate(){
	frmCalculate.action_task.value = 'CalculateCart';
	frmCalculate.submit();
}

function CartConfirm(){
	var action_stop = 'N';
	if(frmConfirm.wok){
	  if(frmConfirm.wok.value){
		if(frmConfirm.server.value && frmConfirm.gameuid_5.value){
			action_stop = 'N';
		}else{
			action_stop = 'Y';
		}
	  }
	}
	//alert(action_stop);
	if(action_stop=='N'){
		frmConfirm.action_task.value = 'ConfirmCart';
		frmConfirm.submit();
	}
}

function CartComplete(){
	frmComplete.action_task.value = 'CompleteCart';
	frmComplete.submit();
}

function PaymentTopup(lang){
	//frmTopup.action = 'http://payment.mycnx.com/meps/main.php?lang='+lang;
	frmTopup.action = 'http://fpx.mycnx.com/main.php?lang='+lang; // Modified by Edison Choong 20090514 1725	
	frmTopup.action_task.value = 'Topup_meps';
	frmTopup.submit();
}

function ClubActivation(){
	if(!frmClub.Card_no.value){
	alert('Please fill in the code!');
	}else if(!frmClub.Card_pin.value){
	alert('Please fill in the pin!');
	}else{
		frmClub.action_task.value = 'ClubActivation';
		frmClub.submit();
	}
}

function ClubUpdate(){
	frmClub.action_task.value = 'ClubUpdate';
	frmClub.submit();		
}

function PopUP(url,height,width,fix){
	window.open(url,'','height='+height+',width='+width+',toolbar=no,menubar=no,location=no,status=no,scrollbars='+fix);
}

function to_char(num){				
	if(num){
		document.frames['charname'].location="main_.php?sec=char_wok&serverid="+num;
		frmConfirm.serverid_5.value = num;
	}
}