var toolwidth=360;
function Tool(){
if($("tool").style.display=="block"){
$("tool").style.display="none";
$("controltool").innerHTML="显示工具箱";
}
else{
$("tool").style.display="block";
$("controltool").innerHTML="隐藏工具箱";
}
ResetSize();
}

function ResetSize(){
document.body.style.overflow = eval((document.documentElement.offsetWidth) ? "document.documentElement" : "document.body").style.overflow = "hidden";
var w = window.innerWidth || self.innerWidth || (document.documentElement &&document.documentElement.clientWidth && document.documentElement.offsetWidth) || document.body.clientWidth;
if(System.ie){w=w-4;}
var h = window.innerHeight  || document.documentElement.clientHeight;
$("main").style.height=h-130+"px";
$("content").style.height=h-155+"px";
if($("code")){
$("code").style.height=h-155+"px";
}

if($("tool").style.display=="block"){
if($("accordion")){
if(System.ie){
$("accordion").style.height=h-149+"px";
}
else{
$("accordion").style.height=h-150+"px";
}
$("content").style.width=w-toolwidth-23+"px";
if($("code")){
$("code").style.width=w-toolwidth-23+"px";
}
}
}
else{
$("content").style.width=w-23+"px";
if($("code")){
$("code").style.width=w-23+"px";
}
}
}

function ClickBody(){
if($("accordiontop").className=="accordion-top2"){
$("accordiontop").className="accordion-top";
}
}

function Save(){
AjaxRequest("index.htm","",ToSave,null);
}

function ToSave(){
if($("code")){
ShowDesign();
$("code").value="";
}
var res=document.createElement("div");
res.id="res";
res.style.cssText="display:none;";
res.innerHTML="<iframe name=\"res\" style=\"display:none;\" src=\"\"></iframe>";
document.body.appendChild(res);
document.client.target="res";
Trading();
Action("save&isiframe=1");
}

function SaveEnd(r){
if(r.substring(0,1)==' '){
ShowMessage(r);
}
else{
ShowMessage("");
ShowMessageDialog("提示",r);
}
$("res").parentNode.removeChild($("res"));
EndTrading();
}

function EditAttributes(){
var content="<div style=\"width:100%;height:100%;overflow:auto;\"><table id=\"editattributes\" class='attribtes'><tr><th><button type=\"button\" onclick=\"ListAdd()\">新建属性</button></th><th width=\"45px\">必填</th><th width=\"130px\">数据类型</th><th width=\"155px\">属性名</th><th width=\"155px\">默认值</th><th width=\"155px\">属性提示</th></tr>";
var attributeName=$N("BSDevelopAttributeName");
var attributeType=$N("BSDevelopAttributeType");
var attributeTitle=$N("BSDevelopAttributeTitle");
var attributeDefaultValue=$N("BSDevelopAttributeDefaultValue");
var attributeIsRequired=$N("BSDevelopAttributeIsRequired");
for(var i=0;i<=attributeName.length-1;i++){
content+="<tr><td><button type=\"button\" onclick=\"ListRemove(this)\">移除属性</button></td><td>";
if(attributeIsRequired[i].value=="1"){
content+="<select name=\"AIsRequired\" style=\"width:45px;\"><option value=\"1\" selected>是</option><option value=\"0\">否</option></select>";
}
else{
content+="<select name=\"AIsRequired\" style=\"width:45px;\"><option value=\"1\">是</option><option value=\"0\" selected>否</option></select>";
}
content+="</td><td><select name=\"AType\" style=\"width:130px;\">";
if(attributeType[i].value=="object"){
content+="<option value='object' selected>object</option>";
}
else{
content+="<option value='object'>object</option>";
}
if(attributeType[i].value=="string"){
content+="<option value='string' selected>string</option>";
}
else{
content+="<option value='string'>string</option>";
}
if(attributeType[i].value=="int"){
content+="<option value='int' selected>int</option>";
}
else{
content+="<option value='int'>int</option>";
}
if(attributeType[i].value=="double"){
content+="<option value='double' selected>double</option>";
}
else{
content+="<option value='double'>double</option>";
}
if(attributeType[i].value=="HaiLi.DateTime"){
content+="<option value='HaiLi.DateTime' selected>HaiLi.DateTime</option>";
}
else{
content+="<option value='HaiLi.DateTime'>HaiLi.DateTime</option>";
}
if(attributeType[i].value=="bool"){
content+="<option value='bool' selected>bool</option>";
}
else{
content+="<option value='bool'>bool</option>";
}
content+="</select></td><td><input name=\"AName\" onKeyDown=\"FileNameKeyDown(event);\" value=\""+attributeName[i].value+"\" style=\"width:150px;\"/></td><td><input name=\"ADefaultValue\" value=\""+attributeDefaultValue[i].value+"\" style=\"width:150px;\"/></td><td><input name=\"ATitle\" value=\""+attributeTitle[i].value+"\"  style=\"width:150px;\"/></td></tr>";
}
content+="<tr id='last'><td align=\"right\" colspan=\"6\"><button type=\"button\" id=\"yes\" onclick=\"ListAddOK();\">确定</button><button type=\"button\" onclick=\"EasyMask.close();\">取消</button></td></tr></table></div>";
EasyMask.init({ width:800, height: 500, title: '编辑控件属性', detail: content });
}

function ListAdd(){
var temp=document.createElement("tr");
var td=document.createElement("td"); 
td.innerHTML="<button type=\"button\" onclick=\"ListRemove(this)\">移除属性</button>";
temp.appendChild(td);
td=document.createElement("td"); 
td.innerHTML="<select name=\"AIsRequired\" style=\"width:45px;\"><option value=\"1\">是</option><option value=\"0\">否</option></select>";
temp.appendChild(td);
td=document.createElement("td"); 
td.innerHTML="<select name=\"AType\" style=\"width:130px;\"><option value='object'>object</option><option value='string'>string</option><option value='int'>int</option><option value='double'>double</option><option value='HaiLi.DateTime'>HaiLi.DateTime</option><option value='bool'>bool</option></select>";
temp.appendChild(td);
td=document.createElement("td"); 
td.innerHTML="<input name=\"AName\" onKeyDown=\"FileNameKeyDown(event);\" style=\"width:145px;\"/>";
temp.appendChild(td);
td=document.createElement("td"); 
td.innerHTML="<input name=\"ADefaultValue\" style=\"width:145px;\"/>";
temp.appendChild(td);
td=document.createElement("td"); 
td.innerHTML="<input name=\"ATitle\" style=\"width:145px;\"/></td>";
temp.appendChild(td);
$("editattributes").childNodes[0].insertBefore(temp,$("editattributes").childNodes[0].childNodes[$("editattributes").childNodes[0].childNodes.length-1]);
}

function ListRemove(obj){
obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
}

function ListAddOK(){
var aName=$N("AName");
var aType=$N("AType");
var aTitle=$N("ATitle");
var aDefaultValue=$N("ADefaultValue");
var aIsRequired=$N("AIsRequired");
for(var i=0;i<=aName.length-1;i++){
if(aName[i].value.trim()==""){
ShowMessageDialog("提示","属性名不能为空");
return;
}
if(aTitle[i].value.trim()==""){
ShowMessageDialog("提示","属性提示不能为空");
return;
}
}
var attributes="";
var attributeName=$N("BSDevelopAttributeName");
var attributeType=$N("BSDevelopAttributeType");
var attributeTitle=$N("BSDevelopAttributeTitle");
var attributeDefaultValue=$N("BSDevelopAttributeDefaultValue");
var attributeIsRequired=$N("BSDevelopAttributeIsRequired");
while(attributeName.length>0){
attributeName[0].parentNode.removeChild(attributeName[0]);
attributeType[0].parentNode.removeChild(attributeType[0]);
attributeTitle[0].parentNode.removeChild(attributeTitle[0]);
attributeDefaultValue[0].parentNode.removeChild(attributeDefaultValue[0]);
attributeIsRequired[0].parentNode.removeChild(attributeIsRequired[0]);
attributeName=$N("BSDevelopAttributeName");
attributeType=$N("BSDevelopAttributeType");
attributeTitle=$N("BSDevelopAttributeTitle");
attributeDefaultValue=$N("BSDevelopAttributeDefaultValue");
attributeIsRequired=$N("BSDevelopAttributeIsRequired");
}
for(var i=0;i<=aName.length-1;i++){
var temp=document.createElement("input");
temp.setAttribute("type","hidden");  
temp.setAttribute("name","BSDevelopAttributeName");  
temp.setAttribute("value",aName[i].value);   
document.client.appendChild(temp);
temp=document.createElement("input");
temp.setAttribute("type","hidden");  
temp.setAttribute("name","BSDevelopAttributeIsRequired");  
temp.setAttribute("value",aIsRequired[i].value);   
document.client.appendChild(temp);
temp=document.createElement("input");
temp.setAttribute("type","hidden");  
temp.setAttribute("name","BSDevelopAttributeType");  
temp.setAttribute("value",aType[i].value);   
document.client.appendChild(temp);
temp=document.createElement("input");
temp.setAttribute("type","hidden");  
temp.setAttribute("name","BSDevelopAttributeDefaultValue");  
temp.setAttribute("value",aDefaultValue[i].value);   
document.client.appendChild(temp);
temp=document.createElement("input");
temp.setAttribute("type","hidden");  
temp.setAttribute("name","BSDevelopAttributeTitle");  
temp.setAttribute("value",aTitle[i].value);   
document.client.appendChild(temp);
}
EasyMask.close();
$("panel-2").innerHTML=GetBweAttributes();
}

function Preview(){
var attributeIsRequired=$N("BSDevelopAttributeIsRequired");
var attributeType=$N("BSDevelopAttributeType");
var attributeName=$N("BSDevelopAttributeName");
var attributeDefaultValue=$N("BSDevelopAttributeDefaultValue");
var attributeTitle=$N("BSDevelopAttributeTitle");
if(document.client.BSDevelopExtension.value==".esc"&&attributeName.length>0){
var content="<table class='attribtes'><tr><th width='120'>数据类型&nbsp;</th><th width='120'>属性名&nbsp;</th><th width='285'>属性值</th><th>&nbsp;提示</th></tr>";
for(var i=0;i<=attributeName.length-1;i++){
if(attributeIsRequired[i].value=="1"){
content+="<tr><td>"+attributeType[i].value+"</td><td>"+attributeName[i].value+"</td><td><input name=\"AT\" value=\""+attributeDefaultValue[i].value+"\"/></td><td>&nbsp;"+attributeTitle[i].value+"</td></tr>";
}
else{
content+="<tr><td>"+attributeType[i].value+"</td><td>"+attributeName[i].value+"</td><td><input name=\"AT\" value=\""+attributeDefaultValue[i].value+"\"/></td><td>&nbsp;"+attributeTitle[i].value+"</td></tr>";
}
}
content+="<tr><td align=\"right\" colspan=\"4\"><button type=\"button\" id=\"yes\" onclick=\"PreviewOK();\">确定</button><button type=\"button\" onclick=\"EasyMask.close();\">取消</button></td></tr></table>";
var height=32*attributeName.length+98;
EasyMask.init({ width:800, height: height, title: '调试', detail: content });
}
else{
Preview2();
}
}

function PreviewOK(){
var attributes="";
var attributeName=$N("BSDevelopAttributeName");
var attributeValue=$N("AT");
var attributeIsRequired=$N("BSDevelopAttributeIsRequired");
for(var i=0;i<=attributeName.length-1;i++){
if(attributeIsRequired[i].value=="1"){
if(attributeValue[i].value==""){
ShowMessageDialog("提示",attributeName[i].value+"不能为空");
return;
}
}
attributes+=" "+attributeName[i].value+"=\""+attributeValue[i].value+"\"";
}
document.client.BSDevelopAttributes.value=attributes;
Preview2();
}

function Preview2(){
var content="<table class='attribtes' style='width:390px;'>";
if($("content").value.indexOf("{$qui.keyword}")>-1){
content+="<tr><td width='80'>类型:</td><td><select id=\"type\"><option value=\"1\">网站首页</option><option value=\"2\">频道首页</option><option value=\"3\">内容页</option><option value=\"4\" selected=\"selected\">其它</option></select></td></tr>";
}
else if($("content").value.indexOf("{$qui.id}")>-1){
content+="<tr><td width='80'>类型:</td><td><select id=\"type\"><option value=\"1\">网站首页</option><option value=\"2\">频道首页</option><option value=\"3\" selected=\"selected\">内容页</option><option value=\"4\">其它</option></select></td></tr>";
}
else if($("content").value.indexOf("{$qui.channelid}")>-1){
content+="<tr><td width='80'>类型:</td><td><select id=\"type\"><option value=\"1\">网站首页</option><option value=\"2\" selected=\"selected\">频道首页</option><option value=\"3\">内容页</option><option value=\"4\">其它</option></select></td></tr>";
}
else{
content+="<tr><td width='80'>类型:</td><td><select id=\"type\"><option value=\"1\">网站首页</option><option value=\"2\">频道首页</option><option value=\"3\">内容页</option><option value=\"4\">其它</option></select></td></tr>";
}
content+="<tr><td>是否WAP模式:</td><td><select id=\"iswap\"><option value=\"true\">是</option><option value=\"false\" selected=\"selected\">否</option></select></td></tr>";
content+="<tr><td>站点:</td><td><select id=\"siteid\" onchange=\"IsShowChannelRoot=false;SetChannel();\"><option value=\"1\">1</option></select></td></tr>";
content+="<tr><td>频道:</td><td><select id=\"channelid\" onchange=\"SetOther();\"><option value=\"1\">1</option></select></td></tr>";
content+="<tr><td align=\"right\" colspan=\"2\"><button type=\"button\" id=\"yes\" onclick=\"Preview2OK();\">确定</button><button type=\"button\" onclick=\"EasyMask.close();\">取消</button></td></tr></table>";
EasyMask.init({ width:405, height: 200, title: '调试', detail: content });
IsShowCurrent=false;
IsShowSiteRoot=false;
IsShowChannelRoot=false;
SetSite();
}

var NaturalLanguage;
var ArticleID;
function Preview2OK(){
if($("type").value=="1"){
if($("siteid").value==""){
ShowMessageDialog("提示","没有可以用于调试的站点");
return;
}
}
else if($("type").value=="2"){
if($("siteid").value==""){
ShowMessageDialog("提示","没有可以用于调试的站点");
return;
}
if($("channelid").value==""){
ShowMessageDialog("提示","所选站点,没有可以用于调试的频道");
return;
}
}
else if($("type").value=="3"){
if($("siteid").value==""){
ShowMessageDialog("提示","没有可以用于调试的站点");
return;
}
if($("channelid").value==""){
ShowMessageDialog("提示","所选站点,没有可以用于调试的频道");
return;
}
if(ArticleID==""){
ShowMessageDialog("提示","所选频道,没有可以用于调试的文章");
return;
}
}
Trading();
document.client.target="_blank";

var applicationPath="";
var group = document.client.BSDevelopPreviewPath.value.split("/");
for(var i = 1; i < group.length; i++){
applicationPath += "../";
}
document.client.action="../../"+document.client.BSDevelopPreviewPath.value+"previewpage.ashx?rn="+new Date()+"&applicationpath="+escape(applicationPath)+"&language"+NaturalLanguage+"&bsdeveloptype="+$("type").value+"&iswap="+$("iswap").value+"&siteid="+$("siteid").value;

if($("type").value!="1"){
document.client.action+="&channelid="+$("channelid").value;
}
if($("type").value=="3"){
document.client.action+="&id="+ArticleID;
}
document.client.submit();
document.client.target="_self";
EndTrading();
}

var IsShowCurrent=false;
var IsShowSiteRoot=false;
var IsShowChannelRoot=false;
function SetRootSite(){
AjaxRequest("?_action=getsitetree&isshowroot="+IsShowSiteRoot+"&isshowcurrent="+false,"",SetRootSiteReturn,null);
}

function SetRootSiteReturn(r){
SetNaturalLanguage();
$("rootsiteid").innerHTML=r;
SetSite();
}

function SetSite(){
AjaxRequest("?_action=getsitetree&isshowroot="+IsShowSiteRoot+"&isshowcurrent="+IsShowCurrent,"",SetSiteReturn,null);
}

function SetSiteReturn(r){
SetNaturalLanguage();
$("siteid").innerHTML=r;
if($("rootchannelid")){
SetRootChannel();
}
else if($("channelid")){
SetChannel();
}
}

function SetRootChannel(){
AjaxRequest("?_action=getchanneltree&siteid="+$("siteid").value+"&isshowroot="+true+"&isshowcurrent="+false,"",SetRootChannelReturn,null);
}

function SetRootChannelReturn(r){
$("rootchannelid").innerHTML=r;
SetChannel();
}

function SetChannel(){
AjaxRequest("?_action=getchanneltree&siteid="+$("siteid").value+"&isshowroot="+IsShowChannelRoot+"&isshowcurrent="+IsShowCurrent,"",SetChannelReturn,null);
}

function SetChannelReturn(r){
$("channelid").innerHTML=r;
if($("channelid").value=="-1"&&$("isreadchildchannelcontainer")){
$("isreadchildchannelcontainer").style.display="";
}
SetOther();
}

function SetNaturalLanguage(){
AjaxRequest("?_action=getnaturallanguage&siteid="+$("siteid").value,"",SetNaturalLanguageReturn,null);
}

function SetNaturalLanguageReturn(r){
NaturalLanguage=r;
}

function SetOther(){
AjaxRequest("?_action=getother&siteid="+$("siteid").value+"&channelid="+$("channelid").value,"",SetOtherReturn,null);
}

function SetOtherReturn(r){
ArticleID=r.trim();;
}

function ShowDesign(){
if($("tool").style.display=="none"){
Tool();
}
$("code").style.display="none";
$("content").style.display="inline";
$("showcode").disabled=false;
$("showdesign").disabled=true;
}

function ShowCode(){
var attributeIsRequired=$N("BSDevelopAttributeIsRequired");
var attributeType=$N("BSDevelopAttributeType");
var attributeName=$N("BSDevelopAttributeName");
var attributeDefaultValue=$N("BSDevelopAttributeDefaultValue");
var attributeTitle=$N("BSDevelopAttributeTitle");
if(document.client.BSDevelopExtension.value==".esc"&&attributeName.length>0){
var content="<table class='attribtes'><tr><th width='120'>数据类型&nbsp;</th><th width='120'>属性名&nbsp;</th><th width='285'>属性值</th><th>&nbsp;提示</th></tr>";
for(var i=0;i<=attributeName.length-1;i++){
if(attributeIsRequired[i].value=="1"){
content+="<tr><td>"+attributeType[i].value+"</td><td>"+attributeName[i].value+"</td><td><input name=\"AT\" value=\""+attributeDefaultValue[i].value+"\"/></td><td>&nbsp;"+attributeTitle[i].value+"</td></tr>";
}
else{
content+="<tr><td>"+attributeType[i].value+"</td><td>"+attributeName[i].value+"</td><td><input name=\"AT\" value=\""+attributeDefaultValue[i].value+"\"/></td><td>&nbsp;"+attributeTitle[i].value+"</td></tr>";
}
}
content+="<tr><td align=\"right\" colspan=\"4\"><button type=\"button\" id=\"yes\" onclick=\"ShowCode2();\">确定</button><button type=\"button\" onclick=\"EasyMask.close();\">取消</button></td></tr></table>";
var height=32*attributeName.length+98;
EasyMask.init({ width:800, height: height, title: 'eqml代码编译为C#代码', detail: content });
}
else{
ShowCode2();
}
}

function ShowCode2(){
AjaxRequest("index.htm","",ToShowCode2,null);
}

function ToShowCode2(){
var attributeName=$N("BSDevelopAttributeName");
if(document.client.BSDevelopExtension.value==".esc"&&attributeName.length>0){
var attributes="";
var attributeValue=$N("AT");
var attributeIsRequired=$N("BSDevelopAttributeIsRequired");
for(var i=0;i<=attributeName.length-1;i++){
if(attributeIsRequired[i].value=="1"){
if(attributeValue[i].value==""){
ShowMessageDialog("提示",attributeName[i].value+"不能为空");
return;
}
}
attributes+=" "+attributeName[i].value+"=\""+attributeValue[i].value+"\"";
}
document.client.BSDevelopAttributes.value=attributes;
EasyMask.close();
}
var res=document.createElement("div");
res.id="r";
res.style.cssText="display:none;";
res.innerHTML="<iframe id=\"res\" name=\"res\" style=\"display:none;\" src=\"\"></iframe>";
document.body.appendChild(res);
document.client.target="res";
if($("tool").style.display=="block"){
Tool();
}
Trading();
Action("getcode&isiframe=1");
}

function GetCodeEnd(result,message){
if(result==1){
if(System.ie){
$("code").value=document.frames["res"].code.value;
}
else{
$("code").value=$("res").contentDocument.getElementById("code").value;
}
$("code").style.display="inline";
$("content").style.display="none";
$("showcode").disabled=true;
$("showdesign").disabled=false;
ShowMessage(message);
}
else{
ShowMessage("");
var content;
if(System.ie){	
content="<div style=\"width:100%;height:100%;overflow:auto;\">"+message+"<br/><br/>"+document.frames["res"].code.value+"</div>";
}
else{
content="<div style=\"width:100%;height:100%;overflow:auto;\">"+message+"<br/><br/>"+$("res").contentDocument.getElementById("code").value+"</div>";
}
EasyMask.init({width:700,height:500,title:"提示",detail:content});
}
$("r").parentNode.removeChild($("r"));
EndTrading();
}