function copyDocument(refUNID) {
	var agenthref = strLeft(document.location.href, ".nsf") + ".nsf/CopyDocument?OpenAgent&refunid=" + refUNID;	
	location.href = agenthref;
}

function repositDocument(refUNID) {
	var agenthref = strLeft(document.location.href, ".nsf") + ".nsf/RepositDocument?OpenAgent&refunid=" + refUNID;
	location.href = agenthref;
}

function deleteDocument(refUNID) {
	var agenthref = strLeft(document.location.href, ".nsf") + ".nsf/DeleteDocument?OpenAgent&refunid=" + refUNID;
	location.href = agenthref;
}

function repositDocumentFromIndex(refUNID) {
	var agenthref = strLeft(document.location.href, ".nsf") + ".nsf/RepositDocument?OpenAgent&refunid=" + refUNID + "&fromindex";
	location.href = agenthref;
}

function deleteDocumentFromIndex(refUNID) {
	var agenthref = strLeft(document.location.href, ".nsf") + ".nsf/DeleteDocument?OpenAgent&refunid=" + refUNID + "&fromindex";
	location.href = agenthref;
}
function repositDocumentConfirmed(refUNID) {
	 showConfirm(clubName, labelConfirmationReposit, labelYes, 'javascript:repositDocumentFromIndex(\'' + refUNID + '\')', labelNo, '', 'Question');	 
}

function deleteDocumentConfirmed(refUNID) {
	 showConfirm(clubName, labelConfirmationDeletion, labelYes, 'javascript:deleteDocumentFromIndex(\'' + refUNID + '\')', labelNo, '', 'Question');	 
}





//Ajax 
var xmlHttp = null;
function createXMLHttpRequest() { 
	if (xmlHttp) xmlHttp.abort();
	xmlHttp = null;
	/*if (window.ActiveXObject) { 	
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
	else if (window.XMLHttpRequest) { 
		
		xmlHttp = new XMLHttpRequest(); 
	}
	
	var req = false;*/
  	
	if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
		
		if(xmlHttp.overrideMimeType){ xmlHttp.overrideMimeType('text/xml'); }
	} 
	else if(window.ActiveXObject){
		try{ xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e){
			try{ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e){}
		}
	}
}



function getCachePrevent()
{
    return "&rand=" + escape( Math.round( Math.random() * 10000 ) );
}


function getCachePreventTime() {
	 var now = new Date();
	return "&rand=" + now.getTime() + escape( Math.round( Math.random() * 10000 ) );
}



/* Edit History */
var divEH;
function showEditHistory(event, unid) {
	if (divEH) closeEditHistory();

	divEH = document.createElement("div");
	divEH.id = "editHistory";
	
	if (!event) var event = window.event;	
	divEH.style.top = (event.clientY + 10) + "px";
	divEH.style.zIndex = "10001";
	
	divEH.onmouseover = stopEditHistoryCloseTimer;
	divEH.onmouseout = startEditHistoryCloseTimer;
	
	divEH.innerHTML = '<img src="../../Script/' + strLeftBack(strLeftBack(strLeft(window.location.href, ".nsf"), "/"), "/") + '/pc_admin.nsf/ani-busy.gif" alt="...">';
	
	document.body.appendChild(divEH);
	
	divEH.style.visibility = "visible";
		
	var url = strLeft(window.location.href, ".nsf") + ".nsf/webcontentedithistory/" + unid + "?OpenDocument";
	prepareShowEditHistory(url + getCachePreventTime());
}


function prepareShowEditHistory(sUrl) {
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = showEditHistoryContent;
	xmlHttp.open("GET", sUrl, true);
	xmlHttp.send(null);
}

function showEditHistoryContent() {

	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {        
			var s = xmlHttp.responseText;			
			//s = strRight(xmlHttp.responseText, "<?xml version=\"1.0\"?>");
			//s = replStr(s, "<?xml version=\"1.0\"?>", "");
			s = replStr(s, "<content>", "");
	          s = replStr(s, "</content>", "");
	            
	           //var elemAjax = document.getElementById("editHistory");             
			//elemAjax.innerHTML = s;                 
			divEH.innerHTML = s;                 
		}
		else {
			alert("Can't retrieve XML: " + xmlHttp.statusText);
		}
		startEditHistoryCloseTimer();
	}
}


var activeEditHistory;

//is called when cursor enters edit history
function stopEditHistoryCloseTimer() {
	if(activeEditHistory) clearTimeout(activeEditHistory);
}
//is called when cursor exits edit history
function startEditHistoryCloseTimer() {
	var timeout = 1000;
	if(activeEditHistory) clearTimeout(activeEditHistory);
	activeEditHistory = setTimeout("closeEditHistory()", timeout);			
}


function closeEditHistory() {		
	if (divEH) {
		divEH.innerHTML = "";
		divEH.style.visibility = "hidden";
		delete divEH;
		divEH = null;	
	}
}
