/* COPYRIGHT XEINET 2006 ALL RIGHTS RESERVED */

function signOut(spanId){
var soDiv = document.getElementById(spanId);
  runAjax('ajax.aspx','t=1&id=' + spanId,signOutCallBack,soDiv);
}

function signOutCallBack(result,soDiv){
soDiv.innerHTML = "<a href='/signin.aspx'>Sign In</a>";
window.location.href=window.location.href;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=

function flagListing(pid,text){
runAjax('ajax.aspx','t=2&id=' + pid + '&msg=' + text,closeFlagBox);
}

function closeFlagBox(result){ }


//--displays the main bar actvity symbol
function showAjaxActivity(on){
    try{
    if(document.getElementById('ajax_bar')){
    if(on){document.getElementById('ajax_bar').style.display="block";
    }else{document.getElementById('ajax_bar').style.display="none";}}
    }catch(e){};
}

//--Xeinet(c) 2006 Custom Ajax Library All rights Reserved
function createXHR() { var xhrObj; if (window.XMLHttpRequest) {try {xhrObj=new XMLHttpRequest();}catch(e){xhrObj = null;}}else if (window.createRequest){try {xhrObj = window.createRequest();}catch(e){xhrObj=null;}}else if(window.ActiveXObject){try{xhrObj=new ActiveXObject("Msxml2.XMLHTTP");} catch(e){try{xhrObj = new ActiveXObject("Microsoft.XMLHTTP");}catch(e){xhrObj = null;}}}return xhrObj;}
//-- Executes Ajax against url, pass in query strings, as params, and include the name of a function 
//-- To Callback E.g ("http://peopleAZ.org","t=1&w=hello+World",showResult);
//-- Expects a JSON encoded respose - so wil rehyrate a object - if we just want a single value use the function runAjaxNOJSON(url,qs,callback)
function runAjax(url,qs,callback,divObj,isPost) {
      var xhr = createXHR();
      showAjaxActivity(true);
      /* Inner function to bind handler and create closure */
      function bindCallback(){ 
          if (xhr.readyState == 4){
              try{
                  if (xhr.status == 200){
                    if(xhr.responseText == "NO_SESSION"){
                     window.location.href = 'logon.aspx';
                    }else{callback( eval('(' +  xhr.responseText + ')'),divObj );showAjaxActivity(false);}
                  }else{
                     showError("PAZ-ERROR:0999>>Status :" + xhr.status)
                     callback(null,divObj);
                     showAjaxActivity(false);
                  }
             } catch (e) { callback(null);
            }
         }
     }
                
     if (xhr) {
         try {
             xhr.onreadystatechange = bindCallback;
             if(isPost){
                 xhr.open('POST', url + '?aj=1&u=' + (Math.random()*Math.random()), true);
                 xhr.send(qs);
               }else{
                 xhr.open('GET', url + '?aj=1&u=' + (Math.random()*Math.random()) + '&' + qs, true);
                 xhr.send(null);
               }
         }catch (e) {
             showError(e);callback(null,divObj);
        }
     }
 } //eof runAjax
 
 //--Runs ajax returning a literal rather than a json object
 function runAjaxNOJSON(url,qs,callback,divObj,isPost) {
      var xhr = createXHR();
      /* Inner function to bind handler and create closure */
      function bindCallback() {
          if (xhr.readyState == 4) {
              try {
                  if (xhr.status == 200){
                        if(xhr.responseText == "NO_SESSION"){
                         window.location.href = 'logon.aspx';
                        }else{callback( xhr.responseText,divObj);showAjaxActivity(false);}
                    }
                 else{
                     showError("Status error:" + xhr.status);
                      callback(null,divObj);
                      showAjaxActivity(false);
                     }
             } catch (e) { showError(e);callback(null,divObj);
            }
         }
     }
                
     if (xhr) {
         try {
             xhr.onreadystatechange = bindCallback;
             if(isPost){
                 xhr.open('POST', url + '?aj=1&u=' + (Math.random()*Math.random()), true);
                 xhr.send(qs);
               }else{
                 xhr.open('GET', url + '?aj=1&u=' + (Math.random()*Math.random()) + '&' + qs, true);
                 xhr.send(null);
               }
         } catch (e) {
             showError(e);callback(null,divObj);
        }
     }
 } //eof runAjax

//-- Error handler for Ajax - customize if required
function showError(e){ alert(e); showAjaxActivity(false);}

//--End Xeinet(c) 2006 Custom Ajax Library All rights Reserved


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function setDialogHTML(html) {
    var claimHtml = document.getElementById('dlg_area');
    claimHtml.innerHTML = html;
}

//--displays the  a Dialog result is a json object, if we have a dialog div displayed just inserts
//--Html into area json object includes title,html,closeFunction,height,width properties
function showDialog(displayJson) {
    
    showAjaxActivity(false);
    //if we have then show
    var dialog = document.getElementById('dialog');

    //only display if we are not already showing
    if (dialog.style.display != "block"){
        dialog.style.display = "block";
        dialog.style.position = "absolute";
        dialog.style.height = (displayJson.height ? displayJson.height : "470px");
        dialog.style.width = (displayJson.width ? displayJson.width : "800px");
        dialog.style.zIndex = 500;
        var IpopTop = (document.body.clientHeight - dialog.offsetHeight) / 2;
        var IpopLeft = (document.body.clientWidth - dialog.offsetWidth) / 2;
        //  dialog.style.left= (IpopLeft + document.body.scrollLeft) + "px";
        dialog.style.left = (IpopLeft + getScrollWidth()) + "px";
        //dialog.style.top=  (IpopTop + document.body.scrollTop) + "px";
        dialog.style.top = GetTopCent(IpopTop) + "px";
        //set a transparent back -- note does not work in IE 7
        setOverlay(true, 200, 'dlg1');
    }

    

    //now write html into main element
    var claimHtml = document.getElementById('dlg_area');
    claimHtml.innerHTML = displayJson.html;

    
    
    document.getElementById('dlg_title').innerHTML = displayJson.title;

    //If a custom close function is included set it here e.g claimclose() 
    if (displayJson.closeFunction)
        document.getElementById('dlg_close').innerHTML = "<a href=\"javascript:" + displayJson.closeFunction + ";\"><img onmouseover=\"this.src='i/closeIcon.png';\"  onmouseout=\"this.src='i/closeIconW.png';\"  src=\"i/closeIconW.png\" /></a>";
    else
        document.getElementById('dlg_close').innerHTML = "<a href=\"javascript:closeDialog();\"><img onmouseover=\"this.src='i/closeIcon.png';\"  onmouseout=\"this.src='i/closeIconW.png';\" src=\"i/closeIconW.png\" /></a>";
}
//--ensures that top of dialog is not off the top
function GetTopCent(IpopTop) { var t = IpopTop + getScrollHeight(); if (t > 0) { return t; } else { return 20; } }

//--closes dialog, if a custom close is passed this will still need to be called to remove the grey overlay & dispose of wincal
function closeDialog() {
    showAjaxActivity(false);
    document.getElementById('dialog').style.display = "none";
    //remove the greyout/overlay
    setOverlay(false, 200, 'dlg1');
}

function getScrollWidth() {
    var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
    return w ? w : 0;
 }

function getScrollHeight() {
    var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
    return h ? h : 0;
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function setOverlay(vis, zIndex, layerId) {
    var op = new Object();
    op.zindex = zIndex;
    grayOut(vis, op, layerId);
}

function grayOut(vis, options, layerId) {
    if (IsIE7) return;

    // Pass true to gray out screen, false to ungray
    // options are optional.  This is a JSON object with the following (optional) properties
    // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
    // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
    // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
    // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
    // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
    // in any order.  Pass only the properties you need to set.
    var options = options || {};
    var zindex = options.zindex || 200;
    var opacity = options.opacity || 60;
    var opaque = (opacity / 100);
    var bgcolor = options.bgcolor || '#000000';
    var dark = document.getElementById(layerId);
    if (!dark) {
        // The dark layer doesn't exist, it's never been created.  So we'll
        // create it here and apply some basic styles.
        // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
        var tbody = document.getElementsByTagName("body")[0];
        var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position = 'absolute';                 // Position absolutely
        tnode.style.top = '0px';                           // In the top
        tnode.style.left = '0px';                          // Left corner of the page
        tnode.style.overflow = 'hidden';                   // Try to avoid making scroll bars            
        tnode.style.display = 'none';                      // Start out Hidden
        tnode.id = layerId;                                // Name it so we can find it later
        tbody.appendChild(tnode);                            // Add it to the web page
        dark = document.getElementById(layerId);              // Get the object.
    }

    if (vis) {
        // Calculate the page width and height 
        if (document.body && (document.body.scrollWidth || document.body.scrollHeight)) {
            var pageHeight = getDocHeight() + "px"; ; // document.body.scrollHeight+'px';
            var pageWidth = document.body.scrollWidth + 'px';

        } else if (document.body.offsetWidth) {
            var pageWidth = getScrollWidth() + 'px';  // document.body.offsetWidth+'px';
            var pageHeight = getScrollHeight() + 'px'; // document.body.offsetHeight+'px';
        } else {
            var pageWidth = getScrollWidth() + 'px';  // document.body.offsetWidth+'px';
            var pageHeight = getScrollHeight() + 'px'; // document.body.offsetHeight+'px';
            //  var pageWidth='100%';
            //  var pageHeight='100%';
        }
        //set the shader to cover the entire page and make it visible.
        dark.style.opacity = opaque;
        dark.style.MozOpacity = opaque;
        dark.style.filter = 'alpha(opacity=' + opacity + ')';
        dark.style.zIndex = zindex;
        dark.style.backgroundColor = bgcolor;
        dark.style.width = pageWidth;
        dark.style.height = pageHeight;
        dark.style.display = 'block';
        //dark.style.position='absolute';                         
    } else {
        dark.style.display = 'none';
    }
}


//+++++++++++++++++++++++MoveWinCode+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
    // This function will return an Object with x and y properties
    var useWindow = false;
    var coordinates = new Object();
    var x = 0, y = 0;
    // Browser capability sniffing
    var use_gebi = false, use_css = false, use_layers = false;
    if (document.getElementById) { use_gebi = true; }
    else if (document.all) { use_css = true; }
    else if (document.layers) { use_layers = true; }
    // Logic to find position
    if (use_gebi && document.all) {
        x = AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
        y = AnchorPosition_getPageOffsetTop(document.all[anchorname]);
    }
    else if (use_gebi) {
        var o = document.getElementById(anchorname);
        x = AnchorPosition_getPageOffsetLeft(o);
        y = AnchorPosition_getPageOffsetTop(o);
    }
    else if (use_css) {
        x = AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
        y = AnchorPosition_getPageOffsetTop(document.all[anchorname]);
    }
    else if (use_layers) {
        var found = 0;
        for (var i = 0; i < document.anchors.length; i++) {
            if (document.anchors[i].name == anchorname) { found = 1; break; }
        }
        if (found == 0) {
            coordinates.x = 0; coordinates.y = 0; return coordinates;
        }
        x = document.anchors[i].x;
        y = document.anchors[i].y;
    }
    else {
        coordinates.x = 0; coordinates.y = 0; return coordinates;
    }
    coordinates.x = x;
    coordinates.y = y;
    return coordinates;
}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
    var coordinates = getAnchorPosition(anchorname);
    var x = 0;
    var y = 0;
    if (document.getElementById) {
        if (isNaN(window.screenX)) {
            x = coordinates.x - document.body.scrollLeft + window.screenLeft;
            y = coordinates.y - document.body.scrollTop + window.screenTop;
        }
        else {
            x = coordinates.x + window.screenX + (window.outerWidth - window.innerWidth) - window.pageXOffset;
            y = coordinates.y + window.screenY + (window.outerHeight - 24 - window.innerHeight) - window.pageYOffset;
        }
    }
    else if (document.all) {
        x = coordinates.x - document.body.scrollLeft + window.screenLeft;
        y = coordinates.y - document.body.scrollTop + window.screenTop;
    }
    else if (document.layers) {
        x = coordinates.x + window.screenX + (window.outerWidth - window.innerWidth) - window.pageXOffset;
        y = coordinates.y + window.screenY + (window.outerHeight - 24 - window.innerHeight) - window.pageYOffset;
    }
    coordinates.x = x;
    coordinates.y = y;
    return coordinates;
}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft(el) {
    var ol = el.offsetLeft;
    while ((el = el.offsetParent) != null) { ol += el.offsetLeft; }
    return ol;
}
function AnchorPosition_getWindowOffsetLeft(el) {
    return AnchorPosition_getPageOffsetLeft(el) - document.body.scrollLeft;
}
function AnchorPosition_getPageOffsetTop(el) {
    var ot = el.offsetTop;
    while ((el = el.offsetParent) != null) { ot += el.offsetTop; }
    return ot;
}
function AnchorPosition_getWindowOffsetTop(el) {
    return AnchorPosition_getPageOffsetTop(el) - document.body.scrollTop;
}


// Determine browser and version.
function Browser() {

    var ua, s, i;

    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;
    }

    // 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();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 1000;

function dragStart(event, id) {

    var el;
    var x, y;

    // If an element id was given, find it. Otherwise use the element being
    // clicked on.

    if (id)
        dragObj.elNode = document.getElementById(id);
    else {
        if (browser.isIE)
            dragObj.elNode = window.event.srcElement;
        if (browser.isNS)
            dragObj.elNode = event.target;

        // If this is a text node, use its parent element.

        if (dragObj.elNode.nodeType == 3)
            dragObj.elNode = dragObj.elNode.parentNode;
    }

    // Get cursor position with respect to the page.

    if (browser.isIE) {
        x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
        y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
    }
    if (browser.isNS) {
        x = event.clientX + window.scrollX;
        y = event.clientY + window.scrollY;
    }

    // Save starting positions of cursor and element.

    dragObj.cursorStartX = x;
    dragObj.cursorStartY = y;
    dragObj.elStartLeft = parseInt(dragObj.elNode.style.left, 10);
    dragObj.elStartTop = parseInt(dragObj.elNode.style.top, 10);

    if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
    if (isNaN(dragObj.elStartTop)) dragObj.elStartTop = 0;

    // Update element's z-index.

    dragObj.elNode.style.zIndex = ++dragObj.zIndex;

    // Capture mousemove and mouseup events on the page.

    if (browser.isIE) {
        document.attachEvent("onmousemove", dragGo);
        document.attachEvent("onmouseup", dragStop);
        window.event.cancelBubble = true;
        window.event.returnValue = false;
    }
    if (browser.isNS) {
        document.addEventListener("mousemove", dragGo, true);
        document.addEventListener("mouseup", dragStop, true);
        event.preventDefault();
    }
}

function dragGo(event) {

    var x, y;

    // Get cursor position with respect to the page.

    if (browser.isIE) {
        x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
        y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
    }
    if (browser.isNS) {
        x = event.clientX + window.scrollX;
        y = event.clientY + window.scrollY;
    }

    // Move drag element by the same amount the cursor has moved.

    dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
    dragObj.elNode.style.top = (dragObj.elStartTop + y - dragObj.cursorStartY) + "px";

    if (browser.isIE) {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
    }
    if (browser.isNS)
        event.preventDefault();
}

function dragStop(event) {

    // Stop capturing mousemove and mouseup events.

    if (browser.isIE) {
        document.detachEvent("onmousemove", dragGo);
        document.detachEvent("onmouseup", dragStop);
    }
    if (browser.isNS) {
        document.removeEventListener("mousemove", dragGo, true);
        document.removeEventListener("mouseup", dragStop, true);
    }
}


