var jscript;
if(!jscript) jscript={};
jscript.img={
	write:function(img,alt,pw,ph,css,link,zoom){
		if (zoom==null) zoom=false;
		with(document){
			write("<div class='"+css+"'><table>");
			write("<tr><td>");
			if (link!=null && link!=false) write("<a href='"+link+"' target='_blank'>");
			write("<img alt='"+alt+"' ");
			if (zoom) write("onload='DrawImage(this,"+pw+","+ph+");' ");
			write("width='"+pw+"' height='"+ph+"' src='"+img+"' border='0' \/>");
			if (link!=null && link!=false) write("</a>");
			write("<\/td><\/tr><\/table><\/div>");
		}
	}
};

jscript.slide={};
jscript.slide.updown = Class.create(); //元素向下滑动展开效果
jscript.slide.updown.prototype={
	initialize: function(eid,duration,callback){
		this.element=$(eid);
		this.duration=duration?duration:1;
		this.callback=isFunction(callback)?callback:null;
		this.error=isNull(this.element)?true:false;
		this.init();
	},
	init:function(){
		if (this.error) return;
		try{
			this.beginheight="1px";
			this.endheight=e.getHeight(this.element)+"px";
			e.setStyle(this.element,"height",this.beginheight);
			e.setStyle(this.element,"visibility","visible");
		}
		catch(para){this.error=true;}
		this.run();
	},
	run:function(){
		if (this.error) return;
		active.effect.Slide(this.element, {duration: (this.duration*1000), from: this.beginheight, to: this.endheight, toggle: false, finish:this.callback});
	}
};
jscript.slide.door = Class.create(); //滑动门效果
jscript.slide.door.prototype={
	initialize:function(menuelements,content,eventopenflag,cssobject){
		this.menuelements          = {parent:"",tag:"",idreg:/(\d)/};
		this.openflag              = eventopenflag;
		this.css                   = {open:"",close:""};
		this.content               = {updateTag:"",action:""}
		this.content.updateTag     = content.updateTag;
		this.content.action	       = content.action;
		this.elements              = [];
		this.error                 = false;
		this.menuelements.parent   = menuelements.parent;
		this.menuelements.tag      = menuelements.tag;
		this.menuelements.idreg    = menuelements.idreg;
		this.css.open              = cssobject.open;
		this.css.close             = cssobject.close;
		this.openedelement         = null;
		this.init();
	},
	init:function(){
		var This=this;
		if(isNull(this.menuelements.parent)){
			this.error=true;
		}
		else{
			if(isNull(this.menuelements.tag)){
				this.elements.push(this.menuelements.parent);
			}
			else{
				$tag(this.menuelements.parent,this.menuelements.tag)._each(function(ele){This.elements.push(ele);});
			}
		}
		if(this.error){return;}
		//if(isNull(this.content.) || !isString(this.openflag)){return;}
		this.elements.each(function(door,index){if(!index){This.openedelement=door.id;}Event.observe(door,This.openflag,This.slide.bind(This));});
		This=null;
	},
	slide:function(){
		var obj=document.This();
		if(!obj.tagName || obj.tagName!=this.menuelements.tag){obj=Event.findElement(obj,this.menuelements.tag);}
		if (this.openedelement==obj.id){return;}
		this.openedelement=obj.id;
		var id=obj.id.replace(this.menuelements.idreg,"$1");
		var This=this;
		//if(id.isInt()){id=id.toInt();}else{id=0;}
		this.elements._each(function(door){if(door.id==obj.id){door.className=This.css.open;}else{door.className=This.css.close;}});
		//this.content(id);
		var This=$(this.content.updateTag);
		var myAjax=new Ajax.Request(
						 this.content.action+'?action='+id,
						 {
							method:'get',
							onComplete:showResponse
						 }
					);
		function showResponse(response){
				$(This).innerHTML=response.responseText;
		}
	}

};
jscript.slide.lable = Class.create(); //标签滑动门效果
jscript.slide.lable.prototype={
	initialize:function(options){
		this.ele                 = options.element!=null?options.element:"";
		this.tag                 = options.tag!=null?options.tag:"";
		this.reg                 = options.reg!=null?options.reg:("").reg("");
		this.str                 = options.contIDstring!=null?options.contIDstring:"";
		this.css                 = options.overcss!=null?options.overcss:"";
		this.event               = options.event!=null?options.event:"";
		this.duration            = options.duration!=null?options.duration:100;
		this.open                = options.open !=null?options.open :"";
		this.height              = options.height !=null?options.height :"";
		this.velocity            = 10;
		this.count               = 0;
		this.run                 = false;
		this.on                  = null;
		this.init();
	},
	init:function(){
		if(isNull(this.ele) || isNull(this.tag) || isNull(this.str)){return;}
		var This=this;
		$tag(this.ele,this.tag)._each(function(ele){e.atta(ele,This.event,This.onfocus.bind(This));});
		This=null;
		if(!isNull(this.open)){
			this.open=$(this.open);
			this.open.className=this.css;
			this.on=$(this.str+this.open.id.replace(this.reg,"$1"));
			e.opened(this.on);
			e.setStyle(this.on,"height","1px");
			this.move();
		}
	},
	onfocus:function(){
		var obj=document.This();
		if(isNull(obj)){return;}
		if(!obj.tagName || obj.tagName!=this.tag){obj=Event.findElement(obj,this.tag);}
		var id=obj.id;
		var idnumber=id.replace(this.reg,"$1");
		if(!isNull(this.open)){
			if(id==this.open.id){return;}
			else{
				this.open.className="";
				e.closed(this.str+this.open.id.replace(this.reg,"$1"));
			}
		}
		this.open=obj;
		obj.className=this.css;
		this.on=$(this.str+idnumber);
		e.opened(this.on);
		e.setStyle(this.on,"height","1px");
		this.move();
	},
	move:function(){
		this.count+=this.velocity;
		this.on.style.height=this.count+"px";
		if(this.count>this.height){
			this.count=0;
			this.on.style.height=this.height+"px";
			window.clearTimeout(timer);
		}
		else{
			timer=window.setTimeout(this.move.bind(this),this.duration);
		}
	}
};

//列表页分类显示开关
jscript.swapBox=function (tabs,img){
	var tab=$(tabs);
	if(isNull(tab)){return;}
	var state=tab.readAttribute("summary").toInt();
	var display = state == 1 ? "none" : "";
	var hitimg =  state == 1 ? "/Skins/blue/vlist_btn_open.gif" : "/Skins/blue/vlist_btn_close.gif";
	if($tag(tab,"ul").length<5){$(img).parentNode.style.display="none";return;}
	$tag(tab,"ul").each(function(trs,ind){if(ind > 3){trs.style.display = display;}});
	tab.setAttribute("summary",(state == 1 ? "0" : "1"));
	$(img).src=hitimg;
};
//初始化下拉列表值
jscript.setSelectValue=function(o,v){
	var obj=$(o);
	for(var i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].value==v)
		obj.options[i].selected=true;
	}
};
//列表页缩小选择范围
jscript.submitList=function (theform){
	$(theform).action="vlist.asp";
	$(theform).submit();
};

jscript.popup = Class.create(); //标签滑动门效果
jscript.popup.prototype={
	initialize:function(opt){
		this.init(opt);
	},
	remove:function(){
		if($("popWrap")!=null){
			document.body.removeChild($("popWrap"));
		}
	},
	init:function(opt){
		 this.remove();
		 var src,title
		 if(opt.act=="favorite"){
			 src="/public/pop/favorite.asp?id="+opt.objid+"&types="+opt.objtypes;
			 title="收藏信息";
		 }
		 if(opt.act=="feedback"){
			 src="/public/pop/feedback.asp";
			 title="签写留言信息";
		 }
		 var html="";
		 html+="<div class=\"popTitle\">";
		 html+="<span class=\"txt\">"+title+"</span>";
		 html+="<span class=\"ext\" id=\"ext\" title=\"关闭\"></span>";
		 html+="</div>";
		 html+="<div class=\"popInner\"><iframe width=\"100%\" height=\"100%\" src=\""+src+"\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" scrolling=\"no\" hspace=\"0\" vspace=\"0\" allowTransparency=\"true\"></iframe></div>";
		 var _pop = document.createElement("DIV");
		 _pop.className="popWrap";
		 _pop.id="popWrap";
		 //var evt=document.Event();
		 //var X=Event.pointerX(evt);
		 //var Y=Event.pointerY(evt);
		 with(_pop.style){
			position = "absolute";
			left = (document.body.offsetWidth-450)/2 + "px";
			top = "250px";
		 }
		 var _box=document.createElement("DIV");
		 	 _box.className="popBox";
			 _box.innerHTML=html;
		_pop.appendChild(_box);
		document.body.appendChild(_pop)
		Event.observe($("ext"),"click",this.remove.bindAsEventListener());
}
};
jscript.closePop=function(){
		if($("popWrap")!=null){
			document.body.removeChild($("popWrap"));
		}
};
//询价
jscript.inquiry=function(forms,id){alert("此栏目正在建设中")};
//留言
jscript.feedback=function(args){new jscript.popup({act:"feedback",objid:args.id})};
//收藏
jscript.favorite=function(args){new jscript.popup({act:"favorite",objid:args.id,objtypes:args.types})};
//IC留言
jscript.icChat=function(args){alert("此栏目正在建设中")};