var t
var y
var ga = 1
var opac = 100
var FadeMethod = -2
var galchoice

var scrolldir = new Array()
var ipos = new Array()
var iheight = new Array()
var top = new Array()
var bottom = new Array()

scrolldir[1] = 0
ipos[1] = 0

scrolldir[2] = 0
ipos[2] = 0

scrolldir[3] = 0
ipos[3] = 0

function CheckForm()
{
	var Name = document.getElementById("Name").value
	var Email = document.getElementById("Email").value
	if (Name && Email)
	{
		document.getElementById("nSubmit").disabled = ""
	}
	else
	{
		document.getElementById("nSubmit").disabled = "disabled"
	}
}

function NumberFormat(num)
{
	numk = Math.floor(num / 1000)
	numh = Math.floor((num - (numk * 1000)) / 100)
	numt = Math.floor((num - (numk * 1000) - (numh * 100)) / 10)
	num1 = Math.floor(num - (numk * 1000) - (numh * 100) - (numt * 10))
	numdec = num - (numk * 1000) - (numh * 100) - (numt * 10) - (num1)
	numdec = Math.round(numdec * 100)
	var total = ""
	if (numk)
	{
		total += numk + ","
	}
	if (numh || numk)
	{
		total += numh
	}
	if (numt || numh || numk)
	{
		total += numt
	}
	if (num1 || numt || numh || numk)
	{
		total += num1
	}
	if (numdec)
	{
		total += "." + numdec
	}
	return total
}

function Calc()
{
	var OW = document.getElementById("OldWatts").options[document.getElementById("OldWatts").selectedIndex].value
	var OL = document.getElementById("OldLife").options[document.getElementById("OldLife").selectedIndex].value
	var OC = document.getElementById("OldCost").value
	var NW = document.getElementById("NewWatts").options[document.getElementById("NewWatts").selectedIndex].value
	var NL = document.getElementById("NewLife").options[document.getElementById("NewLife").selectedIndex].value
	var NC = document.getElementById("NewCost").value
	var Hours = document.getElementById("Hours").options[document.getElementById("Hours").selectedIndex].value
	var Days = document.getElementById("Days").options[document.getElementById("Days").selectedIndex].value
	var ER = document.getElementById("ERate").options[document.getElementById("ERate").selectedIndex].value
	var CR = document.getElementById("CRate").options[document.getElementById("CRate").selectedIndex].value
	
	if (OW && OL && OC && NW && NL && NC && Hours && Days && ER && CR)
	{
		var OkWh = (OW / 1000) * Hours * ((Days * 52) + 1) //Old KiloWattHours per Year
		var NkWh = (NW / 1000) * Hours * ((Days * 52) + 1) //New KiloWattHours per Year
		var OYEC = OkWh * ER //Old Yearly Energy Cost
		var NYEC = NkWh * ER //New Yearly Energy Cost
		var OYRC = (OC) / (OL / (Hours * ((Days * 52) - (0-1)))) //Old Yearly Replacement Cost
		var NYRC = 0 //New Yearly Replacement Cost
		var OCPY = OYRC - (0-OYEC) //Old Cost Per Year
		var NCPY = NYRC - (0-NYEC) //New Cost Per Year
		var Savings = OCPY - NCPY  //Yearly savings
		var NOI = Savings / CR
		var PFI = Math.ceil(NC / Savings * 365)  //Days until it pays for itself.
		document.getElementById("Results").innerHTML = "You would save an average of $" + NumberFormat(Savings) + " <b>per bulb per year</b> between replacement and energy costs.  This translates into a increase in your property's/business's value  of $" + NumberFormat(NOI) + " per bulb with the data you provided (this does not include the cost of time to replace the bulb)."
	}
}

function CheckMin(minimum)
{
	if (document.getElementById("Default"))
	{
		if (document.getElementById("Default").value < minimum)
		{
			document.getElementById("Submit").disabled = "disabled"
			document.getElementById("MinWarn").innerHTML = "To enable the purchase button, please enter at least the minimum order."
		}
		else
		{
			document.getElementById("Submit").disabled = ""
			document.getElementById("MinWarn").innerHTML = ""
		}
	}
	else
	{
		var Total = 0
		if (document.getElementById("Option1"))
		{
			Total = Total - (document.getElementById("Option1").value * (0-1))
		}
		if (document.getElementById("Option2"))
		{
			Total = Total - (document.getElementById("Option2").value * (0-1))
		}
		if (document.getElementById("Option3"))
		{
			Total = Total - (document.getElementById("Option3").value * (0-1))
		}
		if (Total < minimum)
		{
			document.getElementById("Submit").disabled = "disabled"
			document.getElementById("MinWarn").innerHTML = "To enable the purchase button, please enter at least the minimum order."
		}
		else
		{
			document.getElementById("Submit").disabled = ""
			document.getElementById("MinWarn").innerHTML = ""
		}
	}
}

function init()
{
	iheight[1] = document.getElementById("inner1").offsetHeight
	top[1] = 0
	bottom[1] = (iheight[1] * (0-1) + 580)
	
	iheight[2] = document.getElementById("inner2").offsetHeight
	top[2] = 0
	bottom[2] = (iheight[2] * (0-1) + 240)
	
	iheight[3] = document.getElementById("inner3").offsetHeight
	top[3] = 0
	bottom[3] = (iheight[3] * (0-1) + 290)
}

function boost(jump,choice)
{
	ipos[choice] -= (0-jump)
	if (ipos[choice] < bottom[choice])
	{
		ipos[choice] = bottom[choice]
	}
	if (ipos[choice] > top[choice])
	{
		ipos[choice] = top[choice]
	}
	var inner = "inner" + choice
	document.getElementById(inner).style.top = ipos[choice] + "px"
}

function IMan()
{
	if (document.getElementById("imanagetxt").innerHTML == "Open Image Manager")
	{
		document.getElementById("imanagetxt").innerHTML = "Close Image Manager"
		document.getElementById("imanage").style.width = "auto"
		document.getElementById("imanage").style.height = "auto"
		init()
		boost(-250,3);
	}
	else if (document.getElementById("imanagetxt").innerHTML == "Close Image Manager")
	{
		document.getElementById("imanagetxt").innerHTML = "Open Image Manager"
		document.getElementById("imanage").style.width = "0px"
		document.getElementById("imanage").style.height = "0px"
		init()
		boost(250,3);
	}
}

function OpenClose(choice)
{
	var text = choice + "txt"
	
	if (document.getElementById(text).innerHTML == "Open " + choice + " Form")
	{
		document.getElementById(text).innerHTML = "Close " + choice + " Form"
		document.getElementById(choice).style.width = "auto"
		document.getElementById(choice).style.height = "auto"
		init()
		boost(-100,3);
	}
	else if (document.getElementById(text).innerHTML == "Close " + choice + " Form")
	{
		document.getElementById(text).innerHTML = "Open " + choice + " Form"
		document.getElementById(choice).style.width = "0px"
		document.getElementById(choice).style.height = "0px"
		init()
		boost(100,3);
	}
}

function CShow(choice)
{
	var clink = "CLink" + choice
	var comments = "Comments" + choice
	document.getElementById(clink).innerHTML = '<a href="javascript:CClose(\'' + choice + '\')">Hide Comments</a>'
	document.getElementById(comments).style.width = "auto"
	document.getElementById(comments).style.height = "auto"
	init()
}

function CClose(choice)
{
	var clink = "CLink" + choice
	var comments = "Comments" + choice
	document.getElementById(clink).innerHTML = '<a href="javascript:CShow(\'' + choice + '\')">View/Post Comments</a>'
	document.getElementById(comments).style.width = "0px"
	document.getElementById(comments).style.height = "0px"
	init()
}

function Wheel(event,choice)
{
	var delta = 0;
	if (!event)
	{
		event = window.event;
	}
	if (event.wheelDelta)
	{
		delta = event.wheelDelta/120;
		if (window.opera)
		{
			delta = -delta;
		}
	}
	else if (event.detail) 
	{
		delta = -event.detail/3;
	}
	event.returnValue = false;
	if (delta == -1)
	{
		ipos[choice] -= 75
	}
	else if (delta == 1)
	{
		ipos[choice] -= (0-75)
	}
	if (ipos[choice] > top[choice])
	{
		ipos[choice] = top[choice]
	}
	else if (ipos[choice] < bottom[choice])
	{
		ipos[choice] = bottom[choice]
	}
	var inner = "inner" + choice
	document.getElementById(inner).style.top = ipos[choice] + "px"
}

function doscroll(dir,choice)
{
	if (dir != 0)
	{
		scrolldir[choice] = dir
		scrolling(choice)
	}
	else
	{
		clearTimeout(t)
	}
}

function scrolling(choice)
{
	if ((scrolldir[choice] < 0 && ipos[choice] > bottom[choice]) || (scrolldir[choice] > 0 && ipos[choice] < top[choice]))
	{
		ipos[choice] = ipos[choice] - (scrolldir[choice] * (0-1))
		var inner = "inner" + choice
		document.getElementById(inner).style.top = ipos[choice] + "px"
		t = setTimeout("scrolling(" + choice + ")",10)
	}
}

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

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

function GalShift()
{
	clearTimeout(y)
  if (ga)
  {
    opac = Math.floor(opac + FadeMethod)
    document.getElementById("GalImg").style.filter="alpha(opacity=" + opac + ")"
    document.getElementById("GalImg").style.MozOpacity=(opac / 100)
    if (opac == 0)
    {
      FadeMethod = FadeMethod * (0-1)
			GalSwitch(galchoice)
      y = setTimeout("GalShift()",1000)
    }
    else if (opac == 100)
    {
			galchoice = document.getElementById("GalNext").value
      FadeMethod = FadeMethod * (0-1)
      y = setTimeout("GalShift()",8000)
    }
    else
    {
      y = setTimeout("GalShift()",10)
    }
  }
}

function GalJump(choice)
{
	if (opac != 0)
	{
		FadeMethod = -2
	}
	galchoice = choice
	GalShift(galchoice)
}

function GalNext()
{
	if (opac != 0)
	{
		FadeMethod = -2
	}
	galchoice = document.getElementById("GalNext").value
	GalShift()
	ga = 1
}

function GalPrev()
{
	if (opac != 0)
	{
		FadeMethod = -2
	}
	galchoice = document.getElementById("GalPrev").value
	GalShift()
	ga = -1
}

function GalStop()
{
	ga = 0
}

function GalPlay()
{
	ga = 1
}

function GalStart()
{
	var x = setTimeout("GalNext()",8000)
}

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

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