/*
This function can be used to add unlimited window.onload events.
*/
function addLoadEvent(func) {
    var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

/*
This function is used to disable the form to help prevent 
double submits.

Usage: 
<form onsubmit="submitAndDisableForm(this);return void;">
*/
function submitAndDisableForm(form)
{
    form.submit();
    var elements = form.elements();
    for(var i=0;i<elements.length;i++) {
        elements[i].disabled=true;
    }
}

/*
This function can be used to disable the "Enter" key for 
stricter control over forms.
Usage:
document.onkeypress = disableEnterKey;
*/
function disableEnterKey(e)
{
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}

function popupImage(image, title, alt)
{
	img = new Image();
	img.src = image;

    lPos = (screen.width) ? (screen.width-img.width+50)/2 : 0;
	tPos = (screen.height) ? (screen.height-img.height+100)/2 : 0;
	title = title ? title:'Image Popup';
	alt = alt ? alt:'';

	popup = this.open('', '_blank', "toolbar=no,width="+(img.width+50)+",height="+(img.height+100)+",left="+lPos+",top="+tPos+",directories=no,status=no,scrollbars=no,resize=no,menubar=no");

	popup.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">\n');
	popup.document.write('<html xmlns="http://www.w3.org/1999/xhtml">\n');
	popup.document.write('<head>\n');
	popup.document.write('<title>'+title+'</title>\n');
	popup.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\n');
	popup.document.write('<style type="text/css">\n');
	popup.document.write('body { margin: 0px; background-color: #aaa; }\n');
	popup.document.write('a { text-decoration: none; font: normal 10px Arial, Helvetica, sans-serif}\n');
	popup.document.write('img { border: 1px solid #000; }\n');
	popup.document.write('.description { font: normal 12px Arial, Helvetica, sans-serif; color: #000000; line-height: 20px; text-align:center; }\n');
	popup.document.write('.title { font: bold 12px Arial, Helvetica, sans-serif; color: #000000; text-align: center; }\n');
	popup.document.write('.navigation { text-align:center; }\n');
	popup.document.write('</style>\n');
	popup.document.write('</head>\n');
	popup.document.write('<body>\n');
	popup.document.write('<table cellspacing="0" cellpadding="10" style="text-align:center; height:100%; width:100%; border: 0">\n');
	popup.document.write('<tr><td align="center" class="title">'+title+'</td></tr>\n');
	popup.document.write('<tr><td align="center" class="description"><img src="'+image+'" alt="'+alt+'" /></td></tr>\n');
	popup.document.write('<tr><td align="center" class="navigation"><a href="javascript:window.close();">Close Window</a></td></tr>\n');
	popup.document.write('</table>\n');
	popup.document.write('</body>\n');
	popup.document.write('</html>');

	popup.document.close();
	popup.focus();
}
