//----------------------------------------------------------------
//for compat
if (navigator.userAgent.indexOf('MSIE') == -1) 
{
    //alert("no ie");
    var attachEventProxy = function(eventName, eventHandler) {
        eventHandler._mozillaEventHandler = function(e) {
            window.event = e;
            eventHandler();
            return e.returnValue;
        };
        this.addEventListener(eventName.slice(2), eventHandler._mozillaEventHandler, false);
    }

    var detachEventProxy = function (eventName, eventHandler) {
        if (eventHandler._mozillaEventHandler) {
            var mozillaEventHandler = eventHandler._mozillaEventHandler;
            delete eventHandler._mozillaEventHandler;
            
            this.removeEventListener(eventName.slice(2), mozillaEventHandler, false);
        }
    }
    
    window.attachEvent = attachEventProxy;
    window.detachEvent = detachEventProxy;
    window.HTMLDocument.prototype.attachEvent = attachEventProxy;
    window.HTMLDocument.prototype.detachEvent = detachEventProxy;
    window.HTMLElement.prototype.attachEvent = attachEventProxy;
    window.HTMLElement.prototype.detachEvent = detachEventProxy;
    window.HTMLElement.prototype.click = function()
    {
        var evt=document.createEvent('MouseEvent');
        evt.initEvent('click',true,true);
        this.dispatchEvent(evt);
    }
    window.HTMLElement.prototype.fireEvent = function(eventName)
    {
        var evt;
        switch(eventName)
        {
            case "onclick":
                evt=document.createEvent('MouseEvent');
                break;
            case "onchange":

                evt=document.createEvent('HTMLEvents');
                break;
            default:
                evt=document.createEvent('Event');   
        }
        evt.initEvent(eventName.slice(2),true,true);

        this.dispatchEvent(evt);
    }
    
    window.HTMLElement.prototype.__defineGetter__('innerText', function() {
            return this.textContent;
        });
    window.HTMLElement.prototype.__defineSetter__('innerText', function(v) {
            if (v) {
                this.innerHTML = formatPlainTextAsHtml(v);
            }
            else {
                this.innerHTML = '';
            }
        });

        function formatPlainTextAsHtml(str) {
        var sb="";

        var numChars = str.length;
        var prevCh;
        
        for (var i=0; i < numChars; i++) {
            var ch = str.charAt(i);
            //alert(ch);
            switch (ch) {
                case "<":
                    sb+="&lt;";
                    break;
                case ">":
                    sb+="&gt;";
                    break;
                case "\"":
                    sb+="&quot;";
                    break;
                case "&":
                    sb+="&amp;";
                    break;
                case " ":
                    if (prevCh == " ") {
                        sb+="&nbsp;"
                    }
                    else {
                        sb+=" ";
                    }
                    break;
                case "\r":
                    break;
                case "\n":
                    sb+="\r\n<br />";
                    break;
                default:
                    sb+=ch;
                    break;
            }

            prevCh = ch;
        }
        //alert(sb);
        return sb.toString();
    }
    window.Event.prototype.__defineGetter__('srcElement', function () {
            var n = __getNonTextNode(this.explicitOriginalTarget);
            return n;
        });
    function __getNonTextNode(node) 
    {
        try {
            while (node && node.nodeType != 1) 
            {
                node = node.parentNode;
            }
        }
        catch (ex) {
            node = null;
        }
        return node;
    }
    window.Event.prototype.__defineSetter__('cancelBubble', function (v) {
            if (v) {
                this.stopPropagation();
            }
        });
    
    function GetLocation(el) {
        var c = { x : 0, y : 0 };
        while (el) {
            c.x += el.offsetLeft;
            c.y += el.offsetTop;
            el = el.offsetParent;
        }
        return c;
    }
    window.Event.prototype.__defineGetter__('offsetX', function () {
            return window.pageXOffset + this.clientX - GetLocation(this.srcElement).x;
        });
    window.Event.prototype.__defineGetter__('offsetY', function () {
            return window.pageYOffset + this.clientY - GetLocation(this.srcElement).y;
        });
    window.Event.prototype.__defineSetter__('returnValue', function (v) {
            if (!v) {
                this.preventDefault();
            }
            this.cancelDefault = v;
            return v;
        });
    window.Event.prototype.__defineGetter__('returnValue', function() {
            return this.cancelDefault;
        });
    function selectNodes(doc, path, contextNode) {
        contextNode = contextNode ? contextNode : doc;
        var xpath = new XPathEvaluator();
        var result = xpath.evaluate(path, contextNode,
                                    doc.createNSResolver(doc.documentElement),
                                    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

        var nodeList = new Array(result.snapshotLength);
        for(var i = 0; i < result.snapshotLength; i++) {
            nodeList[i] = result.snapshotItem(i);
        }

        return nodeList;
    }

//    function selectSingleNode(doc, path, contextNode) {
//        path += '[1]';
//        var nodes = selectNodes(doc, path, contextNode);
//        if (nodes.length != 0) {
//            for (var i = 0; i < nodes.length; i++) {
//                if (nodes[i]) {
//                    return nodes[i];
//                }
//            }
//        }
//        return null;
//    }

    window.XMLDocument.prototype.selectNodes = function(path, contextNode) {
        contextNode = contextNode ? contextNode : this;
        var xpath = new XPathEvaluator();
        var result = xpath.evaluate(path, contextNode,
                                    this.createNSResolver(this.documentElement),
                                    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

        var nodeList = new Array(result.snapshotLength);
        for(var i = 0; i < result.snapshotLength; i++) {
            nodeList[i] = result.snapshotItem(i);
        }

        return nodeList;
    }
    
    window.XMLDocument.prototype.selectSingleNode = function(path, contextNode) {
        contextNode = contextNode ? contextNode : this;
        var xpath = new XPathEvaluator();
        var result = xpath.evaluate(path, contextNode,
                                    this.createNSResolver(this.documentElement),
                                    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
        
        return result.snapshotItem(0);
    }

    window.XMLDocument.prototype.transformNode = function(xsl) {
        var xslProcessor = new XSLTProcessor();
        xslProcessor.importStylesheet(xsl);

        var ownerDocument = document.implementation.createDocument("", "", null);
        var transformedDoc = xslProcessor.transformToDocument(this);
        
        return transformedDoc.xml;
    }
    
    window.XMLDOMParser = window.DOMParser;
    
    Node.prototype.selectNodes = function(path) {
        var doc = this.ownerDocument;
        return doc.selectNodes(path, this);
    }
    
    Node.prototype.selectSingleNode = function(path) {
        var doc = this.ownerDocument;
        return doc.selectSingleNode(path, this);
    }

    Node.prototype.__defineGetter__('baseName', function() {
        return this.localName;
    });
    
    Node.prototype.__defineGetter__('text', function() {
        return this.textContent;
    });
    Node.prototype.__defineSetter__('text', function(value) {
        this.textContent = value;
    });
    
    Node.prototype.__defineGetter__('xml', function() {
        return (new XMLSerializer()).serializeToString(this);
    });
}
//------------------------------------------------------------------

Function.createDelegate = function(instance, method) 
{
    return function() {return method.apply(instance, arguments);}
}

if (!window.XMLHttpRequest) 
{
    //alert(true);
    window.XMLHttpRequest = function() 
    {
        var progIDs = [ 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP.2.6', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'MSXML.XMLHTTP' ];
        for (var i = 0; i < progIDs.length; i++) 
        {
            try 
            {
                return new ActiveXObject(progIDs[i]);
            }
            catch (ex) { }
        }
	    
        return null;
    }
}
function $(id)
{
    if(id)
    {
        return document.getElementById(id);
    }
    else
    {
        return null;
    }
}
window.XMLDOM = function(markup) {
    if (!window.XMLDOMParser) {
        var progIDs = [ 'Msxml2.DOMDocument.3.0', 'Msxml2.DOMDocument' ];
        
        for (var i = 0; i < progIDs.length; i++) {
            try {
                var xmlDOM = new ActiveXObject(progIDs[i]);
                xmlDOM.async = false;
                xmlDOM.loadXML(markup);
                xmlDOM.setProperty('SelectionLanguage', 'XPath');
                
                return xmlDOM;
            }
            catch (ex) {
            }
        }
        
        return null;
    }
    else {
        var domParser = new window.XMLDOMParser();
        return domParser.parseFromString(markup, 'text/xml');
    }
}
Common=function()
{
    //browser version
   var ver=navigator.appVersion;
   this.ie6=(ver.indexOf("MSIE 6")>-1)?1:0;
   this.ie7=(ver.indexOf("MSIE 7")>-1)?1:0;
   this.mac=(ver.indexOf('Mac')>-1)?1:0;
   this.opera=(navigator.userAgent.indexOf('Opera')>-1);
   
   //mouse loaction
   this.mouseX=0;
   this.mouseY=0;
   this.initialize=function()
   {
        //desktop resize
        if(this.ie6)
        {
            var _reseizeContainerHandler=Function.createDelegate(this,this._resizeContainer);
            window.attachEvent("onresize",_reseizeContainerHandler);
            this._resizeContainer();
        }
        //set mouse location
        var _mouseMoveHandler=Function.createDelegate(this,this._mouseMove);
        document.body.attachEvent("onmousemove",_mouseMoveHandler);
   }
   this._resizeContainer=function()
   {
        $('container').style.height=(document.body.clientHeight-$('top').clientHeight-$('bottom').clientHeight)+"px";
   }
   this._mouseMove=function(e)
   {
        if(this.ie6||this.ie7)
        {
            this.mouseX = event.clientX + document.body.scrollLeft; 
            this.mouseY = event.clientY + document.body.scrollTop; 
        }
        else
        {
            this.mouseX = event.pageX; 
            this.mouseY = event.pageY; 
        }
        //window.status=this.mouseX+","+this.mouseY+"|"+event.x+","+event.y;
   }
   this.getLocation=function(element)
   {
        var offsetTop=0;
        var offsetLeft=0;
        var elmt=element;
        try{
            while(elmt.offsetParent) 
            { 
                offsetTop += elmt.offsetTop-elmt.offsetParent.scrollTop; 
                offsetLeft += elmt.offsetLeft-elmt.offsetParent.scrollLeft; 
                elmt = elmt.offsetParent;
                //alert(offsetLeft+","+offsetTop);
            }
        }catch (ex) {
            }
        return [offsetLeft,offsetTop];
   }
   
}
//---------------------------------------------------------------------------------------
Hashtable=function()
{
    this._hash = new Object();
    this.add = function(key,value)
    {
        if(typeof(key)!="undefined")
        {
            if(this.contains(key)==false)
            {
                this._hash[key]=typeof(value)=="undefined"?null:value;
                return true;
            } 
            else 
            {
                return false;
            }
        }
    }
    this.edit = function(key,value)
    {
        if(typeof(key)!="undefined")
        {
            if(this.contains(key)==false)
            {
                return false;
            } 
            else 
            {   
                this._hash[key]=typeof(value)=="undefined"?null:value;
                return true;
            }
        }
    }
    this.remove = function(key){this._hash[key]=null;delete this._hash[key];}
    this.count = function(){var i=0;for(var k in this._hash){i++;} return i;}
    this.item = function(key){return this._hash[key];}
    this.contains = function(key){ return typeof(this._hash[key])!="undefined";}
    this.clear = function(){for(var k in this._hash){delete this._hash[k];}}
    this.list=function(position)
    {
        var acount=1; 
        var res= new Object();
        for(var n in this._hash)
        {
            if(position<=acount)
            {
                res[n]= this._hash[n];
            }
            acount++;
        } 
        return res;
    } 
}
//---------------------------------------------------------------------------

Drag=function(hand,obj)
{
    var _hand=hand;
    var _obj=obj;
    var _starHandler;
    var _dragHandler;
    var _endHandler;
    var lastX;
    var lastY;
    
    var _enabled=true;
    
    this.initialize=function()
    {
        _startHandler=Function.createDelegate(this,this.start);
        _dragHandler=Function.createDelegate(this,this.drag);
        _endHandler=Function.createDelegate(this,this.end);
        
        _hand.attachEvent("onmousedown",_startHandler);
    }
    this.start=function(e)
    {
        e= e || window.event;
        if(typeof e.layerX=="undefined")e.layerX=e.offsetX;
	    if(typeof e.layerY=="undefined")e.layerY=e.offsetY;
        lastX= e.clientX;
        lastY= e.clientY;
        document.attachEvent("onmousemove",_dragHandler);
        document.attachEvent("onmouseup",_endHandler);
    }
    this.drag=function(e)
    {
        e= e || window.event;
        if(typeof e.layerX=="undefined")e.layerX=e.offsetX;
		if(typeof e.layerY=="undefined")e.layerY=e.offsetY;
        var x= e.clientX;
        var y= e.clientY;
        xx=parseInt(_obj.style.left)+x-lastX;
        yy=parseInt(_obj.style.top)+y-lastY;
        if(_enabled)this.onmove(xx,yy);
        lastX=x;
        lastY=y;
        
        e.returnValue=null;
    }
    this.end=function()
    {
        document.detachEvent("onmousemove",_dragHandler);
        document.detachEvent("onmouseup",_endHandler);
    }
    this.enable=function(value)
    {
        _enabled=value;
    }
    this.onmove=function(){return false;}
    this.initialize();
    this.GC=function()
    {       
        if(_hand)
        {
            _hand.detachEvent("onmousedown");
            _hand=null;
        }
        document.detachEvent("onmousedown");
        document.detachEvent("onmouseup");
        this.onmove=null;
        _startHandler=null;
        _dragHandler=null;
        _endHandler=null;
        _obj=null;
    }
}
//---------------------------------------------------------------------
Resize=function(hand,obj)
{
    var _hand=hand;
    var _obj=obj;
    var _starHandler;
    var _dragHandler;
    var _endHandler;
    var lastX;
    var lastY;
    
    var _enabled=true;
    
    this.initialize=function()
    {
        _startHandler=Function.createDelegate(this,this.start);
        _dragHandler=Function.createDelegate(this,this.drag);
        _endHandler=Function.createDelegate(this,this.end);
        
        _hand.attachEvent("onmousedown",_startHandler);
    }
    this.start=function(e)
    {
        e= e || window.event;
        if(typeof e.layerX=="undefined")e.layerX=e.offsetX;
	    if(typeof e.layerY=="undefined")e.layerY=e.offsetY;
        lastX= e.clientX;
        lastY= e.clientY;
        document.attachEvent("onmousemove",_dragHandler);
        document.attachEvent("onmouseup",_endHandler);
    }
    this.drag=function(e)
    {
        e= e || window.event;
        if(typeof e.layerX=="undefined")e.layerX=e.offsetX;
		if(typeof e.layerY=="undefined")e.layerY=e.offsetY;
        var x= e.clientX;
        var y= e.clientY;
        xx=parseInt(_obj.style.width)+x-lastX;
        yy=parseInt(_obj.style.height)+y-lastY;
        if(_enabled)this.onchangesize(xx,yy);
        lastX=x;
        lastY=y;
        
        e.returnValue=null;
    }
    this.end=function()
    {
        document.detachEvent("onmousemove",_dragHandler);
        document.detachEvent("onmouseup",_endHandler);
    }
    this.enable=function(value)
    {
        _enabled=value;
        if(value)
        {
            hand.style.visibility="visible";
            hand.style.display="block";
        }
        else
        {
            hand.style.visibility="hidden";
            hand.style.display="none";
        }
    }
    this.onchangesize=function(){return false;}
    this.initialize();
    this.GC=function()
    {       
        if(_hand)
        {
            _hand.detachEvent("onmousedown");
            _hand=null;
        }
        document.detachEvent("onmousedown");
        document.detachEvent("onmouseup");
        this.onchangesize=null;
        _startHandler=null;
        _dragHandler=null;
        _endHandler=null;
        _obj=null;
    }
}

function uriEncode(str)
{
    str=escape(str);
    str=str.replace(/\+/g,"%2b");
    return str;
}
function fillData(id)
{  
  
 var str1="document.frames[\""+id+"___Frame\"].frames.item(0).document.body";
 var str2="document.frames[\""+id+"___Frame\"].document.getElementsByTagName(\"textarea\")[0]";
 //alert(eval(str).innerHTML);
 try
 {
    $(id).value=eval(str1).innerHTML;
 }
 catch(ex)
 {
    $(id).value=eval(str2).value;
 }
   
}

FKCRegistor=function(id,interval)
{    
    this.editorId=id;   
    this.timerInterval=interval || 2000;    
    this.timmer=new Object() ;    
}

FKCRegistor.prototype.init=function(instance)
{
    this.timmer=window.setInterval('this.'+instance+'.regFKCEvent()',this.timerInterval);
}
FKCRegistor.prototype.regFKCEvent=function()
{
    if(document.getElementById(this.editorId).contentWindow.frames[0])
    {
        document.getElementById(this.editorId).contentWindow.frames[0].document.addEventListener("blur",this.FCKFF,false);
        window.clearInterval(this.timmer);
    }
} 
//FKCRegistor.prototype.test=function()
//{
//    alert(this.body.innerHTML);    
//}
FKCRegistor.prototype.FCKFF=function()
{
    var id=this.defaultView.parent.frameElement.id.replace(/___Frame/,"");
    $(id).value=this.body.innerHTML;    
}
function attachEventOnFCK(unid,fckid)
{
    if(!document.all)//IE
    {
        eval(unid+'=new FKCRegistor("'+fckid+'___Frame",2000);'+unid+'.init("'+unid+'")');
    }
   
}

 function Print2Excel()
 {
 var ff=document.getElementById("prtExcel");
ff.src="PrintToExcel.aspx";
}


//eval('aaa=new FKCRegistor("FCKeditor1___Frame",2000);aaa.init("aaa")');
//function document.onkeydown() 
//{ 
//if(event.keyCode==13) { 
//if(document.getElementById("image_login")!=null){
//document.getElementById("image_login").click(); 
//return false; }} 
//}