function togmod(idPrefix) {
	var title = document.getElementById(idPrefix + '_title');
	var content = document.getElementById(idPrefix + '_content');
	var isVisible = (content.style.display != "none");
	
	title.className = (isVisible ? "title_dn" : "title_up");
	content.style.display = (isVisible ? "none" : "block");
}

function increaseTextHeight(thisTextarea, add) {
	if (thisTextarea) {
		newHeight = parseInt(thisTextarea.style.height) + add;
		thisTextarea.style.height = newHeight + "px";
	}
}
function decreaseTextHeight(thisTextarea, subtract) {
	if (thisTextarea) {
		if ((parseInt(thisTextarea.style.height) - subtract) > 30) {
			newHeight = parseInt(thisTextarea.style.height) - subtract;
			thisTextarea.style.height = newHeight + "px";
		}
		else {
			newHeight = 30;
			thisTextarea.style.height = "30px";
		}			
	}
}
function map(addr) {
	addr = addr.replace(/ /g, '+');
	var url = "http://maps.google.com/maps?q=" + addr;
	var win = window.open(url,'','menubar=yes,height=550,width=700,resizable=yes,toolbar=yes,location=yes,status=yes,scrollbars=yes');
}

function showTOU(){
	return showLegal('../tos.html');
}
function showPrivacy(){
	return showLegal('../privacy.html');
}
function showLegal(doc){
	var tos = window.open(doc,'','menubar=no,height=600,width=650,resizable=yes,scrollbars=yes,toolbar=no,location=no,status=no');
	return false;
}

function showHelp(helpfile,width,height)	{
	var tos = window.open(helpfile,'','menubar=no,height='+height+',width='+width+',resizable=yes,scrollbars=yes,toolbar=no,location=no,status=no');
	return false;
}

function help(title, id, xOffset, desc, rules, alignBottom) {
	var targAlign = (alignBottom ? "LR" : "UR");
	var popAlign = (alignBottom ? "LL" : "UL");
	return overlib('<div style=\'padding:5px;\'>' + desc + '</div><div class=\'helpRules\'>' + rules + '</div>', ANCHOR, id, ANCHORALIGN, targAlign, popAlign, ANCHORX, xOffset, CAPTION, title);
}

function toggleDiv(id){
	var divRef = document.getElementById(id);
	toggleDivByRef(divRef, divRef.style.display != 'block');
}

function toggleDivByID(id, exp){
	var divRef = document.getElementById(id);
	toggleDivByRef(divRef, exp);
}

function toggleDivByRef(divRef, exp){
	divRef.style.display = exp ? 'block' : 'none';
}

// Allows you to check/clear all the entries in an asp.net checkboxlist on the client
function toggleCheckBoxList(listID, count, check) {
	for (var i = 0; i < count; i++) {
		var item = document.getElementById(listID + '_' + i);
		item.checked = check;
	}
	// returning false keeps us on the same page
	return false;
}

//Used to show extended error information in the site message
function togExtInfo() {
	var div = document.getElementById('extMsg');
	var link = document.getElementById('extMsgLink');
	var isVisible = (div.style.display == "block");
	
	div.style.display = (isVisible ? "none" : "block");
	link.innerHTML = (isVisible ? "View the extended error description &raquo;" : 
		"&laquo; Hide the extended error description");
}

function toggleTextCounter(textAreaId, counterDivId, maxlimit) {
	var textarea = document.getElementById(textAreaId);
	var div = document.getElementById(counterDivId);
	
	if (textarea.value.length > maxlimit) {
		// if too long...trim it!
		textarea.value = textarea.value.substring(0, maxlimit);
	}
	else { 
		// update 'characters left' counter
		var len = maxlimit - textarea.value.length;
		if (len > 999) {
			div.innerHTML = formatNumber(len, "##,###") + ' characters left';
		}
		else if (len == 0) {
			div.innerHTML = "You have reached the limit for this field (" + formatNumber(maxlimit, "##,###") + " characters).";
		}
		else {
			s = (len == 1 ? "" : "s");
			div.innerHTML = len + ' character' + s + ' left';
		}
	}
	div.style.display = (textarea.value.length > 0) ? 'block' : 'none';
}

// From http://weblogs.asp.net/rajbk/archive/2003/12/11/43023.aspx
// Use this to correctly submit the form with the correct submit button
// when there are multiple submit buttons on a page.
function submitForm(e, btnID){ 
	var btn = document.getElementById(btnID);
	//alert(btn);
	if (typeof btn == 'object'){ 
		if(navigator.appName.indexOf("Netscape")>(-1)){ 
			if (e.keyCode == 13){ 
				btn.click(); 
				return false; 
			} 
		} 
		if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
			if (event.keyCode == 13){ 
				btn.click(); 
				return false; 
			} 
		} 
	}
}

// Generic number formatting routine
// Original script: http://members.ozemail.com.au/~dcrombie/format.html

   // CONSTANTS
  var separator = ",";  // use comma as 000's separator
  var decpoint = ".";  // use period as decimal point
  var percent = "%";
  var currency = "$";  // use dollar sign for currency

  function formatNumber(number, format, print) {  // use: formatNumber(number, "format")
    if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

    if (number - 0 != number) return null;  // if number is NaN return null
    var useSeparator = format.indexOf(separator) != -1;  // use separators in number
    var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
    var useCurrency = format.indexOf(currency) != -1;  // use currency format
    var isNegative = (number < 0);
    number = Math.abs (number);
    if (usePercent) number *= 100;
    format = strip(format, separator + percent + currency);  // remove key characters
    number = "" + number;  // convert number input to string

     // split input value into LHS and RHS using decpoint as divider
    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

     // split format string into LHS and RHS using decpoint as divider
    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

     // adjust decimal places by cropping or adding zeros to LHS of number
    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

 // patch provided by Patti Marcoux 1999/08/06
      while (srightEnd.length > nrightEnd.length) {
        nrightEnd = "0" + nrightEnd;
      }

      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
        else break;
      }
    }

     // adjust leading zeros
    sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length) {
      nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
    }

    if (useSeparator) nleftEnd = separate(nleftEnd, separator);  // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
    if (isNegative) {
      // patch suggested by Tom Denn 25/4/2001
      output = (useCurrency) ? "(" + output + ")" : "-" + output;
    }
    return output;
  }

  function strip(input, chars) {  // strip all characters in 'chars' from input
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return output;
  }

  function separate(input, separator) {  // format input using 'separator' to mark 000's
    input = "" + input;
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++) {
      if (i != 0 && (input.length - i) % 3 == 0) output += separator;
      output += input.charAt(i);
    }
    return output;
  }

// Custom events raised on the Atlas PostBack and CallBack methods using UpdateProgressSignup
// From http://dotnetslackers.com/community/blogs/simoneb/archive/2006/09/02/481.aspx
function atlasPostBack(element)
{
    if($(element)) {
        document.body.style.cursor = 'wait';
        var anim = new YAHOO.util.Anim(element, { opacity: { to: 0 } }, 1);
        anim.animate();                    
    }
    else {
        alert("postback " + element);
    }
}
function atlasCallBack(element)
{
    if($(element)) {
        var anim = new YAHOO.util.Anim(element, { opacity: { to: 1 } }, 1);
        anim.animate();
        document.body.style.cursor = 'default';
    }
    else {
        alert("callback " + element);    
    }
}