﻿function $() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);

        if (arguments.length == 1)
            return element;
        elements.push(element);
    }
    return elements;
}


function gotoApply(campaignid)
{
    window.location.href = "ConfirmAddress.aspx?campaignID=" + campaignid;
}

function onKeyPressForDouble(o,event)
{
    //alert("Ok");
    var keyChar = String.fromCharCode(event.keyCode);
    var value = o.value;
    var numstr = "0123456789.";
    if (numstr.indexOf(keyChar)>-1)
    {
        if ((keyChar == ".") && (value.indexOf(".")>-1))
        {
            event.keyCode=0;
        }
    }
    else
    {
        event.keyCode=0;
    }
    return true;
}

function onKeyPressForInt(o,event)
{
    //alert("Ok");
    var keyChar = String.fromCharCode(event.keyCode);
    var value = o.value;
    var numstr = "0123456789";
    if (numstr.indexOf(keyChar)>-1)
    {
        if (value.indexOf(".")>-1)
        {
            event.keyCode=0;
        }
    }
    else
    {
        event.keyCode=0;
    }
    return true;
}

function isnumber(o)
{
    if(isNaN(o.value))
    {
        alert("您输入的不是数字。");
        o.value = "";
        return false;
    }
    return true;
}

function OnOkClick()
{
    if($("hidselectedproduct").value == "")
    {
        alert("请您选择活动的礼品。");
        return false;
    }
    if($("productnum").value == "")
    {
        alert("请填写该礼品的数量。");
        $("productnum").focus();
        return false;
    }
    if($("productnum").value==0)
    {
        alert("礼品数量必须大于0。");
        $("productnum").select();
        return false;
    }
    if(!parseInt($("productnum").value))
    {
        alert("礼品数量必须是数字。");
        $("productnum").select();
        return false;
    }    
    var productinfo;
    var inhtml = "";
    if($("hidselectedproduct").value.indexOf(',') != -1)
    {
        productinfo = $("hidselectedproduct").value.split(',');
        inhtml = "<fieldset style='width:98%;padding:4px;'><legend>已经选择的礼品</legend><input type='hidden' id='award1' name='award1' value='" + productinfo[0] + "' />礼品名称：" + productinfo[1] + " &nbsp;&nbsp;设置数量：<input type='text' style='width:20px;' maxlength='3' id='awardnum1' name='awardnum1' onkeypress='return onKeyPressForInt(this,event)' onblur='return isnumber(this)' value='" + $("productnum").value + "' /></fieldset>";
        parent.$("ctl00_ContentPlaceHolder1_AwardNames").value = productinfo[1];
    }
    parent.$("AwardChoosedList").style.display = "block";
    parent.$("AwardChoosedList").innerHTML = inhtml;
    //parent.$("").value = $("hidselectedproduct").value;
    OnCancelClick();
    return true;
}


function OnBrankOkClick()
{
    var productinfo;
    var inhtml = "<fieldset style='width:98%;padding:4px;'><legend>已经选择的品牌</legend>";
    var brandName="";
    var brandID="";
    var getBrankList=$("hidselectedBrand").value.split('|');
    for(var i=0;i<getBrankList.length;i++)
    {
        if(getBrankList[i].indexOf(',') != -1)
        {
            productinfo =getBrankList[i].split(',');
            inhtml+=(i+1)+".<input type='hidden' id='hidBrandID' name='hidBrandID' value='" + productinfo[0] + "' />品牌名称：" + productinfo[1] + " &nbsp;&nbsp;<br>";
            brandName=brandName+productinfo[1]+",";
            brandID=brandID+productinfo[0]+",";
        }
    }
   
    inhtml+="</fieldset>";
    if(brandName.length>0)
    brandName=brandName.substring(0,brandName.length-1);
    
      if(brandID.length>0)
    brandID=brandID.substring(0,brandID.length-1);
      
    parent.$("ctl00_ContentPlaceHolder1_txtBrandName").value =brandName;
    parent.$("ctl00_ContentPlaceHolder1_hidBrandID").value =brandID;
        
    parent.$("BrandChoosedList").style.display = "block";
    parent.$("BrandChoosedList").innerHTML = inhtml;
    
    OnCancelClick();
    return true;
}

function OnBrankLoadData()
{
    if($("ctl00_ContentPlaceHolder1_txtBrandName").value=="")return;
    var productinfo;
    var inhtml = "<fieldset style='width:98%;padding:4px;'><legend>已经选择的品牌</legend>";
 
    var getBrankList=$("ctl00_ContentPlaceHolder1_txtBrandName").value.split(',');
    for(var i=0;i<getBrankList.length;i++)
    {
            inhtml+=(i+1)+".品牌名称：" + getBrankList[i] + " &nbsp;&nbsp;<br>";
    }
    inhtml+="</fieldset>";
     
    $("BrandChoosedList").style.display = "block";
    $("BrandChoosedList").innerHTML = inhtml;

    return true;
}
    function OnProductLoadData()
{
    if($("ctl00_ContentPlaceHolder1_txtProductName").value=="")return;
    
    var inhtml = "<fieldset style='width:98%;padding:4px;'><legend>已经选择的商品</legend>";
 
    var getBrankList=$("ctl00_ContentPlaceHolder1_txtProductName").value.split(',');
    for(var i=0;i<getBrankList.length;i++)
    {
            inhtml+=(i+1)+".商品名称：" + getBrankList[i] + " &nbsp;&nbsp;<br>";
    }
    inhtml+="</fieldset>";
     
    $("ProductChoosedList").style.display = "block";
    $("ProductChoosedList").innerHTML = inhtml;

    return true;
}
function ShowOnBrankLoadData()
{
    if($("ctl00_ContentPlaceHolder1_txtBrandName").value=="")return;
    var productinfo;
    var inhtml = "<fieldset style='width:98%;padding:4px;'><legend>已经选择的品牌</legend>";
 
    var getBrankList=$("ctl00_ContentPlaceHolder1_txtBrandName").value.split(',');
    for(var i=0;i<getBrankList.length;i++)
    {
            inhtml+=(i+1)+".品牌名称：" + getBrankList[i] + " &nbsp;&nbsp;<br>";
    }
    inhtml+="</fieldset>";
     
    $("BrandChoosedList").style.display = "block";
    $("BrandChoosedList").innerHTML = inhtml;

    return true;
}
    function ShowOnProductLoadData()
{
    if($("ctl00_ContentPlaceHolder1_txtProductName").value=="")return;
    
    var inhtml = "<fieldset style='width:98%;padding:4px;'><legend>已经选择的商品</legend>";
 
    var getBrankList=$("ctl00_ContentPlaceHolder1_txtProductName").value.split(',');
    for(var i=0;i<getBrankList.length;i++)
    {
            inhtml+=(i+1)+".商品名称：" + getBrankList[i] + " &nbsp;&nbsp;<br>";
    }
    inhtml+="</fieldset>";
     
    $("ProductChoosedList").style.display = "block";
    $("ProductChoosedList").innerHTML = inhtml;

    return true;
}

function OnProductOkClick()
{
    var productinfo;
     var inhtml = "<fieldset style='width:98%;padding:4px;'><legend>已经选择的商品</legend>";
    var productname="";
    var productid="";
    var getproductList=$("hidselectedproduct").value.split('|');
        for(var i=0;i<getproductList.length;i++)
    {
        if(getproductList[i].indexOf(',') != -1)
        {
            productinfo =getproductList[i].split(',');
            inhtml+=(i+1)+".商品名称：" + productinfo[1] + " &nbsp;&nbsp;<br>";
            productname=productname+productinfo[1]+",";
            productid=productid+productinfo[0]+",";
        }
    }
        inhtml+="</fieldset>";
    
     if(productname.length>0)
    productname=productname.substring(0,productname.length-1);
      if(productid.length>0)
    productid=productid.substring(0,productid.length-1);
    parent.$("ctl00_ContentPlaceHolder1_txtProductName").value =productname;
    parent.$("ctl00_ContentPlaceHolder1_hidPoductListID").value =productid;
    parent.$("ProductChoosedList").style.display = "block";
    parent.$("ProductChoosedList").innerHTML = inhtml;
    
    
    OnCancelClick();
    return true;
}


function OnOkClickCampaign()
{
    
    var productinfo;

    if($("hidselectedproduct").value.indexOf(',') != -1)
    {
        productinfo = $("hidselectedproduct").value.split(',');
        //inhtml = "<fieldset style='width:98%;padding:4px;'><legend>已经选择的礼品</legend><input type='hidden' id='award1' name='award1' value='" + productinfo[0] + "' />礼品名称：" + productinfo[1] + " &nbsp;&nbsp;设置数量：<input type='text' style='width:20px;' maxlength='3' id='awardnum1' name='awardnum1' onkeypress='return onKeyPressForInt(this,event)' onblur='return isnumber(this)' value='" + $("productnum").value + "' /></fieldset>";
        parent.$("ctl00_ContentPlaceHolder1_txtF_CampaignID").value = productinfo[0];
        parent.$("ctl00_ContentPlaceHolder1_txtF_CampaignTitle").value = productinfo[1];
    }
    //parent.$("AwardChoosedList").style.display = "block";
    //parent.$("AwardChoosedList").innerHTML = inhtml;
    //parent.$("").value = $("hidselectedproduct").value;
    OnCancelClick();
    return true;
}

function ChooseBrand()
{
	g_bgmusic_pop=new Popup({ contentType:1, isReloadOnClose:false, width:680, height:610 });
	g_bgmusic_pop.setContent("title","选择品牌");
	g_bgmusic_pop.setContent("contentUrl","/admin/T_LuckyGuessBrand/ChooseBrand.aspx");
	g_bgmusic_pop.build();
	g_bgmusic_pop.show();
	return false;
}
function g_close_bgmusic_pop(){g_bgmusic_pop.close();}
function ChooseProduct()
{
     var listID = $("ctl00_ContentPlaceHolder1_hidBrandID").value;
     var ischeck=$("ctl00_ContentPlaceHolder1_chkF_IsRelationshipBrandProduct");
      
     if( ischeck.checked==false)
     {
         listID=""
     }
	g_bgmusic_pop=new Popup({ contentType:1, isReloadOnClose:false, width:680, height:610 });
	g_bgmusic_pop.setContent("title","选择产品");
	g_bgmusic_pop.setContent("contentUrl","/admin/T_LuckyGuessProduct/ChooseProduct.aspx?listid="+listID);
	g_bgmusic_pop.build();
	g_bgmusic_pop.show();
	return false;
}

function ChooseBrandIssue()
{
	g_bgmusic_pop=new Popup({ contentType:1, isReloadOnClose:false, width:680, height:610 });
	g_bgmusic_pop.setContent("title","选择品牌");
	g_bgmusic_pop.setContent("contentUrl","/admin/T_SubjectIssue/ChooseBrand.aspx");
	g_bgmusic_pop.build();
	g_bgmusic_pop.show();
	return false;
}
 
function ChooseProductIssue()
{   
     var listID = $("ctl00_ContentPlaceHolder1_hidBrandID").value;

	g_bgmusic_pop=new Popup({ contentType:1, isReloadOnClose:false, width:680, height:610 });
	g_bgmusic_pop.setContent("title","选择产品");
	g_bgmusic_pop.setContent("contentUrl","/admin/T_SubjectIssue/ChooseProduct.aspx?listid="+listID);
	g_bgmusic_pop.build();
	g_bgmusic_pop.show();
	return false;
}

function getAwardNum()
{    var inhtml = "";
    var awardinfo = $("ctl00_ContentPlaceHolder1_hidawards").value.split(',');
    if($("ctl00_ContentPlaceHolder1_hidawards").value != "")
    {
        inhtml = "<fieldset style='width:98%;padding:4px;'><legend>已经选择的礼品</legend><input type='hidden' id='award1' name='award1' value='" + awardinfo[0] + "' />礼品名称：" + awardinfo[1] + " &nbsp;&nbsp;设置数量：<input type='text' style='width:20px;' maxlength='3' id='awardnum1' name='awardnum1' onkeypress='return onKeyPressForInt(this,event)'  onblur='return isnumber(this)' value='" + awardinfo[2] + "' /></fieldset>";
    }
    $("AwardChoosedList").innerHTML = inhtml;
}


function editAward(url)
{
	g_bgmusic_pop=new Popup({ contentType:1, isReloadOnClose:false, width:680, height:410 });
	g_bgmusic_pop.setContent("title","选择礼品");
	g_bgmusic_pop.setContent("contentUrl","ChooseAward.aspx");
	g_bgmusic_pop.build();
	g_bgmusic_pop.show();
	return false;
}

function ChooseCampaign(url)
{
	g_bgmusic_pop=new Popup({ contentType:1, isReloadOnClose:false, width:680, height:410 });
	g_bgmusic_pop.setContent("title","选择活动");
	g_bgmusic_pop.setContent("contentUrl","ChooseCampaign.aspx");
	g_bgmusic_pop.build();
	g_bgmusic_pop.show();
	return false;
}

function SetPrize(url)
{
	g_bgmusic_pop=new Popup({ contentType:1, isReloadOnClose:false, width:800, height:700 });
	g_bgmusic_pop.setContent("title","设置中奖会员");
	g_bgmusic_pop.setContent("contentUrl",url);
	g_bgmusic_pop.build();
	g_bgmusic_pop.show();
	return false;
}

function ViewComment(url)
{
	g_bgmusic_pop=new Popup({ contentType:1, isReloadOnClose:false, width:680, height:405 });
	g_bgmusic_pop.setContent("title","查看评论");
	g_bgmusic_pop.setContent("contentUrl",url);
	g_bgmusic_pop.build();
	g_bgmusic_pop.show();
	return false;
}

function ViewApply(url,status)
{
	g_bgmusic_pop=new Popup({ contentType:1, isReloadOnClose:false, width:400, height:500 });
	g_bgmusic_pop.setContent("title","查看"+ status +"名单");
	g_bgmusic_pop.setContent("contentUrl",url);
	g_bgmusic_pop.build();
	g_bgmusic_pop.show();
	return false;
}

function enabledsmallpic()
{    
    if(document.getElementById("ctl00_ContentPlaceHolder1_ChbautobuildSmallPic").checked == true)
    {
        $("ctl00_ContentPlaceHolder1_txtF_ProductSmallPic").disabled = "False";
        $("ctl00_ContentPlaceHolder1_filePicture").disabled = "False";
        $("previewImage2").style.display = "none";
        $("ctl00_ContentPlaceHolder1_filePicture").value = "";
        $("ctl00_ContentPlaceHolder1_txtF_ProductSmallPic").value = "";
    }
    else
    {
        document.getElementById("ctl00_ContentPlaceHolder1_txtF_ProductSmallPic").disabled = "";
        document.getElementById("ctl00_ContentPlaceHolder1_filePicture").disabled = "";
    }
}

function CheckTimeCompareWithNow(inputid, condition)
{
    var inputTime = $(inputid);
    var strDateArrayStart = inputTime.value.split('-');
    var strDateS = new Date(strDateArrayStart[0] + "/" + strDateArrayStart[1] + "/" + strDateArrayStart[2]);
    var nowDateS = new Date();
    var nowDate = new Date(nowDateS.getFullYear() + "/" + (nowDateS.getMonth() + 1) + "/" + nowDateS.getDate());
    if(condition == "bigger")
    {
        if(strDateS < nowDate)
        {
            alert("输入的日期不能小于今天。");
            $(inputid).value = "";
            return false;
        }
    }
    else
    {
        if(!(strDateS > nowDate))
        {
            alert("输入的日期不能大于今天。");
            $(inputid).value = "";
            return false;
        }
    }
    return true;
}

/// <summary>
/// 日期比较
/// </summary>
/// <param name="inputid">输入的控件ID</param>
/// <param name="inputText">输入控件提示文字</param>
/// <param name="Campareid">比较大控件ID</param>
/// <param name="CampareText">比较控件提示文字</param>
/// <param name="condition">条件：bigger或者smaller</param>
/// <returns></returns>
function CheckTimeCampareWithOther(inputid, inputText, Campareid, CampareText, condition)
{
    var inputTime = $(inputid);
    var strDateArrayinput = inputTime.value.split('-');
    var strDateS = new Date(strDateArrayinput[0] + "/" + strDateArrayinput[1] + "/" + strDateArrayinput[2]);
    var CampareTime = $(Campareid);
    if(CampareTime.value == "")
    {
        alert("请选择" + CampareText);
        $(inputid).value = "";
        return false;
    }
    var strDateArrayCampare = CampareTime.value.split('-');
    var strDateC = new Date(strDateArrayCampare[0] + "/" + strDateArrayCampare[1] + "/" + strDateArrayCampare[2]);
    if(condition == "bigger")
    {
        if(strDateS < strDateC)
        {
            alert(inputText + "不能小于" + CampareText + "。");
            $(inputid).value = "";
            return false;
        }
    }
    else
    {
        if(!(strDateS > strDateC))
        {
            alert(inputText + "不能大于" + CampareText + "。");
            $(inputid).value = "";
            return false;
        }
    }
    return true;
}

function VDateTime()
{
    var inputTime = $("ctl00_ContentPlaceHolder1_txtF_CampaignBeginTime");
    var strDateArrayinput = inputTime.value.split('-');
    var strDateS = new Date(strDateArrayinput[0] + "/" + strDateArrayinput[1] + "/" + strDateArrayinput[2]);
    var CampareTime = $("ctl00_ContentPlaceHolder1_txtF_CampaignEndTime");
    var strDateArrayCampare = CampareTime.value.split('-');
    var strDateC = new Date(strDateArrayCampare[0] + "/" + strDateArrayCampare[1] + "/" + strDateArrayCampare[2]);
    if($("ctl00_ContentPlaceHolder1_txtF_CampaignEndTime").value != "")
    {
        //if campaign end time is not null
        //then compare there values
        if(strDateS > strDateC)
        {
            alert("开始时间不能大于结束时间。");
            inputTime.value = "";
            return false;
        }
    }
    if($("ctl00_ContentPlaceHolder1_txtF_ShippingEndTime").value != "")
    {
        //if campaign shipping end time is not null
        //then compare there values
        CampareTime = $("ctl00_ContentPlaceHolder1_txtF_ShippingEndTime");
        strDateArrayCampare = CampareTime.value.split('-');
        strDateC = new Date(strDateArrayCampare[0] + "/" + strDateArrayCampare[1] + "/" + strDateArrayCampare[2]);
        if(strDateS > strDateC)
        {
            alert("开始时间不能大于运输结束时间。");
            inputTime.value = "";
            return false;
        }
    }
    return CheckTimeCompareWithNow("ctl00_ContentPlaceHolder1_txtF_CampaignBeginTime", 'bigger');
}

/***********************活动多地区选择*****************************/
function setvalue(val, targetFix, containers, d)
{
    var l = val;
    if(l.length>0)
    {
        var p = l.length/5;
        for(var i=1;i<=p;i++)
        {
            var targetid = targetFix + i;
            if(d == "" || d == undefined)
            {
                $("v").value = l.substring(0,i*5);
            }
            else
            {
                //alert($("hid" + d).value);
                $("hid" + d).value = l.substring(0,i*5);
            }
            $(targetid).value = l.substring(0,i*5);
            LoadData(targetid, $(targetid).options[$(targetid).selectedIndex].value, $(targetid).value, containers);
        }
    }
}
function addArea()
{
    var now=new Date();
    var number = now.getSeconds(); 
    var newDiv=document.createElement("div");
    newDiv.style.padding = "2px";
    var DivInnerHTML = $("ctl00_ContentPlaceHolder1_Panel1").innerHTML;
    DivInnerHTML = DivInnerHTML.substr(0, DivInnerHTML.indexOf("<A title") - 7);
    var arraySelect = $("ctl00_ContentPlaceHolder1_Panel1").getElementsByTagName("select");
    var DivCount = "" + now.getHours() + now.getSeconds() + now.getMilliseconds();
    newDiv.id = "div" + DivCount;
    $("ctl00_ContentPlaceHolder1_UpdatePanel1").appendChild(newDiv);
    for(var i=0;i<arraySelect.length;i++)
    {
        var newSelect = document.createElement("select");
        newSelect.id = "s_" + DivCount + "_s" + (i + 1);        
        var options = arraySelect[i].getElementsByTagName("option");
        newSelect.style.width = "120px";
        newSelect.setAttribute("d", (i+1));
        if(i < arraySelect.length - 1)
            newSelect.setAttribute("c","s_" + DivCount + "_s" + (i + 2));
        $("div" + DivCount).appendChild(newSelect);
        $("div" + DivCount).innerHTML += "&nbsp;";
    }
    $("div" + DivCount).innerHTML += "[<a href='javascript:;' onclick='removeArea(\"" + DivCount + "\")'> - </a>]";
    var hidv = document.createElement("input");
    hidv.id = "hid" + DivCount;
    hidv.name = "v";
    hidv.type = "hidden";
    $("div" + DivCount).appendChild(hidv);
    Init("s_" + DivCount, "div" + DivCount);
    return DivCount;
}

function removeArea(id)
{
    id = "div" + id;
    var p = $(id).parentNode;
    p.removeChild($(id));
}

function buildAndfillSelectdArea()
{
    var hidareavalue = $("ctl00_ContentPlaceHolder1_hidv").value;
    if(hidareavalue.indexOf(",") != -1)
    {
        $("v").value = hidareavalue.substr(0, hidareavalue.indexOf(","));
        setvalue($("v").value, "ctl00_ContentPlaceHolder1_s", "ctl00_ContentPlaceHolder1_Panel1", "");
        hidareavalue = hidareavalue.substr(hidareavalue.indexOf(",") + 1, hidareavalue.length - hidareavalue.indexOf(","));
        arrayhidArea = hidareavalue.split(",");
        for(var i=0;i<arrayhidArea.length;i++)
        {
            var d = addArea();
            setvalue(arrayhidArea[i], "s_" + d + "_s", "div" + d, d);
        }
    }
    else
    {
        $("v").value = hidareavalue;
        setvalue($("v").value, "ctl00_ContentPlaceHolder1_s", "ctl00_ContentPlaceHolder1_Panel1", "");
    }
}
/******************************************************************/

function trim(str)
{  //删除左右两端的空格
    return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ltrim(str)
{  //删除左边的空格
    return str.replace(/(^\s*)/g,"");
}
function rtrim(str)
{  //删除右边的空格
    return str.replace(/(\s*$)/g,"");
}
 
//注销用户登录
function JS_CustomerLogout()
{
    
	document.getElementById("Hid_IsLogout").value = "1";
	//JS_ClearHidden("Hid_IsLogout");
	 
	document.forms[0].submit();
}

//去登录页面
//targetPage:登录成功后跳转的页面


//去登录页面
//targetPage:登录成功后跳转的页面
function JS_GoLogin(targetPage,dirPage)
{

	if(dirPage!=undefined)
	location.href =dirPage;
	else 
	location.href ="login.aspx";
	return true;
}