var _popup;

function openPopup(url, width, height, top, left)
{
	if(typeof(_popup) != 'undefined' && typeof(_popup.close()) != 'undefined')
	{
		_popup.close();
	}
		
	var popupWidth = typeof(width) != 'undefined' ? width : 620;
	var popupHeight = typeof(height) != 'undefined' ? height : 530;
	
	var top = typeof(top) != 'undefined' ? top : 20;
	var left = typeof(left) != 'undefined' ? left : 20;
	
	var features = 'scrollbars=0,modal=no,directories=0,menubar=0,titlebar=0,toolbar=0,width=' + popupWidth + ',height=' + popupHeight + ',top=' + top + ',left=' + left;
	
	_popup = openWindow(url, features);
	
	return _popup;
}

function openWindow(url, features)
{
	if(typeof features == 'undefined')
		features = 'scrollbars=1,modal=no,directories=0,menubar=0,titlebar=0,toolbar=0,width=800,height=500,top=20,left=20';
	
	return window.open(url, 'MLP', features);
}

function openCopyPreview(url)
{
	if(typeof(_popup) != 'undefined' && typeof(_popup.close()) != 'undefined')
	{
		_popup.close();
	}
	
	_popup = openWindow(url);
	
	return _popup;
}

// generic element getter
function getElement(id)
{
	// TODO - generic browser impl
	return document.getElementById(id);
}

/* cookie functions */
function getCookie(strCName){
	var strCookie=document.cookie;
	strCName = escape(strCName);
	var strCValue;
	var iStart=strCookie.indexOf(" " + strCName + "=");
	if(iStart==-1)
		{iStart=strCookie.indexOf(strCName + "=");}
	if(iStart==-1)
		{strCValue=null;}
	else{
		iStart=strCookie.indexOf("=",iStart)+1;
		var iEnd=strCookie.indexOf(";",iStart);
		if(iEnd==-1)
			{iEnd=strCookie.length;}
		strCValue=strCookie.substring(iStart,iEnd);
	}
	return unescape(strCValue);
}

function setCookie(strCName,strCValue,strCPath,dLife){
	
	if(document.cookie.length<=7300){
	
		if(typeof strCPath == 'undefined')
			strCPath = "/";
	
		if(typeof dLife == 'undefined')
			dLife = 1000;
	
		var ddate=new Date();
		ddate.setDate(ddate.getDate()+eval(dLife));
		dCExpires=ddate.toGMTString();
		document.cookie=escape(strCName)+"="+escape(strCValue)+";expires="+dCExpires+";Path="+strCPath+";";
	}
}

