var bidon
var Width
var Pos = 0
var Pos2 = 0
var Speed = 1
var t
var switch1 = ""
var switch2 = ""

function Opac()
{
  var opacityAsInt = document.getElementById("Opac").value
	var elem = document.getElementById('MainBG')
	var elem2 = document.getElementById('MainBGTop')
  var opacityAsDecimal = opacityAsInt;
 
  if (opacityAsInt > 100)
	{
		opacityAsInt = opacityAsDecimal = 100; 
	}
	else if (opacityAsInt < 0)
	{
  	opacityAsInt = opacityAsDecimal = 0; 
	}

	opacityAsDecimal /= 100;
	if (opacityAsInt < 1)
	{
		opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
	}
	
	elem.style.opacity = (opacityAsDecimal);
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
	elem2.style.opacity = (opacityAsDecimal);
	elem2.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

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

function Color()
{
	x = document.getElementById("color")
	var color = x.options[x.selectedIndex].text
	bef = "<span style='color:" + color + "'>"
	insertAtCursor('ta',bef,'</span>')
}

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

function Track()
{
	var session = document.getElementById("session").value
	var date = document.getElementById("date").value
	var hits = document.images.length - (0-2)
	var page = document.location
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    return
  } 
  var url="Track.php?session=" + session + "&date=" + date + "&hits=" + hits + "&page=" + page + "&sid="+Math.random()
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function Crawl()
{
	Width = document.getElementById("train").offsetWidth
	Width2 = document.getElementById("train2").offsetWidth
	Pos -= (Speed * 1)
	Pos2 -= (Speed * 1)
	if (Pos < (0-Width) && Speed > 0)
	{
		Pos = Pos2-(0-Width2)
	}
	if (Pos > 567 && Speed < 0)
	{
		Pos = (Pos2-Width)
	}
	if (Pos2 < (0-Width2) && Speed > 0)
	{
		Pos2 = Pos-(0-Width)
	}
	if (Pos2 > 567 && Speed < 0)
	{
		Pos2 = (Pos-Width2)
	}
	document.getElementById("train").style.left = Pos + "px"
	document.getElementById("train2").style.left = Pos2 + "px"
	t = setTimeout("Crawl()",10)
}

function Forward()
{
	Speed -= 1
	if (Speed >= 0)
	{
		Speed = -1
	}
}

function Stop()
{
	Speed = 0
}

function Back()
{
	Speed -= (0-1)
	if (Speed <= 0)
	{
		Speed = 1
	}
}

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

function Redirect(choice,time)
{
	time = time * 1000
	var rdct = setTimeout("Go('" + choice + "')",time)
}

function Center()
{
  /*Left = ((document.getElementById("Offset").offsetWidth - 800) / 2)
  if (Left < -20)
  {
    Left = -20
  }
	if (document.getElementById("main").offsetHeight < 1400)
	{
		document.getElementById("main").style.height = "1400px"
	}
  document.getElementById("container").style.left = Left + "px"*/
	document.getElementById("train2").style.left = document.getElementById("train").offsetWidth + "px"
	Pos2 = document.getElementById("train").offsetWidth
	Track()
	Crawl()
}

function Center2()
{
  /*Left = ((document.getElementById("Offset").offsetWidth - 800) / 2)
  if (Left < -20)
  {
    Left = -20
  }
	if (document.getElementById("main").offsetHeight < 1400)
	{
		document.getElementById("main").style.height = "1400px"
	}
  document.getElementById("container").style.left = Left + "px"*/
	document.getElementById("train2").style.left = document.getElementById("train").offsetWidth + "px"
	Pos2 = document.getElementById("train").offsetWidth
	document.getElementById("container").style.visibility = "visible"
	Crawl()
}

function Center3()
{
  /*Left = ((document.getElementById("Offset").offsetWidth - 800) / 2)
  if (Left < -20)
  {
    Left = -20
  }
	if (document.getElementById("main").offsetHeight < 1400)
	{
		document.getElementById("main").style.height = "1400px"
	}
  document.getElementById("container").style.left = Left + "px"*/
	document.getElementById("train2").style.left = document.getElementById("train").offsetWidth + "px"
	Pos2 = document.getElementById("train").offsetWidth
	document.getElementById("container").style.visibility = "visible"
}

function CheckForm()
{
	var UN = document.getElementById("jUN").value
	var PW = document.getElementById("jPW").value
	var PW2 = document.getElementById("jPW2").value
	var First = document.getElementById("First").value
	var Last = document.getElementById("Last").value
	var Email = document.getElementById("Email").value
	var Phone = document.getElementById("Phone").value
	
	if (UN != "" && PW != "" && First != "" && Last != "" && Email != "" && Phone != "")
	{
		document.getElementById("submit").disabled = ""
		document.getElementById("submit").value = "Submit"
		if (PW != PW2)
		{
			document.getElementById("submit").disabled = "disabled"
			document.getElementById("submit").value = "Passwords Don't Match"
		}
	}
	else
	{
		document.getElementById("submit").disabled = "disabled"
		document.getElementById("submit").value = "Submit"
	}
}

function Swap(cat)
{
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url="http://www.horrordomain.com/Admin/DoSwap.php?s1=" + switch1 + "&s2=" + switch2 + "&cat="+cat+"&sid="+Math.random()
  xmlHttp.onreadystatechange=Swapped
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function Swap2(domain)
{
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url="http://www.horrordomain.com/Admin/DoCatSwap.php?s1=" + switch1 + "&s2=" + switch2 + "&domain=" + domain + "&sid="+Math.random()
  xmlHttp.onreadystatechange=Swapped
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function Swapped() 
{ 
  if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
  { 
    document.getElementById("Order").innerHTML=xmlHttp.responseText
		switch1 = ""
		switch2 = ""
  }
}

function Switch(choice,cat)
{
	if (switch1 == "")
	{
		switch1 = choice
	}
	else if (switch2 == "")
	{
		switch2 = choice
		Swap(cat)
	}
	var thisone = "a" + choice
	document.getElementById(thisone).style.border = "solid 2px red";
}

function Switch2(choice,domain)
{
	if (switch1 == "")
	{
		switch1 = choice
	}
	else if (switch2 == "")
	{
		switch2 = choice
		Swap2(domain)
	}
	var thisone = "a" + choice
	document.getElementById(thisone).style.border = "solid 2px red";
}

function Bid(product)
{
	var bidit = "bid" + product
	var bid = document.getElementById(bidit).value
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  } 
  var url="DoBid.php?bid=" + bid + "&product=" + product + "&sid="+Math.random()
	bidon = product
  xmlHttp.onreadystatechange=BidShow
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function BidShow() 
{ 
  if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete"))
  { 
	  biddiv = "bids" + bidon
    document.getElementById(biddiv).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;
}
