﻿function display(id){
	var div=document.getElementById(id);
	div.style.visibility='visible';
	div.style.display='';
}
function hidden(id){
	var div=document.getElementById(id);
	div.style.visibility='hidden';
	div.style.display='none';
}
function FormToString (form) {
  var elements = form.elements;// Enumeration the form elements
  var element;
  var i;
  var postContent = "";// Form contents need to submit

  for(i=0;i<elements.length;++i) {
	var element=elements[i];

	if(element.type=="text" || element.type=="textarea" || element.type=="hidden") {
	  postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
	}
	else if(element.type=="select-one"||element.type=="select-multiple") {
	  var options=element.options,j,item;
	  for(j=0;j<options.length;++j){
		item=options[j];
		if(item.selected) {
			postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(item.value) + "&";
		}
	  }
	} else if(element.type=="checkbox"||element.type=="radio") {
	  if(element.checked) {
			postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
		}
	} else if(element.type=="file") {
		if(element.value != "") {
			postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
		}
	} else {
			postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
	}
  }
  return postContent;
}
function help(id){
	Dialog.alert
		(
		 	{url: '/Support/?randoms='+Math.random()+'&id='+id , options: {method:'get'}}, 
            {
				className: "alphacube", width:540, okLabel:"关闭继续", 
				minimizable: false, closable: true, draggable: true, wiredDrag: true,
				showEffect:Effect.Grow, hideEffect: Effect.Shrink
			}
		);
}
function ShowOtherEvent(EventID) {
	Dialog.alert({url: "exec_ViewLogs_Logs.asp?randoms=" + Math.random() + "&EventID=" + EventID, options: {method: 'get'}}, 
            {className: "alphacube", width:540, okLabel:"关闭提示", 
			minimizable: false, closable: true, draggable: true, wiredDrag: true,
			showEffect:Effect.Grow, hideEffect: Effect.Shrink});
}
function ShowTempEvent(UserID) {
	Dialog.alert({url: "exec_ViewLogs_Temp.asp?randoms=" + Math.random() + "&UserID=" + UserID, options: {method: 'get'}}, 
            {className: "alphacube", width:540, okLabel:"关闭提示", 
			minimizable: false, closable: true, draggable: true, wiredDrag: true,
			showEffect:Effect.Grow, hideEffect: Effect.Shrink});
}
function ViewSiteLogs(CheckID) {
	Dialog.alert({url: "exec_SiteManager_ViewLogs.asp?randoms=" + Math.random() + "&CheckID=" + CheckID, options: {method: 'get'}}, 
            {className: "alphacube", width:550, okLabel:"关闭日志窗口", 
			minimizable: false, closable: true, draggable: true, wiredDrag: true,
			showEffect:Effect.Grow, hideEffect: Effect.Shrink});
}
function WindowsPostTo(Url, form_obj) {
	Dialog.confirm
		(
		 	{url: Url , options: {method:'post', postBody:FormToString(form_obj)}}, 
            {
				className: "alphacube",
				width:500, 
				okLabel:"返回继续修改", 
				cancelLabel:"退出修改", 
				minimizable: false, closable: true, draggable: true, wiredDrag: true,
				showEffect:Effect.Grow, hideEffect: Effect.Shrink,
				onCancel:function(win){top.location.reload(); return true;}
			}
		);
}
function WebPostTo(Url, form_obj, isButton) {
	form_obj.button.disabled=true;
	Dialog.alert
		(
		 	{url: Url , options: {method:'post', postBody:FormToString(form_obj)}}, 
            {
				className: "alphacube", width:540, okLabel:"关闭提示", 
				minimizable: false, closable: true, draggable: true, wiredDrag: true,
				showEffect:Effect.Grow, hideEffect: Effect.Shrink, 
				onClose:function(win){form_obj.button.disabled=false; return true;}
			}
		);
}
function GoBuyTimes(CheckID) {
	var win = new Window
	(
		{
		 url: "exec_SiteManager_GoBuyTimes.asp?CheckID=" + CheckID + "&randoms" + Math.random(), 
		 className: "alphacube",  width:380, height:300, zIndex: 100, maximizable: false, resizable: false, 
		 title: "待监测网站续费", showEffect:Effect.Grow, hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true
		}
	)
	win.showCenter();        
}
function ChangeStatus(CheckID,IsOK) {
	Dialog.alert
		(
		 	{url: "exec_SiteManager_ChangeStatus.asp?CheckID="+CheckID+"&IsOK="+IsOK+"&randoms="+Math.random() , options: {method:'get'}}, 
            {
				className: "alphacube", width:460, okLabel:"关闭提示", 
				minimizable: false, closable: true, draggable: true, wiredDrag: true,
				showEffect:Effect.Grow, hideEffect: Effect.Shrink, 
				onClose:function(win){top.location.reload(); return true;}
			}
		);
}

//关于添加网站和修改网站的相关函数
function DownloadTestFile() { //下载验证文件
	window.location.href="exec_SiteManager_TestCheckUrl.asp?act=download&randoms="+Math.random();
}
function CheckUrl_Process() 
{
	isReal=false;
	if(AjaxObj.readyState == 4) 
	{ 
		if(AjaxObj.status == 200) 
		{ 
			if(AjaxObj.responseText != "") 
			{ 
				if (AjaxObj.responseText=="succeed") {
					isReal=true;
				}
			}
		}
	}
	
	if (isReal) { //收到信息，并提验证成功
		document.getElementById("TestSiteUrl").innerHTML="<img src='/images/url_ok.gif' barder=0 align='absmiddle' alt='验证成功'>";
		isBusys = false;
		return false;
	} else {
		document.getElementById("TestSiteUrl").innerHTML="<img src='/images/url_err.gif' barder=0 align='absmiddle' alt='验证失败'> <b>[</b><a href='javascript:TestCheckUrl();'>重试</a><b>]</b> <a href=\"javascript:help('testsite');\"><img src=\"/images/what.gif\" border=0 alt=\"怎样验证网站？\" /></a>";
		isBusys = false;
		return false;
	}
} 
var isReal;//已经验证通过
var timerId = -1;
var isBusys = false;
function TestCheckUrl() {
	var UrlStr = document.getElementById("CheckUrl").value;
	if(!isBusys){
		isBusys = true;
		AjaxObj = getXMLHTTPRequest(); 
		AjaxObj.onreadystatechange = CheckUrl_Process;
		AjaxObj.open("get","exec_SiteManager_TestCheckUrl.asp?CheckUrl=" + UrlStr + "&randoms="+Math.random(),true); 
		AjaxObj.setRequestHeader('Content-type','application/x-www-form-urlencoded'); 
		AjaxObj.send(); //发送数据
		document.getElementById("TestSiteUrl").innerHTML="<img src='/images/loading.gif' barder=0 align='absmiddle'>";
	}
}
function isChangedCheckUrl() {//网址已经改变
	isReal=false;
	document.getElementById("TestSiteUrl").innerHTML="<b>[</b><a href='javascript:TestCheckUrl();'>立即验证</a><b>]</b> <a href=\"javascript:help('testsite');\"><img src=\"/images/what.gif\" border=0 alt=\"怎样验证网站？\" /></a>";
}

function AddSite() {
	if(isReal){
		WebPostTo('exec_SiteManager_CheckSiteSetup.asp?&randoms='+Math.random(),ajaxform);
	} else {
		if (window.confirm("您尚未“验证网站”不能提交，如果您不知道“如何验证”网站，请点击确定按钮查看帮助。")){help('testsite');}
	}
}
function CheckSiteSetup(CheckID) {
	Dialog.confirm
		({url: "exec_SiteManager_CheckSiteSetup.asp?randoms=" + Math.random() + "&CheckID=" + CheckID, options: {method: 'get'}}, 
            {
				className: "alphacube", 
				width:590, 
				okLabel:"提交保存", 
				cancelLabel:"暂不变更",
				minimizable: false, closable: true, draggable: true, wiredDrag: true,
				showEffect:Effect.Grow, hideEffect: Effect.Shrink,
				//提交表单
				onOk:function(win){
					WindowsPostTo('exec_SiteManager_CheckSiteSetup.asp?&randoms='+Math.random(),ajaxform);
					return false;
				}
			}
		);
}

function register() {
	WebPostTo("/comm/register.asp?randoms=" + Math.random() , ajaxform);
}

document.writeln("<link rel=\"stylesheet\" type=\"text\/css\" href=\"\/Include\/windows\/themes\/default.css\" \/>");
document.writeln("<link rel=\"stylesheet\" type=\"text\/css\" href=\"\/Include\/windows\/themes\/alphacube.css\" \/>");
document.writeln("<script type=\"text\/javascript\" src=\"\/Include\/windows\/prototype.js\"><\/script>");
document.writeln("<script type=\"text\/javascript\" src=\"\/Include\/windows\/effects.js\"><\/script>");
document.writeln("<script type=\"text\/javascript\" src=\"\/Include\/windows\/window.js\"><\/script>");
document.writeln("<script type=\"text\/javascript\" src=\"\/Include\/windows\/debug.js\"><\/script>");

