﻿
//已经选择的产品数量
var sel_numMerchant = 0;

//最多能选择的产品数
var max_sel_numMerchant = 5;

//已经选择的产品名
var selMerchant = new Array();
var proNameMerchant = new Array();
var MCUserID=new Array();

var MCUserIDType=0;

//吴加 选择产品，当state为true时，添加产品，为false时，删除商家
function updatecheckMerchant(valueMerchant, MerchantName,intMCUserID,stateMerchant)
{
    if (stateMerchant)
    {
    addMerchant(valueMerchant,MerchantName,intMCUserID);
    }
    else
    {
    delMerchant(valueMerchant);
    }
}

//选择产品比较, value:所选择的产品ID
function addMerchant(valueMerchant, MerchantName,intMCUserID)
{
    for(i = 0; i < sel_numMerchant; i++)
    {
        if(selMerchant[i] == valueMerchant)
        {
//          alert(value + " 已选择！");
            alert(MerchantName + " 已选择！");
            break;
        }
    }

    if(i == sel_numMerchant)
    {
        if(sel_numMerchant >= max_sel_numMerchant)
        {
            
           alert("最多只能有" + max_sel_numMerchant + "款参加比较！");
           delChkboxMerchant(valueMerchant);
        }

        else
        {
            selMerchant[sel_numMerchant] = valueMerchant;
            proNameMerchant[sel_numMerchant] = MerchantName;
            MCUserID[sel_numMerchant]=intMCUserID;
            sel_numMerchant++;
            drawMerchant();
        }
    }
}

/* 去掉打过的勾 */
function delChkboxMerchant(valueMerchant)
{
    i = 0;
    for(i = 0; i < document.formMerchant.compareMerchant.length; i++)
    {
        if(valueMerchant == document.formMerchant.compareMerchant[i].value)
        {
            document.formMerchant.compareMerchant[i].checked = false;
            break;
        }
    }
}
//从已选的产品列表中去掉某产品, value:所选择的产品ID
function delMerchant(valueMerchant)
{
	delChkboxMerchant(valueMerchant);

    i = 0;
    while(selMerchant[i] != valueMerchant)
        i++;

    for(j = i; j < sel_numMerchant; j++) {
        selMerchant[j] = selMerchant[j + 1];
        proNameMerchant[j] = proNameMerchant[j + 1];
    }

    sel_numMerchant--;
    drawMerchant();
}

//显示已选的商家的列表
function drawMerchant()
{
//    outMerchant = '';
//    for(i = 0; i < sel_numMerchant; i++)
//    {
//         outMerchant += "<font color=red size=1><b>|</b></font><br>" +
//            " <input type=button  " +
//            " name = 'btn" + i + "'" +
//            " value='" + proNameMerchant[i] + "' " +
//            " style='border:1px solid;border-color:red ;" +
//            " background-color:white;height:24;width:160;' " +
//            " onclick='delMerchant(" + selMerchant[i] + ")';cursor:hand;color:'black';><br>" ;
//    }

//    setInnerHTML(document.getElementById('com_itemMerchant'), outMerchant);
//以上是为了去掉ajax效果而去掉的

    //set_innerHTML('parent.com_item', out);
    //parent.com_item.innerHTML = out;
    document.formMerchant.hidSelMerchantNum.value = sel_numMerchant;
}

//比较已选的商家
function compareClickMerchant(intCategorySectionID)
{
    if(sel_numMerchant < 2)
    {
	    alert("请至少选择两项！");
	    return;
    }
    if(sel_numMerchant > 6)
    {
	    alert("最多选择7项！");
	    return;
    }

    var selMerchantInfo = "";   //所选择的商家ID
    var selMerchantName = "";   //所选择的商家名称

    for(i = 0; i < sel_numMerchant; i++)
    {
	    selMerchantInfo += selMerchant[i] + ".";
	    selMerchantName += proNameMerchant[i] + ".";
    }

    //需要比较的产品, 1表示参加比较, 0不参加, 默认前5个
    var bcomFlagMerchant = "";
    var j = sel_numMerchant > 3?3:sel_numMerchant;
    for(i = 0; i < j; i++)
    {
	    bcomFlagMerchant +=  "1,";
    }
    for(i = j; i < sel_numMerchant; i++)
    {
	    bcomFlagMerchant +=  "0,";
    }
  
    
    var url="/Merchant/MerchantCompare.aspx?CmpID="+selMerchantInfo+"&CategorySectionID="+intCategorySectionID;
    window.open(url);  
}