function openPopup(url,width,height,id)
{
	if (id == null) {
		id = '';
	}
	
	var left   = (screen.width  - width)/2;
	var top    = (screen.height - height)/2;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=no';
	params += ', scrollbars=no';
	params += ', status=no';
	params += ', toolbar=no';
	
	if (typeof popupwin == 'undefined') {
		popupwin=new Array();
	}
	
	popupwin['popup'+id]=window.open(url, 'popup'+id, params);
	popupwin['popup'+id].focus();
	
	return true;
}

trigger_old_new_title = false;
timerId = false;

function flashTitle(newTitle, oldTitle) {
	timerId = setInterval('flashDo(newTitle, oldTitle)', 2000);
	
	return true;
}

function flashDo(newTitle, oldTitle) {
	if (trigger_old_new_title) 
		document.title = oldTitle;
	else
		document.title = newTitle;
		
	trigger_old_new_title = !trigger_old_new_title;
}

function clearFlash(oldTitle) {
	if (timerId) {
		clearInterval(timerId);
		document.title = oldTitle;
	}
	
	return false;
}

function CheckSecurityPolicy(rplFullUrl, pageHost)
{
	/* Allow to access one subdomain from another (eg. access api.site.com from my.site.com) */
	// Validate realplexor URL.
	if (!rplFullUrl.match(/^\w+:\/\/([^/]+)/)) {
		throw 'Dklab_Realplexor constructor argument must be fully-qualified URL, ' + rplFullUrl + ' given.';
	}
	var mHost = RegExp.$1;
	//allow access from one subdomain to another
	if (pageHost.slice(pageHost.indexOf('.')+1)==mHost.slice(mHost.indexOf('.')+1))
		pageHost=pageHost.slice(pageHost.indexOf('.')+1);
	/*  */
	if (mHost != pageHost && mHost.lastIndexOf("." + pageHost) != mHost.length - pageHost.length - 1) {
		throw 'Due to the standard XMLHttpRequest security policy, hostname in URL passed to Dklab_Realplexor (' + mHost + ') must be equals to the current host (' + pageHost + ') or be its direct sub-domain.';
	}
	
	return pageHost;
}

