var ocolorPopup = window.createPopup();
var ecolorPopup=null;
var resizeWin = null;
var xWins={};
var xIdx = 0;  //used to mark xWins's size;
var xIndex = 1; //used to mark z-index;
var x0=0,y0=0,x1=0,y1=0;
var rightboundary=0;
var leftboundary=-200;

//-------menu operations-------------//
function showMenu(alink, index){
	alink.style.background = "url(images/navigator" + index + "/tab_left_on.gif) no-repeat left top";
	alink.style.color = "#ffffff";
	alink.parentElement.style.background = "url(images/navigator" + index + "/tab_right_on.gif) no-repeat right top";
}

function hideMenu(alink, index){
	alink.style.background = "url(images/navigator" + index + "/tab_left.gif) no-repeat left top";
	alink.style.color = "#ffffff";
	alink.parentElement.style.background = "url(images/navigator" + index + "/tab_right.gif) no-repeat right top";
}

//--------colordialog operations-----//
function colordialogmouseout(obj){
    obj.style.borderColor="";
    obj.bgColor="";
}

function colordialogmouseover(obj){
    obj.style.borderColor="#0A66EE";
    obj.bgColor="#EEEEEE";
}

function colordialogmousedown(color){
    ecolorPopup.value=color;
    //document.body.bgColor=color;
    ocolorPopup.document.body.blur();
}

function colordialogmore(){
    var sColor=dlgHelper.ChooseColorDlg(ecolorPopup.value);
    sColor = sColor.toString(16);
    if (sColor.length < 6) {
        var sTempString = "000000".substring(0,6-sColor.length);
        sColor = sTempString.concat(sColor);
    }
    ecolorPopup.value="#"+sColor.toUpperCase();
    //document.body.bgColor="#"+sColor.toUpperCase();
    ocolorPopup.document.body.blur();
}

function colordialog(){
    var e=event.srcElement;
    e.onkeyup=colordialog;
    ecolorPopup=e;
    var ocbody;
    var oPopBody = ocolorPopup.document.body;
    var colorlist=new Array(40);
    oPopBody.style.backgroundColor = "#f9f8f7";
    oPopBody.style.border = "solid #999999 1px";
    oPopBody.style.fontSize = "12px";
	//oPopBody.style.left = event.clientX + "px";
	//oPopBody.style.top = event.clientY + "px";

    colorlist[0]="#000000";    colorlist[1]="#993300";    colorlist[2]="#333300";    colorlist[3]="#003300";
    colorlist[4]="#003366";    colorlist[5]="#000080";    colorlist[6]="#333399";    colorlist[7]="#333333";

    colorlist[8]="#800000";    colorlist[9]="#FF6600";    colorlist[10]="#808000";colorlist[11]="#008000";
    colorlist[12]="#008080";colorlist[13]="#0000FF";colorlist[14]="#666699";colorlist[15]="#808080";

    colorlist[16]="#FF0000";colorlist[17]="#FF9900";colorlist[18]="#99CC00";colorlist[19]="#339966";
    colorlist[20]="#33CCCC";colorlist[21]="#3366FF";colorlist[22]="#800080";colorlist[23]="#999999";

    colorlist[24]="#FF00FF";colorlist[25]="#FFCC00";colorlist[26]="#FFFF00";colorlist[27]="#00FF00";
    colorlist[28]="#00FFFF";colorlist[29]="#00CCFF";colorlist[30]="#993366";colorlist[31]="#CCCCCC";

    colorlist[32]="#FF99CC";colorlist[33]="#FFCC99";colorlist[34]="#FFFF99";colorlist[35]="#CCFFCC";
    colorlist[36]="#CCFFFF";colorlist[37]="#99CCFF";colorlist[38]="#CC99FF";colorlist[39]="#FFFFFF";

    ocbody = "";
    ocbody += "<table CELLPADDING=0 CELLSPACING=3>";
    ocbody += "<tr height=\"20\" width=\"20\"><td align=\"center\"><table style=\"border:1px solid #808080;\" width=\"12\" height=\"12\" bgcolor=\""+e.value+"\"><tr><td></td></tr></table></td><td bgcolor=\"eeeeee\" colspan=\"7\" style=\"font-size:12px;\" align=\"center\">当前颜色</td></tr>";
    
	for(var i=0;i < colorlist.length;i++){
        if(i%8==0)
            ocbody += "<tr>";
        ocbody += "<td width=\"14\" height=\"16\" style=\"border:1px solid;\" onMouseOut=\"parent.colordialogmouseout(this);\" onMouseOver=\"parent.colordialogmouseover(this);\" onMouseDown=\"parent.colordialogmousedown('"+colorlist[i]+"')\" align=\"center\" valign=\"middle\"><table style=\"border:1px solid #808080;\" width=\"12\" height=\"12\" bgcolor=\""+colorlist[i]+"\"><tr><td></td></tr></table></td>";
        if(i%8==7)
            ocbody += "</tr>";
    }
    ocbody += "<tr><td align=\"center\" height=\"22\" colspan=\"8\" onMouseOut=\"parent.colordialogmouseout(this);\" onMouseOver=\"parent.colordialogmouseover(this);\" style=\"border:1px solid;font-size:12px;cursor:default;\" onMouseDown=\"parent.colordialogmore()\">其它颜色</td></tr>";
    ocbody += "</table>";

    oPopBody.innerHTML=ocbody;
	ocolorPopup.show(event.clientX, event.clientY, 158, 147, document.body);
    //ocolorPopup.show(e.offsetLeft, e.offsetTop+e.offsetHeight, 158, 147, document.body);
}

//------generate operations-----//

function setFocus(name){
	var obj=document.getElementById(name);
	obj.style.zIndex=xIndex;
	xIndex++;
}

function getScreenWidth(){
	return(document.body.clientWidth-5);
}

function getScreenHeight(){
	return(document.body.clientHeight-4);
}

function mouseObserver(event){
  var e=event || window.event;
  writeStatus(e);
}
	
function writeStatus(e){
  window.status=e.clientX+","+e.clientY;
}

function buildPicture(fileName, width, height){
	var result = "";
	result = "<img src='Upload/" + fileName + "'";
	if(width != 0){
		result += " width='" + width + "'";
	}
	if(height != 0){
		result += " height='" + height + "'";
	}
	result += " border='0'/>";
	return result;
}

function buildFlash(fileName, width, height){
	var result = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" "
	result += "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\"";
	if(width != 0){
		result += " width=\""+width+"\"";
	}
	if(height != 0){
		result += " height=\""+height+"\"";
	}
	result += " ><param name=\"movie\" value=\"Upload/" + fileName + "\" ><param name=\"quality\" value=\"high\">"
				+ "<param name='wmode' value='transparent'>";
				+ "<embed src=\"Upload/"+fileName+"\"quality=\"high\"";
	if(width != 0){
		result += " width=\""+width+"\"";
	}
	if(height != 0){
		result += " height=\""+height+"\"";
	}
	result += " pluginspage=\"http://www.macromedia.com/go/getTopFlashplayer\" type=\"application/x-shockwave-flash\" wmode=\"transparent\"></embed></object>";
	//result = "<script>document.write('" + result + "');</script>"
	return result;
}

function LoadFlash(url,width,height)
{
	alert(url);
	result = "<embed src='Upload/" + url + "' wmode='transparent' quality='high' "
			 + "pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' "
			 + "width='" + width + "' height='" + height + "'></embed>";
	//result = "<script language='JScript'>document.write(\"" + result + "\")</script>";
	return result;
} 


function buildShowMedia(fileName, width, height){
	var result = "";
	if(fileName.indexOf("swf") != -1){
		result = buildFlash(fileName, width, height);
	}else{
		result = buildPicture(fileName, width, height);
	}
	return result;
}

//--------resize window operations------//

function startResize(name, evt){
	evt = evt ? evt : (window.event ? window.event : null);
	if(resizeWin==null){
		if(evt.button == 1 || evt.button == 0){
				var win=document.getElementById("xWin_"+name);
				x0 = evt.clientX;
				y0 = evt.clientY;
				x1 = win.offsetWidth;
				y1 = win.offsetHeight - 6;
				resizeWin=name;
				
		}
	}
}

function resize(name,evt){
	var win=document.getElementById("xWin_"+name);
	var winTitle = document.getElementById("xTitle_" + name);
	var winCtrl = document.getElementById("xCtrl_" + name);
	var winHeader = document.getElementById("xHeader_" + name);
	var winBody = document.getElementById("xBody_" + name);
	var wLeft=parseInt(win.offsetLeft);
	var wTop=parseInt(win.offsetTop);
	var lastWidth = null;
	var lastHeight = null;
	var minWidth = 100;
	var minHeight = 50;
	
	evt = evt ? evt : (window.event ? window.event : null);
	if(evt){
		if(evt.button == 1 || evt.button == 0){
			if(resizeWin!=null){
				lastWidth=x1 + (evt.clientX - x0);
				lastHeight=y1 + (evt.clientY - y0);
				if(lastWidth<minWidth){
					lastWidth=minWidth;
				}
				if(lastHeight<minHeight){
					lastHeight=minHeight;
				}
				
				winTitle.style.width = (lastWidth - 60 - 2) + "px";
				winCtrl.style.left = (lastWidth - 60 - 1) + "px";
				winBody.style.height = (lastHeight - 40) + "px";
				win.style.width = lastWidth+"px";
				win.style.height  = lastHeight+"px";
				window.status="宽: " + lastWidth +"px  高: "+lastHeight + "px";
				xWins[name].setWidth(lastWidth);
				xWins[name].setHeight(lastHeight);
			}
		}
	}	
}

function stopResize(){
	resizeWin=null;
	window.status = "";
}

function _mouseUp(evt){	
	if(resizeWin!=null){
		resizeWin = null;
		stopResize();
	}
}

function _mouseMove(evt){	
	if(resizeWin!=null){
		resize(resizeWin,evt);
	}
}

//------------------slide menu bar utils-----------------//

function regenerate(){
	window.location.reload();
}

function regenerate2(){
	setTimeout("window.onresize=regenerate",400);
}

function pullordraw(){
	var contentDiv = document.getElementById("menucontent");
	if(contentDiv.innerHTML == ""){
		contentDiv.innerHTML = "加载数据中...";
	}
	
	if(window.pullit){
		draw();
	}else{
		pull();
	}
}

function pull(){
	if (window.drawit){
		clearInterval(drawit);
		drawit = null;
	}
	pullit=setInterval("pullEngine()",50);
}

function draw(){
	if (window.pullit){
		clearInterval(pullit);
		pullit = null;
	}	
	drawit=setInterval("drawEngine()",50);
}

function pullEngine(){
	var themenu = document.getElementById("slidemenubar");
	themenu.style.zIndex = xIndex + 1;
	if (document.all&&themenu.style.pixelLeft<rightboundary)
		themenu.style.pixelLeft+=5;
	else if(themenu.style.left<rightboundary)
		themenu.style.left+=5;
	else if (window.pullit)
		clearInterval(pullit);
}
	
function drawEngine(){
	var themenu = document.getElementById("slidemenubar");
	if (document.all&&themenu.style.pixelLeft>leftboundary)
		themenu.style.pixelLeft-=5;
	else if(themenu.style.left>leftboundary)
		themenu.style.left-=5;
	else if (window.drawit)
		clearInterval(drawit);
}

//---------------show select window dialog and create a new window operations---//
function newWin(pid, tdid, name, title, type){
	var win = new dragonzl.xWin(pid, tdid, name, title, type);
	win.Build4Edit();
	xWins[xIdx] = win;
	var winDiv = document.getElementById("xWin_" + name);
	xWins[xIdx].setWidth(winDiv.offsetWidth);
	xIdx++;
	
	//delete win;
}

function initialWin(dbId, pid, tdid, name, title, type){
	var win = new dragonzl.xWin(pid, tdid, name, title, type);
	win.setDbId(dbId);
	
	win.Build4Edit();
	var winDiv = document.getElementById("xWin_" + name);
	win.setWidth(winDiv.offsetWidth);
	xWins[name] = win;	
	//alert("xWins[" + name + "]" + xWins[name]);
	if(xIdx < name){
		xIdx = name + 1;
	}else{
		xIdx++;
	}	
	//delete win;
}

function initialWin4Show(dbId, pid, tdid, name, title, type){
	//alert(dbId + " : " + pid + " : " + tdid + " : " + name + " : " + title + " : " + type);
	var win = new dragonzl.xWin(pid, tdid, name, title, type);
	win.setDbId(dbId);
	
	//win.Build4Show();
	var winDiv = document.getElementById("xWin_" + name);
	//alert("xWin_" + name + " : " + winDiv);
	win.setWidth(winDiv.offsetWidth);
	xWins[name] = win;	
	if(xIdx < name){
		xIdx = name + 1;
	}else{
		xIdx++;
	}
	//var container = document.getElementById(tdid);
	//alert(container.innerHTML);
}

function initialWin4Preview(dbId, pid, tdid, name, title, type){
	var win = new dragonzl.xWin(pid, tdid, name, title, type);
	win.setDbId(dbId);
	
	win.Build4Show();
	var winDiv = document.getElementById("xWin_" + name);
	win.setWidth(winDiv.offsetWidth);
	xWins[name] = win;	
	if(xIdx < name){
		xIdx = name + 1;
	}else{
		xIdx++;
	}
}
//----------------delete window operations-----//
function deleteWin(tdid, name){
	var container = document.getElementById(tdid);
	var winDiv = document.getElementById("xWin_" + name);
	if(confirm("您确定要删除该窗口")){
		container.removeChild(winDiv);
		if(container.innerHTML == ""){
			container.innerHTML = "&nbsp;";
		}
		if(xWins[name].dbId != null){
			var winId = xWins[name].dbId;
			PageService.deleteWindow(winId, deleteWindowCallBack);
		}		
		xWins[name] = null;
	}	
}

function deleteWindowCallBack(){
	alert("删除完成");
}

//------------show config window dialog and do config window style operations-----//
function decorateWindow(wid, isTitleShow, position, titleBgColor, titleFontColor, borderWidth, borderType, borderColor, bgColor, css, winLeft, winTop, width, height, background, titleBackground){
	var winDiv = document.getElementById("xWin_" + wid);
	var winHeaderDiv = document.getElementById("xHeader_" + wid);
	var winTitleSpan = document.getElementById("xTitle_" + wid);
	var winCtrlSpan = document.getElementById("xCtrl_" + wid);
	var winBodyDiv = document.getElementById("xBody_" + wid);
		
	xWins[wid].setIsTitleShow(isTitleShow);
	xWins[wid].setPosition(position);
	xWins[wid].setBorderWidth(borderWidth);
	xWins[wid].setBorderColor(borderColor);
	xWins[wid].setBorderType(borderType);
	xWins[wid].setBgColor(bgColor);
	xWins[wid].setWidth(width);
	xWins[wid].setHeight(height);
	xWins[wid].setCss(css);
	xWins[wid].setBackground(background);
	xWins[wid].setTitleBackground(titleBackground);
	
	if(position == "absolute"){		
		xWins[wid].setWinLeft(winLeft);
		xWins[wid].setWinTop(winTop);
	}
	if(isTitleShow == 1){
		xWins[wid].setTitleBgColor(titleBgColor);
		xWins[wid].setTitleFontColor(titleFontColor);
	}
	var border = borderWidth + "px " + borderType + " " + borderColor;
	var mainCssStr = "position:" + position + "; border:" + border + "; width:" + width + "px; height:" + height + "px;";
	if(bgColor != ""){
		 mainCssStr += "background-color:" + bgColor + ";";
	}
	if(css != "")
		mainCssStr += css;
	
	if(position == "absolute"){
		mainCssStr += "left:" + winLeft + "px; top:" + winTop + "px;";
	}	
	winDiv.style.cssText = mainCssStr;
	var titleCssStr = "width:"+(width-60-2)+"px;";	
	if(isTitleShow == 1){		
		var headerStyle = "";
		if(titleBgColor != ""){
			headerStyle += "background-color:" + titleBgColor + ";";
		}
		if(titleBackground != ""){
			 headerStyle += "background:" + titleBackground + ";"
		}
		winHeaderDiv.style.cssText = headerStyle;
		titleCssStr += "color:" + titleFontColor + ";";			
	}else{
		winTitleSpan.innerHTML = "";
	}
	winTitleSpan.style.cssText = titleCssStr;	
	var bodyStyle = "height:" + (height-40) + "px;";	
	if(background != "")
		bodyStyle += "background:" + background + ";";
	winBodyDiv.style.cssText = bodyStyle;
	winCtrlSpan.style.cssText = "left:"+(width-1-60)+"px;top:"+0+"px;";
	
}

function decorateWindow4Show(wid, isTitleShow, position, titleBgColor, titleFontColor, borderWidth, borderType, borderColor, bgColor, css, winLeft, winTop, width, height, background, titleBackground){
	xWins[wid].setIsTitleShow(isTitleShow);
	xWins[wid].setPosition(position);
	xWins[wid].setBorderWidth(borderWidth);
	xWins[wid].setBorderColor(borderColor);
	xWins[wid].setBorderType(borderType);
	xWins[wid].setBgColor(bgColor);
	xWins[wid].setWidth(width);
	xWins[wid].setHeight(height);
	xWins[wid].setCss(css);
	xWins[wid].setBackground(background);
	xWins[wid].setTitleBackground(titleBackground);
}

function decorateWindow4Preview(wid, isTitleShow, position, titleBgColor, titleFontColor, borderWidth, borderType, borderColor, bgColor, css, winLeft, winTop, width, height, background, titleBackground){
	var winDiv = document.getElementById("xWin_" + wid);	
	var winHeaderDiv = document.getElementById("xHeader_" + wid);
	var winBodyDiv = document.getElementById("xBody_" + wid);
	//alert(winDiv + " : " + winHeaderDiv + " : " + winBodyDiv);	
	xWins[wid].setIsTitleShow(isTitleShow);
	xWins[wid].setPosition(position);
	xWins[wid].setBorderWidth(borderWidth);
	xWins[wid].setBorderColor(borderColor);
	xWins[wid].setBorderType(borderType);
	xWins[wid].setBgColor(bgColor);
	xWins[wid].setWidth(width);
	xWins[wid].setHeight(height);
	xWins[wid].setCss(css);
	xWins[wid].setBackground(background);
	xWins[wid].setTitleBackground(titleBackground);
	
	if(position == "absolute"){		
		xWins[wid].setWinLeft(winLeft);
		xWins[wid].setWinTop(winTop);
	}
	if(isTitleShow == 1){
		xWins[wid].setTitleBgColor(titleBgColor);
		xWins[wid].setTitleFontColor(titleFontColor);
	}
	
	var border = borderWidth + "px " + borderType + " " + borderColor;
	var mainCssStr = "position:" + position + "; border:" + border + "; width:" + width + "px;";
			
	if(bgColor != ""){
		mainCssStr += "background-color:" + bgColor + ";";
	}
	if(css != ""){
		mainCssStr += css;
	}	
	if(position == "absolute"){
		mainCssStr += "left:" + winLeft + "px; top:" + winTop + "px;";
	}			
	if(isTitleShow == 1){				
		var headerStyle = "color:" + titleFontColor + ";";
		if(titleBgColor != ""){
			headerStyle += "background-color:" + titleBgColor + ";";
		}
		if(titleBackground != "")
			headerStyle += "background:" + titleBackground + ";";
		winHeaderDiv.style.cssText = headerStyle;		
		mainCssStr += "height:" + (height-20) + "px;";
	}else{
		winDiv.removeChild(winHeaderDiv);		
		mainCssStr += "height:" + (height-40) + "px;";
	}
	var bodyStyle = "height:" + (height-40) + "px;";
	if(background != "")
		bodyStyle += "background:" + background + ";";
	winBodyDiv.style.cssText = bodyStyle;	
	winDiv.style.cssText = mainCssStr;
}

//-----------data bind operations-----------------//
function startContentBind(name){
	xWins[name].contentBindPanal();
}

//-----------bind image operation---------------//
	
function showImageBinded(winName, imgId, imgLink, imgSource, width, height){
	xWins[winName].contentId = imgId;
	xWins[winName].imageWidth = width;
	xWins[winName].imageHeight = height;
	var winBody = document.getElementById("xBody_" + winName);
	if(winBody){
		if(imgLink != ""){
			winBody.innerHTML = "<a href='" + imgLink + "'>" + buildShowMedia(imgSource, width, height) + "</a>";
		}else{
			winBody.innerHTML = buildShowMedia(imgSource, width, height);
		}
	}		
}

//-----------bind html operation---------------//

function showHTMLBinded(winName, htmlContent){
	//alert(winName);
	xWins[winName].html = htmlContent;	
	var winBody = document.getElementById("xBody_" + winName);
	//alert("[" + htmlContent + "]");
	if(winBody)
		winBody.innerHTML = htmlContent;
}

//-----------bind content operation---------------//

function showContentBinded(contentId, winId, type, isParam, url, content, attachment){
	xWins[winId].contentType = type;
	xWins[winId].contentId = contentId;
	xWins[winId].url = url;
	xWins[winId].isParam = isParam;
	var winBody = document.getElementById("xBody_" + winId);
	var tempStr = "";
	if(content == null){
		winBody.innerHTML = "本窗口显示传值参数指定的值！！！由于未设置传值参数暂存值，故不显示具体内容！！！";
	}else{	
		if(type == 0){
			tempStr = content.content + "<br>" + attachment;
			if(isParam == 1){
				var winHeader = document.getElementById("xTitle_" + winId);
				if(winHeader != null){
					if(xWins[winId].isTitleShow == 1){
						winHeader.innerHTML = xWins[winId].title;
					}else{
						winHeader.innerHTML = "";
					}
					
				}else{
					winHeader = document.getElementById("xHeader_" + winId);
					if(winHeader != null)
						winHeader.innerHTML = content.title;
				}				
				
			}
		}else if(type == 1){
			if(isParam == 1){
				var winHeader = document.getElementById("xTitle_" + winId);
				if(winHeader != null){
					if(xWins[winId].isTitleShow == 1){
						winHeader.innerHTML = xWins[winId].title;
					}else{
						winHeader.innerHTML = "";
					}
				}else{
					winHeader = document.getElementById("xHeader_" + winId);
					if(winHeader != null)
						winHeader.innerHTML = content.title;
				}				
				
			}
			tempStr = content.summary + "<br>";
			tempStr += "--<a href='" + url + "?id=" + contentId + "' target='blank'>阅读全文</a>";
		}else if(type == 2){
			if(url == ""){
				tempStr = "<span class='titlestyle'>" + content.title + "</span>";
			}else{
				tempStr = "<span class='titlestyle'><a href='" + url + "?id=" + contentId + "'>" + content.title + "</a></span>";
			}			
		}
		winBody.innerHTML = tempStr;
	}	
}

//-----------bind category operation---------------//
function showCategoryBinded(categoryId, winId, type, isPage, line, url, isParam, point, bgColor, color, isAddTime, isMarquee, marqueeDirect, subtitle, category){
	xWins[winId].contentId = categoryId;
	xWins[winId].contentType = type;
	xWins[winId].isPage = isPage;
	xWins[winId].line = line;
	xWins[winId].url = url;
	xWins[winId].isParam = isParam;
	xWins[winId].categoryPoint = point;
	xWins[winId].categoryBgColor = bgColor;
	xWins[winId].categoryFontColor = color;
	xWins[winId].isAddTime = isAddTime;
	xWins[winId].isMarquee = isMarquee;
	xWins[winId].marqueeDirect = marqueeDirect;
	xWins[winId].subtitle = subtitle;
	var winBody = document.getElementById("xBody_" + winId);
	if(winBody != null)
		winBody.innerHTML = category;
}

//----------show binded Navigator operation-------//
function previewNavigator(navDirect, navStyle, links){
	var previewArea = document.getElementById("NavigatorPreview");
	previewArea.innerHTML = "";
	var tempStr = "";
	if(links == ""){				
		if(navDirect == 0){
			tempStr += "<div id='LevelNavigator'><div id='LevelMenu'><ul>";
		}else{
			tempStr += "<div id='VerticalNavigator'><div id='VerticalMenu'><ul>";
		}
		tempStr += "<li style='background: url(images/navigator" + navStyle + "/tab_right.gif) no-repeat right top;'>";
		tempStr += "<a href='#' style='background: url(images/navigator" + navStyle + "/tab_left.gif) no-repeat left top;' onMouseOver='showMenu(this, " + navStyle + ")' onMouseOut='hideMenu(this, " + navStyle + ")'>导航链接</a></li>";
		tempStr += "<li style='background: url(images/navigator" + navStyle + "/tab_right.gif) no-repeat right top;'>";
		tempStr += "<a href='#' style='background: url(images/navigator" + navStyle + "/tab_left.gif) no-repeat left top;' onMouseOver='showMenu(this, " + navStyle + ")' onMouseOut='hideMenu(this, " + navStyle + ")'>导航链接</a></li>";
		tempStr += "</ul></div></div>";						
	}else{
		if(navDirect == 0){
			tempStr += "<div id='LevelNavigator'><div id='LevelMenu'><ul>";
		}else{
			tempStr += "<div id='VerticalNavigator'><div id='VerticalMenu'><ul>";
		}
		var linkArray = links.split("$");
		for(i=0;i<linkArray.length;i++){
			var items = linkArray[i].split(":");
			//alert("[" + items[0] + "] : [" + items[1] + "]");
			tempStr += "<li style='background: url(images/navigator" + navStyle + "/tab_right.gif) no-repeat right top;'>";
			tempStr += "<a href='" + items[1] + "' style='background: url(images/navigator" + navStyle + "/tab_left.gif) no-repeat left top;' onMouseOver='showMenu(this, " + navStyle + ")' onMouseOut='hideMenu(this, " + navStyle + ")'>" + items[0] + "</a></li>";
		}
		tempStr += "</ul></div></div>";
	}
	previewArea.innerHTML = tempStr;
	return tempStr;			
}

function getNavigatorHTML(navDirect, navStyle, links){
	var tempStr = "";
	if(links == ""){				
		if(navDirect == 0){
			tempStr += "<div id='LevelNavigator'><div id='LevelMenu'><ul>";
		}else{
			tempStr += "<div id='VerticalNavigator'><div id='VerticalMenu'><ul>";
		}
		tempStr += "<li style='background: url(images/navigator" + navStyle + "/tab_right.gif) no-repeat right top;'>";
		tempStr += "<a href='#' style='background: url(images/navigator" + navStyle + "/tab_left.gif) no-repeat left top;' onMouseOver='showMenu(this, " + navStyle + ")' onMouseOut='hideMenu(this, " + navStyle + ")'>导航链接</a></li>";
		tempStr += "<li style='background: url(images/navigator" + navStyle + "/tab_right.gif) no-repeat right top;'>";
		tempStr += "<a href='#' style='background: url(images/navigator" + navStyle + "/tab_left.gif) no-repeat left top;' onMouseOver='showMenu(this, " + navStyle + ")' onMouseOut='hideMenu(this, " + navStyle + ")'>导航链接</a></li>";
		tempStr += "</ul></div></div>";						
	}else{
		if(navDirect == 0){
			tempStr += "<div id='LevelNavigator'><div id='LevelMenu'><ul>";
		}else{
			tempStr += "<div id='VerticalNavigator'><div id='VerticalMenu'><ul>";
		}
		var linkArray = links.split("$");
		for(i=0;i<linkArray.length;i++){
			var items = linkArray[i].split(":");
			//alert("[" + items[0] + "] : [" + items[1] + "]");
			tempStr += "<li style='background: url(images/navigator" + navStyle + "/tab_right.gif) no-repeat right top;'>";
			tempStr += "<a href='" + items[1] + "' style='background: url(images/navigator" + navStyle + "/tab_left.gif) no-repeat left top;' onMouseOver='showMenu(this, " + navStyle + ")' onMouseOut='hideMenu(this, " + navStyle + ")'>" + items[0] + "</a></li>";
		}
		tempStr += "</ul></div></div>";
	}
	return tempStr;			
}

function showNavigatorBinded(winId, style, direct, links){
	xWins[winId].navStyle = style;
	xWins[winId].navDirect = direct;
	xWins[winId].links = links;
	var winBody = document.getElementById("xBody_" + winId);	
	if(winBody)		
		winBody.innerHTML = getNavigatorHTML(direct, style, links);	
}

//---------toolkid operations -----------//

function saveWins(btn){
	if(confirm("您确定要保存吗？")){
		for(i=0; i < xIdx; i++){
			if(xWins[i] != null){
				if(xWins[i].dbId == null){
					if(i == (xIdx-1)){
						PageService.newWindow(xWins[i].name, xWins[i].title, xWins[i].type, xWins[i].page, xWins[i].container, newLastWinCallBack);
					}else{
						PageService.newWindow(xWins[i].name, xWins[i].title, xWins[i].type, xWins[i].page, xWins[i].container, newWinCallBack);
					}
					
				}else{
					if(i == (xIdx-1)){
						PageService.updateWindow(xWins[i].dbId, xWins[i].name, xWins[i].title, xWins[i].type, xWins[i].page, xWins[i].container, updateWinCallBack);
						xWins[i].saveBindedData();
						PageService.saveStyle(xWins[i].dbId, xWins[i].name, xWins[i].isTitleShow, xWins[i].position, xWins[i].titleBgColor, xWins[i].titleFontColor, xWins[i].borderWidth, xWins[i].borderColor, xWins[i].borderType, xWins[i].bgColor, xWins[i].css, xWins[i].winLeft, xWins[i].winTop, xWins[i].width, xWins[i].height, xWins[i].background, xWins[i].titleBackground, saveLastStyleCallBack);

					}else{
						PageService.updateWindow(xWins[i].dbId, xWins[i].name, xWins[i].title, xWins[i].type, xWins[i].page, xWins[i].container, updateWinCallBack);
						xWins[i].saveBindedData();
						PageService.saveStyle(xWins[i].dbId, xWins[i].name, xWins[i].isTitleShow, xWins[i].position, xWins[i].titleBgColor, xWins[i].titleFontColor, xWins[i].borderWidth, xWins[i].borderColor, xWins[i].borderType, xWins[i].bgColor, xWins[i].css, xWins[i].winLeft, xWins[i].winTop, xWins[i].width, xWins[i].height, xWins[i].background, xWins[i].titleBackground, saveStyleCallBack);
					}
				}	
			}		
		}
	}	
}

function newWinCallBack(data){
	xWins[data.name].setDbId(data.id);
	xWins[data.name].saveBindedData();
	PageService.saveStyle(xWins[data.name].dbId, data.name, xWins[data.name].isTitleShow, xWins[data.name].position, xWins[data.name].titleBgColor, xWins[data.name].titleFontColor, xWins[data.name].borderWidth, xWins[data.name].borderColor, xWins[data.name].borderType, xWins[data.name].bgColor, xWins[data.name].css, xWins[data.name].winLeft, xWins[data.name].winTop, xWins[data.name].width, xWins[data.name].height, xWins[data.name].background, xWins[data.name].titleBackground, saveStyleCallBack);
}

function newLastWinCallBack(data){
	xWins[data.name].setDbId(data.id);
	xWins[data.name].saveBindedData();
	PageService.saveStyle( xWins[data.name].dbId, data.name, xWins[data.name].isTitleShow, xWins[data.name].position, xWins[data.name].titleBgColor, xWins[data.name].titleFontColor, xWins[data.name].borderWidth, xWins[data.name].borderColor, xWins[data.name].borderType, xWins[data.name].bgColor, xWins[data.name].css, xWins[data.name].winLeft, xWins[data.name].winTop, xWins[data.name].width, xWins[data.name].height, xWins[data.name].background, xWins[data.name].titleBackground, saveLastStyleCallBack);
}

function saveStyleCallBack(){}

function saveLastStyleCallBack(){
	alert("页面已保存");
}

function updateWinCallBack(){}

//---------save binded data---------------//
function saveBindedImage(dbId, winId, contentId, imageWidth, imageHeight, method){
	//alert(dbId + " " + winId + " " + contentId + " " + imageWidth + " " + imageHeight + " " + method);
	PageService.saveBindedImage(dbId, winId, contentId, imageWidth, imageHeight, method, saveBindedDataCallBack);
}

function saveBindedHTML(dbId, winId, html, method){
	PageService.saveBindedHTML(dbId, winId, html, method, saveBindedDataCallBack);
}

function saveBindedContent(dbId, winId, contentId, isParam, contentType, url, method){
	PageService.saveBindedContent(dbId, winId, contentId, isParam, contentType, url, method, saveBindedDataCallBack);
}

function saveBindedCategory(dbId, winId, contentId, isParam, contentType, url, isPage, line, point, bgColor, color, isAddTime, isMarquee, marqueeDirect, subtitle, method){
	PageService.saveBindedCategory(dbId, winId, contentId, isParam, contentType, url, isPage, line, point, bgColor, color, isAddTime, isMarquee, marqueeDirect, subtitle, method, saveBindedDataCallBack);
}

function saveBindedNavigator(dbId, winId, style, direct, links, method){
	PageService.saveBindedNavigator(dbId, winId, style, direct, links, method, saveBindedDataCallBack);
}

function saveBindedDataCallBack(data){}

//------------get binded data ---------------//
function dataBind(id, type, cid){
	//alert(id + " : " + type + " : " + cid);
	if(type == 1){
		PageService.getBindedImageById(id, getBindedImageByIdCallBack);
	}else if(type == 2){
		PageService.getBindedHTMLById(id, getBindedHTMLByIdCallBack);
	}else if(type == 3){
		//alert(id + " : " + type + " : " + cid);
		PageService.getBindedContentById(id, cid, getBindedContentByIdCallBack);
	}else if(type == 4){
		PageService.getBindedCategoryById(id, cid, getBindedCategoryByIdCallBack);
	}else if(type == 5){
		PageService.getBindedNavigatorById(id, getBindedNavigatorByIdCallBack);
	}else{
		return;
	}
}

function getStyleByIdCallBack(data){
	//alert(data.winId+ " , " + data.isTitleShow+ " , " + data.winPosition+ " , " + data.titleBgColor+ " , " + data.titleFontColor+ " , " + data.borderWidth+ " , " + data.borderType+ " , " + data.borderColor+ " , " + data.bgColor+ " , " + data.css+ " , " + data.winLeft+ " , " + data.winTop+ " , " + data.width+ " , " + data.height);
	decorateWindow(data.winId, data.isTitleShow, data.winPosition, data.titleBgColor, data.titleFontColor, data.borderWidth, data.borderType, data.borderColor, data.bgColor, data.css, data.winLeft, data.winTop, data.width, data.height, data.background, data.titleBackground);
}

function getStyleByIdCallBack2(data){
	//alert(data.winId+ " , " + data.isTitleShow+ " , " + data.winPosition+ " , " + data.titleBgColor+ " , " + data.titleFontColor+ " , " + data.borderWidth+ " , " + data.borderType+ " , " + data.borderColor+ " , " + data.bgColor+ " , " + data.css+ " , " + data.winLeft+ " , " + data.winTop+ " , " + data.width+ " , " + data.height);
	
	decorateWindow4Show(data.winId, data.isTitleShow, data.winPosition, data.titleBgColor, data.titleFontColor, data.borderWidth, data.borderType, data.borderColor, data.bgColor, data.css, data.winLeft, data.winTop, data.width, data.height, data.background, data.titleBackground);
}

function getStyleByIdCallBack3(data){
	//alert(data.winId+ " , " + data.isTitleShow+ " , " + data.winPosition+ " , " + data.titleBgColor+ " , " + data.titleFontColor+ " , " + data.borderWidth+ " , " + data.borderType+ " , " + data.borderColor+ " , " + data.bgColor+ " , " + data.css+ " , " + data.winLeft+ " , " + data.winTop+ " , " + data.width+ " , " + data.height);
	
	decorateWindow4Preview(data.winId, data.isTitleShow, data.winPosition, data.titleBgColor, data.titleFontColor, data.borderWidth, data.borderType, data.borderColor, data.bgColor, data.css, data.winLeft, data.winTop, data.width, data.height, data.background, data.titleBackground);
}
	
function getBindedImageByIdCallBack(data){
	//alert(data.winId + " , " + data.imageId + " , " + data.link + " , " + data.source + " , " + data.width + " , " + data.height);
	if(data)
		showImageBinded(data.winId, data.imageId, data.link, data.source, data.width, data.height);
}
	
function getBindedHTMLByIdCallBack(data){
	if(data)
		showHTMLBinded(data.winId, data.html);	
}

function getBindedContentByIdCallBack(data){
	//alert(data.contentId + " , " + data.winId + " , " + data.type + " , " + data.isParam + " , " + data.url + " , " + data.summary);
	if(data){
		showContentBinded(data.contentId, data.winId, data.type, data.isParam, data.url, data.content, data.attachment);
	}
}	
		
function getBindedCategoryByIdCallBack(data){
	//alert(data.contentId + " , " + data.winId + " , " + data.type + " , " + data.isParam + " , " + data.url + " , " + data.summary);
	if(data){
		showCategoryBinded(data.categoryId, data.winId, data.type, data.isPage, data.line, data.url, data.isParam, data.point, data.bgColor, data.color, data.isAddTime, data.isMarquee, data.marqueeDirect, data.subtitle, data.category);
	}
}

function getBindedNavigatorByIdCallBack(data){
	if(data){
		showNavigatorBinded(data.winId, data.style, data.direct, data.links);
	}
}
	


