function isPrime(num)
/*
evaluates whether the number is prime or not, and returns true/false
*/
{
	var prime = false;

	if(num == 2 || num == 3)		//special test for 2 as it does not follow the normal pattern
	{
		prime = true;
	}
	else if(num > 3)
	{
		//loops through all numbers below number entered to find divisors
		for(var i = 2; i <= Math.sqrt(num); i++)
		{
			//window.status = i;
			/*if(x%2 == 0 || x%2 == 2)
			{prime=false;break;}*/
			if(num % i == 0 || num % i == i)
			{
				prime = false;
				break;
			}
			else
			{
				prime = true;
			}
		}
	}
	
	return prime;
}

function FactorList(factorlist, countarray)
/*
class (object) defintion of factor lists, including the list of factors and their occurence rates.
*/
{
	this.list = factorlist;
	this.countList = countarray;
}

function Factor(b, e)
{
	this.base = b;
	this.exponent = e;
}

function generateFactorList(primeFactors)
{
	var combinedFactorList = "";

	for(i = 0; i < primeFactors.length; i++)
	{
		//window.status = i;
		var base = eval(primeFactors[i].base);
		var exponent = eval(primeFactors[i].exponent);
		if(exponent > 1)
		{
			combinedFactorList += base + " <sup>" + exponent + "</sup> &times; ";
		}
		else if(exponent == 1)
		{
			combinedFactorList += base + " &times; ";
		}
	}
	
	combinedFactorList = combinedFactorList.substring(0, combinedFactorList.length - 5);
	
	return combinedFactorList;
}

function getPrimeFactors(num)
/*
Returns an array of type Factor with the prime factors of num.
*/
{
	var factorlist = "";
	var countarray = new Array(num);
	var prime = isPrime(num);
	var numCopy = num;
	countarray[1] = 0;
	
	if(!prime)
	{
		var test = 1;
		for(i = 2; i <= num; i++)
		{
			countarray[i] = 0; 
		
			while(num % i == 0)
			{
				factorlist += i + ", "; 
				num /= i ;
				countarray[i]++; 
			}
		
			if(isPrime(num))
			{
				factorlist += num + ", "; 
				countarray[num] = 1; 
				num = 1;
			}	
	
			//window.status = "PF:" + i;
		}
	}
	else
	{
		countarray[i] = 0;  
		factorlist += num;
		countarray[i]++;  
		combinedFactorList = new Array();
		combinedFactorList.push(new Factor(num,1));
		return combinedFactorList;
	}
	
	if(!prime)
		{factorlist = factorlist.substring(0, factorlist.length - 2);}
	
	factorlist = factorlist.split(",");
	var combinedFactorList = new Array();
	
	for(i = 0; i < factorlist.length; i++)
	{
		//window.status = i;
		v = eval(factorlist[i]);
		if(countarray[v] > 1)
		{
			combinedFactorList.push(new Factor(v,countarray[v]));
			i += countarray[v] - 1;
		}
		else if(countarray[v] == 1)
		{
			combinedFactorList.push(new Factor(v,countarray[v]));
		}
	}

	//return new FactorList(factorlist, countarray);

	return combinedFactorList;

}