function popNew(strURL) {
	window.open(strURL);
}

function popLogin(strURL) {
	popWin = window.open(strURL, "popWin", "left=200,top=150,width=264,height=199,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,menubar=no");
}

function popHelp(strURL) {
	popWin = window.open(strURL, "popWin", "left=10,top=10,width=300,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
}

function popAvail(strURL) {
	popWin = window.open(strURL, "popWin", "left=5,top=10,width=790,height=550,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
}

function PF() { window.print(); }
function PrintMe() {
    window.print();
    return false;
}

function PFpop() {
	var location = "" + document.location.pathname
	if (location.length < 3)
	{ location = "/"; }
	else
	{ location = "" + document.location; }
	if (location.indexOf("?") == -1)
	{ document.location = location + '?POP=1&Print=1'; }
	else
	{ document.location = location + '&POP=1&Print=1'; }
}

function EMailPage() {
	var location = "" + document.location.pathname
	if (location.length < 3)
	{ location = "/"; }
	else
	{ location = "" + document.location; }
	if (location.indexOf("?") == -1)
	{ document.location = location + '?EMailPage=1'; }
	else
	{ document.location = location + '&EMailPage=1'; }
}
function SamePage(AddToQ, AddToQval) {
	var location = "" + document.location.pathname
	if (location.length < 3)
	{ location = "/"; }
	else
	{ location = "" + document.location; }
	if (location.indexOf("?") == -1) {
		document.location = location + '?' + AddToQ + '=' + AddToQval;
	}
	else {
		var QLoc = location.indexOf("?");
		if (location.indexOf(AddToQ, QLoc) == -1) {
			document.location = location + '&' + AddToQ + '=' + AddToQval;
		}
		else {
			var AddToQLoc = location.indexOf(AddToQ, QLoc);
			var AmpLoc = location.indexOf("&", AddToQLoc);
			if (AmpLoc == -1) {
				if (AddToQLoc - QLoc == 1) {
					document.location = location.substring(0, AddToQLoc - 1) + '?' + AddToQ + '=' + AddToQval;
				}
				else {
					document.location = location.substring(0, AddToQLoc - 1) + '&' + AddToQ + '=' + AddToQval;
				}
			}
			else {
				var eqLoc = location.substring(0, AddToQLoc + AddToQ.length) + AddToQval + location.substring(AmpLoc);
			}
		}
	}
}

function GetRadWindow() {
	var oWindow = null;
	try {
		if (window.radWindow) oWindow = window.radWindow;
		else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
	}
	catch (e) {
		oWindow = null
	}
	return oWindow;
}

function closewindow() {
	//alert('close');
	var oWindow = GetRadWindow();
	if (oWindow != null) {
		oWindow.Close();
	}
	else {
		window.close();
	}
}
var initWidth;
var initHeight;
function ResizeWindowToContent() {
	var oWnd;
	var theTop;
	var theLeft;
	window.setTimeout(
        function() {
            oWnd = GetRadWindow();
            //GetParentWindowProperties(oWnd);
            if (initWidth == null) initWidth = document.body.scrollWidth + 40;
            if (initWidth > 850) initWidth = 850;
            if (initHeight == null) initHeight = document.body.scrollHeight + 90;
            if (initHeight > 800) initHeight = 800;
            oWnd.SetSize(initWidth, initHeight);
            //oWnd.MoveTo((window.top.document.body.clientWidth - initWidth) / 2, 0);
        }, 10);
}

function ResizeWindowToContentNews() {
	var oWnd;
	var theTop;
	var theLeft;
	var Height;
	window.setTimeout(
        function() {
        	oWnd = GetRadWindow();
        	Height = document.body.scrollHeight + 62;
        	if (Height > 800) Height = 800;
        	oWnd.SetSize(540, Height);
        }, 10);

}

function remMe(chkBox) {
	var confirmText = "If you tick this box then you will no longer need to log in\n" +
		"when visiting our site from this computer.\n\n" +
		"You can disable this feature at any time by logging out.\n\n" +
		"Don't use this option unless you are the only person\nwho has access to this computer.\n\n" +
		"WARNING:\n" +
		"If you do decide to use this option you could be exposed to \nsecurity breach by anyone who uses your machine to access this site."

	if (chkBox.checked)
		if (!confirm(confirmText))
		chkBox.checked = false;
}
// For evoRadGrid 
function RowDoubleClick(sender, eventArgs) {
	var UniqueID = eventArgs.getDataKeyValue(teKeyValue);
	if (UniqueID != null) {
		OpenEditForm(UniqueID, 0, 0);
		return false;
	}
}

var WindowWidth = 0;
var WindowHeight = 0;
var WindowScrollX = 0;
var WindowScrollY = 0;

function GetParentWindowProperties(oWnd) {
	if (typeof (oWnd.BrowserWindow.window.innerWidth) == 'number') {
		WindowWidth = oWnd.BrowserWindow.window.innerWidth;
		WindowHeight = oWnd.BrowserWindow.window.innerHeight;
	} else if (oWnd.BrowserWindow.document.documentElement && (oWnd.BrowserWindow.document.documentElement.clientWidth || oWnd.BrowserWindow.document.documentElement.clientHeight)) {
		WindowWidth = oWnd.BrowserWindow.document.documentElement.clientWidth;
		WindowHeight = oWnd.BrowserWindow.document.documentElement.clientHeight;
	} else if (oWnd.BrowserWindow.document.body && (oWnd.BrowserWindow.document.body.scrollWidth || oWnd.BrowserWindow.document.body.scrollHeight)) {
		WindowWidth = oWnd.BrowserWindow.document.body.scrollWidth;
		WindowHeight = oWnd.BrowserWindow.document.body.scrollHeight;
	}
	if (typeof (oWnd.BrowserWindow.window.pageYOffset) == 'number') 
	{
		WindowScrollY = oWnd.BrowserWindow.window.pageYOffset;
		WindowScrollX = oWnd.BrowserWindow.window.pageXOffset;
	} else if (oWnd.BrowserWindow.document.body && (oWnd.BrowserWindow.document.body.scrollLeft || oWnd.BrowserWindow.document.body.scrollTop)) 
	{
		WindowScrollY = oWnd.BrowserWindow.document.body.scrollTop;
		WindowScrollX = oWnd.BrowserWindow.document.body.scrollLeft;
	} else if (oWnd.BrowserWindow.document.documentElement && (oWnd.BrowserWindow.document.documentElement.scrollLeft || oWnd.BrowserWindow.document.documentElement.scrollTop)) 
	{
		WindowScrollY = oWnd.BrowserWindow.document.documentElement.scrollTop;
		WindowScrollX = oWnd.BrowserWindow.document.documentElement.scrollLeft;
	}
}

function GetOriginalWindowProperties() {
	if (typeof (window.innerWidth) == 'number') {
		WindowWidth = window.innerWidth;
		WindowHeight = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		WindowWidth = document.documentElement.clientWidth;
		WindowHeight = document.documentElement.clientHeight;
	} else if (document.body && (document.body.scrollWidth || document.body.scrollHeight)) {
		WindowWidth = document.body.scrollWidth;
		WindowHeight = document.body.scrollHeight;
	}

	if (typeof (window.pageYOffset) == 'number') {
		WindowScrollY = window.pageYOffset;
		WindowScrollX = window.pageXOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		WindowScrollY = document.body.scrollTop;
		WindowScrollX = document.body.scrollLeft;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		WindowScrollY = document.documentElement.scrollTop;
		WindowScrollX = document.documentElement.scrollLeft;
	}
}

function OpenEditForm(KeyID1, KeyID2, KeyID3, KeyID4, KeyID5, KeyCopyID) {
	var URLToAppend = "";
	if (KeyID1 != undefined) { URLToAppend += '&KeyID1=' + KeyID1; }
	if (KeyID2 != undefined) { URLToAppend += '&KeyID2=' + KeyID2; }
	if (KeyID3 != undefined) { URLToAppend += '&KeyID3=' + KeyID3; }
	if (KeyID4 != undefined) { URLToAppend += '&KeyID4=' + KeyID4; }
	if (KeyID5 != undefined) { URLToAppend += '&KeyID5=' + KeyID5; }
	var oWindow = window.radopen(teURL + URLToAppend, teTitle);
    oWindow.set_title(teTitle);
    return false;
}

function OpenEditFormExtended(ControlID, NoSave, KeyID1, KeyID2, KeyID3, KeyID4, KeyID5, KeyCopyID) {
	var URLToAppend = "";
	if (ControlID != undefined) { URLToAppend += ControlID; }
	if (NoSave != undefined) { URLToAppend += '&NoSave=' + NoSave; }
	if (KeyID1 != undefined) { URLToAppend += '&KeyID1=' + KeyID1; }
	if (KeyID2 != undefined) { URLToAppend += '&KeyID2=' + KeyID2; }
	if (KeyID3 != undefined) { URLToAppend += '&KeyID3=' + KeyID3; }
	if (KeyID4 != undefined) { URLToAppend += '&KeyID4=' + KeyID4; }
	if (KeyID5 != undefined) { URLToAppend += '&KeyID5=' + KeyID5; }
	var oWindow = window.radopen(URL + URLToAppend, teTitle);
	oWindow.set_title(teTitle);
	return false;
}

function RefreshGrid(arg) {
	if (arg == null)
	{ __doPostBack(teGrid, "CloseAndRebind"); }
	else
	{ __doPostBack(teGrid, arg); };
}

var expand = false;
function ExpColap() {
	var masterview = $find(teMaster);
	var count = masterview.get_dataItems().length;
	if (expand == false)
		expand = true;
	else
		expand = false;

	for (var i = 0; i < count; i++) {
		var mtvItem = masterview.get_dataItems()[i];
		if (mtvItem != null) {
			mtvItem.set_expanded(expand)
		}
	}
}
// Image transition
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}
function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	var currentOpac = 100;
	var newOpac = 0;
	if (document.getElementById(imageid).style.opacity < 100) {
		currentOpac = document.getElementById(imageid).style.opacity * 100;
	}
	if (currentOpac > 50) {
		document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";}
	else{
		newOpac = currentOpac;
	}
	changeOpac(newOpac, imageid);
	document.getElementById(imageid).src = imagefile;
	for (i = newOpac; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')", (timer * speed));
		timer++;
	}
}
function currentOpac(id, opacEnd, millisec) {
	var currentOpac = 100;
	if (document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}
	opacity(id, currentOpac, opacEnd, millisec)
}

function OnLoad(sender, eventArgs) {
	var panelBar = sender;
	var allItems = panelBar.get_allItems();
	for (var i = 0; i < allItems.length; i++) {
		var panelItem = allItems[i];
		var imageElement = panelItem.get_imageElement();
		if (imageElement) {
			imageElement.AssociatedItem = panelItem;
			imageElement.onclick = function(e) {
				if (!e) e = window.event;
				if (this.AssociatedItem.get_expanded()) {
					this.AssociatedItem.collapse();
				}
				else {
					this.AssociatedItem.expand();
				}
				e.cancelBubble = true;
				if (e.stopPropagation) {
					e.stopPropagation();
				}
				return false;
			}
		}
	}
}