
function NewWindow(sUrl, sTitle, sWidth, sHeight, sScrollable) 
{
	var iLeft = (screen.width - sWidth) / 2;
	var iTop = (screen.height - sHeight) / 2;

	var oNewWindow = window.open(sUrl, sTitle, 'height='+sHeight+',width='+sWidth+',top='+iTop+',left='+iLeft+',scrollbars='+sScrollable+',resizable=yes');

	if (oNewWindow && oNewWindow.open && !oNewWindow.closed)
	{
		oNewWindow.window.focus();
	}
	return oNewWindow;
}

var oPoppedWindow = null;

function ClosePoppedWindows()
{
	if (oPoppedWindow && oPoppedWindow.open && !oPoppedWindow.closed)
	{
		oPoppedWindow.close();
	}
}

function ForgotPassword()
{
	oPoppedWindow = NewWindow("ForgotPassword.aspx",'_X_X_X_X_record_dep',450,300,"no");
}

function AmIRegistered()
{
	oPoppedWindow = NewWindow("AmISubscribed.aspx",'_X_X_X_X_record_dep',450,300,"no");
}


function change_page(number)
{
	new_search('start', number);
}

function change_search(text)
{
	new_search('q', text);
}

function change_group(text)
{
	new_search('search', text);
}

function new_search(name, value)
{
	var search = document.location.search;

	search = remove_keys(search, 'page_number');
	search = remove_keys(search, 'start');
	search = remove_keys(search, name);
	
	search = add_key(search, name, value);

	document.location.search = search;
}

function add_key(string, name, value)
{
	value = new String(value);
	
	if (value.length > 0)
	{
		if (string.indexOf('?') < (string.length - 1))
		{
			string = string + '&';
		}

		string = string + name + '=' + value;
	}
	
	return (string);
}

function remove_keys(string, name)
{
	if (name.length > 0)
	{
		name = name + '=';
		
		string = new String(string);
		
		var start = string.indexOf(name);

		while(start > -1)
		{
			var temp = string.substring(0, start);

			var end = string.indexOf('&', start);

			if (end > -1)
			{
				temp = temp + string.substr(end + 1);
			}
			else
			{
				if (temp.charAt(temp.length - 1) == '&')
				{
					temp = temp.substring(0, temp.length - 1);
				}
			}

			string = temp;

			start = string.indexOf(name);
		}
	}
	
	return (string);
}

function ContentEditor(sIdContent, sPage, sCode, iSortOrder)
{
	if (isNaN(iSortOrder))
		iSortOrder = 100;
		
	sQuery = '?';
	if (sIdContent != null)
		sQuery += 'id_content=' + sIdContent + '&';
	sQuery += 'page=' + sPage + '&code=' + sCode + '&sort_order=' + iSortOrder;
	
	var sUrlNoProt = document.location.href.substring(document.location.protocol.length + 2);
	var aUrl = sUrlNoProt.split('/');
	
	var sBase = document.location.protocol + "//" + document.location.host;
	if (sBase.indexOf('localhost') > -1)
	    sBase += '/' + aUrl[1];
	    
	oPoppedWindow = NewWindow(sBase + "/Utility/ContentEditor.aspx" + sQuery,'content_editor','725','600','yes');
}
