function isNum(arg)
{
	var args = arg;
	var fad = true;

	if (args == "" || args == null || args.length == 0)
	{
		return false;
	}

	args = args.toString();

	for (var i = 0;  i<args.length;  i++)
	{
		if (args.substring(i,i+1) < "0" || args.substring(i, i+1) > "9")
		{
			if(args.substring(i, i+1) == ".")
			{
				if(fad == true)
					fad = false;
				else
					return false;			
			}
			else
			{
				return false;
			}
		}
	}
	return true;
}


function tobyte(bytees,type,opt)
{
	if(opt == "SI")
		xval = 1000;
	else
		xval = 1024;

	var value = bytees;
      if(type == "bits")
  	  value = value/8;
	else if(type == "KB")
	  value = value*[Math.pow(xval,1)];
	else if(type == "MB")
	  value = value*[Math.pow(xval,2)];
	else if(type == "GB")
	  value = value*[Math.pow(xval,3)];
	else if(type == "kilobit")
	 value = (value*xval)/8;
	else if(type == "megabit")
	 value = (value*xval*xval)/8;
	else if(type == "gigabit")
	 value = (value*xval*xval*xval)/8;	

	return value;
}

function convert()
{
	var val = document.cir.inp.value;

	if(!isNum(val))
	{
		val = val.substring(0, val.length-1);
		document.cir.inp.value = val;
	}
	else
	{
		var opt = document.cir.opt.value;

		document.cir.ev.value = val+" "+opt;
           
		var byteval = tobyte(val,opt,'SI');
		document.cir.va1.value = byteval;
		document.cir.va11.value = byteval/1000;
		document.cir.va12.value = byteval/1000000;
		document.cir.va13.value = byteval/1000000000;

		eval = byteval*8;
		document.cir.va2.value = eval;
		document.cir.va21.value = eval/1000;
		document.cir.va22.value = eval/1000000;
		document.cir.va23.value = eval/1000000000;

		byteval = tobyte(val,opt,'BIN');
		document.cir.va3.value = byteval;
		document.cir.va31.value = byteval/1024;
		document.cir.va32.value = byteval/(1024*1024);
		document.cir.va33.value = byteval/(1024*1024*1024);

		eval = byteval*8;
		document.cir.va4.value = eval;
		document.cir.va41.value = eval/1024;
		document.cir.va42.value = eval/(1024*1024);
		document.cir.va43.value = eval/(1024*1024*1024);


	}
}



function color(test)
{

	for(var j=2; j<10; j++)
	{
		var myI=document.getElementsByTagName("input").item(j);
		//myI.setAttribute("style",ch);
		myI.style.backgroundColor=test;
	}
}


function color1(test)
{
var myI=document.getElementsByTagName("table").item(0);
//myI.setAttribute("style",ch);
myI.style.backgroundColor=test;
}



