var xmlHttp;

function showHide(el)	{
	if(document.getElementById(el).style.display == 'none')	{
		document.getElementById(el).style.display = 'block';
		document.getElementById(el).style.display = 'table-row';
	}
	else
		document.getElementById(el).style.display = 'none';
}

function showSm(parentObj,el,e)	{
	prev = document.getElementById('visible').value;
	if(prev && prev!=el)
		document.getElementById(prev).style.visibility = 'hidden';
	if(el!='')	{
		var str=document.getElementById(el).innerHTML;
		if(str.replace('\n','')!='')	{
			if(e && document.getElementById(el).style.visibility != 'visible' && parentObj!='') {
				document.getElementById(el).style.top = (findPosY(parentObj)-4)+'px';
				document.getElementById(el).style.left = ((document.body.clientWidth/2)-310)+'px';
			}
			document.getElementById(el).style.visibility = 'visible';
			document.getElementById('visible').value = el;
		}
	}
}

function findPosY(obj)	{
	var posY = 0
	if (obj && obj.offsetParent) {
		posY = obj.offsetTop
		while (obj = obj.offsetParent) {
			posY += obj.offsetTop
		}
	}
	return posY
}

function findPosX(obj)	{
	var posX = 0
	if (obj && obj.offsetParent) {
		posX = obj.offsetLeft
		while (obj = obj.offsetParent) {
			posX += obj.offsetLeft
		}
	}
	return posX
}

function hideSm(el)	{
	document.getElementById('visible').value = '';
	document.getElementById(el).style.visibility = 'hidden';
}

function showArrowMouseover(el) {
	if(document.getElementById(el)) document.getElementById(el).src='_graphics/noArrowRed.jpg';
}
function showArrowMouseout(el) {
	if(document.getElementById(el)) document.getElementById(el).src='_graphics/noArrow.jpg';
}



function editText(id)	{
	if(document.getElementById('edited').value == '')	{
		document.getElementById('d'+id).style.display = 'block';
		document.getElementById('p'+id).style.display = 'none';
		document.getElementById('n'+id).style.visibility = 'hidden';
		document.getElementById('edited').value = id;
	}		
}

function addText(el1,el2)	{
	if(document.getElementById('edited').value == '')	{
		document.getElementById(el2).style.display = 'block';
		document.getElementById(el1).style.visibility = 'hidden';
		//document.getElementById('edited').value = 1;
	}		
}

function add()	{
	addParagraph(document.getElementById('t').value);
	document.getElementById('edited').value = '';
}

function editParagraph(id,data,position)	{
	xmlHttp=GetXmlHttpObject()	
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="_include/editParagraph.asp"		
	xmlHttp.onreadystatechange = function(){stateChangedSP()};
	xmlHttp.open("POST",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send("id="+id+"&data="+escape(data)+"&position="+position)
}

function addParagraph(data,position,number)	{
	xmlHttp=GetXmlHttpObject()	
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="_include/addParagraph.asp"		
	xmlHttp.onreadystatechange = function(){stateChangedSP()};
	xmlHttp.open("POST",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send("pageId="+document.getElementById('pageId').value+"&data="+escape(data)+"&position="+position+"&number="+number)
}

function deleteParagraph(id)	{
	if(document.getElementById('edited').value == '')	{
		xmlHttp=GetXmlHttpObject()	
		if (xmlHttp==null)	{
			alert ("Browser does not support HTTP Request")
			return
		}
		var url="_include/deleteParagraph.asp"		
		xmlHttp.onreadystatechange = function(){stateChangedSP()};
		xmlHttp.open("POST",url,true)
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send("id="+id)
	}
}

function adminLogin(login,password)	{
	xmlHttp=GetXmlHttpObject()	
	if (xmlHttp==null)	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="admin/checkLogin.asp"		
	xmlHttp.onreadystatechange = function(){stateChangedSP('admin')};
	xmlHttp.open("POST",url,true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send("login="+login+"&password="+password)
}

function stateChangedSP(param)	{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{ 		
		//alert(xmlHttp.responseText)
		if(xmlHttp.responseText!="ok" && param!='admin')	{
			alert('Error processing request');
		}
		else if(param!='admin')
			window.location.reload();
		else if(param=='admin' && xmlHttp.responseText!="ok")
			document.getElementById('adminLoginInfo').innerHTML = xmlHttp.responseText;
		else if(param=='admin')
			document.location.href = "/admin/";
	} 	
}

function GetXmlHttpObject()	{
	var xmlHttp=null;
	try	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)	{
		try	{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)	{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}