// v1.2.0

// Module: BOOKMARK
function CCms_AddToFavorites(){ 
	if(document.all)
		window.external.AddFavorite(window.location, document.title);
	else{
		if(window.sidebar)
			window.sidebar.addPanel(document.title, window.location, "")
	}
}

// PANEL:PARSER
function CCms_InsertClosingText(id, start, end){
	var input = document.getElementById(id);
	input.focus();
	
	if(document.selection){
		var sel = document.selection.createRange();
		if(sel.text != "")
			sel.text = start + sel.text + end;
	}
	else{
		var selstart = input.selectionStart;
		var selend = input.selectionEnd;
		var text = input.value.substring(selstart, selend);
		if(selstart != selend)
			input.value = input.value.substring(0, selstart) + start + text + end + input.value.substring(selend);
	}
}
function CCms_InsertText(id, tag){
	var input = document.getElementById(id);
	input.focus();
	
	if(document.selection){
		var range = document.selection.createRange();
		range.text = tag;
	}
	else{
		var selstart = input.selectionStart;
		var selend = input.selectionEnd;
		var text = input.value.substring(selstart, selend);
		input.value = input.value.substring(0, selstart) + tag + input.value.substring(selend);
	}
}

// LAYERS (FLYING DIVS)
function ShowLayer(id, visible){
	if(visible)
	{
		document.getElementById(id).style.visibility = 'visible';
		document.getElementById(id).style.top = window.event.y+20;//+document.documentElement.scrollTop;
		document.getElementById(id).style.left = window.event.x;//+document.documentElement.scrollLeft;
	}
	else
		document.getElementById(id).style.visibility = 'hidden';
}
function ToggleLayer(id)
{
	if(document.getElementById(id).style.visibility != 'visible')
	{
		document.getElementById(id).style.visibility = 'visible';
		document.getElementById(id).style.top = window.event.y;//+20+document.documentElement.scrollTop;
		document.getElementById(id).style.left = window.event.x;//+document.documentElement.scrollLeft;
	}
	else
		document.getElementById(id).style.visibility = 'hidden';
}

// TABS
function ToggleTab(id){
	SetTab(id, !GetTab(id));
}

function SetTab(id, visible){
	//SetCookie('ccms_tab_'+id, visible); // Save tab position

	if(visible == 'true')
		visible = true;
	if(visible == 'false')
		visible = false;
	if(visible == '')
		visible = false;
	
	if(visible){
		document.getElementById(id).style.display = "";
		document.getElementById(id).style.visibility = 'visible';
		if(document.images['img_'+id] != null)
			document.images['img_'+id].src = "images/icons/triangle_b.gif";
	}else{
		document.getElementById(id).style.display = "none";
		document.getElementById(id).style.visibility = 'hidden';
		if(document.images['img_'+id] != null)
			document.images['img_'+id].src = "images/icons/triangle_r.gif";
	}
}
function GetTab(id){
	if(document.getElementById(id).style.visibility == 'hidden')
		return false;
	else
		return true;
}

// COOKIES
function SetCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	
	if(nDays!=null && nDays!=0) {
		expire.setTime(today.getTime() + 3600000*24*nDays);
		document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
	}
	else
		document.cookie = cookieName+"="+escape(cookieValue);
}
function GetCookie( name ){
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
