﻿var winWidth = 0; 
var winHeight = 0; 
window_height = 0;
window_width = 0;

function findDimensions() //函数：获取尺寸
{ 
	//获取窗口宽度 
	if (window.innerWidth) 
		winWidth = window.innerWidth; 
	else if ((document.body) && (document.body.clientWidth)) 
		winWidth = document.body.clientWidth; 

	//获取窗口高度 
	if (window.innerHeight) 
		winHeight = window.innerHeight; 
	else if ((document.body) && (document.body.clientHeight)) 
		winHeight = document.body.clientHeight; 

	//通过深入Document内部对body进行检测，获取窗口大小 
	if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth){ 
		winHeight = document.body.clientHeight; 
		winWidth = document.documentElement.clientWidth; 
	} 

	winHeight_2 = document.body.scrollHeight;
	
	//刷新背景
	document.getElementById("background").style.top = 0 +"px";
	document.getElementById("background").style.left = 0 +"px";
	document.getElementById("background").style.width = winWidth +"px";
	document.getElementById("background").style.height = winHeight_2 +"px";
	//刷新窗口位置
	document.getElementById("window").style.height = window_height +"px";
	document.getElementById("window").style.width = window_width +"px";
	document.getElementById("window").style.top = (winHeight - window_height)/2>20?(winHeight - window_height)/2+"px": 20+"px";
	document.getElementById("window").style.left = (winWidth - window_width)/2 +"px";
	
} 

function $(a){return document.getElementById(a)}

//调用函数，获取数值 



function closewindow(){
	window.onresize="";
	document.getElementById("engine").src= "about:blank";
	document.getElementById("background").style.display = "none";
	document.getElementById("window").style.display = "none";
}



function jumpwindow(strTemp,closewindow){
	scroll(0,0);
	window.onresize=findDimensions;
	if (closewindow==true) {
		$('closewindow').innerHTML = '<a href="javascript:void(0);" onclick="javascript:closewindow();" style="color:#000;text-decoration : none;font-weight : bold;font-family:宋体;">×</a>';}
	else
	{
		$('closewindow').innerHTML = '&nbsp;';
	}
	document.getElementById("background").style.display = "";
	document.getElementById("window").style.display = "";
	document.getElementById("engine").src = strTemp;
	//findDimensions();
}

function changewindowsize(w,h){
	window_height = h;
	window_width = w;
	document.getElementById("engine").width=w-12;
	document.getElementById("engine").height=h-25;
	findDimensions();
	refIframe('loading');
}

function jumpwithoutwindow(strTemp){
	document.getElementById("engine").src = strTemp;
}

function refIframe (sw) {
	switch (sw)
	{
		case 'loading':
			document.getElementById('engine').style.visibility='hidden';
			document.getElementById('window').style.background ='url(Public/images/loading.gif) no-repeat center center';
			document.getElementById('window').style.backgroundColor = '#ffffff';
			break;
		case 'sending':
			window.top.document.getElementById('engine').style.visibility='hidden';
			window.top.document.getElementById('window').style.background ='url(Public/images/sending.gif) no-repeat center center';
			window.top.document.getElementById('window').style.backgroundColor = '#ffffff';
			
			break;
		case 'onload':
			document.getElementById('engine').style.visibility='visible';
			break;
	}
	
}





/*
	for action sendmsg
	*/

function sendmsg () {
	refIframe('sending');
	document.submit_form.submit();
	

}
function sendmsg2 () {
	refIframe('sending');
	document.submit_form2.submit();
	

}
function complete () {
	alert(ThinkAjax.updateTip);
}

var submited = false;
function checkSubmit()
{
	var email = document.postcomment.email.value;
	var pattern=/^([a-zA-Z0-9])+@([a-zA-Z0-9])+\.([a-zA-Z0-9])+/; 
	flag = pattern.test(email); 
	if(document.postcomment.name.value==""){
		alert("姓名不能为空！");
		document.postcomment.name.focus();
		return false;
	}else if(document.postcomment.comment.value==""){
		alert("评论不能为空！");
		document.postcomment.comment.focus();
		return false;
	}else if(!flag){
		alert("请填写正确的信箱！");
		document.postcomment.email.focus();
		return false;
	}else
	{
		if (!submited)
		{
			unresubmit();
			SetCookie2("email",document.postcomment.email.value,999999999);
			SetCookie2("name",document.postcomment.name.value,999999999);
			document.postcomment.submit;
		}
    }
}
function loadname () {
	document.postcomment.email.value = GetCookie("email")==null?"":GetCookie("email");
	document.postcomment.name.value = GetCookie("name")==null?"匿名网友":GetCookie("name");
	
}
function unresubmit () {
	timeout = 10000;
	$('submit').style.display="none";
	$('comment_re_text').innerHTML = '<span style="color:#0088cc;">正在发送...</span>	';
	submited = true;
	setTimeout("submited = false",timeout);
	setTimeout("$('submit').style.display=''",timeout);
	setTimeout("$('comment_re_text').innerHTML = ''",timeout);
}
function unresubmit_off () {
	submited = false;
	$('submit').style.display='';
	$('comment_re_text').innerHTML = '';
}
function clearCommentForm(name,myip,text,date)
{
	$('comment').value='';
	comment_re_close();
	alert('发表成功！\n由于缓存的原因，您的发言将稍后显示。');
	$('thiscomment').style.display='';
	$('thiscomment_name').innerHTML = name + '<span style="color:#999999;" id="thiscomment_ip"></span>';
	$('thiscomment_ip').innerHTML = '['+myip+']';
	$('thiscomment_text').innerHTML = text;
	$('thiscomment_date').innerHTML = date;
	unresubmit_off();
    window.location.hash="thiscomment";
}

function comment_re (commentintro, commentid, commentx, comment_f, name) {
	document.postcomment.name.focus();
	document.postcomment.comment.focus();
	$('comment_id').value = commentid;
	$('comment_x').value = commentx;
	$('comment_f').value = comment_f;
	$('comment_re_text').innerHTML = '<div class="comment_re_text"><strong>回复'+comment_f+'楼:['+name+']</strong> <a href="javascript:void(0)" onclick="javascript:comment_re_close();" style="color:#999999;">取消回复</a><br />'+commentintro+'</div>';
}

function comment_re_close () {
	$('comment_id').value = '';
	$('comment_x').value = '';
	$('comment_f').value = '';
	$('comment_re_text').innerHTML = '';
}
function GetCookie(name){
	//获得Cookie的原始值
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return GetCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
function GetCookieVal(offset){
	//获得Cookie解码后的值
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape	(document.cookie.substring(offset, endstr));
}
function SetCookie2(sName, sValue, iTime){ 
	var date = new Date(); 
	date.setTime(date.getTime()+iTime*1000);
	document.cookie = escape(sName) + "=" + escape(sValue) + "; expires=" + date.toGMTString(); 
} 
document.write('<div style=" position : absolute;background-color : black;z-index : 1;visibility : visible;filter:alpha(opacity=50);/* IE */ -moz-opacity:0.5;/* Moz + FF */ opacity: 0.5;/* 支持CSS3的浏览器（FF 1.5也支持）*/ " id="background" onclick="javascript://closewindow();" ></div>');
document.write('<div style="width : 100px;height : 100px;top : -1050px;left : -500px;position : absolute;background-color : #ffffff;z-index : 1;visibility : visible;border-width : 5px;border-style : solid;border-color : #666;" id="window"><p align="right" style="font-size:12px;margin:3px 3px 3px 0;" id="closewindow"><a href="javascript:void(0);" onclick="javascript:closewindow();" style="color:#000;text-decoration : none;font-weight : bold;font-family:宋体;">×</a></p><center><IFRAME id="engine" width="370" height="200" marginwidth="0" marginheight="0" hspace="0" vspace="0"   frameborder="0" scrolling="auto" src="about:blank" class="engineIframe" name="engine2" align="absmiddle" style="visibility:hidden;background-color:#ffffff;" onload="javascript:refIframe(\'onload\')"></IFRAME></center></div>');


