//if(!Prototype.Browser['IE'])alert('请使用IE浏览本站，以免出现页面错误')
function autoimg(objid,maxsize) { 
	window.onload=function(){
	var img = document.getElementById(objid).getElementsByTagName("img"); 
	for(i=0;i<img.length;i++){
		imgzoom(img[i],maxsize)
		//alert(img[i].src)
	} 
}
} 
window.onerror=function(){return true}
function imgzoom(img,maxsize){
	var a=new Image();
	a.src=img.src
	if(a.width > maxsize * 4)
	{
		img.style.width=maxsize;
	}
	else if(a.width >= maxsize)
	{
		img.style.width=Math.round(a.width * Math.floor(4 * maxsize / a.width) / 4);
	}
	return false;
}
//查找网页内宽度太大的图片进行缩放以及PNG纠正
 function ReImgSize(objid,width){
var img=objid.document.images;
  for (i=0;i<img.length;i++)
   {
   if (document.all){
	if (img[i].width>width)
	 {
       img[i].width=width
       img[i].outerHTML='<a href="'+document.images[i].src+'" target="_blank" title="在新窗口打开图片">'+document.images[i].outerHTML+'</a>'
  	 }
   }
  else{
	if (img[i].width>width) {
	  img[i].title="在新窗口打开图片"
	  img[i].style.cursor="pointer"
	  img[i].onclick=function(e){window.open(img[i].src)}
	}
  }
  }
}
function fontresize(o,s){
document.getElementById(o).style.fontSize=s
}
function GetData(Url,ElementId,loadtxt){
	if(loadtxt==null)loadtxt='数据处理中...'
	if(document.getElementById(ElementId)){ //已存在的ID
	document.getElementById(ElementId).innerHTML=loadtxt+'<script id=\"DataLoad'+ElementId+'\" language=\"JavaScript\" defer></script>'
	}
	else {//点击方式
	if(!document.getElementById(ElementId))document.writeln("<span id=\""+ElementId+"\">"+loadtxt+"</span>");
	document.writeln("<script id=\"DataLoad"+ElementId+"\" language=\"JavaScript\" defer></script>");
	}

	requeststr=(Url.indexOf("?")!=-1)? '&':'?'
	
	try{	
		setTimeout("DataLoad"+ElementId+".src ='"+Url+requeststr+"ElementId="+ElementId+"';",0);
		} 
	
	catch(e){
		document.getElementById(ElementId).innerHTML='数据加载失败'
		return false; 
	} 
	
} 
function AjaxRequest(form,options){
	if(options==undefined)options={method:'get'}
	if(typeof(form)=='object'){
		Form.request(form,options)
	}
	else{
		new Ajax.Request(form,options);
	}

}
//选项卡类 
var TabStrip=function(index,classname1,classname2,classname3,parentelement,e){
	this.defaultindex=index;
	this.classname1=classname1;
	this.classname2=classname2;
	//选项卡对象
	this.tabstrip=(typeof classname1=='object')? classname1:Element.getElementsByClassName(parentelement,classname1);
	//选项卡对应内容对象
	this.contentelement=(typeof classname3=='object')? classname3:Element.getElementsByClassName(parentelement,classname3);	
	//默认选项卡样式
	//if(!isNaN(index))index=0
	this.tabstrip[index].className=classname2;
	//显示默认内容
	this.contentelement[index].show();
	//默认选项卡事件
	this.e=(e)?e:'mouseover';
	this.change=function(obj,index,classname){
		try{
			if(this.defaultindex!=index){
				this.tabstrip[index].className=(classname==undefined)? this.classname2:classname;
				this.tabstrip[this.defaultindex].className=(typeof this.classname1=='object')? '':this.classname1;
				this.contentelement[this.defaultindex].hide();
				this.contentelement[index].show();
			}
			
		}
		catch(e){
			//alert(e.description)
			}
		finally{this.defaultindex=index;}
	}
	this.autochange=function(obj,s,e){
		//恢复自动切换
		if(e&&!this.auto){Event.observe(parentelement,e,this.autochange.bindAsEventListener(this,s,this.e));}
		//创建自动切换
		this.auto=new PeriodicalExecuter((function(){
			this.change(this,this.defaultindex<this.tabstrip.length-1? this.defaultindex+1:0,this.classname2);
		}).bind(this),s);
		//停止切换
		Event.observe(parentelement,this.e,(function(){
			 try{
				 this.auto.stop();
				 }
				 catch(e){alert(e.description)}
			 }).bind(this));
	}

	//绑定切换选项卡事件
	for(var i=0;i<this.tabstrip.length;i++){
		Event.observe(this.tabstrip[i],this.e,this.change.bindAsEventListener(this,i,this.classname2));
	}
}



function AjaxRequest(form,options){
	if(typeof(form)=='object'){
		Form.request(form,options)
	}
	else{
		new Ajax.Request(form,options);
	}

}

function gethtml(url,objid,loading,async){
	try{
		var e=($(objid)==undefined)? false:true
		var asynchronous=(async==undefined)? true:async
		if(e)$(objid).innerHTML=(loading==undefined)? 'loading...':loading;
		var myajax = new Ajax.Request(url,{onComplete:showResponse,asynchronous:asynchronous});
	function showResponse(originalRequest){
//alert(originalRequest.responseText)
		if(e)Element.update(objid,originalRequest.responseText);
		else originalRequest.responseText.evalScripts();
	}
	}catch(e){
			//alert(e.description)
		}
}
function GetUrlParms()    
{
    var args=new Object();   
    var query=location.search.substring(1);//获取查询串   
    var pairs=query.split("&");//在逗号处断开   
    for(var   i=0;i<pairs.length;i++)   
    {   
        var pos=pairs[i].indexOf('=');//查找name=value   
            if(pos==-1)   continue;//如果没有找到就跳过   
            var argname=pairs[i].substring(0,pos);//提取name   
            var value=pairs[i].substring(pos+1);//提取value   
            args[argname]=unescape(value);//存为属性   
    }
    return args;
}
function submitcomment(){
	var username=$F('commentusername');
	var content=$F('commentcontent');
	var channelid=$F('channelid');
	var ownerid=$F('ownerid');
	var formcontent={
		username:username,
		content:content,
		channelid:channelid,
		ownerid:ownerid
		
	}
	Form.disable(document.commentform);
	var myajax = new Ajax.Request( 
		'/comment.asp?action=save', 
		{ 
		method: 'post', 
		parameters: formcontent, 
		onComplete: showResponse 
		} );
	function showResponse(originalRequest){
	try{
		var XmlDoc=originalRequest.responseXML
		//alert(originalRequest.responseText)
		var root=XmlDoc.getElementsByTagName('main')[0];
		if(root.getAttributeNode('status').value.toLowerCase()=='false')Form.enable(document.commentform)
		alert(root.firstChild.text);	
		originalRequest.responseText.evalScripts();
			
	}
	catch(e){
		alert(e.descripiton)
		}
    	}
	
}

function submitform(form,action,para){
	//Element.show('loader')
	var formcontent=(para==undefined)? (Form.serialize(form)):($H(para).toQueryString())
	Form.disable(form);
	var myajax = new Ajax.Request( 
		action, 
		{ 
		method: 'post', 
		postBody: formcontent, 
		onComplete: showResponse 
		} );
	function showResponse(originalRequest){
	try{
		var XmlDoc=originalRequest.responseXML
		//salert(originalRequest.responseText)
		var root=XmlDoc.getElementsByTagName('main')[0]
		if(root.getAttributeNode('status').value.toLowerCase()=='false')Form.enable(form);
		if(root.firstChild.text!='')alert(root.firstChild.text);	
		originalRequest.responseText.evalScripts();
			
	}
	catch(e){
		alert(originalRequest.responseText);
		}
	finally{//Element.hide('loader')
		}
    }
	
}


// 修复 IE 下 PNG 图片不能透明显示的问题
function fixPNG(myImage)
{
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);

	if ((version >= 5.5) && (version < 7) && (document.body.filters))
	{
		var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
		var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
		var imgTitle = (myImage.title) ? "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' ";
		var imgStyle = "display:inline-block;" + myImage.style.cssText;
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + myImage.width
			+ "px; height:" + myImage.height
			+ "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
		myImage.outerHTML = strNewHTML;
	}
}

//根据URL判断搜索选项卡

function searchtab(){
	var channeldir=location.pathname;
	switch (channeldir.substr(1,channeldir.indexOf('/',1)-1).toLowerCase()){
	case 'news':
		return 0;
	case 'knowledge':
		return 1;
	case 'tea':
		return 2;
	case 'author':
		return 3;
	case 'product':
		return 4;
	case 'shop':
		return 4;
	default:
		return 4;
	}
}
function searchtab2(channel){
	switch (channel){
	case 'news':
		return 0;
	case 'knowledge':
		return 1;
	case 'tea':
		return 2;
	case 'author':
		return 3;
	case 'product':
		return 4;
	case 'shop':
		return 4;
	default:
		return 4;
	}
}
//图片预览
var Preview=function(container,img,url){
	this.PreviewImg=$(img);
	this.PreviewUrl=$(url);
	this.Container=$(container);
	Event.observe(this.Container,'mouseout',(function(){Element.hide(this.Container)}).bind(this));
	this.showPreview=function(e){
		var element=Event.element(e);
		var c=Position.realOffset(element);
		c['width']+=Element.getWidth(event.srcElement)/2;
		this.PreviewImg.src=event.srcElement.large-src;
		this.Container.style.top=Element.getHeight(element);
		Element.show(this.Container);
	}
	
}


//弹窗
var OpenWin=function(option){
	this.html='';
	this.options=new Array();
	$H(option).each((function(pair,i) { this.options[i]=pair.key +'='+ pair.value }).bind(this));
	this.o = function(url,name){
		var win=window.open("","",this.options.join(','));
		if(this.html!='')win.document.write(this.html);
	}
}

var OverLay=function(){
	//创建遮罩
	this.zindex=9999;
	//创建层
	this.objOverlay = document.createElement("div");
	this.objOverlay.setAttribute('id','overlay');
	Element.setStyle(this.objOverlay,{display:'none',top:'0px',filter:'alpha(opacity=50)',position:'absolute',width:'100%'})
	this.objOverlay.style.backgroundColor='#EEEEEE';
	document.getElementsByTagName("body").item(0).appendChild(this.objOverlay);
	this.bodyobj=document.documentElement ? document.documentElement : document.body ; 	
	this.handler=function(){this._position();}.bind(this);
	this._position=function(){
		Position.prepare();
		Element.setStyle(this.objOverlay,{left:Position.deltaX})
		
	}
	
	this.show=function(dispobj){
		if(dispobj){$(dispobj).style.zIndex=this.zindex;$(dispobj).show()}
		Element.setStyle(this.objOverlay,{display:'',height:this.bodyobj.clientHeight>this.bodyobj.scrollHeight?this.bodyobj.clientHeight:this.bodyobj.scrollHeight})
		this._position();
		//this.objOverlay.show();
		this.zindex++;
		Event.observe(window,'resize',this.handler);
		Event.observe(window,'scroll',this.handler);
		this.SelectBoxes('hidden')
	}
	
	this.hide=function(){
		this.SelectBoxes('visible')
		this.objOverlay.hide();
		Event.stopObserving(window,'resize',this.handler);
		Event.stopObserving(window,'scroll',this.handler);
		
	}
	this.SelectBoxes=function(s){
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = s;
		}
	}
	
}

//层固定类
var PopUp=function(fix){	
	this.offset=true;
	this.offsetWidth=0;
	this.offsetHeight=0;
	this.offsetTop=null;
	this.zindex=999999;
	this.handler=function(){this._position()}.bind(this);
	this.start=function(obj,p){
		this.popupbox=$(obj);
		this.popupbox.show();
		this.position=p;
		this._position(true);
		this.popupbox.style.zIndex=this.zindex;
		//if(this.popupbox.style.top+this.offsetHeight<Position.deltaY){
			//this.popupbox.style.top=Position.deltaY;
		//}
		this.zindex++;
		if(fix){
			Event.observe(window,'scroll',this.handler);
			Event.observe(window,'resize',this.handler);
		}
	}
	this._setpositon=function(x,y){
		if(x)this.popupbox.style.left=x;	
		this.popupbox.style.top=y;
	}
	this._position=function(inti){
		var x,y;
		this.pageWidth=window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;   //浏览器宽
		
		this.pageHeight=window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;  //浏览器高
		
		Position.prepare();
		this.boxwidth=Element.getWidth(this.popupbox);
		this.boxheight=Element.getHeight(this.popupbox);
		switch (this.position){
			case 0:  //左下角
				x=Position.deltaX+((this.offset||inti)? this.offsetWidth:0);
				y=this.pageHeight-this.boxheight+Position.deltaY+((this.offset||inti)? this.offsetHeight:0);
				this._setpositon(x,y);
				break;
			case 1: //屏幕中间
				x=(this.pageWidth-this.boxwidth)/2+Position.deltaX+((this.offset||inti)? this.offsetWidth:0);
				if(this.offsetTop==null){
					y=(this.pageHeight-this.boxheight)/2+Position.deltaY+((this.offset||inti)? this.offsetHeight:0);
				}
				else{
					//y=this.offsetTop;
					y=this.offsetTop+Position.deltaY+((this.offset||inti)? this.offsetHeight:0);
					}
				this._setpositon(x,y);
				break;
			default:  //默认右下角
				x=this.pageWidth-this.boxwidth+Position.deltaX+((this.offset||inti)? this.offsetWidth:0);
				y=this.pageHeight-this.boxheight+Position.deltaY+((this.offset||inti)? this.offsetHeight:0);

				this._setpositon(x,y);
		}
	}
	this.stop=function(obj){
		Element.hide((obj==undefined)? this.popupbox:obj);
		if(fix){
			Event.stopObserving(window,'resize',this.handler);
			Event.stopObserving(window,'scroll',this.handler);
			}

	}
	this.close=function(obj){
		Element.remove((obj==undefined)? this.popupbox:obj);
	}
}
var cart=function(cartid){
	this.cartid=cartid;
	this.addtocart=function(id,productid,productname,price){
		this.loadtext();
		var p={id:id,productid:productid,productname:productname,price:price}
		var para=$H(p).toQueryString();
		this.request('?action=addtoorder&'+para);
	}
	this.loadtext=function(){
		$(this.cartid).innerHTML='加载购物车...<a href="javascript:cart.toggle()">[关闭]</a>';
		}
	this.loadtext();
	this.show=function(){
		fixpop.start(cartid,1)
		AjaxRequest('default.asp?action=showorder',{onComplete:function(ajax){
			$(this.cartid).innerHTML=ajax.responseText;
		}.bind(this)});
		overlay.show(cartid);
	}
	this.delproduct=function(id){
		this.request('default.asp?action=delorderproduct&id='+id);
	}
	this.clear=function(){
		this.request('default.asp?action=clearorder');
	}
	this.payorder=function(){
		location.href='default.asp?action=order'
	}
	this.modify=function(id,no){
		this.request('default.asp?action=modifyorder&id='+id+'&no='+no)
	}
	this.request=function(url){
		AjaxRequest(url,{onComplete:function(ajax){
			this.show();ajax.responseText.evalScripts();
		}.bind(this)});
	}
	this.toggle=function(){
		Element.toggle(cartid);
		overlay.hide();
		this.loadtext();
	}
}

function pricearea(price){
price=Math.abs(price);
if(price<=1000&&price!=0){
return '<a style="color:green;text-decoration: underline" target="_blank" href="/search.asp?channelid=7&searchType=3&kw=0">(1000元以内)</a>';
}
else if(price>1000&&price<=2000){
return '<a style="color:green;text-decoration: underline" target="_blank" href="/search.asp?channelid=7&searchType=3&kw=1">(1000-2000元)</a>';
}
else if(price>2000){
return '<a style="color:green;text-decoration: underline" target="_blank" href="/search.asp?channelid=7&searchType=3&kw=2">(大于2000元)</a>';
}
else{return ''}
}

jQuery.fn.extend({   
    showsimg: function(options) {
    	this.options=jQuery.extend({exp:'.simgdiv'},options);
		var self=this
	
	//绑定事件
		jQuery(this).mouseover(function(){
			var offset=jQuery(this).parent().offset()
			jQuery(self.options.exp,jQuery(this).parent()).css({position:'absolute',top:offset.top-84,left:offset.left+30}).show('fast');
		}).mouseout(function(){
			jQuery(self.options.exp,jQuery(this).parent()).hide('fast');
			})
	},simpletab:function(options){
		var self=this;
		this.loading=false;
    	this.options=jQuery.extend({area:null,event:'click',content:null,sel:0,classes:{sel:'NewPTabMenuIn',unsel:'NewPTabMenuA'}},options);
		
		this.handler=function(){
			
			if(this.href){
				self.loading=true
				jQuery.getJSON(this.href,self.callback.call(self))
			}
			//alert(self);	
			var index=jQuery(self).index(this);
			if(self.curindex!=index){
				//隐藏上一个选择
				if(self.curindex>=0){
					jQuery(self[self.curindex],self.options.area).attr('class',self.options.classes.unsel)
					jQuery(self.options.content,self.options.area).eq(self.curindex).hide();
				}
			//显示当前选择
			jQuery(self.options.content,self.options.area).eq(index).show();
			jQuery(self[index]).attr('class',self.options.classes.sel)
			self.curindex=index;
			}
		}
		jQuery(this).bind(self.options.event,this.handler)
		if(!isNaN(self.options.sel)){
			//alert(jQuery(this[self.options.sel]));
			jQuery(this[self.options.sel]).trigger(self.options.event);
		}
		return this;
	} 		
	
})
	
//daniu added at 20091223
function ajax_topwrite(){
	jQuery.post('/ajax/ajax_write.php?rand='+new Date().getTime(), {
		name:'快速留言',
		tel:jQuery('#toptel').val(),
		calltime:'未知',
		email:'',
		content:jQuery('#topcontent').val(),
		url:location.href,
		pid:0,
		pname:''
	}, function(data,textStatus) {
		alert(data);
		if(textStatus =='success'){
			if(jQuery('#toptel').val()!='' && jQuery('#topcontent').val()!=''){
				jQuery('#topcontent').val('');
				jQuery('#toptel').val('');
			}
		}
	})
}
function input_hover(obj,color){
	try{
	obj.style.borderColor = color;	
	}catch(e){
		alert(e.getMessage());	
	}
}

function correctPNG()
{
   for(var i=0; i<document.images.length; i++)
   {
   var img = document.images[i]
   var imgName = img.src.toUpperCase()
   if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
   {
   var imgID = (img.id) ? "id='" + img.id + "' " : ""
   var imgClass = (img.className) ? "class='" + img.className + "' " : ""
   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
   var imgStyle = "display:inline-block;" + img.style.cssText
   if (img.align == "left") imgStyle = "float:left;" + imgStyle
   if (img.align == "right") imgStyle = "float:right;" + imgStyle
   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle 
   var strNewHTML = "<span " + imgID + imgClass + imgTitle
   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
   + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
   img.outerHTML = strNewHTML
   i = i-1
   };
   };
};

if(navigator.userAgent.indexOf("MSIE")>-1)
{
window.attachEvent("onload", correctPNG);
};
