//****** Common JavaScript Document for surgezh@163.com QQ:366758899 (MSN:surgezh@yahoo.com.cn) 陈卓红 *****
//****** Create Date: 2007-04-21 ******//
function SetCookie(sName, sValue){//设置Cookie
	date = new Date();
	document.cookie = sName + "=" + escape(sValue) + ";";
}
function GetCookie(sName){//得到Cookie
	// cookies are separated by semicolons
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++)
	{
	// a name/value pair (a crumb) is separated by an equal sign
	var aCrumb = aCookie[i].split("=");
	if (sName == aCrumb[0])
		return unescape(aCrumb[1]);
	}
	// a cookie with the requested name does not exist
	return null;
}

function changeTRclass(objStr,cStr){
	objStr.className=cStr;
}

//显示Flash文件: swf
function showflash(flashURL,flashWidth,flashHeight){
	document.writeln ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+flashWidth+'" height="'+flashHeight+'">');
	document.writeln ('<param name="movie" value="'+flashURL+'" />');
	document.writeln ('<param name="quality" value="high" />');
	document.writeln ('<param name="wmode" value="transparent" />');
	document.writeln ('<embed src="'+flashURL+'" quality="high"  wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+flashWidth+'" height="'+flashHeight+'"></embed>');
	document.writeln ('</object>');
}

//显示滚动.jpg图片的Flash文件
///**********************************************************************************************
	//其中pics的值为: (如)pics=imgUrl1+"|"+imgUrl2+"|"+imgUrl3+"|"+imgUrl4+"|"+imgUrl5;
	//其中links的值为: (如)links=imgLink1+"|"+imgLink2+"|"+imgLink3+"|"+imgLink4+"|"+imgLink5;     **/
//**********************************************************************************************
function showPicRollFlash(flashWidth,flashHeigth,textHeight,flashBgColor,pics,links,texts){
	if(flashBgColor=="")flashBgColor="#F0F0F0";
	if(textHeight=="")textHeight=0;
	var linksStr='';
	var linksArray = links.split("|");
	for (var i=0; i < linksArray.length; i++){
		linksStr = linksStr + escape(linksArray[i]) + '|';
	}
	linksStr = linksStr.substr(0,linksStr.length -1);
	document.writeln ('<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0 width=' + flashWidth + ' height=' + flashHeigth + '>');
	document.writeln ('<param name=allowScriptAccess value=sameDomain>');
	document.writeln ('<param name=movie value=/mb/common/flashs/picScrollAds.swf />');
	document.writeln ('<param name=quality value=high />');
	document.writeln ('<param name=bgcolor value=' + flashBgColor + ' />');
	document.writeln ('<param name=menu value=false />');
	document.writeln ('<param name=wmode value=opaque />');
	document.writeln ('<param name=FlashVars value="pics=' +pics+ '&links=' +linksStr+ '&texts=' + texts+ '&borderwidth=' + flashWidth + '&borderheight=' + flashHeigth + '&textheight=0" />');
	document.writeln ('<embed src=/mb/common/flashs/picScrollAds.swf wmode=opaque FlashVars="pics=' +pics+ '&links=' +linksStr+ '&borderwidth=' + flashWidth + '&borderheight=' + flashHeigth + '&textheight='+textHeight+'"  menu=false bgcolor=' + flashBgColor + ' quality=high width=' + flashWidth + ' height=' + flashHeigth + ' allowScriptAccess=sameDomain type=application/x-shockwave-flash  pluginspage=http://www.macromedia.com/go/getflashplayer></embed>');
	document.writeln ('</object>');
}

function showFlv(sfile,sw,sh,isshowLogo){// showFlv(文件路径,宽,高,是否显示Logo)
	var files=sfile;
	var swf_width=sw;
	var swf_height=sh;
	var FlashVarsStr = 'vcastr_file='+files+'&IsAutoPlay=0&DefaultVolume=50&IsShowBar=2&BarColor=0xFF6600';
	if(isshowLogo)FlashVarsStr += '&LogoUrl=/images/logoswf.gif';
	
	document.write('<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="'+ swf_width +'" height="'+ swf_height +'">');
	document.write('<param name="movie" value="/vcastr22/vcastr22.swf">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="menu" value="false">');
	document.write('<param name="allowFullScreen" value="true">');
	document.write('<param name="FlashVars" value="'+ FlashVarsStr +'">');
	document.write('<embed src="/vcastr22/vcastr22.swf" allowFullScreen="true" FlashVars="'+FlashVarsStr+'" menu="false"  quality="high" width="'+ swf_width +'" height="'+ swf_height +'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'); document.write('</object>');	
}
function showAutomate(sfile,sw,sh,isshowLogo){//自动显示
	var defaultImg = '/images/notpic.gif';
	if(sfile=="" || sfile==null){
		document.write('<img src="'+defaultImg+'" width='+sw+' height='+sh+' border=0>');
		return;
	}
	var _sfile = sfile.toLowerCase();
	_sfile = _sfile.substr(_sfile.lastIndexOf('.')); //得到文件后缀名
	if(_sfile==""||_sfile==null){
		document.write('<img src="'+defaultImg+'" width='+sw+' height='+sh+' border=0>');
		return;
	}else{
		
		if(_sfile==".gif"||_sfile==".jpg"||_sfile==".png"||_sfile==".bmp"){//图片
			document.write('<img src="'+sfile+'" width='+sw+' height='+sh+' border=0>');
			return;
		}else if(_sfile==".swf"){//.swf
			showflash(sfile,sw,sh);
			return;
		}else if(_sfile==".flv"){//.flv
			showFlv(sfile,sw,sh,isshowLogo);
			return;
		}else{
			document.write('<img src="'+defaultImg+'" width='+sw+' height='+sh+' border=0>');
			return;
		}
	}
	
}

//显示视频文件: mp3,avi,wmv,wav,mp4,mid 等yahoo
function showVideo(videoURL,videoWidth,videoHeight){
document.writeln ('<object width="'+videoWidth+'" height="'+videoHeight+'" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" align="baseline" border="0" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">');
 document.writeln ('<param name="FileName" value="'+ videoURL +'">');
 document.writeln ('<param name="ShowControls" value="1">');
 document.writeln ('<param name="ShowPositionControls" value="1">');
 document.writeln ('<param name="ShowAudioControls" value="1">');
 document.writeln ('<param name="ShowTracker" value="1">');
 document.writeln ('<param name="ShowDisplay" value="0">');
 document.writeln ('<param name="ShowStatusBar" value="1">');
 document.writeln ('<param name="AutoSize" value="0">');
 document.writeln ('<param name="ShowGotoBar" value="0">');
 document.writeln ('<param name="AutoStart" value="1">');
 document.writeln ('<param name="PlayCount" value="0">');
 document.writeln ('<param name="AnimationAtStart" value="0">');
 document.writeln ('<param name="TransparentAtStart" value="0">');
 document.writeln ('<param name="AllowScan" value="0">');
 document.writeln ('<param name="EnableContextMenu" value="1">');
 document.writeln ('<param name="ClickToPlay" value="0">');
 document.writeln ('<param name="InvokeURLs" value="1">');
 document.writeln ('<param name="DefaultFrame" value="datawindow">');
 document.writeln ('<embed src="'+ videoURL +'" align="baseline" border="0" width="'+videoWidth+'" height="'+videoHeight+'" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=media&amp;sba=plugin&amp;" name="MediaPlayer" showcontrols="1" showpositioncontrols="1" showaudiocontrols="1" showtracker="1" showdisplay="0" showstatusbar="1" autosize="0" showgotobar="0" showcaptioning="0" autostart="1" autorewind="0" animationatstart="0" transparentatstart="0" allowscan="1" enablecontextmenu="1" clicktoplay="0" invokeurls="1" defaultframe="datawindow">');
 document.writeln ('</embed>');
 document.writeln ('</object>');
}

//复制本文网址发给QQ或MSN好友
function std_playUrl(obj)
{
if(obj==null)
{
  var ok=window.clipboardData.setData("Text",document.title+"\n"+document.location.toString());
  if(ok==true)alert("当前网址已被复制！"); 
  }
else
{
  var url=window.clipboardData.getData("Text");
  if(url==null){alert("剪切板文本内容为空！");return false;}
  var re1 = "/^((http|https|ftp|rtsp|mms|pmn):(\/\/|\\\\)[A-Za-z0-9\./=\?%\-&_~`@\]\':+!]+)/ig";
  var re2 = "/([a-zA-Z0-9_][.](\w)+[.]{1,}(net|com|cn|org|cc)(((\/[\~]*|\\[\~]*)(\w)+)|[.](\w)+)*(((([?](\w)+){1}[=]*))*((\w)+){1}([\&](\w)+[\=](\w)+)*)*)/ig";
  var t1=re1.test(url),t2=re2.test(url);
  if(!t1&&!t2){alert("剪切板内容不是网址，请检查!");return false;}
  if(confirm("确认要打开以下网址？\n\n"+url)){obj.href=(t1?"":"http://")+url;obj.target="_blank";return true}
  return false;
  }
}

//打开小窗口
function smallOpenWindow(furl,widthStr,heightStr){
	var ws=widthStr;
	var hs = heightStr;
	if(ws==null){
		ws = 500;	
	}
	if(hs==null){
		hs = 500;	
	}
	var nName = navigator.appName.toString().toLowerCase();	//返回的值 Opera,Microsoft Internet Explorer,Netscape,其它
	if(nName.indexOf("opera")>-1){
		ws = ws*1 + 100;
		hs = hs*1 + 50;
	}else if(nName.indexOf("microsoft")>-1){
		//alert("microsoft");
	}else if(nName.indexOf("netscape")>-1){
		//alert("netscape");
	}else{
		ws = ws*1 + 100;
		hs = hs*1 + 50;
	}
	window.open(furl,"_blank","top =150,left = 200,width ="+ws+",height="+hs+",status =0,toolbar=0,titlebar = 0,scrollbars =1,resizable =0,menubar =0,location =0，channelmode=0，directories =0");
}
function BASEtrim(str){
	  lIdx=0;rIdx=str.length;
	  if (BASEtrim.arguments.length==2)
	    act=BASEtrim.arguments[1].toLowerCase()
	  else
	    act="all"
      for(var i=0;i<str.length;i++){
	  	thelStr=str.substring(lIdx,lIdx+1)
		therStr=str.substring(rIdx,rIdx-1)
        if ((act=="all" || act=="left") && thelStr==" "){
			lIdx++
        }
        if ((act=="all" || act=="right") && therStr==" "){
			rIdx--
        }
      }
	  str=str.slice(lIdx,rIdx)
      return str
}

function BASEisNotNum(theNum){
	if (BASEtrim(theNum)=="")
		return true
	for(var i=0;i<theNum.length;i++){
	    oneNum=theNum.substring(i,i+1)
        if (oneNum<"0" || oneNum>"9")
          return true
    }
	return false
}

function parseNum(theNum){
  if (theNum.substring(0,1)==0)
    theNum=theNum.substring(1)
  return theNum
}

function BASEisNotInt(theInt){
	theInt=BASEtrim(theInt)
	if ((theInt.length>1 && theInt.substring(0,1)=="0") || BASEisNotNum(theInt)){
		return true
	}
	return false
}

function BASEisNotFloat(theFloat){
	len=theFloat.length
	dotNum=0
	if (len==0)
		return true
	for(var i=0;i<len;i++){
	    oneNum=theFloat.substring(i,i+1)
		if (oneNum==".")
			dotNum++
        if ( ((oneNum<"0" || oneNum>"9") && oneNum!=".") || dotNum>1)
          return true
    }
	if (len>1 && theFloat.substring(0,1)=="0"){
		if (theFloat.substring(1,2)!=".")
			return true
	}
	return false
}

function parseYMD(theYear,theMonth,theDay) {
  theYear=parseNum(theYear)
  theMonth=parseNum(theMonth)
  theDay=parseNum(theDay)
  if ((theYear < 1900) || (theYear > 3000)){
    return 1
  }
  if (theMonth < 1 || theMonth > 12){
    return 2
  }
  if ((theMonth==1 || theMonth==3 || theMonth==5 || theMonth==7 || theMonth==8 || theMonth==10 || theMonth==12) &&
      (theDay <1 || theDay > 31)
     ){
    return 3
  }
  if ((theMonth==4 || theMonth==6 || theMonth==9 || theMonth==11) &&
      (theDay <1 || theDay > 30)
     ){
    return 3
  }
  if (theYear%400==0 || (theYear%4==0 && theYear%100!=0)){  //闰年
    if (theMonth==2 && (theDay <1 || theDay > 29) )
      return 3
  }
  else  //平年
    if (theMonth==2 && (theDay <1 || theDay > 28) )
      return 3
  return 0
}

function isInvalidDate(theDate,separator){
  default_style=1
  if (theDate.length>10 || theDate.length<8)
    return true
  idx1=theDate.indexOf(separator)
  if (idx1==-1)
    return true
  idx2=theDate.indexOf(separator,idx1+1)
  if (idx2==-1)
    return true
  if (isInvalidDate.arguments.length>2)
  	default_style=isInvalidDate.arguments[2]
  if (default_style<1 || default_style>9){
  	alert("传入参数有误！请检查。")
	return true
  }
  if (default_style==1){
  theYear=theDate.substring(0,idx1)
  theMonth=theDate.substring(idx1+1,idx2)
  theDay=theDate.substring(idx2+1)
  }
  if (default_style==2){
  theMonth=theDate.substring(0,idx1)
  theDay=theDate.substring(idx1+1,idx2)
  theYear=theDate.substring(idx2+1)
  }
  if (theDay.length>2)
    return true
  if (parseYMD(theYear,theMonth,theDay)>0)
    return true
  else
    return false
}

function BASEalert(theText,notice){  
	  alert(notice)
	  theText.focus()
	  theText.select()
	  return false
}

function BASEreal_len(theText){ 
	  var real_len=0;
	  text_val=theText.value;
	  text_len=theText.value.length;
	  for(i=0;i<text_len;i++){
	    if (text_val.charCodeAt(i)>127){
		  real_len=real_len+2;
		}
	    else{
		  real_len++;
		}
  	  }
	  return(real_len);
}

function isEmailCheck (objStr) {
	var email = objStr;
	var is_error = false
	var pn_0 = email.indexOf("@")
	var pn_1 = email.indexOf(".",pn_0)
	var pn_2 = email.length
	if (pn_0<1 || pn_1<pn_0+2 || pn_1+2>pn_2){ 
		is_error=true
	}
	if (is_error) {
		return false
	}
	return true;
}

function Check_Email(string){ 
	var str_len = string.length;
	if (str_len<=5){
	   return true
    	}  
	for(i=0;i<str_len;i++){
	    if (string.charCodeAt(i)>127){
		return true 	
		}
	}
	if (string.indexOf("@")<2){
	    return true
    	}  
        if (string.indexOf(".")==1){
	    return true
    	}  
	if (string.indexOf(":")!=-1){
	    return true
	}
}

function BASEinterChar(obj){
	var Letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_";
	var i;
	var c;
	myString = obj;	//输入的字符串
	for( i = 0; i < myString.length; i ++ ){
	   	c = myString.charAt(i);
		if (Letters.indexOf(c) < 0){
			return false;
		}
	}
	return true;
}

function charAndNum(obj){
	var reStr = false;
	var reStr2 = false;
	var LettersAll = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
	var Letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var Letters2 = "1234567890"
	var c;
	var myString = obj;	//输入的字符串
	//if(myString.length<6 || myString.length>30){
		//return false;
	//}
	for(var i=0; i <myString.length; i++){
		c = myString.charAt(i);
		//是否为字符或数字
		if (LettersAll.indexOf(c) >= 0){
			//是否为字符
			if(!reStr){
				if(Letters.indexOf(c) >= 0)reStr = true;
			}
			//是否为数字
			if(!reStr2){
				if(Letters2.indexOf(c) >= 0)reStr2 = true;
			}
		}else{
			return false;
		}
	}
	
	if(reStr && reStr2){
		return true;
	}else{
		return false;
	}
	
}

function isUrl(urlStr){
	var re=/^http:\/\/[a-z_A-Z0-9]+\.[a-z_A-Z-0-9]+\..+$/;
	if(urlStr.match(re)==null){
		return false;
	}
	return true;
}		  

//ajax的使用
function ajaxShow(URLStr,showDiv){
	//检查开始
	var httpStr;
	if (window.XMLHttpRequest) { // Non-IE browsers
		httpStr = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
	   httpStr = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	   httpStr = "";
	   alert("您当前浏览器不支持因操作!");
	   return false;
	}
	httpStr.open("post",URLStr,false);
	httpStr.setRequestHeader("context-type","text/html; charset=gb2312");
	httpStr.send();
	var returnStr = unescape(httpStr.responseText);	//解密
	var oVDiv=document.getElementById(showDiv);
	if(httpStr.status==200){
		oVDiv.innerHTML = returnStr;
	}else{
		alert("您当前操作不成功!");
	   	return false;
	}
	//检查结束
}

//改变图片大小
function resizepic(thispic){
	if(thispic.width>600) thispic.width=600;
}

function loadAJAXData(url,contentid){
	var ocontent=getElement(contentid);
	var xhttp=getXmlhttp();		
		xhttp.onreadystatechange=function(){
			if(xhttp.readyState == 4 && xhttp.status==200)
			{					
				ocontent.innerHTML=xhttp.responseText;
			}
		}
	xhttp.open("GET",url,true);
	xhttp.send(null);
}
function getElement(aID){
  return (document.getElementById) ? document.getElementById(aID): document.all[aID];
}

function getXmlhttp(){
	var http_request;
	
	if(window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType("text/xml");
		}
	}
	else if (window.ActiveXObject) { 
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) { 
		window.alert("can't create XMLHttpRequest object.");
		return null;
	}	
	return http_request;
}

function reloadcode(showid){
	loadAJAXData('/mb/common/asp/reSafecode.asp',showid);
}