﻿$(document).ready(function () {
	// define our own 'if exists' function
	jQuery.fn.exists = function () { return ($(this).length > 0); }

	// init displaying loading element
	// using live() method, to make it works even after ajax request
	$(".L").live('click', function () {
		ShowLoading();
	});

	// EMAIL TAGS
	if ($(".emailTag").exists()) {
		$('.emailTag').click(function () {
			var ins = $(this).attr("alt");
			insertAtCaret('msg', ins);
		});
	}

	// FLOATING OPTIONS
	InitFloatingOptions();

	// DOUBLE CHECKBOXES ON PROJECT TRANSLATIONS LIST (one contains translationId, second - userId)
	$('input.chkTranslation').live('click', function () {
		$(this).next('input').attr("checked", $(this).attr('checked'));
	});

	// TOGGLE GENGO COMMENTS
	$('.toggleGengoComments').live('click', function (e) {
		e.preventDefault();
		if ($(this).next('.gengo_comments').is(':visible')) {
			$(this).next('.gengo_comments').hide();
			$(this).text("show");
		}
		else {
			$(this).next('.gengo_comments').show();
			$(this).text("hide");
		}
	});
});

function InitFloatingOptions() {
	if ($(".floatingOptions").exists()) {
		var floatingOptsInitMargin = parseInt($(".floatingOptions").css("margin-top").substring(0, $(".floatingOptions").css("margin-top").indexOf("px")))
		var floatingOptsInitAbsTop = $(".floatingOptions").offset().top;

		$(window).scroll(function () {
			if ($(document).scrollTop() > floatingOptsInitAbsTop) {
				var offset = 5 + floatingOptsInitMargin + ($(document).scrollTop() - floatingOptsInitAbsTop) + "px";
				$(".floatingOptions").css("margin-top", offset);
			}
			else {
				$(".floatingOptions").css("margin-top", floatingOptsInitMargin);
			}
		});
	}
}

function edit(editPanelId, data) {
	// fill edit panel 
	for (var i in data) {
		var value = (data[i] == null) ? '' : data[i];
		var obj = $("[name='" + i + "'], [id='" + i + "']");

		// set checkbox
		if (obj.is("input[type='checkbox']")) {
			obj.attr("checked", value);
		}
		else if (obj.is("select[type='select-one']")) {
			obj.val(value);
		}
		else if (obj.is("input")) {
			obj.val(value);
		}
		else if (obj.is("textarea")) {
			obj.val(value);
		}
		else if (obj.is("img")) {
			obj.attr('src', value);
		}
		else {
			obj.text(value);
		}

		// clear previous validation messages
		$('#' + i + '_validationMessage').removeClass(Sys.Mvc.FieldContext._validationMessageErrorCss);
		$('#' + i + '_validationMessage').addClass(Sys.Mvc.FieldContext._validationMessageValidCss);
		$('#' + i + '_validationMessage').html('');
	}

	$('#validationSummary').removeClass(Sys.Mvc.FormContext._validationSummaryErrorCss);
	$('#validationSummary').addClass(Sys.Mvc.FormContext._validationSummaryValidCss);
	$('#validationSummary').html('');

	if (editPanelId != null) {
		showEditPanel(editPanelId);
	}
}

function edit2(editPanelId, ajaxContext) {
	eval($('#' + editPanelId + ' script:last-child')[0].innerHTML);

	Sys.Mvc.FormContext._Application_Load();

	if (editPanelId != null) {
		showEditPanel2(editPanelId);
	}
}

function editHistory(editPanelId, data) {
	if (displayMessageFromJqueryJson(data)) {
		HideLoading();
		HideLoading2();
	}

	// clear table
	$("#tblStringHistory tr").remove();
	$('<tr class="tbl_std_header"><th>String</th><th>Date</th></tr>').appendTo("#tblStringHistory");

	var months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

	// fill table
	for (var i in data) {
		var row = "";
		var d = new Date(parseInt(data[i].Date.substr(6)));

		row += "<tr>";
		row += "<td>" + $("<span/>").text(data[i].String).html() + "</td>";
		row += "<td>" + d.getDate() + "-" + months[d.getMonth()] + "-" + d.getFullYear() + " " + d.getHours() + ":" + formatSecs(d.getMinutes()) + ":" + formatSecs(d.getSeconds()) + "</td>";
		row += "</tr>";

		$(row).appendTo("#tblStringHistory");

		// clear previous validation messages
		//$('#' + i + '_validationMessage').html('');
	}

	showEditPanel(editPanelId);
}

function editLoginHistory(editPanelId, data) {
	// clear table
	$("#tblLoginHistory tr").remove();
	$('<tr class="tbl_std_header"><th>Date</th><th>IP</th></tr>').appendTo("#tblLoginHistory");

	var months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

	// fill table
	for (var i in data) {
		var row = "";
		var d = new Date(parseInt(data[i].Date.substr(6)));

		row += "<tr>";
		row += "<td>" + d.getDate() + "-" + months[d.getMonth()] + "-" + d.getFullYear() + " " + d.getHours() + ":" + formatSecs(d.getMinutes()) + ":" + formatSecs(d.getSeconds()) + "</td>";
		row += "<td>" + $("<span/>").text(data[i].IP).html() + "</td>";
		row += "</tr>";

		$(row).appendTo("#tblLoginHistory");
	}

	showEditPanel(editPanelId);
}

function editVerify(editPanelId, data, projectId) {
	$("#projectId").attr('value', projectId);

	// clear table
	$("#tblVerification tr").remove();
	$('<tr class="tbl_std_header"><th>Resource</th><th>Strings</th><th>Error</th></tr>').appendTo("#tblVerification");

	// alter row styles
	var rowStyles = new Array("tbl_std_row1", "tbl_std_row2");
	var k = 1;

	// fill table
	for (var i in data) {
		k = ++k % 2;
		var row = "";

		row += '<tr class="' + rowStyles[k] + '">';
		row += "<td>" + data[i].Resource + "</td>";
		row += "<td><b>Source:</b><br/>" + data[i].SourceString + "<br/><br/><b>Target:</b><br/>" + data[i].TargetString + "</td>";
		row += "<td>" + data[i].ErrMsg + "</td>";
		row += "</tr>";

		$(row).appendTo("#tblVerification");
	}

	showEditPanel(editPanelId);
}

function showEditPanel(editPanelId) {
	//Set height and width to mask to fill up the whole screen   
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();
	$('#edit_mask').css({ 'width': maskWidth, 'height': maskHeight });

	//show transparent mask
	$('#edit_mask').fadeTo(0, 0.8);

	//Get the window height and width  
	var winW = 0, winH = 0;
	if (typeof (window.innerWidth) == 'number') {
		//Non-IE
		winW = window.innerWidth;
		winH = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		winW = document.body.clientWidth;
		winH = document.body.clientHeight;
	}

	$("#" + editPanelId).css('left', winW / 2 - $("#" + editPanelId).width() / 2); //Set the popup window to center
	$("#" + editPanelId).fadeIn(0); //show edit panel
	$('#edit_mask').live('click', function () { clearEditAndHide(null, editPanelId); }); //if mask is clicked
	$("#" + editPanelId + " .btn_close").live('click', function (e) { e.preventDefault(); clearEditAndHide(null, editPanelId); });
	HideLoading();
}

function showEditPanel2(editPanelId) {
	//Set height and width to mask to fill up the whole screen   
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();
	$('#edit_mask').css({ 'width': maskWidth, 'height': maskHeight });

	//show transparent mask
	$('#edit_mask').fadeTo(0, 0.8);

	//Get the window height and width  
	var winW = 0, winH = 0;
	if (typeof (window.innerWidth) == 'number') {
		//Non-IE
		winW = window.innerWidth;
		winH = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		winW = document.body.clientWidth;
		winH = document.body.clientHeight;
	}

	$("#" + editPanelId).css('left', winW / 2 - $("#" + editPanelId).width() / 2); //Set the popup window to center
	$("#" + editPanelId).fadeIn(0); //show edit panel
	$('#edit_mask').live('click', function () { clearEditAndHide2(null, editPanelId); }); //if mask is clicked
	$("#" + editPanelId + " .btn_close").live('click', function (e) { e.preventDefault(); clearEditAndHide2(null, editPanelId); });
	HideLoading();
}

function formatSecs(sec) {
	if (sec < 9) {
		return "0" + sec;
	} else {
		return sec;
	}
}

function add(editPanelId, startupValues) {
	if (startupValues != null) {
		for (var i in startupValues) {
			// set checkbox
			if ($('#' + i).is("input[type='checkbox']")) {
				$('#' + i).attr("checked", startupValues[i]);
			}
			else if ($('#' + i).is("select[type='select-one']")) {
				$('#' + i).val(startupValues[i]);
			}
			else if ($('#' + i).is("input")) {
				$('#' + i).val(startupValues[i]);
			}
			else if ($('#' + i).is("textarea")) {
				$('#' + i).val(startupValues[i]);
			}
			else {
				$('#' + i).text(startupValues[i]);
			}
			// clear previous validation messages
			$('#' + i + '_validationMessage').removeClass(Sys.Mvc.FieldContext._validationMessageErrorCss);
			$('#' + i + '_validationMessage').addClass(Sys.Mvc.FieldContext._validationMessageValidCss);
			$('#' + i + '_validationMessage').html('');
		}
	}

	$('#validationSummary').removeClass(Sys.Mvc.FormContext._validationSummaryErrorCss);
	$('#validationSummary').addClass(Sys.Mvc.FormContext._validationSummaryValidCss);
	$('#validationSummary').html('');

	showEditPanel(editPanelId);
}

function add2(editPanelId, ajaxContext) {
	eval($('#' + editPanelId + ' script:last-child')[0].innerHTML);

	Sys.Mvc.FormContext._Application_Load();

	if (editPanelId != null) {
		showEditPanel2(editPanelId);
	}
}

function addTemplateResource(addFormId, projectId) {
	var translations = '';
	var items = document.getElementsByName('chkTranslation');

	for (var i = 0; i < items.length; ++i) {
		if (items[i].checked) {
			translations += '|' + items[i].id.substr(15);
		}
	}

	add(addFormId, { NewProjectID: projectId, NewTranslationIDs: translations });
}

function clearEditAndHide(ajaxContext, editPanelId) {
	var hide = false;

	if (ajaxContext == null) {
		hide = true;
	}
	else {
		var statusCode = ajaxContext.get_response().get_statusCode();

		if (statusCode !== 222)
			hide = true;
	}

	if (hide == true) {
		document.getElementById(editPanelId).style.display = 'none';
		document.getElementById('edit_mask').style.display = 'none';
	}

	HideLoading();
}

function clearEditAndHide2(ajaxContext, editPanelId) {
	var hide = false;

	if (ajaxContext == null) {
		hide = true;
	}
	else {
		var statusCode = ajaxContext.get_response().get_statusCode();

		if (statusCode !== 222)
			hide = true;
	}

	if (hide == true) {
		$('#' + editPanelId).empty();
		document.getElementById(editPanelId).style.display = 'none';
		document.getElementById('edit_mask').style.display = 'none';
	}

	HideLoading();
}

function displayMessageFromJson(ajaxContext) {
	var msg = JSON.parse(ajaxContext._response._xmlHttpRequest.responseText);

	if (msg.NewCaptcha != null) {
		$('#CaptchaUrl').attr('src', msg.NewCaptcha);
		$('#Captcha').val('');
	}

	alert(msg.Message);
}

function displayMessageFromJqueryJson(response) {
	if (response.Message != null) {
		alert(response.Message);
		return true;
	} else
		return false;
}

function switchUpdateTargetIfModelInvalid(ajaxContext, newUpdateTargetId) {
	var statusCode = ajaxContext.get_response().get_statusCode();

	//222 is out internal code meaning that model has been invalid
	if (statusCode === 222)
		ajaxContext._updateTarget = document.getElementById(newUpdateTargetId);
}

function refreshUserTypeList(url, updateTargetId) {
	$.ajax({
		type: "GET",
		url: url,
		dataType: "html",
		success: function (result) {
			$('#' + updateTargetId).html(result);
		}
	});
}

function refreshUserProjectRoleList(url, updateTargetId) {
	$.ajax({
		type: "GET",
		url: url,
		dataType: "html",
		success: function (result) {
			$('#' + updateTargetId).html(result);
		}
	});
}

function setRolesForUserType(data) {
	$('#userRolesCheckboxList input:checkbox').attr("checked", false); // clear previous selection

	for (var i in data) {
		$('#role_' + data[i]).attr("checked", true);
	}
	HideLoading();
}

var setProjectRolesForUserIndex = 0;

function setProjectRolesForUser(data, updateIndex) {
	HideLoading();

	if (updateIndex != setProjectRolesForUserIndex)
		return;

	$('#userProjectRolesCheckboxList input:checkbox').attr("checked", false); // clear previous selection

	if (data != null) {
		for (var i in data) {
			$('#projectRole_' + data[i]).attr("checked", true);
		}
	}
}

function Init_Roles_UserTypeList(rootPath) {
	$("#UserTypeList").live('change click', function () {
		ShowLoading();
		$.getJSON(rootPath + 'Role.aspx/ListRolesForUserType?userTypeId=' + this.options[this.selectedIndex].value, null, function (data) { setRolesForUserType(data); });
	});
}

function FillNewLanguagePreset(rootPath, id) {
	ShowLoading();
	$.getJSON(rootPath + 'Language.aspx/GetDotNetLanguage?cultureId=' + id, null, function (data) { edit('newLanguageDetails', data); });
}


function Init_ProjectRoles_UserList(rootPath, userListId, projectListId) {
	var userList = document.getElementById(userListId);
	var projectList = document.getElementById(projectListId);

	$('#' + userListId).live('change click', function () {
		var updateIndex = ++setProjectRolesForUserIndex;

		if (userList.selectedIndex > -1 && projectList.selectedIndex > -1) {
			ShowLoading();
			$.getJSON(rootPath + 'Role.aspx/ListProjectRolesForUser?userId=' + userList.options[userList.selectedIndex].value + '&projectId=' + projectList.options[projectList.selectedIndex].value, null, function (data) { setProjectRolesForUser(data, updateIndex); });
		} else {
			setProjectRolesForUser(null, updateIndex);
		}
	});
	$('#' + projectListId).live('change click', function () {
		var updateIndex = ++setProjectRolesForUserIndex;

		if (userList.selectedIndex > -1 && projectList.selectedIndex > -1) {
			ShowLoading();
			$.getJSON(rootPath + 'Role.aspx/ListProjectRolesForUser?userId=' + userList.options[userList.selectedIndex].value + '&projectId=' + projectList.options[projectList.selectedIndex].value, null, function (data) { setProjectRolesForUser(data, updateIndex); });
		} else {
			setProjectRolesForUser(null, updateIndex);
		}
	});
}

function ShowLoading() {
	//Set height and width to mask to fill up the whole screen   
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();
	$('#loading_mask').css({ 'width': maskWidth, 'height': maskHeight });

	//show transparent mask
	$('#loading_mask').fadeTo(0, 0.0);

	//Get the window height and width  
	var winW = 0, winH = 0;
	if (typeof (window.innerWidth) == 'number') {
		//Non-IE
		winW = window.innerWidth;
		winH = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		winW = document.body.clientWidth;
		winH = document.body.clientHeight;
	}

	//Set the popup window to center
	$("#loading").css('top', winH / 2 - $("#loading").height() / 2);
	$("#loading").css('left', winW / 2 - $("#loading").width() / 2);
	$("#loading").fadeIn(0); //show loading panel
}

function ShowLoading2() {
	document.getElementById('loading2').style.display = 'block';
}

function HideLoading() {
	document.getElementById('loading').style.display = 'none';
	document.getElementById('loading_mask').style.display = 'none';
}

function HideLoading2() {
	document.getElementById('loading2').style.display = 'none';
}

function insertAtCaret(areaId, text) { var txtarea = document.getElementById(areaId); var scrollPos = txtarea.scrollTop; var strPos = 0; var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false)); if (br == "ie") { txtarea.focus(); var range = document.selection.createRange(); range.moveStart('character', -txtarea.value.length); strPos = range.text.length; } else if (br == "ff") strPos = txtarea.selectionStart; var front = (txtarea.value).substring(0, strPos); var back = (txtarea.value).substring(strPos, txtarea.value.length); txtarea.value = front + text + back; strPos = strPos + text.length; if (br == "ie") { txtarea.focus(); var range = document.selection.createRange(); range.moveStart('character', -txtarea.value.length); range.moveStart('character', strPos); range.moveEnd('character', 0); range.select(); } else if (br == "ff") { txtarea.selectionStart = strPos; txtarea.selectionEnd = strPos; txtarea.focus(); } txtarea.scrollTop = scrollPos; }

function toggleEditAllStringsFields(editAllId, saveAllId, inputName) {
	if (document.getElementById(saveAllId) == null) return;

	var items = document.getElementsByName(inputName);
	var doShow = ($('#' + saveAllId).css('display') == 'none');

	if (doShow) {
	    translationsWereModified = true;
		$('.' + saveAllId).show();
		$('.edit').hide();
		$('.' + editAllId).val('Cancel');
	}
else {
    translationsWereModified = false;
		$('.' + saveAllId).hide();
		$('.edit').show();
		$('.' + editAllId).val('Edit All');
	}

	for (var i = 0; i < items.length; ++i) {
		var item = items[i];

		$('#' + item.id).val($('#value_' + item.id).val());

		if (doShow) {
			$('#' + item.id).css('display', 'block');
			$('#text_' + item.id).css('display', 'none');
		} else {
			$('#' + item.id).css('display', 'none');
			$('#text_' + item.id).css('display', 'block');
		}
	}
}

function saveAllStrings(editAllId, saveAllId, inputName) {
	if (document.getElementById(saveAllId) == null) return;

	var items = document.getElementsByName(inputName);

	for (var i = 0; i < items.length; ++i) {
		var item = items[i];

		if ($('#' + item.id).val().replace(/\"\"/g, "").indexOf("\"") > -1) {
			alert("Some strings contain a single quotation mark (\").\nA quotation mark (\") must be entered twice to be valid e.g. (\"\")");
			return false;
		}
	}

	for (var i = 0; i < items.length; ++i) {
		var item = items[i];

		$('#' + item.id).css('display', 'none');
		$('#text_' + item.id).css('display', 'block');

		if ($('#' + item.id).val().indexOf(item.id + '_') != 0)
			$('#' + item.id).val(item.id + '_' + $('#' + item.id).val());
	}

	$('.' + saveAllId).hide();
	$('.edit').show();
	$('.' + editAllId).val('Edit All');

	return true;
}

function onEditComplete(ajaxContext, editPanelId, refreshLinkId) {
	HideLoading();
	var statusCode = ajaxContext.get_response().get_statusCode();

	if (statusCode === 200) {
		if (editPanelId != null) {
			var editPane = document.getElementById(editPanelId);

			if (editPane != null) {
				editPane.style.display = 'none';
				document.getElementById('edit_mask').style.display = 'none';
			}
		}

		refresh2(refreshLinkId);

		return false;
	} else {
		return true;
	}
}

function onEditAllComplete(ajaxContext, editPanelId, refreshLinkId) {
	HideLoading();
	var statusCode = ajaxContext.get_response().get_statusCode();

	if (statusCode === 200) {
		if (editPanelId != null) {
			var editPane = document.getElementById(editPanelId);

			if (editPane != null) {
				editPane.style.display = 'none';
				document.getElementById('edit_mask').style.display = 'none';
			}
		}

		refresh();

		return false;
	} else {
		return true;
	}
}

function refresh2(refreshLinkId) {
	if (refreshLinkId != null) {
		var refreshLink = document.getElementById(refreshLinkId);

		if (refreshLink != null) {
			$("#" + refreshLinkId).click();
		}
	}
}

function onComplete(ajaxContext, onSuccess, onFailure, showMsg) {
	HideLoading();
	HideLoading2();

	var statusCode = ajaxContext.get_response().get_statusCode();

	if (statusCode === 222 || statusCode === 400) {
		if (showMsg === true && statusCode === 400)
			displayMessageFromJson(ajaxContext);

		if (onFailure != null)
			onFailure();
	} else {
		if (onSuccess != null)
			onSuccess();
	}
}

function resetValidation() {
	//Removes validation from input-fields
	$('.input-validation-error').addClass('input-validation-valid');
	$('.input-validation-error').removeClass('input-validation-error');
	//Removes validation message after input-fields
	$('.field-validation-error').addClass('field-validation-valid');
	$('.field-validation-error').removeClass('field-validation-error');
	//Removes validation summary 
	$('.validation-summary-errors').addClass('validation-summary-valid');
	$('.validation-summary-errors').removeClass('validation-summary-errors');
}

function selectTranslationCheckboxOnly(id, name) {
	var elements = document.getElementsByName(name);

	for (var i = 0; i < elements.length; ++i) {
		$('#' + elements[i].id).attr('checked', false);
		$('#' + elements[i].id).next('input').attr("checked", false);
	}

	$('#' + id).attr('checked', true);
	$('#' + id).next('input').attr("checked", true);
}

function selectTranslationAllCheckboxes(name, value) {
	var elements = document.getElementsByName(name);

	for (var i = 0; i < elements.length; ++i) {
		$('#' + elements[i].id).attr('checked', true);
		$('#' + elements[i].id).next('input').attr("checked", true);
	}
}

function SetCheckboxes(name, value) {
	$("input[name='" + name + "']").attr('checked', value);
}

function fillGengoJobDetails(jobId, data) {
	//$('#gengo_job_details_' + jobId).show();
	$('#body_original_' + jobId).text(data['body_original']);
	$('#body_translation_' + jobId).text(data['body_translation']);
	$('#credits_' + jobId).text(data['credits']);
	$('#unit_count_' + jobId).text(data['unit_count']);
	$('#tier_' + jobId).text(data['tier']);
	$('#status_' + jobId).text(data['status']);

	var comments = data['comments'];
	var commentsTxt = "<ul>";

	if (comments.length > 0) {
		for (var x = 0; x < comments.length; x++) {
			var comment = comments[x];
			commentsTxt += "<li>";
			commentsTxt += comment['Author'] + ":<br/>";
			commentsTxt += comment['Comment'];
			commentsTxt += "</li>";
		}
		commentsTxt += "</ul>";
	}
	else {
		commentsTxt = "<br/>[no comments]";
	}

	$('#comments_' + jobId).attr('innerHTML', commentsTxt);

	var s = $('#alert_img_' + jobId).attr('src');
	var t = '';
	if (data['ActionRequired'] == true) {
		s = s.replace('g_ok.png', 'g_warn.png');
		t = 'Click to clear alert';
	}
	else {
		s = s.replace('g_warn.png', 'g_ok.png');
		t = 'Click to set alert';
	}
	$('#alert_img_' + jobId).attr('src', s);
	$('#alert_img_' + jobId).attr('title', t);
}

function JobActionChanged(action) {
	if (action == "comment") {
		$('#job_edit_comment').show();
		$('#job_edit_rating').hide();
		$('#job_edit_for_translator').hide();
		$('#job_edit_for_mygengo').hide();
		$('#job_edit_reason').hide();
		$('#job_edit_followup').hide();
		$('#job_edit_captcha').hide();
		$('#job_edit_save').show();
	}
	else if (action == "revise") {
		$('#job_edit_comment').show();
		$('#job_edit_rating').hide();
		$('#job_edit_for_translator').hide();
		$('#job_edit_for_mygengo').hide();
		$('#job_edit_reason').hide();
		$('#job_edit_followup').hide();
		$('#job_edit_captcha').hide();
		$('#job_edit_save').show();
	}
	else if (action == "approve") {
		$('#job_edit_comment').hide();
		$('#job_edit_rating').show();
		$('#job_edit_for_translator').show();
		$('#job_edit_for_mygengo').show();
		$('#job_edit_reason').hide();
		$('#job_edit_followup').hide();
		$('#job_edit_captcha').hide();
		$('#job_edit_save').show();
	}
	else if (action == "reject") {
		$('#job_edit_comment').show();
		$('#job_edit_rating').hide();
		$('#job_edit_for_translator').hide();
		$('#job_edit_for_mygengo').hide();
		$('#job_edit_reason').show();
		$('#job_edit_followup').show();
		$('#job_edit_captcha').show();
		$('#job_edit_save').show();
	}
	else if (action == "force") {
		$('#job_edit_comment').hide();
		$('#job_edit_rating').hide();
		$('#job_edit_for_translator').hide();
		$('#job_edit_for_mygengo').hide();
		$('#job_edit_reason').hide();
		$('#job_edit_followup').hide();
		$('#job_edit_captcha').hide();
		$('#job_edit_save').show();
	}
	else {
		$('#job_edit_comment').hide();
		$('#job_edit_rating').hide();
		$('#job_edit_for_translator').hide();
		$('#job_edit_for_mygengo').hide();
		$('#job_edit_reason').hide();
		$('#job_edit_followup').hide();
		$('#job_edit_captcha').hide();
		$('#job_edit_save').hide();
	}
}

function refresh() {
	location.reload(true);
}

function clickOnEnter(event, itemId) {
	if (event.keyCode == 13) {
		if (itemId != null) {
			var item = document.getElementById(itemId);

			if (item != null) {
				$("#" + itemId).click();
			}
		}
	}
}

function goToOnEnter(event, href) {
	if (event.keyCode == 13) {
		if (href != null) {
			document.location.href = href;
		}
	}
}

function confirmTranslationModeChange() {
	if ($("input[name='IsTranslatedExternally'][type='hidden']").attr('checked') == true
	&& $('#IsTranslatedExternally').attr('checked') == false) {
		if (confirm('Are you sure you want to change translation from myGengo to regular mode?\nmyGengo jobs will be cancelled!'))
			return true;
		else
			return false;
	}
	else
		return true;
}

function confirmChangingPageWhenTranslationModified() {
    if (translationsWereModified == false) {
        return true;
    }
    else {
        if (confirm("Do you want to change page and lose modifications?") == true) { 
            return true;
        }
        else {
            return false;
        }
    }
}
