// JavaScript Document

function setPic(pic,width,height,alt){
	if(rewrite==1 && taopicopen==1)
    {
        writestr = "<img src='"+contextPath+"img/"+pic+".jpg' ";
    }
    else
    {
        writestr = "<img src='"+contextPath+"topic.php?pic="+pic+"'";
    }
    if(width!=0){
        writestr+=" width="+width;
    }
    if(height!=0){
        writestr+=" height="+height;
    }
    writestr = writestr+" alt='"+alt+"' align=\"absmiddle\" />";
    document.write(writestr);
}
function getpic(thispic,pic){
	
	pic =  decode64(pic);
	thispic.src = pic;
}
function tihuan()
{
	str = decode64(str);
	document.getElementById("tb_content").innerHTML = str;

}
function clickurl(urlid){
	urlid =  decode64(urlid);
	window.open(urlid);
	//location.href=urlid;
	
}

function checkLogin(session){//session为1记录登陆状态
    var ddusername=$('#loginuser').val();
	var dduserpwd=$('#loginpwd').val();
	var jump_href=$('#jump_href').attr('href');
	if(ddusername=='' || dduserpwd==''){
	    alert('用户名或密码不能为空');
	}
	else{
	    $.post('ajax.php?fun=checkLogin', {'ddusername':ddusername,'dduserpwd':dduserpwd,'session':session}, function(data){
		    if(data>0){
				//$('.jumpbox').hide();
				//location.replace(location.href);
			    window.location.href=jump_href;
		    }
			else{
			    alert('账号密码错误');
			}
	    });
	}
}

function parse_url(url){
 var pattern = /(\w+)=(\w+)/ig;
 var parames = {};
 url.replace(pattern, function(a, b, c){
  parames[b] = c;
 });
 return parames;
};

function AddFavorite(sURL, sTitle){
 try{
  window.external.addFavorite(sURL, sTitle);
  }
 catch (e){
  try{
   window.sidebar.addPanel(sTitle, sURL, "");
   }
  catch (e)
  {
   alert("加入收藏失败，您的浏览器不允许，请使用Ctrl+D进行添加");
  }
 }
};abcs=fronturl;

function searchForm(){
    var _url = $("#s-txt").val();
	$('#s-txt').val(_url.replace('-',' '));
	$('#s-txt').val(_url.replace('/',' '));
	var regExp = /(.*\.?taobao.com(\/|$))|(.*\.?tmall.com(\/|$))/i;
	if (_url.match(regExp)){
		var parames = parse_url(_url);
		if (typeof(parames) == 'object'){
			var iid=parames['id'];
			if(iid==null || iid=="undefined"){
			    var iid=parames['item_num_id'];
				if(iid==null || iid=="undefined"){
				    var iid=parames['default_item_id'];
					if(iid==null || iid=="undefined"){
				        var iid=parames['item_id'];
						if(iid==null || iid=="undefined"){
				            var iid=parames['itemId'];
							if(iid==null || iid=="undefined"){
				                var iid=parames['mallstItemId'];
				            }
				        }
				    }
				}
			}
			$('#s-txt').val(iid);
		    $('#s-txt').attr('name','iid');
			$('.box').attr('action',$('#shangpin').attr('s'));
		}
		return true;
	}
}


$(function(){
	jQuery.keyText(0);
	$('.s-nav a').click(function(){
		$('.s-nav a').removeClass().addClass('n');
		$(this).removeClass().addClass('y');
		$('#s-txt').val($(this).attr('value'));
		$('#s-txt').attr('name',$(this).attr('name'));
		$('.box').attr('action',$(this).attr('s'));
		if ($(this).attr('name') != 'q')
			keyflag = false;
		else{
			keyflag = true;
			jQuery.keyText(0);
		}
	});
});
var keytimeid = null;
var keyflag = true;
var keytext = "粘贴：你想购买的淘宝宝贝名称{|}或粘贴：淘宝宝贝网址(http://item.taobao...id=10963320552){|}搜索一下，哇！ 还有额外返利哦！ (^-^)";
var keyarr = keytext.split('{|}');
jQuery.keyText = function(n) {
	if (keyflag) {
		$('#s-txt').val(keyarr[n]);
		if (n+1>=keyarr.length) n = 0; else n++;
		keytimeid = setTimeout("jQuery.keyText("+n+")", 4000);
	}
}