var globalsite = "www.wehonews.com/z/wehonews/"

var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1

var ajaxlead = ""

if (is_chrome)
{
	//ajaxlead = "http://" + globalsite
}

function Replies(choice)
{
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url=ajaxlead+"Ajax/ShowReplies.php?choice=" + choice + "&sid="+Math.random()
  xmlHttp.onreadystatechange=function()
	{
		if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
		{ 

			document.getElementById("Replies"+choice).innerHTML=xmlHttp.responseText
		}
	}
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function HideReplies(choice)
{
	document.getElementById("Replies"+choice).innerHTML = "<span class=\"link\" onclick=\"Replies("+choice+")\">View Replies</span>"
}

function CommentSort(choice)
{
	var image = "ArrowUp.jpg"
	var sorter = "Date DESC"
	if (choice == "Date DESC")
	{
		image = "ArrowDown.jpg"
		sorter = "Date"
	}
	document.getElementById("CSorter").innerHTML = "<img src=\"http://"+globalsite+"images/"+image+"\" style=\"cursor:pointer;\" onclick=\"CommentSort('"+sorter+"')\" />"
	xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url=ajaxlead+"Ajax/CommentSort.php?choice=" + choice + "&sid="+Math.random()
  xmlHttp.onreadystatechange=function()
	{
		if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
		{ 
			LoadComments(1)
		}
	}
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function FlagComment(choice)
{
	xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url=ajaxlead+"Ajax/CommentFlag.php?choice="+choice+"&sid="+Math.random()
  xmlHttp.onreadystatechange=function()
	{
		if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
		{ 
			alert("This comment has been flagged.  Thank you for helping improve WeHoNews!")
		}
	}
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function DeleteComment(choice)
{
	if (confirm("Are you sure you want to delete this comment?"))
	{
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		} 
		var url=ajaxlead+"Ajax/CommentDelete.php?choice="+choice+"&sid="+Math.random()
		xmlHttp.onreadystatechange=function()
		{
			if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
			{ 
				LoadComments(document.getElementById("cpg").value)
			}
		}
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
}

function CommentAdd(reply,edit,group)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url=ajaxlead+"Ajax/CommentAdd.php?reply="+reply+"&edit="+edit+"&group="+group+"&sid="+Math.random()
	xmlHttp.onreadystatechange=function()
	{
		if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
		{ 
			document.getElementById("CommentPoster").innerHTML = xmlHttp.responseText
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function LoadComments(pg)
{
	xmlHttpc=GetXmlHttpObject()
  if (xmlHttpc==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url=ajaxlead+"Ajax/CommentsList.php?pg="+pg+"&sid="+Math.random()
  xmlHttpc.onreadystatechange=function()
	{
		if ((xmlHttpc.readyState==4 || xmlHttpc.readyState=="complete"))
		{ 

			document.getElementById("Comments").innerHTML=xmlHttpc.responseText
		}
	}
  xmlHttpc.open("GET",url,true)
  xmlHttpc.send(null)
}


var cev = ""

function EventDesc(choice,mode)
{
	if (cev)
	{
		EventDesc2(cev,"Close")
	}
	if (mode == "Open")
	{
		cev = choice
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url=ajaxlead+"Ajax/EventDesc.php?choice="+choice+"&mode="+mode+"&sid="+Math.random()
	xmlHttp.onreadystatechange=function()
	{
		if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
		{ 
			document.getElementById("Event"+choice).innerHTML = xmlHttp.responseText
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function EventDesc2(choice,mode)
{
	xmlHttp2=GetXmlHttpObject()
	if (xmlHttp2==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url=ajaxlead+"Ajax/EventDesc.php?choice="+choice+"&mode="+mode+"&sid="+Math.random()
	xmlHttp2.onreadystatechange=function()
	{
		if ((xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete"))
		{ 
			document.getElementById("Event"+choice).innerHTML = xmlHttp2.responseText
		}
	}
	xmlHttp2.open("GET",url,true)
	xmlHttp2.send(null)
}

var numads = 0
var at
var xml = new Array()

function doAdCheck(i)
{
	var choice = document.getElementById("AdId"+i).value
	xml[i]=GetXmlHttpObject()
	if (xml[i]==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="Ajax/AdCheck.php?adtem="+choice+"&sid="+Math.random()
	xml[i].onreadystatechange=function()
	{
		if ((xml[i].readyState==4 || xml[i].readyState=="complete"))
		{ 
			document.getElementById("Ad"+i).innerHTML = xml[i].responseText
		}
	}
	xml[i].open("GET",url,true)
	xml[i].send(null)
}

function adCheck()
{
	for (i = 1; i <= numads; i++)
	{
		doAdCheck(i)
	}
	
	at = setTimeout("adCheck()",1000)
}

function rotateAds()
{
	/*var i = 1
	var aid = "Ad"+i
	while (document.getElementById(aid))
	{
		i++
		aid = "Ad"+i
	}
	numads = i-1
	
	at = setTimeout("adCheck()",1000)*/
}

function AdClick(choice)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url=ajaxlead+"Ajax/AdClick.php?clicked="+choice+"&sid="+Math.random()
	xmlHttp.onreadystatechange=function()
	{
		if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
		{ 
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

var numImages = 0

function ListNewImage()
{
	numImages -= (0-1)
	document.getElementById("ImageAdd"+numImages).innerHTML += "<input type=\"file\" name=\"Image" + numImages + "\" /></div><div id=\"ImageAdd" + (numImages - (0-1)) + "\">"
	document.getElementById("ImageNum").value = numImages
}

function ListGalDelete(choice,gal)
{
	if (confirm("Are you sure you want to delete this image?"))
	{
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		} 
		var url=ajaxlead+"Ajax/ListGalDelete.php?choice="+choice+"&gal="+gal+"&sid="+Math.random()
		xmlHttp.onreadystatechange=function()
		{
			if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
			{
				document.getElementById("ListGalCur").innerHTML = xmlHttp.responseText
			}
		}
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
}
