var timer,d = document,$$ = function(id){return d.getElementById(id)};
//ajax 公共类---------------------------------------------
function getArrtop(url,fn){
	var xhr = document.all? new  ActiveXObject('Microsoft.XMLHTTP'):new  XMLHttpRequest;
	xhr.open('GET',url);
	xhr.onreadystatechange=function(){
		if(xhr.readyState == 4){
			try{
				var ad=eval('('+xhr.responseText+')');
				fn(ad);
			}catch(err){
			};
		}
	}
	xhr.send(null);
}
/*设置搜索Action*/
function sub_left(){
  var cate = document.getElementById('select1').value;
  if(cate=='1'){
  	 document.getElementById('search1').action="/home/search_shop.dhtml";
  	 document.search1.submit();
  }else if(cate=='2'){
  	document.getElementById('search1').action="/home/search_product.dhtml";
  	document.search1.submit();
  }
}
function qiehuan(){ 

	var e = $$('qiehuan'),p = {};
	if(!document.all){
		p.top = e.offsetTop;
		p.left = e.offsetLeft;
	
	}else{
		var to = scrollPos = window.document.documentElement.scrollTop;
		var t = e.getBoundingClientRect();
		p.top = t.top+to;
		p.left = t.left;
	}
	$$('qiehuanbox').style.top = p.top+e.offsetHeight+5+'px';
	$$('qiehuanbox').style.left = p.left+'px';
	$$('qiehuanbox').style.display = $$('qiehuanbox').style.display=='block'?'none':'block';

}
function stopTimeout(){
	clearTimeout(timer);
}
function clearQiehuan(){

	timer = setTimeout("$$('qiehuanbox').style.display = 'none'",3000) 
	
}

//20091123 kevin modify 
function addBookmark(sTitle,sURL )
  {
	  try
	  {
	  	window.external.addFavorite(sURL, sTitle);
	  }
	  catch (e)
	  {
		  try
		  {
		  	window.sidebar.addPanel(sTitle, sURL, "");
		  }
		  catch (e)
		  {
		  	alert("加入收藏失败，麻烦您手动添加!");
		  }
	  }
  }
 //switch site
function boxs(v){
 window.scrollTo(0,0);
 var bo = document.getElementsByTagName('body')[0];
 var ht = document.getElementsByTagName('html')[0];
 var boht = document.getElementById('boxs');    
 var city="";
 boht.innerHTML = '';
 bo.style.height='auto';
 bo.style.overflow='auto';
 ht.style.height='auto'; 
 if(v == 1 || v==2){   
  if(v==1){
	city= "上海";
  }else if(v==2){
  	city="北京";
  }
  bo.style.height='100%';
  bo.style.overflow='hidden';
  ht.style.height='100%';  
  boht.innerHTML = '<div id="bg"></div><div id="info"><div id="center"><strong><a href="javascript:boxs(0);">关闭</a></strong><div class="infor"><ul><li class="rowL">你确认下次访问时直接进入<span style="color:#ff0000;font-weight:blod;">'+city+'</span>站吗？</li><li class="rowC"><input type="button" value="我确认" onclick="javascript:boxs('+v+'2);"> <input type="button" onclick="javascript:boxs(0);" value="取 消"> <input type="button" value="先去逛逛" onclick="javascript:boxs('+v+'3);"></li></ul></div></div></div>';   
 }
 if(v == 12){
 	window.location.href="http://bj.article.jiehun.com.cn/gocity.php?city=sh";
 }
 if(v == 13){
 	window.location.href="http://sh.jiehun.com.cn";
 }
 if(v == 22){
 	window.location.href="http://bj.article.jiehun.com.cn/gocity.php?city=bj";
 }
 if(v == 23){
 	window.location.href="http://bj.jiehun.com.cn";
 }
}
function SetHome(obj,vrl){
        try{
                obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
        }
        catch(e){
                if(window.netscape) {
                       try {	
                        	if(confirm('是否将\"'+location.hostname+'\"设为主页？')){
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                        	}
                        }catch (e) {	
                        		var s="此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。";
                                window.alertLay ?alertLay.show({title:'提示',content:s}) : alert(s);
                        }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                        prefs.setCharPref('browser.startup.homepage',vrl);
                 }
        }
}
function us(){
	 document.domain="jiehun.com.cn";
	 getArrtop('http://'+location.host+'/home/findUser.dhtml?time='+(+new Date),function innerWelcome(welcome){
		if(welcome){
			var loguserid = document.createTextNode(welcome[0]);
			$$('logUserId').appendChild(loguserid);
			var logback = document.createTextNode(welcome[1]);
			$$('logBack').appendChild(logback);
			$$('wel1').style.display='none';
         	$$('wel2').style.display='inline';
		}
	})
}
function setMenu(){
	
	var n = $$('menu').getElementsByTagName('a'),l = location.href.split('?')[0];
	for(var i=0,ll=n.length-1;i<ll;i++){
		var p = n[i];
		p&&!new RegExp('/home/register_trader.dhtml$').test(l)&&(p.parentNode.className= new RegExp(p.href.split('?')[0]+'$').test(location.href.split('?')[0])?'top_now':'');
		p&& new RegExp('/home/index').test(p.href.split('?')[0])&& (location.href.indexOf('home/')!=-1)&&(location.href.indexOf('video')==-1)&&(location.href.indexOf('voucher')==-1)&&(location.href.indexOf('exchange')==-1) &&(p.parentNode.className='top_now');
		p&& new RegExp('/home/voucher_list').test(p.href.split('?')[0])&& (location.href.indexOf('home/')!=-1)&&(location.href.indexOf('voucher')!=-1)&&(location.href.indexOf('exchange')==-1) &&(p.parentNode.className='top_now');
		p&& new RegExp('/home/exchange_list.dhtml$').test(p.href.split('?')[0])&& (location.href.indexOf('home/')!=-1)&&(location.href.indexOf('voucher')==-1)&&(location.href.indexOf('exchange')!=-1) &&(p.parentNode.className='top_now');
		p&& new RegExp('/home/search_video.dhtml$').test(p.href.split('?')[0])&& (location.href.indexOf('home/')!=-1)&&(location.href.indexOf('voucher')==-1)&&(location.href.indexOf('video')!=-1) &&(p.parentNode.className='top_now');
		/detail/.test(l)&&/mall/.test(p.href)&&(p.parentNode.className='top_now')
	}
}