// JavaScript Document
//全局变量
var pResizeTimer = null;
var prResizeTimer = null;

$(function(){
	//当页面滚动时自动调整处理提示的位置
	$(window).scroll(function (){
				$("div#xsprogress").css("top",document.documentElement.scrollTop);
			});
	//调整页面左右高度
	if ($("div#left").height()<$("div#right").height())
	{
		if($("div#leftspace").height()<0)
			$("div#leftspace").height(0);
		$("div#leftspace").height($("div#right").height()+$("div#leftspace").height()-$("div#left").height());	
		if($("div#leftspace").height()<0)
			$("div#leftspace").height(0);
	}
		//$("div#left").height($("div#right").height()+6);
	//if ($("div#right").height()<$("div#left").height()-6)
		//$("div#main").height($("div#main").height()+$("div#all").height()-$("div#right").height()-6);
	
	//左侧用户导航
	$("div.userpanel > div.userpanel_title").each(function(i){
				$(this).click(function(){
			$(this).find("div").toggleClass("userpanel_title_2");
			$(this).parent().find("div.sub_area").toggle();										   
			 });
		});
	//动态调整页面高度
	$("div#right").resize(function(){
			doresizeright();
			//if(prResizeTimer) clearTimeout(prResizeTimer); 
    			//prResizeTimer= setTimeout(doresizeright, 50);							   
			
			//$("div#left").height($("div#right").height()+6);
			
	});
	$("div#left").resize(function(){	
								  doresizeleft();
		//if(pResizeTimer) clearTimeout(pResizeTimer); 
    		//pResizeTimer= setTimeout(doresizeleft, 50);			
	});
	$("div#all").resize(function(){	
			if ($("div#left").height()<$("div#right").height())
			{
				if($("div#leftspace").height()<0)
					$("div#leftspace").height(0);
				$("div#leftspace").height($("div#right").height()+$("div#leftspace").height()-$("div#left").height());	
				if($("div#leftspace").height()<0)
					$("div#leftspace").height(0);
			}
			else
			{
				$("div#leftspace").height($("div#right").height()+$("div#leftspace").height()-$("div#left").height());			
			}
	});
	//取得左侧广告信息
	//$("div#left_adarea").load("ajaxcz.aspx?do=getleftad");
	

});

function doresizeright()
{
	$("div#leftspace").height($("div#right").height()+$("div#leftspace").height()-$("div#left").height());
	if($("div#leftspace").height()<0)
		$("div#leftspace").height(0);
	//clearTimeout(prResizeTimer);
}
function doresizeleft()
{
	if ($("div#left").height()<$("div#right").height())
	{
		$("div#leftspace").height($("div#right").height()+$("div#leftspace").height()-$("div#left").height());	
		if($("div#leftspace").height()<0)
			$("div#leftspace").height(0);
	}
	else
	{
		if($("div#left").height()-$("div#leftspace").height()>=$("div#right").height())
			$("div#leftspace").height(0);
	}
		//$("div#left").height($("div#all").height());
	//if ($("div#right").height()<$("div#left").height()-6)
		//$("div#main").height($("div#main").height()+$("div#left").height()-$("div#right").height()-6);
	//clearTimeout(pResizeTimer);
}

//Menu
function menutoggleClass(e)
{
	$(e).find("dl").toggle();
	var obj=$(e).find("a").eq(0);
	if (obj.attr("id")=="")
		obj.attr("id","zt_gray");
	else
		obj.attr("id","");
}

//获取url参数
function getParameter()
{
    var url = top.window.location.href;
    var u, g, StrBack = '';
    
    if(arguments[arguments.length - 1] == "#")
    {
        u = url.split("#");
    }
    else
    {
        u = url.split("?");
    }
    
    if(u.length == 1)
    {
        g = '';
    }
    else
    {
        g = u[1];
    }

    if(g != '')
    {
        var gg = g.split("&");
        var MaxI = gg.length;
        var str = arguments[0] + "=";
        
        for(i = 0; i < MaxI; i++)
        {
            if(gg[i].indexOf(str) == 0)
            {
                StrBack = gg[i].replace(str, "");
                break;
            }
        }
    }
    
    return StrBack;
}
var url="http://localhost/duile/test.html?key=k";
function getUrlPar()
{
	var url = top.window.location.href;
	var pars,p="",ps,pe;
	pars=url.split('?');
	if (pars.length==2)
	{
		p=pars[1];
	}
	ps=p.split('&');
	p="";
	var n=p.length;
	for(var i=0;i<n;i++)
	{
		pe=p[i].split('=');
		p+=pe[0]+"="+escape(pe[1]);
	}
	return p;
}

//显示操作提示
var successtimer=null;
	function showsuccess(str)
	{
		$("div#showSuccessInfo").html(str).show().css("top",document.documentElement.scrollTop+200).css("left",$(window).width()/2-30);
		var successtimer=setTimeout(closesuccess,3000);
	}
	function closesuccess()
	{
		$("div#showSuccessInfo").fadeOut(2000);
		clearTimeout(successtimer);
	}
	
//加好友操作
function addfriend(str)
{
	$.ajax({
		 type:"Get",
		 url:"ajaxcz.aspx?do=af&par="+str,
		 success:function(msg){alert(msg);}
		 });	
}

//列表显示页面调整选中
function showlabelselect(e)
{
	$("ul#showtype > li").each(function (i){
		if (i!=0)
		{
			$(this).removeClass();
		}
	});
	
	$(e).parent("li").addClass("label_selected");
}
function orderlabelselect(e)
{
	$("ul#ordertype > li").each(function (i){
		if (i!=0)
		{
			$(this).removeClass();
		}
	});
	
	$(e).parent("li").addClass("label_selected");
}

jQuery.fn.resizeimg=function(w,h){
			var ew=parseInt(this.width());
			var eh=parseInt(this.height());
			if (w==0)
			{
				if (eh>h)
				{
					ew=ew*h/eh;
					eh=h;
					//this.wrap("<a href='"+this[0].src+"' target='_blank'></a>");
				}
			}
			else if(h==0)
			{
				if (ew>w)
				{
					eh=w*eh/ew;
					ew=w;
					//this.wrap("<a href='"+this[0].src+"' target='_blank'></a>");
				}	
			}
			else
			{
				if (ew>w || eh>h)
				{			
					if (ew/eh >= w/h)
					{
						eh=w*eh/ew;
						ew=w;
					}
					else
					{
						ew=ew*h/eh;
						eh=h;
					}
					//this.wrap("<a href='"+this[0].src+"' target='_blank'></a>");
					//this.after("");
				}
			}
			
			this.width(ew);
			this.height(eh);
							  };

$.fn.resetimg=function(w,h){
			var ew=parseInt(this.width());
			var eh=parseInt(this.height());
			if (w==0)
			{
				if (eh>h)
				{
					ew=ew*h/eh;
					eh=h;
					this.wrap("<a href='"+this[0].src+"' target='_blank'></a>");
				}
			}
			else if(h==0)
			{
				if (ew>w)
				{
					eh=w*eh/ew;
					ew=w;
					this.wrap("<a href='"+this[0].src+"' target='_blank'></a>");
				}	
			}
			else
			{
				if (ew>w || eh>h)
				{			
					if (ew/eh >= w/h)
					{
						eh=w*eh/ew;
						ew=w;
					}
					else
					{
						ew=ew*h/eh;
						eh=h;
					}
					this.wrap("<a href='"+this[0].src+"' target='_blank'></a>");
					//this.after("");
				}
			}
			
			this.width(ew);
			this.height(eh);
			
		};	

jQuery.fn.setimgsize=function(w,h){

			this.width(w);
			this.height(h);
};	

jQuery.fn.getresizeimg=function(w,h){
			var ew=parseInt(this.width());
			var eh=parseInt(this.height());
			if (w==0)
			{
				if (eh>h)
				{
					ew=ew*h/eh;
					eh=h;
				}
			}
			else if(h==0)
			{
				if (ew>w)
				{
					eh=w*eh/ew;
					ew=w;
				}	
			}
			else
			{
				if (ew>w || eh>h)
				{			
					if (ew/eh >= w/h)
					{
						eh=w*eh/ew;
						ew=w;
					}
					else
					{
						ew=ew*h/eh;
						eh=h;
					}
				}
			}
			return new Array(ew,eh);
};

jQuery.fn.resizeuserimg=function(w,h){
			var ew=parseInt(this.width());
			var eh=parseInt(this.height());
			if (w==0)
			{
				if (eh>h)
				{
					ew=ew*h/eh;
					eh=h;
					//this.wrap("<a href='"+this[0].src+"' target='_blank'></a>");
				}
			}
			else if(h==0)
			{
				if (ew>w)
				{
					eh=w*eh/ew;
					ew=w;
					//this.wrap("<a href='"+this[0].src+"' target='_blank'></a>");
				}	
			}
			else
			{
				if (ew>w || eh>h)
				{			
					if (ew/eh >= w/h)
					{
						eh=w*eh/ew;
						ew=w;
					}
					else
					{
						ew=ew*h/eh;
						eh=h;
					}
					//this.wrap("<a href='"+this[0].src+"' target='_blank'></a>");
					//this.after("");
				}
			}
			
			this.width(ew);
			this.height(eh);
			
			this.parent().width(ew);
			this.parent().height(eh);
							  };
//*****************************************************************************							  
//取得省市县	操作区	
function selectchina()
{
	$("div#chinalist").css("top",document.documentElement.scrollTop+100).css("left",$(window).width()/2-300).show('slow');
	sprovince();
}

	function getprovince()
	{
		$("div#clprovincelist_nr").load("ajaxcz.aspx?do=getp");
	}
	function getprovincecl()
	{
		$("div#clprovincelist_nr").load("ajaxcz.aspx?do=getpcl");
		//$("div#clprovincelist").load("ajaxcz.aspx?do=getpcl",null,function(){$("div#clprovincelist").append("<div class='clear'></div>");});
	}
	function getprovincelist()
	{
		$("div#clprovincelist_nr").load("ajaxcz.aspx?do=getprovincelist");
		//$("div#clprovincelist").load("ajaxcz.aspx?do=getprovincelist",null,function(){$("div#clprovincelist").append("<div class='clear'></div>");});
	}
	function getcity(e,pid)
	{
		$("div#clprovincelist_nr > a").removeClass();
		$(e).addClass("chinaselected");
		$("div#clcitylist_nr").load("ajaxcz.aspx?do=getcity&pid="+pid+"");
		//$("div#clcitylist").load("ajaxcz.aspx?do=getcity&pid="+pid+"",null,function(){$("div#clcitylist").append("<div class='clear'></div>");});
		
	}
	function getcitylist(e,pid)
	{
		$("div#clprovincelist_nr > a").removeClass();
		$(e).addClass("chinaselected");
		$("div#clcitylist_nr").load("ajaxcz.aspx?do=getcitylist&pid="+pid+"");
		//$("div#clcitylist").load("ajaxcz.aspx?do=getcitylist&pid="+pid+"",null,function(){$("div#clcitylist").append("<div class='clear'></div>");});
		
	}
	function getarea(e,cid)
	{
		$("div#clcitylist_nr > a").removeClass();
		$(e).addClass("chinaselected");
		$("div#clarealist_nr").load("ajaxcz.aspx?do=getarea&cid="+cid+"");
		//$("div#clarealist").load("ajaxcz.aspx?do=getarea&cid="+cid+"",null,function(){$("div#clarealist").append("<div class='clear'></div>");});
	}
	
	function sprovince()
	{	
		if (arguments[0])
		{
			$("div#clcztitle_nr > a").removeClass();
			$(arguments[0]).addClass("chinaselected");
		}
		$("div#clcitylist").hide();
		$("div#clarealist").hide();
		getprovincelist();
	}
	function scity(e)
	{
		$("div#clcztitle > a").removeClass();
		$(e).addClass("chinaselected");
		$("div#clcitylist_nr").html("请先选择省");
		$("div#clcitylist").show();
		$("div#clarealist").hide();
		getprovincecl();
	}
	function sarea(e)
	{	
		$("div#clcztitle > a").removeClass();
		$(e).addClass("chinaselected");
		$("div#clcitylist_nr").html("请先选择省");
		$("div#clarealist_nr").html("请先选择省市");
		$("div#clcitylist").show();
		$("div#clarealist").show();
		getprovince();
	}
	
	
//-------------------------------------------------------------------------------

//绑定thickbox
function bindthick()
{
	tb_init('a.thickbox, area.thickbox, input.thickbox');
}

//添加收藏
function getfavorite(i,j)
{
	$.ajax({
		   	url:"ajaxcz.aspx?do=addfc&dlid="+i.toString()+"&cs="+j.toString(),
			success:function(e){
					if(e!="")
						alert(e);
				}
		   });	
}
function getdatacouplet(i,j)
{
	$.ajax({
		   	url:"ajaxcz.aspx?do=adddc&dlid="+i.toString()+"&cs="+j.toString(),
			success:function(e){
					if(e!="")
						alert(e);
				}
		   });	
}


function setfn(obj,fn)
{
	$("#"+obj).val(fn);
	
}

//回复评论
function rcomment(i)
{
	$("#pl_scid").val(i);
	$('div#addcomment').show();
	$("#pl_nr").val('').focus();
}
//写留言
function amessage(i)
{
	$("#ly_scid").val(i);
	$('div#addmessage').show();
	$("#ly_nr").val('').focus();
}