var xmlHttp;
function EditArticle(articleid)
{
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
} 
var url="adminmanageupclose.php?articleid="+articleid;
url=url+"&sid="+Math.random();
document.getElementById('editid').value = articleid;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function DeleteArticle(deleteid)
{
if (confirm('Are you sure?'))
{
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
} 

var url="admin_cmsarticles.php?deleteid="+deleteid;
url=url+"&sid="+Math.random();
document.getElementById('deleteid').value = deleteid;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}

function DeleteAttachment(attachid)
{
if (confirm('Are you sure?'))
{
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
} 

var url="admin_cmsarticles.php?attachid="+attachid;
url=url+"&sid="+Math.random();
document.getElementById('attachid').value = attachid;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}

function DeleteIcon(deleteiconid)
{
if (confirm('Are you sure?'))
{
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
} 

var url="admin_cmsarticles.php?deleteiconid="+deleteiconid;
url=url+"&sid="+Math.random();
document.getElementById('deleteicon').value = deleteiconid;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}

function DeleteIcon2(deleteiconid)
{
if (confirm('Are you sure?'))
{
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
} 

var url="admin_sightandsounds.php?deleteiconid="+deleteiconid;
url=url+"&sid="+Math.random();
document.getElementById('deleteicon').value = deleteiconid;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}

function DeleteFlashImage(imageid)
{
	if (confirm('Are you sure?'))
	{
		xmlHttp=GetXmlHttpObject();
		
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		
		var url="admin_flashimages.php?imageid="+imageid;
		url=url+"&sid="+Math.random();
		document.getElementById('deletepicture').value = imageid;
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function DeletePhoto(photogalleryid)
{
if (confirm('Are you sure?'))
{
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
} 

var url="admin_cmsarticles.php?photogalleryid="+photogalleryid;
url=url+"&sid="+Math.random();
document.getElementById('photogalleryid').value = photogalleryid;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
//document.getElementById("articleid").innerHTML=xmlHttp.responseText;
document.form.submit();
}
}

// This is the GetXmlHttpObject
function GetXmlHttpObject(){
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    } 
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function NextPhoto(nextid,uuid)
{
		xmlHttp=GetXmlHttpObject();
		
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		
		var url="../gallery/gallery.php?photogallery=1";
		url = url + "&nextid=" + nextid;
		url = url + "&uuid=" + uuid;
		url=url+"&sid="+Math.random();
		//document.getElementById('photogalleryid').value = photogalleryid;
		xmlHttp.onreadystatechange=stateChanged2;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
}

function PreviousPhoto(previousid,uuid)
{
		xmlHttp=GetXmlHttpObject();
		
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		
		var url="../gallery/gallery.php?photogallery=1";
		url = url + "&previousid=" + previousid;
		url = url + "&uuid=" + uuid;
		url=url+"&sid="+Math.random();
		//document.getElementById('photogalleryid').value = photogalleryid;
		xmlHttp.onreadystatechange=stateChanged2;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
}

function ShowPhoto(imageid)
{
		xmlHttp=GetXmlHttpObject();
		
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		
		var url="../gallery/gallery.php?image=1";
		url = url + "&imageid=" + imageid;
		//url = url + "&caption=" + caption;
		url=url+"&sid="+Math.random();
		//document.getElementById('photogalleryid').value = photogalleryid;
		xmlHttp.onreadystatechange=stateChangedShowPhoto;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
}

var xmlHttp2;

// This is the GetXmlHttpObject
function GetXmlHttpObject2(){
    var xmlHttp2 = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp2 = new XMLHttpRequest();
    } 
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp2;
}

function ShowPhoto2(imageid)
{
		xmlHttp2=GetXmlHttpObject2();
		
		if (xmlHttp2==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		
		var url="../gallery/gallery.php?image=1";
		url = url + "&imageid=" + imageid;
		url = url + "&front=front";
		//url = url + "&caption=" + caption;
		url=url+"&sid="+Math.random();
		//document.getElementById('photogalleryid').value = photogalleryid;
		xmlHttp2.onreadystatechange=stateChangedShowPhoto2;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
		
}

function NextPhoto2(nextid,uuid)
{
		xmlHttp2=GetXmlHttpObject2();
		
		if (xmlHttp2==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		var url="../gallery/gallery.php?photogallery=1";
		url = url + "&nextid=" + nextid;
		url = url + "&uuid=" + uuid;
		url = url + "&front=front";
		url=url+"&sid="+Math.random();
		//document.getElementById('photogalleryid').value = photogalleryid;
		xmlHttp2.onreadystatechange=stateChanged3;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
		
}

function PreviousPhoto2(previousid,uuid)
{
		xmlHttp2=GetXmlHttpObject2();
		
		if (xmlHttp2==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		
		var url="../gallery/gallery.php?photogallery=1";
		url = url + "&previousid=" + previousid;
		url = url + "&uuid=" + uuid;
		url = url + "&front=front";
		url=url+"&sid="+Math.random();
		//document.getElementById('photogalleryid').value = photogalleryid;
		xmlHttp2.onreadystatechange=stateChanged3;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
		
}

function stateChangedShowPhoto() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("displayphoto").innerHTML=xmlHttp.responseText;
	}
}

function stateChangedShowPhoto2() 
{ 
	if (xmlHttp2.readyState==4)
	{ 
	document.getElementById("displayphoto2").innerHTML=xmlHttp2.responseText;
	}
}

function stateChanged2() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("photogallery").innerHTML=xmlHttp.responseText;
	}
}

function stateChanged3() 
{ 
	if (xmlHttp2.readyState==4)
	{ 
	document.getElementById("photogallery2").innerHTML=xmlHttp2.responseText;
	}
}

function DisplayVideo(cmscontentid)
{
		xmlHttp2=GetXmlHttpObject2();
		
		if (xmlHttp2==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		
		var url="../gallery/media.php?video=1";
		url = url + "&cmscontentid=" + cmscontentid;
		url=url+"&sid="+Math.random();
		xmlHttp2.onreadystatechange=stateChangedDisplayVideo;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
		
}

function stateChangedDisplayVideo() 
{ 
	if (xmlHttp2.readyState==4)
	{ 
	document.getElementById("displayvideo").innerHTML=xmlHttp2.responseText;
	}
}

function DisplaySound(cmscontentid)
{
		xmlHttp2=GetXmlHttpObject2();
		
		if (xmlHttp2==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		
		var url="../gallery/media.php?audio=1";
		url = url + "&cmscontentid=" + cmscontentid;
		url=url+"&sid="+Math.random();
		xmlHttp2.onreadystatechange=stateChangedDisplaySound;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
		
}

function stateChangedDisplaySound() 
{ 
	if (xmlHttp2.readyState==4)
	{ 
	document.getElementById("displaysound").innerHTML=xmlHttp2.responseText;
	}
}

function EditMilestone(milestoneid)
{
		xmlHttp2=GetXmlHttpObject2();
		if (xmlHttp2==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		document.getElementById('id').value = milestoneid;
		var url="admin_milestone.php";
		url=url+"&sid="+Math.random();
		xmlHttp2.onreadystatechange=stateChangedMilestone;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
}

function DeleteMilestone(milestoneid)
{
	if (confirm('Are you sure?'))
	{
		xmlHttp2=GetXmlHttpObject2();
		
		if (xmlHttp2==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		document.getElementById('delid').value = milestoneid;
		var url="admin_milestone.php";
		//url = url + "&cmscontentid=" + cmscontentid;
		url=url+"&sid="+Math.random();
		xmlHttp2.onreadystatechange=stateChangedMilestone;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}
}

function stateChangedMilestone() 
{ 
if (xmlHttp2.readyState==4)
{ 
//document.getElementById("articleid").innerHTML=xmlHttp.responseText;
document.form.submit();
}
}

function EditUser(userid)
{
		xmlHttp2=GetXmlHttpObject2();
		if (xmlHttp2==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		document.getElementById('id').value = userid;
		var url="admin_usermgmt.php";
		url=url+"&sid="+Math.random();
		xmlHttp2.onreadystatechange=stateChangedUser;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
}

function DeleteUser(userid)
{
	if (confirm('Are you sure?'))
	{
		xmlHttp2=GetXmlHttpObject2();
		
		if (xmlHttp2==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		document.getElementById('delid').value = userid;
		var url="admin_usermgmt.php";
		//url = url + "&cmscontentid=" + cmscontentid;
		url=url+"&sid="+Math.random();
		xmlHttp2.onreadystatechange=stateChangedUser;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}
}

function stateChangedUser() 
{ 
if (xmlHttp2.readyState==4)
{ 
//document.getElementById("articleid").innerHTML=xmlHttp.responseText;
document.form.submit();
}
}

function do_polltitle(polltitlefld, pollerrordiv, polltranstype, pollid)
{
	if(pollid == undefined)
	{
		pollid = "";
	}
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
		alert ("AJAX is not enabled or your browser does not support AJAX! Please enable AJAX or choose a different browser");
		return false;//this prevents the form from being processed the normal way.
	} 

	if($(polltitlefld).value.length == 0)
	{
		$(pollerrordiv).innerHTML = "Please input a title!";
	} else {
		var dopolltitleurl = "admin_ajaxtrans.php?transmode="+polltranstype+"&polltitle="+$(polltitlefld).value+"&pollid="+pollid;
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4 && xmlHttp.status==200)
			{
				if(xmlHttp.responseText.length < 5)//because the success text will only contain the id of the new poll
				{	
					$(pollerrordiv).innerHTML = "New poll created!";
					window.location = "admin_polldo.php?actionmode=editpoll&pollid="+xmlHttp.responseText;
				} else {
					if(xmlHttp.responseText == "edit title success"){
						$(pollerrordiv).innerHTML = "Poll Title Successfully Edited!";
					} else {
						$(pollerrordiv).innerHTML = xmlHttp.responseText;
					}
				}
			}
		}
		xmlHttp.open("GET",dopolltitleurl,true);
		xmlHttp.send();
	}
	return false;//this prevents the form from being processed the normal way.
}

function SetPollStat(pollid, pollstattoset, transtype)
{
	if(transtype == undefined)
	{
		transtype = "";
	}
	
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
		alert ("AJAX is not enabled or your browser does not support AJAX! Please enable AJAX or choose a different browser");
		return;
	}
	var ajaxurl = "admin_ajaxtrans.php?transmode=setpollstat&pollstat="+pollstattoset+"&pollid="+pollid;
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 && xmlHttp.status==200)
		{
			if(xmlHttp.responseText)
			{	
				if(transtype == "polllist"){
					if(pollstattoset)
					{
						$('transactstat').innerHTML = "Poll is set as the current poll";
						setTimeout("location.reload();",500);
					} else {// - if(pollstattoset)
						$('transactstat').innerHTML = "Poll has been unselected from being the current poll";
						setTimeout("location.reload();",500);
					}//close - if(pollstattoset)
				} else {
					if(pollstattoset)
					{
						$('polltitlerror').innerHTML = "This poll is set as the current poll";
						$('currentstatbtndiv').innerHTML = '<button style="width:190px;" class="submitbutton" onclick="SetPollStat('+pollid+', false);">Unselect Poll as Current</button>';
					} else {
						$('polltitlerror').innerHTML = "Poll has been unselected from being the current poll";
						$('currentstatbtndiv').innerHTML = '<button style="width:190px;" class="submitbutton" onclick="SetPollStat('+pollid+', true);">Select Poll as Current</button>';
					}
				}
			} else {// - if(xmlHttp.responseText)
				if(transtype == "polllist"){
					$('transactstat').innerHTML = "There is an error with the request.";
				} else {
					$('polltitlerror').innerHTML = "There is an error with the request.";
				}
			}//close - if(xmlHttp.responseText)
		}
	}
	xmlHttp.open("GET",ajaxurl,true);
	xmlHttp.send();
}

function CreatePollQn(pollid){
	if($('newqntext').value.length==0){
		alert("Please fill in the question text.");
		return;
	}
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
		alert ("AJAX is not enabled or your browser does not support AJAX! Please enable AJAX or choose a different browser");
		return;
	}
	var ajaxurl = "admin_ajaxtrans.php?transmode=createpollqn&pollid="+pollid+"&newqntxt="+escape($('newqntext').value)+"&newqntype="+$('newqntype').get('value')+"&newqnreqstat="+$('newqnreqstat').get('value');
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 && xmlHttp.status==200)
		{
			if(xmlHttp.responseText == true)
			{	
				$('mainqntransdiv').innerHTML = "New question successfully added!";
				setTimeout("location.reload();",500);
				
			} else {// - if(xmlHttp.responseText)
				$('mainqntransdiv').innerHTML = "There is an error with creating this question.";
			}//close - if(xmlHttp.responseText)
		}
	}
	xmlHttp.open("GET",ajaxurl,true);
	xmlHttp.send();
}

function EditPollQn(QnId, MainId){
	if($('newqntext').value.length==0){
		alert("Please fill in the question text.");
		return;
	}
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("AJAX is not enabled or your browser does not support AJAX! Please enable AJAX or choose a different browser");
		return;
	}
	var ajaxurl = "admin_ajaxtrans.php?transmode=editpollqn&qnid="+QnId+"&newqntxt="+escape($('newqntext').value)+"&newqntype="+$('newqntype').get('value')+"&newqnreqstat="+$('newqnreqstat').get('value');
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 && xmlHttp.status==200)
		{
			if(xmlHttp.responseText == true)
			{	
				alert('Question successfully edited!');
			} else {// - if(xmlHttp.responseText)
				alert('There is an error with editing this question.');
				//$('mainqntransdiv').innerHTML = "There is an error with editing this question.";
			}//close - if(xmlHttp.responseText)
			location = 'admin_polldo.php?actionmode=editpoll&pollid='+MainId;
		}
	}
	xmlHttp.open("GET",ajaxurl,true);
	xmlHttp.send();
}

function SetQnRank(TransType, QnID){
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
		alert ("AJAX is not enabled or your browser does not support AJAX! Please enable AJAX or choose a different browser");
		return;
	}
	var ajaxurl = "admin_ajaxtrans.php?transmode="+TransType+"&qnid="+QnID;
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 && xmlHttp.status==200)
		{
			if(xmlHttp.responseText == true)
			{	
				if(TransType == 'qnrankdown'){
					alert('Successfully moved the question 1 rank down!');
				} else {
					alert('Successfully moved the question 1 rank up!');
				}
				location.reload();
			} else {// - if(xmlHttp.responseText)
				alert('There was an error with this request!'+xmlHttp.responseText);
			}//close - if(xmlHttp.responseText)
		}
	}
	xmlHttp.open("GET",ajaxurl,true);
	xmlHttp.send();	
}

function SetAnsRank(TransType, AnsID){
	xmlHttp = GetXmlHttpObject();
	
	if(xmlHttp == null)
	{
		alert("AJAX is not enabled or your browser does not support AJAX! Please enable AJAX or choose a different browser");
		return;
	}
	var ajaxurl = "admin_ajaxtrans.php?transmode="+TransType+"&ansid="+AnsID;
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			if(xmlHttp.responseText == true)
			{
				if(TransType == 'ansrankdn')
				{
					alert('Successfully moved the answer 1 rank down!');
				} else {
					alert('Successfully moved the answer 1 rank up!');
				}
				location.reload();
			} else {// - if(xmlHttp.responseText == true)
				alert('There was an error with this request!'+xmlHttp.responseText);
			}//close - if(xmlHttp.responseText == true)
		}
	}
	xmlHttp.open("GET",ajaxurl,true);
	xmlHttp.send();
}

function CreatePollAns(QnId){
	if($('newanstxt'+QnId).value.length==0){
		alert("Please fill in the new answer text.");
		return;
	}
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
		alert ("AJAX is not enabled or your browser does not support AJAX! Please enable AJAX or choose a different browser");
		return;
	}
	var ajaxurl = "admin_ajaxtrans.php?transmode=createqnans&qnid="+QnId+"&newanstxt="+escape($('newanstxt'+QnId).value)+"&preselect="+$('newanspreselect'+QnId).get('value');
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 && xmlHttp.status==200)
		{
			
			if(xmlHttp.responseText == true)
			{	
				$('qnanslblerror'+QnId).innerHTML = "New answer successfully added!";
				setTimeout("location.reload();",500);
			} else {// - if(xmlHttp.responseText)
				$('qnanslblerror'+QnId).innerHTML = "There is an error with creating this answer.";
			}//close - if(xmlHttp.responseText)
			
			//$('mainqntransdiv').innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",ajaxurl,true);
	xmlHttp.send();
}

function EditPollAn(AnId, MainId){
	if($('anstxt').value.length==0){
		alert("Please fill in the answer text.");
		return;
	}
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("AJAX is not enabled or your browser does not support AJAX! Please enable AJAX or choose a different browser");
		return;
	}
	var ajaxurl = "admin_ajaxtrans.php?transmode=editpollan&anid="+AnId+"&newantxt="+escape($('anstxt').value)+"&newanpreselect="+$('anspreselect').get('value');
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 && xmlHttp.status==200)
		{
			if(xmlHttp.responseText == true)
			{	
				alert('Answer successfully edited!');
			} else {// - if(xmlHttp.responseText)
				alert('There is an error with editing this answer.'+'\r\n'+xmlHttp.responseText);
				//$('mainqntransdiv').innerHTML = "There is an error with editing this question.";
			}//close - if(xmlHttp.responseText)
			location = 'admin_polldo.php?actionmode=editpoll&pollid='+MainId;
		}
	}
	xmlHttp.open("GET",ajaxurl,true);
	xmlHttp.send();
}

function ShowTextResp(ShowType, DivName, QnId, PageLimit, PageToShow){//function to show textbox responses in admin_pollytics.php
	if(PageToShow == undefined)
	{
		PageToShow = "";
	}
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("AJAX is not enabled or your browser does not support AJAX! Please enable AJAX or choose a different browser");
		return;
	}
	$(DivName).innerHTML = '<img src="../imgs/main/preloader.gif"><br>Getting Data...';
	var ajaxurl = "admin_ajaxtrans.php?transmode=analyticsshowtxt&showtype="+ShowType+"&qnid="+QnId+"&pagelimit="+PageLimit+"&pagetoshow="+PageToShow;
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 && xmlHttp.status==200)
		{
			$(DivName).innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",ajaxurl,true);
	xmlHttp.send();
}
