/******************************************************************************
  Crossday Discuz! Board - Common Modules for Discuz!
  Copyright 2001-2005 Comsenz Technology Ltd (http://www.comsenz.com)
*******************************************************************************/

var sPop = null;
var postSubmited = false;
var itvl = null;
function el(a)
{
	window.open(a.href);
	return false;
}
function ctlent(event) 
{
	if(postSubmited == false && (event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83)) 
	{
		var frm = document.getElementById('input');
		if(frm.pmsubmit) 
		{
			postSubmited = true;
			frm.pmsubmit.disabled = true;
			frm.submit();
		}
		else if(validate(frm)) 
		{
			postSubmited = true;
			if(frm.topicsubmit) frm.topicsubmit.disabled = true;
			if(frm.replysubmit) frm.replysubmit.disabled = true;
			if(frm.editsubmit) frm.editsubmit.disabled = true;
			frm.submit();
		}
	}
}

function checkall(form1, prefix, checkall) {
	var checkall = checkall ? checkall : 'chkall';
	for(var i = 0; i < form1.elements.length; i++) {
		var e = form1.elements[i];
		if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
			e.checked = form1.elements[checkall].checked;
		}
	}
}

function findobj(n, d) {
	var p, i, x;
	if(!d) d = document;
	if((p = n.indexOf("?"))>0 && parent.frames.length) {
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}
	if(x != d[n] && d.all) x = d.all[n];
	for(i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	for(i = 0; !x && d.layers && i < d.layers.length; i++) x = findobj(n, d.layers[i].document);
	if(!x && document.getElementById) x = document.getElementById(n);
	return x;
}


function copycode(obj) {
	var rng = document.body.createTextRange();
	rng.moveToElementText(obj);
	rng.scrollIntoView();
	rng.select();
	rng.execCommand("Copy");
	rng.collapse(false);
}

function toggle_collapse(objname) {
	obj = findobj(objname);
	img = findobj(objname+"_img");
	collapsed = getcookie("discuz_collapse");
	cookie_start = collapsed ? collapsed.indexOf(objname) : -1;
	cookie_end = cookie_start + objname.length + 1;

	if(obj.style.display == "none") {
		obj.style.display = "";
		img_re = new RegExp("_yes\\.gif$");
		img.src = img.src.replace(img_re, '_no.gif');
		if(cookie_start != -1) collapsed = collapsed.substring(0, cookie_start) + collapsed.substring(cookie_end, collapsed.length);
	} else {
		obj.style.display = "none";
		img_re = new RegExp("_no\\.gif$");
		img.src = img.src.replace(img_re, '_yes.gif');
		if(cookie_start == -1) collapsed = collapsed + objname + " ";
	}

	expires = new Date();
	expires.setTime(expires.getTime() + (collapsed ? 86400 * 30 : -(86400 * 30 * 1000)));
	document.cookie = "discuz_collapse=" + escape(collapsed) + "; expires=" + expires.toGMTString() + "; path=/";
}

function show_ann()
{
	ann_panel.innerHTML = '<strong>论坛公告: </strong>' + ann[ann_id];
	ann_id = ann_id + 1;
	if(ann_id >= ann.length)
	{
		ann_id = 0;
	}
}

function imgzoom(o) {
	if(event.ctrlKey) {
		var zoom = parseInt(o.style.zoom, 10) || 100;
		zoom -= event.wheelDelta / 12;
		if(zoom > 0) {
			o.style.zoom = zoom + '%';
		}
		return false;
	} else {
		return true;
	}
}

function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

function gotopage(url)
{
	location.href='http://www.flyeon.com/forum/' + url;
	return false;
}
function gotosite(url)
{
	window.open(url);
	return false;
}
function openpage(url)
{
	window.open('http://www.flyeon.com/forum/' + url);
	return false;
}

function fastreply(subject)
{
	var frm = document.getElementById('input');
	if(frm)
	{
		frm.subject.value = subject;
		frm.message.focus();
	}
	return false;
}

function li(which, src)
{
	if(which.resized)
		return;
	img = new Image(); 
	img.src = src; 
	if(img.width > 700) 
	{ 
		which.style.height = parseInt(img.height * 700 / img.width) + 'px'; 
		which.style.width = '700px'; 
		img.alt='点击图片可在新窗口打开原始尺寸的图片';
	}
	else
	{
		which.style.height = img.height + 'px'; 
		which.style.width = img.width + 'px'; 
	}
	which.resized=true;
	which.src = src;
	which.style.border = '3px solid #e9edf7';
} 

function ci(img)
{
	if(!img.resized)
	{
		return true;
	}
	else
	{
		window.open('http://www.flyeon.com/services/viewpic?src=' + img.src);
	}
}

function ns()
{
	window.status = '';
	return true;
}
function showdswf(src, w, h)
{
	if(w == 0 || w >= 720)
	{
		w = 420;
	}
	if(h == 0 || h >= 600)
	{
		h = 350;
	}

	document.write('<object type="application/x-shockwave-flash" width="' + w + '" height="' + h + '" data="' + src + '">');
	document.write('<param name="movie" value="' + src + '" />');
	document.write('<embed src="' + src + '" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '"></embed>');
	document.write('</object>');
}
function showvideo(src, w, h)
{
	if(w == 0 || w >= 720)
	{
		w = 500;
	}
	if(h == 0 || h >= 600)
	{
		h = 400;
	}
	h = h + 20;
	var param = 'serving=1&amp;file=' + src;
	document.write('<object type="application/x-shockwave-flash" width="' + w + '" height="' + h + '" data="http://www.flyeon.com/services/movieplayer.swf?' + param + '">');
	document.write('<param name="movie" value="http://www.flyeon.com/services/movieplayer.swf?' + param + '" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="http://www.flyeon.com/services/movieplayer.swf?' + param + '" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '"></embed>');
	document.write('</object>');
}

function showdimg(src)
{
	document.write('<img alt="" height="0" src="' + src + '" width="0" onload="li(this, \'' + src + '\')" onclick="ci(this)" />');
}

function change_mod(cbo, tid, fid, sid)
{
	if(cbo.options[cbo.selectedIndex].value != '') 
	{ 
		if(cbo.options[cbo.selectedIndex].value != 'delpost') 
		{
			window.location=('http://www.flyeon.com/forum/topicadmin?tid=' + tid + '&fid=' + fid + '&action=' + cbo.options[cbo.selectedIndex].value+'&sid=' + sid);
		}
		else
		{
			document.getElementById('delpost').submit();
		}
	}
}

function about_discuz()
{
	var html = '<bgsound id="pmregsnd" loop="0" /><a href="http://www.discuz.com" title="访问Discuz!官方网站">Discuz! 4</a> &copy; <a href="http://www.comsenz.com" title="Discuz!是北京康盛世纪科技有限公司(Comsenz Technology Ltd)的产品">Comsenz Technology Ltd</a>';
	document.write(html);
}

function getcookie(name)
{
	var nameEQ = name + '=';
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function show_pmtreg(sep)
{
	var pmtreg = document.getElementById('pmtreg');
	if(pmtreg)
	{
		if(getcookie('pmtreg')!='no')
		{
			itvl = setInterval('pmtreg(' + sep + ', true)', 60000);
		}
	}
}

function pmtreg(sep, again)
{
	clearInterval(itvl);
	var sp = document.getElementById('pmtreg');
	if(sp)
	{
		var html = '<a href="http://www.flyeon.com/forum/" onfocus="ns()" onmouseover="return ns()" onmouseout="ns()" onclick="return onpmtreg();" rel="nofollow">';
		html = html + '<img alt="你有一条短消息" height="16" src="http://www.flyeon.com/forum/images/default/pmtreg.gif" width="16" /></a>';
		html = html + '<strong><a href="http://www.flyeon.com/forum/" onfocus="ns()" onmouseover="return ns()" onmouseout="ns()" rel="nofollow" onclick="return onpmtreg();">';
		html = html + '你有一条短消息</a></strong> ';
		if(sep == 1)
		{
			html = html + '<img alt="" height="12" src="http://www.flyeon.com/img/web/sep.gif" width="1" /> ';
		}
		sp.innerHTML = html;
		var snd = document.getElementById('pmregsnd');
		if(snd)
		{
			snd.src = 'http://www.flyeon.com/forum/images/sound/pmtreg.wav';
			if(again)
			{
				itvl = setInterval('pmtreg(' + sep + ',' + false + ')', 180000);
			}
		}
		location.href = '#';
		window.focus();
	}
}

function onpmtreg()
{
	clearInterval(itvl);
	var sp = document.getElementById('pmtreg');
	if(sp)
	{
		sp.innerHTML = '';
	}
	if(window.showModalDialog)
	{
		var pmt = window.showModalDialog('http://www.flyeon.com/forum/pmtreg?mod=1', '', 'dialogHeight: 250px; dialogWidth: 466px; help: no; scroll:no; status: no');
		if(pmt == 1)
		{
			location.href = 'http://www.flyeon.com/member/register?forward=' + escape(location.href);
		}
		else if(pmt == 2)
		{
			location.href = 'http://www.flyeon.com/member/login?forward=' + escape(location.href);
		}
	}
	else
	{
		var dlg = window.open('http://www.flyeon.com/forum/pmtreg?mod=0', 'pmtregdlg', 'toolbar=no, menubar=no, personalbar=no, width=480, height=250, scrollbars=no, resizable=no, modal=yes, dependable=yes');
	}
	return false;
}

function delicious()
{
	var url = escape(location.href);
	var title = escape(document.title);
	location.href = 'http://del.icio.us/post?url=' + url + '&title=' + title + '&notes=' + escape('来自“Flyeon - 美剧真好看”网站美剧论坛的帖子');
	return false;
}
function rfalse()
{
	return false;
}
function cfalse()
{
	window.clipboardData.setData('Text', '');
}
function set_cpt()
{
	if(document.attachEvent)
	{
		var cpt = null;
		for(var i=1; i<11; i++)
		{
			cpt = document.getElementById('cpt' + i);
			if(!cpt)
			{
				return;
			}
			cpt.attachEvent('onselectstart', rfalse);
		}
		if(document.getElementById('cpt1'))
		{
//			document.body.attachEvent('onblur', cfalse);
		}
	}
}
