﻿
		function open_hidden_div(){
			$("#print_div").show();
		}
				
		var printWindow;
		
		function printform(Orj , contentWidth) {
            //var printContent = document.getElementById('page');
			
			//by david
			//1002 or 680
			//if(contentWidth=="undefined"){
				
			

				
			if (typeof contentWidth == "undefined"){			
				contentWidth="680";
			}
			
			var printContent = document.getElementById(Orj);
			
            var windowUrl = 'about:blank';
            var uniqueName = new Date();
            var windowName = 'Print' + uniqueName.getTime();
			var printContentObj = $('#'+Orj).clone();			
			
            printWindow = window.open(windowUrl, windowName);
			
			
			
			//printWindow.document.write('<link rel="stylesheet" type="text/css" href="css/external_stylesheet.css" />');

			var html_head = document.getElementById('html_head');
			
			printWindow.document.write('<!DOCTYPE html>');
			printWindow.document.write('<html lang="zh-tw">');
			printWindow.document.write('<head>');
			 
			//alert(html_head);
			if(html_head != null){
				var head_str = html_head.innerHTML ; 
				printWindow.document.write(head_str);
			}
			printWindow.document.write('<style>');	
 			printWindow.document.write('html, body {overflow: visible!important;}');	           
			printWindow.document.write('</style>');	
			printWindow.document.write('</head>');
			printWindow.document.write('<body>');
			if(printContent != null){
				
				
				//printWindow.document.write('<center>')
				
				//margin:0 auto; 置中
				//width:undefinedpx; margin:0 auto; 無法置中
				//width:680px; margin:0 auto;				
				printWindow.document.write("<div style='width:"+contentWidth+"px; margin:0 auto;' data-type='content'>");
				printWindow.document.write(printContentObj.html());
				printWindow.document.write('</div>');
				printWindow.document.write('<div class="PrintInput" id="print_div">');
				printWindow.document.write('<a onclick="window.print();open_hidden_div();" onkeypress="window.print();open_hidden_div();" style="cursor:pointer" class="print" id="print_block">列印</a>');
				printWindow.document.write('&nbsp;&nbsp;');
				printWindow.document.write('<a onclick="window.close()" onkeypress="window.close()" style="cursor:pointer" class="print">關閉</a>');
				printWindow.document.write('</div>');
				
				
				
				//printWindow.document.write('</center>')
				
			}
			printWindow.document.write('</body>');
			printWindow.document.write('</html>');
			
			
			
            //printWindow.document.close();
			
			setTimeout(function(){

				if($('div[data-type="content"]', printWindow.document).html()!=''){
				//alert(navigator.userAgent);
				if(navigator.userAgent.indexOf(".NET")>=0){
				//alert('do win++'+navigator.userAgent);
				$('div[data-type="content"]', printWindow.document).html('');
				$('div[data-type="content"]', printWindow.document).html(printContentObj.html());
				//alert($('#'+Orj).find('#Country1 option:selected').val());
				}
				else{
				//alert('do no win++'+navigator.userAgent);
				$('div[data-type="content"]', printWindow.document).html('');
				$('div[data-type="content"]', printWindow.document).append(printContentObj);
				}
				
				if($('div[data-type="content"]', printWindow.document).find("#Section_2").length>0){
					$('div[data-type="content"]', printWindow.document).find("#Section_2").hide();
				}
				if($('div[data-type="content"]', printWindow.document).find(".BackToPrev").length>0){					
					$('div[data-type="content"]', printWindow.document).find(".BackToPrev").hide();
				}
				
				if($('div[data-type="content"]', printWindow.document).find("#Post_NavContainer").length>0){					
					$('div[data-type="content"]', printWindow.document).find("#Post_NavContainer").hide();
				}
				
				
				if($('div[data-type="content"]', printWindow.document).find('#Country1').val($('#'+Orj).find('#Country1')).length>0){
					$('div[data-type="content"]', printWindow.document).find('#Country1').val($('#'+Orj).find('#Country1').find('option:selected').val());
				}
				
				if($('div[data-type="content"]', printWindow.document).find('#class_name').length>0){
					$('div[data-type="content"]', printWindow.document).find('#class_name').val($('#'+Orj).find('#class_name').find('option:selected').val());
				}
				
				if($('div[data-type="content"]', printWindow.document).find('#class_name_c').length>0){
					$('div[data-type="content"]', printWindow.document).find('#class_name_c').val($('#'+Orj).find('#class_name_c').find('option:selected').val());
				}
				
				if($('div[data-type="content"]', printWindow.document).find('#area').length>0){
					$('div[data-type="content"]', printWindow.document).find('#area').val($('#'+Orj).find('#area').find('option:selected').val());
				}
				
				if($('div[data-type="content"]', printWindow.document).find('#Select3').length>0){
					$('div[data-type="content"]', printWindow.document).find('#Select3').val($('#'+Orj).find('#Select3').find('option:selected').val());
				}
				
				if($('div[data-type="content"]', printWindow.document).find(".faq-content").length>0){
					$('div[data-type="content"]', printWindow.document).find(".faq-content").show();
				}
				
				
			}
			},400);
			
			//避免JQ載入不成功，重新reload 即可解決問題 by jeff
			//Chrome 會有問題 by david, 排除 Chrome
			//printWindow.location.reload();			
			//alert(navigator.userAgent)
			var isChrome = navigator.userAgent.search("Chrome") > -1;  
			//alert(isChrome);
			if(isChrome){
			}else{
				printWindow.location.reload();
			}
			
            printWindow.focus();

			// 不預設開印表機 by david
            //printWindow.print();
			
            //printWindow.close();
        } 
