﻿
var maskDiv=null;
function showMaskDiv(){
   
     if(maskDiv==null||!maskDiv){
              maskDiv=document.createElement("DIV");
            
              if(!isIE){maskDiv.style.cssText="position:absolute;top:0px;left:0px;z-index:500;background-color:#000;opacity:.3;";}
              else{maskDiv.style.cssText="position:absolute;top:0px;left:0px;z-index:500;background-color:#000;filter:alpha(opacity=30);";
              }
              maskDiv.style.height=getscrollHeight();
              maskDiv.style.width=document.body.clientWidth;
              document.body.appendChild(maskDiv);
            
              }
          }
          
function closeMaskDiv(){
      if(maskDiv==null)return;
      document.body.removeChild(maskDiv);
      maskDiv=null;
      }

function showMask(){
   var excludeItems=null;
   if(showMask.arguments.length==1)excludeItems=showMask.arguments[0];
   showMaskDiv();
  
   displayElementsByTag("SELECT",false,excludeItems);
   displayElementsByTag("OBJECT",false,excludeItems); 
}
function closeMask(){
   closeMaskDiv();
   displayElementsByTag("SELECT",true,null);
   displayElementsByTag("OBJECT",true,null); 
}

/***************************************************************************/
/********************* Select Category *************************************/


// Container for Selecting Category
// template1 means the template for category level1
// template2 means the template for category level2
// template3 means the template for category level3
function SelectCategoryByAjax(txtCategoryID, txtID, typeID, allowP, template1, template2, template3)
{
    var sUrl = "/Services.aspx";
    var objDiv=getObject("divPopupForSelectCategory");
    if(typeof(allowP)=="undefined")
        allowParent=false;
    else   
        allowParent=allowP;
        
    var dialogsBox = new campton.dialogs(objDiv, "dialogs", "CloseCategoryList()");
    
    dialogsBox.setTitle(__selectCategoryTitle);
    dialogsBox.setContent(__containerBodyContent);
    dialogsBox.setFooter(__containerFooterContent);
//    dialogsBox.render(objDiv);
	showMask();
	objDiv.style.top=document.body.scrollTop+10;
	
//	YAHOO.example.container.panel2.show();
	
    var SuccessToGetCategory = function(o){  
    //alert(o.responseText);
        if(o.responseText !== undefined){ 
            var strContent = o.responseText;  
            
            if (strContent.length > 0)
            {
	            dialogsBox.setContent("<div class='bodyContent'>" + strContent + "</div>");
	            dialogsBox.render(objDiv);
	            YAHOO.example.initTreeView("treeView332541147887");
            }
            else
            {
	            dialogsBox.setContent("<div class='bodyContent'>" + __NoCategoryContent + "</div>");
	            dialogsBox.render(objDiv);
            }
        }
    }

    var FailToGetCategory = function(o){        
            //alert(o.statusText+'\r\n'+o.responseText);
    }

    var CallbackForSelectCategory =
    {
         success: SuccessToGetCategory,
         failure: FailToGetCategory
    };
    if(SelectCategoryByAjax.arguments.length<5){
        template1="";
        template2="";
        template3="";
    }
   
    var strQueryString = "action=GetCategoriesByTypeID&txtCategoryID="+txtCategoryID+"&txtID="+txtID+"&typeID="+typeID+"&templateforlevel1="+template1+"&templateforlevel2="+template2+"&templateforlevel3="+template3;
//alert("sUrl=" + sUrl + "\r\n" + "strQueryString=" + strQueryString);
    YAHOO.util.Connect.asyncRequest("POST", sUrl, CallbackForSelectCategory, strQueryString);

}

function ChooseCategory(idControl, id, nameControl, name)
{
    objID=getObject(idControl);
    objName=getObject(nameControl); 
    if(!allowParent){
        var objLi=event.target || event.srcElement; 
        objLi=getParent("LI",objLi) 
        //var li=getObject(liId);
        var li=objLi;
        if(li != null)
        {
            var child=li.getElementsByTagName("LI");
            if(child.length>1)
                return;
        }
    }
    objID.value=id;
    objName.value=name;
    
    //alert("id=" + id + " name=" + name + " objID.value=" + objID.value + " objName.value=" + objName.value);
    
    var objDiv=getObject("divPopupForSelectCategory");
    objDiv.innerHTML = "";
    closeMask();
    
}

function CloseCategoryList()
{
    var objDiv=getObject("divPopupForSelectCategory");
    objDiv.innerHTML = "";
    closeMask();
}

/*********************** Select Category **************************************/
/***************************************************************************/

/***************************************************************************/
/***************************************************************************/
/*********************** Select Skins **************************************/

function showTemplates(skinTempContent){
    
     showMask();
    
     _activeTemplate=0;
     _viewItems = [{index:0, id:"MNWVDetails", cssClass:"MNWVDetailsS", template:"MNWVDetails"}];
     __title = __selectSkins;
     __key = "";//no use
    
     var menuItems = __tabTemplatetitle; // var menuItems='Aaa,Bbb';
     var tabTitle = __tabTemplatetitle.replace(/\"/g,"").replace(/\'/g,"");
     var tabTitleArray=tabTitle.split(',');
     
     var leftcontent="";
     for(var i=0;i<tabTitleArray.length;i++)
     {
        leftcontent += '<A class=\"Normal\" onclick=\"return false;\" href=\"#' + tabTitleArray[i] + '\" title=\"' + tabTitleArray[i] + '\" >' + tabTitleArray[i] + '</A>';
     }
     
     var skinTemp1 = "";
     var skinTemp2 = "";
     var arySkinTemp = skinTempContent.split("##########");
     if (arySkinTemp && arySkinTemp.length == 2)
     {
        skinTemp1 = arySkinTemp[0];
        skinTemp2 = arySkinTemp[1];
        if (skinTemp2 == "")
            skinTemp2 = __noUserSkins;
     }   
     
     var menuContents=[skinTemp1, skinTemp2];
     var cache = campton.createCache(menuItems.split(','), menuContents, leftcontent);
     campton.seleter({title:__title, className:"tablist", close: closeMask, disableClose:false, closeTagClassName:"closeMe", subNavActive:"subNavActive", command:{left:"cache", content: "cache"}, action:[] }, cache);
}

// type likes "host" or "portal"
function GetSkinTemplate(skintype)
{
    var sUrl = "/Services.aspx";
    var SuccessToGetSkinTempate = function(o){
        if(o.responseText !== undefined){ 
            var strContent = o.responseText;  
            
            if (strContent.length > 0)
            {
                showTemplates(strContent);
            }
            else
            {
	            return __NoCategoryContent;
            }
        }
        else
            return "fail to get.";
    }

    var FailToGetSkinTempate = function(o){        
            //alert(o.statusText+'\r\n'+o.responseText);
            alert("fail.");
    }

    var CallbackForGetSkinTempate =
    {
         success: SuccessToGetSkinTempate,
         failure: FailToGetSkinTempate
    };
    
    var skinFormatTemplate="Templates.System.TemplateForSkins.template";
    
    var strQueryString = "action=GetSkinTemplate&templateforlevel1="+skinFormatTemplate;

    YAHOO.util.Connect.asyncRequest("POST", sUrl, CallbackForGetSkinTempate, strQueryString);

}

/*********************** Select Skins **************************************/
/***************************************************************************/
/***************************************************************************/

/***************************************************************************/
/*************************** Select Layout *********************************/
var Template=function(obj){  

    this.container=typeof(obj)=="string"?getObject(obj):obj;	
  
}

Template.prototype={
      checked:"checked",
	  style:"A",
      getValue:function(){
	     var checked=this.checked;
		 var getImg=this.getImg;
         var  container=this.container;
     	 var aryImg=container.getElementsByTagName("IMG");
	     var temp="";	
	    for(var i=0;i<aryImg.length;i++){
	        if(aryImg[i].title==checked){
			    temp+=getImg(aryImg[i].parentNode).title+",";
			}
	    }
		
		return temp.substring(0,temp.length-1);
		
 },
  getImg: function(li){
	      var checked="checked";
	      var imgs=li.getElementsByTagName("IMG");
		  for(var i=0;i<imgs.length;i++){
		  	  if(imgs[i].title!="" && imgs[i].title!=checked)return imgs[i];
		  }
		  return null;
	 },
  init:function(mutiselect,initValue,style,clickcallback){
   
     var checked=this.checked;
	 var getImg=this.getImg;
	 var sty=this.style;
	 if(style!=undefined)sty=style;
	
     var  container=this.container;
     var onmouseover=function(evt,obj){
	     
	       //obj.className="over";
	 }
	 var onmouseout=function(evt,obj){
	       //obj.className="out";
	 }
	
	 var clickFun=function(evt,obj){
	  
	        var callback; 
	  
			if(isCheckedNode(obj.image))
			{			
			    if(clickcallback!=undefined)
			    {
			      callback=clickcallback+"('')";	
			      eval(callback);				
			    }   
			    removeImg(obj.image.parentNode);
				return;
			}
		
			var selectedNode=CheckedNode();
			if(!mutiselect&&selectedNode!=null)
			{			     
       			  removeImg(selectedNode.parentNode);
			}
			
			addImg(obj.image,sty);
		   
			if(clickcallback!=undefined){
			     callback=clickcallback+"('"+obj.image.title+"')";	
			     //alert("callback = " + callback);
			     eval(callback);
			     //alert("callback end...");				
			 }    	 
			 
	 }
	 var addImg=function(obj,sty){
	        var img=document.createElement("img");
			
		    img.src="/images/icons/"+sty+"_selected.gif";
			img.title=checked;
			img.className=sty+"_selected";
            img.style.position="absolute";
            if(sty=="b")
            {
            img.style.marginLeft=122+"px";
            img.style.marginTop=5+"px";
            }
            obj.parentNode.insertBefore(img,obj);
	 }
	 var removeImg=function(obj){
	      for(var i=0;i<obj.childNodes.length;i++){
		  	   if(obj.childNodes[i].title==checked)
			      obj.removeChild(obj.childNodes[i]);
		  }
	 }
	 var isLeaf=function(li){
	       var aryLI=li.getElementsByTagName("LI");
	       return aryLI.length==0;
	 }	 
	 var init=function(){	
	   
	      var aryLI=container.getElementsByTagName("LI");		 
		 //alert(container.outerHTML)
	
		 for(var i=0;i<aryLI.length;i++){
		       
		        if(!isLeaf(aryLI[i]))continue;
		        var img=getImg(aryLI[i]);				
			//alert(img.outerHTML);
				YAHOO.util.Event.addListener(aryLI[i],'mouseover',onmouseover,aryLI[i]);
				YAHOO.util.Event.addListener(aryLI[i],'mouseout',onmouseout,aryLI[i]);
				YAHOO.util.Event.addListener(aryLI[i],'click',clickFun,{image:img,action:true});
				
				if(typeof(initValue)==undefined||initValue==""||initValue==null)continue;
				if(img==null)continue; 
				if(initValue!=null&&initValue.toLowerCase()==img.title.toLowerCase()){
				      clickFun(null,{image:img,action:false});					 
				};  
		 }		
		
	 }
	
	 var isCheckedNode=function(obj){
	       for(var i=0;i<obj.parentNode.childNodes.length;i++){		      
		  	   if(obj.parentNode.childNodes[i].title==checked)return true;			       
		  }
		  return false;
	 }
	 var CheckedNode=function(){
	 	var aryImg=container.getElementsByTagName("IMG");
	    for(var i=0;i<aryImg.length;i++){
	        if(aryImg[i].title==checked)return aryImg[i];
	    } 
		return null;
	 }
	 
     init();
 }
 }
 
 
 //****************
 
 
if(typeof(campton) == "undefined"){
	var campton = {};
	campton.debug = true;
}

/*
-======= info 对象说明 =======-
info.className 样式类名
info.title 标题 string
info.action 操作 对象数组[{id:"MNWVDetails", cssClass:"MNWVDetailsS"}, {id:"MNWVThumb", cssClass:"MNWVThumbN"}, {id:"MNWVList", cssClass:"MNWVListN"}]
info.tools 附加工具 [{label:"",link:"", callback:""}]
info.subNavActive 当前tab的样式名称
info.baseTabUrl 请求的基本地址
info.baseParam 请求的基本参数
info.command {left:"ListView",content:"ContentView"}
info.close 附加一个函数到关闭事件上
info.closeTagClassName 启动关闭的标签类名,不写就按默认处理
*/

campton.seleter = function(info, cache) {
  
	var debug = campton.debug;
	
  
	if(typeof(info) != "object") return;
	var selecter = $("CamptonBox");
	var action = (typeof(info.action) == "object" ? info.action:[{id:"MNWVDetails", cssClass:"MNWVDetailsS"}]);
	var closeTag=info.closeTag;
	
	var currentView;
	var currentTab;
	var currentTabPage = new campton.cache();
	var pageSize = 24;
	if(typeof(cache) == "undefined"){
		cache = new campton.cache();
	}
	
    var first=true;
	var baseUrl = "/ajax.aspx?";
	if (info.url != null)
	    baseUrl = info.url + "&";
	var wt_level2='';
	var subNavVisible = false;
	var hoverSubNav = -1;
	var activeSubNav = 0;
	var l2timer;
	var l2op=0;
	var l2al=0;
	var mnwPanel = getObject('MNWPanel');
	var mnwFooter = getObject('MNWFooter');
	var isAnimating=false;
	var wt_level1='';
	var msWinPath=''
	var tabsContainer = getObject("MNWTabsC");
	var leftTab=info.currentTitle;
    
	var init = function(){

		var mnwClose = getObject("MNWClose");
	
		YAHOO.util.Dom.setStyle(selecter, "display", "block");
		
		YAHOO.util.Event.removeListener(mnwClose, "click");
	
		YAHOO.util.Event.removeListener(mnwPanel, "click");
		
		YAHOO.util.Event.addListener(mnwClose, "click", close, selecter);
	
		YAHOO.util.Event.addListener(mnwPanel, "click", onClick, info);
		
		if(typeof(info.className) == "string"){
			selecter.className = info.className;
		}
		var width = YAHOO.util.Dom.getStyle(selecter, "width");
		var height = YAHOO.util.Dom.getStyle(selecter, "height");
		
	    var x=getFixXY(width,height).x;
		var y=getFixXY(width,height).y;
		
		if(x > 0 && y > 0){
			YAHOO.util.Dom.setX(selecter, x);
			YAHOO.util.Dom.setY(selecter, y);
		}
	   
		if(typeof(info.command) == "undefined" || 
				  typeof(info.command.left) == "undefined" || 
				  typeof(info.command.content) == "undefined"){
			if(debug) alert("Error Command of info object!!");
			return;
		};
		if(typeof(info.subNavActive) == "undefined") info.subNavActive = "subNavActive";
		display(info.title, "MNWHeader");
		
		createActionView();
		
		createToolsView();
		createTabsView();		//left
		
	};
	var close = function(evt, o){
	    clearActionView();
		updateContentView("");
		cache.clear();
		delete info;
	    YAHOO.util.Dom.setStyle(o, "display", "none");
	    if(typeof(info.close) == "function") info.close();
	};
	var onClick = function(evt, info){
		if(info.disableClose == true) return;
		if(evt==null) evt = window.event;
		var _target = (evt.srcElement ? evt.srcElement : evt.target);
	
		if(closeTag!=null){
		    if(_target.className.toLowerCase().indexOf(closeTag)<0)return;
		}
		
		if(_target == mnwPanel) return;
		
		if(typeof(info.closeTagClassName) == "undefined" || _target.className ==null || _target.className =="")return;
	
		if(info.closeTagClassName.toLowerCase().indexOf(_target.className.toLowerCase())<0) return;
		close(evt, selecter);
	};
	var createActionView = function(){
	   
		var target = getObject("MNWView");
		currentView = (action.length > 0 ? action[0].id : "default");
		
		if(action.length<=1)return;
		for(var i=0; i<action.length; i++){
			var o = action[i];
			var v = document.createElement("DIV");
			v.id = o.id;
			v.className = o.cssClass;
			YAHOO.util.Event.removeListener(v, "mouseover");
			YAHOO.util.Event.removeListener(v, "mouseout");
			YAHOO.util.Event.removeListener(v, "mousedown");
			YAHOO.util.Event.removeListener(v, "mouseup");
			YAHOO.util.Event.removeListener(v, "click");
			YAHOO.util.Event.addListener(v, "mouseover", viewStyle, {obj:v, style:'H'});
			YAHOO.util.Event.addListener(v, "mouseout", viewStyle, {obj:v, style:'N'});
			YAHOO.util.Event.addListener(v, "mousedown", viewStyle, {obj:v, style:'D'});
			YAHOO.util.Event.addListener(v, "mouseup", viewStyle, {obj:v, style:'H'});
			YAHOO.util.Event.addListener(v, "click", changeView, v.id);
			target.appendChild(v);
		}
	};
	var clearActionView = function(){
		var target = getObject("MNWView");
		var end = target.childNodes.length - 2;
		for(var i=0; i<end; i++){
			target.removeChild(target.lastChild);
		}
	}
	var viewStyle = function(evt, p){
		if(typeof(p)=="undefined" || p == null) return;
		if(p.style == "D"){
			for(var i=0; i<action.length; i++){
				if(p.obj.id == action[i].id){
					action[i].cssClass = action[i].id + "S";
					p.obj.className = action[i].id + "D";
				}else{
					action[i].cssClass = action[i].id + "N";
					var t = getObject(action[i].id);
					t.className = action[i].cssClass;
				}
			}
		}else if(p.style == "N"){
			for(var i=0; i<action.length; i++){
				var t = getObject(action[i].id);
				t.className = action[i].cssClass;
			}
		}else{
			p.obj.className = p.obj.id + p.style;
		}
	}
	var changeView = function(evt, id){
		currentView = id;
		var key = cacheKey();
		
		if(cache.contains(key)){
		   
			updateContentView(cache.get(key));
		}else{
		   
			mnwPanel.innerHTML = "";
			YAHOO.util.Dom.addClass(mnwPanel, "loading");
			updateCache(key);
		}
	}
	var createToolsView = function(){
		if(typeof(info.tools) == "undefined" || info.tools == null || info.tools == "") {display("", "UPLOADLINK"); return;}
		var tools = info.tools;
		var oStr = "";
		//alert("tools = " + tools);
		for(var i=0; i<tools.length; i++){
		
		    //  alert("tools[i].label = " + tools[i].label + "\r\n\r\n" + "tools[i].link = " + tools[i].link);
		      
		    if(typeof(tools[i].callback) != "undefined"){
			    oStr += "<a href=\"" + tools[i].link + "\"  onclick=\"" + tools[i].callback + "()\" >" + tools[i].label + "</a>";
			 
			}else{
			    oStr += "<a href=\"" + tools[i].link + "\" target=\"_blank\" >" + tools[i].label + "</a>";
			}
		}
		display(oStr, "UPLOADLINK");
		var tool = document.getElementById("UPLOADLINK");
		var links = tool.getElementsByTagName("A");
				
		for(var i=0; i<links.length; i++){
		    YAHOO.util.Event.removeListener(links[i], "click");
		    YAHOO.util.Event.addListener(links[i], "click", close, selecter);
		}
	}
	var createTabsView = function(){
		if(info.command.left != "cache"){
			var url = baseUrl + "randid="+Math.random()+"&command=" + info.command.left;
		
			campton.update(url, "", "MNWTabsC", addListener2tabs);
			
		}else{
			addListener2tabs("", {responseText:cache.get("$cache23235456464775454")}, getObject("MNWTabsC"));
		}
	}
	
	
	var addListener2tabs = function(p, o, target){
		target.innerHTML = o.responseText;
		var tabs = tabsContainer.getElementsByTagName("A");
		currentTab = (tabs.length > 0 ? tabs[0]: null);
		for(var i=0; i<tabs.length; i++){
		    YAHOO.util.Event.removeListener(tabs[i], "mouseover");
		    YAHOO.util.Event.removeListener(tabs[i], "mouseout");
		    YAHOO.util.Event.removeListener(tabs[i], "click");
			YAHOO.util.Event.addListener(tabs[i], "mouseover", subNavOver, i);
			YAHOO.util.Event.addListener(tabs[i], "mouseout", subNavOut, i);
			YAHOO.util.Event.addListener(tabs[i], "click", subNavClick, {index:i, target:tabs[i]});
			YAHOO.util.Event.addListener(tabs[i], "click", function(){return false;});
			if(leftTab!=null){
			     if(tabs[i].title==leftTab){
	                activeSubNav=i;
	                currentTab = tabs[i];  
	             }
	        }
		}
		var content = getContent();
		currentTab.className = info.subNavActive;
		if(content != null && content != "") {
			
			updateContentView(content);
		}
		if(info.command.left == "treeview"){
			//YAHOO.example.initTreeView("treeView5564565465");
		}
	}
	var updateCache = function(key){
		var p =key.split('|');
		if(p.length != 3) return;
		
		var url = baseUrl + "command=" + info.command.content + "&folder=" + urlEncode(currentTab.title) + "&template=" + currentView + "&pageindex="+getCurrentTabPage() + "&pagesize=" + pageSize;
	   if(first){
	       url+="&first=1";
	       first=false;
	   }
		campton.update(url, info.postData, "", addContent2Cache, key);
	}
	var addContent2Cache = function(key, o, target){
		var content = o.responseText;
		cache.add(key, content);
		updateContentView(content);
	}
	var updateContentView = function(value){
		var splitIndex = value.indexOf("<!-- pager -->");
		
		if(splitIndex >= 0){
			//mnwPanel.innerHTML = value.substring(0, splitIndex);
			
			setInnerHTML(mnwPanel,value.substring(0, splitIndex));
			updatePagerView(value.substring(splitIndex));
		}else{
			//mnwPanel.innerHTML = value;
		
			setInnerHTML(mnwPanel,value);
			updatePagerView();
		}
		YAHOO.util.Dom.removeClass(mnwPanel, "loading");
	}
	var display = function(txt, target){
		if(typeof(target) == "undefined" || target == null) return;
		var t = (typeof(target) == "string" ? getObject(target):target);
		if(typeof(t.innerHTML) == "string") {setInnerHTML(t,txt);}
		else if(typeof(t.innerText) == "string") {setInnerHTML(t,txt);}
		else if(typeof(t.value) == "string") {t.value = txt; }
	}
	var subNavOver = function(evt, index){
		if(index != activeSubNav && index != hoverSubNav) {
			var tabs = tabsContainer.getElementsByTagName("A");
		 	var newTab = tabs[index];
		 	hoverSubNav = index;
		} 
	}
	var subNavOut = function(evt, index) {
		if(index == hoverSubNav && index != activeSubNav) {
			var tabs = tabsContainer.getElementsByTagName("A");
			var hoverTab = tabs[hoverSubNav];
			hoverSubNav = -1;
		} 
	}
	var subNavClick = function(evt, p) {
	 
		if(isAnimating){
			return false;
		}
		var index = p.index;
		var target = p.target;
		currentTab = target;
		if(index != activeSubNav) {
			var tabs = tabsContainer.getElementsByTagName("A");
			var newTab = tabs[index];
			var oldTab = tabs[activeSubNav];
	
			if(newTab && oldTab) {
				newTab.className = info.subNavActive;
				oldTab.className = '';
				activeSubNav = index;
			}		
			if(mnwPanel!=null) {
				wt_level2 = target.childNodes[0].nodeValue;
				var value = getContent(newTab.childNodes[0].nodeValue);
				
				if(value != null && value != "")
				{
					fContent = value;
					isFading = true;
					isAnimating = true;
					l2al=100;
					l2op=1;
					l2timer = setInterval(subNavClickInterval, 1);
				}
			}
		}
		return false;
	}
	var subNavClickInterval = function() {
		if(isFading){
			if(l2al<=0){
				isFading=false;
			    
			    setInnerHTML(mnwPanel,"");
				setInnerHTML(mnwPanel,fContent);
				
			} else{
				l2al=l2al-15;
				if(l2al<0)
					l2al=0;
				l2op=l2op-0.15;
				if(l2op<0)
					l2op=0;
			}
		} else{
			l2al=l2al+15;
			l2op=l2op+0.15;
		}
		mnwPanel.style.MozOpacity = ''+l2op;
		mnwPanel.style.filter = 'alpha(Opacity='+l2al+')';
		if(l2al>=100 && !isFading) {
			mnwPanel.style.MozOpacity = '';
			mnwPanel.style.filter = '';
			clearInterval(l2timer);
			isAnimating = false;
			l2timer = null;
		}
	}
	var getContent = function(tab){
		var key = cacheKey();
		if(cache.contains(key)){
			var value = cache.get(key);
			var splitIndex = value.indexOf("<!-- pager -->");
			if(splitIndex >= 0){
				var content = value.substring(0, splitIndex);
				updatePagerView(value.substring(splitIndex));
			}else{
				var content = value;
				updatePagerView();
			}
			YAHOO.util.Dom.removeClass(mnwPanel, "loading");
			return content;
		}else{
			mnwPanel.innerHTML = "";
			YAHOO.util.Dom.addClass(mnwPanel, "loading");
			updateCache(key);
			return "";
		}
	}
	var updatePagerView = function(value){
		if(typeof(value) == "undefined"){
			mnwFooter.innerHTML = "";
			return;
		}
		mnwFooter.innerHTML = value;
		var list = mnwFooter.getElementsByTagName('A');
		for(var i=0; i<list.length; i++){
		    YAHOO.util.Event.removeListener(list[i], "click");
			YAHOO.util.Event.addListener(list[i], "click", changePage, list[i]);
		}
	}
	var changePage = function(evt, o){
		currentTabPage.add(currentTab.title, o.innerHTML);
		var key = cacheKey();
	
		if(cache.contains(key)){

			updateContentView(cache.get(key));
		}else{
		  
			mnwPanel.innerHTML = "";
			YAHOO.util.Dom.addClass(mnwPanel, "loading");
			updateCache(key);
		}
	}
	
	var cacheKey = function(){return currentView.replace('|','') + "|" + currentTab.title.replace('|','') + "|" + getCurrentTabPage();}
	
	var getCurrentTabPage = function() {return (currentTabPage.contains(currentTab.title) ? currentTabPage.get(currentTab.title):1);}
	
	init();
}
campton.update = function(url, postData, target, callback, param,evalscript){
	var debug = campton.debug;
	if(typeof(url) == "undefined" || url == null || url == "") return;
	if(typeof(target) == "undefined" || target == null) return;
	var obj = (typeof(target) == "string" ? getObject(target) : target);
	if((typeof(obj) == "undefined" || obj == null) && (typeof(callback) != "function")) return;
	var init = function(){
		if(typeof(obj)=="object") YAHOO.util.Dom.addClass(obj, "loading");
		var request = YAHOO.util.Connect.asyncRequest('GET', url, Callback, postData);
	}
	var Success = function(o){
		if(typeof(obj)=="object") YAHOO.util.Dom.removeClass(obj, "loading");
		if(typeof(callback) == "function"){
			callback(param, o, obj);
		}else{
			setInnerHTML(obj, o.responseText);
		}
	}
	var Failure = function(o){
		if(debug) alert(o.responseText);
		YAHOO.util.Dom.removeClass(obj, "loading");
	}
	var Callback = {success:Success, failure:Failure}
	init();
}
campton.cache = function(){this.cache = new Object();}
campton.cache.prototype ={
	contains:function(key){return typeof(this.cache[key]) != "undefined";},
	get:function(key){
		if(typeof(this.cache[key]) != "undefined"){
			return this.cache[key];
		}
		return null;
	},
	add:function(key, value){this.cache[key] = value;},
	remove:function(key){delete this.cache[key];},
	clear:function(){for(var key in this.cache){delete this.cache[key];}},
	getKeys:function(){
		var keys = [];
		for(var key in this.cache){
			keys.push(key)
		}
		return keys;
	}
}
campton.createCache = function(items, contents, leftContent){
	if(items.length != contents.length) return;
	var cache = new campton.cache();
	for(var i=0; i<items.length; i++){
		var key = "default|" + items[i].replace(/^\"|\"$/g,'') + "|1";
		cache.add(key, contents[i]);
	}
	cache.add("$cache23235456464775454", leftContent);
	return cache;
}

function urlEncode(str)
{
	if(str==null||str=="")
		return "";
	var newstr="";
	function toCase(str){
		return str.toString(16).toUpperCase();
	}
	for(var i=0,icode,len=str.length;i<len;i++){
		icode=str.charCodeAt(i);
		if( icode<0x10)
			newstr+="%0"+icode.toString(16).toUpperCase();
		else if(icode<0x80){
			if(icode==0x20)
				newstr+="+";
			else if((icode>=0x30&&icode<=0x39)||(icode>=0x41&&icode<=0x5A)||(icode>=0x61&&icode<=0x7A))
				newstr+=str.charAt(i);
			else
				newstr+="%"+toCase(icode);
		}
		else if(icode<0x800){
			newstr+="%"+toCase(0xC0+(icode>>6));
			newstr+="%"+toCase(0x80+icode%0x40);
		}
		else{
			newstr+="%"+toCase(0xE0+(icode>>12));
			newstr+="%"+toCase(0x80+(icode>>6)%0x40);
			newstr+="%"+toCase(0x80+icode%0x40);
		}
	}
	return newstr;
}
var setInnerHTML = function (el, htmlCode) {
    var ua = navigator.userAgent.toLowerCase();   
    if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {      
        htmlCode = '<div style="display:none">for IE</div>' + htmlCode;
        htmlCode = htmlCode.replace(/<script([^>]*)>/gi,
                                    '<script$1 defer="true">');
          
      
        el.innerHTML = htmlCode;  
       
//        alert("el = " + el + ", el.id = " + el.id + ", el.innerHTML = " + el.innerHTML + ", htmlCode = " + htmlCode);                     
        el.removeChild(el.firstChild);
        
    }
    else {
        var el_next = el.nextSibling;
        var el_parent = el.parentNode;
        el_parent.removeChild(el);
        el.innerHTML = htmlCode;
      
        if (el_next) {
            el_parent.insertBefore(el, el_next)
        } else {
            el_parent.appendChild(el);
        }
    }
}



document.AjaxWrite = function() {
    var body = document.getElementsByTagName('body')[0];
    for (var i = 0; i < arguments.length; i++) {
        argument = arguments[i];
        if (typeof argument == 'string') {
            var el = body.appendChild(document.createElement('div'));
            setInnerHTML(el, argument)
        }
    }
}

 
/*************************** Select Layout *********************************/
/***************************************************************************/

/***************************************************************************/
function formatUrl(sUrl)
{
    var index = sUrl.indexOf("#");
    var url = sUrl;
    
    if (index > -1 && index == url.length-1)
        url = url.substring(0, url.length-1); // remove the #
    
    index = sUrl.lastIndexOf("/");
    if (index > -1 && index == url.length-1)
        url = url + "default.aspx"; // if sUrl likes http://www.aa.com/, it should be added default.aspx to the end.
    
    index = url.indexOf("?");
    if (index > -1 && index == url.length-1) // http://www.123.com/default.aspx?
        url = url.substring(0, url.length-1);
    
    if (url.indexOf("?") > -1) // http://www.123.com/?
        url = url + "&"; // url has already had querystring
    else
        url = url + "?"; // 
    
    return url;
    
}

// Reset the value of the key in querystring
function SetQueryStringValue(url, key, value)
{
    var result = "";
    var index = url.indexOf(key + "=");
    if (index < 0)
    {
        result = formatUrl(url);
        result += key + "=" + value;
    }
    else
    {
        // key exists in url    
        var keyLength = key.length + 1;
        var indexOfStartReplace = index + keyLength;
        var valueContent = url.substring(indexOfStartReplace, url.length);
        var indexOfAnd = valueContent.indexOf("&");
        var indexOfEndReplace;
        if (indexOfAnd < 0)
            indexOfEndReplace = url.length;
        else
            indexOfEndReplace = indexOfStartReplace + indexOfAnd;
            
        var strReplace = url.substring(indexOfStartReplace, indexOfEndReplace);        
        result = url.replace(strReplace, value)
    }
    
    return result;    
}

// Remove the key in querystring
function RemoveQueryString(url, key)
{
    var result = "";
    var index = url.indexOf(key + "=");
    if (index < 0)
	    return url;
    else
    {
        // key exists in url    
        var keyLength = key.length + 1;
        var indexOfStartReplace = index; // from key 
        var valueContent = url.substring(indexOfStartReplace, url.length);
        var indexOfAnd = valueContent.indexOf("&");
        var indexOfEndReplace;
        if (indexOfAnd < 0)
        {
            indexOfStartReplace = index - 1;
            indexOfEndReplace = url.length;
        }
        else
        {
            indexOfEndReplace = indexOfStartReplace + indexOfAnd + 1;
        }
            
        var strReplace = url.substring(indexOfStartReplace, indexOfEndReplace);        
        result = url.replace(strReplace, "")
    }
    
    return result;    
}

/***************************************************************************/


function showImageSelector(target, callback,url,uploadCallback)
{

    __title = "File Tools";
  
    __target32904039439823 = (typeof(target) == "string" ? $(target) : target);
    
    showMask();
    var __link = url;

    campton.seleter({title:__title, className:"treelist",closeTagClassName:"entry,detailpic,title,desc", close: (callback)?callback:closeMask, disableClose: false, subNavActive:"subNavActive", tools:[{label:__uploadLinkText, link:__link, callback:uploadCallback}], command:{left:"treeview", content: "contentview"} });
   

}

function callItBack(value){
    value=value.substring(1);
    value=value.substring(value.indexOf('/')+1);
    value=value.substring(value.indexOf('/')+1);
    if (typeof(__target32904039439823) == "object")
        __target32904039439823.value = value;
}



var _formContainer = "formContainer823938293272932";
var _fileContainer = "fileContainer28932823873";
var _uploadSuccessFiles = [];
var _uploadFailFiles = [];
var _startInfo = {};
var _clearCache = false;

function showUploadControl(callback){
    __uploadsucessCallback=callback;
   // showMask();
	var width = 380;
	var height = 300;
	var x=getFixXY(width,height).x;
	var y=getFixXY(height,height).y;
	

	
	var o = document.createElement("div");
	o.id = _formContainer;
	o.className =_formContainer;
	YAHOO.util.Dom.setStyle(o, "width", width + "px");
	YAHOO.util.Dom.setStyle(o, "height", height + "px");

	var closebar = document.createElement("div");
	closebar.className = "closeUploadBox";
	o.appendChild(closebar);
	YAHOO.util.Event.addListener(closebar, "click", doCloseFiles);
	var infoBar = document.createElement("div");
	infoBar.className = "infoBar";
	var infoText = document.createElement("div");
	infoText.id = "infoText2993289744";
	infoBar.appendChild(infoText);
	o.appendChild(infoBar);

	o.appendChild(buidUploadForm());
//	___hide();
	var btn = document.createElement("input");
	btn.type = "button";
	btn.id = "doUpload23832923";
	btn.value = __uploadLinkText;
	YAHOO.util.Event.addListener(btn, "click", doUploadFiles);

	var btnContainer = document.createElement("div");
	btnContainer.className = "btnContainer";
	btnContainer.appendChild(btn);

	o.appendChild(btnContainer);
	document.body.appendChild(o);
	YAHOO.util.Dom.setX(o, x);
	YAHOO.util.Dom.setY(o, y);
	
    o.style.zIndex=1600;	
    
    var strUploadHellpText="<span class='uploadHelpTextStyle'>"+__uploadHelpText+"</span>";
    
	displayInfo(strUploadHellpText, "WarningMsg");


};

var uploadCallback = {
    upload:uploadCallback
};

function uploadCallback(o){
	var s = o.responseText;
	if(s.indexOf('|')>0){
	    var p = s.split("|");
	    for(var i = 0; i < p.length; i++){
	       eval(p[i] + "\(" + p[++i] + "\)");
	    }
	}
};

function uploadSuccessFile(s){
	_uploadSuccessFiles.push(s);
};

function uploadFailFile(s){   
	_uploadFailFiles.push(s);	
};

function uploadComplete(s){

	_clearCache = true;
	
	if(_uploadFailFiles.length==0){
	  
		doCloseFiles();
		
	}else{
		var target = getObject(_fileContainer);
		var list = getFileItems();
	
		for(var i=0; i < list.length; i++){
			var isFail = false;
			for(var j=0; j< _uploadFailFiles.length; j++){
				if(isNull(_uploadFailFiles[j])) continue;
				if(list[i].value.indexOf(_uploadFailFiles[j]) >= 0){
					isFail = true;
					break;
				}
			}
			if(!isFail) target.removeChild(list[i].parentNode);

		}
		
		resetFormContainer(_formContainer, "display", "");
		returnValue = __uploadReturnText.replace("{1}", _uploadFailFiles);
		returnValue = returnValue.replace("{2}", s);
		displayInfo(returnValue, "ErrorMsg");
		
	}
};

function displayInfo(text, cssClass){
	text = text.replace(/[\r|\n]+/, "<br />");
	var info = getObject("infoText2993289744");
	info.className = cssClass;
	info.innerHTML = text;
};

function doUploadFiles(){
	_uploadSuccessFiles = [];
	_uploadFailFiles = [];
    var formObject = getObject(_fileContainer);
    
    YAHOO.util.Connect.setForm(formObject, true);
    
     var url = "/UploadFilesHandler.aspx?id=" + __portalId + "&key=file" ;
  
    YAHOO.util.Connect.asyncRequest('POST', url, uploadCallback);
  
	resetFormContainer("upLoading", "display", "none");
	
};

function resetFormContainer(s, k, v){
	var obj = getObject("itemTemplate892283732");
	obj.className = s;
	var list = obj.childNodes;
	YAHOO.util.Dom.setStyle("doUpload23832923", k, v);
	for(var i=0; i<list.length; i++){
		YAHOO.util.Dom.setStyle(list[i], k, v);
	}
};

function doCloseFiles(){
    var o = getObject(_formContainer);
    document.body.removeChild(o);
    eval(__uploadsucessCallback);
	
};

function getFileItems(){
    var target = getObject(_fileContainer);
    return YAHOO.util.Dom.getElementsByClassName("cssClassInputItem", "input", target);
};

function resetStatus(index){
    try{
        var btn = getObject("doUpload23832923");
       
        btn.style.display = "";
        var old = getObject("file_" + index);
        var list = getFileItems();
        var o = true;
        for(var i=0; i<list.length; i++){
            YAHOO.util.Dom.setStyle(list[i].parentNode, "backgroundColor", "");
            if(list[i] != old && list[i].value == old.value){
               // alert(__fileExist.replace('\{0\}', old.value));
                YAHOO.util.Dom.setStyle(list[i].parentNode, "backgroundColor", "#00FF00");
                YAHOO.util.Dom.setStyle(old.parentNode, "backgroundColor", "#FF0000");
                btn.style.display = "none";
                return false;
            }
        }
    }catch(e){}
   
    return true;
};
function isNull(value){
    try{
        if(typeof value == "undefined" || value == null){
            return true;
       }
    }catch(e){
        return true;
   } 
    return false;
}
function addNextFile(index, noreset){
   
    if(noreset != true && !resetStatus(index)) return;
    var list = getFileItems();
   
    if(list.length > 7) return;
    index++;
    var obj = getObject("file_" + index);
   
    if(isNull(obj)){
        var target = getObject(_fileContainer);
        var newObj = formItem(index);
        target.appendChild(newObj);
    }
};

function removeFormItem(index){
    var obj = getObject("file_" + index);
    var list = getFileItems();
    var btn = getObject("doUpload23832923");
    if(!isNull(obj) && obj.value.length > 0){
        var bg = YAHOO.util.Dom.getStyle(obj.parentNode, "backgroundColor");
        if(bg.length > 0){
            for(var i=0; i<list.length; i++){
                if(list[i] != obj && list[i].value == obj.value){
                    YAHOO.util.Dom.setStyle(list[i].parentNode, "backgroundColor", "");
                    YAHOO.util.Dom.setStyle(obj.parentNode, "backgroundColor", "");
                    btn.style.display = "";
                }
            }
        }
        var target = getObject(_fileContainer);
        target.removeChild(obj.parentNode);
    }
    var o = true;
    for(var i=0; i<list.length; i++){
        if(list[i].value == ""){
            o = false;
        }
    }
    if(o){
        addNextFile(index+8, true);
    }
};

function buidUploadForm(){
    var o=document.createElement("div");
	o.id="itemTemplate892283732";
    var form = document.createElement("form");
    form.id = _fileContainer;
	form.name = _fileContainer;
    var target = formItem(1);
    form.appendChild(target);
    o.appendChild(form);
    return o;
};

function formItem(index){
    var o = document.createElement("div");
    YAHOO.util.Event.addListener(o, "mouseover", function(){YAHOO.util.Dom.setStyle(this, 'border', '1px solid #404040');});
    YAHOO.util.Event.addListener(o, "mouseout", function(){YAHOO.util.Dom.setStyle(this, 'border', '1px solid #D4D0C8');});
    o.className = "formItem";
    o.innerHTML = "<label class='uploadFileTextStyle'>" + __uploadFileText + "</label><input class=\"cssClassInputItem\" type=\"file\" id=\"file_" + index + "\" name=\"file_" + index + "\" onchange=\"addNextFile(" + index + ");\" /> <a href=\"javascript:void(0);\" onclick=\"removeFormItem(" + index + ");\"> <img src=\"/Tools/images/close_window.jpg\" width=\"11\" height=\"11\" border=\"0\" /></a>";
    return o;
};


function Add(controls, trim)  
{ 
    _uploadFiletext=controls;
   
    showSelector();
   
}
function showSelector(){  
   
    showImageSelector(_uploadFiletext,null,"javascript:void(0);","openUpload");
}
function openUpload(){

   

    showUploadControl("showSelector()")
    window.setTimeout("showMask()",200);
   
   
}

function DeleteOneRecordUpdatePenl()
{
  
  var chkboxtemp=document.getElementsByName("chk_select");
  var pageIndex=(document.getElementById("ddlPage"));
  var pageSize=(document.getElementById("txtPageSize"));
  var index=pageIndex.value; 
  var length=chkboxtemp.length;//当前页面纪录数

  if(length==1)
    {
     index=index-1;
    }
  GetPageContent(index,pageSize.value);
}

function DeleteRecordsUpdatePenl(length,j)
{
    var pageIndex=(document.getElementById("ddlPage"));
    var pageSize=(document.getElementById("txtPageSize")); 
    var index=pageIndex.value; 
    if(j==length)
       {
         index=index-1;
       }
    GetPageContent(index,pageSize.value);
 }
 
 function AddOrEditRecordsUpdatePenl()
 {
    var pageIndex=(document.getElementById("ddlPage"));
    var pageSize=(document.getElementById("txtPageSize"));
    if(pageIndex==null||pageSize==null)
    {
      GetPageContent(1,15);
    }
    else{
    GetPageContent(pageIndex.value,pageSize.value);
    }
 }
 
/**********************************可编辑的list下拉菜单******************************************/
 
 //增加列表的值
function addlistvalue()
{
   var text=document.getElementById("categoryname");
   var list1 = $("editselect");
   var opNode = document.createElement("option");
   var value=text.value.replace(/(^\s*)|(\s*$)/g,"");
   if(value=="")
     {
      alert(__isnull);
      return;
     }
   if(!IsExistValue(value,-1))//检查是否存在相同的Text
     {
         alert(__existevlue);
         return;
     }      
   opNode.text =value;
   opNode.value ="0";
   list1.options.add(opNode);
   text.value="";
   getmodelist();
   list1.selectedIndex=-1;
  
   
}
//得到列表的string值
function getmodelist()
{
  var hiddelist=document.getElementById("hiddelist");
  var string="[";
  var list1 = $("editselect");
  var length=list1.options.length;
  for(var i=0;i<length;i++)
  {
   if(i>0)string+=",";
   string+="{\"ID\":\""+list1.options[i].value+"\", \"Name\":\""+list1.options[i].text+"\"}";
   
  }
  string+="]";
  hiddelist.value=string;
  
}
//编辑列表
function editlistvalue()
{
   var objTable =$("editselect");
   var editcontrol=document.getElementById("edit");
   var text=document.getElementById("categoryname");
   var index=objTable.selectedIndex;
   var value=text.value.replace(/(^\s*)|(\s*$)/g,"");
    if(value=="")
       {
         alert(__isnull);
         return;
        }
     if(!IsExistValue(value,index))//检查是否存在相同的Text
     {
         alert(__existevlue);
         return;
     }    
     objTable[index].text=value;
     text.value="";
     objTable.selectedIndex=-1;
     getmodelist();
     Cancle();
     
    
} 
//删除列表中的值
function deletevalue()
{
  var editcontrol=document.getElementById("edit");
  var objTable =$("editselect");
  var index=objTable.selectedIndex;
  if(index<0)
     {
      alert(__noSelect);
      return;
     }
  var isdelete=confirm(__isDelete);
  if(isdelete)
   {
     objTable.remove(index);
     objTable.selectedIndex=-1;
     getmodelist();
     Cancle();
   }
}
//操作列表的取消
function Cancle()
{
  var addcontrol=document.getElementById("Add");
  var editcontrol=document.getElementById("edit");
  var delecontrol=document.getElementById("deleteid");
  var canccontrol=document.getElementById("cancleid");
  addcontrol.disabled="";
  delecontrol.disabled="disabled";
  canccontrol.disabled="disabled";
  editcontrol.disabled="disabled";
  var text=document.getElementById("categoryname");
  text.value="";
  var objTable =$("editselect");
  objTable.selectedIndex=-1;
 
}

function IsExistValue(value,index)
{
  var list1 = $("editselect");
  var length=list1.options.length;
  for(var i=0;i<length;i++)
  {
   if(index!=i&&list1.options[i].text==value) return false;
   
  }
  return true;
}

function onchanged()
{
  var addcontrol=document.getElementById("Add");
  var editcontrol=document.getElementById("edit");
  var delecontrol=document.getElementById("deleteid");
  var canccontrol=document.getElementById("cancleid");
  addcontrol.disabled="disabled";
  delecontrol.disabled="";
  canccontrol.disabled="";
  editcontrol.disabled="";
  var text=document.getElementById("categoryname");
  var objTable =$("editselect");
  var index=objTable.selectedIndex;
  text.value=objTable[index].text;
}
/*********************************************************************************************/

function getScroll()  {     var t, l, w, h;          if (document.documentElement && document.documentElement.scrollTop) {         t = document.documentElement.scrollTop;         l = document.documentElement.scrollLeft;         w = document.documentElement.scrollWidth;         h = document.documentElement.scrollHeight;     } else if (document.body) {         t = document.body.scrollTop;         l = document.body.scrollLeft;         w = document.body.scrollWidth;         h = document.body.scrollHeight;     }     return { top: t, left: l, width: w, height: h }; } 

function getFixXY(width,height){
      var scoll=getScroll();
	  var x = parseInt((YAHOO.util.Dom.getViewportWidth() - (""+width).replace("px", ""))/2);
	  var y = parseInt((YAHOO.util.Dom.getViewportHeight() - (""+height).replace("px", ""))/2)+scoll.top;
	  return {x:x,y:y};	
}


if(typeof(campton) == "undefined")
	var campton = {};
campton.dialogs = function(o, className, closeEvent){
    if(typeof(closeEvent) == "undefined") closeEvent = "void(0);";
	this.dialogsStr = "<div class=\"" + className + "\"> <div class=\"hd\">  <div class=\"title\">{$title}</div>  <div class=\"close\"><img src=\"/tools/images/close_window.jpg\" alt=\"\" bode=\"0\" onclick=\"" + closeEvent + "\" /></div> </div> <div id=\"divBodyForDeleteCategory\" class=\"bd\">{$content}</div><div class=\"ft\">{$footer}</div></div>";
	this.outStr = this.dialogsStr;
	this.title = "";
	this.content = "";
	this.footer = "";
	this.container=null;

	this.render(o);

	this.body = $("divBodyForDeleteCategory");
}
campton.dialogs.prototype = {
	setTitle:function(strTitle){
		this.title = strTitle;
        this.replaceTag();
	},
	setContent:function(strContent){
		this.content = strContent;
        this.replaceTag();
	},
	setFooter:function(strFooter){
		this.footer = strFooter;
        this.replaceTag();
	},
	replaceTag:function()
	{
	    var strResult = this.dialogsStr.replace("{$title}", this.title).replace("{$content}", this.content).replace("{$footer}", this.footer);

	    this.container.innerHTML = strResult;
	    this.body = $("divBodyForDeleteCategory");
	},
	render:function(o){
         
		if(typeof(o) == "string") o = $(o);
		if(typeof(o) != "object" || o.innerHTML == null) return;
		
		this.container=o;

		o.innerHTML = this.outStr;

		this.replaceTag()
	}
}