﻿//列表切换排序
function sortJump(comparType)
{
//更换comparType的内容
    var argName = "comparType";
	var url = location.protocol + '//' + location.host + location.pathname;
	var args = location.search;
	var reg = new RegExp('([\?&]?)' + argName + '=[^&]*[&$]?', 'gi');
	args = args.replace(reg,'$1');
	
	if (args == '' || args == null) {
		args += '?' + argName + '=' + comparType;
	} else if (args.substr(args.length - 1,1) == '?' || args.substr(args.length - 1,1) == '&') {
			args += argName + '=' + comparType;
	} else {
			args += '&' + argName + '=' + comparType;
	}
	
//更换sort的内容
	reg = new RegExp('([\?&]?)Sort=[^&]*[&$]?', 'gi');
	//alert(args.match(reg));
	if (args.match(reg) == null) {
	    args += '&Sort=desc'
	} else if (args.match(reg) == '?Sort=desc&') {
	    args = args.replace(reg,'$1');
	} else if (args.match(reg) == '&Sort=desc&') {
	    args = args.replace(reg,'$1');
	}

	self.location.href = url + args;
}

//列表页数切换
function pageSizeJump(pagesize)
{
//更换pagesize的内容
    var argName = "pagesize";
	var url = location.protocol + '//' + location.host + location.pathname;
	var args = location.search;
	var reg = new RegExp('([\?&]?)' + argName + '=[^&]*[&$]?', 'gi');
	args = args.replace(reg,'$1');
	
	if (args == '' || args == null) {
		args += '?' + argName + '=' + pagesize;
	} else if (args.substr(args.length - 1,1) == '?' || args.substr(args.length - 1,1) == '&') {
			args += argName + '=' + pagesize;
	} else {
			args += '&' + argName + '=' + pagesize;
	}
	
	self.location.href = url + args;
}

//列表搜索字符串提交
function findJump(strFind)
{
//更换Find的内容
    var argName = "Find";
	var url = location.protocol + '//' + location.host + location.pathname;
	var args = location.search;
	var reg = new RegExp('([\?&]?)' + argName + '=[^&]*[&$]?', 'gi');
	
	args = args.replace(reg,'$1');
	
	if (args == '' || args == null) {
		args += '?' + argName + '=' + strFind;
	} else if (args.substr(args.length - 1,1) == '?' || args.substr(args.length - 1,1) == '&') {
			args += argName + '=' + encodeURI(strFind);
	} else {
			args += '&' + argName + '=' + encodeURI(strFind);
	}
	
	self.location.href = url + args;
}

//插入上传附件
function addUploadItem(type,path,instanceName){
	var EditType=""
	try{
	  var oEditor = parent.FCKeditorAPI.GetInstance(instanceName)
	  EditType="FCkEditor"
	  var hrefLen=location.href.lastIndexOf("/")
      var Fhref=location.href.substr(0,hrefLen+1)
      //path=Fhref+path
	}
	catch(e){
	  EditType="UBBEditor"
	}
	type=type.toLowerCase()
 	 switch(type){
 	  case 'gif':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[img]'+path+'[/img]\n'}
        else{oEditor.InsertHtml('<img src="'+path+'" alt=""/>')}
 	  	break;
 	  case 'jpg':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[img]'+path+'[/img]\n'}
        else{oEditor.InsertHtml('<img src="'+path+'" alt=""/>')}
 	  	break;
 	  case 'png':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[img]'+path+'[/img]\n'}
        else{oEditor.InsertHtml('<img src="'+path+'" alt=""/>')}
 	  	break;
 	  case 'bmp':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[img]'+path+'[/img]\n'}
        else{oEditor.InsertHtml('<img src="'+path+'" alt=""/>')}
 	  	break;
 	  case 'jpeg':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[img]'+path+'[/img]\n'}
        else{oEditor.InsertHtml('<img src="'+path+'" alt=""/>')}
 	  	break;
 	  case 'mp3':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[wma]'+path+'[/wma]\n'}
        else{oEditor.InsertHtml('<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"  id="MediaPlayer" width="450" height="70"><param name=""howStatusBar" value="-1"><param name="AutoStart" value="False"><param name="Filename" value="'+path+'"></object>')}
 	  	break;
 	  case 'wma':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[wma]'+path+'[/wma]\n'}
        else{oEditor.InsertHtml('<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"  id="MediaPlayer" width="450" height="70"><param name=""howStatusBar" value="-1"><param name="AutoStart" value="False"><param name="Filename" value="'+path+'"></object>')}
 	  	break;
 	  case 'rm':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[rm]'+path+'[/rm]\n'}
        else{oEditor.InsertHtml('<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="300"><param name="SRC" value="'+path+'" /><param name="CONTROLS" VALUE="ImageWindow" /><param name="CONSOLE" value="one" /><param name="AUTOSTART" value="true" /><embed src="'+path+'" nojava="true" controls="ImageWindow" console="one" width="400" height="300"></object><br/><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="32" /><param name="CONTROLS" value="StatusBar" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+path+'" nojava="true" controls="StatusBar" console="one" width="400" height="24" /></object><br/><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="32" /><param name="CONTROLS" value="ControlPanel" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+path+'" nojava="true" controls="ControlPanel" console="one" width="400" height="24" autostart="true" loop="false" /></object>')}
 	  	break;
 	  case 'rmvb':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[rm]'+path+'[/rm]\n'}
        else{oEditor.InsertHtml('<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="300"><param name="SRC" value="'+path+'" /><param name="CONTROLS" VALUE="ImageWindow" /><param name="CONSOLE" value="one" /><param name="AUTOSTART" value="true" /><embed src="'+path+'" nojava="true" controls="ImageWindow" console="one" width="400" height="300"></object><br/><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="32" /><param name="CONTROLS" value="StatusBar" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+path+'" nojava="true" controls="StatusBar" console="one" width="400" height="24" /></object><br/><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="32" /><param name="CONTROLS" value="ControlPanel" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+path+'" nojava="true" controls="ControlPanel" console="one" width="400" height="24" autostart="true" loop="false" /></object>')}
 	  	break;
 	  case 'ra':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[ra]'+path+'[/ra]\n'}
        else{oEditor.InsertHtml('<object classid="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" id="RAOCX" width="450" height="60"><param name="_ExtentX" value="6694"><param name="_ExtentY" value="1588"><param name="AUTOSTART" value="true"><param name="SHUFFLE" value="0"><param name="PREFETCH" value="0"><param name="NOLABELS" value="0"><param name="SRC" value="'+path+'"><param name="CONTROLS" value="StatusBar,ControlPanel"><param name="LOOP" value="0"><param name="NUMLOOP" value="0"><param name="CENTER" value="0"><param name="MAINTAINASPECT" value="0"><param name="BACKGROUNDCOLOR" value="#000000"><embed src="'+path+'" width="450" autostart="true" height="60"></embed></object>')}
 	  	break;
 	  case 'asf':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[wmv]'+path+'[/wmv]\n'}
        else{oEditor.InsertHtml('<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" type="application/x-oleobject" standby="Loading..." width="400" height="300"><param name="FileName" VALUE="'+path+'" /><param name="ShowStatusBar" value="-1" /><param name="AutoStart" value="true" /><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="'+path+'" autostart="true" width="400" height="300" /></object>')}
 	  	break;
 	  case 'avi':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[wmv]'+path+'[/wmv]\n'}
        else{oEditor.InsertHtml('<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" type="application/x-oleobject" standby="Loading..." width="400" height="300"><param name="FileName" VALUE="'+path+'" /><param name="ShowStatusBar" value="-1" /><param name="AutoStart" value="true" /><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="'+path+'" autostart="true" width="400" height="300" /></object>')}
 	  	break;
 	  case 'wmv':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[wmv]'+path+'[/wmv]\n'}
        else{oEditor.InsertHtml('<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" type="application/x-oleobject" standby="Loading..." width="400" height="300"><param name="FileName" VALUE="'+path+'" /><param name="ShowStatusBar" value="-1" /><param name="AutoStart" value="true" /><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="'+path+'" autostart="true" width="400" height="300" /></object>')}
 	  	break;
 	  case 'swf':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[swf]'+path+'[/swf]\n'}
        else{oEditor.InsertHtml('<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="400" height="300"><param name="movie" value="'+path+'" /><param name="quality" value="high" /><param name="AllowScriptAccess" value="never" /><embed src="'+path+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="400" height="300" /></object>')}
 	  	break;
 	  default :
        if (EditType=="UBBEditor"){
        if (memberDown==1)
	         {parent.document.forms[0].Message.value+='[mDown='+path+']点击下载此文件[/mDown]\n'}
         else
	         {parent.document.forms[0].Message.value+='[down='+path+']点击下载此文件[/down]\n'}
        }
        else{oEditor.InsertHtml('<a href="'+path+'"><img border="0" src="/images/download.gif" alt="" style="margin:0px 2px -4px 0px"/>点击下载此文件</a>')}
        break;
     }
}

//global base function
var gd = document;
function Gel(id, ob) {
	return (ob ? ob : gd).getElementById(id);
}
function GelTags(tag, ob) {
	return (ob ? ob : gd).getElementsByTagName(tag);
}
function S(i, win) {
	return (win?win:window).document.getElementById(i);
}
function SO(i, o) {
	return Gel(i, o);
}
function SN(i, win) {
	return (win?win:window).document.getElementsByName(i);
}
function SNO(i, o) {
	return (o ? o : gd).getElementsByName(i);
}
function F(sID, win) {
	if(!sID) return null;
	var frame = S(sID, win);
	if(!frame) return null;
	return frame.contentWindow?frame.contentWindow:(win?win:window).frames[sID];
}
function GetSid() {
	try {var s = top.g_sid;}catch(e){}
	s = s ? s : (S("sid") ? S("sid").value : "");
	if (!s) {
		s = (top.location.href.split("?")[1]).split("&");
		s = s[0].split("=")[1];
	}
	return s;
}
function IsShow(obj) {
	obj = (typeof(obj) == "string" ? S(obj) : obj);
	if (!obj) return false;
	return obj.style.display != "none";
}
function Show(obj, bShow) {
	obj = (typeof(obj) == "string" ? S(obj) : obj);
	if (obj) obj.style.display= (bShow ? "" : "none");
}
function ShowN(name, bShow) {
	var o = SN(name);
	for (var i = o.length - 1; i >= 0; i--) {
		Show(o[i], bShow);
	}
}
//quick replace
function StrReplace(s, o, d) {
	return s.replace(new RegExp(o), d);
}
//selectCheckbox
function SelectAll(flag) {
	var list_table = S('list');
	var list_checkbox = GelTags("input", list_table);
	for(var i = list_checkbox.length - 1;i >= 0; i--) {
		list_checkbox[i].checked = flag;
	}
}
function SelectAllByList(flag ,list) {
	var list_table = S(list);
	var list_checkbox = GelTags("input", list_table);
	for(var i = list_checkbox.length - 1;i >= 0; i--) {
		list_checkbox[i].checked = flag;
	}
}
function CheckSelect() {
	var list_table = S('list');
	var list_checkbox = GelTags("input", list_table);
	var checked = false;
	for(var i = list_checkbox.length - 1;i >= 0; i--) {
		if (list_checkbox[i].checked) {
		    checked = true;
		}
	}
	if (!checked) {
	    alert('要至少选中一个项目才能进行此操作，请在项目前打勾');
	    return false;
	}
}
function CheckSelectOne() {
	var list_table = S('list');
	var list_checkbox = GelTags("input", list_table);
	var checked = 0;
	for(var i = list_checkbox.length - 1;i >= 0; i--) {
		if (list_checkbox[i].checked) {
		    checked ++;
		}
	}
	if (checked != 1) {
	    alert('仅允许选择唯一一个项目，请在项目前打勾');
	    return false;
	}
}
function CheckSelectTwo() {
	var list_table = S('list');
	var list_checkbox = GelTags("input", list_table);
	var checked = 0;
	for(var i = list_checkbox.length - 1;i >= 0; i--) {
		if (list_checkbox[i].checked) {
		    checked ++;
		}
	}
	if (checked != 2) {
	    alert('仅允许选择两个项目，请在项目前打勾');
	    return false;
	}
}
function CheckAll(CBName)
{
	var cbs = GelTags("input");
	for(var i=cbs.length-1; i>=0; i--)
	{
		if(cbs[i].name == CBName )
		{
			SetListCheck(cbs[i]);
		}
	}
}
function SetListCheck(obj, checked)
{
	if (obj.type != "checkbox")
	{
		return;
	}
	if (checked == null)
	{
		checked = obj.checked;
	}
	else
	{
		obj.checked = checked;
	}
	//var a = obj.parentNode.parentNode;
	//a.className = checked ? StrReplace(a.className, "", "") + "tr_mouse_over" : StrReplace(a.className, "", "") + "tr_mouse_out";
}

function formInit(){
    //用于控制框架的高度
    if (self.innerHeight){
        document.getElementById("aspnetForm").style.height = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight){
        document.getElementById("aspnetForm").style.height = document.documentElement.clientHeight-2;
    }
    else if (document.body){
        document.getElementById("aspnetForm").style.height = document.body.clientHeight;
    }
    
    //用于隐藏message提示
    setTimeout("hidMessage()",1000);
}

function hidMessage() {
    if (document.getElementById('messag_container')) {
        document.getElementById('messag_container').style.display='none';
    }
}

function setonchange(me)
{
      if(me.options[me.selectedIndex].value!="")
          window.open(me.options[me.selectedIndex].value,"","","_blank");
          me.selectedIndex=0;
}
