
//改变分类数据
	function changepettypes(obj){
		if(obj.value){
			o = obj.value;
			course_pettypes = eval(o);
			common_pettypes = eval(o+"_c");
			$("petclassid").value = "简体中文/拼音";
		}
	}



	var suggests=new Array();
	Array.prototype.distinct=function(){
        var a=[],b=[];
        for(var i=0,len=a.length;i<len;i++){
       	 b[this[i]]?a.push(this[i]):b[this[i]]=1;
        }
        return a;
    }

    function searchpettype(obj){
		var suggest=getSuggestObject(obj.id);
		suggest.obj=obj;
    	if(suggest!=null){
    		suggest.displaypettype();
    	}
    }

    function forwardPage(num,nodeId){
    	var suggest=getSuggestObject(nodeId);
		$("pettype_warp").innerHTML="";
		$("pettype_warp").innerHTML=suggest.getPage(num);
	}

	function getSuggestObject(nodeId){
    	var suggest=null;
    	for(var i=0;i<suggests.length;i++){
    		if(nodeId==suggests[i].nodeId){
    			suggest=suggests[i];
    		}
    	}

    	if(suggest==null){
    		suggest=new pettype_suggest();
	    	suggests[suggests.length]=suggest;
	    	suggest.nodeId=nodeId;
    	}
    	//alert(suggest.nodeId);
    	return suggest;
    }

    function resetValue(obj) {
        if(obj.value==''){
          	obj.value='简体中文/拼音';
        }else{
        	autoFillpettype(obj);
        }
        setTimeout("hidden_suggest()",500);
	}

	function autoFillpettype(obj) {
		var pettype=autoSearch(obj.value);
        if(pettype==''){
          	obj.value='简体中文/拼音';
        }else{
        	obj.value=pettype;
        }
	}

	function autoSearch(pettype) {
		var pettypeNotes=document.getElementsByName("pettypeNote");
		var result='';
		var temp;
		for(var i=0;i<pettypeNotes.length;i++){
			temp=pettypeNotes[i].innerHTML;
			if(temp.toLowerCase().indexOf(pettype.toLowerCase())>-1){
				result=temp;
				break;
			}
		}
		return result;
	}

	window.pettype_suggest = function(){
		this.totalRows = 0; // 记录总数
		this.totalPages = 0; // 总页数
		this.pageSize = 10; // 每页显示数据条数，默认为10条记录
		this.currentPage = 1; // 当前页数
		this.hasPrevious = false; // 是否有上一页
		this.hasNext = false; // 是否有下一页
		this.startNum=0;
		this.endNum=0;
		this.nodeId='';
		this.pettypes=new Array();

		this.obj;

		this.getPage=function (num){
			this.currentPage	= num;
			this.initPage();

			var content='';
			content+='<div id="address_list"><ul class="gray">&nbsp;输入<font color=red>简体中文/拼音</font>搜索犬种</ul><ul class="top">';

			for(var i=this.startNum;i<this.endNum+1;i++){
				content+='<a style="display: block;" class="a1" href="javascript:void(null)" name="pettypeNote" onclick=setpettype("'
						+this.nodeId+'","'+this.pettypes[i-1]+'")>'+this.pettypes[i-1]+'</a>';
			}

			content+='</ul>';

			//底部

			if(this.totalPages>=2){
				content+='<ul class="bottom">';
				content+='<div style="width:160px;background:#FFF;">';
				for(var i=1;i<this.totalPages;i++){
					if(i==num){
						content+='<a class="pagenum" href="javascript:void(null)" name="pettypeNote" onmouseover=forwardPage('
							+i+',"'+this.nodeId+'") style="background:#ff9"><font color="red">'+i+'</font></a>&nbsp;';
					}else{
						content+='<a class="pagenum" href="javascript:void(null)" name="pettypeNote" onmouseover=forwardPage('
							+i+',"'+this.nodeId+'")>'+i+'</a>&nbsp;';
					}
				}
				content+='</ul></div>';
			}

			return content;
		}

		this.goPage=function (num){
			$("pettype_warp").innerHTML="";
			$("pettype_warp").innerHTML=this.getPage(num);
		}

		this.initPage=function (){
			this.totalRows = this.pettypes.length;
		    this.pageSize = this.pageSize;
		    //alert("this.totalRows="+this.totalRows+" this.totalPages="+this.totalPages+" this.pageSize="+this.pageSize);
		    this.totalPages = ((this.totalRows + this.pageSize) - 1) / this.pageSize;
			this.refresh();
		}

		this.refresh=function () {
		    if (this.totalPages <= 1) {
		        this.hasPrevious = false;
		        this.hasNext = false;
		    } else if (this.currentPage == 1) {
		        this.hasPrevious = false;
		        this.hasNext = true;
		    } else if (this.currentPage == this.totalPages) {
		        this.hasPrevious = true;
		        this.hasNext = false;
		    } else {
		        this.hasPrevious = true;
		        this.hasNext = true;
		    }
		    this.setStartNum();
		    this.setEndNum();
		}

		this.setStartNum=function (){
			if(this.totalRows>0)
			this.startNum=(this.currentPage-1)*this.pageSize+1;
		}

		this.setEndNum=function (){
			if(this.currentPage*this.pageSize>this.totalRows){
				this.endNum=this.totalRows;
			}else{
				this.endNum=this.currentPage*this.pageSize;
			}
		}

		this.displaypettype=function () {
			//alert("displaypettype");
	        if(this.obj.value=='简体中文/拼音'){
	          this.obj.value='';
	        }

			var pettype=this.obj.value;
			this.nodeId=this.obj.id;

			if(pettype==''){
				this.getCommonpettype();
			}else{
				this.searchpettypesBypettype(pettype);
			}

			this.showpettypeResponse();
		}

		this.getCommonpettype=function () {
			this.pettypes.distinct;
			this.pettypes.length=0;
			var len=common_pettypes.length;
			for(var i=0;i<len;i++){
				this.pettypes[i]=common_pettypes[i];
			}
			this.pettypes.length=len;
		}

		this.searchpettypesBypettype=function (pettype) {
			pettype=pettype.toLowerCase();
			this.pettypes.distinct;
			this.pettypes.length=0;
			var len=course_pettypes.length;
			var j=0;
			for(var i=0;i<len;i++){
			    var arr=course_pettypes[i].split('--');
	            var fltemp=arr[0].toLowerCase().indexOf(pettype);
	            var fltemp1=arr[1].toLowerCase().indexOf(pettype);
				if(fltemp>-1||fltemp1>-1||course_pettypes[i].toLowerCase()==pettype){
					this.pettypes[j]=course_pettypes[i];
					j++;
				}
			}
			this.pettypes.length=j;
		}



		this.showpettypeResponse=function (){
			//alert(this.nodeId);
			this.goPage(1);
			this.showpettype();
			//$('framemask').style.width=pettype_warp.clientWidth;
			//$('framemask').style.height=pettype_warp.clientHeight;
		}

		this.showpettype=function () {
			//alert("showpettype");
			var rd=getDim(this.obj);
			var x=rd.x;
			var y=rd.y+20;
			//alert(x+" "+y);
			//showTempSelect(event);

			$("pettype_warp").style.left=x+ 'px';
			$("pettype_warp").style.top=y+ 'px';
			//$("pettype_warp").style.display="";

			$("framemask").style.left=x+ 'px';
			$("framemask").style.top=y+ 'px';
			//$('framemask').style.visibility='visible';
			show_suggest();
		}
	}

	function setpettype (id,value) {
		if(id!=null){
			$(id).value=value;
		}else{
			$("fltDomestic04_notice_calender_m").value=value;
		}
		hidden_suggest();
	}
//*************************************************
//*******use for cal element.x and element.y*********

	function calculateOffset(obj,attr){
		var offset=0;
		while(obj){
			offset+=obj[attr];
			obj=obj.offsetParent;
		}
		return offset;
	}

	function getAbsolutePos(el) {
		var SL = 0, ST = 0;
		var is_div = /^div$/i.test(el.tagName);
		if (is_div && el.scrollLeft)
			SL = el.scrollLeft;
		if (is_div && el.scrollTop)
			ST = el.scrollTop;
		var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
		if (el.offsetParent) {
			var tmp = this.getAbsolutePos(el.offsetParent);
			r.x += tmp.x;
			r.y += tmp.y;
		}
		return r;
	};

	function addEvent(){
		//$("a").innerHTML="addEvent";
		if(!document.all) {
			window.document.addEventListener("click",this.hidden_suggest,false);
		}else{
			window.document.attachEvent("onclick",this.hidden_suggest);
		}
	}

	function removeEvent(){
		//$("a").innerHTML="removeEvent"
		if(!document.all) {
			window.document.removeEventListener("click",this.hidden_suggest,false);
		}else{
			window.document.detachEvent("onclick",this.hidden_suggest);
		}
	}

	function hidden_suggest() {
		$("pettype_warp").style.display="none";
		$('framemask').style.visibility='hidden';
	}

	function show_suggest() {
		$("pettype_warp").style.display="";
		$('framemask').style.visibility='visible';
	}

	function  getDim(htmlObj){
       var  rd  =  {x:0,y:0}
       do{
           rd.x  +=  htmlObj.offsetLeft
           rd.y  +=  htmlObj.offsetTop
           htmlObj  =  htmlObj.offsetParent
       }while(htmlObj)
       return  rd
	}

//******************************************
	function showTempSelect(event) {
 		event = event ? event : (window.event ? window.event : null);
   	 	//hao modify 1117
        var mY =(event.clientY ? event.clientY : event.pageY)+document.body.scrollTop;
        var mX=(event.clientX ? event.clientX : event.pageX)+document.body.scrollLeft;
	}