var xcol_cur_menu = null;
var xcol_cur_submenu = null;

//Generating Pop-up Print Preview page

if (typeof (jQuery) != 'undefined') {
    String.prototype.repeat = function(l) {
        return new Array(l + 1).join(this);
    };
}

function getPrint(print_area)

{
//Creating new page
var pp = window.open();
//Adding HTML opening tag with <HEAD> … </HEAD> portion
pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')
pp.document.writeln('<LINK href=Styles.css type="text/css" rel="stylesheet">')
pp.document.writeln('<LINK href=PrintStyle.css type="text/css" rel="stylesheet" media="print">')
pp.document.writeln('<base target="_self"></HEAD>')
//Adding Body Tag
pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0"');
pp.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0">');
//Adding form Tag
pp.document.writeln('<form method="post">');
//Creating two buttons Print and Close within a HTML table
pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right>');
pp.document.writeln('<INPUT ID="PRINT" style="width:120px" class="input-box" type="button" value="Print" ');
pp.document.writeln('onclick="javascript:location.reload(true);window.print();">');
pp.document.writeln('<INPUT ID="CLOSE" style="width:120px" class="input-box" type="button" value="Close" onclick="window.close();">');
pp.document.writeln('</TD></TR><TR><TD></TD></TR></TABLE>');
//Writing print area of the calling page
pp.document.writeln(document.getElementById(print_area).innerHTML);
//Ending Tag of </form>, </body> and </HTML>
pp.document.writeln('</form></body></HTML>');
} 

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

function kH(e) {
var pK = e ? e.which : window.event.keyCode;
return pK != 13;
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function show(id)
{
    if (!isDOMcompliant()) { return; }

    var menu = document.getElementById("Menu" + id);
    var menus = document.getElementById("NavMenuList");
    if (!menus) return;

    var submenu = menus.getElementsByTagName("ul").item(id);
    if (xcol_cur_submenu == null) {
        submenu.style.visibility = "hidden";
    } else {
        xcol_cur_submenu.style.visibility = "hidden";
        submenu.style.visibility = "visible";
    }

    xcol_cur_menu = menu;
    xcol_cur_submenu = submenu;
}

function unshow()
{
    if (!isDOMcompliant()) { return; }
    if (xcol_cur_submenu != null) {
        xcol_cur_submenu.style.visibility = "hidden";
    }
    if (xcol_cur_menu != null) {
        xcol_cur_menu.style.backgroundColor = "#036";
        xcol_cur_menu.style.color = "#FFF";
    }
    xcol_cur_submenu = null;
    xcol_cur_menu = null;
}

function isDOMcompliant()
{
    return document.getElementById && document.getElementsByTagName;
}

function xcShowLoginDiv () {
    if (!document.getElementById) return true;
    var notloge = document.getElementById("NotLoggedInDiv");
    var logboxe = document.getElementById("LoginBox");
    var xcusere = document.getElementById("xc_user");
    if (!notloge || !logboxe || ! xcusere) return true;
    notloge.style.display = 'none';
    logboxe.style.display = 'block';
    xcusere.focus();
    return false;
}

var showNothing = function () { show(0) };
if (window.attachEvent)
    window.attachEvent("onload", showNothing);
if (window.addEventListener)
    window.addEventListener("load", showNothing, false);

function makeDialog(url, p_Width, p_Height)
{
   if (p_Width == "null") {
        lWidth=500;
        lHeight=350;
    }
    else
    {
        lWidth=p_Width;
        lHeight=p_Height;
    }

    leftVal = (screen.width - lWidth) / 2;
    topVal = (screen.height - lHeight) / 2;

    params  = "";
    params += "status:1;";
    params += "unadorned:0;";
    params += "scroll:1;";
    params += "resizable:0;";
    params += "center:1;";
    params += "dialogWidth:" + lWidth + "px;";
    params += "dialogHeight:" + lHeight + "px;";
    
    win = window.showModalDialog(url,self,params);
    
    return win;
}

function makeWindow(url, p_Width, p_Height) 
{

    if (p_Width == "null") {
        lWidth=500;
        lHeight=350;
    }
    else
    {

        lWidth=p_Width;
        lHeight=p_Height;
    }
    
    if ((lWidth<screen.availWidth) && (lHeight<screen.availHeight))
    {
        resize=false;
    } else {
        resize=true;
    }

    leftVal = (screen.width - lWidth) / 2;
    topVal = (screen.height - lHeight) / 2;

    agent = navigator.userAgent;
    windowName = "_blank";
    params  = "";
    params += "toolbar=0,";
    params += "location=0,";
    params += "directories=0,";
    params += "status=1,";
    params += "menubar=0,";
    params += "scrollbars=1,";
    params += "resizable=0,";
    params += "titlebar=0,";
    params += "top=" + topVal + ",";
    params += "left=" + leftVal + ",";
    params += "width=" + lWidth+ ",";
    params += "height=" + lHeight;

    win = window.open(url, windowName , params);

    if (agent.indexOf("Mozilla/2") != -1 && agent.indexOf("Win") == -1) {
      win = window.open(url, windowName , params);
    }

    if (!win.opener) {
      win.opener = window;
    }

    // bring the window to the front
    win.focus();	
    // in case the window.open parameters aren't working right:
    win.moveTo(0,0);
    if (resize) { win.resizeTo(screen.availWidth,screen.availHeight); }
}
