function gts(lang_code, amount, company, description, invoice_recipients, user_id_gts, trans_status, callback) {
	
	var title = 'Secure Payment';
	var cc_name = 'Full Name*';
	var cc_name_label = 'Card owner name, as it appears on the card.';
	var cc_number = 'Card Number*';
	var cc_number_label = 'Your Card Number as it appears on the front side of your card.';
	var cc_exp = 'Card Expiration Date* (MMYY)';
	var cc_exp_label = 'The expiration date of your card. For example: &quot;1012&quot; (December, 2012)';
	var cc_cvv2 = 'CVV2*';
	var cc_cvv2_label = '3 digits on the FRONT-SIDE of your card. In American-Express cards - the CVV2 is a 4 digits number on the BACK of the card.';
	var amount_str = 'amount';
	var	amount_str_label = 'The amount that will be subtracted from the credit card';
	var payments = 'Payments';
	var	payments_label = 'The number of payments';
	var id_number = 'ID Number*';
	var id_number_label = 'Your ID Number';
	
	var notes_title = 'Confirmation';
	var errors_title = 'Some errors occured';
	var submit = 'Submit';
	
	if (lang_code == 'he') {
		title = 'תשלום מאובטח';
		cc_name = 'שם מלא של בעל הכרטיס*';
		cc_name_label = 'שם מלא של בעל הכרטיס, כפי שמופיע בצידו הקידמי של הכרטיס.';
		cc_number = 'מספר כרטיס האשראי*';
		cc_number_label = 'מספר כרטיס האשראי, כפי שמופיע בצידו הקידמי של הכרטיס.';
		cc_exp = 'תאריך תפוגה* (MMYY)';
		cc_exp_label = 'תאריך התפוגה של הכרטיס. לדוגמא: &quot;1012&quot; (דצמבר, 2012)';
		cc_cvv2 = 'CVV2*';
		cc_cvv2_label = '3 ספרות המופיעות בגב הכרטיס. בכרטיסי אמריקן-אקספרס אלו 4 ספרות שמופיעות בצידו הקדמי של הכרטיס.';
		amount_str = 'סכום';
		amount_str_label = 'סכום העסקה';
		payments = 'תשלומים';
		payments_label = 'מספר התשלומים';
		id_number = 'מספר תעודת הזהות*';
		id_number_label = 'מספר תעודת הזהות של בעל הכרטיס';
		
		notes_title = 'אישור';
		errors_title = 'אירעו שגיאות';
		submit = 'שלח';
	}
	
	var gts_background = '<div id="gts_background"></div>';
	var gts_box  = 	'<div id="gts">';
	gts_box		+=		'<center>';
	gts_box     += 			'<div class="gts_outer_transparent_container"></div>';
	gts_box		+=			'<div class="gts_outer_container">';
	gts_box     +=		 		'<div class="gts_close"><img src="https://secure.pnc.co.il/gts/widgets/images/dialog-x.png" alt="" onclick="gts_close()"></div>';
	gts_box     += 				'<div class="gts_container_top"><div class="drag_handle"></div></div>';
	gts_box     += 				'<div class="gts_container">';
	gts_box     += 					'<div class="gts_inner_container">';
	gts_box     += 						'<div class="gts_title"><div class="lock_container"><img src="https://secure.pnc.co.il/gts/widgets/images/lock.png" alt=""></div>'+title+'</div>';
	
	gts_box     += 						'<div id="gts_server_side_notes" class="gts_notes">';
	gts_box     += 							'<div class="n_title">'+notes_title+'</div>';
	gts_box     += 							'<div class="n_content"></div>';
	gts_box     += 						'</div>';
	
	gts_box     += 						'<div id="gts_server_side_errors" class="gts_errors">';
	gts_box     += 							'<div class="e_title">'+errors_title+'</div>';
	gts_box     += 							'<div class="e_content"></div>';
	gts_box     += 						'</div>';
	
	gts_box     += 						'<form id="gts_payment_form">';
	gts_box     += 							'<input type="hidden" id="invoice_recipients" name="invoice_recipients" value="'+invoice_recipients+'">';
	gts_box     += 							'<input type="hidden" id="description" name="description" value="'+description+'">';
	gts_box     += 							'<input type="hidden" id="company" name="company" value="'+company+'">';
	gts_box     += 							'<input type="hidden" id="user_id_gts" name="user_id_gts" value="'+user_id_gts+'">';
	gts_box     += 							'<input type="hidden" id="trans_status" name="trans_status" value="'+trans_status+'">';
	gts_box     += 							'<table cellspacing="0" cellpadding="0">';
	gts_box     += 								'<tr>';
	gts_box     += 									'<td class="label" title="'+cc_name_label+'">'+cc_name+'</td>';
	gts_box     += 									'<td class="field"><input type="text" id="cc_name" name="cc_name" value="" maxlength="50"></td>';
	gts_box     += 									'<td id="icon__cc_name" class="icon"><div><img class="gts_v" src="https://secure.pnc.co.il/gts/widgets/images/icon__v.png"><img class="gts_x" src="https://secure.pnc.co.il/gts/widgets/images/icon__x.png"></div></td>';
	gts_box     +=		 						'</tr>';
	gts_box     += 								'<tr>';
	gts_box     += 									'<td class="label" title="'+id_number+'">'+id_number+'</td>';
	gts_box     += 									'<td class="field"><input type="text" id="id_number" name="id_number" value="" maxlength="12"></td>';
	gts_box     += 									'<td id="icon__id_number" class="icon"><div><img class="gts_v" src="https://secure.pnc.co.il/gts/widgets/images/icon__v.png"><img class="gts_x" src="https://secure.pnc.co.il/gts/widgets/images/icon__x.png"></div></td>';
	gts_box     += 								'</tr>';
	gts_box     += 								'<tr>';
	gts_box     += 									'<td class="label" title="'+cc_number_label+'">'+cc_number+'</td>';
	gts_box     += 									'<td class="field"><input type="text" id="cc_number" name="cc_number" value="" maxlength="16"></td>';
	gts_box     += 									'<td id="icon__cc_number" class="icon"><div><img class="gts_v" src="https://secure.pnc.co.il/gts/widgets/images/icon__v.png"><img class="gts_x" src="https://secure.pnc.co.il/gts/widgets/images/icon__x.png"></div></td>';
	gts_box     += 								'</tr>';
	gts_box     +=		 						'<tr>';
	gts_box     += 									'<td class="label" title="'+cc_exp_label+'">'+cc_exp+'</td>';
	gts_box     += 									'<td class="field"><input type="text" class="short" id="cc_exp" name="cc_exp" value="" maxlength="4"></td>';
	gts_box     += 									'<td id="icon__cc_exp" class="icon"><div><img class="gts_v" src="https://secure.pnc.co.il/gts/widgets/images/icon__v.png"><img class="gts_x" src="https://secure.pnc.co.il/gts/widgets/images/icon__x.png"></div></td>';
	gts_box     +=		 						'</tr>';
	gts_box     += 								'<tr>';
	gts_box     += 									'<td class="label" title="'+cc_cvv2_label+'">'+cc_cvv2+'</td>';
	gts_box     += 									'<td class="field"><input type="text" class="short" id="cc_cvv2" name="cc_cvv2" value="" maxlength="4"></td>';
	gts_box     += 									'<td id="icon__cc_cvv2" class="icon"><div><img class="gts_v" src="https://secure.pnc.co.il/gts/widgets/images/icon__v.png"><img class="gts_x" src="https://secure.pnc.co.il/gts/widgets/images/icon__x.png"></div></td>';
	gts_box     += 								'</tr>';
	gts_box     += 								'<tr>';
	gts_box     += 									'<td class="label" title="'+amount_str_label+'">'+amount_str+'</td>';
	gts_box     += 									'<td class="field"><input type="text" class="short" id="amount" name="amount" value="'+amount+'" maxlength="4"></td>';
	gts_box     += 									'<td id="icon__amount" class="icon"><div><img class="gts_v" src="https://secure.pnc.co.il/gts/widgets/images/icon__v.png"><img class="gts_x" src="https://secure.pnc.co.il/gts/widgets/images/icon__x.png"></div></td>';
	gts_box     += 								'</tr>';
	gts_box     += 								'<tr>';
	gts_box     += 									'<td class="label" title="'+payments_label+'">'+payments+'</td>';
	gts_box     += 									'<td class="field"><input type="text" class="short" id="payments" name="payments" value="1" maxlength="2"></td>';
	gts_box     += 									'<td id="icon__payments" class="icon"><div><img class="gts_v" src="https://secure.pnc.co.il/gts/widgets/images/icon__v.png"><img class="gts_x" src="https://secure.pnc.co.il/gts/widgets/images/icon__x.png"></div></td>';
	gts_box     += 								'</tr>';
	gts_box     += 								'<tr>';	
	gts_box     += 									'<td class="label" title=""></td>';
	gts_box     += 									'<td class="field"><div class="gts_submit" onclick="gts_submit_payment_form(\''+lang_code+'\', '+callback+')">'+submit+'&nbsp;&raquo;</div></td>';
	gts_box     += 									'<td class="icon"><div><img id="icon__loader" class="loader" src="https://secure.pnc.co.il/gts/widgets/images/loader.gif"></div></td>';
	gts_box     += 								'</tr>';
	gts_box     += 							'</table>';
	gts_box     += 						'</form>';
	gts_box     += 					'</div>';
	gts_box     += 				'</div>';
	gts_box     += 				'<div class="gts_container_bottom"></div>';
	gts_box		+=			'</div>';
	gts_box		+=		'</center>';
	gts_box     += 	'</div>';
	
	$('body').append(gts_background);
	$('body').append(gts_box);
	$('#gts_background').height($(document).height());
	$('#gts').height($(document).height());
	$('#gts .gts_outer_transparent_container').height($('#gts .gts_outer_container').height());
	var gts_position_top = (($(window).height()/2) - $('#gts .gts_outer_container').height()/2) + $(window).scrollTop();
	$('#gts .gts_outer_transparent_container').css({top:gts_position_top});
	$('#gts .gts_outer_container').css({top:gts_position_top});
	$('#gts .gts_outer_container').draggable({handle:'.drag_handle'});
	$('#gts .gts_outer_container input').bind('blur', function() {
		gts_validate_field(this.getAttribute('name'));
	});
	$('#gts_background').css('opacity',0.5); /* If this opacity is not set, then in IE the fade-in starts from 100% and the goes transparent */
	$('#gts').hide();
	//$('#gts_background').show('slide',{'direction':'left'},500,function() {
	$('#gts_background').fadeIn('slow',function() {
		//$('#gts').show('slide',{'direction':'right'},500);
		$('#gts').fadeIn('slow');
	});
	
}

function gts_validate_field(field_name) {
	var field_validated = 0;
	var regex = '';
	if (field_name == 'cc_name') {
		regex = /^\D+$/;
	}
	if (field_name == 'id_number') {
		regex = /^[\d]{8,10}$/;
	}
	if (field_name == 'cc_number') {
		regex = /^[\d]{8,16}$/;
	}
	if (field_name == 'cc_exp') {
		regex = /^[\d]{4}$/;
	}
	if (field_name == 'cc_cvv2') {
		regex = /^[\d]{3,4}$/;
	}
	if (field_name == 'amount') {
		regex = /^[\d]{1,5}$/;
	}
	if (field_name == 'payments') {
		regex = /^[\d]{1,2}$/;
	}
	if (regex.test($('#'+field_name).val())) {
		field_validated = 1;
	} else {
		field_validated = 0;
	}
	
	$('#icon__'+field_name+' img:visible').hide('slide', {direction:'left'}, 500);
	setTimeout(function() {
		if (field_validated == 1) {
			$('#icon__'+field_name+' .gts_v').show('slide', {direction:'right'}, 500);
		} else {
			$('#icon__'+field_name+' .gts_x').show('slide', {direction:'right'}, 500);
		}
	}, 500);
	
	return field_validated;
	
}

function gts_submit_payment_form(lang_code, callback) {
	
	var n_successful = 'Transaction successful!';
	var n_voucher_code = 'Your voucher code is:';
	
	if (lang_code == 'he') {
		n_successful = 'העסקה עברה בהצלחה!';
		n_voucher_code = 'מספר האישור הוא:';
	}
	
	var gts_payment_form_validated = 1;
	
	$('#gts_server_side_notes:visible').slideUp('slow');
	$('#gts_server_side_errors:visible').slideUp('slow');
	
	if (gts_validate_field('cc_name') != 1) {
		gts_payment_form_validated = 0;
	}
	if (gts_validate_field('id_number') != 1) {
		gts_payment_form_validated = 0;
	}
	if (gts_validate_field('cc_number') != 1) {
		gts_payment_form_validated = 0;
	}
	if (gts_validate_field('cc_exp') != 1) {
		gts_payment_form_validated = 0;
	}
	if (gts_validate_field('cc_cvv2') != 1) {
		gts_payment_form_validated = 0;
	}
	if (gts_validate_field('amount') != 1) {
		//console.log('amount');
		gts_payment_form_validated = 0;
	}
	if (gts_validate_field('payments') != 1) {
		//console.log('payments');
		gts_payment_form_validated = 0;
	}
	
	setTimeout(function() {
		if (gts_payment_form_validated == 1) {
			$('#icon__loader').show('slide', {direction:'right'}, 500);
			
			/*
			var gts_transaction_submit_form  = 	'<form id="gts_transaction_submit_form" name="gts_transaction_submit_form" action="" target="gts_transaction_submit_iframe" method="POST">';
			gts_transaction_submit_form 	+= 		'<input type="hidden" name="cc_name" value="'+$('#cc_name').val()+'">';
			gts_transaction_submit_form 	+= 		'<input type="hidden" name="id_number" value="'+$('#id_number').val()+'">';
			gts_transaction_submit_form 	+= 		'<input type="hidden" name="cc_number" value="'+$('#cc_number').val()+'">';
			gts_transaction_submit_form 	+= 		'<input type="hidden" name="cc_exp" value="'+$('#cc_exp').val()+'">';
			gts_transaction_submit_form 	+= 		'<input type="hidden" name="cc_cvv2" value="'+$('#cc_cvv2').val()+'">';
			gts_transaction_submit_form 	+= 	'</form>';
			gts_transaction_submit_form 	+= 	'<iframe id="gts_transaction_submit_iframe" name="gts_transaction_submit_iframe" src="https://secure.pnc.co.il/gts/widgets/gts_transaction_submit.php" width="1" height="1"></iframe>';
			
			$('body').append(gts_transaction_submit_form);
			$('#gts_transaction_submit_form').submit();
			
			setTimeout(function() {
				var data = $('#gts_transaction_submit_iframe').contents().find('#result').html();
				alert(data);
				if (data.result == 'OKAY') {
					$('#gts_server_side_notes .n_content').html(n_successful+'<br>'+n_voucher_code+' '+data.shva_voucher_code);
					$('#gts_payment_form').slideUp('fast', function() {
						$('#gts_server_side_notes').slideDown('fast');
					});
				} else { 
					$('#gts_server_side_errors .e_content').html(data.error);
					$('#gts_server_side_errors').slideDown('fast');
				}
				$('#icon__loader').hide('slide', {direction:'right'}, 500);
			}, 300);
			
			
			//$.getJSON('https://secure.pnc.co.il/gts/widgets/gts_transaction_submit.php?cc_name='+$('#cc_name').val()+'&id_number='+$('#id_number').val()+'&cc_number='+$('#cc_number').val()+'&cc_exp='+$('#cc_exp').val()+'&cc_cvv2='+$('#cc_cvv2').val()+'&callback=?',
			*/


			$.post(validate__user_form.href_url,
				{
					'action':'submit-transaction',
					'cc_name':$('#cc_name').val(),
					'id_number':$('#id_number').val(),
					'cc_number':$('#cc_number').val(),
					'cc_exp':$('#cc_exp').val(),
					'cc_cvv2':$('#cc_cvv2').val(),
					'amount':$('#amount').val(),
					'payments':$('#payments').val(),
					'company':$('#company').val(),
					'description':$('#description').val(),
					'invoice_recipients':$('#invoice_recipients').val(),
					'user_id':$('#user_id_gts').val(),
					'trans_status':$('#trans_status').val()
				},
				function (data) {
					if (data.result == 'OKAY') {
						if (callback)
							callback(data);							
						
						$('#gts_server_side_notes .n_content').html(n_successful+'<br>'+n_voucher_code+' '+data.shva_voucher_code);
						$('#gts_payment_form').slideUp('fast', function() {
							$('#gts_server_side_notes').slideDown('fast');
						});
						
					} else { 
						$('#gts_server_side_errors .e_content').html(data.error);
						$('#gts_server_side_errors').slideDown('fast');
					}
					$('#icon__loader').hide('slide', {direction:'right'}, 500);
				}, 'json'
			);
			
		}
	}, 500);
}

function gts_close() {
	//$('#gts').hide('slide',{'direction':'left'},500,function() {
	$('#gts').fadeOut('slow',function() {
		//$('#gts_background').hide('slide',{'direction':'right'},500,function() {
		$('#gts_background').fadeOut('slow',function() {
			$('#gts_background').remove();
			$('#gts').remove();
			location.reload(true);
		});
	});
}

// Capturing 'escape' keystore for widget close
$(document).keyup( function(e) {
	//if (e.keyCode == 13) { $('.save').click(); } // Enter
	if (e.keyCode == 27) { gts_close(); } // ESC
});


