/*<![CDATA[*/

//open a new window
function newin(srcurl){
	window.open(srcurl);
	return false;
}
//check all out
function CheckAll(form)  {
  for (var i=0;i<form.elements.length;i++)    {
    var e = form.elements[i];
    if (e.name != 'chkall')       e.checked = form.chkall.checked; 
   }
}


function checkspace(checkstr) {
	var str = '';
	for(i = 0; i < checkstr.length; i++) {
		str = str + ' ';
	}
return (str == checkstr);
}

//change the url
function ChangeUrl(url) {
	window.location.href = url ;
	return false;
}

//open a new window
function newWinLinks() { 
	$('a[rel=newWin]').attr('target','_blank');
} 
//switch css style
function switchStylestyle(styleName)
{
	$('link[rel*=stylesheet][title]').each(function(i) 
	{
		$(this).attr('disabled','true');
		if ($(this).attr('title') == styleName) $(this).attr('disabled','');
	});
	$.cookie('style', styleName, { expires: 365 });
}

//pageList function
function PageList(Page,TotalCount,Psize,Url,divID,pParam){
var s="";
var TotalPage;
this.pParam = pParam || 'Page';
if (!Page) { Page = 1; }	//default page
//get total page
TotalPage = (TotalCount % Psize) ? parseInt(TotalCount/Psize)+1 : TotalCount/Psize;
Page = parseInt(Page); TotalPage = parseInt(TotalPage);
	if (Url.indexOf("?") == -1)	{ Url += "?"; } else { Url += "&amp;"; }
	Url = Url.replace("&amp;&amp;","&amp;");
	Url = Url.replace("&&","&");
	//page list info
	s += 'Total:'+ TotalCount +'&nbsp;|&nbsp;Page:'+ Page +'/'+ TotalPage +'&nbsp;|&nbsp;';
	s += 'PageSize:'+ Psize +'&nbsp;|&nbsp;';
	s += '<a href="'+ Url + pParam +'=1" title="NO.1">≮ </a>';
	if (Page>5)	{ s += '<a href="'+ Url + pParam +'='+ (Page-5) +'" title="PrePara">＜</a>';	}
	
	var StartPage	= ((Page-4)>0) ? (Page-4) : 1;	//get startpage
	var EndPage		= ((Page+4)>TotalPage) ? TotalPage : (Page+4);	//get endpage
	//s += StartPage +'and'+ EndPage + 'and'+(Page+4);
	
	for (var i=StartPage; i < EndPage+1; i++) {	//format list serial
		if (i == Page) { s += '<em>'+ i +' </em>'; }
		else{ s += '<a href="'+ Url + pParam +'='+ i +'">['+ i +'] </a>'; }
	}
	if ((Page+5)<TotalPage)	{ s += '<a href="'+ Url + pParam +'='+ (Page+5) +'" title="NextPara">＞</a>'; }
	s += '<a href="'+ Url + pParam +'='+ TotalPage +'" title="EndNo.">≯</a>';

	$('#'+divID).html(s);
}


//remember/forget form infomation
function rememberMe () {
	$.cookie('3rgb_gname', $('#gname').val(), { expires: 30 });
	$.cookie('3rgb_gsite', $('#gsite').val(), { expires: 30 });
}

function forgetMe () {
	$.cookie('3rgb_gname',null);$.cookie('3rgb_gsite',null);
}
//remember calendar's year and month
function remCalendar(aY,aM) {
	$.cookie('CalendarYear', aY, { expires: 30 });
	$.cookie('CalendarMonth', aM, { expires: 30 });
}

//set cookie
function setFormCookie() {
	if ($.cookie('3rgb_gname'))
	{
	$("#gname").val($.cookie("3rgb_gname"));
	$("#gsite").val($.cookie("3rgb_gsite"));
	}
}

//get a random string
function MakePara () {
	var d, t;
	d = new Date();
	t = d.getTime();
	t = "&rand=" + t;
	return t;
}

//format a processing string
function ProcessInfo(t,id) {
	var s='';
	if (t=='txt')
	{
		s = '<div id="'+ id +'" style="text-align:center;"><span class="ProcessInfo"><img src="../images/animated_loading.gif" alt="img" />Processing...</span></div>';
	}else{
		s = '<div id="'+ id +'" style="text-align:center;"><img src="../images/loading.gif" alt="Processing..." /></div>';
	};
	return s;
}

function LoadVote(){
	$('#SiteVote').append(ProcessInfo('image','VoteLoading'));
	$.ajax({
		type:'GET',url:'vote.asp',data:'act=',cache:false,
		success:function(result){$('#SiteVote').html(result);$('#VoteLoading').remove();}	
	});
}

function ShowVoteResult() {
	try {$('#VoteLoading').remove();} catch (e){};
	$('#VotePostLine').append(ProcessInfo('image','VoteLoading'));
	$.ajax({
		type:'GET',url:'vote.asp',data:'act=',cache:false,
		success:function(result){$('#voteList').html(result)},
		error:function(){$('#voteList').text('发生错误,未取到投票数据')},
		complete:function(){$('#VoteLoading').remove();}
	});
}
function PostVote(ChkID) {
	//$('#VotePostLine').append($('#VoteForm').serialize());
	$('#VotePostLine').append(ProcessInfo('image','PostInfo'));
	$('#PostBtn').attr('disabled','true').val('提交...');
	$.ajax({
		type:'GET',url:'vote.asp',cache:false,
		data:$('#VoteForm').serialize(),
		success:function(result){
			$('#voteList').html(result);
			$('#PostBtn').val('投票成功');
			$('#VoteTxtList,#VoteImgList').toggle();
		},
		error:reportError,
		complete:function(){$('#PostInfo').remove()}
	});
}

function reportError(request)
{
alert('Sorry. There was an error.');
}


// FCKeditor_OnComplete is a special function that is called when an editor
// instance is loaded ad available to the API. It must be named exactly in
// this way.
function FCKeditor_OnComplete( editorInstance )
{
	// Show the editor name and description in the browser status bar.
	//$('eMessage').innerHTML = 'Instance "' + editorInstance.Name + '" loaded - ' + editorInstance.Description ;

	// Show this sample buttons.
	//$('eButtons').style.visibility = '' ;
}

function InsertHTML(e,inStr)
{
	var oEditor = FCKeditorAPI.GetInstance(e) ;
	if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
	{
		// Insert the desired HTML.
		oEditor.InsertHtml( inStr ) ;
	}
	else
		alert( 'You must be on WYSIWYG mode!' ) ;
}

function SetContents(e,body)
{
	var oEditor = FCKeditorAPI.GetInstance(e) ;
	oEditor.SetData( body ) ;
}

function FckFocus(e) {
	var oEditor = FCKeditorAPI.GetInstance(e);
	oEditor.Focus();
}
function GetContents(e)
{
	var oEditor = FCKeditorAPI.GetInstance(e) ;
	return oEditor.GetXHTML( true ) ;		// "true" means you want it formatted.
}

function ExecuteCommand( commandName,e )
{
	var oEditor = FCKeditorAPI.GetInstance(e) ;
	oEditor.Commands.GetCommand( commandName ).Execute() ;
}

function GetLength(e)
{
	var oEditor = FCKeditorAPI.GetInstance(e) ;
	var oDOM = oEditor.EditorDocument ;
	var iLength ;
	// The are two diffent ways to get the text (without HTML markups).
	// It is browser specific.
	if ( document.all )		// If Internet Explorer.
	{
		iLength = oDOM.body.innerText.length ;
	}
	else					// If Gecko.
	{
		var r = oDOM.createRange() ;
		r.selectNodeContents( oDOM.body ) ;
		iLength = r.toString().length ;
	}

	return iLength ;
}



//]]>
