


function toggleVisibility(id) {
	// reset cursor to default cursor
	var b = null;
	if (document.documentElement && document.documentElement.scrollTop)
		b = document.documentElement;
	else if (document.body)
	b = document.body;
	if (b != null) b.style.cursor='default';
	
	// toggle visibility
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(id).style;
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[id].style;
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[id].style;
	}
	
	if(style2.display) {
		style2.display = style2.display == "none" ? "block" : "none";	
	} else {
		style2.display = "block";
	}
}

function toggleAlertBox(id) {
	toggleVisibility(id);
}

function toggleLayer(whichLayer)
{
	// reset cursor to default cursor
	var b = null;
	if (document.documentElement && document.documentElement.scrollTop)
		b = document.documentElement;
	else if (document.body)
	b = document.body;
	if (b != null) b.style.cursor='default';

	// toggle visibility
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function utf8_len (string)
{
    var len = string.length;
    var utf8_len=0;
    for (var i=0; i<len; i++)
    {
        var c = string.charCodeAt(i);
        if(c < 128) { // 1 byte character
            utf8_len++;
        } else if ((c>127) && (c<2048)) { // 2 byte character, skip next byte
            utf8_len+=2;
        }
        else { // 3 byte character, skip next 2 bytes
            utf8_len+=3;
        }
    }

    return utf8_len;
}

function getMaxCharacters(string, maxLengthInBytes) {
	var len = string.length;
	var old_length;
    var utf8_len=0;
    for (var i=0; i<len; i++)
    {
    	old_length = utf8_len;
        var c = string.charCodeAt(i);
        if(c < 128) { // 1 byte character
            utf8_len++;
        } else if ((c>127) && (c<2048)) { // 2 byte character, skip next byte
            utf8_len+=2;
        }
        else { // 3 byte character, skip next 2 bytes
            utf8_len+=3;
        }
        
        if(utf8_len > maxLengthInBytes) {
        	return i;
        }
    }
    return utf8_len;
}

function imposeMaxLength(Object, MaxLen)
{
	if(utf8_len(Object.value) > MaxLen) {
		alert('The maximum number of characters has been reached. Your input will be trimmed.')
		var maxChars = getMaxCharacters(Object.value, MaxLen);
		Object.value = Object.value.substring(0, maxChars);
		Object.scrollTop = Object.scrollHeight - Object.clientHeight;
	}
}

function rowsPerPageChanged(selectBox) {
	var uri = document.location.href;
	rowsPerPageChanged(selectBox, uri);
}

function rowsPerPageChanged(selectBox, uri) {
	//var selectBox = document.getElementById('numberOfRows');
	var value = selectBox;
	var index = uri.indexOf("?");
	if( index > 0) {
		var parameters = uri.substring(index+1, uri.length);
		uri = uri.substring(0, index) + '?';
		var nameValuePairs = parameters.split("&");
	
		for(var i=0; i<nameValuePairs.length; i++) {
			var nameValue = nameValuePairs[i].split("=");
			if(nameValue[0] != "rowsPerPage" && nameValue[0] != "pageNo") {
				uri += nameValue[0] + '=' + nameValue[1] + '&';
			}
		}
		uri += 'rowsPerPage=' + value + '&pageNo=1';
		
	} else {
		uri += '?rowsPerPage=' + value + '&pageNo=1';
	}
	
	document.location.href = uri;
}

function showSelectBox(id){
	document.getElementById(id).style.height = "auto";
	document.getElementById(id).style.visibility = "visible";
}

function hideSelectBox(id){	
	document.getElementById(id).style.visibility = "hidden";
	document.getElementById(id).style.height = "0.1px";
}

function showFirstMenuPoint(idName){
	var i = 2;
	var id = idName + i;
	
	while(document.getElementById(id) != null){
		document.getElementById(id).style.display = "none";
		
		i++;
		id = idName + i;		
	}
}

function showHideMenu(idName, number){

	var i = 1;
	var id = idName + i;
		
	while(document.getElementById(id) != null){
		if(i != number){
			document.getElementById(id).style.display = "none";
			
		}else{
			document.getElementById(id).style.display = "block";			
		}
		i++;
		id = idName + i;
	}
}

function showDevice(idName, name){

	var i = 1;
	var id = idName + i;

	while(document.getElementById(id) != null){
		if(document.getElementById(id).title == name){
			document.getElementById(id).style.display = "block";
			document.getElementById(id+'showicon').style.display = "none";
			document.getElementById(id+'hideicon').style.display = "block";			
			document.location.hash="#"+name;
		}	
		i++;
		id = idName + i;
	}
	iePositionWorkaround();	
}

function showOrHide(id){	

	var element = document.getElementById(id);	

	if(element.style.display == "" || element.style.display == "none"){
		element.style.display = "block";
		document.getElementById(id+'showicon').style.display = "none";
		document.getElementById(id+'hideicon').style.display = "block";
	}else{
		element.style.display = "none";		
		document.getElementById(id+'showicon').style.display = "block";
		document.getElementById(id+'hideicon').style.display = "none";	
	}
	iePositionWorkaround();	
}

function showAll(idName){

	var i = 1;
	var id = idName + i;

	while(document.getElementById(id) != null){
		document.getElementById(id).style.display = "block";
		document.getElementById(id+'showicon').style.display = "none";
		document.getElementById(id+'hideicon').style.display = "block";
		i++;	
		id = idName + i;
		
	}
	iePositionWorkaround();
}

function hideAll(idName){

	var i = 1;
	var id = idName + i;
	
	while(document.getElementById(id) != null){	
		document.getElementById(id).style.display = "none";
		document.getElementById(id+'showicon').style.display = "block";
		document.getElementById(id+'hideicon').style.display = "none";
		i++;
		id = idName + i;
	}
	iePositionWorkaround();
}



function iePositionWorkaround(){		
		document.getElementById('tlnk').style.position ="relative";	
		document.getElementById('tlnk').style.position ="absolute";
}