﻿/*
This file contains some generic utility java script functions
*/

/* Returns client width */
function getClientWidth()
{
	var w;
	if(document.innerWidth){ w=document.innerWidth; }
	else if(document.documentElement.clientWidth){ w=document.documentElement.clientWidth; }
	else if(document.body){ w=document.body.clientWidth; }
	return w;
}
/* Returns client height */
function getClientHeight()
{
	var h;
	if(document.innerHeight){ h=document.innerHeight; }
	else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight; }
	else if(document.body){ h=document.body.clientHeight; }
	return h;
}


//rounds the input number to the desired precision
//and returns the rounded number
function roundToPrecision(inputNum, desiredPrecision){
 var precisionGuide = Math.pow(10, desiredPrecision);
 return( Math.round(inputNum * precisionGuide) / precisionGuide );
}

//converts the input number into a string and adds zeroes
//until the desired precision is reached and then
//returns the new string
function addZeroesToPrecision(inputNum, desiredPrecision){
 var numString = inputNum + "";
 var afterDecimalString = numString.substring(numString.search(/\./) + 1);
 while (afterDecimalString.length < desiredPrecision) {
   afterDecimalString += "0";
   numString += "0";
 }
 return(numString);
}