function resizeImg(maxWidth) {
	var contentimg = document.getElementById('ContentFrame').getElementsByTagName('img');
	for (var i = 0; i < contentimg.length; i++) {
		if (contentimg[i].clientWidth > maxWidth) {
			var rate = contentimg[i].clientWidth / contentimg[i].clientHeight;
			contentimg[i].width = maxWidth;
			contentimg[i].height = maxWidth / rate;
			contentimg[i].onclick = function() { window.open(this.src)};
			contentimg[i].alt = "点击查看原图";
			contentimg[i].style.cursor = "hand";
		}
		else {
			contentimg[i].width = contentimg[i].clientWidth;
			contentimg[i].height = contentimg[i].clientHeight;
		}
	}
}

var request;
function xmlConnect() {
	if(window.XMLHttpRequest){
		request = new XMLHttpRequest(  );
	}
	else if (window.ActiveXObject){
		request=new ActiveXObject("Microsoft.XMLHTTP");
		if (!request){  
			request=new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
}

var tmpM = 0;
var tmpS = 0;
var tmpC = 0;
function CheckMessege() {
	xmlConnect();
	var url = "scripts/CommonAjax.php?action=CheckMessege&Sessions=" + Math.random();
	request.open("GET", url, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4 && request.status == 200) {
			var result = request.responseXML.firstChild;
			/*if (result != '' && result != 'NonLogin') {
				popMsg('【您有新邮件】', '查看' , 'UserCenter.php?mode=MyMesseges&box=Recieve', 1);
				document.title = result + ' - 我俩交友网 - 单身标志 邂逅无处不在 Cute meet is possible everywhere';
				//document.write("<scr"+"ipt language=javascript src='scripts/common_popmsg.js'></scr"+"ipt>");
				//popMsg('【您有 <strong><font color=red>' + result + '</font></strong> 新消息】', '查看' , 'UserCenter.php?mode=MyMesseges&box=Recieve');
			} else {
				
			}*/
			//alert(result.childNodes[1].firstChild.nodeValue);
			tmp = "";
			if (result.childNodes[1].firstChild.nodeValue > 0) {
				if (result.childNodes[1].firstChild.nodeValue > tmpM) {
					popMsg('【您有 <strong><font color=red>' + result.childNodes[1].firstChild.nodeValue + '</font></strong> 新邮件】', '查看' , 'UserCenter.php?mode=MyMesseges&box=Recieve', 1);
				}
				document.title = '【您有 ' + result.childNodes[1].firstChild.nodeValue + ' 新邮件】 - 我俩交友网 - 单身标志 邂逅无处不在 Cute meet is possible everywhere';
				tmpM = result.childNodes[1].firstChild.nodeValue;
				return;
			}
			if (result.childNodes[2].firstChild.nodeValue > 0) {
				if (result.childNodes[2].firstChild.nodeValue > tmpM) {
					popMsg('【您有 <strong><font color=red>' + result.childNodes[2].firstChild.nodeValue + '</font></strong> 聊天邀请】', '查看' , 'UserCenter.php?mode=MyMesseges&box=ChatLog', 1);
				}
				document.title = '【您有 ' + result.childNodes[2].firstChild.nodeValue + ' 聊天邀请】 - 我俩交友网 - 单身标志 邂逅无处不在 Cute meet is possible everywhere';
				tmpS = result.childNodes[2].firstChild.nodeValue;
				return;
			}
			if (result.childNodes[3].firstChild.nodeValue > 0) {
				if (result.childNodes[3].firstChild.nodeValue > tmpM) {
					popMsg('【您有 <strong><font color=red>' + result.childNodes[3].firstChild.nodeValue + '</font></strong> 新系统消息】', '查看' , 'UserCenter.php?mode=MyMesseges&box=System', 1);
				}
				document.title = '【您有 ' + result.childNodes[3].firstChild.nodeValue + ' 新系统消息】 - 我俩交友网 - 单身标志 邂逅无处不在 Cute meet is possible everywhere';
				tmpC = result.childNodes[3].firstChild.nodeValue;
				return;
			}
		}
	}
	request.send(null);
	setTimeout(CheckMessege, 20000);
}
//window.onload = CheckMessege;
$(function() {
	CheckMessege();
})

function ReplyGM(GMID, UID, GMContent) {
	xmlConnect();
	var url = "scripts/CommonAjax.php?action=GetUserInfo&UserId=" + UID;
	request.open("GET", url, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4 && request.status == 200) {
			var result = request.responseXML.firstChild;
			var UserId = result.childNodes[0].firstChild.nodeValue;
			var UserName = result.childNodes[1].firstChild.nodeValue;
			var Avatar = result.childNodes[2].firstChild.nodeValue;
			var GenderIcon = result.childNodes[3].firstChild.nodeValue;
			var Age = result.childNodes[4].firstChild.nodeValue;
			var Location = result.childNodes[5].firstChild.nodeValue;
			var Character = result.childNodes[7].firstChild.nodeValue;
			var GMType = result.childNodes[8].childNodes[0].firstChild.nodeValue;
			var GMType_m = (GMType == "Gold") ? "/images/GoldMicrophone/MicIcon_Gold.gif" : "/images/GoldMicrophone/MicIcon_Silver.gif";
			var GMType_s = (GMType == "Gold") ? "/images/GoldMicrophone/MicIcon_Gold_s.gif" : "/images/GoldMicrophone/MicIcon_Silver_s.gif";
			document.getElementById('GetUserFrame').innerHTML = "<div style=\"width: 80px; height: 80px; overflow: hidden; margin: 2px; float: left;\"><img src=" + Avatar + " width=80 /></div><div style=\"width: 220px; overflow: hidden; margin: 2px; float: left;\"><div style=\"margin: 2px;\" align=left><strong>" + UserName + "</strong> <img src=" + GenderIcon + " /> " + Age + "</div><div style=\"margin: 2px; font-size: 12px; color: orange;\" align=left>" + Location + "</div><div style=\"margin: 2px; font-size: 12px;\" align=left>" + Character + "</div><div style=\"margin: 2px; font-size: 12px;\" align=left><a href=/space/?u=" + UserId + " target=_blank><img src=/images/button_profile.gif /></a></div></div><div style=\"width: 30px; float: left;\" align=center><img src=" + GMType_m + " /></div>";
			document.getElementById('GMContent').innerHTML = "<img src=" + GMType_s + " /> " + GMContent;
			document.getElementById('GMSubmitButton').value = "我来关心";
		} else {
			document.getElementById('GetUserFrame').innerHTML = "用户资料读取中……";	
		}
	}
	request.send(null);
	
	var w = window.document.body.offsetWidth;
	var h = window.document.body.offsetHeight;
	document.getElementById('GMShadowFrame').style.display = "";
	document.getElementById('GMShadowFrame').style.left = w / 2 - 160 + "px";
	document.getElementById('ShadowFrame').style.display = "";
	document.getElementById('ShadowFrame').style.width = w;
	document.getElementById('ShadowFrame').style.height = h;
	
	document.formgm.action = "../UserProcess.php?action=ReplyGM&GMID=" + GMID;
	
	var flashs = document.getElementsByTagName('embed');
	for (var i = 0; i < flashs.length; i++) {
		flashs[i].style.display = "none";
	}
}
function CloseGM() {
	document.getElementById('ShadowFrame').style.display = "none";
	document.getElementById('GMShadowFrame').style.display = "none";
	
	var flashs = document.getElementsByTagName('embed');
	for (var i = 0; i < flashs.length; i++) {
		flashs[i].style.display = "";
	}
}
function checkGMForm() {
	var f = document.formgm;
	if (f.messege.value.length > 12 || f.messege.value == "") {
		alert("您输入的留言长度不正确，不能为空或超过12个汉字");
		f.messege.focus();
		return false;
	} else {
		return true;
	}
	return false;
}

function ArticleUp(id) {
	xmlConnect();
	var url = "scripts/CommonAjax.php?action=ArticleUp&ArticleId=" + id + "&Sessions=" + Math.random();
	request.open("GET", url, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4 && request.status == 200) {
			var result = request.responseText;
			if (!isNaN(result)) {
				document.getElementById("ArticleUpShow").innerHTML = result;
				alert('感谢您的关注');
			} else {
				alert('参数错误');
			}
		}
	}
	request.send(null);
}

function ArticleDown(id) {
	xmlConnect();
	var url = "scripts/CommonAjax.php?action=ArticleDown&ArticleId=" + id + "&Sessions=" + Math.random();
	request.open("GET", url, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4 && request.status == 200) {
			var result = request.responseText;
			if (!isNaN(result)) {
				document.getElementById("ArticleDownShow").innerHTML = result;
				alert('感谢您的关注');
			} else {
				alert('参数错误');
			}
		}
	}
	request.send(null);
}


