function disableCtrlN()
{
	var pressedKey = event.keyCode;
	if ( (78 == pressedKey) && (event.ctrlKey) ) 
	{
		if(window.document.title.indexOf("Secure") == -1)
		{
			openNewWindow();
		}
		return false;
	}
}

//function disableF11() {
//    if (122 == event.keyCode) {
//        event.keyCode = 0;
//        return false;
//    }
//}

// Traps the F11 keypress to disable IE full screen mode.
function disableF11(event) {

    var key = event.charCode ? event.charCode : event.keyCode ? event.keyCode : 0;
    
	if (key==122)
	{
		key = 0;
		return false;
	}
}

var parentWin = null;

function GetParent()
{
	var counter = 0;
	
	if (parentWin == null || parentWin.Main_Body == null)
	{
		parentWin = window;
		while (parentWin.parent != null)
		{
		if (parentWin.Main_Body != null || counter > 10)
		break;                  
		counter = counter + 1;
		parentWin = parentWin.parent;
		}
	}
	return parentWin;
}

function trapF5(event) {

    var key = event.charCode ? event.charCode : event.keyCode ? event.keyCode : 0;
    
	if (key==116)
	{
		key = 0;
		var doc = GetParent();

		if (doc.Main_Body != null)
		{
			doc.Main_Body.location.reload(true);
		}
		return false;
	}     
}

function openNewWindow()
{
	var popUpContent = "Menu.aspx?hidMLS=" + MyMLSID;
	if (typeof(window[ 'LoginDomain' ]) != "undefined") 
	{
		popUpContent = LoginDomain + popUpContent;
	}
	
	var winName = "new_window";
	var currentDate = new Date()
	winName += currentDate.getHours();
	winName += currentDate.getMinutes();
	winName += currentDate.getSeconds();
	winName += currentDate.getMilliseconds();
	
	var properties = "status=yes,toolbar=yes,location=yes,menubar=yes,width=650,height=500,resizable=yes"
	window.open(popUpContent,winName,properties);
}

function keypressEvents()
{
	try
	{
		var isClientPortal = parent.parent.parent.document.forms[0].id == 'frmClientPortal';
		
		if(!isClientPortal)
		{
			attachKeypressEvents();
		}
	}
	catch(e)
	{
		attachKeypressEvents();
	}
}

function attachKeypressEvents() 
{
    mlsAttachEvent(document, "keydown", disableF11, null);
    mlsAttachEvent(document, "keydown", trapF5, null);    
}

function AddAspxURLParam(URL, paramName, paramValue)
{
	if (URL.indexOf('.aspx') != -1)
	{
		if (URL.indexOf('.aspx?') != -1)
		{
			URL = URL + '&' + paramName + '=' + paramValue;
		}
		else
		{
			URL = URL + '?' + paramName + '=' + paramValue;
		}
	}
	
	return URL;
}

keypressEvents();

//Cross Browser AttachEvent
//Call like this AttachEvent(window, 'load', AddPageButtons)
//Note the omitted 'on' from the evt string parameter
var LITERAL_BOOL_TRUE = true;
var LITERAL_BOOL_FALSE = false;
var LITERAL_ON = "on";
function mlsAttachEvent(obj, evt, func, useCap) {

    var returnValue;

    if (!useCap) {
        useCap = LITERAL_BOOL_FALSE;
    } //if (!useCap)
    if (obj.addEventListener) {
        obj.addEventListener(evt, func, useCap)
        returnValue = LITERAL_BOOL_TRUE;
    } //if (obj.addEventListener)
    else if (obj.attachEvent) {
        returnValue = obj.attachEvent(LITERAL_ON + evt, func);
    } //if (obj.attachEvent)

    return returnValue;
}