/* Cookies */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function OpenOverlay(url,w,h) {
	var wnd = window.radopen(url, 'RadWindow');
	wnd.SetTitle("New title");
	wnd.setSize(w,h);
	wnd.center();
	wnd.SetModal(true);
}

function OpenOverlayWithTitle(url,w,h,title) {
	var wnd = window.radopen(url, 'RadWindow');
	wnd.SetTitle(title);
	wnd.setSize(w,h);
	wnd.center();
	wnd.SetModal(true);
}

function CallBackFunction(radWindow, returnValue) {
	if (returnValue) window.location.reload();
}

// Open an overlay window in the front end
function FEOpenOverlay(url,title,w,h) {
	var id = title.replace(/\s/g,'-').toLowerCase();
	var iframe = document.createElement("iframe");

	// Setup iframe
	iframe.src = url;
	iframe.setAttribute('frameborder',0);
	iframe.setAttribute('border',0);
	iframe.setAttribute('name',id);
	iframe.setAttribute('id',id);
	iframe.setAttribute('width',w);
	iframe.setAttribute('height',h-73-31);
	
	// Setup dialog
	$("body").append($(iframe));

	$(iframe).dialog({
		title: title,
		autoOpen: false,
		modal: true,
		width: w,
		height: h,
		overlay: {
			background: "#000",
			opacity: 0.2
		}
	});
	
	$(iframe).dialog("open");
}

/* not sure what these are but if removed they cause error
backGroundDiv - I'm not sure what this is? */
function f1() {
    var div=document.getElementById('backGroundDiv');
    if (div == null)
        return false; 
    div.className="Popup_BackGround";
}

function f2() {
    var div=document.getElementById('backGroundDiv');
    if (div == null)
        return false;
    div.className="";
}