// Für die vertikale Position der notepad-Box
jQuery(document).ready(function(){
    notepadYpos = 400; 
    $(".product_notepad_btn, .txtList_notepad, .small_notepad_button").click(function(e){
       notepadYpos = e.pageY;
    });
})

function notepad(product_id, sid, titel) {
    $("#notepad_box").css('position', 'absolute');
	$("#notepad_box").css('top', (notepadYpos - 160));
	$("#notepad_box").css('left', 360);	
	$("#notepad_box").draggable();
	$("#notepad_box").show();
	
	$("#notepad_box .hd h3").html('Bitte warten...');
	$("#notepad_box .bd p").html('');
	
	notepadInterfaceUrl = "/php-bin/functions/VoD/includes/notepad_ajax_interface.php?moduleAction=add&productID=" + product_id + "&sid=" + sid;
	
	$.get(notepadInterfaceUrl, function(data){
  		updateDialog(data, titel, sid, product_id);
	});
}

function updateDialog (data, titel, sid, product_id) {
	$("#notepad_box .hd h3").html(titel);
	$("#notepad_box .bd p").html(data);

	// Links zum Notepad. Bei Login-Meldung wird ein anderer Link angezeigt.
	if(data.substr(0,12) == 'Bitte melden') {
		request_uri = window.location.pathname + "?&np_product_id=" + product_id;			
		
		//$("#notepad_box .ft").html('<a href="https://account.maxdome.de/login' + request_uri + '">&gt; zum Login</a>');	
		
		$("#notepad_box .ft").html('<a href="' + getServiceLink(request_uri) + '">&gt; zum Login</a>');	
	} else {
		updateNotepadModule(sid);
		$("#notepad_box .ft").html('<a href="/service/merkzettel/index.php?sid='+ sid +'">&gt; Merkzettel einsehen</a>');	
	}
}

function getServiceLink(request_uri) {
	if(location.href.indexOf('maxdome') == -1) {
		domain = 'nightclub.de';
	} else {
		domain = 'maxdome.de';
	}
	return "https://account." + domain + "/login" + request_uri;
}

function closePopup(id) {
	$("#"+id).css('display', 'none');
}

function updateNotepadModule(sid) {
	notepadModuleUrl = "/php-bin/functions/VoD/includes/notepad_ajax_interface.php?moduleAction=renderNotepadModule&sid=" + sid;
	$("#notepadModule").load(notepadModuleUrl);
}

function isset(varname){
  return(typeof(window[varname])!='undefined');
}