/* /== NetReach Copyright Block ==\
   Copyright 2009, Bastnet, Inc.
   All of the information contained herein is the intellectual property of Bastnet, Inc.  
   No portion of the tools, routines, subroutines and other programs, data and/or materials 
   may be used by any other organization without the express written consent of NetReach, 
   Inc.  Any organization that attempts to reuse any portion of these materials without 
   consent will be prosecuted to the fullest extent allowed by law. 
   \== NetReach Copyright Block ==/ */

// Now used for other things than just rollover, in future should probably be renamed.
$(document).ready(function () {
    if (typeof (Sys) != 'undefined' && Sys.WebForms && Sys.WebForms.PageRequestManager) {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        if (prm) {
            var oldAction = $('#aspnetForm').attr('action');
            prm.add_endRequest(function (sender, args) {
                if (args.get_error()) {
                    var msg = args.get_error().message;
                    alert(msg.substring(msg.indexOf(':') + 1));
                }
                $('#aspnetForm').attr('action', oldAction);
            });
        }
    }
});

// Image Swap and Preload Functions
function newImage(arg) {
	if (document.getElementById) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (preloadFlag) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document.getElementById(changeImages.arguments[i]).src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
var preloads = new Array();
function cmsInitialize() {
	if (document.getElementById) {
		for (var i = 0; i < preloads.length; i++) {
			newImage(preloads[i]);
		}
		preloadFlag = true;
	}
	var hidx = document.getElementById('ScrollX');
	var hidy = document.getElementById('ScrollY');
	var hidRefresh = document.getElementById('isRefresh');
	if (hidx != null && hidy != null) {
		if ((hidx.value != '' || hidy.value != '') && hidRefresh.value == '') {
			window.scrollTo(hidx.value, hidy.value);
		}
		setInterval(cmsSaveScrollXY, 1000);
	}
	if (hidRefresh != null) {
		hidRefresh.value = true;
    }
    if (document.getElementById("nrLoadingDiv")) document.getElementById("nrLoadingDiv").style.display = 'none';
}
function cmsSaveScrollXY() {
	document.getElementById('ScrollX').value = document.documentElement.scrollLeft;
	document.getElementById('ScrollY').value = document.documentElement.scrollTop;
}


var popWin = null;
function popUp(URL, width, height) {
	if (popWin != null && !popWin.closed)
	   popWin.close();
	var strOptions = "";
	strOptions = "width=" + width + ",height=" + height + ",scrollbars=yes,resizable=yes";
	popWin = window.open(URL, 'popWin', strOptions);
	popWin.focus();
}

function CheckEnterPressedInTextBox(e, btnId) {
    var btn = document.getElementById(btnId);
    e = (e) ? e : (window.event) ? event : null;
    if (btn != null && e) {
        var charCode = (e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode : ((e.which) ? e.which : 0));
        if (charCode == 13) {
            var form = document.forms[0];
            var oldSubmit = form.onsubmit;
            form.onsubmit = function() { return false; }
            setTimeout(function() {
                form.onsubmit = oldSubmit;
                if (btn.click) {
                    btn.click();
                } else if (btn.href) {
                    var evt = document.createEvent('MouseEvents');
                    evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
                    if (btn.dispatchEvent(evt)) {
                        window.location = btn.href;
                    }
                }
            }, 25);
            return true;
        }
    }
    return true;
}


;if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
