/*
 *	utils.js
 *
 *	Michael Holder,  March 2010
 *
 *	$Id: Utils.js,v 1.1 2010/04/06 20:54:51 michaelholder Exp $
 */

//========================================================================

function clearDefault(el) {
	if (el.defaultValue==el.value) el.value = ""
	if (el.style) el.style.cssText = ""
}

//========================================================================

function downloadURL(URL,filename) {
	if (window.confirm("A file '"+fileName+"' will be downloaded")){
		document.location=URL;
	}
}

//========================================================================

function phoneNumber(el) {
	
	var outputNum;
	var inputNum = el.value.replace(/[^0-9]+/g,"");
	
	if (inputNum.length > 10) {
		var preLen = inputNum.length - 10;
		outputNum = "+" + inputNum.substr(0,preLen) + " (" + inputNum.substr(preLen,3) +
			") " + inputNum.substr(preLen+3,3) + "-" + inputNum.substr(preLen+6,4);
	} else if (inputNum.length > 7) {
		outputNum = "(" + inputNum.substr(0,3) + ") " + inputNum.substr(3,3) + "-" + inputNum.substr(6);
	} else if (inputNum.length > 3) {
		outputNum = inputNum.substr(0,3) + "-" + inputNum.substr(3);
	} else {
		outputNum = el.value;
	}
	
	el.value = outputNum;
}

//========================================================================


