/**
** powered by singo <alerpache@hotmail.com>
** CopyRight 2009 @ goodjd.com
** top.js add by singo.alerpache 
**/
String.prototype.trim = function(){
	return this.replace(/^[\s]+|[\s]+$/g,'');
}

var Class = {
	create : function(){
		return function(){
			return this.initialize.apply(this,arguments);
		}
	}
}

var Extend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
}

var Bind = function(object, fun) {
	return function() {
		return fun.apply(object, arguments);
	}
}

Function.bind = function(obj,func){
	return function(){
		func.apply(obj,func);
	}
}

var Each = function(list, fun){
	for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};

function BindEvent(idstr,evt,func){
	var args = [];
	var obj = document.getElementById(idstr);
	obj = obj||window;
	for(i=3;i<arguments.length;i++){
		args.push(arguments[i]);
	}
	if(obj.attachEvent){
		obj.attachEvent('on'+evt,function(){return func.apply(obj,args);});
	}
	else{
		obj.addEventListener(evt,function(){return func.apply(obj,args);},false);
	}
}

// calss基础类：
var Class = {
	create : function(){
		return function(){
			return this.initialize.apply(this,arguments);
		}
	}
}

//事件绑定：
function addEventHandler(oTarget, sEventType, fnHandler) {
	if (oTarget.addEventListener) {
		oTarget.addEventListener(sEventType, fnHandler, false);
	} else if (oTarget.attachEvent) {
		oTarget.attachEvent("on" + sEventType, fnHandler);
	} else {
		oTarget["on" + sEventType] = fnHandler;
	}
};

//事件删除：
function removeEventHandler(oTarget, sEventType, fnHandler) {
    if (oTarget.removeEventListener) {
        oTarget.removeEventListener(sEventType, fnHandler, false);
    } else if (oTarget.detachEvent) {
        oTarget.detachEvent("on" + sEventType, fnHandler);
    } else { 
        oTarget["on" + sEventType] = null;
    }
};

// 判断是否是IE：
var isIE = (document.all) ? true : false;

function InitAjax(){
	try{
		return new XMLHttpRequest();    
	}catch(e){
		return new ActiveXObject('Microsoft.XMLHTTP');    
	}
}

function getinfo(id,url)
{
　
　var show = document.getElementById(id); 
　var ajax = InitAjax();

　ajax.open("GET", url, true); 

　ajax.onreadystatechange = function() { 
　
　　if (ajax.readyState == 4 && ajax.status == 200) { 
　　　show.innerHTML = ajax.responseText; 
　　}
　}
　　ajax.send(null); 
}

function getJsInfo(id,url)
{
　
　var show = document.getElementById(id); 
　var ajax = InitAjax();

　ajax.open("GET", url, true); 

　ajax.onreadystatechange = function() { 
　
　　if (ajax.readyState == 4 && ajax.status == 200) { 
	  var str = ajax.responseText;
	  set_innerHTML(id, str);
　　} 
　}
　　ajax.send(null); 
}

function getNewBrand(obj,targetId){
	var objSelect = document.getElementById(targetId);
	objSelect.length=0;
	for (i=0; i<g_Cate[obj.value].length; i++){
		objSelect.options[i] = new Option(g_Brand[g_Cate[obj.value][i]],g_Cate[obj.value][i])
	}
	if(typeof(loadSelect)=='function'){
		loadSelect(document.from2.brand)
	}
	else{
		//alert('内容加载中，请稍等……');
		return true;
	}
}

//取得控件位置
function Offset(e){
        var t = e.offsetTop;
        var l = e.offsetLeft;
        var w = e.offsetWidth;
        var h = e.offsetHeight-2;
        while(e=e.offsetParent){
            t+=e.offsetTop;
            l+=e.offsetLeft;
        }
    return { top : t,left : l,width : w,height : h }
}

///////////////////////////////////////////////////////////////////////////////////////
//下拉选择菜单
	var Accompany = new Array();
	var g_Category = new Array();
	Accompany[0] = 0;
	Accompany[1] = 100;
	Accompany[2] = 101;
	Accompany[3] = 102;
	Accompany[4] = 103;
	Accompany[5] = 104;
	Accompany[6] = 105;
	Accompany[7] = 106;
	Accompany[8] = 107;
	Accompany[9] = 108;
	Accompany[10] = 109;
	Accompany[11] = 110;
	g_Category[0] = '全部分类';
	g_Category[100] = '电视机';
	g_Category[101] = '空调';
	g_Category[102] = '冰箱';
	g_Category[103] = '洗衣机';
	g_Category[104] = '手机';
	g_Category[105] = '数码家电';
	g_Category[106] = '电脑及外设';
	g_Category[107] = '影音家电';
	g_Category[108] = '生活小家电';
	g_Category[109] = '厨卫家电';
	g_Category[110] = '新奇家电';
    var childCreate=false;
    var categoryCreate = false;

function showBrandSelect(obj, _form){
	  if(!_form)
	  {
		  _form = 'SearchHeadForm';
	  }
    var offset=Offset(obj);
     var cidValue = document.getElementById('cid').value;
     
     if(document.getElementById("selectchild")){
     	var tempdiv =  document.getElementById("selectchild");
     	tempdiv.parentNode.removeChild(tempdiv);
     	return false;
     }
        var cDiv = document.createElement("div");
        cDiv.id="selectchild";
        cDiv.style.position = "absolute";
        cDiv.style.width=offset.width * 5 + 2 + "px";
        t = g_Cate[cidValue].length;
        var tmpH = Math.ceil( t / 5);
        cDiv.style.height=tmpH *18 + "px";
        cDiv.style.top=(offset.top+offset.height+2) + "px";
        cDiv.style.left=offset.left + "px";
        cDiv.style.borderWidth = 1 + "px";
    	cDiv.style.borderColor = "#ff9933";
        cDiv.style.background="#ffffff";
        cDiv.style.overflow = "hidden";
        var uUl = document.createElement("ul");
        uUl.id="uUlchild";
        uUl.style.listStyle="none";
        uUl.style.margin="0";
        uUl.style.padding="0";
        uUl.style.fontSize="12px";
        cDiv.appendChild(uUl);
        document.body.appendChild(cDiv);
        childCreate=true;
        for (var i=0;i<t;i++){        
            var lLi=document.createElement("li");
            lLi.id=g_Cate[cidValue][i];
            lLi.style.textIndent="4px";
            lLi.style.height="18px";
            lLi.style.width = offset.width-1 + "px" ;
            lLi.style.lineHeight="16px";
            lLi.style.styleFloat = "left";
            lLi.style.cssFloat = "left";
            lLi.style.color = "#666666";
            lLi.innerHTML= g_Brand[g_Cate[cidValue][i]];
            uUl.appendChild(lLi);
    }
    var liObj=document.getElementById("uUlchild").getElementsByTagName("li");
    for (var j=0;j<liObj.length;j++){
        liObj[j].onmouseover=function(){
            this.style.background="#f2f2f2";
            this.style.color="black";
			this.style.cursor = "pointer";
        }
        liObj[j].onmouseout=function(){
            this.style.background="#ffffff";
            this.style.color="#666666";
        }
        liObj[j].onclick=function(){
            //document.getElementById("selectchild").style.display="none";
			//document.form2.brand.value = this.id;
			var vfrm = document.getElementById(_form);
			vfrm.brand.value = this.id;
			obj.value = this.innerHTML;
			cDiv.parentNode.removeChild(cDiv);
            childCreate=false;
        }
    }
//    } // end else*/
}

function setSelect(frm){
	var frm = document.getElementById(frm);
	frm.brand.value = "0";
	frm.buttonSelect.value ="选择品牌";
	childCreate = false;
	if(document.getElementById("selectchild")){
     	var tempdiv =  document.getElementById("selectchild");
     	tempdiv.parentNode.removeChild(tempdiv);
     	return 0;
     }
	 return 0;
}

function showCateSelect(obj, _form){
	if(!_form)
	{
	   _form = 'SearchHeadForm';
	}
	var offset=Offset(obj);
	if(document.getElementById("selectCateChild")){
    	var tempdiv =  document.getElementById("selectCateChild");
    	tempdiv.parentNode.removeChild(tempdiv);
    	return 0;
	}
	
	var CateDiv = document.createElement("div");
    CateDiv.id="selectCateChild";
    CateDiv.style.position = "absolute";
    CateDiv.style.width=offset.width * 2 + 2 + "px";
    t = Accompany.length;
    var tmpH = Math.ceil( t / 2);
    CateDiv.style.height=tmpH *18 + "px";
    CateDiv.style.top=(offset.top+offset.height+2) + "px";
    CateDiv.style.left=offset.left + "px";
    CateDiv.style.borderWidth = 1 + "px";
    CateDiv.style.borderColor = "#ff9933";
    CateDiv.style.background="#ffffff";
    CateDiv.style.overflow = "hidden";
    
    var uUl = document.createElement("ul");
    uUl.id="cUlchild";
    uUl.style.listStyle="none";
    uUl.style.margin="0";
    uUl.style.padding="0";
//    uUl.style.borderWidth = 2 + "px";
//    uUl.style.borderColor = "#ff9933";
    uUl.style.fontSize="12px";
    CateDiv.appendChild(uUl);
    
    document.body.appendChild(CateDiv);
    categoryCreate = true;
    
    ///加入选择列表：
     for (var i=0;i<t;i++){        
            var lLi=document.createElement("li");
            lLi.id=Accompany[i];
            lLi.style.textIndent="4px";
            lLi.style.height="18px";
            lLi.style.width = offset.width-1 + "px" ;
            lLi.style.lineHeight="16px";
            lLi.style.styleFloat = "left";
            lLi.style.cssFloat = "left";
            lLi.style.color = "#666666";
            lLi.innerHTML= g_Category[Accompany[i]];
            uUl.appendChild(lLi);
    }
    var liObj=uUl.getElementsByTagName("li");
    for (var j=0;j<liObj.length;j++){
        liObj[j].onmouseover=function(){
            this.style.background="#f2f2f2";
            this.style.color="black";
			this.style.cursor = "pointer";
        }
        liObj[j].onmouseout=function(){
            this.style.background="#ffffff";
            this.style.color="#666666";
        }
        liObj[j].onclick=function(){
        	var tmpdiv = document.getElementById("selectCateChild");
			var vfrm = document.getElementById(_form);
			vfrm.cid.value = this.id;
			obj.value = this.innerHTML;
			tmpdiv.parentNode.removeChild(tmpdiv);
            categoryCreate=false;
            setSelect(_form);
        }
    }
}
function ClearSelect(e){
	//var eventSource = window.event.srcElement;
	e = e || window.event;   
      var srcElement = e.srcElement || e.target; 
	if(childCreate && srcElement.name != 'buttonSelect'){
		if(document.getElementById('selectchild')){
			var showDiv = document.getElementById('selectchild');
			showDiv.parentNode.removeChild(showDiv);
			childCreate = false;
		}
	}
	if(categoryCreate && srcElement.name != 'buttonCategory'){
		if(document.getElementById('selectCateChild')){
			var tdiv = document.getElementById('selectCateChild');
			tdiv.parentNode.removeChild(tdiv);
			categoryCreate = false;
		}
	}
	return;
} // end function ClearSelect


if(document.attachEvent){
	document.attachEvent('onclick',ClearSelect);
}
else{
	document.addEventListener('click',ClearSelect,false);
}
/////菜单选择事件结束

////ajax 自动完成类开始：
var AutoComplete = Class.create();
AutoComplete.prototype = {
	initialize : function(argid,geturlfunc){
		this.inputid = document.getElementById(argid);
		this.inputid.setAttribute('autocomplete','off');
		this.getURL = geturlfunc;
		this.contenter = 'autocomplete_'+argid;
		this.cachevalue = '';
		var _this = this;
		this.inputid.onchange = this.inputid.onkeyup = function(){
			setTimeout(function(){_this.list()},50);
		}
	},
	xmlhttp : null, // xmlhttp request 对象
	ajax : function(){ // 创建ajax xmlhttp 对象函数
		try{
			return new XMLHttpRequest();    
		}catch(e){
			return new ActiveXObject('Microsoft.XMLHTTP');    
		}
	},
	list : function(){ //ajax 对象请求操作,查找
		var str = this.inputid.value.trim();
		if(!str.length){
			this.remove(this.contenter);
			return;
		}
		if(this.cachevalue == str){
			return;
		}
		if(this.xmlhttp){
			this.xmlhttp.abort();
			this.remove(this.contenter);
		}
		this.cachevalue = str;
		
		var url = this.getURL() + encodeURIComponent(str);
		var xmlhttp = this.xmlhttp = this.ajax();
		xmlhttp.open('GET',url,true);
		var __this = this;
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
				if(!xmlhttp.responseText.trim().length || xmlhttp.responseText.indexOf('ul')==-1){
					return ;
				}
				__this.show(xmlhttp.responseText);
			}
		},
		xmlhttp.send(null);
	},
	show : function(v){ //显示div,
		this.remove(this.contenter);
		var dv = document.createElement('div');
		dv.id = this.contenter;
		dv.name = 'autocomplete';
		dv.style.position = "absolute";
		//dv.style.backgroundColor = '#ffffff';
		var pos = this.p(this.inputid);
		dv.style.top = pos.top + pos.height + 2 + "px";
		//dv.style.border = '2px solid #f96700';
		dv.style.left = pos.left + "px";
		dv.style.overFlow = 'hidden';
		dv.style.width = pos.width + 'px';
		dv.style.borderWidth = '1px';
		dv.style.zIndex = 9999;
		
		dv.innerHTML = v;
		document.body.appendChild(dv);
		
		var uUL_array = dv.getElementsByTagName('ul');
		uUL = uUL_array[0];
		uUL.style.listStyleType = 'none';
		uUL.style.backgroundColor = '#ffffff';
		uUL.style.marginLeft = '2px';   //IE 下
		uUL.style.paddingLeft = '2px'; //firefox 下
		uUL.style.marginTop = '2px';	// FireFox 下
		uUL.style.borderWidth = '1px';
		uUL.style.borderColor = '#999999';
		uUL.style.fontSize = '12px';
		uUL.style.lineHeight = '20px';
		
		var LI = uUL.getElementsByTagName('li');
		if(!LI.length) return;
		for(var i=0;i<LI.length;i++){
			LI[i].onmouseover = function(){
				this.style.backgroundColor = '#b4d5ef';
			}
			LI[i].onmouseout = function(){
				this.style.backgroundColor = '#ffffff';
			}
		}
		if(document.attachEvent){ //绑定 onkeyup事件，使列表支持键盘
			document.attachEvent('onkeyup',this.onselect(LI));
		}
		else{
			document.addEventListener('keyup',this.onselect(LI),false);
		}
	},
	p : function(o){ //取得控件位置：
        var t = o.offsetTop;
        var l = o.offsetLeft;
        var w = o.offsetWidth;
        var h = o.offsetHeight-2;
        while(o=o.offsetParent){
            t+=o.offsetTop;
            l+=o.offsetLeft;
        }
		return { top:t, left:l, width:w, height:h }
	},
	remove:function(id){ //删除层
		if(document.getElementById(id)){
			var tmpid = document.getElementById(id);
			tmpid.parentNode.removeChild(tmpid);
		}
	},
	onselect : function(liary){ //键盘移动
		return function(e){
			var e = e||event;
			var ckey = e.charCode||e.keyCode||e.which;
			//var li = document.getElementById(divContenter).getElementsByTagName('li');
			var li = liary;
			if(!li.length) return;
			var t = 0;
			len = li.length;
			if(ckey==40){
				for(i=0;i<len;i++){
					var vcolor = li[i].style.backgroundColor;
					if(vcolor.indexOf('rgb')!=-1){
						var cary = vcolor.match(/(\d+)/g);
						var R = parseInt(cary[0],10).toString(16);
						var G = parseInt(cary[1],10).toString(16);
						var B = parseInt(cary[2],10).toString(16);
						var tColor = R+G+B;
						vcolor = '#' + tColor.toLowerCase();
					}
					if(vcolor == '#b4c5ef'){
						t = i;
						t++;
						li[i].style.backgroundColor = '#ffffff';
						break;
					}
				}
		
				if(t==len){
					t = 0;
				}
				li[t].style.backgroundColor = '#b4c5ef';
			} // end if ckey==40
			if(ckey==38){
				for(i=0;i<len;i++){
					var vcolor = li[i].style.backgroundColor;
					if(vcolor.indexOf('rgb')!=-1){
						var cary = vcolor.match(/(\d+)/g);
						var R = parseInt(cary[0],10).toString(16);
						var G = parseInt(cary[1],10).toString(16);
						var B = parseInt(cary[2],10).toString(16);
						var tColor = R+G+B;
						vcolor = '#' + tColor.toLowerCase();
					}
					if(vcolor == '#b4c5ef'){
						t = i;
						t--;
						li[i].style.backgroundColor = '#ffffff';
					}
				} // end for
				if(t < 0){
					t = len-1;
				}
				li[t].style.backgroundColor = '#b4c5ef';
			}
			if(ckey==13){
				for(i=0;i<len;i++){
					var vcolor = li[i].style.backgroundColor;
					if(vcolor.indexOf('rgb')!=-1){
						var cary = vcolor.match(/(\d+)/g);
						var R = parseInt(cary[0],10).toString(16);
						var G = parseInt(cary[1],10).toString(16);
						var B = parseInt(cary[2],10).toString(16);
						var tColor = R+G+B;
						vcolor = '#' + tColor.toLowerCase();
					}
					if(vcolor == '#b4c5ef'){
						li[i].getElementsByTagName('a')[0].click();
					} // end if color
				} // end for
			}	// end if ckey==13
		}// end return function(e)
	} // end function onselect
};
/////////////////////////ajax 自动完成类结束////////////////////
//幻灯片图片类：
var RevealTrans = Class.create();
RevealTrans.prototype = {
  initialize: function(container, options) {
	this._img = document.createElement("img");
	this._a = document.createElement("a");
	
	this._timer = null;//计时器
	this.Index = 0;//显示索引
	this._onIndex = -1;//当前索引
	
	this.SetOptions(options);
	
	this.Auto = !!this.options.Auto;
	this.Pause = Math.abs(this.options.Pause);
	this.Duration = Math.abs(this.options.Duration);
	this.Transition = parseInt(this.options.Transition);
	this.List = this.options.List;
	this.onShow = this.options.onShow;
	//初始化显示区域
	//this._img.src = "javascript:void(0);";//第一次变换时不显示红x图
	this._img.src = '';
	this._img.style.width = '568px';
	this._img.style.height = '190px'; 
	this._img.style.border = 0;
	this._img.onmouseover = Bind(this, this.Stop);
	this._img.onmouseout = Bind(this, this.Start);
	isIE && (this._img.style.filter = "revealTrans()");
	
	this._a.target = "_blank";
	
	//$(container).appendChild(this._a).appendChild(this._img);
	document.getElementById(container).appendChild(this._a).appendChild(this._img);
  },
  //设置默认属性
  SetOptions: function(options) {
	this.options = {//默认值
		Auto:		true,//是否自动切换
		Pause:		2000,//停顿时间(微妙)
		Duration:	1,//变换持续时间(秒)
		Transition:	23,//变换效果(23为随机)
		List:		[],//数据集合,如果这里不设置可以用Add方法添加
		onShow:		function(){}//变换时执行
	};
	Extend(this.options, options || {});
  },
  Start: function() {
	clearTimeout(this._timer);
	//如果没有数据就返回
	if(!this.List.length) return;
	//修正Index
	if(this.Index < 0 || this.Index >= this.List.length){ this.Index = 0; }
	//如果当前索引不是显示索引就设置显示
	if(this._onIndex != this.Index){ this._onIndex = this.Index; this.Show(this.List[this.Index]); }
	//如果要自动切换
	if(this.Auto){
		this._timer = setTimeout(Bind(this, function(){ this.Index++; this.Start(); }), this.Duration * 1000 + this.Pause);
	}
  },
  //显示
  Show: function(list) {
	if(isIE){
		//设置变换参数
		with(this._img.filters.revealTrans){
			Transition = this.Transition; Duration = this.Duration; apply(); play();
		}
	}
	//设置图片属性
	this._img.src = list.img; this._img.alt = list.text;
	//设置链接
	!!list["url"] ? (this._a.href = list["url"]) : this._a.removeAttribute("href");
	//附加函数
	this.onShow();
  },
  //添加变换对象
  Add: function(sIimg, sText, sUrl) {
	this.List.push({ img: sIimg, text: sText, url: sUrl });
  },
  //停止
  Stop: function() {
	clearTimeout(this._timer);
  }
};
//过滤内容
var FILTR_STRING = '腾讯,兑奖,领奖,客服电话,六合彩,腾讯官方客服,法轮功,官方电话,活动热线,视频,聊天,裸聊,qq,QQ,qq客服,迷药,麻醉药,李洪志,一夜情,法轮功,台独,客服总机,中奖,qq游戏,联众,联众游戏,经理电话,客服热线,QQ炫舞,9888,188132,浩方,有奖,传奇,非常6+1,博客公司,人工服务,奔驰,宝马,破解,轮盘,王辉,吉祥宝贝,百家乐,单挑王,老虎机,彩金狮王,五星宏辉,老虎機,定位器,温家宝,胡锦涛,朱镕基,MBA,GET,考试,执业医师,助考设备,共产党,四级,六级,经济师,会计师,建造师,四六级,加盟,连锁,营销,气枪,枪支,工字气枪,疗程,治疗,卡库网,业务代理,基因检测,网络营销,财富热线,招商,群发软件,炒股,广州浩沅电子,深圳市汇潮科技,环球证件集团,股票,免费发送系统,地磅解码器,透视眼镜,群发,克隆手机,情趣,自慰,阳痿,早泄,信泽科技,博览会,展会,北京掌秀,LYM20082009@SINA.COM,GCT,gct,376998761,15980060760,905922138,13615926478,1123250276,945671656,360992888,5860500837,984679428,15862458745,16156839,420447161,86139619,717554527,34406794,349586602,422474154,848135666,13816350006,87806440,87805640,13810776209,85011486,85012141,908351285,13061479607,13420561687,81986825,87402996,81986873,13358438888,13599948548,13903851716,420920720,8828957,957888,39388088,13926868228,86558998,13632933607,86012577,13067166716,83071688,13560386116,48013252,85519439,13828412257,29174443,378016011,413829526,843276058,84895319,13950052396,13213177977,69139860,51662329,479318854,81175200,852135391,15169923131,13578622974,80650040,26969486,13590143676,313808006,8988400,8988200,6228481360929504014,15169923131,13755565500,985330618,38319850';
var FILTR_REGEXP = /[\.\<\>\s\`\'\"\:\-\?\=\*\+;,\(\)\[\]\/\$（）《》·；，。]+/ig;
