﻿var Navigator = new Object();
if(navigator.userAgent.indexOf("MSIE") != -1)
{
    Navigator.IE = true;
    if(navigator.userAgent.indexOf("MSIE 6.0") != -1)
    {
        Navigator.IE6 = true;
    }
    if(navigator.userAgent.indexOf("MSIE 7.0") != -1)
    {
        Navigator.IE7 = true;
    }
}
if(navigator.userAgent.indexOf("Firefox") != -1)
{
    Navigator.Firefox = true;
}
function $(id)
{
    return document.getElementById(id);
}
function SetCookie(sName, sValue)
{
    var date = new Date();
    date.setFullYear(date.getFullYear() + 1);
    document.cookie = sName + "=" + escape(sValue) + "; domain=clozone.com; expires=" + date.toGMTString();
}
function GetCookie(sName)
{
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++)
    {
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0]) 
            return unescape(aCrumb[1]);
    }
    return null;
}
function SetHomePage(url)
{
    document.body.style.behavior='url(#default#homepage)';
    document.body.setHomePage(url);
}
function NewWindow(url)
{
    window.open(url);
}
function Reload()
{
    window.location.href = window.location.href;
}
function ToggleDisplay_none_block(controlID)
{
    var control = $(controlID);
    if (control.style.display == 'none')
    {
        control.style.display = 'block';
    }
    else
    {
        control.style.display = 'none';
    }
}
function SetDisplayNone(controlID)
{
    var control = $(controlID);
    control.style.display = 'none';
}
function SetDisplayBlock(controlID)
{
    var control = $(controlID);
    control.style.display = 'block';
}
function SetDisplayInline(controlID)
{
    var control = $(controlID);
    control.style.display = 'inline';
}
function SetHidden(controlID)
{
    var control = $(controlID);
    control.style.visibility = 'hidden';
}
function SetVisible(controlID)
{
    var control = $(controlID);
    control.style.visibility = 'visible';
}
function SetEnable(controlID)
{
    $(controlID).disabled = false;
}
function SetDisable(controlID)
{
    $(controlID).disabled = true;
}
function SetFocus(controlID)
{
    var control = $(controlID);
    try
    {
        control.focus();
    }
    catch(e){}
}
function SetFloatLeft(control)
{
    if(document.all)
    {
        control.style.styleFloat = 'left';
    }
    else
    {
        control.style.cssFloat = 'left';
    }
}
function SetFloatRight(control)
{
    if(document.all)
    {
        control.style.styleFloat = 'right';
    }
    else
    {
        control.style.cssFloat = 'right';
    }
}
function SetFrameHeight(height)
{
    if(height != null)
    {
        window.frameElement.style.height = height + "px";
    }
    else
    {
        window.frameElement.style.height = document.body.scrollHeight + "px";
    }
}
function SetFrameHeightAtLeast(height)
{
    if(document.body.scrollHeight < height)
    {
        SetFrameHeight(height);
    }
    else
    {
        SetFrameHeight();
    }
}
function AddFrameHeight(height)
{
    window.frameElement.style.height = window.frameElement.offsetHeight + height + "px";
}
function SetHeight(controlID,height)
{
    $(controlID).style.height = height + "px";
}
function SetMaxHeight(control,maxHeight)
{
    if(control.scrollHeight > maxHeight)
    {
        control.style.height = maxHeight + 'px';
        control.style.overflow = 'auto';
    }
    else
    {
        control.style.height = '';
        control.style.overflow = '';
    }
}
function IsNone(controlID)
{
    if($(controlID).style.display == "none")
    {
        return true;
    }
    return false;
}
function IsBlock(controlID)
{
    if($(controlID).style.display == "block")
    {
        return true;
    }
    return false;
}
function CancelBubble(e)
{
    if(document.all)
    {
        event.cancelBubble = true;
    }
    else
    {
        e.stopPropagation();
    }
}
function FireEvent(obj,eventName)
{
    if(document.all)
    {
        obj.fireEvent('on' + eventName);
    }
    else
    {
        var evt = document.createEvent('MouseEvents'); 
        evt.initEvent(eventName, 1, 1)
        obj.dispatchEvent(evt);
    }
}
function CancelEvent(e)
{
    if(document.all)
    {
        event.returnValue = false;
    }
    else
    {
        if (e)
        {
            e.preventDefault();
        }
    }   
}
function GetOffsetLeft(control)
{
    var offsetLeft = 0;
    while(control != null)
    {
        offsetLeft += control.offsetLeft;
        control = control.offsetParent;
    }
    return offsetLeft;
}
function GetOffsetTop(control)
{
    var offsetTop = 0;
    while(control != null)
    {
        offsetTop += control.offsetTop;
        control = control.offsetParent;
    }
    return offsetTop;
}
function Reload()
{
    window.location.href = window.location.href;
}
function DisableContextMenu()
{
    document.oncontextmenu = ReturnFalse;
}
function FixPng(img)
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
	{
		var span = document.createElement('span');
		span.id = img.id;
		span.className = img.className;
		span.title = img.title? img.title:img.alt;
		span.style.width = img.offsetWidth + 'px';
		span.style.height = img.offsetHeight + 'px';
		span.style.display = 'inline-block';
		span.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + img.src + '", sizingMethod="crop")';
		img.parentNode.replaceChild(span,img);
   }
}
function GetPrefix()
{
    var url = window.location.href;
    return url.substring(7,url.indexOf('.clozone.com'));
}
Function.createDelegate = function(object, method)
{
	if(arguments.length == 2)
    {
        return function()
        {        
            method.apply(object,arguments);
        }
    }
    if(arguments.length > 2)
    {
        var args = new Array();
        for(var i = 0; i < arguments.length - 2; i++)
	    {
		    args[i] = arguments[i + 2];
	    }
        return function()
        {
            method.apply(object,args);
        }
    }
}
var scriptQueue = new Array();
var isLoadingScript = false;
function AddScript(src,onload)
{
    scriptQueue[scriptQueue.length] = new ScriptObj(src,onload);
    if(!isLoadingScript)
    {
        CheckScriptQueue();
    } 
}
function ScriptObj(src,onload)
{
    this.Src = src;
    this.Onload = onload;
}
function CheckScriptQueue()
{
    if(scriptQueue.length > 0)
    {
        isLoadingScript = true;
        var scriptObj = scriptQueue[0];
        scriptQueue.splice(0,1);
        var script = document.createElement('script');
        script.language = 'javascript';
        script.type = 'text/javascript';
        script.src = scriptObj.Src;
        script.loadDone = scriptObj.Onload;
        script.onload = script.onreadystatechange = LoadScriptDone;
        var head = document.getElementsByTagName('head')[0];
        head.appendChild(script);
    }
    else
    {
        isLoadingScript = false;
    }
}
function LoadScriptDone()
{
    if(!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')
    {
        if(this.loadDone)
        {
            this.loadDone();
        }
        CheckScriptQueue();
    } 
}
function AddCSS(src)
{
    var css = document.createElement('link');
    css.rel	= 'stylesheet';
	css.type = 'text/css';
	css.href = src;
	var head = document.getElementsByTagName('head')[0];
    head.appendChild(css);
}
// 复制到剪贴板
function CopyToClipboard(control)
{
    if (control.createTextRange)
    {
        var range = control.createTextRange();
        range.select();
        range.execCommand('Copy');
    } 
    else
    {
        var flashcopier = 'flashcopier';
        if(!$(flashcopier)) 
        {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
        }
        $(flashcopier).innerHTML = '';
        var divinfo = '<embed src="http://www.clozone.com/images/_clipboard.swf" FlashVars="clipboard='
                    + escape(control.value) + '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        $(flashcopier).innerHTML = divinfo;
    }
}
function TrimEnd(stringToTrim)
{
    if (stringToTrim != null && stringToTrim.length > 0 )    
    {          
        var temp = stringToTrim.charAt(stringToTrim.length - 1);
        while (stringToTrim.length > 0  && temp == ' ')  
        {
            stringToTrim = stringToTrim.substr(0, stringToTrim.length - 1); 
            temp = stringToTrim.charAt(stringToTrim.length - 1);
        }
    }
    return stringToTrim;          
}
function TimeFormat(dateTime)
{
    if(typeof dateTime == 'string')
    {
        return dateTime.toLocaleString().substr(0,dateTime.toLocaleString().length - 3);
    }
    var minutes = dateTime.getMinutes();
    if (minutes < 10)
    {
        minutes = '0' + minutes;
    }
    var time = dateTime.getFullYear() + '-' + (dateTime.getMonth() + 1) + '-' + dateTime.getDate() + ' ' + dateTime.getHours() + ':' + minutes;
    return time;
}
function RssTimeFormat(dateTime)
{
    return dateTime.toLocaleString().substr(0,dateTime.toLocaleString().length - 7);
}
function TagsFormat(tags)
{
    var tagsFormated="";
    if(tags.length > 0)
    {
        for(var i = 0; i < tags.length - 1; i++)
        {
            if (typeof(tags[i].Name) != 'undefined')
            {
                tagsFormated += tags[i].Name + " ";  
            }
            else
            {
                tagsFormated += tags[i] + " "; 
            }
        }
        if (typeof(tags[tags.length - 1].Name) != 'undefined')
        {
            tagsFormated += tags[tags.length - 1].Name;
        }
        else
        {
           tagsFormated += tags[tags.length - 1];  
        }
    }
    return tagsFormated;
}
function HtmlEncode(s)
{
    var c,r = '';
    for(var i = 0; i < s.length; i ++)
    {
        c = s.substr(i,1);
        switch(c)
        {
            case "&" : r += "&amp;";break;
            case "<" : r += "&lt;";break;
            case ">" : r += "&gt;";break;
            case "\"": r += "&quot;";break;
            case "'" : r += "&#39;";break;
            default  : r += c;
        }
    }
    return r;
}
function HtmlDecode(s)
{
    for(var i = 0; i < s.length; i ++)
    {
        if(s.substr(i,1) != "&")
        {
            continue;
        }
        if(s.substr(i + 1, 4) == "amp;")
        {
            s = s.substring(0,i) + "&" + s.substring(i + 5, s.length);
            continue;
        }
        if(s.substr(i + 1, 3) == "lt;")
        {
            s = s.substring(0,i) + "<" + s.substring(i + 4, s.length);
            continue;
        }
        if(s.substr(i + 1, 3) == "gt;")
        {
            s = s.substring(0,i) + ">" + s.substring(i + 4, s.length);
            continue;
        }
        if(s.substr(i + 1, 5) == "quot;")
        {
            s = s.substring(0,i) + "\"" + s.substring(i + 6, s.length);
            continue;
        }
        if(s.substr(i + 1, 4) == "#39;")
        {
            s = s.substring(0,i) + "'" + s.substring(i + 5, s.length);
            continue;
        }
    }
    return s;
}
function ResizeImage(htmlNode, maxWidth)
{
    var imgNodes = htmlNode.getElementsByTagName('IMG'); 
    if (imgNodes!= null)
    {
        for (var i = 0; i < imgNodes.length; i++)
        {
            var node = imgNodes[i];
            if (node != null) 
            {
                if (node.offsetWidth > 150)
                {
                    node.style.display = 'block';
                }
                if (node.readyState == 'loaded' || node.readyState == 'complete')
                {
                    if (node.offsetWidth > maxWidth)
                    {
                            
                        node.style.height = (maxWidth / node.offsetWidth) * node.offsetHeight + 'px';
                        node.style.width = maxWidth + 'px';
                        if (node.parentNode.tagName != 'A')
                        {
                            node.oldAlt = node.alt;
                            node.alt = node.alt + '(点击查看原图)';
                            node.onclick = ViewImage;
                            node.style.cursor = 'pointer';
                        }
                    }
                }
                else
                {
			        node.MaxWidth = maxWidth;
				    node.onload = ResizeAfterLoad;
                }
            }           
        }
    } 
}
function ResizeAfterLoad(e)
{
    var node;
    if(document.all)
    {
        node = window.event.srcElement;
	}
	else
	{
	    node = e.currentTarget;
	}
	if (node.offsetWidth > node.MaxWidth)
	{
		node.style.height = (node.MaxWidth / node.offsetWidth) * node.offsetHeight + 'px';
		node.style.width = node.MaxWidth + 'px';
        if (node.parentNode.tagName != 'A')
        {
            node.oldAlt = node.alt;
            node.alt = node.alt + '(点击查看原图)';
            node.onclick = ViewImage;
            node.style.cursor = 'pointer';
        }
	}
}
function ViewImage(evt)
{
    if(document.all)
    {
        var node = window.event.srcElement;
	}
	else
	{
	    var node = evt.srcElement;
	}   
    window.open(node.src);    
}
function GetString(s, length)
{
    if(s == null)
    {
        return null;
    }
    var temp = HtmlDecode(s);
    var needEncode = false;
    if(temp != s)
    {
        needEncode = true;
    }
    if(temp.length <= length)
    {
        return needEncode? HtmlEncode(temp):temp;
    }    
    return needEncode? HtmlEncode(temp.substr(0, length - 1) + "…"):(temp.substr(0, length - 1) + "…");
}
function CheckEnterKey(e,handler)
{
    if(e.keyCode != 13)
    {
        return true;
    }
    if(handler != null)
    {
        handler();
    }
    return false; 
}
function IsOverLap(div1,div2)
{
    if(GetOffsetLeft(div1) < GetOffsetLeft(div2) + div2.offsetWidth && GetOffsetLeft(div1) + div1.offsetWidth > GetOffsetLeft(div2) && GetOffsetTop(div1) < GetOffsetTop(div2) + div2.offsetHeight && GetOffsetTop(div1) + div1.offsetHeight > GetOffsetTop(div2))
    {
        return true;
    }
    if(GetOffsetLeft(div2) < GetOffsetLeft(div1) + div1.offsetWidth && GetOffsetLeft(div2) + div2.offsetWidth > GetOffsetLeft(div1) && GetOffsetTop(div2) < GetOffsetTop(div1) + div1.offsetHeight && GetOffsetTop(div2) + div2.offsetHeight > GetOffsetTop(div1))
    {
        return true;
    }
    return false;
}
function ReturnFalse()
{
    return false;
}
/*PageContainer Start*/
function PageContainer(content,pageSize)
{
    this.PageIndex = 0;
    this.Content = content;
    this.PageSize = pageSize;
}
PageContainer.prototype.GetPageIndex = function()
{
    return this.PageIndex;
}
PageContainer.prototype.GetCount = function()
{
    if (this.Content == null)
    {
        return 0;
    }
    return this.Content.length;
}
PageContainer.prototype.GetPageNum = function()
{
    return Math.ceil(this.GetCount() / this.PageSize);
}
PageContainer.prototype.IsLastPage = function()
{
    if (this.PageIndex == this.GetPageNum() - 1 || this.GetPageNum() == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
PageContainer.prototype.IsFirstPage = function()
{
    if (this.PageIndex == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
PageContainer.prototype.GetPage = function(index)
{
    if(index > this.GetPageNum() - 1 || index < 0)
    {
        return null;
    }
    this.PageIndex = index;
    if(index < this.GetPageNum() - 1)
    {
        var result = new Array(this.PageSize);
        for(var i = 0 ; i < this.PageSize ; i ++)
        {
            result[i] = this.Content[this.PageIndex * this.PageSize + i];            
        }
        return result;
    }
    else
    {
        var result = new Array(this.Content.length - this.PageSize * index);
        for(var i = 0 ; i < this.Content.length - this.PageSize * index ; i ++)
        {
            result[i] = this.Content[this.PageIndex * this.PageSize + i];            
        }
        return result;
    }
}
PageContainer.prototype.GetFirstPage = function()
{
    return this.GetPage(0);
}
PageContainer.prototype.GetLastPage = function()
{
    return this.GetPage(this.GetPageNum() - 1);
}
PageContainer.prototype.GetNextPage = function()
{
    return this.GetPage(this.PageIndex + 1);
}
PageContainer.prototype.GetPrePage = function()
{
    return this.GetPage(this.PageIndex - 1);
}
PageContainer.prototype.GetCurrentPage = function()
{
    return this.GetPage(this.PageIndex);
}
PageContainer.prototype.GetItem = function(itemIndex)
{
    if(itemIndex < 0 || itemIndex > this.Content.length - 1)
    {
        return null;
    }
    return this.Content[itemIndex];
}
PageContainer.prototype.DeleteItem = function(itemIndex)
{
    if(itemIndex < 0 || itemIndex > this.Content.length - 1)
    {
        return;
    }
    this.Content.splice(itemIndex,1);
}
PageContainer.prototype.DeleteItemInCurrentPage = function(indexInPage)
{
    this.DeleteItem(this.PageSize * this.PageIndex + indexInPage);
}
PageContainer.prototype.AddItemAt = function(atIndex,item)
{
    if(atIndex < 0 || atIndex > this.Content.length)
    {
        return;
    }
    this.Content.splice(atIndex,0,item);
}
PageContainer.prototype.AddItems = function(newContent)
{
    for(var i = 0; i < newContent.length; i ++)
    {
        this.AddItemAt(this.GetCount(),newContent[i]);       
    } 
}
/*PageContainer End*/
function BufferedPageContainer(functionLoadContent, functionReceiveContent, pageSize, pageCount_PreLoad)
{     
    // public properties       
    this.PageIndex = 0;             
    this.PageSize = pageSize;                        
    this.PageCount = 0;                       
    this.ItemCount = 0;     
    this.LoadContent = functionLoadContent;
    this.ReceiveContent = functionReceiveContent;
    this.PageCount_PreLoad = pageCount_PreLoad;
    this.AutoFill = true;
    
    // private
    this._inited = false;                     
    this._buffer = null;                     
    this._bufferStatus = new Array(); 
    this._postData = new Object();    
}    
// methods
BufferedPageContainer.prototype.LoadPage = function(index)
{   
    if(!this._inited)
    {   
        this.PageIndex = index; 
        this._postData.PageIndex = this.PageIndex;     
        this._postData.FillPageIndex = this.PageIndex; 
        this._postData.CallReceiveContent = true;
        this._bufferStatus[this.PageIndex] = "requesting";
        this.LoadContent(this.PageIndex, this.PageSize, 1, this._postData, Function.createDelegate(this, this.ReceivePages));
        return;
    }
    if (index < 0)
    {
        index = 0;
    }
    if (index > this.PageCount - 1)
    {
        index = this.PageCount - 1;
    }             
    this.PageIndex = index;
            
    if (this._buffer[this.PageIndex] != null)
    {
        if (this.ReceiveContent != null)
        {
            this.ReceiveContent(this._buffer[this.PageIndex]);
        }
        if (this.AutoFill)
        {
            this.FillPage(this.PageIndex - this.PageCount_PreLoad, this.PageIndex + this.PageCount_PreLoad);   
        }                      
    }
    else
    {  
        this._postData.PageIndex = this.PageIndex;         
        this._postData.FillPageIndex = this.PageIndex; 
        this._postData.CallReceiveContent = true;         
        this._bufferStatus[this.PageIndex] = "requesting";
        this.LoadContent(this.PageIndex, this.PageSize, 1, this._postData, Function.createDelegate(this, this.ReceivePages)); 
    }
}
BufferedPageContainer.prototype.FillPage = function(startIndex, endIndex) 
{
    if (startIndex < 0)
    {
        startIndex = 0;
    } 
    if (this._inited) 
    {           
        if (endIndex > this.PageCount - 1)
        {
            endIndex = this.PageCount - 1; 
        }              
        while (startIndex <= endIndex && (this._buffer[startIndex] != null || this._bufferStatus[startIndex] == "requesting"))
        {
            startIndex++;            
        }
        while (startIndex <= endIndex && (this._buffer[endIndex] != null || this._bufferStatus[startIndex] == "requesting"))
        {
            endIndex--;           
        } 
    } 
    if (startIndex > endIndex)
    {
        return;  
    } 
    
    this._postData.PageIndex = this.PageIndex; 
    this._postData.FillPageIndex = startIndex; 
    this._postData.CallReceiveContent = false; 
    for (var i = startIndex; i <= endIndex; i++)
    {
        this._bufferStatus[i] = "requesting";
    }
    this.LoadContent(startIndex, this.PageSize, endIndex - startIndex + 1, this._postData, Function.createDelegate(this, this.ReceivePages));         
}
BufferedPageContainer.prototype.ReceivePages = function(content)
{ 
    if (content == null)
    {
        return;          
    }
    var items = content.Items;
    var itemCount = content.ItemCount;
    var pageIndex = content.PostData.PageIndex;
    var fillPageIndex = content.PostData.FillPageIndex;
    var callReceiveContent = content.PostData.CallReceiveContent;
    
    if (itemCount <= 0)
    {
        this._inited = true;
        this.PageIndex = 0;
        this.ItemCount = 0;                        
        this.PageCount = 1; 
        this._buffer = new Array(1);
        this._bufferStatus = new Array();
        this._buffer[0] = null;
        if (callReceiveContent && this.ReceiveContent != null)
        {
            this.ReceiveContent(null);
        }
        return;
    } 
    if (this._inited == false || itemCount != this.ItemCount)
    { 
        this._inited = true;
        this.ItemCount = itemCount;                         
        this.PageCount = Math.max(1, Math.ceil(this.ItemCount / this.PageSize));
        this._buffer = new Array(this.PageCount); 
        this._bufferStatus = new Array();
    } 
    
    if (items == null || items.length == 0)
    {
        if (callReceiveContent)
        {
            if (pageIndex < 0)
            {
                this.PageIndex = 0;
                this.LoadCurrentPage();
                return;
            }
            if (pageIndex > this.PageCount - 1)
            {
                this.PageIndex = this.PageCount - 1; 
                this.LoadCurrentPage();  
                return;
            }            
        }
        return;
    }
    
    var pageContainer = new PageContainer(items, this.PageSize);
    if (this.PageCount > 0)
    {   
        endIndex = pageContainer.GetPageNum();
        for (j = 0; j < endIndex; fillPageIndex++, j++)
        {
            this._buffer[fillPageIndex] = pageContainer.GetPage(j);              
            this._bufferStatus[fillPageIndex] = "filled";      
        }
    }
    
    if (callReceiveContent)
    { 
        if (this.ReceiveContent != null)
        {
            this.ReceiveContent(this._buffer[pageIndex]);
        }
        if (this.AutoFill)
        {
            this.FillPage(pageIndex - this.PageCount_PreLoad, pageIndex + this.PageCount_PreLoad);
        }        
    }   
}  
BufferedPageContainer.prototype.LoadFirstPage = function()
{
    this.PageIndex = 0;        
    return this.LoadCurrentPage();
}
BufferedPageContainer.prototype.LoadLastPage = function()
{
    this.PageIndex = this.PageCount - 1;        
    return this.LoadCurrentPage();
}
BufferedPageContainer.prototype.LoadNextPage = function()
{              
    this.PageIndex = Math.min(this.PageCount - 1, this.PageIndex + 1);        
    return this.LoadCurrentPage();
}
BufferedPageContainer.prototype.LoadPrePage = function()
{           
    this.PageIndex = Math.max(0, this.PageIndex - 1);        
    return this.LoadCurrentPage();
}
BufferedPageContainer.prototype.LoadCurrentPage = function()
{
    return this.LoadPage(this.PageIndex);
}
BufferedPageContainer.prototype.Reset = function()
{        
    //this.PageIndex = 0;                              
  //  this.PageCount = 0;                       
    this.ItemCount = 0;      
    this._inited = false;                     
    this._buffer = null; 
    this._bufferStatus = new Array();   
}
BufferedPageContainer.prototype.ClearBuffer = function()
{
    this._buffer = null;
    this._bufferStatus = new Array(); 
}
BufferedPageContainer.prototype.GetPage = function(index)
{
    if(!this._inited || this._buffer == null || index < 0 || index > this.PageCount - 1)
    {   
        return null;
    }    
    return this._buffer[this.PageIndex];
}
BufferedPageContainer.prototype.GetCurrentPage = function()
{
    return this.GetPage(this.PageIndex);
}
BufferedPageContainer.prototype.UpdateItem = function(newItem, field)
{
    try
    {
        for(var i = 0; i < this._buffer[this.PageIndex].length; i++)
        {
            if (newItem[field] == this._buffer[this.PageIndex][i][field])
            {
                this._buffer[this.PageIndex][i] = newItem;
                return true;
            }
        }
        return false;
    }
    catch(ex)
    {
        return false;
    }
}
BufferedPageContainer.prototype.GetItemIndex = function(field, fieldValue)
{
    try
    {
        for(var i = 0; i < this._buffer[this.PageIndex].length; i++)
        {
            if (fieldValue == this._buffer[this.PageIndex][i][field])
            {
                return i;
            }
        }
        return -1;
    }
    catch(ex)
    {
        return -1;
    }
}
/*BPC Start*/
//gettingHandler,completeHandler可选
function BPC(getMethod,callback,pageSize,gettingHandler,completeHandler)
{
    this.GetMethod = getMethod;
    this.PageSize = pageSize;
    this.Callback = callback;
    this.Pages = new Array();
    this.ItemCount = 0;
    this.PageCount = 0;
    this.GettingHandler = gettingHandler;
    this.CompleteHandler = completeHandler;
}
BPC.prototype.GetFirstPage = function()
{
    this.PageIndex = 0;
    this.GetCurrentPage();
}
BPC.prototype.GetPrePage = function()
{
    this.PageIndex = Math.max(0,this.PageIndex - 1);
    this.GetCurrentPage();
}
BPC.prototype.GetNextPage = function()
{
    if(this.PageCount)
    {
        this.PageIndex = Math.min(this.PageCount - 1,this.PageIndex + 1);
        this.GetCurrentPage();
    }
}
BPC.prototype.GetLastPage = function()
{
    if(this.PageCount)
    {
        this.PageIndex = this.PageCount - 1;
        this.GetCurrentPage();
    }
}
BPC.prototype.GetCurrentPage = function()
{
    this.GetPage(this.PageIndex);
}
BPC.prototype.GetPage = function(pageIndex)
{
    this.PageIndex = pageIndex;
    if(this.Pages[this.PageIndex])
    {
        this.Callback(this.Pages[this.PageIndex]);
        this.CheckSibling();
    }
    else
    {
        var context = new BPCContext(this,pageIndex,true);
        var callback = Function.createDelegate(context,context.Callback);
        this.GetMethod(this.PageIndex,this.PageSize,callback);
        if(this.GettingHandler)
        {
            this.GettingHandler();
        }
    }
}
BPC.prototype.GetPageSuccess = function(result,context)
{
    //result[0] = items, result[1] = totalItemCount
    if(this.CompleteHandler && context.InvokeCallback)
    {
        this.CompleteHandler();
    }
    if(result && result.length == 2)
    {
        this.ItemCount = result[1];
        this.PageCount = Math.ceil(this.ItemCount / this.PageSize);
        this.Pages[context.PageIndex] = result;
        if(context.InvokeCallback)
        {
            this.Callback(this.Pages[context.PageIndex]);
            this.CheckSibling();
        }        
    }
}
BPC.prototype.CheckSibling = function()
{
    if(this.PageIndex < this.PageCount - 1 && this.Pages[this.PageIndex + 1] == null)
    {
        this.Prefetch(this.PageIndex + 1);
    }
    if(this.PageIndex > 0 && this.Pages[this.PageIndex - 1] == null)
    {
        this.Prefetch(this.PageIndex - 1);
    }
}
BPC.prototype.Prefetch = function(pageIndex)
{
    var context = new BPCContext(this,pageIndex,false);
    var callback = Function.createDelegate(context,context.Callback);
    this.GetMethod(pageIndex,this.PageSize,callback);
}
BPC.prototype.IsFirstPage = function()
{
    return (this.PageIndex == 0);
}
BPC.prototype.IsLastPage = function()
{
    return (this.PageIndex == this.PageCount - 1);
}
BPC.prototype.ClearPagesFromCurrent = function()
{
    for(var i = this.PageIndex; i < this.PageCount; i++)
    {
        this.Pages[i] = null;
    }
}
BPC.prototype.ClearAllPages = function()
{
    for(var i = 0; i < this.PageCount; i++)
    {
        this.Pages[i] = null;
    }
}
function BPCContext(bpc,pageIndex,invokeCallback)
{
    this.BPC = bpc;
    this.PageIndex = pageIndex;
    this.InvokeCallback = invokeCallback;
}
BPCContext.prototype.Callback = function(result)
{
    this.BPC.GetPageSuccess(result,this);
}
/*BPC End*/
/*Slide Start*/
function Slide(targetElement, positionChangedHandler, classSlide, classBg)
{
    this.targetElement = targetElement;
    this.positionChangedHandler = positionChangedHandler;    
    this.oldMousemoveHandler = null;
	this.oldmouseupHandler = null;
	this.canMove = false;
	this.divSlide = document.createElement("div");
    this.divSlide.className = classSlide;
    this.divSlide.onmousemove = ReturnFalse;
    this.divSlide.onmousedown = ReturnFalse;
    this.div = document.createElement("div");
    this.div.className = classBg;
    this.div.onmousedown = Function.createDelegate(this,this.BeginMove);
    if(document.all)
    {
        this.div.ondrag = ReturnFalse;
    }
    this.div.appendChild(this.divSlide);
    this.targetElement.appendChild(this.div);
    this.value = 0;
}
Slide.prototype.SetValue = function(value)
{
    this.value = value;
    if(this.div.offsetWidth == 0 && this.targetElement.style.width != '')
    {
        this.divSlide.style.left = (value / 99) * (parseInt(this.targetElement.style.width) - this.width) + "px";
    }
    else
    {
        this.divSlide.style.left = (value / 99) * (this.div.offsetWidth - this.divSlide.offsetWidth) + "px";
    }
}
Slide.prototype.BeginMove = function(e)
{
    if(document.all)
	{
	    e = event;	    
	}
	this.canMove = true;
	var x = e.clientX - GetOffsetLeft(this.div);
	var imgWidth = this.divSlide.offsetWidth;
	var offsetX = x - imgWidth/2;
	if(offsetX >= 0 && offsetX <= this.div.offsetWidth - imgWidth)
	{
		this.divSlide.style.left = offsetX + "px";
		this.value = Math.floor(offsetX / (this.div.offsetWidth - imgWidth) * 99);
		this.positionChangedHandler(this.value);
	}
	this.oldMousemoveHandler = document.onmousemove;
	this.oldmouseupHandler = document.onmouseup;
	document.onmousemove = Function.createDelegate(this,this.Move);
	document.onmouseup = Function.createDelegate(this,this.EndMove);	
	//document.body.style.cursor = "pointer";
}
Slide.prototype.Move = function(e)
{
    if(this.canMove == false)
    {
        return;
    }
	if(document.all)
	{
	    e = event;	    
	}
	var x = e.clientX - GetOffsetLeft(this.div);
	var imgWidth = this.divSlide.offsetWidth;
	var offsetX = x - imgWidth/2;
	if(offsetX >= 0 && offsetX <= this.div.offsetWidth - imgWidth)
	{
		this.divSlide.style.left = offsetX + "px";
		this.value = Math.floor(offsetX / (this.div.offsetWidth - imgWidth) * 99);
		this.positionChangedHandler(this.value);
	}
}
Slide.prototype.EndMove = function()
{
	this.canMove = false;
	document.onmousemove = this.oldMousemoveHandler;
	document.onmouseup = this.oldmouseupHandler;
	document.body.style.cursor = '';
}
/*Slide End*/
/*Mover Start*/
function Mover(divTarget,divMover)
{
    this.source = divMover;
    this.target = divTarget;
    this.source.onmousedown = Function.createDelegate(this,this.OnMoveStart);
    this.source.onmouseover = Function.createDelegate(this,this.SetMouseStyle);
    this.source.ondrag = ReturnFalse;
    this.target.ondrag = ReturnFalse;
    this.HiddenObjects = new Array();
}
Mover.prototype.SetMouseStyle = function() 
{
    this.orgSourceMouseStyle = this.source.style.cursor;
    this.source.style.cursor = 'move';
}
Mover.prototype.OnMoveStart = function(e)
{
    if(document.all)
    {
        e = window.top.event;
    }
    this.orgDocumetOnMouseMove = window.top.document.onmousemove;
    this.orgDocumetOnMouseUp = window.top.document.onmouseup;
    this.mouseLeft = e.clientX;
    this.mouseTop = e.clientY;
    this.canMove = true;
    window.top.document.onmousemove = Function.createDelegate(this,this.Move);
    window.top.document.onmouseup = Function.createDelegate(this,this.OnMoveEnd);
    window.top.document.body.onselectstart = ReturnFalse;
}
Mover.prototype.OnMoveEnd = function(e)
{
    this.canMove = false;
    this.source.style.cursor = this.orgSourceMouseStyle;
    window.top.document.onmousemove = this.orgDocumetOnMouseMove;
    window.top.document.onmouseup = this.orgDocumetOnMouseUp;
    window.top.document.body.onselectstart = null;    
}
Mover.prototype.Move = function(e)
{
    if(document.all)
    {
        e = event;
    }
    if(e.clientX < 0 || e.clientX > window.top.document.documentElement.clientWidth || e.clientY < 0 || e.clientY > window.top.document.documentElement.clientHeight)
    {
        return;
    }
    if(this.canMove)
    {
        this.target.style.left = parseInt(this.target.style.left) + e.clientX - this.mouseLeft + 'px';
        this.target.style.top = parseInt(this.target.style.top) + e.clientY - this.mouseTop + 'px';
        this.mouseLeft = e.clientX;
        this.mouseTop = e.clientY;
        this.HideObjects();
        this.ShowObjects();
    }
}
Mover.prototype.HideObjects = function()
{
    var objects = document.getElementsByTagName('object');
    for(var i = 0; i < objects.length; i++)
    {
        if(IsOverLap(objects[i],this.target) && objects[i].style.visibility != 'hidden')
        {
            objects[i].style.visibility = 'hidden';
            this.HiddenObjects.push(objects[i]);
        }
    }
    var embeds = document.getElementsByTagName('embed');
    for(var i = 0; i < embeds.length; i++)
    {
        if(IsOverLap(embeds[i],this.target) && embeds[i].style.visibility != 'hidden')
        {
            embeds[i].style.visibility = 'hidden';
            this.HiddenObjects.push(embeds[i]);
        }
    }
}
Mover.prototype.ShowObjects = function()
{
    for(var i = this.HiddenObjects.length - 1; i >= 0 ; i--)
    {
        var object = this.HiddenObjects.pop();
        if(!IsOverLap(object,this.target))
        {
            object.style.visibility = 'visible';
        }
        else
        {
            this.HiddenObjects.push(object);
        }
    }
}
/*Mover End*/
/*Popup Menu Start*/
var hasShown;
var _SelfClickClose;
var _OutClickClose;
var _CloseHandler;
var _PopupMenuContent;
function TogglePopupMenu(content,left, top, width, height,selfClickClose,outClickClose,closeHandler)
{
    if(selfClickClose != null)
    {
        _SelfClickClose = selfClickClose;
    }
    else
    {
        _SelfClickClose = true;
    }
    if(outClickClose != null)
    {
        _OutClickClose = outClickClose;
    }
    else
    {
        _OutClickClose = true;
    }
    if(closeHandler != null)
    {
        _CloseHandler = closeHandler;
    }
    else
    {
        _CloseHandler = null;
    }
    var divPopupMenu = $("divPopupMenu");
    var divPopupMenuBg = $("divPopupMenuBg");
    var iframePopupMenu = $("iframePopupMenu");
    if(divPopupMenu == null)
    {
        divPopupMenu = document.createElement('div');
        divPopupMenu.id = 'divPopupMenu';
        divPopupMenu.style.position = 'absolute';
        divPopupMenu.className = 'divPopupMenu';
        divPopupMenuBg = document.createElement('div');
        divPopupMenuBg.id = 'divPopupMenuBg';
        divPopupMenuBg.style.position = 'absolute';
        iframePopupMenu = document.createElement('iframe');
        iframePopupMenu.id = 'iframePopupMenu';
        iframePopupMenu.frameBorder = '0';
        iframePopupMenu.allowTransparency = true;
        iframePopupMenu.src = "http://www.clozone.com/None.htm"
        divPopupMenuBg.appendChild(iframePopupMenu);        
        if(document.forms.length > 0)
        {
            var parent = document.forms[0];
        }
        else
        {
            var parent = document.body            
        }
        parent.insertBefore(divPopupMenuBg, parent.firstChild);
        parent.insertBefore(divPopupMenu, parent.firstChild);
    }    
    divPopupMenu.style.zIndex = 10;
    divPopupMenuBg.style.zIndex = 9;
    divPopupMenu.innerHTML = content;
    if(width != 0)
    {
        divPopupMenu.style.width = width + "px";
    }
    /*if(height != 0)
    {
        divPopupMenu.style.height = height + "px";
    }*/
    divPopupMenuBg.style.left = divPopupMenu.style.left = left + "px";
    divPopupMenuBg.style.top = divPopupMenu.style.top = top + "px";
    hasShown = false;
    document.onclick = DocumentClick;
    if(_PopupMenuContent == content)//Normal Toggle
    {
        if(divPopupMenu.style.display == "block")
        {
            HideMenu();
        }
        else
        {
            divPopupMenuBg.style.display = divPopupMenu.style.display = "block";
            iframePopupMenu.style.width = divPopupMenuBg.style.width = divPopupMenu.offsetWidth + "px";
            iframePopupMenu.style.height = divPopupMenuBg.style.height = divPopupMenu.offsetHeight + "px";
            if(!document.all)
            {
                iframePopupMenu.style.display = 'none';
            }
            HideObjects_Popup();
        }
    }
    else//Open Another new Popup Menu
    {
        _PopupMenuContent = content;
        divPopupMenuBg.style.display = divPopupMenu.style.display = "block";
        iframePopupMenu.style.width = divPopupMenuBg.style.width = divPopupMenu.offsetWidth + "px";
        iframePopupMenu.style.height = divPopupMenuBg.style.height = divPopupMenu.offsetHeight + "px";
        if(height != 0)
        {
            SetMaxHeight(divPopupMenu,height);
            SetMaxHeight(divPopupMenuBg,height);
        }
        if(!document.all)
        {
            iframePopupMenu.style.display = 'none';
        }
        HideObjects_Popup();
    }
}
function DocumentClick(e)
{
    if(hasShown == false)
    {
        hasShown = true;
        return;
    }
    var divPopupMenu = $("divPopupMenu");
    if(divPopupMenu == null)
    {
        return;
    }
    var top = divPopupMenu.offsetTop;
    var left = divPopupMenu.offsetLeft;
    var width = divPopupMenu.offsetWidth;
    var height = divPopupMenu.offsetHeight;
    var x,y;
    if(document.all)
    {
        x = event.offsetX + GetOffsetLeft(event.srcElement);
        y = event.offsetY + GetOffsetTop(event.srcElement);
    }
    else
    {
        x = e.offsetX >= 0 ? e.offsetX:0;
        x += GetOffsetLeft(e.target);
        y = e.offsetY >= 0 ? e.offsetY:0;
        y += GetOffsetTop(e.target);
    }    
    if(_OutClickClose == true)
    {
        if(x < left || x > left + width || y < top || y > top + height)
        {
            HideMenu();
        }
    }
    if(_SelfClickClose == true)
    {
        if(x > left && x < left + width && y > top && y < top + height)
        {
            HideMenu();
        }
    }
}
function ChangeMenu(content)
{
    var divPopupMenu = $("divPopupMenu");
    var divPopupMenuBg = $("divPopupMenuBg");
    var iframePopupMenu = $("iframePopupMenu");
    if(divPopupMenu != null)
    {
        divPopupMenu.innerHTML = content;
        iframePopupMenu.style.width = divPopupMenuBg.style.width = divPopupMenu.offsetWidth + "px";
        iframePopupMenu.style.height = divPopupMenuBg.style.height = divPopupMenu.offsetHeight + "px";
    }
}
function HideMenu()
{   
    var divPopupMenu = $("divPopupMenu");
    var divPopupMenuBg = $("divPopupMenuBg");
    if(divPopupMenu == null || divPopupMenu.style.display == "none")
    {
        return;
    }
    divPopupMenuBg.style.display = divPopupMenu.style.display = "none";
    ShowObjects_Popup();
    if(_CloseHandler != null)
    {
        _CloseHandler();
    }    
    document.onclick = null;
}
function GetPopupMenuHeight()
{
    var divPopupMenu = $("divPopupMenu");
    if(divPopupMenu != null)
    {
        return divPopupMenu.offsetHeight;
    }
    else
    {
        return 0;
    }
}
function IsPopupMenuShown()
{
    var divPopupMenu = $("divPopupMenu");
    if(divPopupMenu != null && divPopupMenu.style.display == 'block')
    {
        return true;
    }
    return false;
}
function SetPopupMenuPosition(left,top)
{
    $("divPopupMenu").style.left = $("divPopupMenuBg").style.left = left + 'px';
    $("divPopupMenu").style.top = $("divPopupMenuBg").style.top = top + 'px';
}
function ResizePopupMenu(width,height)
{
    var divPopupMenu = $("divPopupMenu");
    var divPopupMenuBg = $("divPopupMenuBg");
    var iframePopupMenu = $("iframePopupMenu");
    if(width == 0)
    {
        iframePopupMenu.style.width = divPopupMenuBg.style.width = divPopupMenu.offsetWidth + "px";        
    }
    else
    {
        iframePopupMenu.style.width = divPopupMenuBg.style.width = divPopupMenu.style.width = width + "px";
    }
    if(height == 0)
    {
        iframePopupMenu.style.height = divPopupMenuBg.style.height = divPopupMenu.offsetHeight + "px";
    }
    else
    {
        iframePopupMenu.style.height = divPopupMenuBg.style.height = divPopupMenu.style.height = height + "px";
    }
}
function SetZIndex(zIndex)
{
    var divPopupMenu = $("divPopupMenu");
    var divPopupMenuBg = $("divPopupMenuBg");
    if(divPopupMenu != null)
    {
        divPopupMenu.style.zIndex = zIndex;
    }
    if(divPopupMenuBg != null)
    {
        divPopupMenuBg.style.zIndex = zIndex - 1;
    }
}
function SetBgColor(control)
{
    control.className = 'divPopupOn';
}
function RemoveBgColor(control)
{
    control.className = 'divPopupOff';
}
var hiddenObjects_Popup = new Array();
function HideObjects_Popup()
{
    var divPopupMenu = $('divPopupMenu');
    var objects = document.getElementsByTagName('object');
    for(var i = 0; i < objects.length; i++)
    {
        if(IsOverLap(objects[i],divPopupMenu) && objects[i].style.visibility != 'hidden')
        {
            objects[i].style.visibility = 'hidden';
            hiddenObjects_Popup.push(objects[i]);
        }
    }
    var embeds = document.getElementsByTagName('embed');
    for(var i = 0; i < embeds.length; i++)
    {
        if(IsOverLap(embeds[i],divPopupMenu) && embeds[i].style.visibility != 'hidden')
        {
            embeds[i].style.visibility = 'hidden';
            hiddenObjects_Popup.push(embeds[i]);
        }
    }
}
function ShowObjects_Popup()
{
    var divPopupMenu = $('divPopupMenu');
    for(var i = hiddenObjects_Popup.length - 1; i >= 0 ; i--)
    {
        var object = hiddenObjects_Popup.pop();
        object.style.visibility = 'visible';
    }
}
/*Popup Menu End*/
/*Card Start*/
function DelayShowCard(divContent,control,width,left,top)
{
    ClearHideCard();
    divCard = $('divCard');
    if(divCard == null)
    {
        divCard = document.createElement('div');
        divCard.id = 'divCard';
        divCard.style.position = 'absolute';
        if(document.all)
        {
            divCard.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale src="http://www.clozone.com/Images/alpha70.png")'; 
        }
        else
        {
            divCard.style.background = 'url("http://www.clozone.com/Images/alpha70.png")';
        }
        var parent = document.body;
        parent.insertBefore(divCard, parent.firstChild);
    }
    if(left)
    {
        divCard.style.left = left + 'px';
    }
    else
    {
        divCard.style.left = ((GetOffsetLeft(control) + control.offsetWidth + width > document.documentElement.offsetWidth) ? (GetOffsetLeft(control) - width) : (GetOffsetLeft(control) + control.offsetWidth)) + 'px';
    }
    if(top)
    {
        divCard.style.top = top + 'px';
    }
    else
    {
        divCard.style.top = GetOffsetTop(control) + 'px';
    }    
    divCard.style.width = width + 'px';
    divCard.style.zIndex = 200;
    divCard.style.display = 'none';
    if(divCard.childNodes[0])
    {
        divCard.removeChild(divCard.childNodes[0]);
    }
    divCard.appendChild(divContent);
    divCard.onmouseover = ClearHideCard;
    divCard.onmouseout = DelayHideCard;
    delayShow = setTimeout("ShowCard()",500);
    ShowObjects_Card();
}
function ShowCard()
{
    if (window.divCard)
	{
		divCard.style.display = "block";
	}
	HideObjects_Card();
}
function Contains(parent, child)
{
    if(child)
    {
	    while (child.parentNode)
	    {
		    if ((child = child.parentNode) == parent)
			return true;
	    }
	}
	return false;
}
function HideCard()
{
	if (window.divCard)
	{
		divCard.style.display = "none";
	}
	ShowObjects_Card();
}
function DelayHideCard(e)
{
    ClearShowCard();
    if(document.all)
    {
        e = window.event;
    }
	var toElement = document.all? e.toElement: e.relatedTarget;
	var fromElement = document.all? e.fromElement: e.currentTarget;
	if(Contains(fromElement,toElement))
	{
		return;
	}
	delayHide = setTimeout("HideCard()",500);
}
function ClearShowCard()
{    
    if(window.delayShow)
    {
        clearTimeout(delayShow);
    }
}
function ClearHideCard()
{
    if (window.delayHide)
	{
		clearTimeout(delayHide);
	}
}
var hiddenObjects_Card = new Array();
function HideObjects_Card()
{
    var divCard = $('divCard');
    var objects = document.getElementsByTagName('object');
    for(var i = 0; i < objects.length; i++)
    {
        if(IsOverLap(objects[i],divCard) && objects[i].style.visibility != 'hidden')
        {
            objects[i].style.visibility = 'hidden';
            hiddenObjects_Card.push(objects[i]);
        }
    }
    var embeds = document.getElementsByTagName('embed');
    for(var i = 0; i < embeds.length; i++)
    {
        if(IsOverLap(embeds[i],divCard) && embeds[i].style.visibility != 'hidden')
        {
            embeds[i].style.visibility = 'hidden';
            hiddenObjects_Card.push(embeds[i]);
        }
    }
}
function ShowObjects_Card()
{
    var divCard = $('divCard');
    for(var i = hiddenObjects_Card.length - 1; i >= 0 ; i--)
    {
        var object = hiddenObjects_Card.pop();
        object.style.visibility = 'visible';
    }
}
/*Card End*/
/*OO PopupMenu*/
function PopupMenu(divElement, left, top, width, height, selfClickClose, outClickClose, closeHandler)
{
    this.Div = divElement;
    this.Left = left;
    this.Top = top;
    this.Width = width;
    this.Height = height;
    this.SelfClickClose = selfClickClose;
    this.OutClickClose = outClickClose;
    this.CloseHandler = closeHandler;
    this.HasShown = false;
    this.DivBg = document.createElement("div");
    this.iframe = document.createElement("iframe");
    this.Div.style.zIndex = 10;
    this.DivBg.style.zIndex = 9;
}
PopupMenu.prototype.DocClick = function(e)
{
    if(this.HasShown == false)
    {
        this.HasShown = true;
        return;
    }
    if(document.all)
    {
        var x = event.offsetX + GetOffsetLeft(event.srcElement);
        var y = event.offsetY + GetOffsetTop(event.srcElement);
    }
    else
    {
        var x = e.offsetX >= 0 ? e.offsetX:0;
        x += GetOffsetLeft(e.target);
        var y = e.offsetY >= 0 ? e.offsetY:0;
        y += GetOffsetTop(e.target);
    }
    var left = GetOffsetLeft(this.Div);
    var top = GetOffsetTop(this.Div);
    var width = this.Div.offsetWidth;
    var height = this.Div.offsetHeight;
    if(this.OutClickClose == true)
    {        
        if(x < left || x > left + width || y < top || y > top + height)
        {
            this.Hide();
        }
    }
    if(this.SelfClickClose == true)
    {
        if(x > left && x < left + width && y > top && y < top + height)
        {
            this.Hide();
        }
    }
}
PopupMenu.prototype.Show = function()
{ 
    document.body.insertBefore(this.Div,document.body.firstChild);
    this.Div.parentNode.appendChild(this.DivBg);
    this.DivBg.appendChild(this.iframe);
    
    this.DivBg.style.display = this.Div.style.display = "block";    
    this.iframe.frameBorder = "0";
    if(this.Width != 0)
    {
        this.Div.style.width = this.Width  + "px";
    }
    if(this.Height != 0)
    {
        this.Div.style.height = this.Height + "px";
    }
    this.iframe.width = this.DivBg.style.width = this.Div.offsetWidth  + "px";
    this.iframe.height = this.DivBg.style.height = this.Div.offsetHeight + "px";
    this.DivBg.style.left = this.Div.style.left = this.Left + "px";
    this.DivBg.style.top = this.Div.style.top = this.Top + "px";    
    this.DivBg.style.position = this.Div.style.position = "absolute";  
   
    this.Div.style.backgroundColor = "#FFFFFF";    
    
    if(!document.all)
    {
        this.iframe.style.display = 'none';
    }
    this.HasShown = false;
    this.preDocClick = document.onclick;
    document.onclick = Function.createDelegate(this, this.DocClick);
    if(typeof(GetDivPlayer) != 'undefined' && GetDivPlayer() != null)
    {
        var divPlayer = GetDivPlayer();
        if(IsOverLap(divPlayer,this.Div))
        {
            HidePlayer();
        }
    }
}
PopupMenu.prototype.Hide = function()
{
    if(this.Div.style.display == "none")
    {
        return;
    }
    this.DivBg.style.display = this.Div.style.display = "none";    
    if(this.CloseHandler != null)
    {
        this.CloseHandler();
    }
    if(typeof(GetDivPlayer) != 'undefined' && GetDivPlayer() != null)
    {
        ShowPlayer();
    }
    document.body.removeChild(this.Div);
    document.body.removeChild(this.DivBg);
    document.onclick = this.preDocClick; 
}
PopupMenu.prototype.Toggle = function()
{
    if(this.HasShown)
    {
        this.Hide();
    }
    else
    {
        this.Show();
    }
}
PopupMenu.prototype.GetPopupMenuHeight = function()
{
    return this.Div.offsetHeight;
}
PopupMenu.prototype.ChangeMenu = function(content)
{
    this.Div.innerHTML = content;
    this.iframe.width = this.DivBg.style.width = this.Div.offsetWidth  + "px";
    this.iframe.height = this.DivBg.style.height = this.Div.offsetHeight + "px";
}
PopupMenu.prototype.SetZIndex = function(zIndex)
{
    this.Div.style.zIndex = zIndex;
    this.DivBg.style.zIndex = zIndex - 1;
}
function CommonBox(content, title, left, top, width, height, moveable, middle, closeHandler)
{
    var table = window.top.document.createElement('table');
    table.cellSpacing = 0;
    table.cellPadding = 0;
    var row = table.insertRow(0);
    this.Title = row;
    var cell = row.insertCell(0);
    cell.innerHTML = '&nbsp;';
    cell.style.width = '17px';
	cell.style.height = '35px';
    if(Navigator.IE6)
    {        
	    cell.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://www.clozone.com/images/CommonBox/left_top.png")';
    }
    else
    {
        cell.style.background = 'url(http://www.clozone.com/images/CommonBox/left_top.png) no-repeat';
    }
    cell = row.insertCell(1);
	cell.style.height = '35px';
    if(Navigator.IE6)
    {        
	    cell.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://www.clozone.com/images/CommonBox/top.png",sizingMethod="scale")';
    }
    else
    {
        cell.style.background = 'url(http://www.clozone.com/images/CommonBox/top.png) repeat-x';
    }
    var spanTitle = window.top.document.createElement('span');
    spanTitle.innerHTML = title;
    spanTitle.style.margin = '15px 0px 0px 5px';
    spanTitle.style.lineHeight = 'normal';
    SetFloatLeft(spanTitle);
    cell.appendChild(spanTitle);    
    var imgClose = window.top.document.createElement('img');
    imgClose.id = 'imgClose';
    imgClose.src = 'http://www.clozone.com/images/CommonBox/close.gif';
    imgClose.onclick = Function.createDelegate(this,this.Hide);
    imgClose.alt = '关闭';
    cell.appendChild(imgClose);    
    cell = row.insertCell(2);
    cell.style.width = '17px';
	cell.style.height = '35px';
    if(Navigator.IE6)
    {        
	    cell.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://www.clozone.com/images/CommonBox/right_top.png")';
    }
    else
    {
        cell.style.background = 'url(http://www.clozone.com/images/CommonBox/right_top.png) no-repeat';
    }
    cell.innerHTML = '&nbsp;';
    row = table.insertRow(1);
    if(height)
    {
        row.style.height = height + 'px';
    }
    cell = row.insertCell(0);
    cell.innerHTML = '&nbsp;';
    cell.style.width = '17px';
    if(Navigator.IE6)
    {        
	    cell.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://www.clozone.com/images/CommonBox/left.png",sizingMethod="scale")';
    }
    else
    {
        cell.style.background = 'url(http://www.clozone.com/images/CommonBox/left.png) repeat-y';
    }
    cell = row.insertCell(1);
    cell.className = 'CenterCommon';
    if(width)
    {
        cell.style.width = width + 'px';
    }
    if (typeof content == 'object')
    {
        cell.appendChild(content);
    }
    else
    {
        cell.innerHTML = content;
    }
    this.divContent = cell;
    cell = row.insertCell(2);
    cell.innerHTML = '&nbsp;';
    cell.style.width = '17px';
    if(Navigator.IE6)
    {        
	    cell.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://www.clozone.com/images/CommonBox/right.png",sizingMethod="scale")';
    }
    else
    {
        cell.style.background = 'url(http://www.clozone.com/images/CommonBox/right.png) repeat-y';
    }
    row = table.insertRow(2);
    cell = row.insertCell(0);
    cell.innerHTML = '&nbsp;';
    cell.style.width = '17px';
    cell.style.height = '17px';
    if(Navigator.IE6)
    {        
	    cell.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://www.clozone.com/images/CommonBox/left_bottom.png")';
    }
    else
    {
        cell.style.background = 'url(http://www.clozone.com/images/CommonBox/left_bottom.png) no-repeat';
    }
    cell = row.insertCell(1);
    cell.style.height = '17px';
    if(Navigator.IE6)
    {        
	    cell.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://www.clozone.com/images/CommonBox/bottom.png",sizingMethod="scale")';
    }
    else
    {
        cell.style.background = 'url(http://www.clozone.com/images/CommonBox/bottom.png) repeat-x';
    }
    cell.innerHTML = '&nbsp;';
    cell = row.insertCell(2);
    cell.innerHTML = '&nbsp;';
    cell.style.width = '17px';
    cell.style.height = '17px';
    if(Navigator.IE6)
    {        
	    cell.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://www.clozone.com/images/CommonBox/right_bottom.png")';
    }
    else
    {
        cell.style.background = 'url(http://www.clozone.com/images/CommonBox/right_bottom.png) no-repeat';
    }
    
    this.divCommonBox = window.top.document.createElement('div');
    this.divCommonBox.id = 'divCommonBox';
    this.divCommonBox.appendChild(table);
    this.defaultZIndex = 150;
    this.divCommonBox.style.zIndex = this.defaultZIndex;
    if(left)
    {
        this.divCommonBox.style.left = left + 'px';
    }
    if(top)
    {
        this.divCommonBox.style.top = top + 'px';
    }
    this.divCommonBox.style.display = 'none';    
    this.divBackground = window.top.document.createElement('div');
    this.divBackground.id = 'divCommonBoxBackground';
    this.divBackground.style.zIndex = this.defaultZIndex - 1;
    this.divBackground.style.display = 'none';
    var parent = window.top.document.body;
    parent.insertBefore(this.divBackground, parent.firstChild);  
    parent.insertBefore(this.divCommonBox, parent.firstChild);
    this.middle = middle;
    if(moveable == true)
    {
        new Mover(this.divCommonBox, this.Title)
    }    
    this.CloseHandler = closeHandler;
    this.HiddenObjects = new Array();
}
CommonBox.prototype.Show = function(left,top)
{
    if(left != null)
    {
        this.divCommonBox.style.left = left + 'px';
    }
    if(top != null)
    {
        this.divCommonBox.style.top = top + 'px';
    }
    this.divCommonBox.style.display = "block";
    this.divBackground.style.left = '0px';
    this.divBackground.style.top = '0px';
    this.divBackground.style.width = Math.max(window.top.document.documentElement.scrollWidth,window.top.document.documentElement.clientWidth) + 'px';
    this.divBackground.style.height = Math.max(window.top.document.documentElement.scrollHeight,window.top.document.documentElement.clientHeight) + 'px';
    this.divBackground.style.display = "block";
    if(this.middle == true)
    {
        ShowMiddle(this.divCommonBox);
    }
    var objects = document.getElementsByTagName('object');
    for(var i = 0; i < objects.length; i++)
    {
        if(IsOverLap(objects[i],this.divCommonBox) && objects[i].style.visibility != 'hidden')
        {
            objects[i].style.visibility = 'hidden';
            this.HiddenObjects.push(objects[i]);
        }
    }
    var embeds = document.getElementsByTagName('embed');
    for(var i = 0; i < embeds.length; i++)
    {
        if(IsOverLap(embeds[i],this.divCommonBox) && embeds[i].style.visibility != 'hidden')
        {
            embeds[i].style.visibility = 'hidden';
            this.HiddenObjects.push(embeds[i]);
        }
    }
}
CommonBox.prototype.Hide = function()
{
    this.divCommonBox.style.display = "none";
    this.divBackground.style.display = "none";
    for(var i = this.HiddenObjects.length - 1; i >= 0 ; i--)
    {
        var object = this.HiddenObjects.pop();
        object.style.visibility = 'visible';
    }
    if(this.CloseHandler != null)
    {
        this.CloseHandler();
    }
}
CommonBox.prototype.SetContent = function(content)
{
    this.divContent.innerHTML = content;    
}
CommonBox.prototype.Toggle = function(left,top)
{
    if(this.divCommonBox.style.display == "block")
    {
        this.Hide();
    }
    else
    {
        this.Show(left,top);
    }
}
CommonBox.prototype.SetZIndex = function(zIndex)
{
    this.divCommonBox.style.zIndex = zIndex;
    this.divBackground.style.zIndex = zIndex - 1;
}
function ShowProcess(message)
{
    var topWindow = window.top;
    var topDocument = topWindow.document;
    var divProcess = topDocument.getElementById('divProcess');
    if(divProcess != null)
    {
        divProcess.style.display = 'block';
        divProcess.innerHTML = message;
    }
    else
    {
        divProcess = topDocument.createElement('div');
        divProcess.id = 'divProcess';
        divProcess.style.position = 'absolute';
        divProcess.style.padding = '3px';
        divProcess.style.color = '#FFFFFF';
        divProcess.style.fontWeight = 'bold';
        divProcess.style.backgroundColor = '#CC0000';
        divProcess.style.zIndex = 100;
        divProcess.innerHTML = message;
        topDocument.body.insertBefore(divProcess, topDocument.body.firstChild);
        if(topWindow.addEventListener)
        {
            window.addEventListener('scroll', MoveProcess, false);
            window.addEventListener('resize', MoveProcess, false);
        }
        else if(window.attachEvent)
        {
            window.attachEvent('onscroll', MoveProcess);
	        window.attachEvent('onresize', MoveProcess);
        }
    }
    MoveProcess();
}
function HideProcess()
{
    var divProcess = window.top.$('divProcess');
    if(divProcess != null)
    {
        divProcess.style.display = 'none';
    }
}
function MoveProcess()
{
    var scrollYT, scrollXT;
    var topWindow = window.top;
    var topDocument = topWindow.document;
    var divProcess = topDocument.getElementById('divProcess');
    if(divProcess == null)
    {
        return;
    }
    if(document.all)
    {
        scrollYT = topDocument.documentElement.scrollTop; 
		scrollXT = topDocument.body.scrollLeft;
    }
    else
    { 
		scrollYT = topWindow.pageYOffset; 
		scrollXT = topWindow.pageXOffset; 
	}
	divProcess.style.top = scrollYT + 1 + "px";
	divProcess.style.right = -scrollXT + "px";
	divProcess.style.top = scrollYT + "px";
	
}
function ShowResultBox(message, success)
{
    HideProcess();
    var title = '提示';
    var html = ''+
    '<div id="divResult" style="margin:20px auto 20px auto;text-align:center;">'+
        message + '<br /><br /><input id="btnResultClose" type="button" onclick="HideResultBox()" value="确定" class="btnCommon2"/>'+
    '</div>';
    if(window.top.boxResult)
    {
        window.top.boxResult.SetContent(html);        
    }
    else
    {
        window.top.boxResult = new window.top.CommonBox(html,title,0,0,200,100,false,true,null);
    }
    window.top.boxResult.SetZIndex(window.top.boxResult.defaultZIndex + 2);
    window.top.boxResult.Show();
    window.top.$('btnResultClose').focus();
    if(success)
    {        
        setTimeout("HideResultBox()",1000);
    }    
}
function HideResultBox()
{
    if(window.top.boxResult)
    {
        window.top.boxResult.Hide();
    }
}
/*Login Related*/
var _loginSuccessHandler = new Array();
var loginBox = null;
function ToggleLoginBox(loginSuccessHandler)
{
    var html = '';
    html += '<div id="divLogin" style="width:190px;margin: 10px auto 0px auto;">';
    html += '用户名:'
    html += '<input id="txtUsername" type="text" style="border-width:0px; border-bottom:solid 1px #ccc;width:140px;"/><br />';
    html += '密码　:';
    html += '<input id="txtPassword" type="password" onkeydown="if(event.keyCode == 13) Login($(\'txtUsername\').value,$(\'txtPassword\').value);" style="border-width:0px; border-bottom:solid 1px #ccc;width:140px;"/><br />';
    html += '<a href="http://www.clozone.com/" onclick="GetPassword($(\'txtUsername\').value);return false;">忘记密码?</a>&nbsp;&nbsp;&nbsp;';
    html += '<a href="http://www.clozone.com/" onclick="ToggleRegisterBox();loginBox.Hide();return false;">获取一个新帐号</a>';
    html += '<div style="text-align:right;">';
    html += '<input class="btnCommon2" type="button" value="登录" onclick="Login($(\'txtUsername\').value,$(\'txtPassword\').value);" />';
    html += '</div>';
    html += '</div>';
    if(loginSuccessHandler != null)
    {
        _loginSuccessHandler = _loginSuccessHandler.concat(loginSuccessHandler);
    }
    if(loginBox == null)
    {
        loginBox = new CommonBox(html,'用户登录',0,0,300,180,false,true,null);
    }
    loginBox.Toggle();
    SetFocus('txtUsername');
}
function GetPassword(username)
{
    if(username == "")
    {
        alert("请填写用户名");
        return;
    }
    ShowProcess('正在提交请求，请稍候...');
    Clozone.Web.WebService.User.GetPassword(username,GetPasswordSuccess);
    if(window.loginBox)//For Test
    {
        loginBox.Hide();
    }
}
function GetPasswordSuccess(result)
{
    HideProcess();
    switch(result)
    {
        case 0:
            ShowResultBox('获取密码请求已发送至您的注册邮箱，请注意查收',false);
            break;
        case 1:
            ShowResultBox('您的注册邮箱尚未通过验证，无法获取密码',false);
            break;
        case 2:
            ShowResultBox('您的用户名不存在，请确认后重试',false);
            break;
        default:
            ShowResultBox('有错误发生，请重试',false);
            break;
    }    
}
var boxRegister = null;
function ToggleRegisterBox()
{
    var width = 500;
    var height = 400;
    var html = '<iframe src="/Register.aspx" frameborder="0" width="' + width + 'px" height="' + height + 'px" scrolling="no"></iframe>';
    if(boxRegister == null)
    {
        boxRegister = new CommonBox(html,'用户注册',0,0,width,0,false,true,null);
    }
    else
    {
        boxRegister.SetContent(html);
    }
    boxRegister.Toggle();
}
var boxCreateGroup = null;
function ToggleCreateGroupBox()
{
    var width = 500;
    if(document.all)
    {
        var height = '410';
    }
    else
    {
        var height = '420';
    }
    var html = '<iframe src="/CreateGroup.aspx" frameborder="0" width="' + width + 'px" height="' + height + 'px" scrolling="no"></iframe>';
    if(boxCreateGroup == null)
    {
        boxCreateGroup = new CommonBox(html,'创建新群组',0,0,width,0,false,true,GetGroups);
    }
    else
    {
        boxCreateGroup.SetContent(html);
    }
    boxCreateGroup.Toggle();
}
function AddLoginSuccessHanlder(handler)
{
    _loginSuccessHandler = _loginSuccessHandler.concat(handler);
}
function ClearLoginSuccessHanlder()
{
    _loginSuccessHandler = new Array();
}
function Login(username,password)
{
    if(username == "")
    {
        alert("请填写用户名");
        return;
    }        
    if(password == "")
    {
        alert("请填写密码");
        return;
    }    
    ShowProcess('正在登陆，请稍候...');
    Clozone.Web.WebService.User.Login(username, password,GetResultFromLogin);
    if(window.loginBox)//For Test
    {
        loginBox.Hide();
    }
}  
function GetResultFromLogin(result)
{
    HideProcess();
    if(result == 0)
    {
        if(_loginSuccessHandler != null && _loginSuccessHandler.length > 0)
        {
            for(var i = 0; i < _loginSuccessHandler.length; i++)
            {
                _loginSuccessHandler[i]($("txtUsername").value);
            }
        }
        else
        {
            window.location.href = window.location.href;
        }
    }
    if(result == -1)
    {
        ShowResultBox("该用户名不存在",false);
    }
    if(result == -2)
    {
        ShowResultBox("密码错误",false);
    }
    if(result == -3)
    {
        ShowResultBox("有错误发生",false);
    }
}
function Logout()
{
    ShowProcess('正在注销，请稍候...');
    Clozone.Web.WebService.User.Logout(LogoutSuccess);
}
function LogoutSuccess(result)
{
    if(result == true)
    {
        window.location.href = window.location.href;
    }
    else
    {
        ShowResultBox("注销失败，请重试",false);
    }
}
function GetMyRank()
{
    Clozone.Web.WebService.Main.GetMyRank(GetMyRankSuccess);
    ShowProcess('正在获取您的排名，请稍候...');
}
function GetMyRankSuccess(result)
{
    HideProcess();
    if(result == null)
    {
        ShowResultBox('有错误发生，请重试',false);
    }
    var rank = result;
    var html = ''+
    '<div style="text-align:center;margin:10px;">'+
        '<table width="100%">'+
            '<caption><b>以下是您在酷螺网的排名</b></caption>'+
            '<tr><td width="50%">综合排名：</td><td>第' + rank.TotalRank + '位</td></tr>'+
            '<tr><td>博客排名：</td><td>第' + rank.BlogRank + '位</td></tr>'+
            '<tr><td>图片排名：</td><td>第' + rank.PhotoRank + '位</td></tr>'+
            '<tr><td>网摘排名：</td><td>第' + rank.BookmarkRank + '位</td></tr>'+
            '<tr><td>音乐排名：</td><td>第' + rank.MusicRank + '位</td></tr>'+
            '<tr><td>人际排名：</td><td>第' + rank.SnsRank + '位</td></tr>'+
        '</table>'+
    '</div>';
    
    if(!window.boxRank)
    {
        boxRank = new CommonBox(html,'排名信息',null,null,250, 180, false, true, null);
    }
    else
    {
        boxRank.SetContent(html);
    }
    boxRank.Show();
}

function ShowMiddle(div)
{
    var scrollYT, scrollXT;
    var topWindow = window.top;
    var topDocument = topWindow.document;
    if(div == null)
    {
        return;
    }
    if(document.all)
    {
        scrollYT = topDocument.documentElement.scrollTop; 
		scrollXT = topDocument.documentElement.scrollLeft;
    }
    else
    { 
		scrollYT = topWindow.pageYOffset; 
		scrollXT = topWindow.pageXOffset; 
	}
	var top = Math.floor((topDocument.documentElement.clientHeight - div.offsetHeight) / 2) + scrollYT;
	if(top < 0)
	{
	    top = 0;
	}
	var left = Math.floor((topDocument.documentElement.clientWidth - div.offsetWidth) / 2) + scrollXT;
	if(left < 0)
	{
	    left = 0;
	}
    div.style.top = top + 'px';
    div.style.left = left + 'px';
}

function UIGenerator_CreateLinklistTable(targetDocument, linkList)
{
    var table = targetDocument.createElement('TABLE');
    table.width = "100%";
    table.border = 0;
    table.align = "center";
    table.cellPadding = 0;
    table.cellSpacing = 0;
    table.style = "word-break:break-all;width:100%";
    for (var i = 0; i < linkList.length; i++)
    {
        row = table.insertRow(-1);
        cell = row.insertCell(-1);
        var div = document.createElement('div');
        div.style.width = "100%";
        div.style.overflow = "hidden";
        div.style.lineHeight = "auto";
        div.className = "divBottomLine1";
        div.appendChild(linkList[i]);
        cell.appendChild(div);
    }
    return table;
}
function UIGenerator_CreateList_HTML(linkList)
{
    
    var html = '<table width=100% border=0 align="center" cellPadding=0 cellSpacing=0 style="word-break: break-all;overflow:hidden;width:100%">';    
    for (var i = 0; i < linkList.length; i++)
    {
        html += '<tr><td><div class="divBottomLine1" style="width:100%;overflow:hidden">' + linkList[i] + '</div></td></tr>';
    }
    html += '</table>';
    return html
}
function RemoveElementEvents(element)
{
    if (element != null)
    { 
        if (typeof(element.onclick) != 'undefined' && element.onclick != ViewImage)
        {   
            element.onclick = null;
        }        
        if (typeof(element.onload) != 'undefined')
        {   
            element.onload = null;
        }
        if (typeof(element.onmouseout) != 'undefined')
        {   
            element.onmouseout = null;
        }
        if (typeof(element.onmouseover) != 'undefined')
        {   
            element.onmouseover = null;
        }
        if (typeof(element.onmouseup) != 'undefined')
        {   
            element.onmouseup = null;
        }
        if (typeof(element.onblur) != 'undefined')
        {   
            element.onblur = null;
        }
        if (typeof(element.onactivate) != 'undefined')
        {   
            element.onload = null;
        }
        if (typeof(element.onactivate) != 'undefined')
        {   
            element.onload = null;
        }
        if (typeof(element.onmousedown) != 'undefined')
        {   
            element.onmousedown = null;
        }if (typeof(element.onmousemove) != 'undefined')
        {   
            element.onmousemove = null;
        }
        if (typeof(element.onmouseup) != 'undefined')
        {   
            element.onmouseup = null;
        }
        if (typeof(element.onkeypress) != 'undefined')
        {   
            element.onkeypress = null;
        }
        // to do
        
        var oChilds = element.childNodes;
        for (var i = oChilds.length - 1; i >= 0; i--)
        {
            if(oChilds[i].tagName && (oChilds[i].tagName.toLowerCase() == 'script' || oChilds[i].tagName.toLowerCase() == 'link'))
            {
                element.removeChild(oChilds[i]);
            }
            else
            {
                RemoveElementEvents(oChilds[i]);           
            }
        }
    }    
}
function IsSafeElement(e)
{
    if(e.onabort || e.onactive|| e.onafterprint || e.onafterupdate || e.onbeforeactive || e.onbeforecopy || e.onbeforecut || e.onbeforedeactive || e.onbeforeeditfocus || e.onbeforepaste || e.onbeforeprint ||
     e.onbeforeupload || e.onbeforeupdate || e.onblur || e.onbounce || e.oncellchange || e.onchange || e.onclick || e.oncontextmenu || e.oncontrolselect || e.oncopy || e.oncut || e.ondataavailable || e.ondatasetchanged ||
     e.ondatasetcomplete || e.ondblclick || e.ondeactive || e.ondrag || e.ondragend || e.ondragenter || e.ondragleave || e.ondragover || e.ondragstart || e.ondrop || e.onerror || e.onerrorupdate || e.onfilterchange ||
     e.onfinish || e.onfocus || e.onfocusin || e.onfocusout || e.onhelp || e.keydown || e.onkeypress || e.onkeyup || e.onlayoutcomplete || e.onload || e.onlosecapture || e.onmousedown || e.onmouseenter || e.onmouseleave ||
     e.onmousemove || e.onmouseout || e.onmouseover || e.onmouseup || e.onmousewheel || e.onmove || e.onmoveend || e.onmovestart || e.onpaste || e.onpropertychange || e.onreadystatechange || e.onreset || e.onresize ||
     e.onresizeend || e.onresizestart || e.onrowenter || e.onrowdelete || e.onrowinserted || e.onscroll || e.onselect || e.onselectionchange || e.onselectstart || e.onstart || e.onstop || e.onsubmit || e.onunload)
    {
        alert('由于安全原因，不允许定义事件');
        return false;
    }
    if(e.tagName && e.tagName.toLowerCase() == 'script')
    {
        alert('由于安全原因，不允许运行脚本');
        return false;
    }
    if(e.tagName && e.tagName.toLowerCase() == 'link')
    {
        alert('由于安全原因，不允许使用<Link>标签');
        return false;
    }
    if(e.tagName && e.tagName.toLowerCase() == 'style')
    {
        if(e.innerHTML.toLowerCase().indexOf('javascript:') != -1)
        {
            alert('请勿在<style>标签中使用脚本进行黑客行为');
            return false;
        }
    }
    if(e.attributes)
    {
        for(var i = 0; i < e.attributes.length; i++)
        {
            if(e.attributes[i].value.toLowerCase().indexOf('javascript:') != -1)
            {
                alert('由于安全原因，不允许运行脚本');
                return false;
            }
        }
    }
    for(var i = 0; i < e.childNodes.length; i++)
    {
        if(!IsSafeElement(e.childNodes[i]))
        {
            return false;
        }
    }
    return true;   
}
/*** blog write div start ***/
/*function ResizeWriteDiv()
{
    var divWriteBlog= $('divWriteBlog');

    var left = divWriteBlog.offsetParent.scrollLeft; 
    if (document.documentElement.clientWidth > 850)
    {
        left += (document.documentElement.clientWidth - 850) / 2;
    }
    divWriteBlog.style.left = left + 'px';
    
    var top = divWriteBlog.offsetParent.scrollTop;
    if (document.documentElement.clientHeight > 580)
    {
        top += (document.documentElement.clientHeight - 580) / 2;
    }
    divWriteBlog.style.top = top + 'px';     
}     */
var boxAddBlog;
function ShowWriteBlogDiv(blogID)
{   
    var editPage = 'http://' + prefix + '.clozone.com/_BlogEdit.aspx';
    if (blogID != 0)
    {
        editPage += '?BlogID=' + blogID;
    } 
    var width;
    if (blogID == 0)
    {
        width = 810;
    }
    else
    {
        width = 610;
    }    
    var html = '<div style="width: 95%;">'
                 + '<iframe id="iframeBlogEdit" src="' + editPage + '" frameborder="0" scrolling="auto" width="100%" height="570px"></iframe>'
             + '</div>';
    boxAddBlog = new CommonBox(html, '编辑博客', 0, 0, width, 0, true, true, null);
    boxAddBlog.Show();
}
var boxAddBlog_Group;
function ShowWriteBlogDiv_Group()
{   
    var editPage = 'http://' + prefix + '.clozone.com/_BlogEdit_Group.aspx';   
    var width = 650; 
    var html = '<div style="width:100%;">'
             + '<iframe id="iframeBlogEdit" src="' + editPage + '" frameborder="0" scrolling="no" width="100%" height="600px"></iframe>'
             + '</div>';
    
    boxAddBlog_Group = new CommonBox(html, '编辑文章', 0, 0, width, 0, true, true, null);
    boxAddBlog_Group.Show();
}
/*** blog write div end ***/
var boxAddBookmark;
function ShowWriteBookmarkDiv(bookmarkID)
{       
    var editPage = 'http://' + prefix + '.clozone.com/_BookmarkEdit.aspx?BookmarkID=' + bookmarkID;
    var width;
    if (bookmarkID == -1)
    {
        width = 810;
    }
    else
    {
        width = 610;
    }   
    var html = '<div style="width: 95%;">'
                 + '<iframe id="iframeBookmarkEdit" src="' + editPage + '" frameborder="0" scrolling="no" width="100%" height="580px"></iframe>'
             + '</div>';
    
    boxAddBookmark = new CommonBox(html, '编辑网摘', 0, 0, width, 0, true, true, null);
    boxAddBookmark.Show();
}
var boxAddBookmark_Group;
function ShowWriteBookmarkDiv_Group()
{       
    var editPage = 'http://' + prefix + '.clozone.com/_BookmarkEdit_Group.aspx';  
    var width = 650;       
    var html = '<div style="width:100%;">'
             + '<iframe id="iframeBookmarkEdit" src="' + editPage + '" frameborder="0" scrolling="no" width="100%" height="600px"></iframe>'
             + '</div>';
    boxAddBookmark_Group = new CommonBox(html, '编辑网摘', 0, 0, width, 0, true, true, null);
    boxAddBookmark_Group.Show();
}
function ShowWriteBookmarkDivByContent(contentType, extraID)
{
    var editPage = 'http://' + prefix + '.clozone.com/_BookmarkEdit.aspx?prefix=' + prefix + '&extraID='+extraID+'&contentType='+contentType;   
    var width = 810;    
    var html = '<div style="width:95%">'
                 + '<iframe id="iframeBookmarkEdit" src="' + editPage + '" frameborder="0" scrolling="no" width="100%" height="580px"></iframe>'
             + '</div>';
    boxAddBookmark = new CommonBox(html, '编辑网摘', 0, 0, width, 0, true, true, null);
    boxAddBookmark.Show();
}
function CloseWriteBookmarkDiv()
{
    HideMenu();
}
function ShowPlayer_Bookmark()
{
    var divRssReader=$("divRssReader");
    if (divRssReader!=null)
    {
        if (divRssReader.style.display!='none')
            return;
    }
    ShowPlayer();   
}
/*** bookmark write div end ***/
function GetArrayIndex(tArray, attribute, value)
{
    try
    {
        for(var i = 0; i < tArray.length; i++)
        {
            if (tArray[i][attribute] == value)
            {
                return i;
            }
        }
        return -1;
    }
    catch(e)
    {
        return -1;
    }
}
/****编辑模式**/
function SetEditMode(control)
{
    control = control.parentNode;
    if (control.childNodes[1].style.display == 'none')
    {
        control.childNodes[1].style.display = 'block';
        control.childNodes[1].focus();
        control.childNodes[0].style.display = 'none';
    }
    else
    {
        control.childNodes[1].style.display = 'none';
        control.childNodes[0].style.display = 'block'; 
    }
}
function DashIn(control)
{
    control.style.borderStyle = 'dashed';

}
function DashOut(control)
{
    control.style.borderStyle = 'none';
}
function ReplaceEnter(strContent)
{
    var returnData = strContent;
    while(returnData.indexOf('\n') != -1)
    {
        returnData = returnData.replace('\n', '<br />');
    }
    return returnData;
}
function ReplaceBR(strContent)
{
    var returnData = strContent;
    while(returnData.indexOf('<br />') != -1)
    {
        returnData = returnData.replace('<br />', '\n');
    }
    return returnData;
}
function RemoveBR(strContent)
{
    var returnData = strContent;
    while(returnData.indexOf('<br>') != -1)
    {
        returnData = returnData.replace('<br>', ' ');
    }
    return returnData;
}
function BaseUserCard(user)
{
    var table = document.createElement('table');
    var row = table.insertRow(0);
    var cell = row.insertCell(0);
    cell.rowSpan = 5;
    cell.width = 110;
    //cell.align = 'center';
    cell.innerHTML = '<div class="divImgCard"><img class="imgCard" src="http://www.clozone.com/' + (user.PortraitUploaded? ('UserFile/' + user.Username + '/' + user.Username + 'Big.jpg'):('images/nopicBig.gif')) + '" ></div>';
    cell = row.insertCell(1);
    cell.innerHTML = '用户名：<a href="http://' + user.Username + '.clozone.com" target="_blank">' + user.Username +'</a>';
    row = table.insertRow(1);
    cell = row.insertCell(0);
    cell.innerHTML = '昵称&nbsp;&nbsp;&nbsp;：' + user.Nickname;
    row = table.insertRow(2);
    cell = row.insertCell(0);
    cell.innerHTML = '性别&nbsp;&nbsp;&nbsp;：' + user.Gender;
    row = table.insertRow(3);
    cell = row.insertCell(0);
    cell.innerHTML = '年龄&nbsp;&nbsp;&nbsp;：' + user.Age;
    row = table.insertRow(4);
    cell = row.insertCell(0);
    cell.innerHTML = '城市&nbsp;&nbsp;&nbsp;：' + user.City;
    row = table.insertRow(5);
    cell = row.insertCell(0);
    cell.colSpan = 2;
    cell.innerHTML = '最近登录：' + TimeFormat(user.LatestActiveTime);
    row = table.insertRow(6);
    cell = row.insertCell(0);
    cell.colSpan = 2;
    cell.innerHTML = '最近发表：<a href="' + user.LatestContentUrl + '" target="_blank">' + user.LatestContentName + '</a>';
    return table;
}
function BaseGroupCard(group)
{
    var table = document.createElement('table');
    var row = table.insertRow(0);
    var cell = row.insertCell(0);
    cell.rowSpan = 4;
    cell.width = 110;
    //cell.align = 'center';
    cell.innerHTML = '<div class="divImgCard"><img class="imgCard" src="http://www.clozone.com/' + (group.PortraitUploaded? ('UserFile/' + group.Prefix + '/' + group.Prefix + 'Big.jpg'):('images/DefaultGroupBig.gif')) + '"></div>';
    cell = row.insertCell(1);
    cell.innerHTML = '群组名称：<a href="http://' + group.Prefix + '.clozone.com" target="_blank">' + group.Name +'</a>';
    row = table.insertRow(1);
    cell = row.insertCell(0);
    cell.innerHTML = '群组描述：' + group.Description;
    row = table.insertRow(2);
    cell = row.insertCell(0);
    cell.innerHTML = '成员数　：' + group.CountMembers;
    row = table.insertRow(3);
    cell = row.insertCell(0);
    cell.innerHTML = '微内容数：' + group.CountContent;
    row = table.insertRow(4);
    cell = row.insertCell(0);
    cell.colSpan = 2;
    cell.innerHTML = '最新发布：<a href="' + group.LatestContentUrl + '" target="_blank">' + group.LatestContentName + '</a>';
    return table;    
}
function UpdatePortalVisit()
{
    var prefix = GetPrefix();
    Clozone.Web.WebService.User.UpdatePortalVisit(prefix); 
}
/**********Friend Related Begin**********/
function AddFriend(e)
{
    if(typeof e == 'number')
    {   
        Clozone.Web.WebService.Friend.AddFriend(e,AddFriendSuccess);
        ShowProcess('正在添加好友，请稍候...');
    }
    else
    {
        HideCard();
        var userID = document.all? event.srcElement.userID: e.target.userID;
        Clozone.Web.WebService.Friend.AddFriend(userID,AddFriendSuccess);
        ShowProcess('正在添加好友，请稍候...');
        CancelEvent(e);
    }
}
function AddFriendSuccess(result)
{
    HideProcess();
    if(result == -1)
    {
        ShowResultBox('有错误发生，请重试',false);
    }
    if(result == 0)
    {
        ShowResultBox('已成功将该用户添加为您的好友',true);
    }
    if(result == 1)
    {
        ShowResultBox('该用户需要进行身份验证才能加为好友，请等待其批准',false);
    }
    if(result == 2)
    {
        ShowResultBox('该用户不允许其他人加其为好友',false);
    }
    if(result == 3)
    {
        ShowResultBox('您已申请将他（她）加为好友或已是您的好友',false);
    }
    if(result == 5)
    {
        ShowResultBox('不能加自己为好友',false);
    }
}
function RemoveFriend(e)
{
    if(typeof e == 'number')
    {
        if(confirm('确定删除该好友？'))
        {       
            Clozone.Web.WebService.Friend.RemoveFriend(e,RemoveFriendSuccess);
            ShowProcess('正在删除好友，请稍候...');
        }
    }
    else
    {
        HideCard();
        CancelEvent(e);
        var userID = document.all? event.srcElement.userID: e.target.userID;
        var username = document.all? event.srcElement.username: e.target.username;
        if(confirm('确定删除该好友' + username + '？'))
        {       
            Clozone.Web.WebService.Friend.RemoveFriend(userID,RemoveFriendSuccess);
            ShowProcess('正在删除好友，请稍候...');
        }
    }
}
function RemoveFriendSuccess(result)
{
    HideProcess();
    if(result == false)
    {
        ShowResultBox('有错误发生，请重试',false);
    }
    else
    {
        ShowResultBox('已成功删除好友',true);
        if(window.GetFriends)
        {
            GetFriends();
        }
    }
}
/**********Friend Related End**********/
/**********Group Related Begin**********/
function JoinGroup(e)
{
    if(typeof e == 'number')
    {   
        Clozone.Web.WebService.Group.Join(e,JoinGroupSuccess);
        ShowProcess('正在申请加入群组，请稍候...');
    }
    else
    {
        HideCard();
        var portalID = document.all? event.srcElement.portalID: e.target.portalID;
        Clozone.Web.WebService.Group.Join(portalID,JoinGroupSuccess);
        ShowProcess('正在申请加入群组，请稍候...');
        CancelEvent(e);
    }
}
function JoinGroupSuccess(result)
{
    HideProcess();
    if(result == 0)
    {
        ShowResultBox('成功加入该群',true);
    }
    if(result == 1)
    {
        ShowResultBox('申请成功，请等待管理员批准',false);
    }
    if(result == 2)
    {
        ShowResultBox('该群不允许新成员加入',false);
    }
    if(result == 3)
    {
        ShowResultBox('您已申请加入该群，请勿重复申请',false);
    }
    if(result == 4)
    {
        ShowResultBox('您已是该群成员',false);
    }
    if(result == -1)
    {
        ShowResultBox('有错误发生，请重试',false);
    }    
}
function SecedeGroup(e)
{
    if(confirm('确定退出该群？'))
    {
        if(typeof e == 'number')
        {   
            Clozone.Web.WebService.Group.Secede(e,SecedeSuccess);
            
        }
        else
        {
            var portalID = document.all? event.srcElement.portalID: e.target.portalID;
            Clozone.Web.WebService.Group.Secede(portalID,SecedeSuccess);
            CancelEvent(e);
        }
        ShowProcess('正在退出该群，请稍候...');        
    }
}
function SecedeSuccess(result)
{
    HideProcess();
    if(result == -1)
    {
        ShowResultBox('有错误发生，请重试',false);
    }
    else if(result == 1)
    {
        ShowResultBox('您是该群唯一管理员，请先指定一管理员后才能退出该群',false);
    }
    else
    {
        window.location.href = window.location.href;
    }
}
/**********Group Related End**********/
/**********WebIM Related Begin**********/
function ShowWebIM()
{
    var left = window.screen.width - 300;
    window.open('http://www.clozone.com/WebIM/WebIM.aspx','_blank','scrollbars=no,width=350,height=600,left=' + left + ',top=0,status=no,resizable=no');
}
/**********WebIM Related End**********/
function GetContentTypeName(contentType)
{        
    var name;
    switch(contentType)
    {
        case 1:
            if (isGroup)
            {
                name = '讨论版文章';
            }
            else
            {
                name = '日志';
            }
            break;
        case 2:
            name = '网摘';
            break;
        case 8:
            name = '音乐';
            break;
        case 9:
            name = '图片';
            break;
        case 10:
            name = '门户';
    }
    return name;
}
/********* Comment Start ****************/
var count_Smiley = 32;
function ToggleSmiley(control, targetName)
{
    var basePath = 'http://www.clozone.com/images/smiley/';    
    var html = '';
    for (var i = 0; i < count_Smiley; i++)
    {
	    var url = basePath + (i + 1) + ".gif";
	    html += '<img src="' + url + '" border=0 style="cursor:pointer;margin:5px;height:19px;width:19px;" onclick="InsertSmiley(' + (i + 1) + ', \'' + targetName + '\')">'; 
    }
    var left = GetOffsetLeft(control) + control.offsetWidth - 240;             
    var top = GetOffsetTop(control) + control.offsetHeight;
    TogglePopupMenu(html, left, top, 240, 400, true, true, null);
}
var colors_Font = new Array('brown','red', 'orange', 'yellow', 'green', '#238E68', '#3299CC', 'blue', 'purple', 'gray', 'white', 'black', 'olive', 'lime', 'maroon', 'fuchsia');
var colorCount_Font = 16;
function ToggleFontColor(control, targetName)
{   
    var html = '';
    for (var i = 0; i < colorCount_Font; i++)
    {
	    html += '<input type="button" style="float:left;cursor:pointer;margin:7px;height:19px;width:19px;border:solid 1px #999999;background-color:' + colors_Font[i] + '"  onclick="InsertFontColor(' + i + ', \'' + targetName + '\');">'; 
    }
    var left = GetOffsetLeft(control) + control.offsetWidth - 133;             
    var top = GetOffsetTop(control) + control.offsetHeight;
    TogglePopupMenu(html, left, top, 133, 400, true, true, null);
}
function InsertSmiley(index, targetName)
{
    var target = $(targetName);
    var value = '[smiley' + index + ']';
    InsertIntoTextArea_Clear(value, target);
}
function InsertBold(targetName)
{
    var target = $(targetName);
    InsertIntoTextArea('[B]', '[/B]', target);
}
function InsertItalicize(targetName)
{
    var target = $(targetName);
    InsertIntoTextArea('[I]', '[/I]', target);
}
function InsertUnderline(targetName)
{
    var target = $(targetName);
    InsertIntoTextArea('[U]', '[/U]', target);
}
function InsertSize(select, targetName)
{
    var target = $(targetName);
    InsertIntoTextArea('[SIZE=' + select.value + ']', '[/SIZE]', target);
}
function InsertFont(select, targetName)
{
    var target = $(targetName);
    InsertIntoTextArea('[FONT=' + select.value + ']', '[/FONT]', target);
}
function InsertFontColor(index, targetName)
{
    var target = $(targetName);
    var value = '[smiley' + index + ']';
    InsertIntoTextArea('[COLOR=' + colors_Font[index] + ']', '[/COLOR]', target);
}
function InsertIntoTextArea(headTag, tailTag, target)
{
    if (target == null || target.tagName != 'TEXTAREA')
    {
        return;
    }
    if (document.selection) 
    {
        target.focus();
        document.selection.createRange().text = headTag + document.selection.createRange().text + tailTag;
    }
    else 
    {
        if (target.selectionStart || target.selectionStart == '0') 
        {
            var startPos = target.selectionStart;
            var endPos = target.selectionEnd;
            target.value = target.value.substring(0, startPos) + headTag + target.value.substring(startPos, endPos) + tailTag + target.value.substring(endPos, target.value.length);
        } 
        else 
        {
            target.value += value;
        } 
    }
}
function InsertIntoTextArea_Clear(value, target)
{
    if (target == null || target.tagName != 'TEXTAREA')
    {
        return;
    }
    if (document.selection) 
    {
        target.focus();
        document.selection.createRange().text = value;
    }
    else 
    {
        if (target.selectionStart || target.selectionStart == '0') 
        {
            var startPos = target.selectionStart;
            var endPos = target.selectionEnd;
            target.value = target.value.substring(0, startPos) + value + target.value.substring(endPos, target.value.length);
        } 
        else 
        {
            target.value += value;
        } 
    }
}
/********* Comment End ******************/