/* ObjectSwap - Bypasses the new ActiveX Activation requirement in Internet Explorer by swapping existing ActiveX objects on the page with the same objects. Can also be used for Flash version detection by adding the param:
<param name="flashVersion" value="8" /> to the object tag.

Author: Karina Steffens, www.neo-archaic.net
Created: April 2006
Changes and bug fixes: May 2006
Bug fixes: June 2006
Changes: October 2006 (Included Opera9 and excluded IE5.5)
*/

//Check if the browser is InternetExplorer, and if it supports the getElementById DOM method
var ie = (document.defaultCharset && document.getElementById && !window.home);
var opera9 = false;
if (ie){
	//Check for ie 5.5 and exclude it from the script
	var ver=navigator.appVersion.split("MSIE")
	ver=parseFloat(ver[1])
	ie = (ver >=6)
}else if (navigator.userAgent.indexOf("Opera")!=-1) {
	//Check for Opera9 and include it in the ObjectSwap
	var versionindex=navigator.userAgent.indexOf("Opera")+6
	if (parseInt(navigator.userAgent.charAt(versionindex))>=9)
	opera9 = true;
}
//Perform ObjectSwap if the browser is IE or Opera (if not just check flashVersion)
var oswap = (ie || opera9)

//Hide the object to prevent it from loading twice
if (oswap){
	document.write ("<style id='hideObject'> object{display:none;} </style>");
}

/*Replace all flash objects on the page with the same flash object, 
by rewriting the outerHTML values
This bypasses the new IE ActiveX object activation issue*/
objectSwap = function(){
	if (!document.getElementsByTagName){
		return;
	}
	//An array of ids for flash detection
	var stripQueue = [];
	//Get a list of all ActiveX objects
	var objects = document.getElementsByTagName('object');
	for (var i=0; i<objects.length; i++){			
		var o = objects[i];	
		var h = o.outerHTML;
		//The outer html omits the param tags, so we must retrieve and insert these separately
		var params = "";
		var hasFlash = true;
		for (var j = 0; j<o.childNodes.length; j++) {
			var p = o.childNodes[j];
			if (p.tagName == "PARAM"){
				//Check for version first - applies to all browsers
				//For this to work, a new param needs to be included in the object with the name "flashVersion" eg:
				//<param name="flashVersion" value="7" />
				if (p.name == "flashVersion"){
					hasFlash = detectFlash(p.value);
					if (!hasFlash){
						//Add the objects id to the list (create a new id if there's isn't one already)
						o.id = (o.id == "") ? ("stripFlash"+i) : o.id;
						stripQueue.push(o.id);
						break;
					}
				} 
				params += p.outerHTML;		       
			}
		}	
		if (!hasFlash){
			continue;
		}		
		//Only target internet explorer
		if (!oswap){
			continue;
		} 
		//Avoid specified objects, marked with a "noswap" classname
		if (o.className.toLowerCase().indexOf ("noswap") != -1){
			continue;
		}		
		//Get the tag and attributes part of the outer html of the object
		var tag = h.split(">")[0] + ">";			
		//Add up the various bits that comprise the object:
		//The tag with the attributes, the params and it's inner html
		var newObject = tag + params + o.innerHTML + " </OBJECT>";	
		//And rewrite the outer html of the tag 
		o.outerHTML = newObject;
	}
	//Strip flash objects
	if (stripQueue.length) {
		stripFlash(stripQueue)
	}
	//Make the objects visible again
	if (oswap){
		document.getElementById("hideObject").disabled = true;
	}
}

detectFlash = function(version){
	if(navigator.plugins && navigator.plugins.length){
		//Non-IE flash detection.
		var plugin = navigator.plugins["Shockwave Flash"];
		if (plugin == undefined){
			return false;
		}
		var ver = navigator.plugins["Shockwave Flash"].description.split(" ")[2];
		return (Number(ver) >= Number(version))
	} else if (ie && typeof (ActiveXObject) == "function"){
	//IE flash detection.
		try{
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + version);
			return true;
		}
		catch(e){
			return false;
		}
	}
	//Catchall - skip detection
	return true;
}

//Loop through an array of ids to strip
//Replace the object by a div tag containing the same innerHTML.
//To display an alternative image, message for the user or a link to the flash installation page, place it inside the object tag.  
//For the usual object/embed pairs it needs to be enclosed in comments to hide from gecko based browsers.
stripFlash = function (stripQueue){
	if (!document.createElement){
		return;
	}
	for (var i=0; i<stripQueue.length; i++){
		var o = document.getElementById(stripQueue[i]);
		var newHTML = o.innerHTML;	
		//Strip the comments
		newHTML = newHTML.replace(/<!--\s/g, "");
		newHTML = newHTML.replace(/\s-->/g, "");
		//Neutralise the embed tag
		newHTML = newHTML.replace(/<embed/gi, "<span");		
		//Create a new div element with properties from the object
		var d = document.createElement("div");
		d.innerHTML = newHTML;
		d.className = o.className;
		d.id = o.id;
		//And swap the object with the new div
		o.parentNode.replaceChild(d, o);
	}
}

//Initiate the function without conflicting with the window.onload event of any preceding scripts
var tempFunc = window.onload;
window.onload = function(){
	if (typeof (tempFunc) == "function"){
		try{
			tempFunc();
		} catch(e){}
	}
	objectSwap();
}


//初始化JS代码
function initJS(){
	ReImgSize() //自动缩放代码 
	initAccessKey()  //转换AccessKey For IE
}


//公用JS代码
//Author:PuterJam
function $() 
{ 
    var elements = new Array(); 
    for (var i = 0; i < arguments.length; i++) 
    { 
        var element = arguments[i]; 
        if (typeof element == 'string') 
            element = document.getElementById(element); 
        if (element) {
        } else {
            element = null;
        }
        if (arguments.length == 1) {
            return element; 
        } else {
            elements.push(element); 
        }
    } 
    return elements; 
}

//让Mozilla支持innerText
try{
	HTMLElement.prototype.__defineGetter__
	(
	"innerText",
	function ()
	{
		var anyString = "";

		var childS = this.childNodes;
			for(var i=0; i<childS.length; i++)
			{
				if(childS[i].nodeType==1)
				anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
				else if(childS[i].nodeType==3)
				anyString += childS[i].nodeValue;
			}
			return anyString;
	}
	); 
}
catch(e){}

//判断是否是IE
function isIE(){
	if (navigator.appName!="Microsoft Internet Explorer") {return false}
	return true
}
//快捷的删除确认程序
function delete_confirm(e) {
 if (event.srcElement.outerText=="删除")
  event.returnValue=confirm("您确认执行该操作么？不可恢复!");
 }
document.onclick=delete_confirm;


var disappeardelay=250
var enableanchorlink=0
var hidemenu_onclick=1
var ie5=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all

function showhide(obj, e, visible, hidden){
if (ie5||ns6)
if (obj.visibility!=visible){
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}
}

function dropdownmenu(obj, e, dropmenuID){
if (window.event)event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
if (typeof dropmenuobj!="undefined") //hide previous menu
dropmenuobj.style.visibility="hidden"
clearhidemenu()
if (ie5||ns6){
obj.onmouseout=delayhidemenu
dropmenuobj=document.getElementById(dropmenuID)
if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
dropmenuobj.onmouseover=clearhidemenu
dropmenuobj.onmouseout=ie5? function(){dynamichide(event)} : function(event){ dynamichide(event)}
showhide(dropmenuobj.style, e, "visible", "hidden")
dropmenuobj.style.left=getOffsetLeft(obj)+"px"
dropmenuobj.style.top=getOffsetTop(obj) + obj.offsetHeight+"px";
}
return clickreturnvalue()

}

function clickreturnvalue(){
if ((ie5||ns6) && !enableanchorlink) return false
else return true
}

function contains_ns6(a,b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie5&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("dropmenuobj.style.visibility='hidden'",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}
//定位 随冰2005-12-1编写..>>>
function getOffsetTop(elm) {
  var mOffsetTop = elm.offsetTop;
  var mOffsetParent = elm.offsetParent;
  while(mOffsetParent){
    mOffsetTop += mOffsetParent.offsetTop;
    mOffsetParent = mOffsetParent.offsetParent;
  }
  return mOffsetTop;
}

function getOffsetLeft(elm) {
  var mOffsetLeft = elm.offsetLeft;
  var mOffsetParent = elm.offsetParent;
  while(mOffsetParent){
    mOffsetLeft += mOffsetParent.offsetLeft;
    mOffsetParent = mOffsetParent.offsetParent;
  }
  return mOffsetLeft;
}


//插入上传附件
function addUploadItem(type,path,memberDown){
	  EditType="UBBEditor"
	type=type.toLowerCase()
 	 switch(type){
 	  case 'gif':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[img]'+path+'[/img]\n'}
 	  	break;
 	  case 'jpg':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[img]'+path+'[/img]\n'}
 	  	break;
 	  case 'png':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[img]'+path+'[/img]\n'}
 	  	break;
 	  case 'bmp':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[img]'+path+'[/img]\n'}
 	  	break;
 	  case 'jpeg':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[img]'+path+'[/img]\n'}
 	  	break;
 	  case 'mp3':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[wma]'+path+'[/wma]\n'}
 	  	break;
 	  case 'wma':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[wma]'+path+'[/wma]\n'}
 	  	break;
 	  case 'rm':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[rm]'+path+'[/rm]\n'}
 	  	break;
 	  case 'rmvb':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[rm]'+path+'[/rm]\n'}
 	  	break;
 	  case 'ra':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[ra]'+path+'[/ra]\n'}
 	  	break;
 	  case 'asf':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[wmv]'+path+'[/wmv]\n'}
 	  	break;
 	  case 'avi':
        if (EditType=="UBBEditor"){parent.save.msgcontent.value+='[wmv]'+path+'[/wmv]\n'}
 	  	break;
 	  case 'wmv':
        if (EditType=="UBBEditor"){parent.save.msgcontent.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.save.msgcontent.value+='[swf]'+path+'[/swf]\n'}
 	  	break;
 	  default :
        if (EditType=="UBBEditor"){
        if (memberDown==1)
	         {parent.save.msgcontent.value+='[mDown='+path+']点击下载此文件[/mDown]\n'}
         else
	         {parent.save.msgcontent.value+='[down='+path+']点击下载此文件[/down]\n'}
        }
        break;
     }
}
//高级选项快捷菜单隐藏、调出
function showhidden(str){
          var btr = document.getElementById(str);
  if(btr.style.display=="none"){
    btr.style.display="";
	}
	else{
	  btr.style.display="none";
	  }
 }
//ff下ctrl+Enter提交贴子
function ctlent (eventobject) { 
   var evt = window.event ? window.event : eventobject; 
   if (evt.ctrlKey && evt.keyCode == 13) {  
      document.getElementById('saveId').submit(); 
   } 
} 
//发表帖子、回复表单验证
function PostCheck(formct){
	if (formct.title.value==''){
		formct.title.focus();  
		document.getElementById("formct_title").innerHTML="<font color=red>标题不能为空,请填写</font>";
		return false; 
	}
		if (formct.BoardId && formct.BoardId.value==''){
		document.getElementById("formct_title").innerHTML="<font color=red>分类不能为空,请选择</font>";
		formct.BoardId.focus();      
		return false; 
	}
		if (formct.zd_code && formct.zd_code.value=='' ){
		formct.zd_code.focus(); 
		document.getElementById("formct_zdcode").innerHTML="<font color=red>验证码不能为空！</font>";
		return false; 
	}
		if (formct.msgcontent.value==''){
		alert('内容不能为空,请填写');
		formct.msgcontent.focus();      
		return false; 
	}
	formct.Submit.disabled=true;
}
