if ($(window).width()<=500)
{
	window.location="http://tou.mobi/wap/";
}
var url;
d = new Date();
t = d.getTime()/1000;
url="/";  
$(":text").focus(function(){
	$(this).select();
});

$(":password").focus(function(){
	$(this).select();
});
$("img.zhi").click(function(){
	$('img.zhi span.close').remove();
	$("img.zhi").next('div').css('display','none');
	$(this).next('div').css('visibility','hidden');
	$(this).next('div').css('display','block');
	var dh=$(this).next('div').height();
	$(this).next('div').css('visibility','visible');
	$(this).next('div').css('height','1px');
	$(this).next('div').animate( { height: dh}, { queue: false, duration:500});
	$(this).next('div').append('<span class="close"></span>');
	$("span.close").click(function(){
		$(this).parent('div').css('display','none');
	});
});
//点击搜索生成静态页
$("#search").click(function(){
	var key=$('#keyword').attr("value");
	$.get(url+"function/createhtm.php",{k:key,random:Math.random()},function(data){
		if (data=='error')
		{
			alert('正在生成查询结果,请稍后再试!');
		}
		else
		{
			window.location=url+'html/'+data.substr(0,8)+'/'+data+'.html';
		}
	});
});
//加入收藏夹
var address = function (obj, url, title) {
    var e = window.event || arguments.callee.caller.arguments[0];
    
    var B = {
        IE : /MSIE/.test(window.navigator.userAgent) && !window.opera
        , FF : /Firefox/.test(window.navigator.userAgent)
        , OP : !!window.opera
    };
    
    obj.onmousedown = null;
    
    if (B.IE) {
        obj.attachEvent("onmouseup", function () {
            try {
                window.external.AddFavorite(url, title);
                window.event.returnValue = false;
            } catch (exp) {}
        });
    } else {
        if (B.FF || obj.nodeName.toLowerCase() == "a") {
            obj.setAttribute("rel", "sidebar"), obj.title = title, obj.href = url;
        } else if (B.OP) {
            var a = document.createElement("a");
            a.rel = "sidebar", a.title = title, a.href = url;
            obj.parentNode.insertBefore(a, obj);
            a.appendChild(obj);
            a = null;
        }
    }
};
function vote(table,id)
{
	$.get("http://tou.mobi/function/vote.php",{t:table,k:id,act:'up',random:Math.random()},function(data){
			alert(data);
	});
}
function reject(table,id)
{
	$.get("http://tou.mobi/function/vote.php",{t:table,k:id,act:'down',random:Math.random()},function(data){
			alert(data);
	});
}
function opentaobaobyid(pid)
{
	$.get("http://tou.mobi/function/getinfo.php",{k:pid,act:'gettaobaourl',random:Math.random()},function(data){
			window.location.href=data;	
	});
}
function searhbyxing()
{
	var key=$('#xing').val();
	$.get("http://tou.mobi/function/nametools.php",{k:key,act:'geturl',random:Math.random()},function(data){
		window.location='http://tou.mobi/html/name/'+data;
	});
}
function readhistory(str)
{
	var c=window.location.href;
	$.get("http://tou.mobi/function/history.php",{url:c,tag:str,random:Math.random()},function(data){
		$('#'+str).html(data);
		$("input[name='"+str+"']").attr('value',data);
	});
}
//根据关键字进行搜索，并输出内容到页面
function autosearch(key,style)
{
	$.get("http://tou.mobi/function/presearch.php",{k:key,act:style,random:Math.random()},function(data){
		$('.handphonelist').append(data);
		if (data)
		{
			if (data.indexOf('mysql_connect')!=-1)
			{
				autosearch(key,1);
			}
		}
		else
		{
			if ($('#result .handphonelist').html()=='')
			{
				$('#result').html('<img src="http://tou.mobi/images/searchempty.gif"/>');
			}
			if ($('#result .namelist').html()=='')
			{
				$('#result').html('<img src="http://tou.mobi/images/searchempty.gif"/>');
			}

		}
	});
}
function addinfo()
{
	//清除全局ajax域
	$.ajaxSetup({global: false});
	$.get("http://tou.mobi/function/infoadd.php",$('#nameform').serialize(),function(data){
		alert(data);
		//$('#nameform input[type="text"]').val('');
	});
}
//更新页面缓存
function pageupdate(tpl)
{
	setTimeout("update('"+tpl+"')",50);
}
function update(str)
{
	//更新页面缓存
	var c=window.location.href;
	//清除全局ajax域
	$.ajaxSetup({global: false});
	$.post("http://tou.mobi/function/page.php?key="+encodeURI(key)+"&tpl="+str+"&url="+c,$('#html').serialize(),function(data){
		$('#copyright').prepend(data);
	});
}
function createadv(tpl)
{
	/*
	//ad1底部的广告栏960*60
	var data='<div style="color:red;text-align:center;line-height:60px;">广告位(960*60)招租!请联系QQ:40459931</div>';
	$('div#ad1').html(data);
	$("input[name='ad1']").attr('value',data);
	//ad2左侧的广告栏240*100
	data='<div style="color:red;text-align:center;line-height:100px;">广告位(240*100)招租!请联系QQ:40459931</div>';
	$('div#ad2').html(data);
	$("input[name='ad2']").attr('value',data);
	//ad3右侧的广告栏240*100
	data='<div style="color:red;text-align:center;line-height:100px;">广告位(240*100)招租!请联系QQ:40459931</div>';
	$('div#ad3').html(data);
	$("input[name='ad3']").attr('value',data);
	//ad4顶部的广告栏960*20
	data='<div style="color:red;text-align:right;line-height:20px;">广告位(960*20)招租!请联系QQ:40459931</div>';
	$('div#ad4').html(data);
	$("input[name='ad4']").attr('value',data);
	*/
}
//根据不同的模板调用不同的JS代码
if (tpl=='nametpl')
{
	//根据生成时间判断是否需要更新缓存
	if (tdate=='<<[[date]]>>'||(parseInt(t)-parseInt(tdate)>36000))
	{
		$.get("http://tou.mobi/function/getinfo.php",{k:key,act:'nameinfo',random:Math.random()},function(data){
			$('div#nameinfo').html(data);
			$("input[name='nameinfo']").attr('value',data);
			//绑定事件
			$("img.zhi").click(function(){
				$('img.zhi span.close').remove();
				$("img.zhi").next('div').css('display','none');
				$(this).next('div').css('visibility','hidden');
				$(this).next('div').css('display','block');
				var dh=$(this).next('div').height();
				$(this).next('div').css('visibility','visible');
				$(this).next('div').css('height','1px');
				$(this).next('div').animate( { height: dh}, { queue: false, duration:500});
				$(this).next('div').append('<span class="close"></span>');
				$("span.close").click(function(){
					$(this).parent('div').css('display','none');
				});
			});
		});
		$.get("http://tou.mobi/function/getinfo.php",{k:key,act:'bolglist',random:Math.random()},function(data){
			$('div#bolglist').html(data);
			$("input[name='bolglist']").attr('value',data);
		});
		$.get("http://tou.mobi/function/getinfo.php",{k:key,act:'relatedword',random:Math.random()},function(data){
			$('div#relatedword').html(data);
			$("input[name='relatedword']").attr('value',data);
		});
		$.get("http://tou.mobi/function/getinfo.php",{k:key,act:'relatedimg',random:Math.random()},function(data){
			$('div#relatedimg').html(data);
			$("input[name='relatedimg']").attr('value',data);
		});
		readhistory('history');
		createadv();
		//所有的ajax停止后生成静态页面
		$('body').ajaxStop(function(){
			pageupdate('nametpl');
		});
	}
	$.get("http://tou.mobi/function/search.php",{k:key,act:1,random:Math.random()},function(data){
		$('div#result').html(data);
		$("input[name='result']").attr('value',data);
		autosearch(key,1)
	});
}else if(tpl=='phonetpl')
{
	//根据生成时间判断是否需要更新缓存
	if (tdate=='<<[[date]]>>'||(parseInt(t)-parseInt(tdate)>36000))
	{
		
		$.get("http://tou.mobi/function/getinfo.php",{k:key,act:'phoneinfo',random:Math.random()},function(data){
			$('#phoneinfo').html(data);
			$("input[name='phoneinfo']").attr('value',data);
		});
		$.get("http://tou.mobi/function/cardinfo.php",{phone:key,random:Math.random()},function(data){
			$('#phonearea').html(data);
			$("input[name='phonearea']").attr('value',data);
		});

		readhistory('history');
		createadv();
		//所有的ajax停止后生成静态页面
		$('body').ajaxStop(function(){
			pageupdate('phonetpl');
		});
	}
	$.get("http://tou.mobi/function/search.php",{k:key,act:2,random:Math.random()},function(data){
		$('#result').html(data);
		$("input[name='result']").attr('value',data);
		autosearch(key,2)
	});
}else if(tpl=='errortpl')
{
	readhistory('history');
	pageupdate('errortpl');
}else if(tpl=='article')
{
	//文章展示页面的更新
	if (tdate=='<<[[date]]>>'||(parseInt(t)-parseInt(tdate)>36000))
	{
		$.get("http://tou.mobi/function/getinfo.php",{k:key,act:'readbolglist',random:Math.random()},function(data){
			$('div#bolglist').html(data);
			$("input[name='bolglist']").attr('value',data);
		});
		createadv();
		//所有的ajax停止后生成静态页面
		$('body').ajaxStop(function(){
			data=$('div#content').html();
			$("input[name='content']").attr('value',data);
			pageupdate('article');
		});
	}
}else if(tpl=='index')
{
	if (tdate=='<<[[date]]>>'||(parseInt(t)-parseInt(tdate)>3600))
	{
		$.get("http://tou.mobi/function/list.php",{p:path,random:Math.random()},function(data){
			$('#list').html(data);
		});
	}
}else if(tpl=='name')
{
	//调用ajax起名工具
	$.get("http://tou.mobi/function/nametools.php",{k:'',act:'',random:Math.random()},function(data){
		$('#ajaxnametools').html(data);
	});
}else if (tpl=='home')
{
	//首页要调用的JS函数
	$("#keyword").keyup(function(){
		var str=$("#keyword").attr('value');
		if (str.length>=7)
		{
			$.get("/function/cardinfo.php",{phone:str,random:Math.random()},function(data){
				$('.result').html(data);
			});
		}
	});
	//根据生成时间判断是否需要更新缓存
	if (tdate=='<<[[date]]>>'||(parseInt(t)-parseInt(tdate)>18000))
	{
		//最近在找谁
		//readhistory('toolsnav');
		//调用最新的博客文章
		$.get("http://tou.mobi/function/getinfo.php",{k:'',act:'newblog',random:Math.random()},function(data){
			$('div#newblog').html(data);
			$("input[name='newblog']").attr('value',data);
		});
		//调用最热门人物榜
		$.get("http://tou.mobi/function/getinfo.php",{k:'',act:'hotpeople',random:Math.random()},function(data){
			$('div#toolsnav').html(data);
			$("input[name='toolsnav']").attr('value',data);
		});
		//所有的ajax停止后生成静态页面
		$('body').ajaxStop(function(){
			pageupdate('home');
		});
	}
}
