﻿var sLoading = "<img src='/images/loading.gif' />正在加载中...";

//分类联动
var cldobj = "";
var cid = "";

function getcategorylist(parentid,objcld,objName)
{
	if(parentid == null || parentid == "")
	{
		return;
	}
	else if(parentid == "0")
	{
		return;
	}
	else
	{
		if(objcld != null && objcld != "") cldobj = objcld;
		cid = parentid;
        //var show_type_id = "show_"+objcld;
        //alert(document.getElementById(show_type_id).innerHTML);
        //document.getElementById(show_type_id).innerHTML='<select name="'+objName+'" name="'+objcld+'" size="15"><option value="">正在读取数据....</option></select>';
		AjaxObject.GetCategoryList(parentid,categorydatabind);
	}
}

function categorydatabind(response)
{
	if (response.error != null)
	{
		return;
	}
	
	var obj = document.getElementById(cldobj);
	if (obj == null)
	{
		return;
	}
	var tb = response.value;
	if (tb == null || typeof(tb) != "object")
	{
		return;
	}
	
	var rowCount = tb.Rows.length;
	if(rowCount == 0)
	{
	    //obj.style.display = "none";
	    //alert(cid);;
	    //document.getElementById(objbrandID).style.display = "";
	}
	else
	{
	    //obj.style.display = "";
	    //document.getElementById('brand_add1_brandList').style.display = "none";
	}
	//alert(rowCount);
	obj.options.length = 0;
	if (rowCount>0)
	{
		obj.options[obj.options.length] = new Option("-请选择子类-", "");
		for (var i = 0; i < rowCount; i++)
		{
			obj.options[obj.options.length] = new Option(tb.Rows[i].Name, tb.Rows[i].ID);
			if(i == 0) {
			    //obj.options[1].selected = true;
			}
		}
	}	
}
//end

function openUrl(cid)
{
    if(cid == "")
    {
        alert('请选择产品子类！');
        return;
    }
    //alert(cid);
    window.location.href = "/dealerpage/promotion/" + cid + "__1_1_1/";
}

function openUrl2(cid)
{
    if(cid == "")
    {
        alert('请选择产品子类！');
        return;
    }
    
    //alert(cid);
    window.location.href = "/dealerpage/list/" + cid + "__1_1_1/";
}

function show_rank_tab(block_id,block_num,module_num){

	for(var i=1; i<=module_num; i++){
		if(i==block_num){
			document.getElementById("rank_"+block_id+"_"+i).className = 'act';
			document.getElementById("rank_detail_"+block_id+"_"+i).style.display = 'block';
		}else{
			document.getElementById("rank_"+block_id+"_"+i).className = '';
			document.getElementById("rank_detail_"+block_id+"_"+i).style.display = 'none';
		}
	}
	
}

var show_id;
function show_promotion_tab(id,block_num,index_num,idList){
	
	for(var i=1;i<=index_num;i++){
		if(i==block_num){
		    if(i == 1)
			    document.getElementById("new_promote_"+i).className = 'act1';
			else
			    document.getElementById("new_promote_"+i).className = 'act';
			    
			ShowDealerPromotion(id,idList);    
	        
	    /*
		}	
		else if(i==index_num){
			if( block_num == index_num){
				document.getElementById("new_promote_"+i).className='act';
			}else{
				document.getElementById("new_promote_"+i).className='last'; 
			}*/
		}else{
		    if(i == 1)
			    document.getElementById("new_promote_"+i).className = 'act0';	
			else
			    document.getElementById("new_promote_"+i).className = '';	
		}
	}
	show_id = "new_promote";
	
	/*
	var url = "./get_merchant_info_data_new.php?location_id="+location_id+"&type=3&timestamp=" + new Date().getTime();
	
	show_info(url);
	document.getElementById('city').style.display = 'none';
	if(area_name.length>0){
		document.getElementById('area_act_show').innerHTML =  area_name;
	}
	*/
}

//调整图片宽度和高度
//调用:<img onload="ResizeImage(this,80,80);" />
var imageObject;
function ResizeImage(obj, MaxW, MaxH)
{
    if (obj != null) imageObject = obj;
    var state=imageObject.readyState;
	if(state!='complete') {
        setTimeout("ResizeImage(null,"+MaxW+","+MaxH+")",50);
		return;
    }
    var oldImage = new Image();
    oldImage.src = imageObject.src;
    var dW=oldImage.width; var dH=oldImage.height;
    if(dW>MaxW || dH>MaxH) {
        a=dW/MaxW;
        if(MaxH>0){b=dH/MaxH;}else{b=1;}
        if(b>a) a=b;
        dW=dW/a; dH=dH/a;
        if(oldImage.width>MaxW && MaxH==0){imageObject.style.cursor="pointer",imageObject.alt="点击'+oldImage.width+'查看原图！",imageObject.onclick=function(){window.open(imageObject.src)}}
    }
    if(dW > 0 && dH > 0) {
        imageObject.width=dW;
		imageObject.height=dH;
	}
}

//经销商促销信息
function ShowDealerPromotion(id,idList)
{
    $("#promotionList").html(sLoading);
    AjaxObject.ShowDealerPromotion(id,idList,dealerPromotionCallBack);
}
function dealerPromotionCallBack(result)
{
    $("#promotionList").html(result.value);
}

function onSearch()
{
    var keyword;
    keyword = $('#header1_keyword').val();
    if(keyword == "")
    {
        alert('请输入搜索关键字！');
        $('#header1_keyword').focus();
        return;
    }
    keyword = encodeURI(keyword);

    var cid;
    cid = $('#header1_ddlCategoryID').val()
    if(typeof(cid) == "undefined")
        cid = "";
        
    if(cid == "")
    {
        alert('请选择商品子分类！');
        $('#header1_ddlCategoryID').focus();
        return;
    }
    
    var tp = 0, tpName = "";
    tp = $('#header1_search_type').val()
    if(tp == 2)
        tpName = "promotion";
    else
        tpName = "list";

    //alert("/search/" + keyword + "-" + cid + "-1" + "_" + tpName);
    window.location.href= "/dealerpage/" + tpName + "/" + cid + "__1_1_1/" + keyword;
}

/*首页会员登录*/
function fncDealerLogin()
{
    var record = false;
    var dealerName = $("#dealerName").val();
	var dealerPass = $("#dealerPass").val();
	
	if(dealerName == null || dealerName == "")
	{
	    alert('请输入登录名！');
	    $("#dealerName").focus();
	    return false;
	}
	
	if(dealerPass == null || dealerPass == "")
	{
	    alert('请输入密码！');
	    $("#dealerPass").focus();
	    return false;
	}
	
	var result = AjaxObject.CheckDealerLogin(dealerName,dealerPass,record).value;
    if(result)
        window.location.href='/dealer/manage/';
    else
    {
        alert('登陆失败！');
        $("#dealerName").focus();
    }
}