// JavaScript Document
//   增加一个名为   trim   的函数作为 
//   String   构造函数的原型对象的一个方法。 
String.prototype.trim = function()
{
    // 用正则表达式将前后空格 
    // 用空字符串替代。 
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

/*返回一个对象*/
function $( obj_id )
{
	return document.getElementById( obj_id );
}

/*返回一个数组*/
function $N( _tagName )
{
	return document.getElementsByTagName( _tagName );
}

/*返回一组样式为_className的数组*/
function getClassName( _className )
{
	return document.getElementsByClassName( _className );
}

/*返回在obj_id节点下获取的数组*/
function getChildTag( obj_id,_tagName )
{
	return $( obj_id ).getElementsByTagName( _tagName );
}

/*返回创建的节点*/
function $C( _tagName )
{
	return document.createElement( _tagName );
}

/*设为主页*/
var browser = new Object(); 
function getBrowser() {
    var b = navigator.userAgent.toLowerCase();
    browser = { 
        safari: /webkit/.test(b),
        opera: /opera/.test(b),
        ie6: /msie 6/.test(b) && !/opera/.test(b),
        ie7: /msie 7/.test(b) && !/opera/.test(b),
        msie: /msie/.test(b) && !/opera/.test(b),
        mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
    };
}
function setHomePage(title,url)
{
	getBrowser();
    if(browser.msie || browser.ie6) {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(url);
    }
    else if(browser.mozilla) {
        if(window.netscape)
        {
            try { 
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
            } 
            catch (e) { 
                alert("此项操作已被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); 
            }
        }

        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref(title,url);
    }    
}

/*将光标定位于页面中第一个可输入的位置*/
function initInputFocus()
{
	try{
		var obj_form = $N( 'form' )[0];
		var int_length = obj_form.length;
		for( var int_i=0; int_i<int_length; int_i++ )
		{
			if( obj_form[int_i].type && obj_form[int_i].type.toLowerCase() == 'text' )
			{
				obj_form[int_i].focus();
				return;
			}
		}
	}
	catch( e ){}
}

/*全选,反选*/
function chooseAll( t_id )
{
	var checkboxs = getChildTag( t_id,'input' );
	for( var i=0; i<checkboxs.length; i++ ){ checkboxs[i].checked = true; }
}
function chooseOth( t_id )
{
	var checkboxs = getChildTag( t_id,'input' );
	for( var i=0; i<checkboxs.length; i++ ){ checkboxs[i].checked = checkboxs[i].checked==true ? false : true; }
}

/*
 *等比例缩放图片
 *ImgD - 图片自身
 *iwidth - 最大宽度
 *iheight - 最大高度
*/
var flag = false;
function DrawImage( ImgD, iwidth, iheight )
{
	var image = new Image();
	image.src = ImgD.src;
	if( image.width > 0 && image.height > 0 )
	{
		flag = true;
		if( image.width/image.height >= iwidth/iheight )
		{
			if( image.width > iwidth )
			{
				ImgD.width = iwidth;
				ImgD.height = ( image.height*iwidth ) / image.width;
			}
			else
			{
				ImgD.width = image.width;
				ImgD.height = image.height;
			}
			//ImgD.alt=image.width+"×"+image.height;
		}
		else{
			if( image.height > iheight )
			{
				ImgD.height = iheight;
				ImgD.width = ( image.width*iheight ) / image.height;
			}
			else
			{
				ImgD.width = image.width;
				ImgD.height = image.height;
			}
			//ImgD.alt=image.width+"×"+image.height;
		}
	}
}

/*设置图片大小,防止图片撑破*/
/*
* obj_id   从该对象(id)中获取
* _tagName 获取的对象的tagName
* maxWidth 最大宽度
*/
function setImgs( obj_id,_tagName,maxWidth )
{
	var maxWidth = parseInt( maxWidth );//最大宽
	var imgs = getChildTag( obj_id, _tagName );
	for( var i=0; i<imgs.length; i++ )
	{
		var oldWidth,newWidth,oldHeight;
		if( parseInt( imgs[i].width ) > maxWidth )
		{
			oldWidth = imgs[i].width;
			oldHeight = imgs[i].height;
			newWidth = maxWidth;
			imgs[i].width = maxWidth;
			imgs[i].height = oldHeight*( newWidth/oldWidth );
		}
	}
}

/*图片预览*/
function previewImg( obj, id )
{
	var objSrc = obj.value.substring( obj.value.length - 3 ).toUpperCase();
	if( objSrc == 'GIF' || objSrc == 'JPG' || objSrc == 'PNG' )
	{
		$( id ).src = obj.value;
		$( id ).width = 60;
		$( id ).height = 60;
	}
	else
	{
		alert('您上传的图片不符合要求，请重新上传！');
		obj.outerHTML = obj.outerHTML;
		return false;
	}
}
/*网吧图片上传验证*/
var imgSize = 1024 * 300; //最大100K
//var imgSize = 1024 * 1024 * 2; //最大2MB
function checkImgSize( obj, id )
{
	/*
	var file = obj;
	var val = file.value;
	if( /^.*?\.(gif|png|jpg|jpeg)$/.test( val ) ){}
	else
	{
		alert("只能上传gif, png, jpg格式的图片，请重新选择图片！");
		obj.outerHTML = obj.outerHTML;
		return false;
	}
	var img = new Image();
	img.onreadystatechange = function()
	{
		if( img.readyState == "complete" )
		{
			if( img.fileSize <= 0 || img.fileSize > imgSize )
			{
				alert( "当前文件大小" + img.fileSize / 1024 + "KB, 超出最大限制 " + imgSize / 1024 + "KB" );
				obj.outerHTML = obj.outerHTML;
				return false;
			}
			else
			{
				//$( id ).src = obj.value;
				alert(1);
				$( id ).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = obj.value;
				$( id ).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = 'scale';
				//$( id ).width = 60;
				//$( id ).height = 60;
			}
		}
	}
	img.src = val;
	*/
	var objSrc = obj.value.substring( obj.value.length - 3 ).toUpperCase();
	if( objSrc == 'GIF' || objSrc == 'JPG' || objSrc == 'PNG' )
	{
		$( id ).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = obj.value;
    	$( id ).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = 'scale';
		$( id ).style.width = '70px';
		$( id ).style.height = '70px';
	}
	else
	{
		alert('您上传的图片不符合要求，请重新上传！');
		obj.outerHTML = obj.outerHTML;
		return false;
	}
}
function delPic( obj,id,Isrc )
{
	obj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = Isrc + 'no_pic.jpg';
	$( id ).outerHTML = $( id ).outerHTML;
}
function checkMemberImgSize( obj, id )
{
	var objSrc = obj.value.substring( obj.value.length - 3 ).toUpperCase();
	if( objSrc == 'GIF' || objSrc == 'JPG' || objSrc == 'PNG' )
	{
		$( id ).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = obj.value;
    	$( id ).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = 'scale';
		$( id ).style.width = '130px';
		$( id ).style.height = '130px';
	}
	else
	{
		alert('您上传的图片不符合要求，请重新上传！');
		obj.outerHTML = obj.outerHTML;
		return false;
	}
}

/*cookie操作*/
/*获取所有cookie*/
function getAllCookie()
{
	var str = document.cookie;
	if( str == '' )
	{
		str = '没有保存任何cookie！';
	}
	alert(str);
}

/*
* 设置cookie
* cName:cookie的name
* cValue:cookie的值
* cTime:cookie过期时间
*/
function setCookie( cName,cValue,cTime )
{
	var str = cName + '=' + escape( cValue );
	if( parseInt( cTime ) > 0 )
	{
		var date = new Date();
		var ms = cTime*3600*1000;
		str += "; expires=" + date.toGMTString();
	}
	document.cookie = str;
}

/*
* 获取指定的cookie值,并返回该值
* cValue;
*/
function getCookie( cValue )
{
	var CookieArray = document.cookie.split( '; ' );
	for( var i=0; i<CookieArray.length; i++ )
	{
		var temp = CookieArray[i].split( '=' );
		if( temp[0] == cValue )
			return unescape( temp[1] );
	}
}

/*
* 删除指定名为cValue的cookie
* 时间设置为过去的时间，值设置为joe
*/
function delCookie( cValue )
{
	var Date = new Date();
	date.setTime(date.getTime() - 10000);
	document.cookie = cValue + "=joe; expires=" + date.toGMTString();
}

/*
* 左侧菜单创建
*/
function creatNav( _navArray,pSrc)
{
	for( var i=0; i<_navArray.length; i++ )
	{
		var nDiv = $C( 'div' );
			//nDiv.onclick = function(){setNavCookie(this);}
		
		if( i==11 ){ nDiv.style.display = 'none'; }
		
		var nImg = $C( 'img' );
			nImg.src = pSrc + 'leftNav_' + [i+1] + '.gif';
			nImg.align = 'absmiddle';
		var nSpan = $C( 'span' );

		if (i == 100) { nSpan.innerHTML = '<a target="ControlContent" href="' + _navArray[i][1] + '">' + _navArray[i][0] + '</a>' + '&nbsp;<img src="' + pSrc + 'new1.gif" />'; }
		else if (i == 15) { nSpan.innerHTML = '<a target="ControlContent" href="' + _navArray[i][1] + '">' + _navArray[i][0] + '</a>'; }
		else { nSpan.innerHTML = '<a target="ControlContent" href="' + _navArray[i][1] + '">' + _navArray[i][0] + '</a>'; }
		
		nDiv.appendChild( nImg );
		nDiv.appendChild( nSpan );
		$( 'leftNav' ).appendChild( nDiv );
	}
	
	var lDiv = $C( 'div' );
		lDiv.style.height = '2px';
		lDiv.style.overflow = 'hidden';
		lDiv.style.width = '120px';
		lDiv.style.borderTop = '1px solid #CDD6DB';
		lDiv.style.margin = '10px auto';
		lDiv.style.boderBotton = '1px solid #fff';
	$( 'leftNav' ).appendChild( lDiv );
	
//	var nP = $C( 'p' );
//		nP.style.textAlign = 'center';
//		nP.style.marginBottom = '30px';
//		nP.innerHTML = '<a href="' + _logout + '"><img src="' + pSrc + 'logout.jpg" /></a>';
//	$( 'leftNav' ).appendChild( nP );
}
function setNavCookie( obj )
{
	var oImg = obj.getElementsByTagName('img')[0];
	var oA = obj.getElementsByTagName('a')[0];
	document.cookie = 'imgSrc=' + oImg.src;
	document.cookie = 'inner=' + escape( oA.innerHTML );
	//alert(document.cookie);
}
function getNavCookie( aLink )
{
	var imgSrc,inner;
	var navCookie = document.cookie.split( '; ' );
	for( var i=0; i<navCookie.length; i++ )
	{
		var temp = navCookie[i].split( '=' );
		if( temp[0] == 'imgSrc' ){ imgSrc = temp[1]; }
		if( temp[0] == 'inner' ){ inner = unescape( temp[1] ); }
	}
	
	if( imgSrc == null || imgSrc == '' || imgSrc == 'undefined' || inner == null || inner == '' || inner == 'undefined' ){ return false; }
	
	var nTable = $C( 'table' );
		nTable.width = '100%';
		nTable.border = '0';
		
	var nTbody = $C( 'tbody' );
	
	var nTr = $C( 'tr' );
	
	var nLeftTd = $C( 'td' );
		nLeftTd.width = '50%';
		nLeftTd.align = 'left';
		
	var nRightTd = $C( 'td' );
		nRightTd.width = '50%';
		nRightTd.align = 'right';
		
	var nDiv = $C( 'div' );
	
	var nImg = $C( 'img' );
		nImg.src = imgSrc;
		nImg.align = 'absmiddle';
		
	var nSpan = $C( 'span' );
		nSpan.innerHTML = inner;
		
	var nA = $C( 'a' );
		nA.href = aLink;
		nA.className = 'rtn';
		nA.innerHTML = '返回主页管理中心 &gt;&gt;';
		
	nDiv.appendChild( nImg );
	nDiv.appendChild( nSpan );
	nLeftTd.appendChild( nDiv );
	nRightTd.appendChild( nA );
	nTr.appendChild( nLeftTd );
	nTr.appendChild( nRightTd );
	nTbody.appendChild( nTr );
	nTable.appendChild( nTbody );
	$( 'nowpage' ).appendChild( nTable );
}

/*IP地址操作,验证*/
function mask( obj,ip )
{
	obj.value = obj.value.replace( /[^\d]/g,'' );
	key1 = event.keyCode;
	if( key1 == 37 || key1 == 39 )
	{
		obj.blur();
		nextip = parseInt( obj.id.substr(2,1) );
		nextip = key1 == 37 ? nextip-1 : nextip+1;
		nextip = nextip >= 5 ? 1 : nextip;
		nextip = nextip <= 0 ? 4 : nextip;
		$( ip + nextip ).focus();
	} 
	if( obj.value.length >= 3 ) 
	if( parseInt( obj.value ) >= 256 || parseInt( obj.value ) <= 0 )
	{
		alert( parseInt( obj.value ) + "IP地址错误！" );
		obj.value = "";
		obj.focus();
		return false;
	}
	else 
	{
		obj.blur();
		nextip = parseInt( obj.id.substr( 2,1 ) ) + 1;
		nextip = nextip >= 5 ? 1 : nextip;
		nextip = nextip <= 0 ? 4 : nextip;
		$( ip + nextip ).focus();
	}
}
function mask_c( obj )
{
	clipboardData.setData( 'text',clipboardData.getData('text').replace(/[^\d]/g,''))
}
function setIp( obj )
{
	ipArray = obj.split( '.' );
	$('ip1').value = ipArray[0];
	$('ip2').value = ipArray[1];
	$('ip3').value = ipArray[2];
	$('ip4').value = ipArray[3];
	event.returnValue = false; //此事是防止客户端事件回发，进行提交PostBack
	return false;
}
function clearIp()
{
	$('ip1').value = '';$('ip2').value = '';$('ip3').value = '';$('ip4').value = '';
}

/*上传图片限制*/
UpLoadFileCheck = function()
{
	this.AllowExt         = ".jpg,.gif";   //允许上传的文件类型 0为无限制 每个扩展名后边要加一个"," 小写字母表示
	this.AllowImgFileSize = 0;             //允许上传文件的大小 0为无限制 单位：KB
	this.AllowImgWidth    = 0;             //允许上传的图片的宽度 0为无限制　单位：px(像素)
	this.AllowImgHeight   = 0;             //允许上传的图片的高度 0为无限制　单位：px(像素)
	this.ImgObj           = new Image();
	this.ImgFileSize      = 0;
	this.ImgWidth         = 0;
	this.ImgHeight        = 0;
	this.FileExt          = "";
	this.ErrMsg           = "";
	this.IsImg            = false;         //全局变量
}
UpLoadFileCheck.prototype.CheckExt = function( obj )
{
	this.ErrMsg = "";
	this.ImgObj.src = obj.value;
	//this.HasChecked=false;
	if( obj.value == "" )
	{
		this.ErrMsg = "\n请选择一个文件";
	}
	else
	{
		this.FileExt = obj.value.substr( obj.value.lastIndexOf( "." ) ).toLowerCase();
		if( this.AllowExt != 0 && this.AllowExt.indexOf( this.FileExt ) == -1 )//判断文件类型是否允许上传
		{
			this.ErrMsg = "\n该文件类型不允许上传。请上传 " + this.AllowExt + " 类型的文件，当前文件类型为" + this.FileExt;
		}
	}
	if( this.ErrMsg != "" )
	{
		this.ShowMsg( this.ErrMsg, false );
		return false;
	}
	else
	return this.CheckProperty( obj );
}
UpLoadFileCheck.prototype.CheckProperty = function( obj )
{
	if( this.ImgObj.readyState != "complete" )
	{
		sleep( 1000 );//一秒使用图能完全加载
	}
	if( this.IsImg == true )
	{
		this.ImgWidth  = this.ImgObj.width; //取得图片的宽度
		this.ImgHeight = this.ImgObj.height;//取得图片的高度
		
		if( this.AllowImgWidth != 0 && this.AllowImgWidth < this.ImgWidth )
		this.ErrMsg = this.ErrMsg + "\n图片宽度超过限制。请上传宽度小于" + this.AllowImgWidth + "px的文件，当前图片宽度为" + this.ImgWidth + "px";

		if( this.AllowImgHeight != 0 && this.AllowImgHeight < this.ImgHeight )
		this.ErrMsg = this.ErrMsg + "\n图片高度超过限制。请上传高度小于" + this.AllowImgHeight + "px的文件，当前图片高度为" + this.ImgHeight + "px";
	}

	this.ImgFileSize = Math.round( this.ImgObj.fileSize/1024*100 )/100;//取得图片文件的大小
	if( this.AllowImgFileSize != 0 && this.AllowImgFileSize < this.ImgFileSize )
	this.ErrMsg = this.ErrMsg + "\n文件大小超过限制。请上传小于" + this.AllowImgFileSize + "KB的文件，当前文件大小为" + this.ImgFileSize + "KB";

	if( this.ErrMsg != "" )
	{
		this.ShowMsg( this.ErrMsg, false );
		document.getElementById( 'adPic' ).outerHTML = document.getElementById( 'adPic' ).outerHTML;//file域置为空值
		return false;
	}
	else
	return true;
}
UpLoadFileCheck.prototype.ShowMsg = function( msg,tf )//显示提示信息 tf=false 显示错误信息 msg-信息内容
{
	alert( msg );
}
function sleep( num )
{
	var tempDate   = new Date();
	var tempStr    = "";
	var theXmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
	while( ( new Date() - tempDate ) < num )
	{
		tempStr += "\n" + ( new Date() - tempDate );
		try{
			theXmlHttp.open( "get", "about:blank?JK="+Math.random(), false );
			theXmlHttp.send();
		}
		catch(e){}
	}
	return;
}
function checkImg( obj,size )
{
	var d   = new UpLoadFileCheck();
	d.IsImg = true;
	d.AllowImgFileSize = size;
	d.CheckExt( obj );
}

/*左右互考*/
function aa(d,t)
{
	var tOps = $('barList').getElementsByTagName( 'option' );
	var isInset = 0;
	for(var i=0;i<$(d).options.length;i++)
	{
		if($(d).options[i].selected==true)
		{
			for( var j=0; j<tOps.length; j++ )
			{
				if( tOps[j].text == $(d).options[i].text )
				{
					isInset = 1;
				}
			}
			if( isInset == 0 )
			{
				addoption($(d).options[i].text,$(d).options[i].value,t);
			}
			else
			{
				alert('您已经选择该网吧了！');
			}
		}
	}
}
function addoption(t,v,s)
{
	var s=s||"barList";
	var op=document.createElement("option");
	op.appendChild(document.createTextNode(t));
	op.value=v;
	$(s).appendChild(op);
}
function opdel(a)
{
	var obj=$(a);
	for (var i=obj.length-1;i>=0;i--)
	{
		if (obj.options[i].selected)
		{
			obj.options[i]=null;
		}
	}
}
function sel(d)
{
	for(var i=0;i<$(d).length;i++)
	{
		$(d).options[i].selected=true;
	}
}
function shang(a)
{
	var obj2=$(a);
	var p="",n="";
	if(obj2.options.selectedIndex>0)
	{
		for(var i=0;i<obj2.length;i++)
		{
			if(obj2.options[i].selected)
			{
				p=obj2.options[i];
				n=obj2.options[i-1];
				obj2.insertBefore(p,n);
			}
		}
	}
}
function next(a)
{
	var obj2=$(a);
	var p="",n="";
	if(obj2.options.selectedIndex!=obj2.length-1)
	{了
		for(var i=0;i<obj2.length;i++)
		{
			if(obj2.options[i].selected)
			{
			   p=obj2.options[i];
			   n=obj2.options[i+1];
			   obj2.insertBefore(n,p);
			   return;
			}
		}
	}
}
function moveall(l,r)
{
	var obj2=$(l);
	var obj3=$(r);
	
	for(var i=0;i<obj2.length;i++)
	{
		if(obj2.options[i].selected)
		{
			var s=obj2.options.selectedIndex;
			var oo=obj2.options;
			addoption(oo[i].text,oo[i].value,r);
		}
	}
	
	for (var i=obj2.length-1;i>=0;i--)
	{
		if(obj2.options[i].selected){
			obj2.options[i]=null;
		}
	}
}











