var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute"
	});
	//only need force for IE6
	
	//$("#backgroundPopup").css({
		
	//});
	
}

var xmlDoc;
var html;

function showcurcity(){
	html="<table width=663>";
	if(window.ActiveXObject){
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";   
		xmlDoc.load('serverList.xml');
		html+="<tr>";
		var nodes=xmlDoc.documentElement.childNodes;
		
		for(var i=0;i<nodes.length;i++){
			html+="<td class=common >"
			html+="<a  class=zonea "
			if(nodes[i].childNodes.item(0).text==2){
				html+=">";
			}else{
				html+="href="+nodes[i].childNodes.item(2).text +" target=_blank>";
			}
			if(nodes[i].childNodes.item(0).text==1){
				html+="<img src=http://www.76park.cn/home/images/smsj_zone_chosen.gif />" ;
			}
			if(nodes[i].childNodes.item(0).text==2){
				html+="<img src=http://www.76park.cn/home/images/smsj_zone_forbit_red.gif />";
			}
			html+=nodes[i].childNodes.item(1).text;
			html+="</a> </td> ";
			if((i+1)%3==0){
				html+="</tr>"
				html+="</table>"
				html+="<table>"
				html+="<tr>"
			}
		}
		html+="</tr>"
		html+="</table>"
		//alert(html)
		document.getElementById('divServer').innerHTML = html;
	}else if(document.implementation && document.implementation.createDocument){
		var xmlHttp=new XMLHttpRequest();
		xmlHttp.open("GET", "serverList.xml", false);
		xmlHttp.send(null);
		xmlDoc=xmlHttp.responseXML;
		var url=xmlDoc.getElementsByTagName("url");
	    var txt=xmlDoc.getElementsByTagName("name");
		var status=xmlDoc.getElementsByTagName("status");
		html+="<tr>"
		for(var i=0;i<url.length;i++){
			html+="<td class=common >"
			html+="<a  class=zonea ";
			if(status[i].firstChild.data==2){
				html+=">";
			}else{
				html+="href="+url[i].firstChild.data +" target=_blank>";
			}
			if(status[i].firstChild.data==1){
				html+="<img src=http://www.76park.cn/home/images/smsj_zone_chosen.gif />" ;
			}
			if(status[i].firstChild.data==2){
				html+="<img src=http://www.76park.cn/home/images/smsj_zone_forbit_red.gif />";
			}
			html+=txt[i].firstChild.data;
			html+="</a> </td> ";
			if( (i+1)%3==0 ){
				html+="<tr/>"
				html+="</table>"
				html+="<table>"
				html+="<tr>"
		}
		}
		html+="</tr>"
		html+="</table>"
		//alert(html);
		document.getElementById('divServer').innerHTML = html;
	}
}




//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

/* 
2009.10.20 CARD-2875 官网首页选择服务器的开始游戏按钮慢的问题	

	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
*/
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
