var URL, pSC;

function aj_desk(pid, UR, step){
	URL = UR;
	
	if (step == 1){
		document.getElementById("ajDesk" + pid + "_a").innerHTML = "<a class='sm' href='javascript:aj_desk(" + '"'+ pid + '", "' + URL + '", 0' + ");'>открыть</a>";
		document.getElementById("ajDesk" + pid).style.display = "none";
		return;
	}

	if (document.getElementById("ajDesk" + pid).innerHTML != ""){
		document.getElementById("ajDesk" + pid).style.display = "block";
		document.getElementById("ajDesk" + pid + "_a").innerHTML = "<a class='sm' href='javascript:aj_desk(" + '"'+ pid + '", "' + URL + '", 1' + ");'>скрыть</a>";
		return;
	}
	
	pSC = pid;
	if(window.XMLHttpRequest){
		r_ajdesk = new XMLHttpRequest();
		r_ajdesk.onreadystatechange = pSC_ajdesk;
		r_ajdesk.open("GET", "/ajax/desk" + pid + ".php?p=" + URL, true);
		r_ajdesk.send(null);
	} else if (window.ActiveXObject) {
		r_ajdesk = new ActiveXObject("Microsoft.XMLHTTP");
		if (r_ajdesk) {
			r_ajdesk.onreadystatechange = pSC_ajdesk;
			r_ajdesk.open("GET", URL, true);
			r_ajdesk.send();
		}
	}	
}
function pSC_ajdesk(){
	if (r_ajdesk.readyState == 4){
		if (r_ajdesk.status == 200){
			document.getElementById("ajDesk" + pSC).style.display = "block";
			document.getElementById("ajDesk" + pSC).innerHTML = r_ajdesk.responseText;
			document.getElementById("ajDesk" + pSC + "_a").innerHTML = "<a class='sm' href='javascript:aj_desk(" + '"'+ pSC + '", "' + URL + '", 1' + ");'>скрыть</a>";
		}else{
			document.getElementById("ajDesk" + pSC).style.display = "none";
		}
	}
}
