/********************************************************************************************************************/
/* STARTS  : Function for gray box display for popup box*/
/********************************************************************************************************************/

function showPopup(popDiv,loaderImage) {
    greyoutnew(true);
    if (navigator.userAgent.indexOf("Firefox") > -1){
        currentDocHeight=window.pageYOffset;
        currentDocWidth=window.pageXOffset;
        scrollH= currentDocHeight;
        scrollW= currentDocWidth;
     } else {
        currentDocHeight=document.body.scrollTop;
        currentDocWidth=document.body.scrollLeft;
        scrollH= currentDocHeight;
        scrollW= currentDocWidth;
     }
     var viewportwidth;
     var viewportheight;

     if (typeof window.innerWidth != 'undefined') {
     // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
         viewportwidth = window.innerWidth,
         viewportheight = window.innerHeight
     }  else if (typeof document.documentElement != 'undefined'  && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
     // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
      viewportwidth = document.documentElement.clientWidth,
      viewportheight = document.documentElement.clientHeight
     }  else {
     // older versions of IE
      viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
      viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
 
     //ABSOLUTE
     //x=event.clientX+scrollW;
     //y=event.clientY+scrollH;

     //	CENTER
     //x=((viewportwidth-750)/2)+scrollW;
     //y=((viewportheight-450)/2)+scrollH;
     x=((viewportwidth-100)/2)+scrollW;
     y=((viewportheight-100)/2)+scrollH;
    var showElement = document.getElementById(popDiv);
    var animGif = document.getElementById(loaderImage);

    if (showElement) {
        showElement.style.display = '';
        showElement.style.left=x+'px';
        showElement.style.top=y+'px';
    }
    if (animGif) {
        setTimeout(function() { animGif.src = animGif.src + "?rnd" + new Date().getTime() }, 300);
    }
}

function hidePopup(popDiv) {
        greyoutnew(false);

    document.getElementById(popDiv).style.display = 'none';
}

function greyoutnew(d,z) {

    var obj = document.getElementById('greyout');
    if(!obj) {
        appendElement(document.body,'div','greyout');
        obj = document.getElementById('greyout');
        obj.style.position = 'absolute';
        obj.style.top = '0px';
        obj.style.left = '0px';
        obj.style.cursor = 'not-allowed';
        obj.style.background = '#111';
        obj.style.opacity = '.5';
        obj.style.filter = 'alpha(opacity=50)';
        obj.style.zIndex = '2'; // Added by muhtu
    }
    if(d) {
        if(!z){ z - 50 }
        //obj.style.zIndex = z;
        obj.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
        obj.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
        obj.style.display = 'block';
        addEvent(window,'resize',greyoutResize);
    }
    else {
        obj.style.display = 'none';   
        removeEvent(window,'resize',greyoutResize);
    }
}
 
function greyoutResize() {
    var obj = document.getElementById('greyout');
    obj.style.height = document.body.clientHeight+'px';
    obj.style.width  = document.body.clientWidth+'px';
    obj.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
    obj.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
}

function addEvent(obj ,evt, fnc) {
    if (obj.addEventListener)
        obj.addEventListener(evt,fnc,false);
    else if (obj.attachEvent)
        obj.attachEvent('on'+evt,fnc);
    else
        return false;
    return true;
}

function removeEvent(obj ,evt, fnc) {
     if (obj.removeEventListener)
         obj.removeEventListener(evt,fnc,false);
    else if (obj.detachEvent)
         obj.detachEvent('on'+evt,fnc);
    else
         return false;
    return true;
}

function appendElement(node,tag,id,htm) {
    var ne = document.createElement(tag);
    if(id) ne.id = id;
    if(htm) ne.innerHTML = htm;
    node.appendChild(ne);
}
/********************************************************************************************************************/
/* ENDS  : Function for gray box display for popup box*/
/********************************************************************************************************************/