		////////////////////////////// Colour Functions /////////////////////////////////////
		//Convert a hex value to its decimal value - the inputed hex must be in the
		// format of a hex triplet - the kind we use for HTML colours. The function
		// will return an array with three values.
		function hex2num(hex) {
		 if(hex.charAt(0) == "#") { 
			hex = hex.slice(1);
		 }
		 hex = hex.toUpperCase();
		 var hex_alphabets = "0123456789ABCDEF";
		 var value = new Array(3);
		 var k = 0;
		 var int1,int2;
		 for(var i=0;i<6;i+=2) {
			int1 = hex_alphabets.indexOf(hex.charAt(i));
			int2 = hex_alphabets.indexOf(hex.charAt(i+1));
			value[k] = (int1 * 16) + int2;
			k++;
		 }
		 return(value);
		}
		//Give a array with three values as the argument and the function will return
		// the corresponding hex triplet.
		function num2hex(triplet) {
		 var hex_alphabets = "0123456789ABCDEF";
		 var hex = "#";
		 var int1,int2;
		 for(var i=0;i<3;i++) {
			int1 = triplet[i] / 16;
			int2 = triplet[i] % 16;

			hex += hex_alphabets.charAt(int1) + hex_alphabets.charAt(int2);
		 }
		 return(hex);
		}

		//Function that fades the color.
		//Arguments...
		//id - ID of the element whose colour must be faded.
		//start_hex - The initial color of the element.
		//stop_hex - The final color. The element will fade from the initial color to the final color.
		//difference- The colour values will be incremented by this number
		//delay - The speed of the the effect - higher delay means slower effect.
		//color_background- The fade must be for the color of the element or for its background.
		//      Allowed values are 'c'(Color of element) and 'b'(Background)
		function fadeColor(id,start_hex,stop_hex,difference,delay,color_background) {
		 //Default values...
		 if(!difference) difference = 20;
		 if(!delay) delay = 100;
		 if(!start_hex) start_hex = "#FFFFFF";
		 if(!stop_hex) stop_hex = "#000000";
		 if(!color_background) color_background = "c";
		 
		 var ele = document.getElementById(id);
		 if(!ele) return;
		 var start= hex2num(start_hex);
		 var stop = hex2num(stop_hex);
		 
		 //Make it numbers rather than strings.
		 for(var i=0;i<3;i++) {
			start[i] = Number(start[i]);
			stop[i] = Number(stop[i]);
		 }

		 //Morph one colour to the other. If the start color is greater than the stop colour, start color will
		 // be decremented till it reaches the stop color. If it is lower, it will incremented.
		 for(var i=0;i<3;i++) {
			if (start[i] < stop[i]) {
			 start[i] += difference;
			 if(start[i] > stop[i]) start[i] = stop[i];//If we have overshot our target, make it equal - or it won't stop.
			}
			else if(start[i] > stop[i]) {
			 start[i] -= difference;
			 if(start[i] < stop[i]) start[i] = stop[i];
			}
		 }

		 //Change the color(or the background color).
		 var color = "rgb("+start[0]+","+start[1]+","+start[2]+")";
		 if(color_background == "b") {
			ele.style.backgroundColor = color;
		 } else {
			ele.style.color = color;
		 }

		 //Stop if we have reached the target.
		 if(start[0] == stop[0] && start[1] == stop[1] && start[2] == stop[2]) return;

		 start_hex = num2hex(start);
		 //Keep calling this function
		 window.setTimeout("fadeColor('"+id+"','"+start_hex+"','"+stop_hex+"',"+difference+","+delay+",'"+color_background+"')",delay);
		}

		function collapse(id)
		{
			var obj       = document.getElementById(id);
			var obj2	  = document.getElementById(id + 'chart');
			obj.timer     = setInterval(smoothGrow, 10);
			currentHeight = obj.offsetHeight * 1;
			height		    = 100;

			function smoothGrow()
			{
				currentHeight = currentHeight -  20;
				
				//for ie, ie doesnt like negative height
				if(currentHeight > 0)	
					obj.style.height = currentHeight + "px";

				if (currentHeight <= height)
				{
					clearInterval(obj.timer);
					obj2.style.display = 'none';
				}
			}
		}

		function expand(id)
		{
			var obj = document.getElementById(id);
			var obj2 = document.getElementById(id + 'chart');
			obj.timer= setInterval(smoothGrow, 10);
			
			obj2.style.display = "block";
			currentHeight = obj.offsetHeight;	
			height = obj2.offsetHeight + currentHeight;
			
			function smoothGrow()
			{
				currentHeight += 20;
				obj.style.height = currentHeight + "px";

				if (currentHeight >= height)
				{
					clearInterval(obj.timer);
					obj.style.height = currentHeight + "px";
				}
			}
		}
		function show (id, showHide, origBG)
		{
				if(showHide == 'show')
				{
					expand(id);
					fadeColor(id, document.getElementById(id).style.backgroundColor, '#ffff99', 40, 100,'b');

					document.getElementById(id + '_show').style.display = 'none';
					document.getElementById(id + '_hide').style.display = 'inline';
				} else {
					collapse(id);
					fadeColor(id, '#ffff99', origBG, 40, 100,'b');
					document.getElementById(id + '_show').style.display = 'inline';
					document.getElementById(id + '_hide').style.display = 'none';
				}
		}
    function show_id(ID) {
      var elem = document.getElementById(ID);
      if (elem) {
         if (elem.nodeName == "DIV") elem.style.display = 'block'; 
         else elem.style.display = 'inline';
      }
    }
    function hide_id(ID) {
      var elem = document.getElementById(ID);
      if (elem) {
         elem.style.display = 'none';
      }
    }
    
    function hide_show_id(ID,aID,hstr,sstr) {
      var elem = document.getElementById(ID);
      var a = document.getElementById(aID);
      if (elem) {
         if (elem.style.display == "none") {
            if (elem.nodeName == "DIV") elem.style.display = 'block'; 
            else elem.style.display = 'inline';
            if (a) {
               var t = a.innerHTML.replace(sstr,hstr);
               a.innerHTML = t;
            }
         } else {
            elem.style.display = 'none';
            if (a) {
               var t = a.innerHTML.replace(hstr,sstr);
               a.innerHTML = t;
            }
         }
      }
    }
    function hide_show_menu() {
        hide_show_id("nav_area","toggle_nav","hide","show");
        /*
        var nav_area = document.getElementById("nav_area");
        var mttd = document.getElementById("maintabletd");
        var mt = document.getElementById("maintable");
        if (nav_area.style.display=="none") {
          mt.style.width = "800";
          mttd.style.width = "800";
        } else {
          mt.style.width = "";
          mttd.style.width = "";
        }
        */
    }
	function isNotEmpty(elem) {
        var str = elem.value;
    var re = /.+/;
    //alert("Checking " + elem.name + "...");
    if(!str.match(re)) {
        alert("Please fill in the " + elem.name);
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        submit_okay = false;
        return false;
    } else {
        return true;
    }
}
function isEmpty(elem) {
    var str = elem.value;
    var re = /.+/;
    if(!str.match(re)) {
        return true;
    } else {
        return false;
    }
}
//validates that the entry is a positive or negative number
function isNumber(elem) {
        var str = elem.value;
    var re = /\d*/;
    str = str.toString();
    if (!str.match(re)) {
        alert("Enter only numbers into the field.");
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        submit_okay = false;
        return false;
    }
    return true;
}


// validate that the user made a selection other than default
function isChosen(select) {
    if (select.selectedIndex == 0) {
        alert("Please make a choice from the list.");
        return false;
    } else {
        return true;
    }
}

// validate that the user has checked one of the radio buttons
function isValidRadio(radio) {
    var valid = false;
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            return true;
        }
    }
    alert("Make a choice from the radio buttons.");
    return false;
}

function focusElement(formName, elemName) {
    var elem = document.forms[formName].elements[elemName];
    elem.focus();
    elem.select();
}
function isEmailAddr(elem) {
   var str = elem.value;
   var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
   if (!str.match(re)) {
      alert("Improperly formated e-mail address.");
      setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
      return false;
   } else {
      return true;
   }
}
function checkEMail(elem) {
   if (isEmpty(elem)) {
     // Empty is okay
     return true;
   } else {
     // Otherwise must be properly formated
     return isEmailAddr(elem);
   } 
}
function switch_page(page){
     //alert('Next Page : '+page);
     setTimeout("window.location.href = '"+page+"';",10000);
}

String.prototype.toProperCase = function()
{
  return this.toLowerCase().replace(/^(.)|[\s\-](.)/g, 
      function($1) { return $1.toUpperCase(); });
}
function make_proper(id) {
  var elem = document.getElementById(id);
  if (elem) {
    str = elem.value.toProperCase();
    str = str.replace(/\sLlc/,' LLC');
    elem.value = str;
    elem.focus();
  }
}
function bodyFS(sz,lh) {
    document.body.style.fontSize = sz;
    document.body.style.lineHeight = lh;
    var cssstr = "body {font-size:"+sz+"; line-height:"+lh+";}";
    // Clear the User CSS when the font is set to 13px
    if (sz == "13px") cssstr = "Reset";
    save_user_css(cssstr);
}

//Gets the browser specific XmlHttpRequest Object
function cssXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
        return false;
	}
}

var save_css_Req = false;
function save_user_css(cssstr) {
    if (!save_css_Req) save_css_Req = cssXmlHttpRequestObject();
    if (save_css_Req) {
     	if (save_css_Req.readyState == 4 || save_css_Req.readyState == 0) {
		   var str = escape(cssstr);
		   save_css_Req.open("GET", '/members/user_css.php?CSS=' + str, true);
		   save_css_Req.onreadystatechange = handle_save_css_req; 
		   save_css_Req.send(null);
	    }
	}
}
function handle_save_css_req() {
	if (save_css_Req.readyState == 4) {
		var str = save_css_Req.responseText;
		window.status = str;
		//alert(str);
	}
}


