var additionalinformation_idx = 0;

$(document).ready(function() 
{ 
	$('input').css('marginTop', 0); 
	$('input').css('marginBottom',0);

	$('#txtAdditionalInformation1').focus() ;
	$('#btnAdditionalInformationUpdate').button().bind('click',saveAdditionalInformation) ;
	clearAdditionalInformation();
	filterAdditionalInformation();
}) ;
function filterAdditionalInformation() {
	var data = { 
		"type"				: C_GET,
	} ;
	var url = "request.pzx?c=" + additionalinformation_url + "&d=" + new Date().getTime() ;
	callServer(url,"json",data,onResponseAdditionalInformation,null) ;
}
function saveAdditionalInformation() {
	// if(validateAdditionalInformation()) {
		var data = { 
			"type"				: C_UPDATE, 
			"user_defined_1"	: $('#txtAdditionalInformation1').val(),
			"user_defined_2"	: $('#txtAdditionalInformation2').val(),
			"user_defined_3"	: $('#txtAdditionalInformation3').val(),
			"user_defined_4"	: $('#txtAdditionalInformation4').val(),
		} ;
		var url = "request.pzx?c=" + additionalinformation_url + "&d=" + new Date().getTime() ;
		callServer(url,"json",data,onResponseAdditionalInformation,null) ;
	// }
}
function clearAdditionalInformation() {
	$('#txtAdditionalInformation1').val('');
	$('#txtAdditionalInformation2').val('');
	$('#txtAdditionalInformation3').val('');
	$('#txtAdditionalInformation4').val('');
}
function validateAdditionalInformation() {
	if ($('#txtAdditionalInformation1').val()=="") {
		$('#txtAdditionalInformation1').focus() ;
		swal("System Warning", "User Defined Caption 1 cannot be blank.", "warning") ;
		return false ;
	}
	
	if ($('#txtAdditionalInformation2').val()=="") {
		$('#txtAdditionalInformation2').focus() ;
		swal("System Warning", "User Defined Caption 2 cannot be blank.", "warning") ;
		return false ;
	}

	if ($('#txtAdditionalInformation3').val()=="") {
		$('#txtAdditionalInformation3').focus() ;
		swal("System Warning", "User Defined Caption 3 cannot be blank.", "warning") ;
		return false ;
	}
	
	if ($('#txtAdditionalInformation4').val()=="") {
		$('#txtAdditionalInformation4').focus() ;
		swal("System Warning", "User Defined Caption 4 cannot be blank.", "warning") ;
		return false ;
	}

	return true ;
}
function onResponseAdditionalInformation(obj,resp) {
	if (resp.status != C_OK) {
		swal("Error",resp.mesg, "error") ;
	} 
	if(resp.type == C_UPDATE) {
		swal("System Message",resp.mesg, "success") ;
	} else if(resp.type == C_GET) {
		$('#txtAdditionalInformation1').val(resp.data.user_defined_1);
		$('#txtAdditionalInformation2').val(resp.data.user_defined_2);
		$('#txtAdditionalInformation3').val(resp.data.user_defined_3);
		$('#txtAdditionalInformation4').val(resp.data.user_defined_4);
	}
}