
function CollapseControl(ControlName, HideLabel)
{
	if (document.getElementById(ControlName).style.display == "none")
	{
		document.getElementById(ControlName).style.display = "inline";
		document.getElementById(HideLabel).innerText		= "Hide";
	}
	else
	{
		document.getElementById(ControlName).style.display = "none";
		document.getElementById(HideLabel).innerText		= "Show";
	}
}

function ShowHide(controlName)
{
	if (document.getElementById(controlName).style.display == "none")
		document.getElementById(controlName).style.display = "inline";
	else
		document.getElementById(controlName).style.display = "none";
}

function Capitalize(txtVar) {
  MyText = trim(txtVar.value);
  txtVar.value = MyText.substr(0, 1).toUpperCase() + MyText.substr(1);
}

function CapitalizeAll(txtVar) {
  MyText = trim(txtVar.value);
  txtVar.value = MyText.substr(0).toUpperCase();
}

function CapitalizeEveryWord(txtVar) {
  MyText = trim(txtVar.value);
  var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters 
  var a = MyText.split(/\s+/g); // split the sentence into an array of words

    for (i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2];

        a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
    }
    
    txtVar.value = a.join(' '); // join it back together
}

function CapitalizeEveryBloodyThing(txtVar) {
  MyText = trim(txtVar.value);
  var pattern = /([a-zA-Z_0-9\.\-\'\"\(\)\:\;\?\,\#\$\%\!\@\/])([a-zA-Z_0-9\.\-\'\"\(\)\:\;\?\,\#\$\%\!\@\/]*)/; // a letter, and then one, none or more letters 
  var a = MyText.split(/\s+/g); // split the sentence into an array of words

    for (i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2];

        a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
    }
    
    txtVar.value = a.join(' '); // join it back together
}


function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

// insert() is merely a convenience here
String.prototype.insert = function(chr, pos)
{
	return this.substring(0,pos) + chr + this.substring(pos);
}

// toCurrency will convert a number to a string in the form:
//	symbol + 1,234,567.89
//	where symbol is either "$" (default) or any other currency
//	symbol you supply as the argument
// 	examples given below for euro, pound and yen
Number.prototype.toCurrency = function(sym)
{
	var symbol = sym ? sym : "$";
	var num = Math.round(this * 100)/100;
	var parts = ("" + num).split(".");
	
	if(parts[1])
		while(parts[1].length < 2) 
			parts[1] += "0";
	else
		parts[1] = "00";
	
	var i = parts[0].length - 3;
	while(i > 0)
	{
		parts[0] = parts[0].insert(",", i);
		i -= 3;
	} 
	return symbol + parts.join(".");
}

function FormatVal(val)
{
	var temp1, retVal, CurrencySymbol;
	CurrencySymbol = val.substring(0,1);
	if (CurrencySymbol == "-")
		CurrencySymbol = val.substring(1,1);
		
	if (!(parseInt(CurrencySymbol,10) >= 0 && parseInt(CurrencySymbol,10) <= 9))
		val = val.replace(CurrencySymbol,"");

	temp1 = val.split(",");
	
	retVal = round(parseFloat(temp1.join("")), 2);

	if (isNaN(retVal))
		retVal = 0;
	
	return retVal;				
}

function FormatCurrencyVal(val, currencySymbol)
{
	var temp1, retVal;
	
	val = val.replace(currencySymbol, "");

	temp1 = val.split(",");
	
	retVal = round(parseFloat(temp1.join("")), 2);

	if (isNaN(retVal))
		retVal = 0;
	
	return retVal;				
}


function FormatValX(val, x)
{
	var temp1, retVal;
	val = val.replace("$","");
	
	temp1 = val.split(",");
	
	retVal = round(parseFloat(temp1.join("")), x);

	if (isNaN(retVal))
		retVal = 0;
	
	return retVal;				
}

function FormatValExtended(val)
{
	var temp1, retVal;
	val = val.replace("$","");
	
	temp1 = val.split(",");
	
	retVal = round(parseFloat(temp1.join("")), 10);

	if (isNaN(retVal))
		retVal = 0;
	
	return retVal;				
}

function round(number,X) 
{
	// rounds number to X decimal places, defaults to 2
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function formatCurrency(num) 
{
	num		= num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign	= (num == (num = Math.abs(num)));
	num		= Math.floor(num*100+0.50000000001);
	cents	= num%100;
	num		= Math.floor(num/100).toString();
	
	if(cents<10)
		cents = "0" + cents;
		
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
		
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function ConvertDecimalToMinutes(val)
{
	var retVal = Math.round(val * 6 / 10);
	if (retVal < 10)
		return "0" + retVal;
	else
		return retVal;
}

function addFavorite()
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) 
	{
		var url="http://www.skyjet.com/";
		var title="Bombardier Skyjet.com";
		document.write('<A class="link-md-black" HREF="javascript:window.external.AddFavorite(\'' + url + '\',\'' + title + '\');"');
		document.write('<small>Add this site to your favorites!</small><br></a>');
	}
	else 
	{
		var msg = " <b> - press (Ctrl-D) </b> to add this site to your favorites!";
		document.write(msg);
	}
}

function checkMaxLength(field, maxlimit) 
{
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
}

function clearText(field, defaultMessage) 
{
	if( field.value  == defaultMessage ) 
		field.value = "" ;
}
