function game_start(link) {
		checkLogin(link);
}

function ecard_start(link) {
//		checkLogin(link);
//		window.showModalDialog("ecard/ecard.htm","ecard","dialogHeight: 600px; dialogWidth: 700px; dialogTop: px; dialogLeft: px; center: Yes; help: No; edge: Raised; resizable: No; status: No; scroll:No");
		xShowModalDialog("ecard/ecard.htm","ecard","dialogHeight: 600px; dialogWidth: 700px; dialogTop: px; dialogLeft: px; center: Yes; help: No; edge: Raised; resizable: No; status: No; scroll:No");
}

function checkLogin(link) {
	var params = "act=CheckLogin";
	var url = "member_manager.php";
	var xmlHttp;

	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}

	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				if(xmlHttp.responseText==1) {
//					window.showModalDialog("final/game.htm","games","dialogHeight: 700px; dialogWidth: 920px; dialogTop: px; dialogLeft: px; center: Yes; help: No; edge: Raised; resizable: No; status: No; scroll:No");
					xShowModalDialog("final/game.htm","games","dialogHeight: 700px; dialogWidth: 920px; dialogTop: px; dialogLeft: px; center: Yes; help: No; edge: Raised; resizable: No; status: No; scroll:No");
				} else {
					window.location.href = "member_login.php?site="+link;
				}
			} else {
				alert(xmlHttp.responseText);
			}
		}
	}
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	xmlHttp.send(params);
}

function Logout(link) {
	var params = "act=Logout";
	var url = "member_manager.php";
	var xmlHttp;

	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}

	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				window.location.href = "member_login.php?site="+link;
			} else {
				alert(xmlHttp.responseText);
			}
		}
	}
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	xmlHttp.send(params);
}

function startLogin(uname, pword, remem, link) {
	var xmlHttp;
	var params = "act=Login&un="+uname+"&pw="+pword+"&remember="+remem;
	var url = "member_manager.php";
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				if(xmlHttp.responseText == 1) {
					window.location.href = link;
				} else if(xmlHttp.responseText == 2) {
					alert("Your e-mail user name is not activate ..");
				} else {
					alert("E-mail user name or Password is not found ..");
				}
			} else {
				alert(xmlHttp.responseText);
			}
		}
	}
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	xmlHttp.send(params);
}

modalWin = "null";

function xShowModalDialog( sURL, vArguments, sFeatures ) {
	dFeatures = 'dialogHeight: 450px; dialogWidth: 1049px; dialogTop: 646px; dialogLeft: 4px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;';//default features

	if (sURL==null||sURL=='') {
		alert ("Invalid URL input.");
		return false;
	}
	if (vArguments==null||vArguments==''){
		vArguments='';
	}
	if (sFeatures==null||sFeatures==''){
		sFeatures=dFeatures;
	}
//	alert("window.navigator.appVersion="+window.navigator.appVersion);
	if (window.navigator.appVersion.indexOf("MSIE")!=-1)	{
		window.showModalDialog ( sURL, vArguments, sFeatures );
		return false;
	}
	sFeatures = sFeatures.replace(/ /gi,'');
	aFeatures = sFeatures.split(";");
	sWinFeat = "directories=0,menubar=0,titlebar=0,toolbar=0,";
	for ( x in aFeatures )
	{
		aTmp = aFeatures[x].split(":");
		sKey = aTmp[0].toLowerCase();
		sVal = aTmp[1];
		switch (sKey)
		{
			case "dialogheight":
				sWinFeat += "height="+sVal+",";
				pHeight = sVal;
				break;
			case "dialogwidth":
				sWinFeat += "width="+sVal+",";
				pWidth = sVal;
				break;
			case "dialogtop":
				sWinFeat += "screenY="+sVal+",";
				break;
			case "dialogleft":
				sWinFeat += "screenX="+sVal+",";
				break;
			case "resizable":
				sWinFeat += "resizable="+sVal+",";
				break;
			case "status":
				sWinFeat += "status="+sVal+",";
				break;
			case "center":
				if ( sVal.toLowerCase() == "yes" ) {
					sWinFeat += "screenY="+((screen.availHeight-pHeight)/2)+",";
					sWinFeat += "screenX="+((screen.availWidth-pWidth)/2)+",";
				}
				break;
		}
	}
	modalWin=window.open(String(sURL),"",sWinFeat);
	if (vArguments!=null&&vArguments!='')	{
		modalWin.dialogArguments=vArguments;
	}

	addListener(this, "focus", function() { checkFocus(); });
	addListener(document, "focus", function() { checkFocus(); });
}

function checkFocus() {
	try{
		if (window.navigator.appVersion.indexOf("MSIE")==-1) {
			if (modalWin!="null") {
				if(!modalWin.closed){
					self.blur();
					modalWin.focus();
				}
			}
		}
	}
	catch(e) {alert(e);}
}

function addListener(element, event, listener, bubble) {
  if(element.addEventListener) {
    if(typeof(bubble) == "undefined") bubble = false;
    element.addEventListener(event, listener, bubble);
  } else if(this.attachEvent) {
    element.attachEvent("on" + event, listener);
  }
}


function game_match_start(link) {
		checkLogin_match(link);
}
function checkLogin_match(link) {
	var params = "act=CheckLogin";
	var url = "member_manager.php";
	var xmlHttp;

	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}

	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				if(xmlHttp.responseText==1) {
//					window.showModalDialog("final/game.htm","games","dialogHeight: 700px; dialogWidth: 920px; dialogTop: px; dialogLeft: px; center: Yes; help: No; edge: Raised; resizable: No; status: No; scroll:No");
					xShowModalDialog("final_match/game.htm","games","dialogHeight: 700px; dialogWidth: 920px; dialogTop: px; dialogLeft: px; center: Yes; help: No; edge: Raised; resizable: No; status: No; scroll:No");
				} else {
					window.location.href = "member_login.php?site="+link;
				}
			} else {
				alert(xmlHttp.responseText);
			}
		}
	}
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	xmlHttp.send(params);
}
