/**
* function show_hide
* Toggles the visibility of the specified element
* Inputs: id - HTML Document id value e.g. id="element1"
*/
function show_hide(id){
	var visible = document.getElementById(id).style.visibility;
	if(visible == 'hidden'){
		show(id);
	}else{
		hide(id);
	}
}

function show(id){
	document.getElementById(id).style.visibility='visible';
	document.getElementById(id).style.height='100%';
}

function hide(id){
	document.getElementById(id).style.visibility='hidden';
	document.getElementById(id).style.height='0';
}
/*************************************************************/
/**
* function appendValue
* Appends the entered value to the specified element
* Inputs: id - HTML Document id value e.g. id="element1", value - the value to be appended
*/
function appendValue(id,value){
	document.getElementById(id).value = document.getElementById(id).value + value;
}
/**
* function showContent
* Shows the entered content as the Inner HTML of the specified element
* Inputs: id - HTML Document id value e.g. id="element1", content - the content to be displayed
* Notes: Javascript required specific formatting of the content string
* e.g - "<table width=\'100%\' cellpadding=\'3\' cellspacing=\'0\'><tr><td></td></table>"
* escape single quotes ('), and do not put hard line breaks in the content string
* e.g. "<table width=\'100%\' cellpadding=\'3\' cellspacing=\'0\'>
			<tr>
				<td></td>
			</tr>
		</table>"
	*** This will not work ***
			
*/
function showContent(id,content){
	document.getElementById(id).style.visibility='visible';
	document.getElementById(id).innerHTML = content;
	document.getElementById(id).style.height = '100%';
}
/**
* function goToURL
* Redirects to the specified URL
* Inputs: url - the URL to redirect to
*/
function goToURL(url){
	window.location.href = url;
}
/**
* function changeBorderBorder
* Changes the borderColor of the specified element
* Inputs: id - HTML Document id value e.g. id="element1", color - the new color
*/
function changeBorderColor(id,color){
	document.getElementById(id).style.borderColor = color;
}
/**
* function changeFontColor
* Changes the font color of the specified element
* Inputs: id - HTML Document id value e.g. id="element1", color - the new color
*/
function changeFontColor(id,color){
	document.getElementById(id).style.color = color;
}
/**
* function changeBGColor
* Changes the background of the specified element
* Inputs: id - HTML Document id value e.g. id="element1", color - the new color
*/
function changeBGColor(id,color){
	document.getElementById(id).style.background = color;
}
/**
* function changeInnerHTML
* Toggles between the two specified html strings
* Inputs: id - HTML Document id value e.g. id="element1", html, html2 - HTML content to toggle between
*/
function changeInnerHTML(id,html,html2){
	var current_html = document.getElementById(id).innerHTML;
	current_html = replaceString(current_html,'"','\'');
	current_html = trimString(current_html);
	
	if(current_html == html){
		document.getElementById(id).innerHTML = html2;
	}else{
		document.getElementById(id).innerHTML = html;
	}
}
/**
* function replaceString
* Replaces matched needle in the haystack, on the entered string
* Inputs: string - the string to do the replacing on, haystack - the value to be replaced, needle - the new value
*/
function replaceString(string,haystack,needle) {
	var strLength = string.length, txtLength = haystack.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(haystack);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + needle;

    if (i+txtLength < strLength)
        newstr += replaceString(string.substring(i+txtLength,strLength),haystack,needle);

    return newstr;
}
/**
* function replaceString
* Removes leading and trailing white space
* Inputs: str - the string to trim
*/
function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
