/**
 *@version	CnYuComm v0.1 - CnYu Common JavaScript Function Pack.
 
 *@thanks	Zarknight<zarknight@gmail.com>
 
 *@copyright(c)<2006-2009>,Zarknight & yLin Rain<cisky@126.com>
 *infos		HTTP://WWW.CnYu.NET
 */
 
//function ChkAll(){
//    var cssflag = (arguments.length==0)?".chkall":arguments[0];
//    var arr = $$(cssflag+' input[type=checkbox]');
//    for(var i=0;i<arr.length;i++){
//        arr[i].checked=true;
//    }
//}
//function GetChkAllValue(){
//    var cssflag = (arguments.length==0)?".chkall":arguments[0];
//    var arr = $$(cssflag+' input[type=checkbox]');
//    for(var i=arr.length;i>0;i--){
//        if(!arr[i].checked) arr.erase(arr[i]);
//    }
//}

//全选指定参数复选框
// formid 表单名称
// prefixstr 名字开始标示
// checkedstr 获取设置状态值
function ChkAll(formid,prefixstr,checkedstr){
    for(var i=0;i<formid.elements.length;i++){
        var el = formid.elements[i];
        if(el.name.substr(0,prefixstr.length)==prefixstr){
            el.checked = checkedstr;
        } 
    }
}
//将选定复选框组转为数组存入指定表单
// formid 表单名称
// prefixstr 名字开始标示
// toid 要存入的表单名
function GetChkAllValue(){
    if (arguments.length<2) return;
    var formid=arguments[0];
    var prefixstr=arguments[1];
    var toid=null;
    if(arguments.length=3&&toid){ 
        toid =arguments[2];
	    $(toid).value = '';
	}
	var temp = '';
    for(var i=0;i<formid.elements.length;i++){
        var el = formid.elements[i];
        if(el.name.substr(0,prefixstr.length)==prefixstr){
			if(el.checked==true)
			{
				if(temp!='') temp+=',';
				temp+=el.value;
			}
        } 
    }
    if(toid!=null) $(toid).value=temp;
    else return temp;
}

/*验证码Validate
默认为英文验证码,格式为:
img.id=Validate,input.class=ValidChk
中文验证码格式为:
img.id=Validate1,input.class=ValidChk
*/
window.addEvent('domready', function() {
	var uri = '/CnYuComm/img.aspx';
	
	if ($('Validate')){//英文验证码
		var params = $H({'timestamp': $time()});
		var img_uri = uri + '?' + params.toQueryString();
		$('Validate').set('src',img_uri).setStyle('cursor','pointer');
		
		$('Validate').addEvent('click',function(event){
			params.set('timestamp', $time());
			var img_uri = uri + '?' + params.toQueryString();
			this.set('src',img_uri);
		});
	}
	
	if ($('Validate1')){//中文验证码
		var params = $H({'Lan': 'CN', 'timestamp': $time()});
		var img_uri = uri + '?' + params.toQueryString();
		$('Validate1').set('src', img_uri).setStyle('cursor','pointer');
		
		$('Validate1').addEvent('click', function(event){
			params.set('timestamp', $time());
			var img_uri = uri + '?' + params.toQueryString();
			this.set('src',img_uri);
		});
	}
	
	$$('input.ValidChk').each(function(el){
		$(el).addEvent('blur',function(event){
			new Request({
				url:'/CnYuComm/ValidateCode.aspx?Code='+$(el).value,
				method: 'get',
		        onComplete: function(txt){
					if(this.response.text=='YES')
					{
						$(el).setStyle('border','1px solid #ecf5ef');
					}
					else
					{
						$(el).setStyle('border','1px solid #ff0000');
					}
		        }
		    }).send();	
		});
	});
});

/**
 * Tabber功能实现类，感谢zarknight提供MooTabber！
 * 为避免与旧版本冲突,正式更名为CnYuTabber.
 */
var CnYuTabber = new Class({
	Implements: Options,
	options:{
		mousetype:'click',
		tabhead:'li',
		tabbody:'div'
	},
	initialize: function(id,options){
		this.setOptions(options);
		var mousetype = this.options.mousetype;
		var tabhead = this.options.tabhead;
		var tabbody = this.options.tabbody;
		var titles = $$('#'+id+' .TabTitle '+tabhead);
		var contents = $$('#'+id+' .TabContent '+tabbody);
		this.titles = titles;
		this.contents = contents;
		
		titles.each(function(title){
			title.addEvent(mousetype, function(event){
				titles.each(function(content, index){
					content.className = (content == title) ? 'active' : 'normal';
					contents[index].setStyle('display', (content == title) ? 'block' : 'none');
				});
			});
		});
	},
	
	select: function(index){
		return this.titles[index].fireEvent(this.options.mousetype);
	}
	
});
/**
Tips by Manuel Garcia (thekeeper)
 * http://www.mgarcia.info
**/
window.addEvent('domready', function() {
	$$('.CnYuTips').each(function(el){
	    //new CnYuTips(el);
	});
});

var CnYuTips = new Class({

    initialize: function(el) {
		alert('x');
	    this.span = new Element('span').addClass('hint')
	    .set('html',el.getProperty('alt')).inject(el, 'after');
	    
	    var span2 = new Element('span').addClass('hint-pointer').inject(this.span);
			this.img = new Element('img').setProperty('src','/images/close.png')
			.inject(span2, 'before');
			
		  this.AddEvent(el);
		  
		},
		AddEvent: function(el) {
			var Localthis = this;
			this.img.addEvent('click', function(event) {
				Localthis.Minimize(el);
	  			Localthis.Effect(1,0,Localthis.span);
			})
			el.addEvent('focus', function(event) {
				Localthis.span.setStyle('display','inline');
	  			Localthis.Effect(0,1,Localthis.span);
			})
			el.addEvent('blur', function(event) {
			    Localthis.Effect(1,0,Localthis.span);
			});
		
    },
	
    Effect: function(s,e,el) { // start, end , element
      	var ef = new Fx.Style(el, 'opacity', {
				duration: 500,
		  	transition: Fx.Transitions.quartInOut
		  });
		  ef.start(s,e);
    },
    
	Minimize: function (el) {
			// make minihint
      var Localthis = this;
    }
	
});

//建立cookie
function setCookie(name,value)
{
	var Days = 30; //此 cookie 将被保存 30 天
	var exp = new Date(); //new Date("December 31, 9998");
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString();
}
//获取cookie
function getCookie(name)
{
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null) return unescape(arr[2]); return null;
}
//accordion，滑动菜单
		function myaccordion(e1,e2,id){
			var accordion = new Accordion(e1+'.atStart', e2+'.atStart', {
				opacity: false,
				onActive: function(toggler, element){
					toggler.setStyle('color', '#ff3300');
				},
				
				onBackground: function(toggler, element){
					toggler.setStyle('color', '#222');
				}
			}, $(id));
			
			//添加新菜单
			//var newTog = new Element(e1, {'class': 'toggler'}).se('html','Common descent');
			
			//var newEl = new Element(e2, {'class': 'element'}).set('html','');
			
			//accordion.addSection(newTog, newEl, 0);
		}
//收缩栏目
var JSHidden = function(img,id){
	var iurl = $(img).getProperty('src');
	if(iurl.indexOf("hidden")>=0){
		$(img).setProperties({'src':iurl.replace(/hidden/g,"show"),'alt':'关闭'});
		$(id).setStyle('display','');
		}
	else{
		$(img).setProperties({'src':iurl.replace(/show/g,"hidden"),'alt':'打开'});
		$(id).setStyle('display','none');
		}
	
	}
	
//列表控制显示（IE）
window.addEvent('domready', function() {
	$$('input.jsLCss').each(function(el){
    	el.addEvent('click', function(event) {
    	var c=0;
    	$$('input[id^=cc]').each(function(el){
        if($(el).getProperty('checked')==true) c+=1;
    	});
    	var colid=$(el).getProperty('id').replace(/cc/g,'col');
    	alert(c+'aaaaa');
      if(c==0) {$(el).setProperty('checked',true);}
      if($(el).getProperty('checked')==true) $(colid).setStyle('display','');
      else $(colid).setStyle('display','none');
		});
	});
});

//列表控制拖动（IE）
window.addEvent('domready', function() {
	$$('span.jsRS').each(function(el){
    	el.addEvent('mousedown', function(event) {
        $(el).mouseDownX=event.clientX;
        $(el).pareneTdW=$(el).parentElement.offsetWidth;
        $(el).pareneTableW=T1.offsetWidth;
        $(el).setCapture();
		});
    	el.addEvent('mousemove', function(event) {
        if(!$(el).mouseDownX) return false;
        var newWidth=$(el).pareneTdW*1+event.clientX*1-$(el).mouseDownX;
        if(newWidth>0)
        {
          $(el).parentElement.style.width = newWidth;
          T1.style.width=$(el).pareneTableW*1+event.clientX*1-$(el).mouseDownX;
        }
		});
    	el.addEvent('mouseup', function(event) {
        $(el).releaseCapture();
        $(el).mouseDownX=0;
		});
		
	});
});

//生成Tree
var CnYuTree = function(){

    if (arguments.length>7) return false;
	var myArr = new Array("","","","","","","");
      
    if(arguments.length==0){
        myArr[0] = "Tree";
    }
    else{
        for (var i=0;i<arguments.length;i++){
            myArr[i] = arguments[i];
        }
    }

    if ($("u"+myArr[0])){
        if($("u"+myArr[0]).getStyle('display')=='none'){
            $("u"+myArr[0]).setStyle('display','');
            if($("i"+myArr[0])) {
                $("i"+myArr[0]).setProperty('src',$('i'+myArr[0]).getProperty('src').replace(/hidden/g,"show"));
                $("f"+myArr[0]).setProperty('src',$('f'+myArr[0]).getProperty('src').replace(/hidden/g,"show"));
            }
        }
        else{
            $("u"+myArr[0]).setStyle('display','none');
            if(("i"+myArr[0])) {
                $("i"+myArr[0]).setProperty('src',$('i'+myArr[0]).getProperty('src').replace(/show/g,"hidden"));
                $("f"+myArr[0]).setProperty('src',$('f'+myArr[0]).getProperty('src').replace(/show/g,"hidden"));
            }
        }
    }
    else{
        var temp = $(myArr[0]).innerHTML.replace(/hidden/g,"show");
        $(myArr[0]).set('html',temp+'<ul class=CnYuTree><li style="color: #a9a9a9;"><img src=/images/tree/loader.gif />loading...</li></ul>');

		new Request({
			url:'/CnYuMin/CnYuTree.aspx',
            data:{
                'c':myArr[0],
                'k':myArr[1],
                'b':myArr[2],
                'n':myArr[3],
                'u':myArr[4],
                'g':myArr[5],
                't':myArr[6]
            },
            update:null,
            onComplete: function(){
                $(myArr[0]).set('html',temp+this.response.text);
            }
        }).send();
    }
}
//关闭树
var CloseItem = function(el){
    $(el).setStyle('display','none');
}


//改变对象高度
var changesize = function(id,h){
	if (parseInt($(id).offsetHeight)+h>100) {
		$(id).Height = (parseInt($(id).offsetHeight) + h);
	}
}
//selclass无限分类调用
function selectShow(uri,sid,pid)
{
var id = $('cid').value;
if (pid!=-1) 
	{
	pid=id;
	var tempId = "selBack"+sid;
	new Request({
		url:uri,
		postBody:"action=sel&sid="+sid+"&cid="+pid,
		update:tempId
	}).send();
	}
else
	{
	pid=0;
	new Request({
		url:uri,
		postBody:"action=sel&sid="+sid+"&cid="+pid,
		update:"showSelectList"
	}).send();
	}
}

function mylock1(){
      event.returnValue=false;
    }
//msg提示信息
var msg = function(json){
	var m=0;
	for(;m<50;m++)
	{
		if(!$('msgBox'+m)) break;
	}
	$(document.body).setStyle('overflow', 'hidden');
	var position = $(document.body).getCoordinates();

	var w = json.w?json.w:300;
	var h = json.h?json.h:80;
	var l = json.l?json.l:Math.ceil((position.width-w)/2);
	var t = json.t?json.t:Math.ceil((position.height-h)/2);
	this.div = new Element('div', {
        'id': 'msgBox'+m,
        'class':'msgBox'
    }).inject(document.body).setStyle('z-index',50+m).fade(0.95);

	new Element('div', {
		'id': 'msgBack'+m,
		'class':'msgBack',
		'styles': {
	        'top':t, 
	        'left':l,
	        'width':w
        }
    }).inject(this.div);
	
	new Element('div', {
        'id': 'msgShow'+m,
        'class':'msgShow',
		'styles':{
			'height':h-20
		}
    }).inject('msgBack'+m);
	//$('msgBack'+m).makeDraggable();
	new Element('div', {
        'id': 'msgLink'+m,
        'class':'msgLink'
    }).inject('msgBack'+m);
        
  new Element('div', {
        'id': 'bDiv'+m,
        'class':'bDiv'
  }).inject('msgBack'+m);
		
  if (json.c==1) {
        new Element('img', {
           'src': '/images/close.png',
           'align': 'right',
           'events': {
              'click': function(e){
                  $('msgBox'+m).destroy();
                  $(document.body).setStyle('overflow', 'auto');
              }
           }
       }).inject('bDiv'+m);
  }
		
  new Element('span', {
       'id': 'bMsg'+m
  }).inject('bDiv'+m).set('html','<A HREF=HTTP://WWW.CnYu.NET>CnYu.NET</A>');
	var temp='';
	if(json.i!=-1)
	{
    temp='<img src=/images/notice' + json.i + '.gif />';
	}
	temp +=unescape(json.msg);
	$('msgShow'+m).set('html',temp);
	
	json.links.each(function(el){
		new Element('a', {'href': el.url,'text':el.text}).inject('msgLink'+m);
	});
	return m;
}
//menu下拉菜单，仍有问题
window.addEvent('domready', function() {
	$$('.menu').each(function(el){
    	el.addEvent('mouseenter', function(event) {
    	var evt = new Event(event);
    	var ipt = evt.target;
    	ipt.setProperty('out');
			new DivList(el);
			if($('zarkDiv')){
					$('zarkDiv').addEvent('mouseleave', function(e){
					$('zarkDiv').setStyle('display','none');
					$(el).setStyle('background','');
        });
			}
		});
	});
});
//生成列表(FF)
window.addEvent('domready', function() {
	$$('.CnYuTable').each(function(el){
        new Request({
			url:window.location.pathname,
		    method: 'get',
            data: {
			    action: 'List'	
		    },
            onComplete: function(txt){
                CnYuTable(JSON.decode(txt));
            }
        }).send();
	});
});
//Ajax+json List&Control
var CnYuTable = function(json){
	//if(!$(json.cpid)) msg(JSON.decode("{i:1,msg:'pid或cpid参数设置错误！',c:0,links:[]}"));
	myid = json.id ? json.id : 'T1';    
	if(!$(myid)) {
		cn = json.cn ? json.cn.split('|') : [];

        if (!$(json.pid)) {
			new Element('table', {
				'id': myid,
				'class': 'adminTable'
			}).setProperties({
				'cellPadding': 4,
				'cellSpacing': 1
			}).inject(document.body);
		} else {
			new Element('table', {
				'id': myid,
				'class': 'adminTable'
			}).inject(json.pid).setProperties({
				'cellPadding': 4,
				'cellSpacing': 1
			});
		}
		
		new Element('thead',{'id':'T1th'}).inject(myid);//插入表头
		new Element('tr',{'id':'T1tr'}).inject('T1th');//插入表头
		new Element('div',{'id':'hDiv'}).setStyle('display', 'none').inject(json.pid);//插入隐藏span
		new Element('ul',{'id':'hUl'}).inject('hDiv');//插入ul
        new Element('colgroup',{
			'id':'cols'
		}).inject(myid);	//插入colgroup
        for(var i=0;i<cn.length;i++) {
			new Element('th').set('html','<span class=jsRS>|</span>'+cn[i]).inject('T1tr');//插入列头
            
			new Element('col',{
				'id': 'col'+i
			}).inject('cols');	//插入col
            
			new Element('li').set('html','<input id="cc'+i+'" type="checkbox" checked="checked" class="jsLC" />'+cn[i]).inject('hUl');	//插入列表控制
        }
        
    }
	
	json.tB.each(function(el){
        new Element('tBody', {'id': el.id}).inject(myid);//插入tbody
 	    el.tR.each(function(i){
            new Element('tr',{'id':i.id}).inject(el.id);//插入tr
            i.tD.each(function(j){
	            new Element('td',{'id':j.id}).set('text',j.txt).inject(i.id);//插入td
	            j.act.each(function(k){
	                $(j.id).setProperty(k.n,k.p);//设置td属性
	            });
	        });
	    });
    });

	$('T1tr').addEvent('click',function(event){
		var p = $('T1tr').getCoordinates();
		var l = p.left;
		var t = p.top+p.height;
		$('hDiv').setStyles({
			'left':l,
			'top':t,
			'display':'',
			'background':'#fff',

			'border:':'2px',			
			'position':'absolute'
		});
		new Element('img', {
           'src': '/images/close.png',
           'events': {
              'click': function(e){
                  $('hDiv').destroy();
              }
           }
       }).inject('hDiv');
	    new msg(JSON.decode("{i:3,msg:'"+$('hDiv').innerHTML+"',w:200,l:"+l+",t:"+t+",c:1,links:[]}"));	
	});
	
	$$('input.jsLC').each(function(el){
    	el.addEvent('click', function(event) {
    		var i = 0;
			
	    	$$('input[id^=cc]').each(function(el){
	        	if($(el).getProperty('checked')) i++;
	    	});
			
    		var colid = $(el).getProperty('id').replace(/cc/g, 'col');
    		
      		if(i == 0) {
				$(el).setProperty('checked', true);
			}
      		
			if ($(el).getProperty('checked')) {
				$(colid).setStyle('display', '');
			} else {
				$(colid).setStyle('display', 'none');
			}
     	});
	});
}

//input列表
window.addEvent('domready', function() {
	$$('.zarkDiv').each(function(el){
    	el.addEvent('click', function(event) {
			new DivList(el);
		});
	});
});
//input输入提醒
window.addEvent('domready', function() {
	$$('input.Ac').each(function(el){
    	el.addEvent('keyup', function(event) {
			var evt = new Event(event);
			var ipt = evt.target;
			ipt.setProperty('pa', ipt.value);
			new DivList(el);
		});
	});
});
//input输入更新提交
function search(el){
	var temp = $(el).value;
	$(el).setProperty('pa', temp);
	$(el).setProperty('w', '500px');
	temp = $(el).getProperty('url');
	$(el).setProperty('url',$(el).getProperty('href'));
	new DivList(el);
	$(el).setProperty('w', '');
	$(el).setProperty('url',temp);
}

//input输入更新
function supdate(str,uri){
	new Request({
		url:uri,
		postBody:"k="+str+"&up=1",update:null
	}).send();
}

/**
 * DivList功能实现类，为感谢zarknight帮助,故命名为zarkDiv
  by 白菜(CnYu.NET)
 */
 //CnYuTree
 /*
window.addEvent('domready', function() {
	$$('.CnYuTree').each(function(el){
    	el.addEvent('click', function(event) {
			new DivList1(el);
			new Element('div', {
				'id': 'CnYuTree'
			}).inject('listShow');

		});
	});
});
//重构DivList
var DivList1 = new Class({
	initialize: function(el) {
		$(el).setStyle('background','white url(/images/inputloading.gif) no-repeat right');
		if ($('CnYuDiv')&&$(el).getProperty('reload')) $('CnYuDiv').destroy();
		var position = $(el).getCoordinates();
		var w = ($(el).getProperty('w'))?$(el).getProperty('w'):$(el).clientWidth;
		this.div = new Element('div',{
			'id':'CnYuDiv',
			'styles':{
				'top':(position.top+position.height)+'px', 
				'left':(position.left)+'px',
				width: w			
			}
		}).inject(document.body);
        
	  	this.div.makeDraggable();
		
		new Element('div', {
			'id': 'listShow',
			'styles': {
				'border': '.1em solid #e0e0e0',
				'opacity': 0.9,
				'background':'white'
			}
		}).inject(this.div);
		
		new Element('div', {
			'id':'bDiv',
			'styles': {
				'border-bottom': '.1em solid #e0e0e0',
				'background': '#eeeeee',
				height:20
			}
		}).inject(this.div).adopt(
			new Element('img', {
				'src': '/images/close.png',
				'align':'right',
				'events': {
					'click': function(e){
						$('zarkDiv').setStyle('display','none');
						$(el).setStyle('background','');
					}
				}
			}),
			new Element('span', {
					'id': 'bMsg',
					'styles': {
						'cursor': 'pointer',
						'text-align': 'left',
						'font-weight': 'bold',
						'color': '#ff9900',
						'margin-left':'3px',
						'max-width':'90%'
					}
				}
			)	
		);
		$('bMsg').set('html','<A HREF=HTTP://WWW.CnYu.NET>CnYu.NET</A>');		
	}
});
*/
var DivList = new Class({
	
    initialize: function(el) {
		$(el).setStyle('background','white url(/images/inputloading.gif) no-repeat right');
		var position = $(el).getCoordinates();
		if ($('zarkDiv')) $('zarkDiv').destroy();
      	var w;
		if ($(el).getProperty('w')){
			w = $(el).getProperty('w');
		} else {
			w = 200
		}
		this.div = new Element('div', {
			'id': 'zarkDiv'
		}).setStyles({
			'top':(position.top+position.height)+'px', 
			'left':(position.left)+'px',
			width: w
		}).inject(document.body);
        
	  	this.div.makeDraggable();
		
		new Element('div', {
			'id': 'listBack',
			'styles': {
				'border': '.1em solid #e0e0e0',
				'opacity': 0.9,
				'background':'white'
			}
		}).inject(this.div);
		
		new Element('div', {
			'id':'bDiv',
			'styles': {
				'border-bottom': '.1em solid #e0e0e0',
				'background': '#eeeeee',
				height:20
			}
		}).inject(this.div).adopt(
			new Element('img', {
				'src': '/images/close.png',
				'align':'right',
				'events': {
					'click': function(e){
						$('zarkDiv').setStyle('display','none');
						$(el).setStyle('background','');
					}
				}
			}),
			new Element('span', {
					'id': 'bMsg',
					'styles': {
						'cursor': 'pointer',
						'text-align': 'left',
						'font-weight': 'bold',
						'color': '#ff9900',
						'margin-left':'3px',
						'max-width':'90%'
					}
				}
			)	
		);
		$('bMsg').set('html','<A HREF=HTTP://WWW.CnYu.NET>CnYu.NET</A>');
		
		var uri = $(el).getProperty('url');

		var params = "k="+$(el).getProperty('pa');
		var s = "&s="+$(el).getProperty('s');
		new Request({
			url:uri,
			method: 'get',
//			update: 'listBack',
			data:   params + s,
			onComplete: function(){
				$('listBack').load(uri);
				$$('#listBack ul .vlink').each(function(i){
					i.addEvent('click', function(e){
						$(el).value = this.getProperty('pa');
						$('zarkDiv').setStyle('display','none');
						$(el).setStyle('background','');
					});
				});
				
				////////////////////////////////////////////////////
				new Element('div', {
					'id': 'subMenuArea',
					'styles': {
						border: '1px solid #dddddd'
					}
				}).inject($('listBack'));
				
				$$('.cSub').each(function(i){
					i.addEvent('click', function(e){
						var pa = i.getProperty('pa');
						//2008-01-07
						var cn = i.getProperty('cn');
						var s1 = i.getProperty('s').split('$')[0].split('|');
						var s2 = i.getProperty('s').split('$')[1].split('|');
						$('bMsg').set('html',cn);
						$('bMsg').addEvent('click', function(e){
								$(el).value = bMsg.getText();
								for(j=0;j<s1.length;j++){
									$(s1[j]).value=s2[j];
								}
								$('zarkDiv').setStyle('display','none');
								$(el).setStyle('background','');
							});
						//这里可以根据拿到的数据，来发出一个Ajax请求，去查询出所有子菜单项，插入到subMenuArea中去 
						new Request({
							url:uri, 
							method: 'get',
							update: 'subMenuArea',
							data:  "k="+ pa + s,
							onComplete: function(){
								$$('#subMenuArea .cSub').each(function(i){																  
									i.addEvent('click', function(e){
										var pa = i.getProperty('pa');
										//2008-01-07
										var cn = i.getProperty('cn');
										$('bMsg').set('html','<span pa='+pa+' cn='+cn+'>'+cn+'</span>');
										$('bMsg').addEvent('click', function(e){
											$(el).value = bMsg.getText();
											if ($('TempID')){$('TempID').value= pa ;}
											$('zarkDiv').setStyle('display','none');
											$(el).setStyle('background','');
										});
									});
								});
							}
						}).send();

					});
				});
				////////////////////////////////////////////////////
			}
		}).send();
    }
});


var cSub = function (id,area){
	var uri;
	new Request({
		url:uri,
		postBody:"k="+id,update:area
	}).send();
}
window.addEvent('domready', function() {
	$$('input.oN').each(function(el){
		el.addEvent('keydown', function(event) {
			if(!(event.keyCode==46)&&!(event.keyCode==8)&&!(event.keyCode==37)&&!(event.keyCode==39)) 
			if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105))) 
			event.returnValue=false; 
			});
		});
	});
//格式化日期
Date.prototype.format = function(format)
{
    var o =
    {
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(),    //day
        "h+" : this.getHours(),   //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
        "S" : this.getMilliseconds() //millisecond
    }
    if(/(y+)/.test(format))
    format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
    if(new RegExp("("+ k +")").test(format))
    format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
}
	
	
//检查是否整形
function isInteger(str)
{  
	var regu = /^[-]{0,1}[0-9]{1,}$/;
	return regu.test(str);
}
//HTML2Text
function Html2Txt(htmlText) 
{ 
    str = htmlText.replace(/\r\n/g, " "); 
    str = str.replace(/\r/g, " ");  
    str = str.replace(/\n/g, " ");  
    str = str.replace(/\t/g, ""); 
    str = str.replace(/<BR>/gi,"\r\n"); 
    str = str.replace(/<[^>]+?>/g,""); 
    str = str.replace(/&nbsp;/g, " "); 
    str = str.replace(/&gt;/g, ">"); 
    str = str.replace(/&lt;/g, "<"); 
    str = str.replace(/&amp;/g, "&"); 
    return str; 
}
//copy from dvcomm
//Byte Counter
function len(str)
{
	var bytes = 0;
	for(i=0; i<str.length; i++)
	{
		ascii = str.charCodeAt(i);
		bytes += (ascii < 255 ? 1 : 2);
	}
	return bytes;
}


//Trim
function trim(str)
{
	return str.replace(/(^[\s　]*)|([\s　]*$)/g, '');
}
String.prototype.trim = function()
{
	return this.replace(/(^[\s　]*)|([\s　]*$)/g, '');
}


//Format
String.prototype.format = function()
{
	var s = this.replace(/\r/g, '');
	s = s.replace(/[\v\t　 ]*\n[\v\t　 ]*/g, '\n');
	s = s.replace(/(\n+)/g, '$1　　');
	s = s.replace(/[\n]{2,}/g, '\n\n');
	s = s.replace(/\n/g, '\r\n');
	s = '　　' + s;
	s = s.replace(/(　　!)/g, '');
	s = s.replace(/　　(\[uploadimage)/gi, '$1');
	return s;
}


//Filter
String.prototype.shitEncode = function()
{
	return this.replace(/(妈的|妈b|妈比|fuck|shit|我日|法轮|产党|泽东)/gi, "**");
}


//HtmlEncode
String.prototype.htmlEncode = function()
{
	var s = this.replace(/&/g, '&amp;');
	s = s.replace(/[ 　]*\r/g, '');
	s = s.replace(/  /g, '&nbsp; ');
	s = s.replace(/\t/g, '&nbsp; &nbsp; ');
	s = s.replace(/\"/, '&quot;');
	s = s.replace(/\'/, '&#39;');
	s = s.replace(/</g, '&lt;');
	s = s.replace(/>/g, '&gt;');
	s = s.replace(/\n/g, '<BR>');
	return s.shitEncode();
}


//TextEncode
String.prototype.textEncode = function()
{
	var s = this.replace(/&/g, '&amp;');
	s = s.replace(/</g, '&lt;');
	s = s.replace(/>/, '&gt;');
	return s.shitEncode();
}


//UbbCode

function vgetCookie(parameter)
{
	var reg,allCookie,allCookie2,iLen,iStart,iEnd;
	allCookie = document.cookie;
	reg = new RegExp(parameter);
	if(allCookie.search(reg) == -1){
		return "";
	}
	else{
		iLen = parameter.length;
		iStart = allCookie.search(reg) + iLen +1;
		allCookie2 = allCookie.substr(iStart);
		iEnd = iStart + allCookie2.search(/;/i);		
		if((iStart - 1) == iEnd){
			return allCookie.substr(iStart);
		}
		else{
			return allCookie.substr(iStart,iEnd - iStart);
		}
	}
}

function frameon(url, img){
	if (window == top){
		top.location.href = "index.aspx?action=frameon&url="+escape(url);
	}else{
		top.location.href = url;
	}
}

function changeframeicon(img, path){
	if (!img){return false;}
	if (window == top){
		img.src = path + 'isleft.gif';
	}else{
		img.src = path + 'noleft.gif';

	}
}

// 检查并更改图片大小 added by 小点@20070612
function imgresize(o){
	var parentNode=o.parentNode;
	if (parentNode){
		if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
		}else{
		var parentNode=o.parentNode
		if (parentNode){
			if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
			}
		}
}
function resizeimage(img)    
{
	var w=img.width,h=img.height; 
	var maxHeight=760,maxWidth=760;
	if (h>maxHeight)    
	{    
		img.height=maxHeight;    
		img.width=(maxHeight/h)*w;    
		w=img.width;   
		h=img.height;   
	}    
	if (w>maxWidth)    
	{    
		img.width=maxWidth;    
		img.height=(maxWidth/w)*h;    
	}    
}    



function addTitleHead(obj, tovalue){	//modified by caoxin03 2007 0816
	var x = eval('obj.form.' + tovalue);
	if (obj.options.selectedIndex > 0 && x.value.length < 46 && len(x.value) < 64)
	{
		x.value = obj.options[obj.options.selectedIndex].text + x.value;
		obj.options.selectedIndex = 0;
	}
}

function PostShowTime(stat){
	if(1 == stat){
		document.getElementById("uncertainstarttime").style.display = 'block';
		document.getElementById("certainstarttime").style.display = 'none';
	}else{
		document.getElementById("uncertainstarttime").style.display = 'none';
		document.getElementById("certainstarttime").style.display = 'block';
	}
}

// 展开关闭事件
function divdisplay(obj){
	if (obj){
		obj.style.display = (obj.style.display=="none") ? "block":"none";
	}
}


//获取访问者操作系统
function osinfo()
{
	$os="";
	$Agent = navigator.userAgent;
	if(getCookie($app_prefix + 'os') != 'ok')
	{
		if (($Agent.match(new RegExp('win', 'ig'))) != null)   //(eregi('win',$Agent))
		{
			$os="1";
		}
		else if (($Agent.match(new RegExp('linux', 'ig'))) != null)   //(eregi('linux',$Agent))
		{
			$os="2";
		}
		else if ((($Agent.match(new RegExp('Mac', 'ig'))) != null) && (($Agent.match(new RegExp('PC', 'ig'))) != null))   //(eregi('Mac',$Agent) && eregi('PC',$Agent))
		{
			$os="3";
		}
		else if (($Agent.match(new RegExp('FreeBSD', 'ig'))) != null)   //(eregi('FreeBSD',$Agent))
		{
			$os="4";
		}
		else if ((($Agent.match(new RegExp('sun', 'ig'))) != null) && (($Agent.match(new RegExp('os', 'ig'))) != null))   //(eregi('sun',$Agent) && eregi('os',$Agent))
		{
			$os="5";
		}
		else if (($Agent.match(new RegExp('AIX', 'ig'))) != null)   //(eregi('AIX',$Agent))
		{
			$os="6";
		}
		else if ((($Agent.match(new RegExp('ibm', 'ig'))) != null) && (($Agent.match(new RegExp('os', 'ig'))) != null))   //(eregi('ibm',$Agent) && eregi('os',$Agent))
		{
			$os="7";
		}
		else
		{
			$os="0";
		}

		return $os;
	}
}

//获取访问者浏览器
function browse_info()
{
	if(getCookie($app_prefix + 'browser') != 'ok')
	{
		var $Browsers = ['msie', 'netscape', 'konqueror', 'opera', 'lynx', 'firefox'];
		var $Agent = navigator.userAgent;
		var type;
		for (var i = 0; i < $Browsers.length; i++)
		{
			if ($Agent.toLowerCase().indexOf($Browsers[i]) != -1)
			{
				type = i + 1;
				return type.toString();
			}
		}
		return '0';
	}
}

var $app_prefix = getCookie('app_prefix');
if (!$app_prefix)
{
	app_prefix = 'dv_';
}

//var $os = osinfo();
//var $browser = browse_info();

//alert($os+ "." + $browser);  //Windows.MSIE  1.6
//document.cookie = 'os=' + escape($os) + '; browser=' + escape($browser) + ';';
//document.cookie = 'os2=' + escape($os);
//document.cookie = 'browser2=' + escape($browser);

//alert(getCookie($app_prefix + 'os')+"."+getCookie($app_prefix + 'browser'));
if(getCookie($app_prefix + 'os') == null)
{
	var $os = osinfo();
	//setCookie($app_prefix + 'os', escape($os));
	document.cookie = $app_prefix + 'os' + "=" + escape($os);
}

if(getCookie($app_prefix + 'browser') == null)
{
	var $browser = browse_info();
	//setCookie($app_prefix + 'browser', escape($browser));
	document.cookie = $app_prefix + 'browser' + "=" + escape($browser);
}

//alert(getCookie($app_prefix + 'session'));
//alert(getCookie($app_prefix + 'user'));   //null

if(getCookie($app_prefix + 'oldsession') == null && getCookie($app_prefix + 'session') != null)
{
	//setCookie($app_prefix + 'oldsession', getCookie($app_prefix + 'session'));
	document.cookie = $app_prefix + 'oldsession' + "="+ getCookie($app_prefix + 'session');
}

if(getCookie($app_prefix + 'user') == null && getCookie($app_prefix + 'olduser') == null)
{
	//setCookie($app_prefix + 'olduser', '游客');
	document.cookie = $app_prefix + 'olduser' + "=游客";
}
else if(getCookie($app_prefix + 'user') != null && getCookie($app_prefix + 'olduser') == null)
{
	//setCookie($app_prefix + 'olduser', getCookie($app_prefix + 'user'));
	document.cookie = $app_prefix + 'olduser' + "=" + escape(getCookie($app_prefix + 'user'));
}

//alert(getCookie($app_prefix + 'oldsession'));
//alert(getCookie($app_prefix + 'olduser'));
function checkNum(obj)
{
	if(obj.value.search(/\d{10}/)>=0)
	{
		alert("您输入的数字太大，输入小于9位的数字!");
	}
}
