var selobj;

function AddItem(i_sel)
{
  selobj=GetSelect(i_sel);
  //计算总的ID列表
  var s_idlst=GetSelectIdList(selobj);
  if(s_idlst=="")
  	s_idlst="0";
  
  popup_open("/admin/getcontent/default.aspx?tp="+i_sel+"&nid="+escape(s_idlst),"选择相关"+(i_sel==0?"资讯":"产品")+"记录",510,465);
   
}	

function AddNews()
{
	//var s_in=window.prompt("请输入网站名称和页面地址，使用“-”分隔","");
	
  popup_open("/admin/dynamic.aspx?body=1&sel=8","新闻转载记录",510,300);

	
}

function SetUrlValue(s_name,s_value)
{
	var s_in=s_name+" - "+ s_value;
	
	$('C_News').options[$('C_News').options.length] = new Option(s_in, s_in);
	
	popup_close();
}

function AddItemTo()
{
	selobj=$('CRelation');
	var s_idlst=GetSelectIdList(selobj);
  if(s_idlst=="")
  	s_idlst="0";
  
  popup_open("/admin/getcontent/default.aspx?tp=5&nid="+escape(s_idlst),"链接到此文档记录",510,465);
  
}

//英文格式化 第一个字符大写
function FormatTitle()
{
	var s_con=$('C_Title').value.split(' ');
	var s_ret="";
	for(i=0;i<s_con.length;i++)
	{
		s_ret+=" "+s_con[i].substr(0,1).toUpperCase()+s_con[i].substr(1).toLowerCase();
	}
	
	if(s_ret.length>1)
	{
		s_ret=s_ret.substr(1);
	}
	
	$('C_Title').value=s_ret;
	
}

//插入数据
function SetItem(o_con)
{
	
	for(var o in o_con)
  {
  	if(typeof(o_con[o])!="undefined")
  	{
    	selobj.options[selobj.options.length] = new Option(o_con[o].name, o);
    }	
  }
}

function GetSelect(i_sel)
{
	var selobj;
	switch(i_sel)
	{
		case 0:
		{
			selobj=$('C_Correlate');
			break;
		}
		case 1:
		{
			selobj=$('C_Product');			
			break;
		}
		case 2:
		{
			selobj=$('CRelation');			
			break;
		}
		case 3:
		{
			selobj=$('C_News');			
			break;
		}
	}
			
	return selobj;	
}



function DelItem(i_sel)
{
	var selobj=GetSelect(i_sel);
	DelSelectItem(selobj);
}


function ShowAllTR()
{
	for(i=0;i<$('itemtable').rows.length;i++)
	{
		$('itemtable').rows[i].style.display="";
	}
}

$('C_Template').onchange=function (){
 //禁用某些字段显示
 ShowTemplate();
}






function ShowTemplate()
{
	var s_value=$('C_Template').value;
  ShowAllTR();
  
  //debugger;
  
  if(typeof(top.o_pageTemplate[s_value])!="undefined")
  {
 		 var s_con=top.o_pageTemplate[s_value].split(',');
 	 	 
	 	 for(i_cyc=0;i_cyc<s_con.length;i_cyc++)
	 	 {
	 	 	 if(s_con[i_cyc]!="")
	 	 	 {
		 	 	 switch(s_con[i_cyc])
		 	 	 {
		 	 	 	 case "C_Content":
		 	 	 	 {
			 	 	 	 	$("C_Content").value=" ";
			 	 	 		$('trcontent').style.display="none";
			 	 	 		$("Template").parentNode.parentNode.style.display="none";
			 	 	 		$("CRelation").parentNode.parentNode.style.display="none";
		 	 	 	 		break;
		 	 	 	 }	 
		 	 	 	 case "C_Repeat":
		 	 	 	 {
		 	 	 	 		$("CRepeat").parentNode.parentNode.style.display="none";
		 	 	 	 		break;
		 	 	 	 }
		 	 	 	 default:
		 	 	 	 {
			 	 	 	  if($(s_con[i_cyc])!=null)
					 	 	{
					 	 	 	 $(s_con[i_cyc]).parentNode.parentNode.style.display="none";
					 	 	}			
		 	 	 	 }
		 	 	 }
		 	 }
	 	 }
 	}
 	
 	if(($('C_Product').parentNode.parentNode.style.display=="none")&&($('C_Correlate').parentNode.parentNode.style.display=="none"))
 	{
 		$("CRelation").parentNode.parentNode.style.display="none";
 	}
}

function ShowTemplateInput()
{
	if(top.o_pageTemplateInput[$('Template').value]!="")
	{
		$('butinput').style.display="";
		//可以模板编辑
	}
	else
	{
		$('butinput').style.display="none";
	}
	

}

function OpenTemplate()
{
		ShowMode(0);// 复杂页面保存有问题
	  popup_open("/admin/class/getinput.aspx?cid="+$('C_CID').value+"&fn=/template/html/"+top.o_pageTemplateInput[$('Template').value]+"&rnd="+Math.random(),"模板输入",775,465);

}

$('Template').onchange=function(){
		
		var s_value=$('Template').value;
		if(s_value=="0")
		{
			
			SetEditorContents("C_Content"," ");
			$('butinput').style.display="none";
		}
		else
		{	
			
			if(typeof(top.o_contentTemplate[s_value])=="undefined")
			{
				top.o_parentFrame=window;
				ExecuteScript("/admin/dynamic.aspx?sel=3&temp="+ $('Template').value+"&Rnd="+Math.random());
			}
			else
			{
				
				SetEditorContents("C_Content",top.o_contentTemplate[s_value]);	
				ShowTemplateInput();
			}	
		}	
}

function LoadBody()
{
	top.o_parentFrame=window;	
	window.setTimeout("$('itemtable').focus()",100);
	window.setTimeout("ShowTemplate()",400);
}

function BuildTitleUrl()
{
	BuildTitleUrlByName('C_Title')
}

function SetCIDvalue()
{
	if($('CCID')!=null)
	{
		var s_cid= GetCookie('CCID');
		
		if(s_cid!=null)
		{
			$('CCID').value=s_cid;
		}
	}
}

function checkOther()
{
	var b_error=false;
	//全选
	SetSelectValue('C_Product');
	SetSelectValue('C_Correlate');
	SetSelectValue('CRelation');
	SetSelectValue('C_News');
	
	
	if(!CheckUrl('C_Url'))
	{
		b_error=true;
	}
	
	if($('CCID')!=null)
	{
			SetCookie("CCID",$('CCID').value);
			
			$('C_CID').value=$('CCID').value;
	}
	
	
	
	
	if(i_mode==1)
	{
		//保存到 内容中
		var oEditor = FCKeditorAPI.GetInstance("CContent") ; 
		$('C_Content').value=	oEditor.GetHTML();
	}
	
	
	
	
	if($('C_OutTitle').value=="")
	{
		$('C_OutTitle').value=$('C_Title').value;
	}
	
	if($('CRepeat').checked)
	{
		$('C_Repeat').value="1";
	}
	else
		{
			$('C_Repeat').value="0";
		}
		
	
	if($('CSync')!=null)
	{	
		if(!$('CSync').checked)
		{
			$('C_Sync').value="0";
		}
		
	}
	return b_error;
}

function MoveItem(i_sel,i_move)
{
	MoveItemSelect(GetSelect(i_sel),i_move);
}




function OpenCompare(s_id)
{
	popup_open("/admin/class/getcompare.aspx?cid="+s_id,"输入对比内容",530,465);
}

function GetMemoTip()	
{
	var s_text=$('C_Content').value;
	var s_ret="线路名称："+$('C_Title').value+"\r\n线路价格："+$('C_Price').value+"元\r\n";
	var s_con=new Array("出发地","行程天数","线路类型","发团日期","报名日期","线路主题");
	
	for(i=0;i<s_con.length;i++)
	{
		var s_name=s_con[i];
		var re = new RegExp(s_name+"：</b>(.*?)</td>");
		re.exec(s_text);
		if(s_name=="出发地")
			s_name="出发地点";
		s_ret+=s_name+"："+RegExp.$1.replace(/<.*?>/g,"")+"\r\n";	
	}
	$('C_Memo').value=s_ret;
}



function ShowFckeditor()
{
	popup_open("/admin/common/fckeditor.html","高级编辑",630,500);
}

var i_mode=0;
function ShowMode(i_sel)
{
	if(i_mode==i_sel)
		return ;
	
	$('ahrmode'+i_sel).className="selecttab";
	
	$('ahrmode'+(1-i_sel)).className="unselecttab";
	
	//$('ahrmode'+i_sel).style.color="red";
	//$('ahrmode'+(1-i_sel)).style.color="blue";
	
	$('C_Content').style.display="none";
	$('MyEditor___Frame').style.display="none";
	$('MyEditor___Frame').style.position="static";
	MyEditor___Frame
	
	var oEditor = FCKeditorAPI.GetInstance("CContent") ; 
	
	if(i_sel==0)
	{
		//简单模式
		$('C_Content').style.display="";
		$('C_Content').value=	oEditor.GetHTML();
	}
	else
	{
		$('MyEditor___Frame').style.display="";
    
		oEditor.SetHTML($('C_Content').value);
	}
	
	i_mode=i_sel;
}

function DoReturn(i_sel)
{
	//返回时更新记录
	var s_id=s_cid;
	var i_return =-1;
	
	if(s_id=="0")
	{
		if($('CCID')!=null)
		{
			s_id=$('CCID').value;
			i_return=0;
			
			window.open('/admin/class/contentlist.aspx?cid='+s_id+'&ord=c_id desc','_self');
		}
	}
	
	return 	i_return;
}