function calcstorage()
{
	var size = window.document.form1.size.value
	var fps = window.document.form1.fps.value
	var time = window.document.form1.time.value
	var nrofcams = window.document.form1.nrofcams.value 
	var hours = window.document.form1.hours.value
		
	if ((size != "") && (fps != ""))
	{
		if (time != "")
		{
			var result = eval(size * fps * time * nrofcams * 60 * 60 * hours * 1.048576)
			window.document.form1.space.value = Math.round (result)
			unit()
		}
	}
}

function unit()
{
	var space = window.document.form1.space
	var length = space.value.length
	if (space.value.indexOf("B") != -1)
	{
		space.value = window.document.form1.space.value.substring(0, length-2)
		length -= 2
	}
	if (length > 9)
		{
		var last = space.value.substring(length-9, length)
		space.value = space.value.substring(0,length-9) + "." + last.charAt(0) + " Tb"
	}
	   else if (length > 6)
	{
		var last = space.value.substring(length-6, length)
		while (last.charAt(last.length - 1) == "0")
				last = last.substring(0, last.length-1)
		if (last.length != 0)
			space.value = space.value.substring(0,length-6) + "." + last.charAt(0) + " Gb"
		else
			space.value = space.value.substring(0,length-6) + " Gb"
	}
		else if (length > 3)
	{
		var last = space.value.substring(length-3, length)
		while (last.charAt(last.length - 1) == "0")
				last = last.substring(0, last.length-1)
		if (last.length != 0)
			space.value = space.value.substring(0,length-3) + "." + last.charAt(0) + " Mb"
		else
			space.value = space.value.substring(0,length-3) + " Mb"
	}
	else
		space.value += " สม"
}

function InitCompression()
{
  var form = window.document.form1
  var resList = form.conf_Image_Resolution
  var comprList = form.conf_Image_Compression

  if (resList.selectedIndex == 0) {
  
    comprList.options[0].text = "1 (Minimum)"
    comprList.options[1].text = "2"
    comprList.options[2].text = "3"
    comprList.options[3].text = "4"
    comprList.options[4].text = "5 (Maximum)"
   } else if (resList.selectedIndex == 1) {
    comprList.options[0].text = "1 (Minimum)"
    comprList.options[1].text = "2"
    comprList.options[2].text = "3"
    comprList.options[3].text = "4"
    comprList.options[4].text = "5 (Maximum)"
  } else if (resList.selectedIndex == 2) {
    comprList.options[0].text = "1 (Minimum)"
    comprList.options[1].text = "2"
    comprList.options[2].text = "3"
    comprList.options[3].text = "4"
    comprList.options[4].text = "5 (Maximum)"
  }  
}

function InitResolution()
{
  var form = window.document.form1
  var resList = form.conf_Image_Resolution
  var comprList = form.conf_Image_Compression

  if (comprList.selectedIndex == 0) {
    resList.options[0].text = "704x576"
    resList.options[1].text = "704x288"
    resList.options[2].text = "352x288"
  } else if (comprList.selectedIndex == 1) {
    resList.options[0].text = "704x576"
    resList.options[1].text = "704x288"
    resList.options[2].text = "352x288"
  } else if (comprList.selectedIndex == 2) {
    resList.options[0].text = "704x576"
    resList.options[1].text = "704x288"
    resList.options[2].text = "352x288"
  } else if (comprList.selectedIndex == 3) {
    resList.options[0].text = "704x576"
    resList.options[1].text = "704x288"
    resList.options[2].text = "352x288"
  } else if (comprList.selectedIndex == 4) {
    resList.options[0].text = "704x576"
    resList.options[1].text = "704x288"
    resList.options[2].text = "352x288"
  } 
}


function InitSize()
{
  var form = window.document.form1
  var resList = form.conf_Image_Resolution
  var comprList = form.conf_Image_Compression
  var size = form.size
  var color_frame = form.color

 if(color_frame.selectedIndex == 0) {
  if (comprList.selectedIndex == 0) {
    if (resList.selectedIndex == 0) size.value = "27.9"
    else if (resList.selectedIndex == 1) size.value = "16.9"
    else if (resList.selectedIndex == 2) size.value = "13.0"
  }
  else if (comprList.selectedIndex == 1) {
    if (resList.selectedIndex == 0) size.value = "10.5"
    else if (resList.selectedIndex == 1) size.value = "6.2"
    else if (resList.selectedIndex == 2) size.value = "5.4"
  }
  else if (comprList.selectedIndex == 2) {
    if (resList.selectedIndex == 0) size.value = "9.4"
    else if (resList.selectedIndex == 1) size.value = "5.4"
    else if (resList.selectedIndex == 2) size.value = "4.6"
  }
  else if (comprList.selectedIndex == 3) {
    if (resList.selectedIndex == 0) size.value = "6.7"
    else if (resList.selectedIndex == 1) size.value = "3.8"
    else if (resList.selectedIndex == 2) size.value = "3.6"
  }
  else if (comprList.selectedIndex == 4) {
    if (resList.selectedIndex == 0) size.value = "6.4"
    else if (resList.selectedIndex == 1) size.value = "3.7"
    else if (resList.selectedIndex == 2) size.value = "3.5"
  }
  }

 if(color_frame.selectedIndex == 1) {
  if (comprList.selectedIndex == 0) {
    if (resList.selectedIndex == 0) size.value = "25.9"
    else if (resList.selectedIndex == 1) size.value = "16.1"
    else if (resList.selectedIndex == 2) size.value = "11.9"
  }
  else if (comprList.selectedIndex == 1) {
    if (resList.selectedIndex == 0) size.value = "8.9"
    else if (resList.selectedIndex == 1) size.value = "5.3"
    else if (resList.selectedIndex == 2) size.value = "4.5"
  }
  else if (comprList.selectedIndex == 2) {
    if (resList.selectedIndex == 0) size.value = "7.8"
    else if (resList.selectedIndex == 1) size.value = "4.5"
    else if (resList.selectedIndex == 2) size.value = "3.6"
  }
  else if (comprList.selectedIndex == 3) {
    if (resList.selectedIndex == 0) size.value = "5.5"
    else if (resList.selectedIndex == 1) size.value = "3.0"
    else if (resList.selectedIndex == 2) size.value = "2.9"
  }
  else if (comprList.selectedIndex == 4) {
    if (resList.selectedIndex == 0) size.value = "5.1"
    else if (resList.selectedIndex == 1) size.value = "3.2"
    else if (resList.selectedIndex == 2) size.value = "2.7"
  }
 }

}


function InitCompressionAndResolution()
{
  InitCompression()
  InitResolution()
  InitSize()
}

function CompressionChange()
{
  InitResolution()
  InitSize()
}

function ColorChange()
{
  InitSize()
}

function ResolutionChange()
{
  InitCompression()
  InitSize()
}