﻿var partID="ctl00_ContentPlaceHolder1_";
function genEmbed1()
{
    setValue("txtEmbed1",getGenEmbed(928,320));
}
function getEmbed2()
{
    setValue("txtEmbed2",getGenEmbed(getValue("TheWidthEmbed"),getValue("TheHeightEmbed")));
}
function getGenEmbed(width,height)
{
    return "<iframe height='"+height+"' width='"+width+"' scrolling='no' frameborder='0'  src='"+location.href+"/embed/"+height+"/"+width+"'></iframe>";
}
function changeCustomerEmbed()
{
    if(containsCss("func_customize","hide"))
    {
        addCss("func_down","hide");
        removeCss("func_customize","hide");
    }
    else
    {
        addCss("func_customize","hide");
        removeCss("func_down","hide");
    }
}
function changeAddTimelineToList()
{
    if(containsCss("divAddTimelineToList","hide"))
        removeCss("divAddTimelineToList","hide");
    else
        addCss("divAddTimelineToList","hide");
}
function addTimelineToList(timelineID)
{
    var timelineListID=getValue(partID+"dropLists");
    if(timelineListID=="")
    {
        alert("please select a list");
        return;
    }
    if(timelineListID=="__Create")
    {
        return;
    }
    getAjaxContent("../ajax/timelinelist.aspx?act=addtolist&timelineid="+timelineID+"&timelinelistid="+timelineListID,function(result){
        if(result=="Completed")
        {
            alert("Timeline added");
            changeAddTimelineToList();
        }
        else
            alert("this list has contains this timeline");
    },null);
}
function onDropTimelinListChange(me)
{
    if(me.selectedIndex==1)
    {
        getObj(partID+"dropLists").disabled="disabled";
        getAjaxContent("../ajax/timelinelist.aspx?act=quickcreate",onDropTimelinListChange_Callback,null);
    }
}
function onDropTimelinListChange_Callback(result)
{
    getObj(partID+"dropLists").disabled="";
    var t=result.indexOf("|");
    if(t==-1)
    {
        alert("this list has contains this timeline");
        return;
    }
    var timelineListID=result.substring(0,t);
    var text=result.substring(t+1,result.length);
    setValue(partID+"dropLists",text+"$"+timelineListID);
    var ctrl = getObj(partID+"dropLists");
    ctrl.selectedIndex=ctrl.options.length-1;
}

var oldW = "928";
var oldH = "390";
function changeEmbedSize(size,sizeType,txtEmbedId)
{
    var newEmbedCode = "";
    var embedCode = getValue(txtEmbedId);
    if(isNumber(size))
    {
        var _tmpSize = parseInt(size);
        if(sizeType == "width")//宽度
        {
            if(_tmpSize < 300 || _tmpSize > 930)
            {
                alert("range of width is: 300 ~ 930");
                return;
            }
            newEmbedCode = embedCode.replace(oldW,size).replace(oldW,size);
            oldW = size;
        }
        else
        { 
            if(_tmpSize < 300 || _tmpSize > 450)
            {
                alert("range of height is: 300 ~ 450");
                return;
            }
            newEmbedCode = embedCode.replace(oldH,size).replace(oldH,size);
            oldH = size;
        }
        setValue(txtEmbedId,newEmbedCode);
    }
}
function copyEmbedCode(embedCode)
{
    window.clipboardData.setData('text',embedCode);
}

function viewTimeline(timelineId)
{
    getAjaxContent("../ajax/timeline.aspx?act=view&id=" + timelineId);
}