﻿addLoadEvent(onloadVerifyFile);
addLoadEvent(SubmitMessage);
addLoadEvent(MessageList);
addLoadEvent(HrList);
addLoadEvent(Guestbook);

function Guestbook()
{
	var oPost=document.getElementById("guestbook_please")
	var oFormGuestBook=document.getElementById("guestbook_post")
	if (!oPost) return false;
	if (!oFormGuestBook) return false;
	oFormGuestBook.style.display ='none';
	oPost.onclick=function()
	{
		oFormGuestBook.style.display ='block';
	}
}
function HrList()
{
	var oHrList = document.getElementById('HrList');
	if (oHrList)
	{
		var oA = oHrList.getElementsByTagName('a');
		oA[0].parentNode.getElementsByTagName('div')[0].style.display ='block';
		for (var i = 0; i < oA.length; i++)
		{
			if (oA[i].getAttribute("rel") == "ALink")
			{
				oA[i].onclick = function()
				{
					var oA = document.getElementById('HrList').getElementsByTagName('a');
					for (var j = 0; j < oA.length; j++)
					{
						if (oA[j].getAttribute("rel") == "ALink")
						{
							oA[j].parentNode.getElementsByTagName('div')[0].style.display ='none';
						}
					}
					this.parentNode.getElementsByTagName('div')[0].style.display ='block';
					return false;
				}
			}
		}
	}
}

function MessageList()
{
	var oInof = document.getElementById('guestbook_info');
	if (!oInof) return false;
	InfoNone();
	var oStrong = oInof.getElementsByTagName('strong');
	oStrong[0].parentNode.getElementsByTagName('ul')[0].style.display ='block';
	for (var i=0;i<oStrong.length;i++)
	{
		oStrong[i].onclick=function()
		{
			InfoNone();
			this.parentNode.getElementsByTagName('ul')[0].style.display ='block';
		}
	}
}
function InfoNone()
{
	var oInof = document.getElementById('guestbook_info');
	if (!oInof) return false;
	var oStrong = oInof.getElementsByTagName('strong');
	for (var i=0;i<oStrong.length;i++)
	{
		oStrong[i].parentNode.getElementsByTagName('ul')[0].style.display ='none';
	}
}

function SubmitMessage()
{
	var oMessageBoard = document.forms["messageBoard"];

	if (typeof oMessageBoard != 'undefined')
	{
		var oName = oMessageBoard.elements["Name"];
		var oTitle = oMessageBoard.elements["Title"];
		var oContent = oMessageBoard.elements["Content"];
		var oVerifyCode = oMessageBoard.elements["VerifyCode"];
		
		oMessageBoard.onsubmit = function()
		{
			var sMessage = "";
			if (oName.value == "")
			{
				sMessage = sMessage + "\n請輸入留言者姓名";
			}
			else if (oName.value.length > 5)
			{
				sMessage = sMessage + "\n姓名不能多於5個字";
			}

			if (oTitle.value == "")
			{
				sMessage = sMessage + "\n請輸入標題";
			}
			else if (oTitle.value.length > 20)
			{
				sMessage = sMessage + "\n標題不能多於20個字";
			}

			if (oContent.value == "")
			{
				sMessage = sMessage + "\n請輸入留言內容";
			}

			if (oVerifyCode.value == "")
			{
				sMessage = sMessage + "\n請輸入驗證碼";
			}

			if (sMessage != "")
			{
				alert(sMessage);
				return false;
			}
			return true;
		}
	}
	return true;
}

function swf_obj(src,w,h,swfid){
	swf_html = '';
	swf_html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'" id="'+swfid+'" align="middle">';
	swf_html += '<param name="allowScriptAccess" value="always">';
	swf_html += '<param name="movie" value="'+src+'">';
	swf_html += '<param name="quality" value="high">';
	swf_html += '<param name="bgcolor" value="#ffffff">';
	swf_html += '<PARAM NAME="wmode" value="transparent">';
	swf_html += '<embed src="'+src+'" quality="high" bgcolor="#ffffff" width="'+w+'" height="'+h+'" name="'+swfid+'" align="middle" allowScriptAccess="always" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
	swf_html += '</object>';
	document.write(swf_html);
}

//外部链接
document.onclick = function(e)
{
	var target = e ? e.target : window.event.srcElement;
	while (target && !/^(a|body)$/i.test(target.nodeName))
	{
		target = target.parentNode;
	}
	if (target && target.getAttribute('rel') && target.rel == 'external')
	{
		var external = window.open(target.href);
		return external.closed;
	}
}

//加载及刷新验证码
function onloadVerifyFile()
{
	var verifycode = document.getElementById('verifycode');
	if (!verifycode) return false;
	verifycode.onfocus = function()
	{
		var getcode = document.getElementById('getcode');
			if (!getcode)
			{
				getcode = document.createElement("img");
				getcode.setAttribute("alt", "点击刷新验证码");
				getcode.setAttribute("src", "getcode.asp");
				getcode.setAttribute("id", "getcode");
				verifycode.parentNode.appendChild(getcode);
				getcode.onclick = function ()
				{
					this.setAttribute('src',this.src.split('?')[0]+'?t='+Math.random());
				}
			}
	}
}
function click(e) {
 if (document.all) {
  if (event.button==1||event.button==2||event.button==3) {
   oncontextmenu='return false';
  }
 }
 if (document.layers) {
  if (e.which == 3) {
   oncontextmenu='return false';
  }
 }
}
if (document.layers) {
 document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
document.oncontextmenu = new Function("return false;")

var travel=true
var hotkey=17   /* hotkey即为热键的键值,是ASII码,这里99代表c键 */
if (document.layers)
document.captureEvents(Event.KEYDOWN)
function gogo(e)
{ if (document.layers) {
if (e.which==hotkey&&travel){
 alert("操作错误.或许是您按错了按键!");  } }
else if (document.all){
if (event.keyCode==hotkey&&travel){ alert("操作错误.或许是您按错了按键!"); }}
}
document.onkeydown=gogo
//监听事件
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
