﻿function findPos(obj) {
    
    var curleft = 0;
    var curtop = 0;

    if (obj.offsetParent) {

        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;

        } while (obj = obj.offsetParent);

    }
    var res = [curleft, curtop];

    //document.getElementById("pos").innerHTML = res[0];
    return res;
}





function ImageExpander(oThumb, sImgSrc) {



    // store thumbnail image and overwrite its onclick handler.
    this.oThumb = oThumb;
    this.oThumb.expander = this;


    this.oThumb.onclick = function() { this.expander.expand(); }

    // record original size
    this.smallWidth = oThumb.offsetWidth;
    this.smallHeight = oThumb.offsetHeight;

    this.bExpand = true;
    this.bTicks = false;

    // self organized list
    if (!window.aImageExpanders) {
        window.aImageExpanders = new Array();
    }
    window.aImageExpanders.push(this);

    // create the full sized image.
    this.oImg = new Image();
    this.oImg.expander = this;
    this.oImg.onload = function() { this.expander.onload(); }
    this.oImg.src = sImgSrc;
}

ImageExpander.prototype.onload = function() {
    this.oDiv = document.createElement("div");
    document.body.appendChild(this.oDiv);
    this.oDiv.appendChild(this.oImg);
    this.oDiv.style.position = "absolute";
    this.oDiv.expander = this;
    this.oDiv.onclick = function() { this.expander.toggle(); };
    this.oImg.title = "Click to reduce.";
    this.bigWidth = this.oImg.width;
    this.bigHeight = this.oImg.height;

    if (this.bExpand) {
        this.expand();
    }
    else {
        this.oDiv.style.visibility = "hidden";
        this.oImg.style.visibility = "hidden";
    }
}
ImageExpander.prototype.toggle = function() {
    this.bExpand = !this.bExpand;
    if (this.bExpand) {
        for (var i in window.aImageExpanders)
            if (window.aImageExpanders[i] !== this)
            window.aImageExpanders[i].reduce();
    }
}
ImageExpander.prototype.expand = function() {
    // set direction of expansion.
    this.bExpand = true;

    // set all other images to reduce
    for (var i in window.aImageExpanders)
        if (window.aImageExpanders[i] !== this)
        window.aImageExpanders[i].reduce();

    // if not loaded, don't continue just yet
    if (!this.oDiv) return;

    // hide the thumbnail
    this.oThumb.style.visibility = "hidden";

    // calculate initial dimensions

    /*
    this.x = this.oThumb.offsetLeft; 
    this.y = this.oThumb.offsetTop; 
    */
    this.x = findPos(this.oThumb)[0];
    this.y = findPos(this.oThumb)[1];
    

    this.w = this.oThumb.clientWidth;
    this.h = this.oThumb.clientHeight;

    this.oDiv.style.left = this.x + "px";
    this.oDiv.style.top = this.y + "px";
    this.oImg.style.width = this.w + "px";
    this.oImg.style.height = this.h + "px";
    this.oDiv.style.visibility = "visible";
    this.oImg.style.visibility = "visible";

    // start the animation engine.
    if (!this.bTicks) {
        this.bTicks = true;
        var pThis = this;
        window.setTimeout(function() { pThis.tick(); }, 5);
    }
}
ImageExpander.prototype.reduce = function() {
    // set direction of expansion.
    this.bExpand = false;
}
ImageExpander.prototype.tick = function() {
    // calculate screen dimensions
    var cw = document.body.clientWidth;
    var ch = document.body.clientHeight;
    var cx = document.body.scrollLeft + cw / 2;
    var cy = document.body.scrollTop + ch / 2;

    // calculate target
    var tw, th, tx, ty;
    if (this.bExpand) {
        tw = this.bigWidth;
        th = this.bigHeight;
        if (tw > cw) {
            th *= cw / tw;
            tw = cw;
        }
        if (th > ch) {
            tw *= ch / th;
            th = ch;
        }
        tx = cx - tw / 2;
        ty = cy - th / 2;
    }
    else {
        tw = this.smallWidth;
        th = this.smallHeight;
        tx = findPos(this.oThumb)[0];
        ty = findPos(this.oThumb)[1];
    
    }
    // move 5% closer to target
    var nHit = 0;
    var fMove = function(n, tn) {
        var dn = tn - n;
        if (Math.abs(dn) < 3) {
            nHit++;
            return tn;
        }
        else {
            return n + dn / 10;
        }
    }
    this.x = fMove(this.x, tx);
    this.y = fMove(this.y, ty);
    this.w = fMove(this.w, tw);
    this.h = fMove(this.h, th);

    this.oDiv.style.left = this.x + "px";
    this.oDiv.style.top = this.y + "px";
    this.oImg.style.width = this.w + "px";
    this.oImg.style.height = this.h + "px";

    // if reducing and size/position is a match, stop the tick	
    if (!this.bExpand && (nHit == 4)) {
        this.oImg.style.visibility = "hidden";
        this.oDiv.style.visibility = "hidden";
        this.oThumb.style.visibility = "visible";

        this.bTicks = false;
    }

    if (this.bTicks) {
        var pThis = this;
        window.setTimeout(function() { pThis.tick(); }, 5);
    }
}

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// AJAX main object
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function getXHTTP() {
  var xhttp;
   try {   // The following "try" blocks get the XMLHTTP object for various browsers…
      xhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
 		 // This block handles Mozilla/Firefox browsers...
	    try {
          xhttp = new XMLHttpRequest();
	    } catch (e3) {
	    
	      xhttp = false;
	    }
      }
    }
      
      
  return xhttp; // Return the XMLHTTP object
}	

function ajaxLoader(objId, mode)
{
    var obj = document.getElementById(objId);
    if (obj!=undefined)
    {
        switch (mode) {
            case 0:
                obj.innerHTML = "<p style='text-align: center; font-family: tahoma; font-size: 10px; font-weight: bold; color: #666666;'><img src='images/ajax-loader.gif' /></p>";
                break;
            case 1:
                obj.innerHTML = "<p style='text-align: center; font-family: tahoma; font-size: 10px; font-weight: bold; color: #666666;'><img src='images/ajax-loader.gif' /></p>";
                break;
            case 2:
                obj.innerHTML = "<p style='text-align: center; font-family: tahoma; font-size: 10px; font-weight: bold; color: #666666;'><img src='images/ajax-loader.gif' /></p>";
                break;
            case 3:
                obj.innerHTML = "<p style='text-align: center; font-family: tahoma; font-size: 10px; font-weight: bold; color: #666666;'><img src='images/ajax-loader.gif' /></p>";
                break;
            default:
                obj.innerHTML = "";
                break;
        }
  
    }
}

/*
function ajaxLoaderImg(objId, mode)
{
    var obj = document.getElementById(objId);
    if (obj!=undefined)
    {
        switch (mode) {
            case 0:
                obj.innerHTML = "<p style='text-align: center; font-family: tahoma; font-size: 10px; font-weight: bold; color: #666666;'><img src='images/ajax-loader.gif' /><br /><small>Initializing</small></p>";
                break;
            case 1:
                obj.innerHTML = "<p style='text-align: center; font-family: tahoma; font-size: 10px; font-weight: bold; color: #666666;'><img src='images/ajax-loader.gif' /><br /><small>Loading</small></p>";
                break;
            case 2:
                obj.innerHTML = "<p style='text-align: center; font-family: tahoma; font-size: 10px; font-weight: bold; color: #666666;'><img src='images/ajax-loader.gif' /><br /><small>Processing</small></p>";
                break;
            case 3:
                obj.innerHTML = "<p style='text-align: center; font-family: tahoma; font-size: 10px; font-weight: bold; color: #666666;'><img src='images/ajax-loader.gif' /><br /><small>Completing</small></p>";
                break;
            default:
                obj.innerHTML = "";
                break;
        }
  
    }
}
*/
function ajaxLoaderTxt(objId, mode)
{
    var obj = document.getElementById(objId);
    if (obj!=undefined)
    {
        switch (mode) {
            case 0:
                obj.innerHTML = "<div style='color: #666666;'>initializing</div>";
                break;
            case 1:
                obj.innerHTML = "<div style='color: #666666;'>loading</div>";
                break;
            case 2:
                obj.innerHTML = "<div style='color: #666666;'>processing</div>";
                break;
            case 3:
                obj.innerHTML = "<div style='color: #666666;'>completing</div>";
                break;
            default:
                obj.innerHTML = "";
                break;
        }
        
  
    }
}


// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isChrome = false;
  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Chrome";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isChrome = true;
    this.isNS = true
    //this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    //this.version = 6.1;
    return;
  }
}
var browser = new Browser();    

    


function print(objName, theme)
{
    var content = document.getElementById(objName).innerHTML;
    var wnd = window.open("", "printContent", "width=800, height=500, status=no, scrollbars=yes, location=no, toolbar=n, resizeable=yes");
    wnd.document.write("<html><head><title>Print</title><link href='stylesheet1.css' rel='stylesheet' type='text/css' /><link href='App_Themes/" + theme + "/stylesheet1.css' rel='stylesheet' type='text/css' /><style> body { padding: 10px; } body { overflow-y: auto; overflow-x: auto; }</style></head><body>" + content + "</body></html>");
    wnd.document.close();
    wnd.print();
    
    
}   


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// AJAX main object
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function getXHTTP() {
  var xhttp;
   try {   // The following "try" blocks get the XMLHTTP object for various browsers…
      xhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
 		 // This block handles Mozilla/Firefox browsers...
	    try {
          xhttp = new XMLHttpRequest();
	    } catch (e3) {
	    
	      xhttp = false;
	    }
      }
    }
  return xhttp; // Return the XMLHTTP object
}	




function Hide(objname)
{
    try {
	    var obj = document.getElementById(objname);
	    obj.style.visibility = "hidden";
	    obj.style.position = "absolute";
	}
	catch (e) {
	}
}

function Show(objname, displayTime)
{
    try {
	    var obj = document.getElementById(objname);
	    obj.style.visibility = "visible";
	    obj.style.position = "relative";
        if (displayTime!=undefined)
            setTimeout("Hide('" + objname + "')", displayTime);
	}
	catch (e) {
	}
}

function getKeyChar(e)
{
    var keynum;
    var keychar;
    var numcheck;
    if(window.event) // IE
      {
      keynum = e.keyCode;
      }
    else if(e.which) // Netscape/Firefox/Opera
      {
      keynum = e.which;
      }
    keychar = String.fromCharCode(keynum);
    
    return keychar

}

function getKeyNum(e)
{
    var keynum;
    var keychar;
    var numcheck;
    if(window.event) // IE
      {
      keynum = e.keyCode;
      }
    else if(e.which) // Netscape/Firefox/Opera
      {
      keynum = e.which;
      }
    //keychar = String.fromCharCode(keynum);
    
    return keynum

}


function ajaxLoaderImg(objId, mode)
{
    var obj = document.getElementById(objId);
    if (obj!=undefined)
    {
        switch (mode) {
            case 0:
                obj.innerHTML = "<img src='images/ajax-loader.gif' />";
                break;
            case 1:
                obj.innerHTML = "<img src='images/ajax-loader.gif' />";
                break;
            case 2:
                obj.innerHTML = "<img src='images/ajax-loader.gif' />";
                break;
            case 3:
                obj.innerHTML = "<img src='images/ajax-loader.gif' />";
                break;
            default:
                break;
        }
  
    }
}


function ajaxLoaderImg2(objId, mode)
{
    var obj = document.getElementById(objId);
    if (obj!=undefined)
    {
        switch (mode) {
            case 0:
                obj.innerHTML = "<img src='images/ajax-loader2.gif' />";
                break;
            case 1:
                obj.innerHTML = "<img src='images/ajax-loader2.gif' />";
                break;
            case 2:
                obj.innerHTML = "<img src='images/ajax-loader2.gif' />";
                break;
            case 3:
                obj.innerHTML = "<img src='images/ajax-loader2.gif' />";
                break;
            default:
                break;
        }
  
    }
}

function ajaxLoaderImgTxt(objId, mode)
{
    var obj = document.getElementById(objId);
    if (obj!=undefined)
    {
        switch (mode) {
            case 0:
                obj.innerHTML = "<p style='text-align: center; font-weight: bold; color: #ffcccc; font-size:10px;'><img src='images/ajax-loader.gif' /><br />initializing</p>";
                break;
            case 1:
                obj.innerHTML = "<p style='text-align: center; font-weight: bold; color: #ffcccc; font-size:10px;'><img src='images/ajax-loader.gif' /><br />loading</p>";
                break;
            case 2:
                obj.innerHTML = "<p style='text-align: center; font-weight: bold; color: #ffcccc; font-size:10px;'><img src='images/ajax-loader.gif' /><br />processing</p>";
                break;
            case 3:
                obj.innerHTML = "<p style='text-align: center; font-weight: bold; color: #ffcccc; font-size:10px;'><img src='images/ajax-loader.gif' /><br />completing</p>";
                break;
            default:
                break;
        }
  
    }
}

function ajaxLoaderImgSmall(objId, mode)
{
    var obj = document.getElementById(objId);
    if (obj!=undefined)
    {
        switch (mode) {
            case 0:
                obj.innerHTML = "<img src='images/ajax-loader-sm.gif' style='padding-top:2px;padding-right:5px;float-left;' /><small>initializing</small>";
                break;
            case 1:
                obj.innerHTML = "<img src='images/ajax-loader-sm.gif' style='padding-top:2px;padding-right:5px;float-left;' /><small>loading</small>";
                break;
            case 2:
                obj.innerHTML = "<img src='images/ajax-loader-sm.gif' style='padding-top:2px;padding-right:5px;float-left;' /><small>processing</small>";
                break;
            case 3:
                obj.innerHTML = "<img src='images/ajax-loader-sm.gif' style='padding-top:2px;padding-right:5px;float-left;' /><small>completing</small>";
                break;
            default:
                break;
        }
  
    }
}



function CheckCapsLock( e ) {
   var myKeyCode = 0;
   var myShiftKey = e.shiftKey;
   
   if ( document.all ) {
      // Internet Explorer 4+
      myKeyCode = e.keyCode;
   } else if ( document.getElementById ) {
      // Mozilla / Opera / etc.
      myKeyCode = e.which;
   }
   
   if ((myKeyCode >= 65 && myKeyCode <= 90 ) || (myKeyCode >= 97 && myKeyCode <= 122)) {
      if ( 
         // Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
         ( (myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey )

         ||

         // Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
         ( (myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey )
       )
      {
         Show("divCapsLockWarn", 5000);
      }
      else {
         Hide("divCapsLockWarn");
      }
   }
}

//replace string
function replace(theString, subStr1, subStr2)
{
        //replaces subStr1 with subStr2 in theString
        var i = theString.indexOf(subStr1);
        if (i == -1) 
			return theString;  
        else 
			return(theString.substring(0,i) + subStr2 + replace(theString.substring(i+subStr1.length,theString.length),subStr1,subStr2));
}




function handleMenuClick(id, zoneId)
{

    switch (id) {
    
        case "home":
            document.location.href="default.aspx";
            break;
        case "about":
            document.location.href="about.aspx";            
            break;
        case "gallery":
            document.location.href="gallery.aspx";
            break;
        case "models":
            document.location.href="models.aspx";
            break;
        case "players":
            document.location.href="players.aspx";
            break;
        case "links":
            document.location.href="links.aspx";
            break;   
        case "contact":
            document.location.href="contact.aspx";
            break;                        
        case "forum":
            document.location.href = "forums/default.aspx";
            break;
        case "blog":
            window.open("http://artingerguitar.wordpress.com", "artingerblog");
            break;

        case "repairs":
	
            document.location.href = "repairs.aspx";
            break;
        
        default:
            alert("Action not yet supported");
            break;
    }

}


function initMenu(xml)
{
   try
    {
            
	    var menu = new dhtmlXMenuObject("menu", "dhx_black");
	    
	    menu.setImagePath("dhtmlx/dhtmlxMenu/codebase/imgs/");
	    menu.setIconsPath("images/");
	    menu.attachEvent("onClick", handleMenuClick);
	    menu.loadXMLString(xml);
	    
	    
	    
	
    }
    catch (e)
    {
        alert("debug: " + e);
    }
    
}

function setPageHeader(hdr)
{
    document.getElementById("pageHeader").innerHTML = hdr;

}

function getNextBanner()
{
    var imgCount = 11;
    var bannerImg = 1;
    
    var bannerImg= GetCookie("bannerimg");
    
    if (bannerImg==null)
        bannerImg = 1;
    
    document.getElementById("bannerimg").style.backgroundImage="url(images/banner-" + bannerImg + ".png)";
    
    bannerImg = parseInt(bannerImg) + 1;
    
    if (bannerImg > imgCount)
        bannerImg = 1;


    SetCookie("bannerimg", bannerImg, expdate);
    
}

function loadMenu(skipLoginCheck)
{

    getNextBanner();
 
          
    var res = '<?xml version="1.0"?><menu><item id="home" text="Home" /><item id="about" text="About" />' +
              '<item id="models" text="Models" /><item id="gallery" text="Gallery" />' + 
              '<item id="players" text="Players" ></item>' +
              '<item id="repairs" text="Repairs" />' + 
              '<item id="forum" text="Forum" /><item id="links" text="Links" /><item id="contact" text="Contact" /><item id="blog" text="Blog" /></menu>';
    initMenu(res);  
    return;
    
    // random banner 
    //var randomnumber = Math.floor(Math.random()*6) + 1;
    //document.getElementById("header").style.backgroundImage="url(images/banner" + randomnumber + ".png)";

    
    
    var url = "_ajax/common.aspx";
    var params = "mode=getmenu";
    
    if (skipLoginCheck!=undefined)
        params += "&skiplogincheck=true";
    
    var http = getXHTTP();
    http.open("POST", url, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.onreadystatechange = function () { completeLoadMenu(http); }
    
    http.send(params);
   
}

function completeLoadMenu(myHttp)
{

    try {
         var res = '';
       
        
         //ajaxLoaderTxt("menu", myHttp.readyState);
         
         if (myHttp.readyState == 4)
         {
            
            res = myHttp.responseText;  
            
            if (res != "Session timed out")
                initMenu(res);  
         }    
     }
     catch (e) {
        alert(e);
     }
}



function getListSelections(ctrlName)
{
    var val = "";
    
    if (document.getElementById(ctrlName)!=undefined)
        for (x=0;x<document.getElementById(ctrlName).length;x++)
            if (document.getElementById(ctrlName).options[x].selected)
            {
                if (val!="")
                    val += ",";
                val += document.getElementById(ctrlName).options[x].value;
            }
            

    return val;
}


function ajaxListControl(ctrlName, source, val, arg, doAfter)
{

    // if list control already initialized, retain selected value(s)
    if (val=="") 
        if (document.getElementById(ctrlName)!=undefined)
            val = getListSelections(ctrlName);
            
    var ctrl = document.getElementById("div_" + ctrlName);
//    if (ctrl!=undefined) 
//        ctrl.innerHTML = "<span style='text-align:center; font-family:<%=DEFAULT_FONT_FACE %>; font-size:10px; font-weight:bold; color:Gray;'>Loading...</span>";

    var url = "_ajax/_lists.aspx";
    var params = "source=" + source;
    params += "&ctrl=" + ctrlName;
    params += "&val=" + val;
    params += "&arg=" + arg;
    
    var http = getXHTTP();
    http.open("POST", url, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.onreadystatechange = function () { completeAjaxListControl(http, ctrlName, doAfter); }
    
    http.send(params);

}

function completeAjaxListControl(myHttp, ctrlName, doAfter)
{
    try {
         var res = '';

         ajaxLoaderTxt("div_" + ctrlName, myHttp.readyState);
       
         if (myHttp.readyState == 4)
         {
            ajaxLoaderTxt("div_" + ctrlName, "");
            
            lstObj = document.getElementById("div_" + ctrlName);
            
            res = myHttp.responseText;  
            if (res == "Session timed out")
            {
                document.location.href = document.location.href;
                return
            }
            lstObj.innerHTML = res;
            
            if (doAfter!=undefined)
                eval(doAfter);
            
            //tabbar.adjustSize(); //force size update
                
         }    
     }
     catch (e) {
        alert(e);
     }         
}


function onEnterKeyDoLogin(event)
{
    var characterCode;
    
    if (event.which) //if which property of event object is supported (NN4)
        characterCode = event.which; //character code is contained in NN4's which property
    else
        characterCode = event.keyCode; //character code is contained in IE's keyCode property
    
    if(characterCode == 13) //if generated character code is equal to ascii 13 (if enter key)
    { 
        doLogin();
        return false; 
    }
    else
        return true; 
    

}

function doLogout()
{
    
    
    var url = "_ajax/common.aspx";
    var params = "mode=logout";
    
    var http = getXHTTP();
    http.open("POST", url, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.onreadystatechange = function () { completeDoLogout(http); }
    
    http.send(params);
    
    
}

function completeDoLogout(myHttp)
{
    
    try {
         var res = '';
       
         if (myHttp.readyState == 4)
         {
            
            res = myHttp.responseText;  
            if (res!="ok")
                alert(res);
            else   
                document.location.href = "default.aspx";   
            //if (res != "Session timed out")
                  
         }    
     }
     catch (e) {
        alert(e);
     }
 
}



function loadContent(mode, objName, loaderStyle, extraParams, doAfter, skipLoginCheck)
{
    
    
    var url = "_ajax/common.aspx";
    params = "mode=" + mode;
    
    if (skipLoginCheck!=undefined)
        params += "&skiplogincheck=true";
    
    if (extraParams!=undefined)
        params += extraParams;
    
    var http = getXHTTP();
    http.open("POST", url, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.onreadystatechange = function () { completeLoadContent(http, objName, loaderStyle, doAfter); }
    
    http.send(params);
    
    
}

function completeLoadContent(myHttp, objName, loaderStyle, doAfter)
{
    
    try {
         var res = '';
         
         switch (loaderStyle) {
             case "img":
                ajaxLoaderImg(objName, myHttp.readyState);
                break;
             case "img2":
                ajaxLoaderImg2(objName, myHttp.readyState);
                break;
             case "txt":
                ajaxLoaderTxt(objName, myHttp.readyState);
                break;
             case "imgtxt":
                ajaxLoaderImgTxt(objName, myHttp.readyState);
                break;
             default:
         }
       
         if (myHttp.readyState == 4)
         {
            
            res = myHttp.responseText;  
            
            //alert(res);
            document.getElementById(objName).innerHTML = res;
                  

            if (doAfter!=undefined)
               if (doAfter!="")
                   eval(doAfter);
         }    
     }
     catch (e) {
        alert(e);
     }
 
}


function ajaxCall(url, params, doWithResult, doAfter) {

    if (params == undefined)
        params = "";

    var http = getXHTTP();
    http.open("POST", url, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    if (params.length > 0)
        http.setRequestHeader("Content-length", params.length);

    if (!browser.isIE)
        http.setRequestHeader("Connection", "close");
    http.onreadystatechange = function() { completeAjaxCall(http, doWithResult, doAfter); }

    http.send(params);

}

function completeAjaxCall(myHttp, doWithResult, doAfter) {
    try {
        var res = '';

        if (myHttp.readyState == 4) {

            res = myHttp.responseText;

            if (doWithResult != undefined) {
                // debugging tool: pass 'alert' to doWithResult

                switch (doWithResult) {
                    case "alert":
                        alert(res);
                        break;
                    default:
                        eval(replace(doWithResult, "%res%", replace(res, "'", "\\'")));
                        break;
                }

            }

            if (doAfter != undefined)
                eval(doAfter);

        }
    }
    catch (e) {
        alert(e);
    }

}	


function ajaxUtil(params, doAfter)
{

    var url = "_ajax/common.aspx";
    
    var http = getXHTTP();
    http.open("POST", url, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.onreadystatechange = function () { completeAjaxUtil(http, doAfter); }
    
    http.send(params);
}

function completeAjaxUtil(myHttp, doAfter)
{
     var res = '';
     if (myHttp.readyState == 4) { 
         res = myHttp.responseText;  
         if (res!='ok')
             alert(res);
         
         if (doAfter!=undefined)
            if (doAfter!="")
                eval(doAfter);
     }
     
}



function trim(str)
{

	while(''+str.charAt(0)==' ')
		str=str.substring(1,str.length);
	while(''+str.charAt(str.length)==' ')
		str=str.substring(0,str.length-1);
	return str
}



function printThread(fDesc, tDesc)
{

    if (fDesc == "")
        if (document.getElementById("divThreadHeader")!=undefined)
            fDesc = document.getElementById("divThreadHeader").innerHTML;
        
    if (tDesc == "")
        tDesc = document.getElementById("divMessageHeader").innerHTML;
        
        
    var thrd = document.getElementById("divMessages").innerHTML;
    
    var wnd = window.open("", "printThread", "width=624, height=500, status=no, scrollbars=yes, location=no, toolbar=no, resizeable=yes");
    wnd.document.write("<html><head><title>MTS - Print Thread</title><link href='StyleSheet1-print.css' rel='stylesheet' type='text/css' /></style></head><body>" + fDesc + "" + tDesc + "" + thrd + "</body></html>");
    wnd.document.close();
    wnd.print();
    
    
}   



function checkSecurity(lvl)
{
    
    var url = "_ajax/common.aspx";
    var params = "mode=checksecurity";
    params += "&lvl=" + lvl;
    
    var http = getXHTTP();
    http.open("POST", url, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    http.onreadystatechange = function () { completeCheckSecurity(http); }
    
    http.send(params);
   
}

function completeCheckSecurity(myHttp)
{

    try {
         var res = '';
       
         //ajaxLoaderImg("div_grxUsers", myHttp.readyState);
         
         if (myHttp.readyState == 4)
         {
            
            res = myHttp.responseText;  
            // if not ok, then user is not authorized to view page
            if (res!="ok")
                document.location.href="default.aspx";
         }    
     }
     catch (e) {
        alert(e);
     }

}

var expdate = new Date();
FixCookieDate(expdate);
expdate.setTime(expdate.getTime() + ((24 * 365) * 60 * 60 * 1000));  // expire in 1 year 


	function getCookieVal (offset) {
		var endstr = document.cookie.indexOf (';', offset);
		if (endstr == -1)
			endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
	
	function FixCookieDate (date) {
		var base = new Date(0);
		var skew = base.getTime(); // dawn of (Unix) time - should be 0
		if (skew > 0)  // Except on the Mac - ahead of its time
			date.setTime (date.getTime() - skew);
	}
	
	function SetCookie (name,value,expires,path,domain,secure) {
		document.cookie = name + '=' + escape (value) +
		((expires) ? '; expires=' + expires.toGMTString() : '') +
		((path) ? '; path=' + path : '') +
		((domain) ? '; domain=' + domain : '') +
		((secure) ? '; secure' : '');
	}
	    
	function GetCookie (name) {
		var arg = name + '=';
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		while (i < clen) {
			var j = i + alen;
			if (document.cookie.substring(i, j) == arg)
				return getCookieVal (j);
			i = document.cookie.indexOf(' ', i) + 1;
			if (i == 0) break; 
		}
		return null;
	}
    
	function DeleteCookie (name,path,domain) {
		if (GetCookie(name)) {
			document.cookie = name + '=' + 
			((path) ? '; path=' + path : '') +
			((domain) ? '; domain=' + domain : '') +
			'; expires=Thu, 01-Jan-70 00:00:01 GMT';
		}
	}
