//------------------------------- publish page
function axPublish(id){        
        var xmlhttp;
if (window.XMLHttpRequest)
            {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
            }
else if (window.ActiveXObject)
            {
            // code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
else
            {
            alert("Your browser does not support XMLHTTP!");
            }
        xmlhttp.open("GET","ajax/publishpage.aspx?id=" + id,true);
        xmlhttp.send(null);    
        
        xmlhttp.onreadystatechange=function()
        {
        if(xmlhttp.readyState == 4)
            {
                document.getElementById('strPub').innerHTML = xmlhttp.responseText;
                //document.getElementById('strPub').style.visibility = 'hidden';
                //alert(xmlhttp.responseText)
            }
        }
    }
    //------------------------------- publish page end

    //*------------------------------- Switch lang
    function switchLang() {
        var xmlhttp;
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else {
            alert("Your browser does not support XMLHTTP!");
        }
        xmlhttp.open("GET", "ajax/SwitchLang.aspx", true);
        xmlhttp.send(null);

        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
               
                location.reload(true);
                //alert(xmlhttp.responseText)
            }
        }
    }
    //*------------------------------- Switch lang end 


var allowConfirm = true;
function dontgo() {
    if (allowConfirm)
        event.returnValue = "You may lose any unsaved work on this page.";
    else
        allowConfirm = true;
}    

/////////////////////////////////////////////////////////////////
function showhide(el,strHide,strShow) {    
    //alert(el.replace(strHide, strShow));
    allowConfirm = false;
        if (document.getElementById(el.replace(strHide, strShow)).className == 'show') {
            document.getElementById(el.replace(strHide, strShow)).className = 'hide';
        }
        else {
            document.getElementById(el.replace(strHide, strShow)).className = 'show';
        }
}
/////////////////////////////////////////////////////////////////


function scrolldiv() {
   var pos1 = getPosition(document.getElementById('scrolltome'),'y');
   var pos2 = getPosition(document.getElementById('formsrightbar'), 'y');
   
       pos = (pos1 - pos2)/2;  //pos1//- pos2;

       //alert(pos);
       //alert(pos1 + "," + pos2 + "," + pos + "," + document.getElementById('formsrightbar').scrollHeight)
       document.getElementById('formsrightbar').scrollTop = pos;  //document.getElementById('formsrightbar').scrollHeight


   }
   
   
/////////////  get position  ///////////////////////////////////
function getPosition(obj,axis) {
    var topValue = 0, leftValue = 0;
    while (obj) {
        leftValue += obj.offsetLeft;
        topValue += obj.offsetTop;
        obj = obj.offsetParent;
    }
    if (axis == 'x')
    { finalvalue = leftValue }
    else if (axis == 'y')
    { finalvalue = topValue }
    else {
        finalvalue = leftValue + "," + topValue;
    }
    return finalvalue;
    //alert(finalvalue);
}
/////////////  get position end ////////////////////////////////

function setPosition(tar) {
    //alert(getPosition(document.getElementById(src), 'x'));
    //document.getElementById(tar).style.left = getPosition(document.getElementById(src), 'x')
    document.getElementById(tar).style.top = event.clientY //getPosition(document.getElementById(src), 'y');
    

}


// ----------------- forms session timeout warning ------------------------------------------
//   also includes bit in ajaxTimeOut() for the item notes
//  place this in page needing timeout warning: setTimeout("timeout()", 3540000)

x = 60 //x is number of seconds to countdown
function countdown() {
    //document.getElementById("timeleft").style.display = "block"
    document.getElementById('timeleft').innerHTML = x + " seconds left"
    x = x - 1
    if (x >= 0) //for countdown to stop; else it will carry on in minus numbers
        t = setTimeout("countdown()", 1000);
    else {
        document.getElementById('ajaxContent').innerHTML ="<h1>Your session has now expired</h1><h2>You may have to log in again</h2>";
        document.getElementById('timeleft').style.display = "none";
    }        
}

function timeout() {
    //alert("test")     
    document.getElementById("time-out").style.display = "block"
    a = ajaxTimeOut('timeout')
    c = countdown()
    t = setTimeout("timeout()", 1200000)
}

function ajaxTimeOut(qstring) {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        alert("Your browser does not support XMLHTTP!");
    }
    if (qstring == 'timeout') {
        url = "ajax/timeout.aspx?qstring=1"
    }
    else if (qstring == 'keepalive') {
        url = "ajax/timeout.aspx?qstring=2"
    }    

    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            document.getElementById('ajaxContent').innerHTML = xmlhttp.responseText;
            if (qstring == 'keepalive') {
                document.getElementById("time-out").style.display = "none";
                document.getElementById("goaway").style.display = "inline";
            }
        }
    }
}
// ----------------- forms session timeout warning end ---------------------------------------


//------Ajax Maintenance mode------------------------------------------------------------------
function CheckQuartzMaintenanceJS() {
    var v1 = '<%=ConfigurationManager.AppSettings["QuartzMaintenance"].ToString() %>'
    if (v1 == 'NoWrite') {
    alert('The page you requested is temporarily unavailable due to essential maintence work being carried out.');
    return false;
    }
}
//------end Ajax Maintenance mode-----------------------------------------------------------------
