﻿var additionalRecipientsCount = 0;

function ShowRecommenationForm(hrid) 
{
	jQuery.ajax({
		url: applicationPath + "/ajaxservice/recommendationAjax.html?hrid=" + hrid,
		success: function (html) {
			jQuery("#recommendationForm").html(html);
			jQuery("#recommendationForm").modal(
			{
				close: true,
				closeHTML: '',
				closeClass: "popupBoxClosePopup"
			});
			jQuery('#draggableProductRecommendation').draggable({ scroll: false, handle: '#draggableHandelProductRecommendation', cancel: ':input,option,a' });
			CheckIfResized();
			return false;
		}
	})

}

function CheckIfResized() 
{
	var scrollPanel = jQuery('#ScrollPaneDiv1ProductRecommendation');
	scrollPanel.jScrollPane({ showArrows: true, scrollbarWidth: 13, dragMaxHeight: 93, dragMinHeight: 93, preventAni: true});
}

function ShowVideo(id) {
	jQuery("#" + id).modal({
		close: true,
		closeClass: "popupBoxClose"
	});   
}

function SendRecommendationEmail() {
	jQuery("#recommendationEmailForm").validate().form();

	if (jQuery("#recommendationEmailForm").valid()) 
	{
		jQuery.post(applicationPath + "/ajaxservice/sendRecommendationEmail.html",
			jQuery("#recommendationEmailForm").serialize(),
			function(html) 
			{
				jQuery.modal.close();
				jQuery("#recommendationForm").html(html);
				jQuery('#recommendationForm').modal(
				{
					closeHTML: '',
					close: true,
					closeClass: "popupBoxClosePopup"
				});

			jQuery('#draggableProductRecommendationThankYou').draggable({ scroll: false, handle: '#draggableHandelProductRecommendation', cancel: ':input,option,a' });
			return false;
		   }
	   );
   }
	CheckIfResized();
}

function ShowVideo(title, previewImage, sd, hd, url, id) {

	var flashvars = {};
	// corner radius - clockwise from top-left
	flashvars.corners = "10,10,10,10";
	flashvars.framerate = "25";
	flashvars.platform = navigator.platform
	flashvars.browser = navigator.userAgent;
	flashvars.localXML = applicationPath + "/medien/videoPlayerLocalization.xml";
	flashvars.recommendations = applicationPath + '/ajaxService/sendRecommendationVideo.html?url=' +  url + "?playid=" + id;
	flashvars.initdelay = "0";
	flashvars.buffer = "10";

	if (sd == '' && hd != '') 
	{
		sd = hd;
		hd = null;
	}
	if (hd == '')
		hd = null;

	var videos = [
				{
					videoID: '',
					PageInfo: '',
					name: title,
					info: '',
					image: previewImage,
					sd: sd,
					hd: hd
				}
			];

	flashvars.videos = encode(videos);

	var params = {};
	params.allowfullscreen = "true";
	//params.wmode = "transparent";

	var attributes = { id: 'video', name: 'video' }; // give an id to the flash object

	jQuery("#videoPreviewModal").modal({
		close: true,
		closeHTML: '',
		closeClass: "popupBoxClosePopup",
		onOpen: function(dialog) {
			jQuery("#videoTitle").html(title);
			swfobject.embedSWF(applicationPath + "/js_files/VideoPlayer.swf?v=1.1", "videoplayer", "640", "400", "9.0.0", applicationPath + "/js_files/expressInstall.swf", flashvars, params, attributes);
			dialog.overlay.fadeIn('fast', function() {
				dialog.container.slideDown('fast', function() {
					dialog.data.fadeIn('fast');
				});
			});
		},
		onClose: function(dialog) {
			dialog.data.fadeOut('fast', function() {
				dialog.container.slideUp('fast', function() {
					dialog.overlay.fadeOut('fast', function() {
						jQuery.modal.close();
					});
				});
			});
		}
	});
}

function CloseModal() {
	jQuery.modal.close(); 
}


function showWindow(url, name, width, height) {
	var win = window.open(url, name, 'width=' + width + ',height=' + height + ',top=20,left=20,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no', true);
	if (win) {
		win.focus();
	}
	return false;
}

function RemoveRecipient(titleId, inputId)
{
	jQuery('#' + titleId).remove();
	jQuery('#' + inputId).remove();
	//revalidate form if not valid

	if (jQuery(".ErrorContainerrecommendationEmailForm :first").length > 0) {
		jQuery("#recommendationEmailForm").validate().form();
	}
	additionalRecipientsCount--;
	CheckIfResized();
	if (additionalRecipientsCount == 0) {
		jQuery('#artikel').html('den');
	}
}

function AddRecipient() 
{
	var row = document.getElementById('subjectLine');
	var table = row.parentNode;
	var id = new Date().getTime();
	
	var newRow = table.insertRow(row.rowIndex);
	jQuery(newRow).attr('id', 'recipientTitle' + id);
	jQuery(newRow).html(jQuery('#recipientTitle').clone().html());

	var title = jQuery('#recipientTitle' + id + ' span').html('Weiterer Empfänger');

	var button = jQuery('#recipientTitle' + id + ' .recipientButton');
	button.attr('src', applicationPath + '/images/bt-recipient-remove.png');
	button.removeAttr('onclick');
	button.bind('click', function () { RemoveRecipient('recipientTitle' + id, 'recipientLine' + id) });

	newRow = table.insertRow(row.rowIndex);
	jQuery(newRow).attr('id', 'recipientLine' + id);

	jQuery(newRow).html(jQuery('#recipientLine').html());

	var newNameId = 'ReceiverNameProductRecommendation' + id;
	var newEmailId = 'ReceiverEmailProductRecommendation' + id;

	jQuery('#recipientLine' + id + " input[name='ReceiverEmailProductRecommendation']").attr('id', newEmailId).attr('name', newEmailId);
	jQuery('#recipientLine' + id + " input[name='ReceiverNameProductRecommendation']").attr('id', newNameId).attr('name', newNameId);


	jQuery('#' + newNameId).rules("add", {
					 required: true,
					 messages: {
					   required: "Bitte geben Sie einen Empfängernamen ein."
					 }
					});

	jQuery('#' + newEmailId).rules("add", {
					 required: true,
					 email: true,
					 messages: {
						 required: "Bitte geben Sie eine gültige Empfänger Email ein.",
					   email: "Bitte geben Sie eine gültige Empfänger Email ein."
					 }
					});

	CheckIfResized();
	additionalRecipientsCount++;
	jQuery('#artikel').html('die');

}

function ChangePassword() {
	jQuery("#changePasswordForm").validate().form();

	if (jQuery("#changePasswordForm").valid()) {
		jQuery.post(applicationPath + "/ajaxservice/changepassword.html",
			jQuery("#changePasswordForm").serialize(),
			function (html) {
				jQuery("#contentChangePassword").html(html);
				return false;
			}
	   );
	}

	}

	function ChangeLogin() {
		jQuery("#changeLoginForm").validate().form();

		if (jQuery("#changeLoginForm").valid()) {
			jQuery.post(applicationPath + "/ajaxservice/changelogin.html",
			jQuery("#changeLoginForm").serialize(),
			function (html) {
				jQuery("#contentChangeLogin").html(html);
				jQuery.ajax({
					url: applicationPath + "/ajaxservice/ajaxLogin.html",
					success: function (html) {
						jQuery("#ajaxLoginForm").html(html);
						jQuery("#contentChangePassword").html(null);

					} 
				});
				return false;
			}
	   );
		}
	}   
	

