function open_gift_box (title, cont, pic, recipient_mobile) {
	var sms_background = '<div id="sms_background"></div>';
	var notes_title = 'Confirmation';
	var errors_title = 'Some errors occured';
	
	var mobile = 'הטלפון שלכם*';
	var mobile_label = 'מספר טלפון לחזרה אליכם.';
	var submit = 'שלח';
	
	var cont_table = '<table cellspacing="0" cellpadding="0" style="margin-bottom:20px"><tr><td style="vertical-align:top">'+unescape(cont)+'</td><td><img src="'+pic+'"></td></tr></table>';
	
	var sms_box  = 	'<div id="sms">';
	sms_box		+=		'<center>';
	sms_box     += 			'<div class="sms_outer_transparent_container"></div>';
	sms_box		+=			'<div class="sms_outer_container">';
	sms_box     += 				'<div class="sms_close"><img src="https://secure.pnc.co.il/gts/widgets/images/dialog-x.png" alt="" onclick="close_gift_box()"></div>';
	sms_box     += 				'<div class="sms_container_top"><div class="drag_handle"></div></div>';
	sms_box     += 				'<div class="sms_container">';
	sms_box     += 					'<div class="sms_inner_container">';
	sms_box     += 						'<div class="sms_title"><div class="lock_container"><img src="images/small_logo.png" alt=""></div>'+title+'</div>';

	sms_box     += 						'<div id="sms_server_side_notes" class="sms_notes">';
	sms_box     += 							'<div class="n_title">'+notes_title+'</div>';
	sms_box     += 							'<div class="n_content"></div>';
	sms_box     += 						'</div>';
	
	sms_box     += 						'<div id="sms_server_side_errors" class="sms_errors">';
	sms_box     += 							'<div class="e_title">'+errors_title+'</div>';
	sms_box     += 							'<div class="e_content"></div>';
	sms_box     += 						'</div>';
	
	sms_box += '<div>' + cont_table + '</div>'

	
	sms_box     += 						'<form id="sms_form">';
	sms_box     += 							'<input type="hidden" name="amount" value="" maxlength="3">';
	sms_box     += 							'<input type="hidden" id="msg" name="msg" value="קופסת מתנה">';	
	sms_box     += 							'<table cellspacing="0" cellpadding="0">';
	sms_box     += 								'<tr>';
	sms_box     += 									'<td class="label" title="'+mobile_label+'">'+mobile+'</td>';
	sms_box     += 									'<td class="field"><input type="text" id="mobile" name="mobile" value="" maxlength="12"></td>';
	sms_box     += 									'<td id="icon__mobile" class="icon"><div><img class="sms_v" src="https://secure.pnc.co.il/gts/widgets/images/icon__v.png"><img class="sms_x" src="https://secure.pnc.co.il/gts/widgets/images/icon__x.png"></div></td>';
	sms_box     += 								'</tr>';
	sms_box     += 									'<td class="label" title=""></td>';                //\''+recipient_mobile+'\'
	sms_box     += 									'<td class="field"><div class="sms_submit" onclick="sms_submit_form(\'he\', \''+recipient_mobile+'\')">'+submit+'&nbsp;&raquo;</div></td>';
	sms_box     += 									'<td class="icon"><div><img id="icon__loader" class="loader" src="https://secure.pnc.co.il/gts/widgets/images/loader.gif"></div></td>';
	sms_box     +=		 						'</tr>';
	sms_box     += 							'</table>';
	sms_box     += 						'</form>';
	
	sms_box     +=		 			'</div>';
	sms_box     += 				'</div>';
	sms_box     += 				'<div class="sms_container_bottom"></div>';
	sms_box     += 			'</div>';
	sms_box		+=		'</center>';
	sms_box		+=	'</div>';
	
	$('body').append(sms_background);
	$('body').append(sms_box);
	$('#sms_background').height($(document).height());
	$('#sms').height($(document).height());
	$('#sms .sms_outer_transparent_container').height($('#sms .sms_outer_container').height());
	var sms_position_top = (($(window).height()/2) - $('#sms .sms_outer_container').height()/2) + $(window).scrollTop();
	$('#sms .sms_outer_transparent_container').css({top:sms_position_top});
	$('#sms .sms_outer_container').css({top:sms_position_top});
	$('#sms .sms_outer_container').draggable({handle:'.drag_handle'});
	$('#sms .sms_outer_container input').bind('blur', function() {
		sms_validate_field(this.getAttribute('name'));
	});
	$('#sms_background').css('opacity',0.5); /* If this opacity is not set, then in IE the fade-in starts from 100% and the goes transparent */
	$('#sms').hide();
	$('#sms_background').fadeIn('slow',function() {
		$('#sms').fadeIn('slow');
	});
	
}

function close_gift_box () {
	$('#sms').fadeOut('slow',function() {
		$('#sms_background').fadeOut('slow',function() {
			$('#sms_background').remove();
			$('#sms').remove();
		});
	});
}

function sms(lang_code, recipient_mobile, params) {
	
	title = 'SMS your question!';
	msg = 'Message*';
	msg_label = 'The message you wish to send us.';
	msg_content = '';
	mobile = 'Your mobile*';
	mobile_label = 'The phone number you wish us to call back.';
	
	var notes_title = 'Confirmation';
	var errors_title = 'Some errors occured';
	var submit = 'Submit';
	
	var contact = '';
	var added_title = params == null ? '' : 'השאירו פרטים ותכף נחזור';
	if (params != null) {
		var phones = '<tr><td><div class="title">טלפון:</div>';
		phones += '<div class="val ltr">' + params.phone1 + '</div>';
		phones += '<div class="val ltr">' + params.phone2 + '</div></td></tr>';

		
		var fax = '<tr><td><div class="title">פקס:</div>';
		fax += '<div class="val ltr">' + params.fax + '</div></td></tr>';

		
		var email = '<tr><td><div class="title">מייל:</div>';
		email += '<div class="val"><a href="mailto:' + params.e_mail + '">'+ params.e_mail +'</a></div></td></tr>';

		
		var mail = '<tr><td><div class="title">כתובת:</div>';
		mail += '<div class="val">' + params.address + '</div></td></tr>';

		
		var smail = '<tr><td><div class="title">משלוח דואר:</div>';
		smail += '<div class="val">' + params.mail_address + '</div></td></tr>';
		
		var spacer = '<tr><td class="spacer"></td></tr>';
		
		contact = phones + spacer + fax + spacer + email + spacer + mail + spacer + smail;
		contact = '<table class="contact_table">' + contact + '</table>';
		contact = '<table><tr><td>' + contact + '</td>';
		contact += '<td><img src="' + params.map + '"></td></tr></table>';
	}
	
	
	if (lang_code == 'he') {
		title = 'צרו קשר';
		msg = params == null ? 'השאלה' : 'שם:';
		msg_label = 'השאלה שלך בפירוט.';
		msg_content = '';
		mobile = 'הטלפון שלכם*';
		mobile_label = 'מספר טלפון לחזרה אליכם.';
		
		notes_title = 'אישור';
		errors_title = 'אירעו שגיאות';
		submit = 'שלח';
	}
	
	var sms_background = '<div id="sms_background"></div>';
	var sms_box  = 	'<div id="sms">';
	sms_box		+=		'<center>';
	sms_box     += 			'<div class="sms_outer_transparent_container"></div>';
	sms_box		+=			'<div class="sms_outer_container">';
	sms_box     += 				'<div class="sms_close"><img src="https://secure.pnc.co.il/gts/widgets/images/dialog-x.png" alt="" onclick="sms_close()"></div>';
	sms_box     += 				'<div class="sms_container_top"><div class="drag_handle"></div></div>';
	sms_box     += 				'<div class="sms_container">';
	sms_box     += 					'<div class="sms_inner_container">';
	sms_box     += 						'<div class="sms_title"><div class="lock_container"><img src="images/small_logo.png" alt=""></div>'+title+'</div>';
	
	sms_box     += 						'<div id="sms_server_side_notes" class="sms_notes">';
	sms_box     += 							'<div class="n_title">'+notes_title+'</div>';
	sms_box     += 							'<div class="n_content"></div>';
	sms_box     += 						'</div>';
	
	sms_box     += 						'<div id="sms_server_side_errors" class="sms_errors">';
	sms_box     += 							'<div class="e_title">'+errors_title+'</div>';
	sms_box     += 							'<div class="e_content"></div>';
	sms_box     += 						'</div>';
	
	sms_box += contact;
	sms_box += '<div class="title">'+added_title+'</div><br />';
	
	sms_box     += 						'<form id="sms_form">';
	sms_box     += 							'<input type="hidden" name="amount" value="" maxlength="3">';
	sms_box     += 							'<table cellspacing="0" cellpadding="0">';
	sms_box     += 								'<tr>';
	sms_box     += 									'<td class="label" title="'+msg_label+'">'+msg+'</td>';
	sms_box     += 									'<td class="field"><input type="text" id="msg" name="msg" value="'+msg_content+'" maxlength="50"></td>';
	sms_box     += 									'<td id="icon__msg" class="icon"><div><img class="sms_v" src="https://secure.pnc.co.il/gts/widgets/images/icon__v.png"><img class="sms_x" src="https://secure.pnc.co.il/gts/widgets/images/icon__x.png"></div></td>';
	sms_box     += 								'</tr>';
	sms_box     += 								'<tr>';
	sms_box     += 									'<td class="label" title="'+mobile_label+'">'+mobile+'</td>';
	sms_box     += 									'<td class="field"><input type="text" id="mobile" name="mobile" value="" maxlength="12"></td>';
	sms_box     += 									'<td id="icon__mobile" class="icon"><div><img class="sms_v" src="https://secure.pnc.co.il/gts/widgets/images/icon__v.png"><img class="sms_x" src="https://secure.pnc.co.il/gts/widgets/images/icon__x.png"></div></td>';
	sms_box     += 								'</tr>';
	sms_box     += 									'<td class="label" title=""></td>';
	sms_box     += 									'<td class="field"><div class="sms_submit" onclick="sms_submit_form(\''+lang_code+'\', \''+recipient_mobile+'\')">'+submit+'&nbsp;&raquo;</div></td>';
	sms_box     += 									'<td class="icon"><div><img id="icon__loader" class="loader" src="https://secure.pnc.co.il/gts/widgets/images/loader.gif"></div></td>';
	sms_box     +=		 						'</tr>';
	sms_box     += 							'</table>';
	sms_box     += 						'</form>';
	sms_box     +=		 			'</div>';
	sms_box     += 				'</div>';
	sms_box     += 				'<div class="sms_container_bottom"></div>';
	sms_box     += 			'</div>';
	sms_box		+=		'</center>';
	sms_box		+=	'</div>';
	
	$('body').append(sms_background);
	$('body').append(sms_box);
	$('#sms_background').height($(document).height());
	$('#sms').height($(document).height());
	$('#sms .sms_outer_transparent_container').height($('#sms .sms_outer_container').height());
	var sms_position_top = (($(window).height()/2) - $('#sms .sms_outer_container').height()/2) + $(window).scrollTop();
	$('#sms .sms_outer_transparent_container').css({top:sms_position_top});
	$('#sms .sms_outer_container').css({top:sms_position_top});
	$('#sms .sms_outer_container').draggable({handle:'.drag_handle'});
	$('#sms .sms_outer_container input').bind('blur', function() {
		sms_validate_field(this.getAttribute('name'));
	});
	$('#sms_background').css('opacity',0.5); /* If this opacity is not set, then in IE the fade-in starts from 100% and the goes transparent */
	$('#sms').hide();
	//$('#sms_background').show('slide',{'direction':'left'},500,function() {
	$('#sms_background').fadeIn('slow',function() {
		//$('#sms').show('slide',{'direction':'right'},500);
		$('#sms').fadeIn('slow');
	});
	
}

function sms_validate_field(field_name) {
	var field_validated = 0;
	var regex = '';
	if (field_name == 'msg') {
		regex = /^.{5,70}$/;
	}
	if (field_name == 'mobile') {
		$('#'+field_name).val($('#'+field_name).val().replace(/[^\d]+/,''));
		regex = /^05[\d]{8}$/;
	}
	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+' .sms_v').show('slide', {direction:'right'}, 500);
		} else {
			$('#icon__'+field_name+' .sms_x').show('slide', {direction:'right'}, 500);
		}
	}, 500);
	
	return field_validated;
	
}

function sms_submit_form(lang_code, recipient_mobile) {
	
	var href_url = 'http://www.shabluldjs.com/';
	var site_title = 'Shablul';
	
	var n_successful = 'Message successfully sent!';
	//var n_voucher_code = 'Your voucher code is:';
	
	if (lang_code == 'he') {
		n_successful = 'הודעתך נשלחה בהצלחה!';
	}
	
	var sms_form_validated = 1;
	
	$('#sms_server_side_notes:visible').slideUp('slow');
	$('#sms_server_side_errors:visible').slideUp('slow');
	
	if (sms_validate_field('msg') != 1) {
		sms_form_validated = 0;
	}
	if (sms_validate_field('mobile') != 1) {
		sms_form_validated = 0;
	}
	
	setTimeout(function() {
		if (sms_form_validated == 1) {
			$('#icon__loader').show('slide', {direction:'right'}, 500);
			$.getJSON(href_url+'?action=submit-sms&recipient-mobile='+recipient_mobile+'&msg='+$('#msg').val()+'&from='+$('#mobile').val()+'&lang='+lang_code+'&callback=?',
				function (data) {
					if (data.result == 'OKAY') {
						$('#sms_server_side_notes .n_content').html(n_successful+'<br>'+site_title);
						$('#sms_form').slideUp('fast', function() {
							$('#sms_server_side_notes').slideDown('fast');
						});
					} else { 
						$('#sms_server_side_errors .e_content').html(data.error);
						$('#sms_server_side_errors').slideDown('fast');
					}
					$('#icon__loader').hide('slide', {direction:'right'}, 500);
				}
			);
		}
	}, 500);
}

function sms_close() {
	//$('#sms').hide('slide',{'direction':'left'},500,function() {
	$('#sms').fadeOut('slow',function() {
		//$('#sms_background').hide('slide',{'direction':'right'},500,function() {
		$('#sms_background').fadeOut('slow',function() {
			$('#sms_background').remove();
			$('#sms').remove();
		});
	});
}

