var child = ""
var listDiv = ""
var Layout = "Full Page"
var formarr = ""
var commentchoice = ""

var a
var current = 1
var y
var ty = new Array()

var FadeMethod = -2
var opac = 100
var opac2 = 0
var topac = new Array()
var site
var position = 0
var inner = ""
var outer = ""
var c
var Speed = 1

var trainl = 0
var traindivl = 0
var trainp = 0
var traing = 1
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var mX = 0
var mY = 0
var trainpush = 0
var traininc = 0
trainmove = 2

var Images = new Array()
var IMax

//-----Gallery Functions-----//

function getMouse(e) 
{
  if (IE) { // grab the x-y pos.s if browser is IE
    mX = event.clientX + document.body.scrollLeft
    mY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    mX = e.pageX
    mY = e.pageY
  }  
  // catch possible negative values in NS4
  if (mX < 0){mX = 0}
  if (mY < 0){mY = 0} 
  return mX
}

function Float(e)
{
	var start = mX
	var end = getMouse(e)
	var outer = document.getElementById("outer").offsetWidth
	var inner = document.getElementById("inner").offsetWidth
	if (start < end)
	{
		mpct = (end - start) / 100
		if (mpct > .025)
		{
			mpct = .025
		}
		var pusher = mpct * inner * (2/3)
		trainp -= pusher
		trainmove = 2
	}
	else if (end < start)
	{
		mpct = (start - end) / 100
		if (mpct > .025)
		{
			mpct = .025
		}
		var pusher = mpct * inner * (2/3)
		trainp -= (0-pusher)
		trainmove = -2
	}
	if (trainp < (outer - inner))
	{
		trainp = (outer - inner)
	}
	if (trainp > 0)
	{
		trainp = 0
	}
	document.getElementById("inner").style.left = trainp + "px"
}

function FloatLeft(amount)
{
	var outer = document.getElementById("outer").offsetWidth
	var inner = document.getElementById("inner").offsetWidth
	trainp -= amount
	trainmove = 2
	if (trainp < (outer - inner))
	{
		trainp = (outer - inner)
	}
	document.getElementById("inner").style.left = trainp + "px"
}

function FloatRight(amount)
{
	var outer = document.getElementById("outer").offsetWidth
	var inner = document.getElementById("inner").offsetWidth
	trainp -= (0-amount)
	trainmove = -2
	if (trainp > 0)
	{
		trainp = 0
	}
	document.getElementById("inner").style.left = trainp + "px"
}

function Display(choice,type,sf)
{
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url="Ajax/Display.php?choice=" + choice + "&type=" + type + "&sf=" + sf + "&sid="+Math.random()
  xmlHttp.onreadystatechange=DoDisplay
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function DoDisplay() 
{ 
  if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
  { 
    document.getElementById("Display").innerHTML=xmlHttp.responseText
  }
}

function Pause()
{
	Speed = 0
}

function Play()
{
	Speed = 1
}

function Crawl()
{
	if (!inner)
	{
		inner = document.getElementById("inner").offsetWidth
		outer = document.getElementById("outer").offsetWidth
	}
	document.getElementById("inner").style.left = position + "px"
	position -= Speed
	if (position < (0 - inner))
	{
		position = outer
	}
	c = setTimeout("Crawl()",10)
}

function doPreload()
{
	for (var i = 0; i <= IMax; i++)
	{
		var a = new Image()
		a.src = Images[i]
	}
}

function Fade()
{
	clearTimeout(y)
	opac = Math.floor(opac + FadeMethod)
	opac2 = (100 - opac)
	document.getElementById("FadeImg").style.filter="alpha(opacity=" + opac + ")"
	document.getElementById("FadeImg").style.MozOpacity=(opac / 100)
	document.getElementById("FadeImg").style.opacity=(opac / 100)
	document.getElementById("FadeImg2").style.filter="alpha(opacity=" + opac2 + ")"
	document.getElementById("FadeImg2").style.MozOpacity=(opac2 / 100)
	document.getElementById("FadeImg2").style.opacity=(opac2 / 100)
	if (opac == 0)
	{
		FadeMethod = FadeMethod * (0-1)
		var curimg = document.getElementById("ICount").value
		var maximg = IMax
		curimg = curimg - (0-1)
		if (curimg > maximg)
		{
			curimg = 0
		}
		document.getElementById("FadeImg").src = Images[curimg];
		document.getElementById("ICount").value = curimg
		y = setTimeout("Fade()",4000)
	}
	else if (opac == 100)
	{
		FadeMethod = FadeMethod * (0-1)
		curimg = document.getElementById("ICount").value
		maximg = IMax
		curimg = curimg - (0-1)
		if (curimg > maximg)
		{
			curimg = 0
		}
		document.getElementById("FadeImg2").src = Images[curimg];
		document.getElementById("ICount").value = curimg
		y = setTimeout("Fade()",4000)
	}
	else
	{
		y = setTimeout("Fade()",20)
	}
}

function StartFade()
{
	if (!IMax)
	{
		var ImgList = document.getElementById("GalImageList").innerHTML
		Images = ImgList.split(" | ")
		IMax = (document.getElementById("IMax").value - 1)
		doPreload()
		site = document.getElementById("Site").value
		y = setTimeout("Fade()",4000)
	}
}

var galdiv = ""

function DoGal(gal,width,height,div,pg,gid)
{
	galdiv = div
	xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url="Ajax/ShowGal.php?gal=" + gal + "&width=" + width + "&height=" + height + "&pg=" + pg + "&div=" + div + "&gid=" + gid + "&sid="+Math.random()
	document.getElementById(galdiv).innerHTML="Loading..."
  xmlHttp.onreadystatechange=ShowGal
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function ShowGal() 
{ 
  if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
  { 
    document.getElementById(galdiv).innerHTML=xmlHttp.responseText
  }
}

//-----Form Functions-----//

function CheckForm()
{
	var billFirst = document.getElementById("billFirst").value
	var billLast = document.getElementById("billLast").value
	var Email = document.getElementById("Email").value
	
	var shipFirst = document.getElementById("shipFirst").value
	var shipLast = document.getElementById("shipLast").value
	var shipAddress = document.getElementById("shipAddress").value
	var shipCity = document.getElementById("shipCity").value
	var y=document.getElementById("shipState")
	var shipState = y.options[y.selectedIndex].value
	var shipZip = document.getElementById("shipZip").value
	
	if (billFirst && billLast && shipFirst && shipLast && shipAddress && shipCity && shipState && shipZip && Email)
	{
		document.getElementById("Submit").innerHTML = '<input type="Submit" value="Submit" />'
	}
	else
	{
		document.getElementById("Submit").innerHTML = '<font color="red">*</font>Field is required.  Please fill out all required fields to activate the submit button.<br /><input type="submit" value="Submit (Disabled)" disabled />'
	}
}

function CheckForm2()
{
	var billFirst = document.getElementById("billFirst").value
	var billLast = document.getElementById("billLast").value
	var Email = document.getElementById("Email").value
	
	if (billFirst && billLast && Email)
	{
		document.getElementById("Submit").innerHTML = '<input type="Submit" value="Submit" />'
	}
	else
	{
		document.getElementById("Submit").innerHTML = '<font color="red">*</font>Field is required.  Please fill out all required fields to activate the submit button.<br /><input type="submit" value="Submit (Disabled)" disabled />'
	}
}

function UseAbove()
{
	var billFirst = document.getElementById("billFirst").value
	var billLast = document.getElementById("billLast").value
	var billAddress = document.getElementById("billAddress").value
	var billCity = document.getElementById("billCity").value
	var x=document.getElementById("billState")
	var billState = x.options[x.selectedIndex].value
	var billZip = document.getElementById("billZip").value

	document.getElementById("shipFirst").value = billFirst
	document.getElementById("shipLast").value = billLast
	document.getElementById("shipAddress").value = billAddress
	document.getElementById("shipCity").value = billCity
	var y=document.getElementById("shipState")
	y.options[y.selectedIndex].value = billState
	y.options[y.selectedIndex].text = billState
	document.getElementById("shipZip").value = billZip

	CheckForm()
}

var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
{
	document.onmousemove = getMouseXY;
}

var tempX = 0
var tempY = 0
var tempH = 0
var tempW = 0

function getMouseXY(e) 
{ 
	tempX = 0;
	tempY = 0;
	tempH = 0;
	tempW = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		tempX = e.pageX;
		tempY = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		tempX = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		tempY = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	
	if (window.innerHeight)
	{
		tempH = window.innerHeight
		tempW = window.innerWidth
	}
	else if (document.documentElement.clientHeight > 0)
	{
		tempH = document.documentElement.clientHeight
		tempW = document.documentElement.clientWidth
	}
	else
	{
		tempH = document.body.clientHeight
		tempW = document.body.clientWidth
	}

	document.getElementById("Help").style.top = (tempY - (0-5)) + "px"
	document.getElementById("Help").style.left = (tempX - (0-5)) + "px"
	
	if (tempX + document.getElementById("Help").offsetWidth > (tempW + document.body.scrollLeft + document.documentElement.scrollLeft))
	{
		tempX -= (tempX + document.getElementById("Help").offsetWidth - (tempW + document.body.scrollLeft + document.documentElement.scrollLeft))
		document.getElementById("Help").style.left = (tempX + (0-5)) + "px"
	}
	
	if (tempY + document.getElementById("Help").offsetHeight > (tempH + document.body.scrollTop + document.documentElement.scrollTop))
	{
		tempY -= (tempY + document.getElementById("Help").offsetHeight - (tempH + document.body.scrollTop + document.documentElement.scrollTop))
		document.getElementById("Help").style.top = (tempY + (0-5)) + "px"
	}
  return true
}

function Help(helptext)
{
	document.getElementById("Help").style.height = "0px"
	document.getElementById("Help").innerHTML = helptext
	document.getElementById("Help").style.visibility = "visible"
	document.getElementById("Help").style.width = "200px"
	document.getElementById("Help").style.height = "auto"
}

function HelpClose()
{
	document.getElementById("Help").innerHTML = ""
	document.getElementById("Help").style.visibility = "hidden"
	document.getElementById("Help").style.width = "0px"
	document.getElementById("Help").style.height = "0px"
}

//-----Page Functions-----//

function CommentEdit(choice,page,url)
{
	commentchoice = choice
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url="Ajax/CommentEdit.php?choice=" + choice + "&page=" + page + "&url=" + url + "&sid="+Math.random()
  xmlHttp.onreadystatechange=DoCommentEdit
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function DoCommentEdit() 
{ 
  if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
  { 
    document.getElementById("Comment" + commentchoice).innerHTML=xmlHttp.responseText
  }
}

function WordCount(choice)
{
	formcontent = document.getElementById(choice).value
	formcontent = formcontent.replace(/(<([^>]+)>)/ig,"")
	formarr = formcontent.split(/\s/)
	return formarr.length
}

function TextShow(choice,div)
{
	var text = document.getElementById(choice).value
	var Words = WordCount(choice)
	var text1 = ""
	var text2 = ""
	var charlist = text.split("")
	var characters = charlist.length
	var charlist2 = text.replace(/(<([^>]+)>)/ig,"").split("")
	var characters2 = charlist2.length
	var charcount = 1
	var chartrue = 0
	var breakhere
	var breaks = 0
	for (i = 0; i < characters; i++)
	{
		if (charlist[i] == "<")
		{
			charcount = 0
		}
		if (charcount == 1)
		{
			chartrue++
			if (charlist[i] == " ")
			{
				breaks++
				if (chartrue > charlist2.length / 2 && !breakhere)
				{
					breakhere = 1
				}
			}
		}
		if (charlist[i] == ">")
		{
			charcount = 1
		}
		if (!breakhere)
		{
			text1 += charlist[i]
		}
		else
		{
			text2 += charlist[i]
		}
	}
	if (Layout == "Columns")
	{
		document.getElementById("Col1" + div).innerHTML = "<p>" + text1 + "</p>"
		document.getElementById("Col2" + div).innerHTML = "<p>" + text2 + "</p>"
	}
	else
	{
		text = "<p>" + text + "</p>"
		document.getElementById("Col1" + div).innerHTML = text
	}
}

function TextLayout(choice,target,div)
{
	Layout = document.getElementById(choice).value
	TextShow(target,div)
}

//-------- Control Functions ----------//
function ColorShow(choice)
{
	choice2 = choice + "all"
	document.getElementById(choice).style.width = '210px'
	document.getElementById(choice).style.height = '210px'
	document.getElementById(choice2).style.backgroundColor = 'black'
}

function ColorClose(choice)
{
  choice2 = choice + "all"
	document.getElementById(choice).style.width = '0px'
	document.getElementById(choice).style.height = '0px'
	document.getElementById(choice2).style.backgroundColor = ''
}

function insertAtCursor(fname, bef, aft) 
{
	myField = document.getElementById(fname)
  if (document.selection) 
	{
    myField.focus();
    sel = document.selection.createRange();
    sel.text = bef + sel.text + aft;
  }
  else if (myField.selectionStart || myField.selectionStart == '0') 
	{
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos) + bef + myField.value.substring(startPos, endPos) + aft + myField.value.substring(endPos, myField.value.length);
  } 
	else 
	{
    myField.value += myValue;
  }
	TextShow(fname)
}

function Color(ch,cl)
{
	var color = cl
	bef = "<span style='color:" + color + "'>"
	insertAtCursor(ch,bef,'</span>')
}

function DoCol(clr,bg,clist,fname)
{
	Color(fname,clr)
	document.getElementById(bg).style.backgroundColor = clr
	ColorClose(clist)
}

function Size(ch,sz)
{
	x = document.getElementById(sz)
	var size = x.options[x.selectedIndex].text
	bef = "<span style='font-size:" + size + "px'>"
	insertAtCursor(ch,bef,'</span>')
}

//-----General Functions-----//

function Go(choice)
{
	document.location = choice;
}

function LinkList(refer,target,width,height)
{
	if (document.getElementById(refer).innerHTML == "+")
	{
		document.getElementById(refer).innerHTML = "-"
		document.getElementById(target).style.width = width
		document.getElementById(target).style.height = height
		document.getElementById(target).style.visibility = "visible"
	}
	else
	{
		document.getElementById(refer).innerHTML = "+"
		document.getElementById(target).style.width = "0px"
		document.getElementById(target).style.height = "0px"
		document.getElementById(target).style.visibility = "hidden"
	}
}

function AJAX_FUNCTION(DOVAR)
{
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url="PHP_PAGE.php?VAR=" + DOVAR + "&sid="+Math.random()
  xmlHttp.onreadystatechange=AJAXCALL
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function AJAXCALL() 
{ 
  if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
  { 
    document.getElementById("AJAXDIV").innerHTML=xmlHttp.responseText
  }
}

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;
}