if(typeof Print == "undefined") var Print = new Object();
Print = function() {
	
}
Print.prototype = {
	showTicket:function(movieTitle, date, day, time, dateTime, t1Number, t2Number, price, seats1, seats2) {
		this.w = window.open('', '', 'location=0,status=0,scrollbars=0,width=100,height=50');
		
		this.w.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><head><title>Ticket</title>");
		
		this.w.document.write("<script language=\"JavaScript\" type=\"text/javascript\">");
		this.w.document.write("function printTicket(){");
 		//this.w.document.write("button.style.display = \"none\";");
 		this.w.document.write("window.print();");
 		this.w.document.write("window.close(); }");
		this.w.document.write("window.onload = function() { printTicket(); }");
		this.w.document.write("</script>");
		
		this.w.document.write("<style type=\"text/css\">");
		this.w.document.write("body { background: #FFF;	width: 100%; height: 100%; padding: 0; margin: 0; }");
		this.w.document.write("#ticket { width: 800px; height: 120px; }");
		this.w.document.write("input { background: none; border: none; font-size: 13px; font-family: Lucida Console; }");
		this.w.document.write("#ticketId1 {	position: absolute;	left: 395px; top: 0; text-align: right; width: 130px; }");
		this.w.document.write("#ticketId2 {	position: absolute;	left: 650px; top: 0; text-align: right;	width: 130px; }");
		this.w.document.write("#movieTitle { position: absolute; left: 26px; top: 0; text-align: center; width: 500px; }");
		this.w.document.write("#ticketPlace1 { position: absolute; left: 20px; top: 53px; text-align: center; width: 80px; }");
		this.w.document.write("#date { position: absolute; left: 180px;	top: 53px; text-align: left; width: 110px; }");
		this.w.document.write("#weekDay { position: absolute; left: 298px; top: 53px; text-align: center; width: 78px; }");
		this.w.document.write("#hour { position: absolute; left: 390px;	top: 53px; text-align: center; width: 80px; }");
		this.w.document.write("#price { position: absolute; left: 575px; top: 53px; text-align: center; width: 115px; }");
		this.w.document.write("#fullDate { position: absolute; left: 800px; top: 10px; text-align: center; width: 230px; }");
		this.w.document.write("#ticketPlace2 { position: absolute; left: 800px;	top: 40px; text-align: center; width: 230px; }");
		this.w.document.write("#printButton { border:solid 1px #000; background: #999; }");
		this.w.document.write("</style>");
		
		this.w.document.write("</head><body>");
		this.w.document.write("<div id=\"ticket\">");
		this.w.document.write("<!--<input type=\"text\" id=\"ticketId1\" value=\"" + t1Number + "\" />");
		this.w.document.write("<input type=\"text\" id=\"ticketId2\" value=\"" + t2Number + "\" />-->");
		this.w.document.write("<input type=\"text\" id=\"movieTitle\" value=\"" + movieTitle + "\" />");
		this.w.document.write("<input type=\"text\" id=\"ticketPlace1\" value=\"" + seats1 + "\" />");
		this.w.document.write("<input type=\"text\" id=\"date\" value=\"" + date + "\" />");
		this.w.document.write("<input type=\"text\" id=\"weekDay\" value=\"" + day + "\" />");
		this.w.document.write("<input type=\"text\" id=\"hour\" value=\"" + time + "\" />");
		this.w.document.write("<input type=\"text\" id=\"price\" value=\"price:" + price + "\" />");
		this.w.document.write("<input type=\"text\" id=\"fullDate\" value=\"" + dateTime + "\" />");
		this.w.document.write("<input type=\"text\" id=\"ticketPlace2\" value=\"" + seats2 + "\" />");
		this.w.document.write("</div>");
		this.w.document.write("<!--<input type=\"button\" onclick=\"javascript:printTicket(this)\" value=\"print\" id=\"printButton\"/>-->");
		this.w.document.write("</body></html>");
		
		this.w.document.close();
		this.w.focus();
	},
	printTickets:function(tickets) {
		
		var numOfTickets = tickets.length;
		var ticketsStr = "";
		for(i=0; i<numOfTickets; i++) {
			
			var seats1 = tickets[i].seats1;
			
			ticketsStr += "\n\n<div class=\"ticket\">";
			
			ticketsStr += "<div class=\"firstRow\">\n";
			ticketsStr += "<div class=\"movieTitle\">" + tickets[i].movieTitle + "</div>";
			ticketsStr += "<div class=\"dateTime\">" + tickets[i].dateTime + "</div><br class='clear' />";
			ticketsStr += "</div>\n";
			
			ticketsStr += "<div class=\"secondRow\">\n";
			ticketsStr += tickets[i].seats1 + getIntervals(13);
			ticketsStr += tickets[i].date + getIntervals(7);
			ticketsStr += tickets[i].day + getIntervals(7);
			ticketsStr += tickets[i].time + getIntervals(18);
			ticketsStr += tickets[i].price + getIntervals(23);
			ticketsStr += "Rað " + seats1.charAt(0) + getIntervals(3);
			ticketsStr += "Stólur " + seats1.charAt(1) + (seats1.charAt(2) ? seats1.charAt(2) : "");
			ticketsStr += "</div>\n";
			
			ticketsStr += "</div>";
			
		}
		
		// paper size - ? x 55mm
		var ticketTopDistance = "55px";
		var ticketWidth = "1100px";
		var firstRowLeftDistance = "15px";
		var firstRowWidth = "1010px";
		var distanceBetweenTheRows = "80px";
		var secondRowLeftDistance = "15px";
		var fontSize = "13px";
		
		this.w = window.open('', '', 'location=0,status=0,scrollbars=1,width=150,height=80');
		
		this.w.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><head><title>Ticket</title>");
		
		this.w.document.write("<script language=\"JavaScript\" type=\"text/javascript\">\n");
		this.w.document.write("function printTicket(){\n");
 		//this.w.document.write("button.style.display = \"none\";");
 		this.w.document.write("window.print();\n");
 		this.w.document.write("window.close(); }\n");
		this.w.document.write("window.onload = function() { printTicket(); }\n");
		this.w.document.write("</script>\n");
		
		this.w.document.write("<style type=\"text/css\">\n");
		this.w.document.write("body { background: #FFF;	width: 100%; height: 100%; padding: 0; margin: 0; }\n");		
		this.w.document.write("div { font-size: " + fontSize + "; font-family: Lucida Console; }\n");
		this.w.document.write(".clear { clear:both; }\n");
		
		// main		
		this.w.document.write(".ticket { padding: 55px 0 0 0; width: " + ticketWidth + "; display: block; page-break-after: always; }\n");
		this.w.document.write(".firstRow {	display: block; margin: 0 0 0 " + firstRowLeftDistance + "; width: " + firstRowWidth + "; }\n");
		this.w.document.write(".secondRow { display: block; margin: " + distanceBetweenTheRows + " 0 0 " + secondRowLeftDistance + "; }\n");
		
		// first row
		this.w.document.write(".movieTitle { float: left; }\n");
		this.w.document.write(".dateTime { float: right; }\n");
		
		this.w.document.write("</style>\n\n");
		
		this.w.document.write("</head><body>");
		this.w.document.write(ticketsStr);
		this.w.document.write("</body></html>");
		
		this.w.document.close();
		this.w.focus();
	}	
}

function getIntervals(num) {
	var str = "";	
	var i = 0;
	for(i=0; i<num; i++) {	
		str += "&nbsp;";
	}
	return str;
}

var p = new Print();
