printSim = function() {
	var DocumentContainer = $('#handle_sim');
	//alert(DocumentContainer.innerHTML);
	var WindowObject = window.open('', 'PrintWindow', 'width='+(DocumentContainer.width()+60)+',height='+(DocumentContainer.height()+60)+',top=30,left=30,toolbars=no,scrollbars=no,status=no,resizable=no');
	WindowObject.document.writeln('<?xml version="1.0" encoding="UTF-8" ?>\n'+
		'<!DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n'+
		'<html xmlns="http://www.w3.org/1999/xhtml">\n<head>\n<link rel="stylesheet" type="text/css" href="'+cpath+'/css/base.css" />\n'+
		'<link rel="stylesheet" type="text/css" href="'+cpath+'/css/calendar_custom.css" />\n'+
		'<link rel="stylesheet" type="text/css" href="'+cpath+'/css/page.css" />\n'+
		'<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="'+cpath+'/css/base_ie.css" /><![endif]-->\n'+
		'<!--[if IE 7]><link rel="stylesheet" type="text/css" href="'+cpath+'/css/base_ie_7.css" /><![endif]-->\n'+
		'<link rel="stylesheet" type="text/css" href="'+cpath+'/css/print.css" media="print"/>\n'+
		'<!--[if lte IE 7]><link rel="stylesheet" type="text/css" href="'+cpath+'/css/print-ie6.css" media="print"/><![endif]-->'+
		'<style type="text/css" media="screen, print">\n'+
		'	#handle_sim {margin: 15px; display: block !important; top: 15px; left: 15px; height: '+DocumentContainer.height()+'px; width: '+DocumentContainer.width()+'px; }\n'+
		'	#print-sim, .print, #handle-print { display: none}\n.handle {height: 0; border-top:17px solid #ff0000; padding: 0}\n'+
		'	#close_panel {margin-top: -15px; color: #ffffff !important;}\n'+
		'	input.picker {width:68px;}\n#simSubmitButton {background-color: #f0f0f0 !important;}\n'+
		'</style>\n'+
		'</head><body><div id="handle_sim">'+DocumentContainer.html()+'</div></body></html>');
	//WindowObject.document.writeln(DocumentContainer.innerHTML);
	try {WindowObject.document.getElementsByName('simFileNumber')[0].value=$("[name=simFileNumber]").val(); } catch(e){}
	try {WindowObject.document.getElementsByName('simOnDate')[0].value=$("[name=simOnDate]").val(); } catch(e){}
	try {WindowObject.document.getElementsByName('simIncome')[0].value=$("[name=simIncome]").val(); } catch(e){}
	try {WindowObject.document.getElementsByName('simPaymentDate')[0].value=$("[name=simPaymentDate]").val(); } catch(e){}
	WindowObject.document.close();
	WindowObject.focus();
	WindowObject.print();
	WindowObject.close();
};
showSim = function($sim) {
	$sim.css({
		"top": ($(window).height() - $sim.outerHeight()) / 2 + $(window).scrollTop() - 80 + "px", //175px
		"left": ($(window).width() - $sim.outerWidth()) / 2 + $(window).scrollLeft() + "px"
	});
	$.getScript(cpath+'/javascript/jquery.ui.datepicker.js');
	$.getScript(cpath+'/javascript/calendar_custom.js');
	$sim.draggable({handle: ".handle"});
	$sim.fadeIn();
	$("#close_panel").click(function() {
		$sim.fadeOut();
		$sim.empty();
	});
	$("#simSubmitButton").click(function() {
		var simFileNumber = $("[name=simFileNumber]").val();
		var simOnDate = $("[name=simOnDate]").val();
		var simIncome = $("[name=simIncome]").val();
		var simPaymentDate = $("[name=simPaymentDate]").val();
		var simDataString = "simFileNumber=" + simFileNumber + "&simOnDate=" + simOnDate + 
			"&simIncome=" + simIncome + "&simPaymentDate=" + simPaymentDate;
		//alert(cpath + "/calculeaza-penalitati.action?"+simDataString);
		$.ajax({
			type: "POST",  
			url: cpath + "/calculeaza-penalitati.action",
			data: simDataString,
			cache: false,
			success: function(msg) {
		    	//alert(msg); alert($("#result_sim").attr('id'));
				$("#result_sim").html(msg).fadeIn();
			}
		});
	});
	var remarq_width='320px';
	if ($.browser.msie && $.browser.version=='6.0')
		remarq_width='360px';
	var rLeft, rTop;
	$("[id^=simPreremarq_]").hover(
			function(e) {
				rLeft=$(this).position().left, rTop=$(this).position().top;
				rowDetailId = (this.id).substring((this.id).indexOf("_") + 1);
				$("#remarq_" + rowDetailId).css({"display":"block","top": (rTop+25)+"px","left":(rLeft-100)+"px","width":remarq_width});
			},
			function(e) {
				$("#remarq_" + rowDetailId).css("display", "none");
			}
	);
};
$(function() {
	var isAlive = false;
	var handle_sim;
	$("#sim").click(function() {
		if (!isAlive) {
			// inserare css
			var headTag = document.getElementsByTagName("head")[0];         
			var newCSSNode = document.createElement('link');
			newCSSNode.type = 'text/css';
			newCSSNode.rel = 'stylesheet';
			newCSSNode.href = cpath+'/css/calendar_custom.css';
			newCSSNode.media = 'screen';
			headTag.appendChild(newCSSNode);
			/*var newJSNode1 = document.createElement('script');
			newJSNode1.type = 'text/javascript';
			newJSNode1.src = cpath+'/javascript/jquery.ui.datepicker.js';
			headTag.appendChild(newJSNode1);
			var newJSNode2 = document.createElement('script');
			newJSNode2.type = 'text/javascript';
			newJSNode2.src = cpath+'/javascript/calendar_custom.js';
			headTag.appendChild(newJSNode2);*/
			
			
			handle_sim = $("<div>");
			handle_sim.attr("id", "handle_sim");
			$("body").append(handle_sim);
			
			isAlive = true;
		} else { 
			handle_sim.empty();
		}
		handle_sim.append('<div class="handle"><div id="close_panel">X</div></div>');
		handle_sim.append('<div class="body_panel"></div>');
		//alert(isAlive);
		//$('.body_panel').load(cpath + "/commonjsp/i.simulator.jsp?cpath="+cpath);
		$.ajax({
			type: "GET",  
			url: cpath + "/commonjsp/i.simulator.jsp?cpath="+cpath,
			cache: false,
			success: function(msg) {
				//alert(msg);
				$('.body_panel').append(msg);
				showSim(handle_sim);
			}
		});
	});
});
