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)
{
var value = bytees;
	if(type == "bits")
  	  value = value/8;
	else if(type == "KB")
	  value = value*1024;
	else if(type == "MB")
	  value = value*[Math.pow(1024,2)];
	else if(type == "GB")
	  value = value*[Math.pow(1024,3)];

	return value;
}

function frombyte(bytees,type)
{
 var value = bytees;
	if(type == "bits")
  	   value = value*8;
  	if(type == "KB")
  	   value = Math.round((bytees/1024)*100000000)/100000000;
  	if(type == "MB")
  	   value = Math.round((bytees/[Math.pow(1024,2)])*100000000)/100000000;
  	if(type == "GB")
  	   value = Math.round((bytees/[Math.pow(1024,3)])*100000000)/100000000;

 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);
		document.cir.va1.value = byteval;

		var eval = frombyte(byteval,'KB');
		document.cir.va11.value = eval;

		eval = eval*8;
		document.cir.va21.value = eval;

		eval = frombyte(byteval,"MB");
		document.cir.va12.value = eval;

		eval = eval*8;
		document.cir.va22.value = eval;

		eval = frombyte(byteval,"GB");
		document.cir.va13.value = eval;

		eval = eval*8;
		document.cir.va23.value = eval;

		eval = frombyte(byteval,"bits");
		document.cir.va2.value = eval;
	}
}



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;
}




