// JavaScript Document

/*function topage(pages,url)
{
	replaceParam('page',pages,url);
}
function replaceTopFunctions(id,obj,strTop){
	$('#r_desc').css({"display":"none"});
	$('#v_subfunctions').val('0');
	$('#v_topfunctions').val(id);
	$('#r_subfunctions').html('');
	$("a[id^='ra_sub_functions_']").css({"background-color":""});
	$("a[id^='ra_top_functions_']").css({"background-color":""});
	$("#ra_top_functions_"+id).css({"background-color":"#dddddd"});
	strTop = "<a href=\"javascript:delFilter('v_topfunctions','r_topfunctions','ra_top_functions');\" title=\"房间:" + strTop + "\" ><h5>房间:</h5> "+strTop + "<span class=\"close-icon\"></span></a>";
	$('#'+obj).html(strTop);	
}
function replaceFunctions(id,obj,topId,strTop,strSub){
	$('#r_desc').css({"display":"none"});
	$('#v_topfunctions').val(topId);
	$('#v_subfunctions').val(id);
	$("a[id^='ra_top_functions_']").css({"background-color":""});
	$("a[id^='ra_sub_functions_']").css({"background-color":""});
	$("#ra_sub_functions_"+id).css({"background-color":"#dddddd"});
	strTop = "<a href=\"javascript:delFilter('v_topfunctions','r_topfunctions','ra_top_functions');\" title=\"房间:" + strTop + "\" ><h5>房间:</h5> "+strTop + "<span class=\"close-icon\"></span></a>";
	$('#r_topfunctions').html(strTop);
	
	strSub = "<a href=\"javascript:delFilter('v_subfunctions','r_subfunctions','ra_sub_functions',"+topId+");\" title=\"功能:" + strSub + "\" ><h5>功能:</h5> "+strSub + "<span class=\"close-icon\"></span></a>";
	$('#r_subfunctions').html(strSub);
}
function replacePrice(key,obj,strVal){
	$('#r_desc').css({"display":"none"});
	$('#v_price').val(key);
	$("a[id^='ra_price_']").css({"background-color":""});
	$("#ra_price_"+key).css({"background-color":"#dddddd"});
	strVal = "<a href=\"javascript:delFilter('v_price','"+obj +"','ra_price');\" title=\"价格:" + strVal + "\" ><h5>价格:</h5> "+strVal + "<span class=\"close-icon\"></span></a>";
	$('#'+obj).html(strVal);
}
function replaceTopCat(id,obj,strVal){
	$('#r_desc').css({"display":"none"});
	$('#v_subcategory').val('0');
	$('#v_topcategory').val(id);	
	$("div[id^='subcat_']").css({"display":"none"});
	$("#subcat_"+id).css({"display":""});
	$("a[id^='ra_topcat_']").css({"background-color":""});
	$("#ra_topcat_"+id).css({"background-color":"#dddddd"});
	strVal = "<a href=\"javascript:delFilter('v_topcategory','"+obj +"','ra_topcat');\" title=\"风格:" + strVal + "\" ><h5>风格:</h5> "+strVal + "<span class=\"close-icon\"></span></a>";
	$('#'+obj).html(strVal);
}
function replaceSubCat(id,obj,strVal){
	$('#r_desc').css({"display":"none"});
	$('#v_subcategory').val(id);
	$("a[id^='ra_subcat_']").css({"background-color":""});
	$("#ra_subcat_"+id).css({"background-color":"#dddddd"});
	strVal = "<a href=\"javascript:delFilter('v_subcategory','"+obj +"','ra_subcat');\" title=\"品牌:" + strVal + "\" ><h5>品牌:</h5> "+strVal + "<span class=\"close-icon\"></span></a>";
	$('#'+obj).html(strVal);
}
function replaceMinMaxprice(minPrice,maxPrice){
	$('#r_desc').css({"display":"none"});
	$('#v_price').val('0');
	$('#v_min_price').val(minPrice);
	$('#v_max_price').val(maxPrice);
	
	$("a[id^='ra_price_']").css({"background-color":""});
	strVal = "<a href=\"javascript:delPrice();\" title=\"价格:" + minPrice + '-' + maxPrice + "元\" ><h5>价格:</h5> "+ minPrice + '-' + maxPrice + "元<span class=\"close-icon\"></span></a>";
	$('#r_price').html(strVal);
}
function delPrice(){
	$('#v_min_price').val('0');
	$('#v_max_price').val('0');
	$('#v_price').val('0');
	$('#r_price').html('');
}
function delFilter(inputID,objID,linkID,id){
	if(id=='undefined'){id=0;}
	$('#'+inputID).val('0');
	$('#'+objID).html('');
	if(objID=='r_topfunctions'){
		$('#r_subfunctions').html('');
		$("a[id^='ra_sub_functions_']").css({"background-color":""});
	}
	if(objID=='r_topcat'){
		$('#r_subcat').html('');
		$("div[id^='subcat_']").css({"display":"none"});
	}
	if(objID=='r_subfunctions'){
		$("#ra_top_functions_"+id).css({"background-color":"#dddddd"});
	}
	$("a[id^='"+linkID+"_']").css({"background-color":""});
}
function showmorecat(){
	$("li[class='more_cat']").css({"display":""});
	$(".more").css({"display":"none"});
}*/
function showDropMenu(Obj) {
	Obj.className = "hover";
}
function hideDropMenu(Obj) {
	Obj.className = "active";
}
/* *
 * 添加商品到收藏夹
 */
/*function collect(goodsId)
{
	$.get('user.php?act=collect',{'id':goodsId}, function(json){
		//var data=eval(result);
		var json = eval("(" + json + ")");
		if(json.error==1){
			if(confirm("因为您还没有登陆，因此您还不能进行此操作！\r\n\r\n您需要现在登陆吗？")){
				location.href="user.php";
			}
		}
		else{
			alert(json.message);
		}
	});

}
function changeArea(parent, type, target,sn)
{
	var opt="<option value='0'>--请选择--</option>";
	if(type==1){		
		$('#selProvinces_'+sn).html(opt);
		$('#selCities_'+sn).html(opt);
		$('#selDistricts_'+sn).html(opt);	
	}
	if(type==2){		
		$('#selCities_'+sn).html(opt);
		$('#selDistricts_'+sn).html(opt);	
	}
	$.get('region_jq.php',{"type":type,"target":target,"parent":parent},function(res){
		var result = eval("(" + res + ")");
		
		$.each(result, function(i, item){
			opt += "<option value='" + item.region_id+"'>"+item.region_name+"</option>";
		});
		$("#"+target).html(opt);
	});	
}
function submitSearch(){
	var category = $('#category').val();
	var functions = $('#functions').val();
	var skey = $('#skey').val();
	if(skey == ' 请输入关键词' || skey =='请输入关键词' ){
		var url = 'category.php?id='+category+'&topfunctions='+functions;

		location.href = url;
		return false;
	}
	else{

		$('#searchForm').attr('action','search.php');	
		return true;
	}
	
}*/
/**
 * 点选可选属性或改变数量时修改商品价格的函数
 */
/*function changePrice()
{
  var attr = getSelectedAttributes(document.forms['TJ_FORMBUY']);
  var qty = $('#number').val();
  $.get('goods.php',{"act":"price","id":goodsId,"attr":attr,"number":qty},function(res){
	  var res = eval("(" + res + ")");
	  if (res.err_msg.length > 0)
	  {
		alert(res.err_msg);
	  }
	  else
	  {		  
		  $('#number').val(res.qty);
		  $('#TJ_GOODS_AMOUNT').html(res.result); 
	  }
  });  
}*/
/* *
 * 评论的翻页函数
 */
/*function gotoPage(page, id, type)
{
	$.get('comment.php',{"act":"gotopage","page":page,"id":id,"type":type},function(res){		
		var res = eval("(" + res + ")");
		$("#TJ_COMMENT").html(res.content);
	});
}
*/

//加入收藏夹
function bookmarksite(title, url) {
    if (document.all)
        window.external.AddFavorite(url, title);
    else if (window.sidebar)
        window.sidebar.addPanel(title, url, "");
}
function OnEnter(field) {
    if (field.value == field.defaultValue) {
        field.value = "";
    }
}
function OnExit(field) {
    if (field.value == "") {
        field.value = field.defaultValue;
    }
}
/* *
 * 添加商品到购物车
 */
/*function addToCart(goodsId,towhere, parentId)
{
	
  var goods        = new Object();
  var spec_arr     = new Array();
  var fittings_arr = new Array();
  var number       = 1;

  // 检查是否有商品规格  
  spec_arr = getSelectedAttributes();
  number = $('#number').val();   
  

  goods.spec     = spec_arr;
  goods.goods_id = goodsId;
  goods.number   = number;
 
  goods.parent   = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);
  $.post('flow.php?step=add_to_cart',{'step':'add_to_cart', 'goods': goods}, function(res){
	  var result = eval("(" + res + ")");
	   if (result.error > 0)
	  {
		// 如果需要缺货登记，跳转
		if (result.error == 2)
		{
		  if (confirm(result.message))
		  {
			location.href = 'user.php?act=add_booking&id=' + result.goods_id;
		  }
		}
		// 没选规格，跳到商品详情页
		else if (result.error == 6)
		{
		  if (confirm(result.message))
		  {
			location.href = 'goods.php?id=' + result.goods_id;
		  }
		}
		else
		{
		  alert(result.message);
		}
	  }
	  else
	  {
		
		var cart_url = 'flow.php?step=cart';
		
		$('#TJ_CARTINFO').html(result.number);
		$('#shopDropList').html(result.cartinfo);
		
		if (result.one_step_buy == '1')
		{
		  location.href = cart_url;
		}
		else
		{
		  switch(result.confirm_type)
		  {
			case '1' :
			  if (!confirm(result.message)) location.href = cart_url;
			  break;
			case '2' :
			  if (confirm(result.message)) location.href = cart_url;
			  break;
			case '3' :
			  location.href = cart_url;
			  break;
			default :
			  break;
		  }
		}
	  }
  });
}
function delgoods(goodsid){
		if(confirm('您确定要从购物车中删除这个产品吗?')){
			$.get('flow.php',{"step":"del_goods",'id':goodsid},function(res){
				var result = eval("(" + res + ")");
				$('#TJ_CARTINFO').html(result.number);
				$('#shopDropList').html(result.cartinfo);
			});
		}	
}
*/
/**
 * 获得选定的商品属性
 */
/*function getSelectedAttributes()
{
  var spec_arr = new Array();
  var j = 0;

  var formBuy      = document.forms['TJ_FORMBUY'];
  for (i = 0; i < formBuy.elements.length; i ++ )
  {
    var prefix = formBuy.elements[i].name.substr(0, 5);

    if (prefix == 'spec_' && (
      ((formBuy.elements[i].type == 'radio' || formBuy.elements[i].type == 'checkbox') && formBuy.elements[i].checked) ||
      formBuy.elements[i].tagName == 'SELECT'))
    {
      spec_arr[j] = formBuy.elements[i].value;
      j++ ;
    }
  }

  return spec_arr;
}

function replaceCat(topCat,subCat,topFun,subFun,price,minPrice,maxPrice,url){	
	url = url + '?topcategory=' +topCat+'&subcategory='+subCat+'&topfunctions='+topFun+'&subfunctions='+subFun+'&price='+price+'&price_min='+minPrice+'&price_max='+maxPrice;
	location.assign(url);
}
*/
/* 替换参数 */
/*function replaceParam(key,value,url)
{
	
    var params = location.search.substr(1).split('&');
    var pfound  = false;
	var ofound = false;
    for (var i = 0; i < params.length; i++)
    {
        param = params[i];
        arr   = param.split('=');
        pKey  = arr[0];
        if (pKey == 'page')
        {
            params[i] = 'page=1';
        }
		if(pKey=='order'){
			if(arr[1]=='DESC'){
				params[i] = pKey + '=ASC' ;
			}
			else{
				params[i] = pKey + '=DESC' ;
			}
			ofound=true;
		}
        if (pKey == key)
        {
            params[i] = key + '=' + value;
            pfound = true;
        }
    }
    if (!pfound)
    {
        //value = transform_char(value);
        params.push(key + '=' + value);
    }
	if (!ofound)
    {
        params.push('order=DESC');
    }

	if(url=='category.php' || url=='functions.php'){
		location.assign(url + '?' + params.join('&') + '#view_area');
	}
	else{
		location.assign(url + '?' + params.join('&') );
	}
    
}
*/
/* 删除参数 */
/*function dropParam(key,url)
{
    var params = location.search.substr(1).split('&');
    for (var i = 0; i < params.length; i++)
    {
        param = params[i];
        arr   = param.split('=');
        pKey  = arr[0];
        if (pKey == 'page')
        {
            params[i] = 'page=1';
        }
        if (pKey == key)
        {
            params.splice(i, 1);
        }
    }
    location.assign(url + '?' + params.join('&'));
}
*///jquery 幻灯片
/*$.fn.extend({
    GetRandomInt: function (min, max) {//返回min到max之间的整数【包括min,不包括max】
        return parseInt(Math.random() * (max - min), 10) + min;
    },
    RandomImgListPlayer: function (options) {
        var settings = { select: "div[name='focus_img_list']", timer: 5000, menu: "#play_text", imgsrc: "originalsrc" };
        options = options || {};
        $.extend(settings, options);

        var image_list = $("'" + settings.select + "'", this);
        var n = 0;
        var count = 1;
        image_list.hide();
        if (image_list.length > 0) {
            var auto = null;
            var rand = this.GetRandomInt(0, image_list.length);
            if (rand >= image_list.length)
                rand = image_list.length - 1;
            var obj = image_list.eq(rand);
            obj.show();
            var img_list = $("a > img", obj);
            count = img_list.length;
            img_list.each(function (i) {
                var originalsrc = img_list.eq(i).attr(settings.imgsrc);
                if (originalsrc != null && this.src == "") {
                    this.src = originalsrc;
                }
            });
            var ulcontent = "<ul>";
            for (i = 1; i <= count; i++) { ulcontent = ulcontent + "<li>" + i + "</li>"; }
            ulcontent = ulcontent + "</ul>";
            $(settings.menu).html(ulcontent);
            $("a:not(:first-child)", this).hide();
            $(settings.menu + " li").eq(0).css({ "background": "#000000", "color": "#fff", "font-weight": "bolder" });
            $(settings.menu + " li").mouseover(function () {
                i = $(this).text() - 1;
                n = i;
                if (n >= count) return;
                $("a", obj).filter(":visible").fadeOut(200, function () { $(this).parent().children().eq(n).fadeIn(300); });
                $(this).css({ "background": "#000", "color": "#fff", "font-weight": "bolder" }).siblings().css({ "background": "#999999", "color": "#fff", "font-weight": "normal" });
            });
            var auto = setInterval(showAuto, settings.timer);
            obj.hover(function () { clearInterval(auto) }, function () { auto = setInterval(showAuto, settings.timer); });
        }
        function showAuto() {
            n = n >= (count - 1) ? 0 : ++n;
            $(settings.menu + " li").eq(n).trigger('mouseover');
        }
    },
    RandomImgIsInit: false,
    RandomImgList: new Object(),
    AddRandomImg: function (_url, _scale, _link, _aparam) {
        if (this.RandomImgIsInit == false) {
            this.RandomImgList.imgAry = new Array();
            this.RandomImgList.max = 0;
            this.RandomImgIsInit = true;
        }
        var imgView = new Object();
        imgView.url = _url;
        imgView.scale = parseInt(_scale);
        imgView.link = _link;
        if (_aparam == null)
            imgView.aparam = '';
        else
            imgView.aparam = _aparam;
        index = this.RandomImgList.imgAry.length;
        this.RandomImgList.imgAry[index] = imgView;
        this.RandomImgList.imgAry[index].scalemin = this.RandomImgList.max;
        this.RandomImgList.max = this.RandomImgList.max + this.RandomImgList.imgAry[index].scale;
        this.RandomImgList.imgAry[index].scalemax = this.RandomImgList.max;
    },
    GetRandomImg: function () {
        ran = this.GetRandomInt(1, this.RandomImgList.max + 1);
        if (ran > this.RandomImgList.max) {
            return this.RandomImgList.imgAry[this.RandomImgList.imgAry.length - 1];
        }
        else {
            for (i = 0; i < this.RandomImgList.imgAry.length; i++) {
                if (ran > this.RandomImgList.imgAry[i].scalemin && ran <= this.RandomImgList.imgAry[i].scalemax) {
                    return this.RandomImgList.imgAry[i];
                }
            }
        }
    },
    GetRandomImgHTML: function () {
        var obj = this.GetRandomImg();
        return "<a href='" + obj.link + "' " + obj.aparam + " target='_blank'><img src='" + obj.url + "'/></a>";
    },
    GetRandomImgListHtml: function () {
        var first = this.GetRandomImg();
        var html = "";
        html = html + "<a href='" + first.link + "' " + first.aparam + " target='_blank'><img src='" + first.url + "'/></a>";
        this.RandomImgList.imgAry.sort(function (a, b) { if (a.scale != b.scale) { return b.scale - a.scale; } else { return a.Index - b.Index; } });
        for (i = 0; i < this.RandomImgList.imgAry.length; i++) {
            if (this.RandomImgList.imgAry[i].url != first.url) {
                html = html + "<a href='" + this.RandomImgList.imgAry[i].link + "' " + this.RandomImgList.imgAry[i].aparam + " target='_blank'><img src='" + this.RandomImgList.imgAry[i].url + "'/></a>";
            }
        }
        return html;
    },
    RandomImgPlayer: function (options) {
        var settings = { multiImg: false };
        options = options || {};
        $.extend(settings, options);

        if (settings.multiImg == true)
            this.html(this.GetRandomImgListHtml());
        else
            this.html(this.GetRandomImgHTML());
    }
});*/
/* 修复IE6以下版本PNG图片Alpha */
/*function fixpng()
{
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])

  if ((version >= 5.5) && (document.body.filters))
  {
     for(var i=0; i<document.images.length; i++)
     {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
        {
           var imgID = (img.id) ? "id='" + img.id + "' " : ""
           var imgClass = (img.className) ? "class='" + img.className + "' " : ""
           var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
           var imgStyle = "display:inline-block;" + img.style.cssText
           if (img.align == "left") imgStyle = "float:left;" + imgStyle
           if (img.align == "right") imgStyle = "float:right;" + imgStyle
           if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
           var strNewHTML = "<span " + imgID + imgClass + imgTitle
           + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
           + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
           + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
           img.outerHTML = strNewHTML
           i = i-1
        }
     }
  }
}*/
