var gRequestjson;
var gInterval = 1000;
var gActionId;

/**
 * This function invokes the actual output request by calling the request_handler
 * The request handler manages the action XML, insert an entry in the action table and polls the database
 * The doRequestAjax function retrieves the information send by the request handler and updates the user interface
 */

function sendEngineRequest(){
	
	$.ajax({
		url: "functions/ajax/request_handler.php",
		dataType: "json",
		data: gRequestjson, //the data is set by request specific init functions (global).
		cache: false,
		success: function(requestdata){
			
			if(requestdata.doPoll){
				
				gInterval = requestdata.interval;
				gActionId = requestdata.actionid;
				gTimeOutCounter = 0;
				
				if(requestdata.file){
					gRequestjson.file = requestdata.file;
				}
				pollAction(0,requestdata.timeout);
			} else {
				updateInterface(requestdata);
			}
			
		},
		error: function(){
			updateDialog("An error occured.");
		},
		timeout: function(){
			updateDialog("Time Out");
		}
		
	});
		
}

function updateDialog(msg){
	
	alert(msg);
}

/**
 * Function that polls the database for the status of an 'action'
 * @return
 */
function pollAction(timeoutcounter,timeout) {
	
	$.ajax({
		type: "POST",
		url: "/functions/ajax/action_status.php",
		data: "actionid=" + gActionId,
		dataType: "json",
		cache: false,
		async: false,
		success: function(data){
		
			if (data.percentage > 0){
				$("#progressBarElement").updateProgress(data.percentage);
				timeoutcounter = 0;
			}
			
			if (data.actionStatusId == 4){
				//ready
				data.result = "ok"
				updateInterface(data);
				return;
			}
			
			if (data.actionStatusId == 5){
				//engine error
				data.result = "error"
				updateInterface(data);
				return;
			}
			
			if(timeoutcounter == timeout){
				//engine busy
				data.result = "error"
				updateActionStatus(gActionId,5);
				updateInterface(data);
				return;
			}
			
			timeoutcounter++;
			setTimeout(function(){pollAction(timeoutcounter,timeout);timeoutcounter = null,timeout = null},gInterval);
		}
	
	});
	
}

/**
 * This function is used to update the status of an action (tblaction)
 * E.g. in case a timeout error the status of the action is set to 5 (error)
 * @param actionId
 * @param actionStatusId
 */
function updateActionStatus(actionId,actionStatusId){

	var url = '/functions/ajax/action_updatestatus.php';
	var randVal = Math.random(9999);
	var data = { actionid: actionId, actionstatusid: actionStatusId, rand: randVal };
	$.post(url, data);
	 
}

/**
 * The final step in the preview process, update the UI
 * @param report
 * @return
 */
function updateInterface(report) {

	//Remove the busy class from the parent if applicable
	if (gRequestjson.targetplaceholder){
		$(gRequestjson.targetplaceholder).parent().removeClass("statusIconBusy");
	}

	//Handle the returned message
	switch (report.result){
		case "error":
			
			if (gRequestjson.busymethod == "placeholder"){
				$("#progressWarning").show();
				$("#progressWarning").children(".statusMessage").html(report.message);
			} else if (gRequestjson.busymethod == "dialog" ){
				$("#dialog div.statusLine").show();
				if(typeof report.message != 'undefined'){
					$("#dialog div.statusLine").children(".statusMessage").html(report.message);
				}
				
				if(gRequestjson.busyindicator == "progressbar"){
					$("#progressBar").hide();
				} else {
					$("#requestStatus").hide();					
				}
			} else {
				$("#busyFormContent .statusLine").children(".statusIcon").removeClass("statusIconBusy").addClass("statusIconWarning");		
				$("#busyFormContent .statusLine").children(".statusMessage").html(report.message);	
			}
			break;
			
		case "ok":
			
			if (gRequestjson.targetplaceholder){
	 			$("#requestStatus").hide();
				$(gRequestjson.targetplaceholder).children("img").remove();
				$(gRequestjson.targetplaceholder).append("<img />");
				$(gRequestjson.targetplaceholder).children("img").attr('src',gRequestjson.file);
				$(gRequestjson.targetplaceholder).show();
				// fadeIn seems broken in safari and chrome
				//$(gRequestjson.targetplaceholder).fadeIn('fast');
				$(gRequestjson.targetplaceholder).unbind('click').bind('click', function(){
					openWindow('../pages/preview_popup.php?fnCurrentLayout=' + gRequestjson.layout + '&fcImageName=Preview',700,500)
				});
				$(gRequestjson.targetplaceholder).addClass('pointer');
			} else if (gRequestjson.targetpage){
				document.location.href = 'site.php?pageid=' + gRequestjson.targetpage;
	 		} else if (gRequestjson.targetdialog){
	 			closeDialog();
	 			
	 			// id =  used to retrieve information to display in the dialog
	 			dialogParams = eval("({})");
	 			dialogParams.dialogid = gRequestjson.targetdialog;
	 			
	 			if(gRequestjson.id){
	 				dialogParams.id = gRequestjson.id;
	 			}
	 			if(report.data){	
	 				dialogParams.data = report.data;
	 			}
	 			
				generateDialog(dialogParams);
	 		} else {
	 			closeDialog();
	 		}
			break;

	}
	
	if(gRequestjson.postProcess){
		eval(gRequestjson.postProcess);
	}
	
 		
}


/**
 * This function submits the form of the Output Dialog via Ajax.
 * This method prevents a conditional javascript call on the Job Properties page.
 */
function initOutput(thisForm,jobId){
	
	ajaxSetSaveButtonGlobal(); //PSW - required to make sure the validation process is started.
	
	var selectedOutputMethod = parseInt($("#fnOutputMethodField").val());

	if(ajaxValidateForm(thisForm)){
		
		gRequestjson = eval("({})");
		gRequestjson.busymethod = 'dialog';
		gRequestjson.jobid = jobId;
		gRequestjson.busyindicator = "progressbar";
		gRequestjson.message = 'cGeneratingOutput';
		gRequestjson.postProcess = 'generateJobOutputHistory(' + jobId + ')';
		gRequestjson.dialogId = 'output_progress';
		switch(selectedOutputMethod)
		{
		
			case 1: // Print
				gRequestjson.outputmethod = 'print';
				gRequestjson.printerid = $('#fnPrinterIDField').val();
				gRequestjson.rangemethod = $('input[name=fnRangeMethod]').fieldValue();
				gRequestjson.copies = $('#fnCopiesField').val();
				if(gRequestjson.rangemethod == 2){
					gRequestjson.rangefrom = $('#fnFromField').val();
					gRequestjson.rangeto = $('#fnToField').val();
				}
				break; 
			
			case 2: // Print to File
				gRequestjson.outputmethod = 'printtofile';
				gRequestjson.busyindicator = "progressbar";
				gRequestjson.printerid = $('#fnPrinterIDField').val();
				gRequestjson.folderid = $('#fnOutputFolderIDField').val();
				gRequestjson.copies = $('#fnCopiesField').val();
				gRequestjson.rangemethod = $('input[name=fnRangeMethod]').fieldValue();
				if(gRequestjson.rangemethod == 2){
					gRequestjson.rangefrom = $('#fnFromField').val();
					gRequestjson.rangeto = $('#fnToField').val();
				}
				break;
				
			case 3: // Create PDF
				gRequestjson.outputmethod = 'createpdf';
				gRequestjson.printerid = $('#fnPrinterIDField').val();
				gRequestjson.joboptionid = $('#fnJobOptionIDField').val();
				gRequestjson.folderid = $('#fnOutputFolderIDField').val();
				gRequestjson.copies = $('#fnCopiesField').val();
				gRequestjson.rangemethod = $('input[name=fnRangeMethod]').fieldValue();
				if(gRequestjson.rangemethod == 2){
					gRequestjson.rangefrom = $('#fnFromField').val();
					gRequestjson.rangeto = $('#fnToField').val();
				}
				break;
				
			case 4: // Preflight
				gRequestjson.outputmethod = 'preflight';
				gRequestjson.printerid = $('#fnPrinterIDField').val();
				gRequestjson.targetdialog = 'preflight_result';
				gRequestjson.message = 'cPreflightingDocumentPleaseWait';
				gRequestjson.id = jobId; //this id is used to retrieve the job info in the dialog
				break; 	
				
			case 5: // Send To PlanetPress Watch
				gRequestjson.outputmethod = 'sendtowatch';
				gRequestjson.dialogId = 'output_busy';
				gRequestjson.printerid = $('#fnPrinterIDField').val();
				gRequestjson.copies = $('#fnCopiesField').val();
				gRequestjson.rangemethod = $('input[name=fnRangeMethod]').fieldValue();
				if(gRequestjson.rangemethod == 2){
					gRequestjson.rangefrom = $('#fnFromField').val();
					gRequestjson.rangeto = $('#fnToField').val();
				}
				break; 	
				
			case 6: // Send To Folder (SPDF & FUP)
				gRequestjson.outputmethod = 'sendtofolder';
				gRequestjson.folderid = $('#fnOutputFolderIDField').val();
				gRequestjson.dialogId = 'output_busy';
				break; 
				
			case 7: // PrintPDF (SPDF)
				gRequestjson.outputmethod = 'print';
				gRequestjson.dialogId = 'output_busy';
				gRequestjson.printerid = $('#fnPrinterIDField').val();
				gRequestjson.rangemethod = $('input[name=fnRangeMethod]').fieldValue();
				gRequestjson.copies = $('#fnCopiesField').val();
				if(gRequestjson.rangemethod == 2){
					gRequestjson.rangefrom = $('#fnFromField').val();
					gRequestjson.rangeto = $('#fnToField').val();
				}
				break; 
		
		}
		
		closeDialog();
		generateDialog({'dialogid':gRequestjson.dialogId,'message':gRequestjson.message});
		setTimeout('sendEngineRequest()',500);	
		
	 }
	
}


/**
 * This function submits the form of the Output Dialog via Ajax.
 * This method prevents a conditional javascript call on the Job Properties page.
 */
function initSoftproofDatabaseInput(thisForm,jobId){
	
	ajaxSetSaveButtonGlobal(); //PSW - required to make sure the validation process is started.
		
	if(ajaxValidateForm(thisForm)){
		
		// gRequestjson is used in sendEngineRequest
		gRequestjson = eval("({})");
		gRequestjson.busymethod = 'dialog';
		gRequestjson.targetpage = 'preview_displaypdf';
		gRequestjson.outputmethod = 'rendersoftproof';
		gRequestjson.previewmode = 'true';
		gRequestjson.croptolayout = 'true';
		gRequestjson.rangefrom = $('#fnFromField').val();
		gRequestjson.rangeto = $('#fnToField').val();
		gRequestjson.generatejobdata = 'full';
		gRequestjson.jobid = jobId;

		generateDialog({'dialogid':'preview_progress'});
		setTimeout('sendEngineRequest()',500);	
		
	}

}



/**
 * This function submits the form of the Output Dialog via Ajax.
 * This method prevents a conditional javascript call on the Job Properties page.
 */
function initSoftproofNoInput(jobId){
	
		// gRequestjson is used in sendEngineRequest
		gRequestjson = eval("({})");
		gRequestjson.busymethod = 'dialog';
		gRequestjson.targetpage = 'preview_displaypdf';
		gRequestjson.outputmethod = 'rendersoftproof';
		gRequestjson.previewmode = 'true';
		gRequestjson.croptolayout = 'true';
		gRequestjson.rangefrom = -1;
		gRequestjson.rangeto = -1;
		gRequestjson.generatejobdata = 'dummy';
		gRequestjson.jobid = jobId;

		generateDialog({'dialogid':'preview_progress'});
		setTimeout('sendEngineRequest()',500);	

}

/**
 * This function submits the form of the Output Dialog via Ajax.
 * This method prevents a conditional javascript call on the Job Properties page.
 */
function initSoftproofUserInput(thisForm,jobId){
	
	//Loop through the fck editors and update the accompanying hidden fields
	updateFCKeditorsFormField();
	
	ajaxSetSaveButtonGlobal(); //PSW - required to make sure the validation process is started.
		
	if(ajaxValidateForm(thisForm)){
		
		var rand = Math.random(9999);
		var queryString = $(thisForm).formSerialize() + '&rand=' + rand;
	
		$.ajax({
			type: "POST",
			url: "/functions/ajax/preview_userinput_init_functions.php",
			data: queryString,
			cache: false,
			async: false,
			success: function(){
			
				// gRequestjson is used in sendEngineRequest
				gRequestjson = eval("({})");
				gRequestjson.busymethod = 'dialog';
				gRequestjson.busyindicator= 'progressbar';
				gRequestjson.targetpage = 'preview_displaypdf';
				gRequestjson.outputmethod = 'rendersoftproof';
				gRequestjson.previewmode = 'true';
				gRequestjson.croptolayout = 'true';
				gRequestjson.rangefrom = -1;
				gRequestjson.rangeto = -1;
				gRequestjson.jobid = jobId;
				gRequestjson.generatejobdata = 'full';

				generateDialog({'dialogid':'preview_progress'});
				setTimeout('sendEngineRequest()',500);	
				
			}
		
		});

	 }

}


/**
 * This function submits the form of the Output Dialog via Ajax.
 * This method prevents a conditional javascript call on the Job Properties page.
 */
function initPreviewDatabaseInput(thisForm,jobId,currentRecord){
		
	$("#jpgPreview").hide();
	$("#jpgPreview").parent().addClass("statusIconBusy");
	
	if($('#cDragResultField').length && $('#cDragResultField').val	()){
		var rand = Math.random(9999);
		var queryString = $('#cDragResultField').fieldSerialize() + '&rand=' + rand;
		
		$.ajax({
			type: "POST",
			url: "/functions/ajax/preview_databasemapping_init_functions.php",
			data: queryString,
			async: false,
			cache: false,
			success: function(){
				doPreviewDatabaseInputRequest();
			}
		});
		
	} else {
		doPreviewDatabaseInputRequest();
	}
		
	function doPreviewDatabaseInputRequest(){
		
		// hide possible warning elements
		$('div.statusLine').hide();
		
		// gRequestjson is used in sendEngineRequest
		gRequestjson = eval("({})");
		gRequestjson.busymethod = 'placeholder';
		gRequestjson.targetplaceholder = '#jpgPreview';
		gRequestjson.outputmethod = 'renderjpg';
		gRequestjson.currentrecord = 'true';
		gRequestjson.previewmode = 'true';
		gRequestjson.jobid = jobId;
		gRequestjson.generatejobdata = 'temp';

		if($('#nLayoutField').length){
			gRequestjson.layout = $('#nLayoutField').val();
		} else {
			gRequestjson.layout = 1;
		}
		
		if(typeof currentRecord != 'undefined'){
			gRequestjson.currentrecord = currentRecord;
		}
	
		sendEngineRequest();
	}

}


/**
 * This function submits the form of the Output Dialog via Ajax.
 * This method prevents a conditional javascript call on the Job Properties page.
 */
function initPreviewUserInput(thisForm,jobId){
	
	//Loop through the fck editors and update the accompanying hidden fields
	updateFCKeditorsFormField();
	
	ajaxSetSaveButtonGlobal(); //PSW - required to make sure the validation process is started.
	
	if(ajaxValidateForm(thisForm)){
	
		var rand = Math.random(9999);
		var queryString = $(thisForm).formSerialize() + '&rand=' + rand;
		
		$("#jpgPreview").hide();
		$("#jpgPreview").parent().addClass("statusIconBusy");
		
		$.ajax({
			type: "POST",
			url: "/functions/ajax/preview_userinput_init_functions.php",
			data: queryString,
			async: false,
			cache: false,
			success: function(){
				// hide possible warning elements
				$('div.statusLine').hide();
				
				// gRequestjson is used in sendEngineRequest
				gRequestjson = eval("({})");
				gRequestjson.busymethod = 'placeholder';
				gRequestjson.targetplaceholder = '#jpgPreview';
				gRequestjson.outputmethod = 'renderjpg';
				gRequestjson.previewmode = 'true';
				gRequestjson.jobid = jobId;
				gRequestjson.generatejobdata = 'temp';
	
				if($('#nLayoutField').length){
					gRequestjson.layout = $('#nLayoutField').val();
				} else {
					gRequestjson.layout = 1;
				}
				
				sendEngineRequest();	
			}
		
		});
	}
}
/**
 * This functions instantiates a dongle information request
 */
function initGetDongleData(){
	
	// gRequestjson is used in sendEngineRequest
	gRequestjson = eval("({})");
	gRequestjson.engine = 'psm';
	gRequestjson.busymethod = 'dialog';
	gRequestjson.targetpage = 'setting_license';
	gRequestjson.outputmethod = 'getdongledata';
	generateDialog({'dialogid':'busy','message':'cRetrievingDongleInformation'});
	setTimeout('sendEngineRequest()',500);	

}

/**
 * This functions instantiates a dongle upgrade url request
 */
function initGetUpgradeUrl(){
	
	// gRequestjson is used in sendEngineRequest
	gRequestjson = eval("({})");
	gRequestjson.engine = 'psm';
	gRequestjson.busymethod = 'dialog';
	gRequestjson.targetdialog = 'setting_license_upgraderequest';
	gRequestjson.outputmethod = 'getupgradeurl';
	generateDialog({'dialogid':'busy','message':'cRetrievingDongleInformation'});
	setTimeout('sendEngineRequest()',500);	

}

function initGetVoucherUrl(){
	
	// gRequestjson is used in sendEngineRequest
	gRequestjson = eval("({})");
	gRequestjson.engine = 'psm';
	gRequestjson.busymethod = 'dialog';
	gRequestjson.targetdialog = 'setting_license_voucherrequest';
	gRequestjson.outputmethod = 'getupgradeurl';
	generateDialog({'dialogid':'busy','message':'cRetrievingDongleInformation'});
	setTimeout('sendEngineRequest()',500);	
	
}


/**
 * This functions instantiates a upgrade activation request
 */
function initActivateUpgrade(thisForm){
	
	ajaxSetSaveButtonGlobal(); //PSW - required to make sure the validation process is started.
	
	if(ajaxValidateForm(thisForm)){
		
		// gRequestjson is used in sendEngineRequest
		gRequestjson = eval("({})");
		gRequestjson.engine = 'psm';
		gRequestjson.busymethod = 'dialog';
		gRequestjson.outputmethod = 'activateupgrade';
		gRequestjson.upgradecode = $('#fcActivationCodeField').val();
		gRequestjson.postProcess = "if(report.result == 'ok'){ clickGetDongleButton(); }";
		
		closeDialog();
		generateDialog({'dialogid':'busy','message':'cActivatingUpgrade'});
		setTimeout('sendEngineRequest()',500);	
		
	}
	
}

function clickGetDongleButton(){
	$(document).ready(function() {
		initGetDongleData();
	});
}


/**
 * This function submits the form of the Output Dialog via Ajax.
 * This method prevents a conditional javascript call on the Job Properties page.
 */
function initPreflightDatabaseInput(thisForm,jobId,printerId){
	
	if($('#cDragResultField').length && $('#cDragResultField').val	()){
		//This part stores the header order for the preview_databse_mapping page (drag & drop)
		var rand = Math.random(9999);
		var queryString = $('#cDragResultField').fieldSerialize() + '&rand=' + rand;
		
		$.ajax({
			type: "POST",
			url: "/functions/ajax/preview_databasemapping_init_functions.php",
			data: queryString,
			async: false,
			cache: false,
			success: function(){
			doPreflightDatabaseInputRequest();
			}
		});
		
	} else {
		doPreflightDatabaseInputRequest();
	}
	
	function doPreflightDatabaseInputRequest(){
		
		// gRequestjson is used in sendEngineRequest
		gRequestjson = eval("({})");
		gRequestjson.busymethod = 'dialog';
		gRequestjson.busyindicator= 'progressbar';
		gRequestjson.targetdialog = 'preflight_result';
		gRequestjson.outputmethod = 'preflight';
		gRequestjson.rangefrom = -1;
		gRequestjson.rangeto = -1;
		gRequestjson.jobid = jobId;
		if(printerId){
		gRequestjson.printerid = printerId;
		}
		gRequestjson.generatejobdata = 'full';
		gRequestjson.id = jobId; //this id is used to retrieve the job info in the preflight result dialog
	
		generateDialog({'dialogid':'preflight_progress'});
		setTimeout('sendEngineRequest()',500);	
		
	}
}



/**
 * Checking FCKeditors on the page
 * If the content has changed update the hidden field which is used by FCK (the linked field)
 */
function updateFCKeditorsFormField()
{

	var fckeditorName, editorInstance;

	if (window.FCKeditorAPI)
	{		   
		
	   for (fckeditorName in FCKeditorAPI.__Instances) // Use __Instances in FCKeditors prior to version 2.6
	   {
	      if ((editorInstance = FCKeditorAPI.GetInstance(fckeditorName)).IsDirty())
	      {
	    	  FCKeditorAPI.GetInstance(fckeditorName).UpdateLinkedField();
	      }
	   }
	}

	return false;
}

/**
* Open a window using Javascript and center the window on screen
* 
* Code was found on the following url:
* http://www.boutell.com/newfaq/creating/windowcenter.html
* 
*/
function openWindow(url, w, h)
{
	// Fudge factors for window decoration space.
	// In my tests these work well on all platforms & browsers.
	w += 32;
	h += 96;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	
	// IE5 and other old browsers might allow a window that is
	// partially offscreen or wider than the screen. Fix that.
	// (Newer browsers fix this for us, but let's be thorough.)

	if (wleft < 0) {
		w = screen.width;
		wleft = 0;
	}
	if (wtop < 0) {
		h = screen.height;
		wtop = 0;
	}
	var win = window.open(url,'',
	'width=' + w + ', height=' + h + ', ' +
	'left=' + wleft + ', top=' + wtop + ', ' +
	'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=yes, resizable=yes');
	
	// Just in case width and height are ignored
	win.resizeTo(w, h);
 	
	// Just in case left and top are ignored
	win.moveTo(wleft, wtop);
	win.focus();
}


function setOutputMethodsStaticPdf(formItem){

	var outputmethod = formItem.options[formItem.selectedIndex].value;
	
	clearWarnings();
	
	if(outputmethod == 7){
		showFormElement('fnPrinterIDLine');
		$('#fnOutputFolderIDLine').hide();
		$('#fnJobOptionIDLine').hide();
		showFormElement('cCopiesAndRangeFieldset');
	}
	
	if(outputmethod == 6){
		$('#fnPrinterIDLine').hide();
		showFormElement('fnOutputFolderIDLine');
		$('#fnJobOptionIDLine').hide();
		$('#cCopiesAndRangeFieldset').hide();
	}
	
}

function setOutputMethodsStaticPsm(formItem){

	var outputmethod = formItem.options[formItem.selectedIndex].value;
	
	clearWarnings();
	
	//print
	if(outputmethod == 1){
		showFormElement('fnPrinterIDLine');
		$('#fnOutputFolderIDLine').hide();
		$('#fnJobOptionIDLine').hide();
		showFormElement('fnCopiesLine');
		showFormElement('fnRangeMethodLine');
		showFormElement('fnFromLine');
		showFormElement('fnToLine');
	}
	
	//printtofile
	if(outputmethod == 2){
		showFormElement('fnPrinterIDLine');
		showFormElement('fnOutputFolderIDLine');
		$('#fnJobOptionIDLine').hide();
		$('#fnCopiesLine').hide();
		showFormElement('fnRangeMethodLine');
		showFormElement('fnFromLine');
		showFormElement('fnToLine');
	}
	
	//createpdf
	if(outputmethod == 3){
		showFormElement('fnPrinterIDLine');
		showFormElement('fnOutputFolderIDLine');
		showFormElement('fnJobOptionIDLine');
		$('#fnCopiesLine').hide();
		showFormElement('fnRangeMethodLine');
		showFormElement('fnFromLine');
		showFormElement('fnToLine');
	}
	
	//preflight
	if(outputmethod == 4){
		showFormElement('fnPrinterIDLine');
		$('#fnOutputFolderIDLine').hide();
		$('#fnJobOptionIDLine').hide();
		$('#fnCopiesLine').hide();
		showFormElement('fnRangeMethodLine');
		showFormElement('fnFromLine');
		showFormElement('fnToLine');
	}
	
	//sendtowatch
	if(outputmethod == 5){
		$('#fnPrinterIDLine').hide();
		$('#fnOutputFolderIDLine').hide();
		$('#fnJobOptionIDLine').hide();
		$('#fnRangeMethodLine').hide();
		$('#fnFromLine').hide();
		$('#fnToLine').hide();
		showFormElement('fnCopiesLine');
	}

	toggleCopiesAndRange();
}


function setOutputMethodsFileUpload(formItem){

	var outputmethod = formItem.options[formItem.selectedIndex].value;
	
	clearWarnings();
	
	if(outputmethod == 7){
		showFormElement('fnPrinterIDLine');
		$('#fnOutputFolderIDLine').hide();
		$('#fnJobOptionIDLine').hide();
		showFormElement('cCopiesAndRangeFieldset');
	}
	
	if(outputmethod == 6){
		$('#fnPrinterIDLine').hide();
		showFormElement('fnOutputFolderIDLine');
		$('#fnJobOptionIDLine').hide();
		$('#cCopiesAndRangeFieldset').hide();
	}
	
}


function toggleCopiesAndRange(){
	copiesAndRangeChilds = $('#cCopiesAndRangeFieldset div.content div.formLine:visible').length;
	if(copiesAndRangeChilds == 0){
		$('#cCopiesAndRangeFieldset').hide();
	} else {
		showFormElement('cCopiesAndRangeFieldset');
	}
}

function generateJobOutputHistory(jobId){
	$.ajax({
		type: "POST",
		url: "/functions/ajax/output_history.php",
		data: "jobId=" + jobId,
		dataType: "html",
		cache: false,
		success: function(data){
			$("#cOutputHistoryFieldset .content").html(data);
		}
	});

}