function showElementById(id) {
	$('#' + id).show();
}

function hideElementById(id) {
	$('#' + id).hide();
}

function showElement(element) {
	element.style.display = "";
}

function hideElement(element) {
	element.style.display = "none";
}

function convertDateFormat(dateFormat){
	var convertedFormat = dateFormat.replace("MM","mm");
	convertedFormat = convertedFormat.replace("yyyy","yy");
	return convertedFormat;
}

function isFormValid(formId){
	return $('#' + formId).validationEngine({
		returnIsValid	: true
	});
}

function removeValidationErrors(){
	$.validationEngine.closePrompt('.formError',true);
}

function submitFormOnEnter(formId, buttonId){
	$('#' + formId + ' :input').keypress(function(e){
		if(e.which == 13){
			e.preventDefault();
			jQuery('#' + buttonId).focus().click();
		}
	});
}

function createChart(id, xml, type, width, height, contextPath){
	var myChart;
	if (type == "pie3D"){
		myChart = new FusionCharts(contextPath + "/charts/FCF_Pie3D.swf", "chartId_" + id, width, height);
	}else if (type == "gantt"){
		myChart = new FusionCharts(contextPath + "/charts/FCF_Gantt.swf", "chartId_" + id, width, height);
	}else if (type == "MSLine"){
		myChart = new FusionCharts(contextPath + "/charts/FCF_MSLine.swf", "chartId_" + id, width, height);
	}else{
		myChart = new FusionCharts(contextPath + "/charts/FCF_Line.swf", "chartId_" + id, width, height);
	}
	myChart.addParam("WMode", "Transparent");
	myChart.setDataXML(xml);
	myChart.render(id);
}

function confirmAndClickOn(clazz, message){
	jConfirm(clazz, message, 'Confirmation', function(clazz, r) {
	    if (r){
	    	$('.' + clazz).click();
	    }
	});
}

function setSelectedByLabelPart(selectId, label){
	options = document.getElementById(selectId).options;
	for (var i=0; i < options.length; i++){
		if (options[i].text.indexOf(label) > -1){
			options[i].selected = true;
			break;
		}	
	}
}

function getGMTTimezoneOffset(){
	  var offset = new Date().getTimezoneOffset() / 60 * -1;
	  var gmtOffset = "GMT";
	  
	  if (offset != 0){
		  var hours = Math.floor(offset);
		  var sign = "+";
		  if (offset < 0){
		  	hours = Math.abs(Math.ceil(offset));
		  	sign = "-";
		  }
		  var mins = Math.abs(60 * (offset % hours));
		  if (mins == 0){
		  	mins = "00";
		  }  
		  if (hours < 10){
			hours = "0" + hours;
		  }
		  gmtOffset = gmtOffset + sign + hours + ":" + mins;  
	  }
	  return gmtOffset;
}

function roundTo5(value){
	return Math.round(parseInt(value)/5)*5;
}
