/*
Common scripting for this application
*/

var intDefaultPopUpWidth = 590;
var intDefaultPopUpHeight = 450;
function OpenPopUp(strURL, intPopUpWidth, intPopUpHeight) {
	var reURL = /^([^\.\/\\]*)\.[^\.]*$/;
	var strWinName
	if (reURL.test(strURL)) {
		aryURL = reURL.exec(strURL);
		strWinName = aryURL[1];
	} else {
		strWinName = 'newWin';
	}
	var intX = parseInt((screen.width - intPopUpWidth) / 2);
	var intY = parseInt((screen.height - intPopUpHeight) / 2);
	var strWinAttrib = 	'width=' + intPopUpWidth + ',height=' + intPopUpHeight + ',menubar=no,toolbar=no,scrollbars=no,resizable=no,top=' + intY + ',left=' + intX;
	window.open(strURL, strWinName, strWinAttrib);
}

function OpenScrollablePopUp(strURL, intPopUpWidth, intPopUpHeight) {
	var reURL = /^([^\.\/\\]*)\.[^\.]*$/;
	var strWinName
	if (reURL.test(strURL)) {
		aryURL = reURL.exec(strURL);
		strWinName = aryURL[1];
	} else {
		strWinName = 'newWin';
	}
	var intX = parseInt((screen.width - intPopUpWidth) / 2);
	var intY = parseInt((screen.height - intPopUpHeight) / 2);
	var strWinAttrib = 	'width=' + intPopUpWidth + ',height=' + intPopUpHeight + ',menubar=no,toolbar=no,scrollbars=yes,resizable=no,top=' + intY + ',left=' + intX;
	window.open(strURL, strWinName, strWinAttrib);
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = ("; expires=" + date.toGMTString());
	}
	else var expires = "";
	document.cookie = (name + "=" + value + expires + "; path=/");
}

function readCookie(name) {
	var nameEQ = (name + "=");
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return (c.substring(nameEQ.length, c.length));
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}


function keyPressed(objElement, objEvent) 
{
    var intAsciiCode;
    
    if (objEvent && objEvent.which) 
    {
        intAsciiCode = objEvent.which;
    } 
    else if (window.event) 
    {
        objEvent = window.event;
        intAsciiCode = objEvent.keyCode;
    }
    return intAsciiCode;
}

function enterPressed(objElement, objEvent) 
{
    return (keyPressed(objElement, objEvent) == 13);
}


function Hide(strElementId) 
{
    var objElement = document.getElementById(strElementId);
    if (objElement) 
    {
        objElement.style.display = 'none';
    }
}

function Show(strElementId) 
{
    var objElement = document.getElementById(strElementId);
    if (objElement) 
    {
        objElement.style.display = 'block';
    }
}
