function pageInit(p)
	{
	if(p=="Coll")
		{
		//YAHOO.util.Event.addListener(document.body, "beforeunload", checkLeave);
		loadCont();
		if((own=="true")||(betaMode)) { YAHOO.util.Event.addListener("collForm","submit",saveChanges); }
		var inps = YAHOO.util.Dom.getElementsByClassName("collEdit");
		for(var i=0; i<inps.length; i++)
			{
			YAHOO.util.Event.addListener(inps[i],"blur",blurInp);
			YAHOO.util.Event.addListener(inps[i],"focus",focusInp);
			YAHOO.util.Event.addListener(inps[i],"keyup",changeInp);
			};
		var inps = YAHOO.util.Dom.getElementsByClassName("collRadio");
		for(var i=0; i<inps.length; i++)
			{
			YAHOO.util.Event.addListener(inps[i],"click",changeInp);
			YAHOO.util.Event.addListener(inps[i],"keyup",changeInp);
			};
		}
//	var inps = YAHOO.util.Dom.getElementsByClassName("collBlank");
//	for(var i=0; i<inps.length; i++)
//		{ inps[i].style.height = inps[i].scrollheight+"px"; }
	var u = document.getElementById("urlEdit");
	if(u&&u.select) u.select();
	
	}

function blurInp(e,o)
	{
	this.className = "collEdit collEditOff";
	}

function focusInp(e,o)
	{
	this.className = "collEdit collEditOn";
	}

function changeInp(e,o)
	{
	changed = true;
	document.getElementById("submitBtn").disabled = false;
	}

function loadCont()
	{
	var collCont = document.getElementById("collDispCont");
	var collForm = document.getElementById("collForm");
	if(!collForm) { throw "Collection contents form is not available"; return(false); }
	YAHOO.util.Connect.setForm(collForm);
	var myCollCallback =
			{ 
			success: function(o) {
				collCont.innerHTML = o.responseText;
				},
			failure: function(o) {
				var collTxt = 'Retreival of collection contents failed with a status of '+o.status+': '+o.statusText+
					'. Please refresh the page to try again. If this error continues, and you are sure you are using a browser '+
					' supported by this site, please contact support and note this message.';
				collCont.innerHTML = collTxt;
				},
			timeout: 20000
			}
	var cObj = YAHOO.util.Connect.asyncRequest('POST', "../ajax/ajax_get_collcont.asp", myCollCallback);
	}

function copyClip(text2copy)
	{
	if (window.clipboardData)
		{
		window.clipboardData.setData("Text",text2copy);
		return(true);
 		};
 	var flashcopier = 'flashcopier';
	if(!document.getElementById(flashcopier))
		{
		var divholder = document.createElement('div');
		divholder.id = flashcopier;
		document.body.appendChild(divholder);
		}
	document.getElementById(flashcopier).innerHTML = '';
	var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
	document.getElementById(flashcopier).innerHTML = divinfo;
	return(true);
 	}
	
function copyUrl()
	{
	var u = document.getElementById("urlEdit");
	if(copyClip(u.value))
		{ alert("The Learner URL has been copied to your clipboard") }
		else
		{ alert("Sorry, your browser settings do not allow copying to the clipboard. Please right-click within the text box and select copy from the drop-down menu instead.") }
	}

var collDiag;
var dlDiag;
var changed = false;

function checkLeave(ev)
	{
	if(changed&&!confirm('Any changes you have made since pressing the "Submit Changes" button will be lost. Are you sure you wish to proceed?'))
		{
		YAHOO.util.Event.stopEvent(ev);
		}
	}

function editCollConts()
	{
	var pCfg = {
		close:false,  
		draggable:false,
		fixedcenter:true,
		constraintoviewport:true,
		underlay:"shadow",
		modal:true,
		visible:false,
		width: "750px",
		height: "500px",
		zIndex: 1000,
		appendtodocumentbody: true
		};
	collDiag = false;
	collDiag = new YAHOO.widget.Panel("collEditPanel", pCfg);
	collDiag.setHeader('Editing collection contents');
	var iF = document.createElement("IFRAME");
	iF.style.width = "100%";
	iF.style.height = "100%";
	iF.src = "/pops/editColl.asp?collId="+loid;
	collDiag.setBody(iF);
	collDiag.setFooter("Unchanged");
	collDiag.render(document.body);
	var srcCell = document.getElementById("collDispCell");
	collDiag.subscribe("hide",function() { flyFrom(collDiag.element,srcCell); window.setTimeout(function(){collDiag.destroy();},2000) });
	flyFrom(srcCell,collDiag.element,function(){collDiag.show()});
	}
	
function getCollConts()
	{
	return(document.getElementById("collCont").value);
	}
	
function saveCont(stat,mess,cont)
	{
	collDiag.setFooter(mess);
	contStat = stat;
	if(cont)
		{
		document.getElementById("collCont").value = cont; 
		if(contStat) loadCont();
		changeInp();
		}
	return(true);
	};
	
function delColl()
	{
	return(confirm("Are you sure you wish to delete this collection? This cannot be undone."));	
	}
	
function dlColl(loid,defTar,viz)
	{
	if(changed&&!confirm('Any changes you have made since pressing the "Submit Changes" button will not be reflected in the download. Are you sure you wish to proceed?'))
		{ return false; }
	var pCfg = {
		close:true,
		draggable:false,
		fixedcenter:true,
		constraintoviewport:true,
		underlay:"shadow",
		modal:true,
		visible:false,
		width: "500px",
		height: "400px",
		zIndex: 1000,
		appendtodocumentbody: true
		};
	dlDiag = new YAHOO.widget.Panel("collDownloadPanel", pCfg);
	dlDiag.setHeader('Downloading collection');
	var iF = document.createElement("IFRAME");
	iF.style.width = "100%";
	iF.style.height = "100%";
	var du = "/pops/dlColl2.asp?collId="+loid;
	if(viz&&(viz=="permanent")) du="/pops/dlColl3.asp?collId="+loid+"&viz="+viz;
	if(defTar) du+="&defTar="+defTar;
	iF.src = du;
	dlDiag.setBody(iF);
	dlDiag.setFooter("");
	dlDiag.render(document.body);
	var srcCell = document.getElementById("dlCollCell");
	dlDiag.subscribe("hide",function() { flyFrom(dlDiag.element,srcCell); window.setTimeout(function(){dlDiag.destroy();},2000) });
	flyFrom(srcCell,dlDiag.element,function(){dlDiag.show()});
	return false
	}
	
function saveChanges(ev)
	{
	//alert('Sorry, saving changes is not currently available');
	changed = false;
	var subBtn = document.getElementById("submitBtn");
	if(!subBtn) return(false);
	subBtn.disabled = true;
	var collInfo = document.getElementById("collInfo");
	collInfo.innerHTML = '<p ><img src="imin/ani-busy.gif" />Saving changes</p>';
	YAHOO.util.Connect.setForm(document.getElementById("collForm"));
	var myCollCallback =
			{ 
			success: function(o) {
				collInfo = document.getElementById("collInfo");
				collInfo.innerHTML = '<p class="info">'+o.responseText+'</p>';
				},
			failure: function(o) {
				collInfo = document.getElementById("collInfo");
				var collTxt = 'Updating of collection failed with a status of '+o.status+': '+o.statusText+
					'. Please try again. If this error continues, and you are sure you are using a browser '+
					' supported by this site, please contact support and note the above message.';
				collInfo.innerHTML = '<p class="info">'+collTxt+'</p>';
				subBtn.disabled = false;
				},
			timeout: 20000
			}
	var cObj = YAHOO.util.Connect.asyncRequest('POST', "../ajax/ajax_update_coll.asp", myCollCallback);
	YAHOO.util.Event.stopEvent(ev);
	return false;
	}
