$(function()
{
	$("#hideChangeLog").click(function()
	{
		$("#tm4b-changing").fadeOut();
		$.ajax(
		{
			type: "GET",
			url: "http://www.tm4b.com/_static/ajax-controls.php",
			data: "action=hideChangeLog"
		});
		return false;
	});

	$("#helpdeskQuickTexts .helpdeskQuickTexts div").click(function()
	{
		var existingMessage = $("#new_message").val();
		var quickText = $(this).attr("class"); 
		quickText = quickText.replace("\n\n", "\n\n");
		var newMessage = existingMessage + quickText + "\n\n";
		$("#new_message").val(newMessage);
	});

	$("form").submit(function()
	{
		$(this).find(" :submit").attr('disabled', 'disabled');
	});
});
 
/*Character counter 1*/
function textCounter(areaName,cntfield) 
{
	var areaName = areaName.value;
	areaName = areaName.replace("[","[[");
	areaName = areaName.replace("]","]]");
	areaName = areaName.replace("{","{{");
	areaName = areaName.replace("}","££");
	areaName = areaName.replace("€","€€");
	areaName = areaName.replace("^","^^");
	areaName = areaName.replace("|","||");
	areaName = areaName.replace("~","~~");
	areaName = areaName.replace("\\","\\\\");
	cntfield.value = areaName.length;
}

function realignTextLength(text) 
{
	text = text.replace("[","[[");
	text = text.replace("]","]]");
	text = text.replace("{","{{");
	text = text.replace("}","££");
	text = text.replace("€","€€");
	text = text.replace("^","^^");
	text = text.replace("|","||");
	text = text.replace("~","~~");
	text = text.replace("\\","\\\\");
	return text;
}

/*Check/Uncheck All for Bulk Recipients*/
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName]) return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes) return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes) 	objCheckBoxes.checked = CheckValue;
	else for(var i = 0; i < countCheckBoxes; i++) objCheckBoxes[i].checked = CheckValue;
}

/*JS Equivalent of php_self*/
baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1) || "index.php";

/*JS Equivalent of trim*/
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

/*Popup to confirm action with custo message*/
function confirmSubmit(msg)
{
	var agree=confirm(msg);
	if(agree) return true;
	else return false;
}

/*This function opens up a new window*/
function popup(url, name, width, height)
{
	newwindow=window.open(url,name,'height='+ height +',width='+ width +',top=200,left=50,scrollbars=1,resizable=1');
	if(window.focus) newwindow.focus();
	return false;
}


function popupReceipt(url, name)
{
	newwindow=window.open(url,name,'height=800,width=600,top=200,left=50,scrollbars=1,resizable=1,menubar=1');
	if(window.focus) newwindow.focus();
	return false;
}



/*These functions are for clearing input*/
function clearField(field)
{
	if(field.value == field.defaultValue) field.value = "";
}

function checkField(field)
{
	if(field.value == "") field.value = field.defaultValue;
}
