﻿function modalWindow(url, name, width, height)
  {
    if (!width)
        width = "300";
    if (!height)
        height = "300";
        opt = 'height=' + height + ',width=' + width + ',toolbars=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes';
    window.open(url, '',opt);
}
var windowHelp="";
var windowImage="";

function openImagePicker(htmlFormElementId, imageDir, buttonId)
{
    if (buttonId == undefined)
    {
         var iUrl = "../ImagePicker2.aspx?ReturnMethod=FormElement&Element=" + htmlFormElementId + "&TargetFolder=" + imageDir; 
    }
    else
    {   
         var iUrl = "../ImagePicker2.aspx?ReturnMethod=FormElement&Element=" + htmlFormElementId + "&TargetFolder=" + imageDir + "&Button=" +buttonId; 
    }
    if(windowImage.closed == false){
    windowImage.focus();    
    }else{
    windowImage = window.open(iUrl ,"ImagePicker","toolbar=no,status=no,scrollbars=no,resizable=yes,width=650,height=500");
    } 
}

function openMultiImagePicker(htmlFormElementId, imageDir, buttonId)
{
    if (buttonId == undefined)
    {
         var iUrl = "../ImagePicker2.aspx?Multi=true&ReturnMethod=FormElement&Element=" + htmlFormElementId + "&TargetFolder=" + imageDir; 
    }
    else
    {   
         var iUrl = "../ImagePicker2.aspx?Multi=true&ReturnMethod=FormElement&Element=" + htmlFormElementId + "&TargetFolder=" + imageDir + "&Button=" +buttonId; 
    }
    if(windowImage.closed == false){
    windowImage.focus();    
    }else{
    windowImage = window.open(iUrl ,"ImagePicker","toolbar=no,status=no,scrollbars=no,resizable=yes,width=650,height=500");
    } 
}

function helpwindow(helpId)
{
    var sUrl = "../Help/help.aspx?SectionId=" + helpId;    
    if(windowHelp.closed == false){
    windowHelp.focus();
    }else{
    windowHelp = window.open(sUrl ,"helpWindow","toolbar=no,status=no,scrollbars=no,resizable=yes,width=800,height=500");
    } 
    
}
function helpwindow2(helpId)
{
    if (!helpId)
        helpId = 1; 
    var sUrl = "Help/help.aspx?SectionId=" + helpId;    
    if(windowHelp.closed == false){
    windowHelp.focus();
    }else{
    windowHelp = window.open(sUrl ,"helpWindow","toolbar=no,status=no,scrollbars=no,resizable=yes,width=800,height=600");
    }
    
}
function helpwindowadmin(helpId)
{
    var sUrl = "../Help/help.aspx?SectionId=" + helpId +"&admin=yes";    
    if(windowHelp.closed == false){
    windowHelp.focus();
    }else{
    windowHelp = window.open(sUrl ,"helpWindow","toolbar=no,status=no,scrollbars=no,resizable=yes,width=800,height=600");
    }
    
}
function helpwindowDirect(SectionId,helpId)
{
    var sUrl = "../Help/help.aspx?Sectionid=" + SectionId + "&HelpId=" + helpId;    
    if(windowHelp.closed == false){
    windowHelp.focus();
    }else{
    windowHelp = window.open(sUrl ,"helpWindow","toolbar=no,status=no,scrollbars=no,resizable=yes,width=800,height=600");
    }
    
}

function confirmClose()
{
    if (window.confirm("Are you sure you wish to Cancel?"))
        window.close();
}

function NavigateToAdminSection(x,y)
{
   //Using indexes for the frames because the frame name does not work in Firefox.
    //Menu
   window.top.frames[1].location = x + "/Menu.aspx?SectionId=" + y;
    //body
   window.top.frames[2].location = x + "/Default.aspx?SectionId=" + y;
   
   parent.window.collapseSide(0);
   
}

function NavigateHome()
{
   //Using indexes for the frames because the frame name does not work in Firefox.
    //Menu
   window.top.location = "max.aspx";
    //body
    
}

function UpdateAllChildren(nodes, checked)
{
    var i;
    for (i=0; i<nodes.length; i++)
    {
        if (checked)         
            nodes[i].Check();         
        else        
            nodes[i].UnCheck(); 
        
        if (nodes[i].Nodes.length > 0)        
            UpdateAllChildren(nodes[i].Nodes, checked);        
    }
}

function AfterCheck(node)
{
    if (!node.Checked && node.Parent != null)
        node.Parent.UnCheck();    
        
    var siblingCollection = (node.Parent != null) ? node.Parent.Nodes : node.TreeView.Nodes;
    
    var allChecked = true;
    for (var i=0; i<siblingCollection.length; i++)
    {
        if (!siblingCollection[i].Checked)
        {
            allChecked = false;
            break;
        }
    }
    if (allChecked && node.Parent != null)
    {
        node.Parent.Check();
    }
    
    UpdateAllChildren(node.Nodes, node.Checked);
}

function showMessage(swfFileName)
{
    var tDiv = document.getElementById("alertDiv");
    if (tDiv != null)
        tDiv.innerHTML = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"300\" height=\"80\" id=\"alert\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"movie\" value=\"images/saved_general.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><param name=\"bgcolor\" value=\"#ffffff\" /><embed src=\"images/saved_general.swf\" quality=\"high\" wmode=\"transparent\" bgcolor=\"#ffffff\" width=\"300\" height=\"80\" name=\"alert\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object>";
}

function hideAlert()
{
    tDiv = document.getElementById("alertDiv");
    if (tDiv != null)
        tDiv.innerHTML = "";
}

function clickButton(e, buttonid,ignore){
var bt = document.getElementById(buttonid)
    if (typeof bt == 'object'){
        if(navigator.appName.indexOf("Netscape")>(-1)){
            if (e.keyCode == 13){ 
                if(ignore){
                    return false
                }else{
                     bt.click()
                     return false
                }
            }
        } 
        if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
            if (event.keyCode == 13){
                if(ignore){
                    return false
                }else{
                    bt.click()
                    return false
                }
            } 
        } 
     } 
 } 

function NavigateToSettingsArea(areaName, querystr)
{
    var sUrl = areaName + ".aspx";
    if (querystr != null)
        sUrl += "?" + querystr;
    
   //navigate frame
   window.top.frames[2].location = sUrl;
}
function StretchMenu()
{
    var mDiv = document.getElementById("menuDiv");
    if (mDiv != null)       
       s=getWindowHeight(); 
       var L=layer("menuDiv")
       s = s - 80;
       //alert(s);
       mDiv.style.height = s+"px"; 
    
}
function StretchLogin(theme)
{   
    var mbody = document.getElementById("bg");
    var mtable = document.getElementById("logTable");
    x=getWindowHeight();
    y=getWindowWidth();
    if (theme == "Xplore"){
        mtable.style.width = "600px";
        mtable.style.height = "434px"; 
    }else{
        mtable.style.width = "439px"; 
        mtable.style.height = "292px";   
    }
    var L=layer("bg")
    if (y > 1100)
    {    
    
    L.setBgImage("../app_themes/"+theme+"/images/login_bg_xl.jpg"); 
    }else{
    L.setBgImage("../app_themes/"+theme+"/images/login_bg.jpg");
    }
    
    //x = x - 200;
    mbody.style.height = x+'px';
    mbody.style.width = y+'px';        
    document.getElementById('EmailAddress').focus();

}

/************************************************\
| KLayers 2.97                                   |
| DHTML Library for Internet Explorer 4.* - 6.*, |
| Netscape 4.* - 7.*, Mozilla, Opera 5.* - 7.*   |
| Copyright by Kruglov S. A. (kruglov.ru) 2003   |
\************************************************/

/***  See for description and latest version  ***\
\***  http://www.kruglov.ru/klayers/          ***/

function initKLayers(){
  isDOM=document.getElementById?true:false
  isOpera=isOpera5=window.opera && isDOM
  isOpera6=isOpera && window.print
  isOpera7=isOpera && document.readyState
  isMSIE=isIE=document.all && document.all.item && !isOpera
  isStrict=document.compatMode=='CSS1Compat'
  isNN=isNC=navigator.appName=="Netscape"
  isNN4=isNC4=isNN && !isDOM
  isMozilla=isNN6=isNN && isDOM

  if(!isDOM && !isNC && !isMSIE && !isOpera){
    KLayers=false
    return false
  }

  pageLeft=0
  pageTop=0

  KL_imgCount=0
  KL_imgArray=new Array()

  KL_imageRef="document.images[\""
  KL_imagePostfix="\"]"
  KL_styleSwitch=".style"
  KL_layerPostfix="\"]"

  if(isNN4){
    KL_layerRef="document.layers[\""
    KL_styleSwitch=""
  }

  if(isMSIE){
    KL_layerRef="document.all[\""
  }

  if(isDOM){
    KL_layerRef="document.getElementById(\""
    KL_layerPostfix="\")"
  }

  KLayers=true
  return true
}

initKLayers()

// document and window functions:

function KL_getBody(w){
  if(!w) w=window
  if(isStrict){
    return w.document.documentElement
  }else{
    return w.document.body
  }
}

function getWindowLeft(w){
  if(!w) w=window
  if(isMSIE || isOpera7) return w.screenLeft
  if(isNN || isOpera) return w.screenX
}

function getWindowTop(w){
  if(!w) w=window
  if(isMSIE || isOpera7) return w.screenTop
  if(isNN || isOpera) return w.screenY
}

function getWindowWidth(w){
  if(!w) w=window
  if(isMSIE) return KL_getBody(w).clientWidth
  if(isNN || isOpera) return w.innerWidth
}

function getWindowHeight(w){
  if(!w) w=window
  if(isMSIE) return KL_getBody(w).clientHeight
  if(isNN || isOpera) return w.innerHeight
}

function getDocumentWidth(w){
  if(!w) w=window
  if(isMSIE || isOpera7) return KL_getBody(w).scrollWidth
  if(isNN) return w.document.width
  if(isOpera) return w.document.body.style.pixelWidth
}

function getDocumentHeight(w){
  if(!w) w=window
  if(isMSIE || isOpera7) return KL_getBody(w).scrollHeight
  if(isNN) return w.document.height
  if(isOpera) return w.document.body.style.pixelHeight
}

function getScrollX(w){
  if(!w) w=window
  if(isMSIE || isOpera7) return KL_getBody(w).scrollLeft
  if(isNN || isOpera) return w.pageXOffset
}

function getScrollY(w){
  if(!w) w=window
  if(isMSIE || isOpera7) return KL_getBody(w).scrollTop
  if(isNN || isOpera) return w.pageYOffset
}

var KL_LAYER=0
var KL_IMAGE=1

function KL_findObject(what,where,type){
  var i,j,l,s
  var len=eval(where+".length")
  for(j=0;j<len;j++){
    s=where+"["+j+"].document.layers"
    if(type==KL_LAYER){
      l=s+"[\""+what+"\"]"
    }
    if(type==KL_IMAGE){
      i=where+"["+j+"].document.images"
      l=i+"[\""+what+"\"]"
    }
    if(eval(l)) return l
    l=KL_findObject(what,s,type)
    if(l!="null") return l
  }
  return "null"
}

function KL_getObjectPath(name,parent,type){
  var l=((parent && isNN4)?(parent+"."):(""))+((type==KL_LAYER)?KL_layerRef:KL_imageRef)+name+((type==KL_LAYER)?KL_layerPostfix:KL_imagePostfix)
  if(eval(l))return l
  if(!isNN4){
    return l
  }else{
    return KL_findObject(name,"document.layers",type)
  }
}

function layer(name){
  return new KLayer(name,null)
}

function layerFrom(name,parent){
  if(parent.indexOf("document.")<0) parent=layer(parent).path
  return new KLayer(name,parent)
}

function image(name){
  return new KImage(name,null)
}

function imageFrom(name,parent){
  if(parent.indexOf("document.")<0) parent=layer(parent).path
  return new KImage(name,parent)
}

// class "KLayer":

function KLayer(name,parent){
  this.path=KL_getObjectPath(name,parent,KL_LAYER)
  this.object=eval(this.path)
  if(!this.object)return
  this.style=this.css=eval(this.path+KL_styleSwitch)
}

KLP=KLayer.prototype

KLP.isExist=KLP.exists=function(){
  return (this.object)?true:false
}

function KL_getPageOffset(o){ 
  var KL_left=0
  var KL_top=0
  do{
    KL_left+=o.offsetLeft
    KL_top+=o.offsetTop
  }while(o=o.offsetParent)
  return [KL_left, KL_top]
}

KLP.getLeft=function(){
  var o=this.object
  if(isMSIE || isMozilla || isOpera) return o.offsetLeft-pageLeft
  if(isNN4) return o.x-pageLeft
}

KLP.getTop=function(){
  var o=this.object
  if(isMSIE || isMozilla || isOpera) return o.offsetTop-pageTop
  if(isNN4) return o.y-pageTop
}

KLP.getAbsoluteLeft=function(){
  var o=this.object
  if(isMSIE || isMozilla || isOpera) return KL_getPageOffset(o)[0]-pageLeft
  if(isNN4) return o.pageX-pageLeft
}

KLP.getAbsoluteTop=function(){
  var o=this.object
  if(isMSIE || isMozilla || isOpera) return KL_getPageOffset(o)[1]-pageTop
  if(isNN4) return o.pageY-pageTop
}

KLP.getWidth=function(){
  var o=this.object
  if(isMSIE || isMozilla || isOpera7) return o.offsetWidth
  if(isOpera) return this.css.pixelWidth
  if(isNN4) return o.document.width
}

KLP.getHeight=function(){
  var o=this.object
  if(isMSIE || isMozilla || isOpera7) return o.offsetHeight
  if(isOpera) return this.css.pixelHeight
  if(isNN4) return o.document.height
}

KLP.getZIndex=function(){ //deprecated
  return this.css.zIndex
}

KLP.setLeft=KLP.moveX=function(x){
  x+=pageLeft
  if(isOpera){
    this.css.pixelLeft=x
  }else if(isNN4){
    this.object.x=x
  }else{
    this.css.left=x+"px"
  }
}

KLP.setTop=KLP.moveY=function(y){
  y+=pageTop
  if(isOpera){
    this.css.pixelTop=y
  }else if(isNN4){
    this.object.y=y
  }else{
    this.css.top=y+"px"
  }
}

KLP.moveTo=KLP.move=function(x,y){
  this.setLeft(x)
  this.setTop(y)
}

KLP.moveBy=function(x,y){
  this.moveTo(this.getLeft()+x,this.getTop()+y)
}

KLP.setBgImage=function(url){
  if(isMSIE || isMozilla || isOpera6){
    this.css.backgroundImage="url("+url+")"
  }else if(isNN4){
    this.css.background.src=url
  }
}