function slideInOut(obj)
{
	if ($(obj+":first").is(":hidden")) {
		$(obj).slideDown("normal");
	} else {
		$(obj).slideUp("normal");
	}

}

function slideIn(obj){ $(obj).slideUp("normal"); }
function slideOut(obj){ $(obj).slideDown("normal"); }

function slideInOutPanel(divID,btnID)
{
	if ($(divID+":first").is(":hidden")) {
		$(btnID).removeClass('x-tool-collapse-south');
		$(btnID).addClass('x-tool-expand-south');
	} else {
		$(btnID).removeClass('x-tool-expand-south');
		$(btnID).addClass('x-tool-collapse-south');
	}
	slideInOut(divID);
}

function slideInPanel(divID,btnID)
{
	$('#'+btnID).removeClass('x-tool-expand-south');
	$('#'+btnID).addClass('x-tool-collapse-south');
	$(divID).slideUp("normal");
}

function slideOutPanel(divID,btnID)
{
	$('#'+btnID).removeClass('x-tool-collapse-south');
	$('#'+btnID).addClass('x-tool-expand-south');
	$(divID).slideDown("normal");
}

//functions for the panel class
var addClassBtn = function() {
	$('#'+this.id).addClass('x-btn-over');
};
var removeClassBtn = function() {
	$('#'+this.id).removeClass('x-btn-over');
};
var addClassFieldFocus = function() {
	$('#'+this.id).addClass('x-form-focus');
};
var removeClassFieldFocus = function() {
	$('#'+this.id).removeClass('x-form-focus');
};

$("select").bind("focus",addClassFieldFocus);
$("select").bind("blur",removeClassFieldFocus);
$("input").bind("focus",addClassFieldFocus);
$("input").bind("blur",removeClassFieldFocus);
$("textarea").bind("focus",addClassFieldFocus);
$("textarea").bind("blur",removeClassFieldFocus);
$(".x-btn-wrap").bind("mouseover",addClassBtn);
$(".x-btn-wrap").bind("mouseout",removeClassBtn);

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function countCharLeft(txtarea,counterarea,text,numcharslimit) {
	var txtareaObj=getObject(txtarea);
	var counterareaObj=getObject(counterarea);
	var longitud=numcharslimit - txtareaObj.value.length;
	if(longitud <= 0) {
		longitud=0;
		text='<span class="disable"> '+text+' </span>';
		txtareaObj.value=txtareaObj.value.substr(0,numcharslimit);
	}
	counterareaObj.innerHTML = text.replace("{CHAR}",longitud);
}

function textCounter(field, cntfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		cntfield.value = maxlimit - field.value.length;
	}
}

function toggleVisibility(elId) {
	var elem = document.getElementById(elId);
	if (elem.style.display == "none") {
		elem.style.display = "";
	} else {
		elem.style.display = "none";
	}
	document.body.focus();
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
	return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	if(radioObj.checked)
	return radioObj.value;
	else
	return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
	return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function getfileextension(filename)
{
	if( filename.length == 0 ) { 
		return "";
	}
	
	var dot = filename.lastIndexOf(".");
	
	if( dot == -1 ) {
		return "";
	}
	
	var extension = filename.substr(dot+1,filename.length);
	
	if (extension != undefined) {
		extension = extension.toLowerCase();
	}
	
	return extension;
}
function AddToFavorites(title,url)
{
	if (window.sidebar) { // Mozilla Firefox Bookmark
		alert("Make sure you uncheck the 'Load this bookmark in the sidebar' checkbox when adding this bookmark");
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title);
	} else {
		alert("This is not supported on your browser.  Try typing 'Ctrl + D' to bookmark this page.");
	}
}