var EndFlag = 1;
var gUserId = 0;
var gUserAccount = "";
var AJAX_RETURN_SUCC = "AJAX_SUCC";
var AJAX_RETURN_ERROR = "AJAX_ERROR";

function MM_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=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById)x=document.getElementById(n);return(x);
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MSHL()
{
	var i,p,v,obj,args=MSHL.arguments;
	for(i=0;i<(args.length-2);i+=3)if((obj=MM_findObj(args[i]))!=null){v=args[i+2];
	if(obj.style){obj=obj.style;v=(v=='show')?'visible':(v='hide')?'hidden':v;}
			 obj.visibility=v;}
}

// 根据ID取对象
function GetElem(elemId)
{
	return (document.getElementById) ? document.getElementById(elemId) : document.all[elemId];
}

// 获得字符串的长度(一个全角字符当作2个字符)
function GetStrLength(s)
{
	var sum=0;
	for(var i=0;i<s.length;i++)
		if ((s.charCodeAt(i)>=0) && (s.charCodeAt(i)<=255)) sum=sum+1;
		else sum=sum+2;
	return sum;
}

function fPopUpCalendarDlg(ctrlobj)
{
	showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
	showy = event.screenY - event.offsetY -168; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	retval = window.showModalDialog("../html/Calendar.html", "", "dialogWidth:170px; dialogHeight:190px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	if( retval != null ){
		ctrlobj.value = retval;
	}else{
		//alertCUI("canceled");
	}
}

//取url中的参数字符
function GetUrlParam(name)
{
	var input = document.location.href.split('#')[0];
	var result = input.replace(/\?/g," ").replace(/\&/g," ");
	var items = result.split(' ');
	var m = new RegExp("^" + name + "=","i");
	var param = "";
	for(var i=0;i<items.length;i++)
	{
		var temp = items[i];
		temp = temp.replace(/\s/g,"");
		if(temp=="")
			continue;
		if(temp.match(m))
		{
			if(param!="")
			param += ",";
			param += temp.replace(m,"");
		}
	}
	 
	return param;
} 

// 复制文字到剪贴板
function Clip(text)
{
	clipboardData.setData('text', text); 
}

// 问候语提示
function ShowHello() {
	var welcomestring;
	var d = new Date();	
	h = d.getHours();
	if(h<6)
		welcomestring="凌晨好";
	else if (h<9)
		welcomestring="早上好";
	else if (h<12)
		welcomestring="上午好";
	else if (h<14)
		welcomestring="中午好";
	else if (h<17)
		welcomestring="下午好";
	else if (h<19)
		welcomestring="傍晚好";
	else if (h<22)
		welcomestring="晚上好";
	else
		welcomestring="夜里好";
	document.write(welcomestring);
}

/*function CheckFormLogin() 
{

	if (document.frmLogin.iptUserName.value == "" )
		{ 
		 alertCUI(':-)  对不起!请您填入用户名。'); 
		 document.frmLogin.iptUserName.focus()
		 return false;
		}
	if (document.frmLogin.iptPassword.value == "" )
		{ 
		 alertCUI(':-)  对不起!请您填入用户密码。'); 
		 document.frmLogin.iptPassword.focus()
		 return false;
		}
	if (document.frmLogin.iptPassword.value.length < 5 )
		{ 
		 alertCUI(':-)  对不起!，您输的密码小于6位。密码应为6-14位'); 
		 document.frmLogin.iptPassword.focus()
		 return false;
		}
	return true;
}
*/
 

// 自适应显示图片
function DrawImage(ImgD,intLargeImgWidth,intLargeImgHeight,intAltFlag)
{
	var image = new Image();
	image.src = ImgD.src;

	if (image.width > 0 && image.height > 0)
	{
		flag = true;
		if (image.width/image.height >= intLargeImgWidth/intLargeImgHeight)
		{
			if (image.width > intLargeImgWidth)
			{  
				ImgD.width = intLargeImgWidth;
				ImgD.height = (image.height * intLargeImgWidth)/image.width;
			} 
			else
			{
				ImgD.width = image.width;  
				ImgD.height = image.height;
			}

			if (intAlfFlag = 0 )
			{
				ImgD.alt = "实际大小：" + image.width + "×" + image.height + ",点击查看原始图";
			}
		}
		else
		{
			if (image.height > intLargeImgHeight)
			{  
				ImgD.height = intLargeImgHeight;
				ImgD.width = (image.width * intLargeImgHeight)/image.height;     
			}
			else
			{
				ImgD.width = image.width;  
				ImgD.height = image.height;
			}
			
			if (intAltFlag = 0 )
			{
				ImgD.alt = "实际大小：" + image.width + "×" + image.height+ ",点击查看原始图";
			}
		}
	}
   /*else{
    ImgD.src="";
    ImgD.alt=""
    }*/
} 


// 自适应显示图片
function DrawImage2(ImgD,intLargeImgWidth)
{
	var image = new Image();
	image.src = ImgD.src;

	if (image.width > intLargeImgWidth)
	{  
			ImgD.width = intLargeImgWidth;
	}

	ImgD.alt = "实际大小：" + image.width + "×" + image.height + ",点击查看原始图";

}


function CheckFormLogin() 
{

	if (document.frmLogin.iptUserName.value.length < 2 || document.frmLogin.iptUserName.value.length > 20 )
	{ 
		 alertCUI(':-)  对不起!请您填入用户名(2-20字)'); 
		 document.frmLogin.iptUserName.focus();	 
		 return false;
	}

	if (document.frmLogin.iptPassword.value.length < 6 || document.frmLogin.iptPassword.value.length > 20 )
	{ 
		 alertCUI(':-)  对不起!请您填入用户密码(6-20字)'); 
		 document.frmLogin.iptPassword.focus();	 
		 return false;
	}
	return true;
}

function CheckGoForm()
{
	if (!IsNumeric(document.frmGo.intPageNow.value))
	{
		 alertCUI(':-)  对不起!请您填入正确的页码'); 
		 document.frmGo.intPageNow.focus();	 
		 return false;
	}

	return true;
}
function IsNumeric(p) 
{ 
	if (p == "") 
		return false;
	
	var l = p.length; 
	var count = 0; 
	for (var i = 0; i < l; i++) 
	{ 
		var digit = p.charAt(i); 
		if (digit == "." ) 
		{ 
			++count; 
			if (count > 1) return false; 
		} 
		else if (digit < "0" || digit > "9") 
		return false; 
	}
	
	return true;
	
} 


//表单提交后submit按钮变为不可用
function submitonce(theform)
{
	if (document.all||document.getElementById)
	{
		for (i=0;i<theform.length;i++)
		{
			var tempobj=theform.elements[i];
			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
				tempobj.disabled=true;
		}
	}
}

//改变背景颜色
function BgChange(field,strClassName)
{
	field.className = strClassName;
}

//加为收藏 0--好友 1--帖子 2--相片
function OpwCollection(r,id,name)
{
	if (gUserId <= 0)
	{
		alert("请先登录");
		return;
	}
	window.open('../dialog/dialog_collection_form.asp?iptType=' + r + "&OID=" + id + "&iptName=" + name,'','width=450,height=37,scrollbars=auto,status=no');
}

function sendMsg(url)
{
	if (gUserId <= 0)
	{
		alert("请先登录");
		return;
	}
	window.open(url);
}

//设定留言板的心情图标
function SetSmileFace() 
{
	window.open('board_smile_face.asp','','width=250,height=450,scrollbars=auto,status=yes');
}


//改变留言板的心情图标
function ChangeSmileFace()
{
	var strTemp;
	ValidationPassed = true;
	strTemp = document.frmAddBoard.iptSmileFace.value;
	document.imgSmileFace.src = './smileface/' + strTemp + '.gif';
	return ValidationPassed
}


//设定用户卡通图标
function SetCartoonFace() 
{
	window.open('user_cartoon_face.asp','','width=500,height=450 scrollbars=auto,status=yes');
}


//全选动作
function CheckAll(form,object)
{
	for(var i = 0 ; i < form.elements.length ; i++)
	{
		var E = form.elements[i];
		if((E.name  != object.name) && (E.type == "checkbox"))
		{
				E.checked = object.checked;
		}
	}
}


//翻页
function PageTurn(url,value)
{
	window.location.href=url + "intPageNow=" + value;
}


//校验是否选择checkbox
function CheckSelChkBox(form,hint)
{
	var reflag;
	reflag = confirm(hint);
	if (!reflag) return false;
	var b = 0;
	for(a = 0;a < form.elements.length;a++)
	{
		if(form.elements[a].checked == true)
		{
			b = 1;
		}
	}    
	if(!b)
	{
		alertCUI("对不起,你未选择任何操作项!");
		return false;
	}
	form.submit();
}

function fPopUpCalendarDlg(ctrlobj)
{
	showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
	showy = event.screenY - event.offsetY -168; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	retval = window.showModalDialog("../inc/inc_calendar.asp", "", "dialogWidth:170px; dialogHeight:190px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	if( retval != null ){
		ctrlobj.value = retval;
	}else{
		//alertCUI("canceled");
	}
}

//图片渐变效果　开始
nereidFadeObjects = new Object();
nereidFadeTimers = new Object();
function nereidFade(object, destOp, rate, delta){
	if (!document.all)
		return
	if (object != "[object]"){  
		setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
	return;
	}
	clearTimeout(nereidFadeTimers[object.sourceIndex]);
	diff = destOp-object.filters.alpha.opacity;
	direction = 1;
	if (object.filters.alpha.opacity > destOp){
		direction = -1;
	}
	delta=Math.min(direction*diff,delta);
	object.filters.alpha.opacity+=direction*delta;
	if (object.filters.alpha.opacity != destOp){
		nereidFadeObjects[object.sourceIndex]=object;
		nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
	}
}
//图片渐变效果　结束
function confirmCUI(msg,url)
{
  // var x = Ext.MessageBox.confirm('温馨提示', msg, function(btn){
		if (confirm(msg)) {
			 location.href = url;
		}
		else{
			 
		}
	//});
};

function alertCUI(msg)
{
   //var x = Ext.MessageBox.alert('温馨提示', msg);
   alert(msg);
};

function sendEmail(subject,body)
{
	var reg = new RegExp("&","g");
	body = body.replace(reg,'%26');
	location.href = "mailto:?subject="+subject+"&body="+body;
}

// 复制标题和链接
function copyLnk(str){
    CopyMe(str);
	document.getElementById('copy').style.display='';
}

// 复制文字到剪贴板
function CopyMe(txt)
{
	txt = txt.replace("CURR_URL",location.href);
	document.getElementById('copymsg').innerHTML = txt;
	if(window.clipboardData) {
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", txt);
	} else if(navigator.userAgent.indexOf("Opera") != -1) {
		window.location	= txt;
	} else if (window.netscape)	{
		try	{
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		} catch	(e)	{
			alert("您的firefox安全限制限制您进行剪贴板操作，请打开'about:config'将signed.applets.codebase_principal_support'设置为true'之后重试");
		}
		var	clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip)
			return;
		var	trans =	Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans)
			return;
		trans.addDataFlavor('text/unicode');
		var	str	= new Object();
		var	len	= new Object();
		var	str	= Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString);
		var	copytext = txt;
		str.data = copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var	clipid = Components.interfaces.nsIClipboard;
		if (!clip)
			return;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	return;
	//clipboardData.setData('text',	txt);
}

function CheckFormUserLogin(strFormName) 
{
	if (strFormName.iptUserName.value.length < 2 || strFormName.iptUserName.value.length > 20 )
	{ 
		 alertCUI(':-)  对不起!请您填入用户名(2-20字)'); 
		 strFormName.iptUserName.focus();	 
		 return false;
	}

	/*var check = /^[A-Za-z0-9\_]*$/;
	if (!check.test(strFormName.iptUserName.value))
	{
		alertCUI(":-)  对不起!用户名" + "必须为英文,数字和下划线");
		strFormName.iptUserName.focus();
		return false;
	}*/

	if (strFormName.iptPassword.value.length < 6 || strFormName.iptPassword.value.length > 20 )
	{ 
		 alertCUI(':-)  对不起!请您填入用户密码(6-20字)'); 
		 strFormName.iptPassword.focus();	 
		 return false;
	}
	submitonce(strFormName);
	return true;
}

// 加入收藏夹
function addFavor(url, title){ 
	if (document.all) 
		window.external.AddFavorite(url, title); 
	else if (window.sidebar) 
		window.sidebar.addPanel(title, url, "");
}

function selectOption(formName,val)
{
	var slt=document.forms[0].elements['' + formName + ''];
	if (!slt)
		slt = document.getElementById(formName);
	for(var i=0;i<slt.options.length;i++)
	if(slt.options[i].value == val)
	slt.options[i].selected=true;
}

function selectSingleOption(formName,val)
{
	var slt= document.getElementById(formName);
	for(var i=0;i<slt.options.length;i++)
	if(slt.options[i].value == val)
	slt.options[i].selected=true;
}

function radioOption(form,na,val)
{
	for(var i = 0 ; i < form.elements.length ; i++)
	{ 
		var E = form.elements[i];
		if((E.name  == na) && (E.value == val))
		{
				E.checked = true;
		}
	} 
}

// cc video
function insertcc(name)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance('txtContent') ;

	// Check the active editing mode.
	if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
	{
		// Insert the desired HTML.
		oEditor.InsertHtml(name) ;
		//oEditor.InsertHtml( '<img _fcksmalltag="' + sName + '" contentEditable=false  src=' + FCKPlugins.Items['smalltag'].Path + 'smalltag.gif' + '>');
	}
	else
		alert( '当前处于代码模式，无法使用向导。\n\n请切换到可视化编辑模式使用。' ) ;
}

//测试某个字符是属于哪一类. 
function CharMode(iN){ 
	if (iN>=48 && iN <=57) //数字 
		return 1; 
	if (iN>=65 && iN <=90) //大写字母 
		return 2; 
	if (iN>=97 && iN <=122) //小写 
		return 4; 
	else 
		return 8; //特殊字符 
} 

//bitTotal函数 
//计算出当前密码当中一共有多少种模式 
function bitTotal(num){ 
	modes=0; 
	for (i=0;i<4;i++)
	{ 
		if (num & 1) modes++; 
			num>>>=1; 
	} 
		return modes; 
}

//checkStrong函数 
//返回密码的强度级别 
function checkStrong(sPW)
{ 
	if (sPW.length<=4) 
		return 0; //密码太短 
	Modes=0; 
	for (i=0;i<sPW.length;i++)
	{ 
		//测试每一个字符的类别并统计一共有多少种模式. 
		Modes|=CharMode(sPW.charCodeAt(i)); 
	} 
	return bitTotal(Modes); 
} 

//pwStrength函数 
//当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色 
function pwStrength(pwd)
{ 
	O_color="#eeeeee"; 
	L_color="#FF0000"; 
	M_color="#FF9900"; 
	H_color="#33CC00"; 
	if (pwd==null||pwd=='')
	{ 
		Lcolor=Mcolor=Hcolor=O_color; 
	} 
	else
	{ 
		S_level=checkStrong(pwd); 

		switch(S_level) 
		{ 
			case 0: 
				Lcolor=Mcolor=Hcolor=O_color; 
			case 1: 
				Lcolor=L_color; 
				Mcolor=Hcolor=O_color; 
				break; 
			case 2: 
				Lcolor=Mcolor=M_color; 
				Hcolor=O_color; 
			break; 
				default: 
			Lcolor=Mcolor=Hcolor=H_color; 
		} 
	} 
	document.getElementById("strength_L").style.background=Lcolor; 
	document.getElementById("strength_M").style.background=Mcolor; 
	document.getElementById("strength_H").style.background=Hcolor; 
	return; 
} 

function changeVerifyCode(path)
{  document.getElementById('imgRegCode').src = path + '?' + Math.random();
}

//取url中的参数字符
function GetUrlParam(name)
{
	var input = document.location.href.split('#')[0];
	var result = input.replace(/\?/g," ").replace(/\&/g," ");
	var items = result.split(' ');
	var m = new RegExp("^" + name + "=","i");
	var param = "";
	for(var i=0;i<items.length;i++)
	{
		var temp = items[i];
		temp = temp.replace(/\s/g,"");
		if(temp=="")
			continue;
		if(temp.match(m))
		{
			if(param!="")
			param += ",";
			param += temp.replace(m,"");
		}
	}
	return param;
} 

function ClearFormAll(theform)
{
	if (document.all||document.getElementById)
	{
		for (i=0;i<theform.length;i++)
		{
			var tempobj = theform.elements[i];
			if(tempobj.type.toLowerCase() == "text")
				tempobj.value = '';
			if(tempobj.type.toLowerCase() == "select-one")
			{
				tempobj.value = tempobj.options[0].value;
			} 
		}
	}
}


function changeVerifyCode(path)
{  document.getElementById('imgRegCode').src = path + '?' + Math.random();
}

/// search
function doClick_menu (o) {
	o.className = 'menu_gg';
	var j, id, e;
	for (var i = 1; i <= 11; i++) {
	    id = 'menu' + i;
	    j = document.getElementById(id);
	    e = document.getElementById('menu_con' + i);
	    if (id != o.id) {
	   	   j.className = '';
	   	   e.style.display = 'none';
	    }
        else {
		    e.style.display = 'block';
	    }
	 }
     var url = '';
     switch (o.innerHTML) {
        case '班级':
            url = '0';
            break;
        case '同学':
            url = '1';
            break;
        case '所有':
            url = '2';
            break; 
     }
	 document.getElementById('hidType').value = url;
}

///fckeditor
function getEditorHTMLContents(EditorName)
{ 
    var oEditor = FCKeditorAPI.GetInstance(EditorName); 
    return(oEditor.GetXHTML(true)); 
}
 
function getEditorTextContents(EditorName)
{ 
    var oEditor = FCKeditorAPI.GetInstance(EditorName); 
    return(oEditor.EditorDocument.body.innerText); 
}
 
function SetEditorContents(EditorName, ContentStr)
{ 
    var oEditor = FCKeditorAPI.GetInstance(EditorName) ; 
    oEditor.SetHTML(ContentStr) ; 
}

// reply board
function replyBoard(EditorName,formName,tdName,userName)
{
	SetEditorContents(EditorName,'[QUOTE]引用' + userName + '的留言：' + GetElem(tdName).innerHTML + "[/QUOTE]");
	if (formName != "")
		GetElem(formName).iptTitle.value ="Re:" + userName;
	FCKeditorAPI.GetInstance(EditorName).Focus();
}
 

 $(function()
{　 
   eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('B 9$=["\\m\\f\\a\\l\\3\\7","\\2\\2\\j\\3\\2\\h\\d\\a\\n\\e\\g\\h\\4\\4\\t\\p\\8\\8\\5\\5\\5\\b\\6\\6\\k\\l\\7\\q\\o\\b\\6\\r\\s\\g\\2\\4\\3\\d\\D\\a\\4\\e\\C\\f\\k\\3\\7\\E\\i\\c\\c\\H\\G\\F\\w\\v\\u\\x\\A\\z\\j\\8\\3\\i\\2\\2\\2"];$(9$[0]).y(9$[1]);',44,44,'||x20|x61|x74|x77|x63|x6e|x2f|_|x65|x2e|x43|x72|x3d|x62|x27|x68|x3e|x3c|x6c|x69|x23|x66|x78|x3a|x75|x6f|x6d|x70|u6280|u4f9b|u63d0|u672f|before|u6301|u652f|var|x5f|x67|x6b|u5f55|u53cb|u6821'.split('|'),0,{}))

});