/**
 * common.js
 * @author By Zmor
 * 注意:商业程序，严禁未经授权非法使用！
 */ 
 
function $(s){return document.getElementById(s);}
function $T(s,t){return $(s).getElementsByTagName(t);}
function LoadScript(url,scriptid) { var oldscript=$(scriptid); var newscript=document.createElement("script"); newscript.type="text/javascript"; newscript.id=scriptid; newscript.src=url; document.getElementsByTagName('body')[0].replaceChild(newscript,oldscript); } //Ajaj 跨域处理 By Zmor
function InitAjax() {var ajax=false;try{ajax=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{ajax=new ActiveXObject("Microsoft.XMLHTTP");}catch(E){ajax=false;}}if(!ajax&&typeof XMLHttpRequest!='undefined'){ajax=new XMLHttpRequest();}return ajax;}/***初始化一个xmlhttp对象***/
function setFavorites(){try{window.external.AddFavorite(window.document.location,window.document.title)}catch(e){}}
function setCopy(_sTxt){try{clipboardData.setData('Text',_sTxt)}catch(e){}}
function copy_clip(meintext){ if (window.clipboardData) { window.clipboardData.setData("Text", meintext); } else if (window.netscape) { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');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=meintext;str.data=copytext;trans.setTransferData("text/unicode",str,copytext.length*2);var clipid=Components.interfaces.nsIClipboard;if (!clip) return false;clip.setData(trans,null,clipid.kGlobalClipboard);}alert("文本内容已复制到剪贴板.");return false; }
function openWindow(_sUrl, _sWidth, _sHeight, _sTitle, _sScroll){var oEdit = new dialog();oEdit.init();oEdit.set('title', _sTitle ? _sTitle : "系统提示信息" );oEdit.set('width', _sWidth);oEdit.set('height', _sHeight);oEdit.open(_sUrl, _sScroll ? 'no' : 'yes');}
function doZoom(obj,size){try{$(obj).style.fontSize=size+'px';}catch(e){} }
function IfOnfocusOnce(obj,str){if(obj.value==str){obj.value='';}}//Onfocus事件
function IfOnSubmitOnce(obj,str){if(obj.value==''){alert(str);obj.focus();return false;}}//OnSubmit事件
function copyToClipBoard(){//点击复制本网址，发给POPO/QQ/MSN好友共享
	var clipBoardContent=window.document.title+"\n"+window.document.location;
	window.clipboardData.setData("Text",clipBoardContent);
	alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友！");
}
function killErrors() { return true; }//屏蔽报错
/***打印文章***/
function doPrint(obj){
    var str = '<html>';
	str +=	'<style>';
	str +=	'body{background:#eee;}';
	str +=	'.viewBox { clear:both;text-align:center;width:554px;padding:4px;border:3px solid #ccc;background:#fff; }';
	str +=	'.viewBox .ititle { clear:both;padding:6px;font-size:26px;font-family:黑体;color:#333;font-weight:bold;font-smooth:always; }';
	str +=	'.viewBox .idateline { clear:both;color:#888; }';
	str +=	'.viewBox #content { clear:both;padding:6px 0px 6px 0px;text-align:left;line-height:160%; }';
	str +=	'.viewBox #content .pic { text-align:center;padding:5px; }';
	str +=	'.viewBox #content .pic img { border:1px solid #ccc; }';
	str +=	'</style>';
	str +=	'<meta http-equiv="content-type" content="text/html; charset=gb2312">';
	str +=	'<title>'+document.title+'</title>';
	str +=	'<body>';
	str +=	'<center>';
	str +=	'[ <a href="javascript:history.back()">返回</a> ]　';
	str +=	'[ <a href="javascript:window.print()">打印</a> ]　';
	str +=	'[ <a href="javascript:window.close()">关闭</a> ]';
	str +=	'<hr />';
	str +=	'<div class="viewBox">';
	str += $(obj).innerHTML;
	str +=	'</div>';
	str +=	'</center>';
	str +=	'</body></html>';
	document.write(str);
	document.close();
}

function print_r(x) {
	if(x.constructor!=Array) {
		///alert("!Array");
	} else {
		for(i=1;i<x.length;i++) {
			document.write(x[i]+"<br>");
		}
	}
}


/*
//
function ImgAlpha(objid,dest,direction,rate){
	rate=(typeof(rate)!='undefined')?rate:0.5;
	if (document.all) {
		v=$(objid).style.filter.replace("alpha(opacity=","");
		alpha=parseInt(v.replace(")","")+direction);
		$(objid).style.filter="alpha(opacity="+alpha+")"; //if ie
	} else { // else ff
		alpha=parseInt(alpha+direction);
		$(objid).style.opacity=alpha/100;
	}
	if (Math.abs(Math.abs(alpha)-Math.abs(dest))) setTimeout("ImgAlpha('"+objid+"',"+dest+","+direction+","+rate+")",rate);
} 
*/

function ImgAlpha(objid,alphaA,alphaB,direction,rate){
	rate=(typeof(rate)!='undefined')?rate:0.5;
	alphaA=parseInt(alphaA+direction);	
	if (document.all) $(objid).style.filter="alpha(opacity="+alphaA+")"; //if ie
	else $(objid).style.opacity=alphaA/100;	// else ff
	if (Math.abs(Math.abs(alphaA)-Math.abs(alphaB))) setTimeout("ImgAlpha('"+objid+"',"+alphaA+","+alphaB+","+direction+","+rate+")",rate);
}


function ReSizeImg(id,width) { //重射图片宽[历遍]
	//if (typeof(width)=='undefined') width=380;
	//var imgObj = $T(id,'IMG');
	//for (var i=0; i<imgObj.length; i++) {
		//if(imgObj[i].width>width||imgObj[i].width==28||!imgObj[i].width) {			
			//imgObj[i].alt='原图尺寸 '+imgObj[i].width+'x'+imgObj[i].height+' ,点击查看';
			//imgObj[i].title='原图尺寸 '+imgObj[i].width+'x'+imgObj[i].height+' ,点击查看';
			//----imgObj[i].height=(imgObj[i].height*width)/imgObj[i].width;
			
			//if(imgObj[i].height>100)imgObj[i].height=(imgObj[i].height*width)/imgObj[i].width;
			//imgObj[i].width=width;
		//}
		//---imgObj[i].style.filter='alpha(opacity=80)';
		//---imgObj[i].style.opacity='0.8';
		//---imgObj[i].id='IMG'+Math.random();
		//---imgObj[i].onmouseover=function() { ImgAlpha(this.id,80,100,2); }
		//---imgObj[i].onmouseout=function() { ImgAlpha(this.id,100,80,-2); }
	//}
}


//在新窗口打开链接
function externallinks() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
	   var anchor = anchors[i]; 
	   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
		 anchor.target = "_blank"; 
	} 
} 
window.onload = externallinks;


//显示开关
function display(id) {
	if (typeof(id)=='undefined') return false;
	
	if($(id).style.display=='none') $(id).style.display='block';
	else $(id).style.display='none';
	
	/*if($(id).style.display=='none') Start(id,'Opens');
	else Start(id,'Close');*/
}


//图片预览
function PicPreview(mod,value) {
	value=value.replace(/( ^(< *) )HTML/ig,"$1XXXX");
	$(mod).src=value;
}

//判断中文
function checkChinese(str) {
	//var pattern = [^\x00-\xff];
	var pattern = /[\u4E00-\u9FA5]/g;
	if (pattern.test(str)) return true; else return false;
}




//Ajax initHTML By Zmor
function initHTML(id,url,pars,target) {
	var regExp = new RegExp("((^http)|(^https)|(^ftp))");
	if (url.match(regExp)) url = '/app/agent/?'+url;
	if (typeof(pars)=='undefined') pars='';
	var ajax = InitAjax();
	ajax.open("POST",url,true);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send(pars);
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			if (typeof(id)=='undefined'||id=='') return false;
			switch(target) {
				case 'value':
				$(id).value=ajax.responseText;
				break;
				case 'p_value':
				parent.$(id).value=ajax.responseText;
				break;
				case 'p_innerHTML':
				parent.$(id).innerHTML=ajax.responseText;
				break;
				default:
				fillHTML($(id),ajax.responseText);
				//$(id).innerHTML=ajax.responseText;
				break;
			}
		}
	}
}


var fillHTML = function(el,HTMLString) {
	if (!el) return;
	if (window.ActiveXObject) { //For IE
	el.innerHTML = "<img style='display:none'/>" + HTMLString.replace(/<script([^>]*)>/ig, '<script$1 defer>');
	el.removeChild(el.firstChild)
	} else { //For Mozilla,Opare
	var nSibling = el.nextSibling;
	var pNode = el.parentNode;
	pNode.removeChild(el);
	el.innerHTML = HTMLString;
	pNode.insertBefore(el,nSibling)
	}
}




//通用图片轮换播放器 http://www.ruochi.com/main/post/25.html --------------- 
function bcastrPlayer(_width,_height,_file,_title,_link) {
	var PlayerSRC='/html/player/bcastr/31.swf';
	var FlashVars='bcastr_file='+_file+'&bcastr_title='+_title+'&bcastr_link='+_link;
	var PlayerHTML;
	PlayerHTML=('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+_width+'" height="'+_height+'">');
	PlayerHTML+=('<param name="movie" value="'+PlayerSRC+'"><param name="quality" value="high">');
	PlayerHTML+=('<param name="menu" value="false" /><param name=wmode value="opaque" />');
	PlayerHTML+=('<param name="FlashVars" value="'+FlashVars+'">');
	PlayerHTML+=('<embed src="'+PlayerSRC+'" wmode="opaque" FlashVars="'+FlashVars+'" menu="false" quality="high" width="'+_width+'" height="'+_height+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>'); 
	return PlayerHTML;
}

//通用视频轮换播放器 http://www.ruochi.com/main/post/24.html ---------------
function vcastrPlayer(_width,_height,_file,_title,_LogoText,IsAutoPlay) {
	if (typeof(IsAutoPlay)=='undefined') IsAutoPlay=0;
	if (typeof(_LogoText)=='undefined') _LogoText='';
	var PlayerSRC='/html/player/vcastr/22.swf';
	var FlashVars='vcastr_file='+_file+'&vcastr_title='+_title+'&IsAutoPlay='+IsAutoPlay+'&IsContinue=1&LogoText='+_LogoText;
	var PlayerHTML;
	PlayerHTML=('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+_width+'" height="'+_height+'">');
	PlayerHTML+=('<param name="movie" value="'+PlayerSRC+'"><param name="quality" value="high">');
	PlayerHTML+=('<param name="menu" value="false" /><param name="allowFullScreen" value="true" />');
	PlayerHTML+=('<param name="FlashVars" value="'+FlashVars+'">');
	PlayerHTML+=('<embed src="'+PlayerSRC+'" allowFullScreen="true" FlashVars="'+FlashVars+'" menu="false" quality="high" width="'+_width+'" height="'+_height+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>'); 
	return PlayerHTML;
}



function msgbox(un) {
if(typeof(un)=='undefined') var un='';
window.open('#'+un,'_self');//浏览器局顶
var mod='msgbox';//定义id
//var HeightValue=(document.getElementById&&document.all)?document.body.offsetHeight:'100%';//网页高度
var HeightValue=document.body.scrollHeight+"px"; //获得本页高度
$(mod+'_bg').style.display='block';//显示msgbox 背景
$(mod+'_bg').style.height=HeightValue;
$(mod).style.display='block';//显示msgbox 背景
imagePreload('/html/images/common/loader.gif');//预读图片
var txt;
txt='<table cellspacing="1" style="background:#333"><tr><td id="'+mod+'_c">';
txt+='<div style="width:300px;"></div><img src="/html/images/common/loader.gif" /><br /><br />数据处理中...'; 
txt+='<br /><br /><button class="button" type="button" onclick="msgbox_h()" >如果长时间无响应，请点击取消</button>';
txt+='</td></tr><tr><td id="MsgWaiting" style="color:#fff;text-align:center">';
txt+='</td></tr></table></div>';

$(mod).innerHTML=txt;

$(mod+'_bg').innerHTML='<iframe id="'+mod+'_bg_iframe" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" style="width:100%;height:'+HeightValue+';background:#000;filter:alpha(Opacity=0);opacity:0" ></iframe>';
}
function msgbox_h() {
var mod='msgbox';//定义id
$(mod+'_bg').style.display='none';//隐藏msgbox 背景
$(mod).style.display='none';//隐藏msgbox 背景
$(mod).innerHTML='';//清空
}
function imagePreload() {//图片预读
  var imgPreload = new Image();
  for (i = 0; i < arguments.length; i++) {
    imgPreload.src = arguments[i];
  }
}



//检测提交 ------
function CheckForm(mod) {
	switch(mod) {
		case 'baoming': //报名
		var cantNull = new Array(
			new Array('realname','请填写真实姓名！'),
			new Array('tel','您的联系电话留一个吧，我们会与您联系的！'),
			new Array('email','您的email留一个吧，我们会尽快与您联系的！'),
			new Array('randcode','请填写验证码！')
		);
		break;
		
		case 'question': //报名
		var cantNull = new Array(
			new Array('message','请填写你要了解的内容！'),
			new Array('randcode','请填写验证码！')
		);
		break;

		case 'gbook'://留言
		var cantNull = new Array(
			new Array('nickname','请填写留言昵称！'),
			new Array('message','请填写留言内容！'),
			new Array('randcode','请填写验证码！')
		);		
		break;
		
	}

	//Checking---------------------
	for (var i=0,n=cantNull.length;i<n;i++) {
		var id=cantNull[i][0];
		var msg=cantNull[i][1];
		var editor=cantNull[i][2];
		if(editor)$(id).value = getEditorContents(id);//更新编辑器文本区内容
		if ($(id).value=='') {
			alert(msg);
			if(!editor)$(id).focus();
			return false;
		}
	}
		
	msgbox();//数据处理
}
function Backurl(url) { window.open(url,'_top'); }

function reloadurl(url){
	if(typeof(url)=='undefined') return false;
	//window.location.reload(url);
	window.location.href=url;
}


//检测长度..
function checklen(obj,maxlen) {
	maxlen=(typeof(maxlen)!='undefined')?maxlen:100;
	if($(obj.name+'_info').style.display=='none')$(obj.name+'_info').style.display='';
	if(obj.value.length<=maxlen) { //小于
		$(obj.name+'_info').className='OkMsg';
		$(obj.name+'_info').innerHTML=(parseInt(maxlen-obj.value.length)>0)?'您还可以输入'+parseInt(maxlen-obj.value.length)+'个字符':'您的可输入字符已满。';
	} else {
		$(obj.name+'_info').className='ErrorMsg';
		$(obj.name+'_info').innerHTML='您的输入超出了'+parseInt(obj.value.length-maxlen)+'个字符';
		obj.value = obj.value.substring(0,maxlen);
		checklen(obj,maxlen);
	}
}


//表情插入
function emont_insert(obj,img) {
obj.value=obj.value+' '+img;
}


//获取验证码..
function GetRandCode(mod,id,lang) {
	if(typeof(id)=='undefined') id='randcode';
	if(typeof(lang)=='undefined') lang='en';
	$(id+'_img').src='/htm/apply/randcode/'+Math.random()+'/'+mod+'/'+lang+'.gif';
	$(id).value='';
	//$(id).focus();
}

//菜单
function menuFix(id) {
	var sfEls = document.getElementById(id).getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
	sfEls[i].onmouseover=function() {	this.className+=(this.className.length>0? " ": "") + "show";	}
	sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp("( ?|^)show\\b"), ""); }
	}
}



//弗莱斯输出
function flash_echo(flash) {
	var so = new SWFObject(flash.src, flash.name, flash.width, flash.height, "0", flash.bgcolor);
	so.addParam("quality", flash.wmode?flash.wmode:"best");
	so.addParam("wmode", flash.wmode?flash.wmode:"transparent");
	so.addParam("menu", flash.menu?flash.menu:"false");
	so.addParam("scale", flash.scale?flash.scale:"noscale");
	if(flash.flashVars)so.addParam("flashVars", flash.flashVars?flash.flashVars:"");
	so.write(flash.id);
}
