var topPadding = 0;

function pageInit() {
  try{
	changeway=parseInt(JSJaCCookie.read("changeway").getValue());
  }catch(e){
	changeway=0;
  }
  dd.elements.backFantom.setOpacity(0);
  document.getElementById("backFantom").style.zIndex = -1;
  document.getElementById("backFantom").style.display="";
  document.getElementById("main_frame").style.display="";
  var h=dd.getWndH()*0.8>330?330:dd.getWndH()*0.8;
  if(flag == 0){
	dd.elements.main_frameFantom.resizeTo(182, h);
	dd.elements.main_frame.resizeTo(182, h);
  }else{
	dd.elements.main_frameFantom.resizeTo(dd.elements.main_frame.w, h);
	dd.elements.main_frame.resizeTo(dd.elements.main_frame.w, h);
  }
  if(flag == 0){//web直接登录时用户列表窗口位置调整到任务条下方
	  dd.elements.main_frameFantom.moveTo(dd.getWndW()-dd.elements.main_frame.w-2, dd.getWndH() + dd.getScrollY() - dd.elements.main_frame.h - 32);
	  dd.elements.main_frame.moveTo(dd.getWndW()-dd.elements.main_frame.w-2, dd.getWndH() + dd.getScrollY() - dd.elements.main_frame.h - 32);
  }else{//在线感知等用户列表窗口位置调整
	  dd.elements.main_frameFantom.moveTo(dd.getWndW()-dd.elements.main_frame.w-20, dd.getScrollY() + 20);
	  dd.elements.main_frame.moveTo(dd.getWndW()-dd.elements.main_frame.w-20, dd.getScrollY() + 20);
  }
  document.getElementById("main_textDiv").style.width="100%";
  document.getElementById("main_textDiv").style.height="100%";
  var va = 0,vb = 26;
  dd.elements.main_windowButtons.moveTo(dd.elements.main_frame.x+dd.elements.main_frame.w-dd.elements.main_windowButtons.w-6, dd.elements.main_frame.y+va);
  dd.elements.main_resizehandle.moveTo(dd.elements.main_frame.x+dd.elements.main_frame.w-dd.elements.main_resizehandle.w-2, dd.elements.main_frame.y+dd.elements.main_frame.h-dd.elements.main_resizehandle.h-2);
  dd.elements.main_headerMovable.moveTo(dd.elements.main_frame.x, dd.elements.main_frame.y);
  dd.elements.main_headerMovable.resizeTo(dd.elements.main_frame.w-dd.elements.main_windowButtons.w-3, vb);
  //dd.elements.main_headerMovable.setOpacity(0);
  if(flag != 0){
  	dd.elements.service_logo.moveTo(dd.getWndW()-dd.elements.service_logo.w-2, (dd.getWndH()-dd.elements.service_logo.h-2)+dd.getScrollY());
  }
  var mainWindow = new Object();
  mainWindow.x = dd.elements.main_frame.x;
  mainWindow.y = dd.elements.main_frame.y;
  mainWindow.w = dd.elements.main_frame.w;
  mainWindow.h = dd.elements.main_frame.h;
  mainWindow.state = WINDOW_STATE_REGULAR;
  windowItems["main"] = mainWindow;
  if(arguments.length==0){
	  fmd = frames["main_iframe1"].iRoster.document;
	  if(is.ie)fmd.getElementById("roster").style.width = fmd.body.clientWidth;
	  objName = "main";
	  if(isNoFlash){
		  showWindowItem(objName);
		  windowMaximizeZ(objName);
	  }else{
		  /*if(typeof orgid == "undefined"){
			  dd.elements.service_logo.show();
		  }*/
	  }
  }
  if(flag == 0){
	dd.elements.taskbar.moveTo(0, dd.getWndH()+dd.getScrollY()-28);
	dd.elements.taskbar.resizeTo(dd.getWndW(), 28);
  	refreshTaskbar(); 
  }
  this.focus();
}

function incZ() {
  zValue = zValue + 5;
  return zValue;
}
function windowMaximizeZ(objName) {
  incZ();
  document.getElementById(objName + "_frameFantom").style.zIndex = zValue-2;
  document.getElementById(objName + "_frame").style.zIndex = zValue-1;
  document.getElementById(objName + "_frame_body").style.zIndex = zValue - 1;
  if(document.getElementById(objName + "_resizehandle"))
  document.getElementById(objName + "_resizehandle").style.zIndex = zValue;
  document.getElementById(objName + "_headerMovable").style.zIndex = zValue;
  document.getElementById(objName + "_windowButtons").style.zIndex=zValue;
  dd.elements[objName + "_windowButtons"].z = zValue+1;
  dd.elements[objName + "_headerMovable"].z = zValue+1;
}

function addTaskBarItem(windowId, taskbarItemName) {
  var obj = taskbarItems[windowId];
  if(obj==null) {
    obj = new Object();
    obj.windowId = windowId;
    obj.name = taskbarItemName;
    obj.state = TASKBAR_STATE_SELECTED;
    taskbarItems[windowId] = obj;
    if(dd.elements[windowId]==null) ADD_DHTML(windowId+CURSOR_HAND+NO_DRAG);
    document.getElementById(windowId).innerHTML = "<a href=\"###\">" + taskbarItemName + "</a>";
  }
  document.getElementById(windowId).style.visibility="visible";
  incZ();
  dd.elements[windowId].z = zValue;
  ACTIVE_OBJECTID = windowId;

  refreshTaskbar();
}

function removeTaskBarItem(windowId) {
  ACTIVE_OBJECTID =  "";

  var taskbarItem = taskbarItems[windowId + "_taskbarItem"];
  taskbarItem.visible = false;
  document.getElementById(windowId + "_taskbarItem").style.visibility="hidden";

  delete taskbarItems[windowId + "_taskbarItem"];

  refreshTaskbar();
}

function refreshTaskbar() {
  var totalLen=-2;
  //dd.elements["hide_taskbarItem"].moveTo(dd.getWndW()- 26, dd.getWndH()+ dd.getScrollY()-25);
  //dd.elements["hide_taskbarItem"].div.style.zIndex = 100000;
  //dd.elements["login_taskbarItem"].moveTo(dd.getWndW()- 99, dd.getWndH()+ dd.getScrollY()-25);
  //dd.elements["login_taskbarItem"].div.style.zIndex = 100000;
  var objCode = ACTIVE_OBJECTID;
  mark = objCode.indexOf("_");
  if(mark>0) objCode = objCode.substr(0,mark);

  i = 0;
  for (var n in taskbarItems) {
    var item = taskbarItems[n];
    if(typeof item=="function"){
        continue;
    }
    item.number = i;
    totalLen += dd.elements[item.windowId].w + 3;
    dd.elements[item.windowId].moveTo(dd.getWndW()- totalLen, dd.getWndH()+ dd.getScrollY()-26);
    dd.elements[item.windowId].div.style.zIndex = 100000;
    var itemCode = item.windowId;
    mark = itemCode.indexOf("_");
    if(mark>0) itemCode = itemCode.substr(0, mark);
    var obj = document.getElementById(item.windowId);
    var windowItem = document.getElementById(itemCode + "_frame");
    if(item.windowId=="login_taskbarItem"){
        
    }else if(item.windowId!=(objCode+"_taskbarItem")) {
      if(obj!=null && windowItem!=null) {
       /* if(item.state==TASKBAR_STATE_FLASH){
          windowItem.className = "im-window im-window-flash";
          obj.className = "im-taskbaritem-flash";
        }
        else {*/
        obj.className = "im-taskbaritem-des";
        item.state = TASKBAR_STATE_UNSELECTED;
      //windowItem.className = "im-window im-window-des";
        //}
      }
    }else {
      if(obj!=null && windowItem!=null) {
        //if(item.state==TASKBAR_STATE_FLASH) stopFlashWindow(itemCode);
        obj.className = "im-taskbaritem";
        item.state = TASKBAR_STATE_SELECTED;
        windowItem.className = "im-window common_border_color";

        windowMaximizeZ(itemCode);
      }
    }
    i++;
  }
}

function taskbarItemClick(objName) {
    if(!con || !con.connected()){
        document.getElementById("login_inner_div").style.background="url(" + basePath + "images/login.png) no-repeat scroll center center transparent";
        showWindowItem('login');
        windowMaximizeZ('login');
        return;
    }
  var objCode = objName;
  i = objCode.indexOf("_");
  objCode = objCode.substr(0,i);
  if(objCode=="login"){
      logout();
      return;
  }
  /*if(objCode=="openOptions" && dd.elements[objCode + "_frame"]==null){
    openOptions(1);
    return;
  }*/
  if(objCode=="openStatus" && dd.elements[objCode + "_frame"]==null){
    openChangeStatus(1);
    return;
  }
  if(objCode=="openSubscription" && dd.elements[objCode + "_frame"]==null){
      openSubscription();
      return;
  }
  if(document.getElementById("subRequestWindow").hasChildNodes() && objCode=="openSubscription"){
      return false;
  }
  if(document.getElementById("subscriptionWindow").hasChildNodes() && document.getElementById("subscriptionWindow").childNodes.length>1 && objCode=="openSubscription"){
      return false;
  }

  var obj = document.getElementById(objName);
  var taskbarItem = taskbarItems[objName];

  var windowItem = windowItems[objCode];

  if(obj!=null && taskbarItem!=null && windowItem.state!=WINDOW_STATE_POPOUT && objCode!="login") {
    if(taskbarItem.state==TASKBAR_STATE_SELECTED) {
      ACTIVE_OBJECTID = "";
      obj.className = "im-taskbaritem-des";
      taskbarItem.state = TASKBAR_STATE_MINIMIZED;
      windowMinimize(objCode);
    }
    else if(taskbarItem.state==TASKBAR_STATE_MINIMIZED) {
      ACTIVE_OBJECTID = objName;
      obj.className = "im-taskbaritem";
      taskbarItem.state = TASKBAR_STATE_SELECTED;
      windowMaximizeRestore(objCode);
    }
    else if(taskbarItem.state==TASKBAR_STATE_UNSELECTED) {
      ACTIVE_OBJECTID = objName;
      obj.className = "im-taskbaritem";
      taskbarItem.state = TASKBAR_STATE_SELECTED;
      var windowItem = windowItems[objCode];
      if(windowItem!=null && windowItem.state!=WINDOW_STATE_REGULAR) windowMaximizeRestore(objCode);
    }
    else if(taskbarItem.state==TASKBAR_STATE_FLASH) {
      ACTIVE_OBJECTID = objName;
      obj.className = "im-taskbaritem";
      taskbarItem.state = TASKBAR_STATE_SELECTED;
    }
  }
  else if(windowItem.state==WINDOW_STATE_POPOUT) {
    var popWindowItem = popoutItems[objCode];
    if(popWindowItem!=null) {
      popWindowItem.focus();
    }
  }
  refreshTaskbar();
}

function my_PickFunc() {
  document.getElementById("backFantom").style.zIndex = zValue;
  hideAllChatSelecitons();

  var objName = dd.obj.name;
  i = objName.indexOf("_");
  objName = objName.substr(0,i);

  ACTIVE_OBJECTID = objName;
  refreshTaskbar();
}

function my_DragFunc() {

	var objName = dd.obj.name;
	i = objName.indexOf("_");
	objName = objName.substr(0,i);

	incZ();
        document.getElementById(objName + "_frameFantom").style.zIndex = zValue;
	dd.elements[objName + "_frameFantom"].setOpacity(0.5);

	document.getElementById(objName + "_frameFantom").style.borderStyle="dashed";
	document.getElementById(objName + "_frameFantom").style.backgroundColor="#ffffff";
	var posX = dd.obj.x;
	var posY = dd.obj.y;
	if(posX<0) posX = 0;
	if((posY-dd.getScrollY())<0) posY = dd.getScrollY();
	if(dd.elements[objName + "_resizehandle"])
	dd.elements[objName + "_resizehandle"].setOpacity(0);

	if(dd.obj.name==(objName + "_resizehandle")) {

		windowState = WINDOW_STATE_REGULAR;

		// check if the re-size goes out of the screen
		if(posX>(dd.getWndW()-15)) posX = dd.getWndW()-15;
		if(posY>(dd.getWndH()-13-TASKBAR_HEIGHT+dd.getScrollY())) posY = dd.getWndH()-13-TASKBAR_HEIGHT+dd.getScrollY();

		// everything is fine, let's change the size of all required objects
		var newW = dd.obj.vertical ? dd.elements[objName + "_frameFantom"].w : posX-dd.elements[objName + "_frameFantom"].x+15;
		var newH = dd.obj.horizontal ? dd.elements[objName + "_frameFantom"].h : posY-dd.elements[objName + "_frameFantom"].y+15;
		dd.elements[objName + "_frameFantom"].resizeTo(newW, newH);
		dd.elements[objName + "_resizehandle"].moveTo(dd.elements[objName + "_frameFantom"].x+dd.elements[objName + "_frameFantom"].w-dd.elements[objName + "_resizehandle"].w-2, dd.elements[objName + "_frameFantom"].y+dd.elements[objName + "_frameFantom"].h-dd.elements[objName + "_resizehandle"].h-2);

	}
	else {

		if(posX>(dd.getWndW()-dd.elements[objName + "_frame"].w)) posX = dd.getWndW()-dd.elements[objName + "_frame"].w;
        if(posY>(dd.getWndH()-dd.elements[objName + "_frame"].h)-TASKBAR_HEIGHT+dd.getScrollY()) posY = dd.getWndH()-dd.elements[objName + "_frame"].h-TASKBAR_HEIGHT+dd.getScrollY();
		if(objName!="main") {
		  if(posY<topPadding) posY = topPadding;
		}

		dd.elements[objName + "_frameFantom"].moveTo(posX, posY);
	}
}

function my_DropFunc() {

  document.getElementById("backFantom").style.zIndex = -1;

	var objName = dd.obj.name;
	i = objName.indexOf("_");
	objName = objName.substr(0,i);

	var posX = dd.obj.x;
	var posY = dd.obj.y;
	if(posX<0) posX = 0;
	if(posY-dd.getScrollY()<0) posY = dd.getScrollY();
	if(posX>(dd.getWndW()-dd.elements[objName + "_frame"].w)) posX = dd.getWndW()-dd.elements[objName + "_frame"].w;
	if(posY>(dd.getWndH()-dd.elements[objName + "_frame"].h)-TASKBAR_HEIGHT+dd.getScrollY()) posY = dd.getWndH()-dd.elements[objName + "_frame"].h-TASKBAR_HEIGHT+dd.getScrollY();

        if(objName!="main") {
          if(posY-dd.getScrollY()<topPadding) posY = topPadding+dd.getScrollY();
        }
    if(dd.elements[objName + "_resizehandle"])
	dd.elements[objName + "_resizehandle"].setOpacity(1);

	if(dd.obj.name==(objName + "_resizehandle")) {
		var newW = dd.obj.x-dd.elements[objName + "_frameFantom"].x+17;
		var newH = dd.obj.y-dd.elements[objName + "_frameFantom"].y+17;
		dd.elements[objName + "_frameFantom"].resizeTo(newW, newH);
		dd.elements[objName + "_frame"].resizeTo(newW, newH);
        if(dd.elements[objName + "_chat"]){
			dd.elements[objName + "_chat"].resizeTo(newW-166, newH-152);
			document.getElementById(objName + "_schedulebar").style.width = (dd.elements[objName + "_chat"].w+3) + "px";
		}
		dd.elements[objName + "_headerMovable"].resizeTo(newW-dd.elements[objName + "_windowButtons"].w-3, dd.elements[objName + "_headerMovable"].h);
		dd.elements[objName + "_resizehandle"].moveTo(dd.elements[objName + "_frameFantom"].x+dd.elements[objName + "_frameFantom"].w-dd.elements[objName + "_resizehandle"].w-2, dd.elements[objName + "_frameFantom"].y+dd.elements[objName + "_frameFantom"].h-dd.elements[objName + "_resizehandle"].h-2);
		dd.elements[objName + "_windowButtons"].moveTo(dd.elements[objName + "_frame"].x+dd.elements[objName + "_frame"].w-dd.elements[objName + "_windowButtons"].w-6, dd.elements[objName + "_frame"].y+(objName=="main"?(typeof orgid != dd_u?26:0):0));

		document.getElementById(objName + "_textDiv").style.width="100%";
		document.getElementById(objName + "_textDiv").style.height="100%";

                //check if it's a chat window and resize its components
                /*if(objName.indexOf("contact")==0) {
                  var objChatMessages = document.getElementById(objName + "_chatMessages");
                  var objTextArea = document.getElementById("message_" + objName);
                  objChatMessages.style.height=newH-162;
                  //objChatMessages.style.width=newW-134;
                  //objTextArea.style.width = newW-116;
                }*/
	}
	else {
		dd.elements[objName + "_frameFantom"].moveTo(posX, posY);
		dd.elements[objName + "_frame"].moveTo(posX, posY);
		dd.elements[objName + "_headerMovable"].moveTo(posX, posY);
		if(dd.elements[objName + "_resizehandle"])
        dd.elements[objName + "_resizehandle"].moveTo(dd.elements[objName + "_frame"].x+dd.elements[objName + "_frame"].w-dd.elements[objName + "_resizehandle"].w-2, dd.elements[objName + "_frame"].y+dd.elements[objName + "_frame"].h-dd.elements[objName + "_resizehandle"].h-2);
	}


	windowMaximizeZ(objName);

	dd.elements[objName + "_frameFantom"].setOpacity(0);
        var windowItem = windowItems[objName];
        if(windowItem!=null) {
          windowItem.x = dd.elements[objName + "_frame"].x;
          windowItem.y = dd.elements[objName + "_frame"].y;
          windowItem.w = dd.elements[objName + "_frame"].w;
          windowItem.h = dd.elements[objName + "_frame"].h;
        }
}

function windowClose(objName) {
  hideWindowItem(objName);
  hideAllChatSelecitons();

  var windowItem = windowItems[objName];
  if(windowItem!=null) {
    windowItem.state = WINDOW_STATE_CLOSED;
  }
  
  if(flag == 0){
  	removeTaskBarItem(objName);
  }
}

var lastFocusObject = null;
var isNoFocusMain = false;
function focusEvent(obj) {
	lastFocusObject = obj;
	if(obj=='main' && isNoFocusMain) {
		isNoFocusMain = false;
		return;
	}
	windowFocus();
	//if(obj==null) alert('null');
	var objName = obj;
	i = objName.indexOf("_");
	if(i>0) objName = objName.substr(0,i);
	hideAllChatSelecitons();
	if(objName!=null && objName!="" && ACTIVE_OBJECTID != objName) {
    	ACTIVE_OBJECTID = objName;
	}
}

function windowMinimize(objName) {

        i = objName.indexOf("_");
	if(i>0) objName = objName.substr(0,i);

        hideWindowItem(objName);

        var windowItem = windowItems[objName];
        if(windowItem!=null) {
          windowItem.state = WINDOW_STATE_MINIMIZED;
        }

        var obj = document.getElementById(objName + "_taskbarItem");
        var taskbarItem = taskbarItems[objName + "_taskbarItem"];
        if(obj!=null && taskbarItem!=null) {
          obj.className = "im-taskbaritem-des";
          taskbarItem.state = TASKBAR_STATE_MINIMIZED;
        }

        hideAllChatSelecitons();

}

function windowMaximizeRestore(objName) {

  focusEvent(objName);

  hideAllChatSelecitons();

  var windowItem = windowItems[objName];
  if(windowItem!=null) {
    if(windowItem.state==WINDOW_STATE_REGULAR) {
      dd.elements[objName + "_frameFantom"].moveTo(0, dd.getScrollY());
      dd.elements[objName + "_frame"].moveTo(0, dd.getScrollY());
      dd.elements[objName + "_frameFantom"].resizeTo(dd.getWndW(), dd.getWndH()-TASKBAR_HEIGHT);
      dd.elements[objName + "_frame"].resizeTo(dd.getWndW(), dd.getWndH()-TASKBAR_HEIGHT);
      if(dd.elements[objName + "_chat"]){
	  	dd.elements[objName + "_chat"].resizeTo(dd.getWndW()-166, dd.getWndH()-TASKBAR_HEIGHT-152);
			document.getElementById(objName + "_schedulebar").style.width = (dd.elements[objName + "_chat"].w+3) + "px";
	  }
      dd.elements[objName + "_resizehandle"].moveTo(dd.elements[objName + "_frameFantom"].x+dd.elements[objName + "_frameFantom"].w-dd.elements[objName + "_resizehandle"].w-2, dd.elements[objName + "_frameFantom"].y+dd.elements[objName + "_frameFantom"].h-dd.elements[objName + "_resizehandle"].h-2);
      dd.elements[objName + "_windowButtons"].moveTo(dd.elements[objName + "_frame"].x+dd.elements[objName + "_frame"].w-dd.elements[objName + "_windowButtons"].w-6, dd.elements[objName + "_frame"].y);
      document.getElementById(objName + "_textDiv").style.width="100%";
      document.getElementById(objName + "_textDiv").style.height="100%";
      windowItem.state = WINDOW_STATE_MAXIMIZED;
    }
    else {
      dd.elements[objName + "_frameFantom"].resizeTo(windowItem.w, windowItem.h);
      dd.elements[objName + "_frame"].resizeTo(windowItem.w, windowItem.h);
      dd.elements[objName + "_frameFantom"].moveTo(windowItem.x, windowItem.y);
      dd.elements[objName + "_frame"].moveTo(windowItem.x, windowItem.y);
      if(dd.elements[objName + "_chat"]){
	  	dd.elements[objName + "_chat"].resizeTo(windowItem.w-166, windowItem.h-152);
			document.getElementById(objName + "_schedulebar").style.width = (dd.elements[objName + "_chat"].w+3) + "px";
	  }
      dd.elements[objName + "_resizehandle"].moveTo(dd.elements[objName + "_frameFantom"].x+dd.elements[objName + "_frameFantom"].w-dd.elements[objName + "_resizehandle"].w-2, dd.elements[objName + "_frameFantom"].y+dd.elements[objName + "_frameFantom"].h-dd.elements[objName + "_resizehandle"].h-2);
      dd.elements[objName + "_windowButtons"].moveTo(dd.elements[objName + "_frame"].x+dd.elements[objName + "_frame"].w-dd.elements[objName + "_windowButtons"].w-6, dd.elements[objName + "_frame"].y);
      document.getElementById(objName + "_textDiv").style.width="100%";
      document.getElementById(objName + "_textDiv").style.height="100%";
      windowItem.state = WINDOW_STATE_REGULAR;
    }

    dd.elements[objName + "_headerMovable"].moveTo(dd.elements[objName + "_frame"].x, dd.elements[objName + "_frame"].y);
    dd.elements[objName + "_headerMovable"].resizeTo(dd.elements[objName + "_frame"].w-dd.elements[objName + "_windowButtons"].w-3, 25);

    //check if it's a chat window and resize its components
      /*if(objName.indexOf("contact")==0) {
        var objChatMessages = document.getElementById(objName + "_chatMessages");
        var newW = dd.elements[objName + "_frameFantom"].w;
        var newH = dd.elements[objName + "_frameFantom"].h;
        var objTextArea = document.getElementById("message_" + objName);
        objChatMessages.style.height=newH-162;
        //objChatMessages.style.width=newW-134;
        //objTextArea.style.width = newW-116;
      }*/

    showWindowItem(objName);
    windowMaximizeZ(objName);
  }
}

function startChat(contact,user) {

  var windowId = "contact" + contact;
  var taskBarObj = document.getElementById(windowId + "_taskbarItem");
  var obj = dd.elements[windowId + "_frame"];
  if(obj==null) {
    var posX,posY;
  	if(typeof user.position != "undefined" && user.position == "center"){
		posX = dd.getScrollX() + (dd.getWndW()-508)/2;
		posY = dd.getScrollY() + (dd.getWndH()-374)/2;
	}else{
	    var rangeX = Math.random()*(dd.getWndW()-325-480);
	    posX=Math.floor(rangeX);
	    var rangeY = Math.random()*(dd.getWndH()-40-400);
	    posY=Math.floor(rangeY);
	
	    posX = posX+320;
	    if(posY-dd.getScrollY()<topPadding) posY = topPadding+dd.getScrollY();
	}
    var chatWindows = document.getElementById("chatWindows");
    var chatWindow = null;

    var chatWindow = document.createElement("div");
    chatWindow.setAttribute("id", windowId + "_chatWindow");
    chatWindows.appendChild(chatWindow);
    var text = "";
    text = text + "<div id=\"" + windowId + "_frameFantom\" class=\"im-windowfantom-des\" style=\"top:" + posY + "px;left:" + posX + "px;width:508px;height:410px\"></div>";
    text = text + "<div id=\"" + windowId + "_resizehandle\" class=\"im-window-resizehandle\" title=\"Resize\"></div>";
    text = text + "<div id=\"" + windowId + "_frame\" class=\"im-window common_border_color\" style=\"top:" + posY + "px;left:" + posX + "px;width:508px;height:410px\">";
    text = text + "	<DIV id=" + windowId + "_frameHeader class=im-windowhead onfocus=focusEvent(this.id)>";
	text = text + "  	<div class=\"im-windowhead-radius-a\"></div>";
	text = text + "		<div class=\"im-windowhead-radius-b common_background_color common_border_color\">";
	text = text + "			<table border=0 cellspacing=0 cellpadding=0 style=\"width:100%;height:1px;\">";
	text = text + "				<tr><td class=\"im-windowhead-radius-b-l\"></td><td class=\"im-windowhead-radius-b-inner\">&nbsp;</td><td class=\"im-windowhead-radius-b-l\"></td></tr>";
	text = text + "			</table>";
	text = text + "		</div>";
	text = text + "		<div class=\"common_background_color\"><div class=\"im-windowhead-radius-m common_border_color\"><div class=\"im-windowhead-radius-f\"><div id=" + windowId + "_windowheadContent style=\"background: url(" + basePath + "images/unavailable.png) no-repeat scroll 7px center;\">&nbsp;";
	text = text + "			<DIV style=\"width:" + (flag == 0 ? 90 : 63) + "px\" id=" + windowId + "_windowButtons class=im-windowbutton-container onfocus=focusEvent(this.id) align=right>";
	if(flag == 0){
		text = text + "			<span class=\"im-window-button im-window-transition\"></span><span class=\"im-window-button im-window-minimizebutton\" title=\"最小化\" onclick=\"windowMinimize(\'" + windowId + "\')\"></span>";
	}
	text = text + "				<span class=\"im-window-button im-window-transition\"></span><span class=\"im-window-button im-window-maximizerestorebutton\" title=\"最大化/还原\" onclick=\"windowMaximizeRestore(\'" + windowId + "\')\"></span>";
	text = text + "				<span class=\"im-window-button im-window-transition\"></span><span class=\"im-window-button im-window-closebutton\" title=\"关闭\" onclick=\"windowClose(\'" + windowId + "\')\"></span>";
	text = text + "			<\/DIV>";
	text = text + "		</div></div></div></div>";
	text = text + "	<\/DIV>";
    text = text + "<div id=\"" + windowId + "_frame_body\" class=\"im-windowbody common_background_color common_border_color\" onfocus=\"focusEvent(this.id)\">";
    text = text + "<div id=\"" + windowId + "_textDiv\" class=\"im-windowbody-inner common_background_color\">";
    text = text + getChatBody(windowId,user.jid).join("");
    text = text + "</div><div id=\"" + windowId + "_statusText\" style=\"font-size:11px;padding:1px 2px;color:555555\">&nbsp;</div></div></div>";
    text = text + "<div id=\"" + windowId + "_headerMovable\" class=\"im-windowfantom-des\" style=\"top:" + posY + "px;left:" + posX + "px;width:240px;height:26px;padding-top:5px;text-indent:22px;line-heigth:26px;\" onfocus=\"focusEvent(this.id)\"><span id=\"" + windowId + "user_name\" onmousedown=\"(is.ie) ? event.cancelBubble=true : event.stopPropagation();\" onclick=\"openUserInfo(\'" + user.jid + "\');\" style=\"font-weight: bold;font-size:12px;margin-left:5px;vertical-align: top;cursor:pointer;\"></span><span id=\"" + windowId + "awaymsg\" style=\"font-size:12px;margin-left:5px;vertical-align: top;\"></span></div>";
    if(flag == 0){
    	text = text + "<div id=\"" + windowId + "_taskbarItem\" class=\"im-taskbaritem\" onclick=\"taskbarItemClick(this.id)\" style=\"top:-100px;left:-100px; WIDTH: 130px;\"></div>";
    }
    chatWindow.innerHTML = text;
    document.getElementById(windowId + "_chat").src="javascript:\"<script src='" + basePath + "switchStyle.js'><\/script><script>window.onblur = window.parent.windowBlur;window.onfocus = window.parent.windowFocus;<\/script><style type='text/css' id='timestampstyle'>.time { display:none;}<\/style><style type='text/css' id='timestampstyle'><\/style>\"";
	ADD_DHTML(windowId + "_frameFantom"+TRANSPARENT+NO_DRAG);
    ADD_DHTML(windowId + "_frame"+NO_DRAG);
    ADD_DHTML(windowId + "_windowButtons"+NO_DRAG);
    ADD_DHTML(windowId + "_textDiv"+NO_DRAG);
    ADD_DHTML(windowId + "_resizehandle"+CURSOR_NW_RESIZE);
    ADD_DHTML(windowId + "_headerMovable"+CURSOR_MOVE);
    ADD_DHTML(windowId + "_chat"+NO_DRAG);
    document.getElementById(windowId + "_schedulebar").style.width = (dd.elements[windowId + "_chat"].w+2) + "px";
	dd.elements[windowId + "_chat"].resizeTo(dd.elements[windowId + "_frame"].w-166, dd.elements[windowId + "_frame"].h-152);
  }else{
	if(user.windowId == ""){
		user.windowId = windowId;
		user.cFrame = document.getElementById(user.windowId + "_chat").contentWindow.document;
	}
  }
  dd.elements[windowId + "_windowButtons"].moveTo(dd.elements[windowId + "_frame"].x+dd.elements[windowId + "_frame"].w-dd.elements[windowId + "_windowButtons"].w-6, dd.elements[windowId + "_frame"].y);
  dd.elements[windowId + "_resizehandle"].moveTo(dd.elements[windowId + "_frame"].x+dd.elements[windowId + "_frame"].w-dd.elements[windowId + "_resizehandle"].w-2, dd.elements[windowId + "_frame"].y+dd.elements[windowId + "_frame"].h-dd.elements[windowId + "_resizehandle"].h-2);
  dd.elements[windowId + "_headerMovable"].moveTo(dd.elements[windowId + "_frame"].x, dd.elements[windowId + "_frame"].y);
  dd.elements[windowId + "_headerMovable"].resizeTo(dd.elements[windowId + "_frame"].w-dd.elements[windowId + "_windowButtons"].w-3, 26);
 // dd.elements[windowId + "_headerMovable"].setOpacity(0);

  var windowItem = windowItems[windowId];
  if(windowItem==null) {
    windowItem = new Object();
    windowItem.x = dd.elements[windowId + "_frame"].x;
    windowItem.y = dd.elements[windowId + "_frame"].y;
    windowItem.w = dd.elements[windowId + "_frame"].w;
    windowItem.h = dd.elements[windowId + "_frame"].h;
    windowItem.state = WINDOW_STATE_REGULAR;
    windowItem.contact = contact;
    windowItems[windowId] = windowItem;
    windowContacts[windowContacts.length] = windowId;
  }
  if(flag == 0){
	addTaskBarItem(windowId + "_taskbarItem", "<div id=\"" + windowId + "taskbarItemContent\" class=\"im-taskbaritem-des-border\" style=\"background: url(" + basePath + "images/unavailable.png) no-repeat scroll 3px center;\"><div class=\"im-common-shadow\" style=\"float:left;width:95px;text-indent:17px;\">" + user.name + "</div><div class=\"im-common-shadow\" style=\"float:left;font-weight:bold;color:red;text-align:center;width:16px;\" title=\"关闭窗口\" onclick=\"windowClose('" + windowId + "')\">X</div></div>");
  }
  showWindowItem(windowId);
  windowMaximizeZ(windowId);

}

var newMessageTimer;

function newMessageNotification() {
	if(!focusFlag) {
		document.title = arguments[0];
		if(newMessageTimer) clearTimeout(newMessageTimer);
		newMessageTimer = setTimeout("newMessageNotification('" + arguments[0].substr(1) + arguments[0].substr(0,1) + "')", 500);
	}else {
		if(newMessageTimer) clearTimeout(newMessageTimer);
	}
}

function showWindowItem(windowId) {
  dd.elements[windowId + "_frame"].show();
  dd.elements[windowId + "_frameFantom"].show();
  if(dd.elements[windowId + "_resizehandle"])
  dd.elements[windowId + "_resizehandle"].show();
  dd.elements[windowId + "_headerMovable"].show();
  if(document.getElementById(windowId + "_iframe1"))
  document.getElementById(windowId + "_iframe1").style.visibility="visible";
}

function hideWindowItem(windowId) {
  dd.elements[windowId + "_frame"].hide();
  dd.elements[windowId + "_frameFantom"].hide();
  if(dd.elements[windowId + "_resizehandle"])
  dd.elements[windowId + "_resizehandle"].hide();
  dd.elements[windowId + "_headerMovable"].hide();
  if(document.getElementById(windowId + "_iframe1"))
  document.getElementById(windowId + "_iframe1").style.visibility="hidden";
}

function WINSZ() {
  pageInit(1);
}

isEmotionSelectionVisible = false;
isFontNameSelectionVisible = false;
isFileSelectionVisible = false;
isChangewaySelectionVisible = false;
isAppraiseSelectionVisible = false;
isPickerSelectionVisible = false;
activeChatWindowId = "";

initEmotionsFlag = false;
function initEmotions() {
	var t=new Array();
	t[t.length]="<table cellspacing='0' cellpadding='0' border='0'><tbody>";
	var j=0;
	for (var i in emoticons) {
		if(typeof emoticons[i] =="function"){
			continue;
		}
		j++;
		if(j%15==1){
			t[t.length]="<tr>";
		}
		if(i=="close"){
			t[t.length]="<td><div class='emotionItem' onclick='hideEmotionSelection();' style='font-size:12px;'>关闭</div></td>";
		}else{
      		var iq = i.replace(/\\/g, '');
      		t[t.length]="<td><div onclick='addEmotion(\""+iq+"\")' class='emotionItem' onmouseout='lowlightie5(this)' onmouseover='highlightie5(this)'><img src='"+emoticonpath+emoticons[i][0]+"' alt='"+emoticons[i][1]+"' title='"+emoticons[i][1]+"'/></div></td>";
		}
		if(j%15==0){
			t[t.length]="</tr>";
		}
    }
    while (j%15!=0){
    	j++;
    	t[t.length]="<td><div class='emotionItem'>&nbsp;</div></td>";
    	if(j%15==0){
    		t[t.length]="</tr>";
    	}
    }
    t[t.length]="</tbody></table><div style='font: 0px/0px sans-serif;clear: both;display: block'> </div>";
    document.getElementById("shared_emotionsDiv").innerHTML=t.join('');
    initEmotionsFlag=true;
}
function showEmotionSelection(objName,e) {
  	if(!initEmotionsFlag) initEmotions();
  	activeChatWindowId = objName;
  	hideAllChatSelecitons("emotion");
	var emotionsDiv = document.getElementById("shared_emotionsDiv");
	emotionsDiv.style.width="auto";
	emotionsDiv.style.height="auto";
    var chatObj = (e.target || e.srcElement).parentNode;
    x = getLeft(chatObj);
    y = getTop(chatObj)+chatObj.offsetHeight-document.getElementById(objName + "_textDiv").scrollTop;
    if(emotionsDiv.clientWidth+x>dd.getWndW()+dd.getScrollX()){
    	x=dd.getWndW()+dd.getScrollX()-emotionsDiv.clientWidth-10;
    }
    if(emotionsDiv.clientHeight+y>dd.getWndH()+dd.getScrollY()){
    	y=dd.getWndH()+dd.getScrollY()-emotionsDiv.clientHeight-10;
    }
    dd.elements.shared_emotionsDiv.moveTo(x,y);
    incZ();
    document.getElementById("shared_emotionsDiv").style.zIndex = zValue;
    if(isEmotionSelectionVisible){
    	emotionsDiv.style.visibility = "hidden";
    	isEmotionSelectionVisible = false;
    }else{
    	emotionsDiv.style.visibility = "visible";
    	isEmotionSelectionVisible = true;
    }
	(is.ie) ? e.cancelBubble = true : e.stopPropagation();
}
function showAppraiseSelection(objName,e) {
  	activeChatWindowId = objName;
  	var objDiv = document.getElementById("shared_appraiseDiv");
	objDiv.style.width="auto";
	objDiv.style.height="auto";
    hideAllChatSelecitons("appraise");
    var chatObj = (e.target || e.srcElement).parentNode;
    x = getLeft(chatObj);
    y = getTop(chatObj)-objDiv.clientHeight-document.getElementById(objName + "_textDiv").scrollTop;
    if(objDiv.clientWidth+x>dd.getWndW()+dd.getScrollX()){
    	x=dd.getWndW()+dd.getScrollX()-objDiv.clientWidth-10;
    }
    if(objDiv.clientHeight+y>dd.getWndH()+dd.getScrollY()){
    	y=dd.getWndH()+dd.getScrollY()-objDiv.clientHeight-10;
    }
    dd.elements.shared_appraiseDiv.moveTo(x,y);
    incZ();
    document.getElementById("shared_appraiseDiv").style.zIndex = zValue;
    if(isAppraiseSelectionVisible){
    	objDiv.style.visibility = "hidden";
        isAppraiseSelectionVisible = false;
    }else{
	    objDiv.style.visibility = "visible";
	    isAppraiseSelectionVisible = true;
	    for(var i = 0; i<document.getElementsByName("r_appraise").length;i++){
	    	document.getElementsByName("r_appraise")[i].checked = false;
	    	document.getElementById("vote_note").value = "";
	    }
    }
	(is.ie) ? e.cancelBubble = true : e.stopPropagation();
}
function showFontNameSelection(objName,e) {
  	activeChatWindowId = objName;
  	var objDiv = document.getElementById("shared_fontNameDiv");
	objDiv.style.width="auto";
	objDiv.style.height="auto";
    hideAllChatSelecitons("font");
    var chatObj = (e.target || e.srcElement).parentNode;
    x = getLeft(chatObj);
    y = getTop(chatObj)-document.getElementById(objName + "_textDiv").scrollTop-objDiv.clientHeight;
    if(objDiv.clientWidth+x>dd.getWndW()+dd.getScrollX()){
    	x=dd.getWndW()+dd.getScrollX()-objDiv.clientWidth-10;
    }
    if(objDiv.clientHeight+y>dd.getWndH()+dd.getScrollY()){
    	y=dd.getWndH()+dd.getScrollY()-objDiv.clientHeight-10;
    }
    dd.elements.shared_fontNameDiv.moveTo(x,y);
    incZ();
    document.getElementById("shared_fontNameDiv").style.zIndex = zValue;
    if(isFontNameSelectionVisible){
    	objDiv.style.visibility = "hidden";
        isFontNameSelectionVisible = false;
    }else{
	    objDiv.style.visibility = "visible";
	    isFontNameSelectionVisible = true;
    }
    s2e();
	(is.ie) ? e.cancelBubble = true : e.stopPropagation();
}
function showPickerSelection(objName) {
  	activeChatWindowId = objName;
  	var objDiv = document.getElementById("shared_pickerDiv");
	objDiv.style.width="auto";
	objDiv.style.height="auto";
    hideAllChatSelecitons("picker");
    var chatObj = dd.elements[objName + "_frame"];
    x = chatObj.x + chatObj.w;
    y = chatObj.y  + 50;
    dd.elements.shared_pickerDiv.moveTo(x-dd.elements.shared_pickerDiv.w-5,y);
    incZ();
    document.getElementById("shared_pickerDiv").style.zIndex = zValue;
    if(isPickerSelectionVisible){
    	objDiv.style.visibility = "hidden";
        isPickerSelectionVisible = false;
    }else{
	    objDiv.style.visibility = "visible";
	    isPickerSelectionVisible = true;
    }
}
function fileUploadOnLoad(){
	showFileSelection(activeChatWindowId);
}

function showFileSelection(objName,e) {
	activeChatWindowId = objName;
	if(document.getElementById("fileUpload")!=null){
		var objDiv = document.getElementById("shared_fileDiv");
	    hideAllChatSelecitons("file");
		if(uploading){
			alert("已有文件在传送，请稍候再试！");
			return;
		}
    	var chatObj = (e.target || e.srcElement).parentNode;
    	x = getLeft(chatObj);
    	y = getTop(chatObj)+chatObj.offsetHeight+2-document.getElementById(objName + "_textDiv").scrollTop;
	    dd.elements.shared_fileDiv.moveTo(x,y);
	    incZ();
	    dd.elements.shared_fileDiv.resizeTo(dd.elements[objName + "_chat"].w,35);
	    document.getElementById("shared_fileDiv").style.zIndex = zValue;
	    if(isFileSelectionVisible){
	    	$um_obj("fileUpload").width="1";
	    	$um_obj("fileUpload").height="1";
	        isFileSelectionVisible = false;
	    }else{
		    $um_obj("fileUpload").width="100%";
	    	$um_obj("fileUpload").height="34";
		    $um_obj("fileUpload").setVal(UMWEBSERVER,jid.substring(0,jid.indexOf("/")),activeChatWindowId.substr(7));
		    isFileSelectionVisible = true;
	    }
    }else{
    	FlashHelper.writeFlash("fileUpload",basePath + "fileUpload.swf","1","1");
    }
	(is.ie) ? e.cancelBubble = true : e.stopPropagation();
}
function showCaptureSelection(objName) {
	activeChatWindowId = objName;
	try{
		document.captureScreen.SetInfo(UMWEBSERVER,"5224",jid.substring(0,jid.indexOf("/")),activeChatWindowId.substr(7));
		document.captureScreen.SetCompleteHandler(onCompleteCapture);
		document.captureScreen.Capture();
	}catch(e){
		window.open(basePath + "screencap/activeX_setup.html");
	}
	(is.ie) ? e.cancelBubble = true : e.stopPropagation();
}
function onCompleteCapture(imgURL){
	imgURL=imgURL.replace(/\\/g,"\/");
	var body = "<img src=\"http://" + UMWEBSERVER + ":5273/" + imgURL + "\" um=\"true\"\/>";
	if (body == '') // don't send empty message
	  return false;
	var user = roster.getUserByJID(activeChatWindowId.substr(7));
	
	sendMessage(user,body);
	
	// add message to our message history
	addtoHistory(body);
	return false;
}

function sendMessage(user,body){
	var aMessage = new JSJaCMessage();
	aMessage.setType('chat');
	aMessage.setTo(user.jid);
	aMessage.setBody(body);
	var aNode=aMessage.getNode().appendChild(aMessage.getDoc().createElement("font"));
	if(messageFontFamily){
		var tNode=aMessage.getDoc().createTextNode(messageFontFamily);
		var family=aNode.appendChild(aMessage.getDoc().createElement("fontname"));
		family.appendChild(tNode);
	}
	if(messageFontStyle || messageFontWeight || messageTextDecoration){
		var temp="";
		if(messageFontStyle){
			temp=temp+"fs"+messageFontStyle.substr(0,1).toUpperCase()+messageFontStyle.substr(1)+":";
		}
		if(messageFontWeight){
			temp=temp+"fs"+messageFontWeight.substr(0,1).toUpperCase()+messageFontWeight.substr(1)+":";
		}
		if(messageTextDecoration){
			var a=messageTextDecoration.split(" ");
			for(var i=0;i<a.length;i++){
				if(a[i]=="line-through"){
					temp=temp+"fsStrikeOut:";
				}else{
					temp=temp+"fsUnderline:";
				}
			}
		}
		
		var tNode=aMessage.getDoc().createTextNode(temp);
		var textStyle=aNode.appendChild(aMessage.getDoc().createElement("style"));
		textStyle.appendChild(tNode);
	}
	if(messageFontSize){
		var tNode=aMessage.getDoc().createTextNode(parseInt(messageFontSize));
		var textSize=aNode.appendChild(aMessage.getDoc().createElement("size"));
		textSize.appendChild(tNode);
	}
	if(messageColor){
		var temp=parseInt(messageColor.substr(5,2) + messageColor.substr(3,2) + messageColor.substr(1,2),16);
		var tNode=aMessage.getDoc().createTextNode(temp);
		var textSize=aNode.appendChild(aMessage.getDoc().createElement("color"));
		textSize.appendChild(tNode);
	}
	con.send(aMessage);
	
	// insert into chat window
	putMsgHTML(aMessage,user);
}
function showChangewaySelection(objName,e) {
	activeChatWindowId = objName;
	var objDiv = document.getElementById("shared_changewayDiv");
    hideAllChatSelecitons("changeway");
    var chatObj = (e.target || e.srcElement);
   	x = getLeft(chatObj);
   	y = getTop(chatObj)+chatObj.offsetHeight-document.getElementById(objName + "_textDiv").scrollTop;
    if(objDiv.clientWidth+x>dd.getWndW()+dd.getScrollX()){
    	x=dd.getWndW()+dd.getScrollX()-objDiv.clientWidth-10;
    }
    if(objDiv.clientHeight+y>dd.getWndH()+dd.getScrollY()){
    	y=dd.getWndH()+dd.getScrollY()-objDiv.clientHeight-10;
    }
    dd.elements.shared_changewayDiv.moveTo(x,y);
    incZ();
    document.getElementById("shared_changewayDiv").style.zIndex = zValue;
    if(isChangewaySelectionVisible){
    	objDiv.style.visibility = "hidden";
        isChangewaySelectionVisible = false;
    }else{
    	var a_changeway=document.getElementById("shared_changewayDiv").getElementsByTagName("a");
    	a_changeway[0].getElementsByTagName("span")[0].className="";
    	a_changeway[1].getElementsByTagName("span")[0].className="";
    	a_changeway[changeway].getElementsByTagName("span")[0].className="changeway";
	    objDiv.style.visibility = "visible";
	    isChangewaySelectionVisible = true;
    }
	(is.ie) ? e.cancelBubble = true : e.stopPropagation();
}
function setUpload(){
	uploading=true;
	hideFileSelection();
}
function hideAllChatSelecitons() {
	if(!arguments[0] || arguments[0]!="statusMenuDiv")
	document.getElementById("main_iframe1").contentWindow.document.getElementById("statusMenuDiv").style.visibility="hidden";
	if(!arguments[0] || arguments[0]!="mainMenuDiv")
	document.getElementById("main_iframe1").contentWindow.document.getElementById("mainMenuDiv").style.visibility="hidden";
	document.getElementById("main_iframe1").contentWindow.document.getElementById("iRoster").contentWindow.menuobj.style.visibility = "hidden";
	if(!arguments[0] || arguments[0]!="emotion")
	hideEmotionSelection();
	if(!arguments[0] || arguments[0]!="font")
	hideFontNameSelection();
	if(!arguments[0] || arguments[0]!="file")
	hideFileSelection();
	if(!arguments[0] || arguments[0]!="changeway")
	hideChangewaySelection();
	if(!arguments[0] || arguments[0]!="appraise")
	hideAppraiseSelection();
	if(!arguments[0] || arguments[0]!="picker")
	hidePickerSelection();
}
function hideEmotionSelection() {
  var emotionsDiv = document.getElementById("shared_emotionsDiv");
  if(isEmotionSelectionVisible) {
    emotionsDiv.style.visibility = "hidden";
    isEmotionSelectionVisible = false;
  }
}
function hideAppraiseSelection() {
  var objDiv = document.getElementById("shared_appraiseDiv");
  if(isAppraiseSelectionVisible) {
	objDiv.style.visibility = "hidden";
    isAppraiseSelectionVisible = false;
  }
}
function hidePickerSelection() {
  var objDiv = document.getElementById("shared_pickerDiv");
  if(isPickerSelectionVisible) {
	objDiv.style.visibility = "hidden";
    isPickerSelectionVisible = false;
  }
}
function hideFontNameSelection() {
  var objDiv = document.getElementById("shared_fontNameDiv");
  if(isFontNameSelectionVisible) {
	objDiv.style.visibility = "hidden";
    isFontNameSelectionVisible = false;
  }
}
function hideFileSelection() {
	if(document.getElementById("fileUpload")!=null){
		if(isFileSelectionVisible) {
		 	$um_obj("fileUpload").width="1";
		 	$um_obj("fileUpload").height="1";
		  isFileSelectionVisible = false;
		}
	}
}
function hideChangewaySelection() {
  var objDiv = document.getElementById("shared_changewayDiv");
  if(isChangewaySelectionVisible) {
   	objDiv.style.visibility = "hidden";
    isChangewaySelectionVisible = false;
  }
}
function highlightie5(e){
  	e.className = "emotionItem-sel";

}
function lowlightie5(e){
  	e.className = "emotionItem";
}

function addEmotion(emotion) {
  var messageObj = document.getElementById(activeChatWindowId + "_msgbox");
  messageObj.focus();
  messageObj.value = messageObj.value + " " + emotion + " ";
}
function FontNameChange(fontname)
{
	document.getElementById("Text1").value=fontname;
	document.getElementById("chatwordsFrame").style.fontFamily=fontname;
}
function FontStyleChange(fontname)
{
	document.getElementById("Text2").value=fontname.value;
	var obj=document.getElementById("chatwordsFrame");
	if(fontname.value=='常规')
	{
		obj.style.fontStyle="";
		obj.style.fontWeight="";
	}else if(fontname.value=='粗体')
	{
		obj.style.fontStyle="";
		obj.style.fontWeight="bold";
	}else if(fontname.value=='斜体')
	{
		obj.style.fontStyle="italic";
		obj.style.fontWeight="";
	}else if(fontname.value=='粗斜体')
	{
		obj.style.fontStyle="italic";
		obj.style.fontWeight="bold";
	}
}
function FontSizeChange(fontname)
{
	document.getElementById("Text3").value=fontname;
	document.getElementById("chatwordsFrame").style.fontSize=fontname + "pt";
}
function FontColorChange(fontname)
{
	document.getElementById("chatwordsFrame").style.color=fontname;
}
function Checkbox1Click()
{
	var temp="";
	if(document.getElementById("Checkbox1").checked){
		temp+=" " + document.getElementById("Checkbox1").value;
	}
	if(document.getElementById("Checkbox2").checked){
		temp+=" "+ document.getElementById("Checkbox2").value;
	}
	temp=temp.replace(/(^\s*)|(\s*$)/g,'');
	document.getElementById("chatwordsFrame").style.textDecoration=temp;
}

function s2e(){
	var obj1=document.getElementById("chatwordsFrame");
	obj1.style.fontFamily=messageFontFamily;
	obj1.style.fontStyle=messageFontStyle;
	obj1.style.fontWeight=messageFontWeight;
	obj1.style.textDecoration=messageTextDecoration;
	obj1.style.fontSize=messageFontSize;
	obj1.style.color=messageColor;
	document.getElementById("Select1").value=document.getElementById("Text1").value=messageFontFamily;
	if(messageFontStyle=="" && messageFontWeight==""){
		document.getElementById("Select2").value=document.getElementById("Text2").value="常规";
	}else if(messageFontStyle=="italic" && messageFontWeight==""){
		document.getElementById("Text2").value=document.getElementById("Select2").value="斜体";
	}else if(messageFontStyle=="" && messageFontWeight=="bold"){
		document.getElementById("Select2").value=document.getElementById("Text2").value="粗体";
	}else{
		document.getElementById("Select2").value=document.getElementById("Text2").value="粗斜体";
	}
	document.getElementById("Select3").value=document.getElementById("Text3").value=parseInt(messageFontSize);
	document.getElementById("Select4").value=messageColor;
	var a=messageTextDecoration.split(" ");
	document.getElementById("Checkbox1").checked=false;
	document.getElementById("Checkbox2").checked=false;
	for(var j=0;j<a.length;j++){
		if(a[j]=="underline"){
			document.getElementById("Checkbox2").checked=true;
		}
		if(a[j]=="line-through"){
			document.getElementById("Checkbox1").checked=true;
		}
	}
}

function e2s(){
	var obj1=document.getElementById("chatwordsFrame");
	for(var i=0;i<windowContacts.length;i++){
		document.getElementById(windowContacts[i] + "_msgbox").style.fontFamily=obj1.style.fontFamily;
		document.getElementById(windowContacts[i] + "_msgbox").style.fontSize=obj1.style.fontSize;
		document.getElementById(windowContacts[i] + "_msgbox").style.fontStyle=obj1.style.fontStyle;
		document.getElementById(windowContacts[i] + "_msgbox").style.fontWeight=obj1.style.fontWeight;
		document.getElementById(windowContacts[i] + "_msgbox").style.color=obj1.style.color;
		document.getElementById(windowContacts[i] + "_msgbox").style.textDecoration=obj1.style.textDecoration;
	}
	messageFontFamily = obj1.style.fontFamily;
	messageFontSize = obj1.style.fontSize;
	messageColor = document.getElementById("Select4").value;
	messageFontStyle = obj1.style.fontStyle;
	messageFontWeight = obj1.style.fontWeight;
	messageTextDecoration = obj1.style.textDecoration;
	new JSJaCCookie("messageFontFamily",messageFontFamily,10*24*3600).write();
	new JSJaCCookie("messageFontSize",messageFontSize,10*24*3600).write();
	new JSJaCCookie("messageColor",messageColor,10*24*3600).write();
	new JSJaCCookie("messageFontStyle",messageFontStyle,10*24*3600).write();
	new JSJaCCookie("messageFontWeight",messageFontWeight,10*24*3600).write();
	new JSJaCCookie("messageTextDecoration",messageTextDecoration,10*24*3600).write();
	c();
	return false;
}

function f_changeway(ind){
	changeway=ind;
	var a_changeway=document.getElementById("shared_changewayDiv").getElementsByTagName("a");
   	a_changeway[0].getElementsByTagName("span")[0].className="";
   	a_changeway[1].getElementsByTagName("span")[0].className="";
   	a_changeway[ind].getElementsByTagName("span")[0].className="changeway";
    new JSJaCCookie("changeway",ind,10*24*3600).write();
    return false;
}

function doAppraise(){
	var level = "";
	for(var i=0;i<document.getElementsByName("r_appraise").length;i++){
		if(document.getElementsByName("r_appraise")[i].checked == true){
			level = document.getElementsByName("r_appraise")[i].value;
			break;
		}	
	}
	if(level == ""){
		alert("请选择满意度");
		return;
	}
	var vote_note = document.getElementById("vote_note").value.trim();
	if(_length(vote_note) > 300){
		alert("输入字数超过200个字符，请重新输入！");
		return;
	} 
	var iq = new JSJaCIQ();
	iq.setIQ(activeChatWindowId.substr(7), "set", "appraise_1");
	iq.setFrom(jid.substring(0,jid.indexOf("/")));
	iq.appendNode("query", {xmlns:"jabber:iq:appraise"}, [["level", level],["content", vote_note],["orgid", oCon.orgid]]);
	con.send(iq);
	c();
	return false;
}
function _length(str) {
    var len = 0;
    for (var i = 0; i < str.length; i++) {
        if (str.charAt(i) > "~") {
            len += 2;
        } else {
            len++;
        }
    }
    return len;
}
String.prototype.trim=function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
