/* * 	使用套件	： jQuery * 	版本		： 1.3  *///google 流量統計var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));try {var pageTracker = _gat._getTracker("UA-264931-26");pageTracker._trackPageview();} catch(err) {}//訂購單增加商品數量function change_prod_num( type ){		var num = $("#buynum").val();		if( type == "add")		num ++;	else if( type == "re" )		num --;				if( num < 1)		num = 1;  if( num >= 10 )    var discount = 0.9;  else    var discount = 1;	$("#buynum").attr('value' , num);			var price = $("#reader_price").val();	var amount = num * price;	$("#total_num1").text(amount+"元");	$("#total_num2").text(amount * discount+"元");	$("#discount").text((100 - discount * 100)+"%");}//信用卡購買nreader ,收件人同購買人隱藏欄位function hide_receiver_form(){		if ( $("#receiver").is(":checked") )		$("#receiver_form").hide();	else		$("#receiver_form").show();}//信用卡購買nreader,檢查輸入欄位function check_reader_form(){	var flag = true;		//購買人	$("#table1 :input").each(		function(){							if( $(this).val() == 0 && $(this).attr("class") != "nn")				flag = false;		}	);			//收件人	if( !$("#receiver").is(":checked") )	{		$("#table2 :input").each(			function(){								if( $(this).val() == 0 && $(this).attr("class") != "nn")					flag = false;			}		);	}		//勾選二欄式發票	if ( $("#invoice_2").is(":checked") )	{		if( !$("#invoice_2_same").is(":checked")  )		{						$("#table3 :input").each(				function(){									if( $(this).val() == 0 )						flag = false;				}			);					}				else if( $("input[name=invoice_name2]").val() == "" )		{			flag = false;		}	}		//勾選三欄式發票	if ( $("#invoice_3").is(":checked") )	{		if( !$("#invoice_3_same").is(":checked")  )		{						$("#table4 :input").each(				function(){									if( $(this).val() == 0 )						flag = false;				}			);					}				else if( $("input[name=invoice_name3]").val() == "" || $("input[name=vat_number]").val() == "")		{			flag = false;		}	}		if( flag )		$("form").submit(); 	else		alert("請完成欄位的填寫");}//ajax產生城鎮function show_town( uc_seq , ut_id ){	$.ajax	({		type: "POST",		url: "ajax.php?action=show_town", 		data: "uc_seq=" + uc_seq ,					success: function(msg)		{ 									$("#"+ut_id).html(msg);			} 	});}//信用卡購物，檢查發票輸入欄位function check_buy_invoice(){	var flag = true;		var default_value = $("#default_invoice").text();		if( default_value == '' && !$("#invoice_1").is(":checked") && !$("#invoice_2").is(":checked") && !$("#invoice_3").is(":checked") )			flag = false;		if ( $("#invoice_2").is(":checked") )	{		$("#table2 :input").each(			function(){								if( $(this).val() == 0 )					flag = false;			}		);			}		if ( $("#invoice_3").is(":checked") )	{		$("#table3 :input").each(			function(){								if( $(this).val() == 0 )					flag = false;			}		);	}		if( flag )		$("form").submit();		 	else		alert("請完成欄位的填寫");}//重新產生驗證碼function refresh_authcode(){	var authcode_php = "./image_create.php" ;	$("#authcode_img").attr( 'src' , authcode_php + '?' + (new Date()).getTime() );	}//廣告輪撥$(document).ready(function(){		ad_banner_ctrl();});function ad_banner_ctrl(){		var total = $("#banner>div").size();	var now = $("#now_num").val();	var next = parseInt(now) + 1;		if( next > total)		next = 1;		$("#banner>div").each(		function(){							$(this).hide();		}	);				$("#banner_"+next).show();	$("#now_num").attr("value" , next);		setTimeout("ad_banner_ctrl()", 5000 );}//ajax訂閱、退訂電子報function edm_action( action ){	var email = $("#edm_mail").val();		$.ajax	({		type: "POST",		url: "ajax.php?action="+action, 		data: "email=" + email ,					success: function(msg)		{ 									alert(msg)			} 	});}//以下尚未用到，是copy過來當範例的//更改表單送出網址function change_action(form_action){		$("form").attr( 'action' , form_action );	$("form").submit(); }/*//驗證表單$(document).ready(function(){ 	$("form").validate	({						rules:		{      			cpc_seq:{required:true},			password:{required:true},			password2:{required:true , equalTo:"#password"},			nick:{required:true},			email:{required:true , email:true},			book_name:{required:true}	           		},				messages:		{			cpc_seq:{required:"請輸入您的帳號"},			password:{required:"請輸入您的密碼"},			password2:{required:"請再次輸入您的密碼" , equalTo:"請輸入相同的密碼"},			nick:{required:"請輸入您的暱稱"},			email:{required:"請輸入您的信箱" , email:"請輸入正確格式的信箱"},			book_name:{required:"請填寫書名"}		},				submitHandler:function(form)		{			if( $("#password2").val() )			{				$.ajax				({					type: "POST",					url: "account.php?action=check", 					data: "val=" +  $("#password").attr("value") + "&seq=" + $("#seq").attr("value") + "&name=" +  encodeURI( $("#nick").attr("value")) ,								success: function(msg)					{ 						if( msg == "true" )							form.submit();						else if ( msg == "false" )							alert("密碼/暱稱與他人重覆，請重新輸入");														} 				});			}			else				form.submit();		}	});});*///清除表單欄位function remove_val(input_id){	$("#"+input_id).attr("value" , "");}//確認警示框function show_confirm(str , url){	var answer = confirm(str);		if( answer )		location.href = url;		}var line_num = 2;//上傳書籍 - 增加欄位function new_line(){		var newline = $("#copyline").clone();		newline.attr( "id" , "line" + line_num ).show();	$("a" , newline).attr( "href" , "javascript:show_confirm('確定刪除此檔案？' , 'javascript:delete_line(\\'line"+ line_num +"\\')' );" );		newline.insertBefore("#copyline");		line_num++;}//上傳書籍 - 刪除欄位function delete_line(line_id){	$("#"+line_id).remove();}//上傳書籍 - 上傳檔案function upload_book_file(){	if( $("#book_name").val() == "" )	{		alert("請填寫書名！");	}	else if( $("input[type=file]").val() == "" )	{		alert("請至少上傳一個檔案！");	}	else	{		$("#upload_form").ajaxSubmit		({					beforeSend:function()			{				$("#submit_link").click();			},					success: function(msg)			{ 									if( msg == "error" )				{					alert("檔案大小超過80MB！");					location.href = "cm_4.php";				}				else				{					var answer = confirm("上傳完成，請問是否要繼續上傳？");								if( answer )						location.href = "cm_4.php";					else						location.href = "cm_5.php";				}			} 		});	}	}//內容管理 - 修改單元function edit_book_unit(seq){	$("#upload_form").ajaxSubmit	({				beforeSend:function()		{			$("#submit_link").click();		},				success: function(msg)		{ 								if( msg == "error" )			{				alert("請重新上傳檔案！");				history.go(0);			}			else			{				location.href = "cm_5.php?action=list_unit&seq="+seq;							}		} 	});}//內容管理 - 新增單元function new_book_unit(seq){	$("#upload_form").ajaxSubmit	({				beforeSend:function()		{			$("#submit_link").click();		},				success: function(msg)		{ 								if( msg == "error" )			{				alert("請上傳至少一個檔案！");				history.go(0);			}			else			{				location.href = "cm_5.php?action=list_unit&seq="+seq;			}		} 	});		}//內容管理 - 刪除書籍function delete_book(seq){	var answer = confirm("確認刪除此書籍？");		if( answer )	{			$.ajax		({			type: "GET",			url: "cm_9.php?action=delete", 			data: "seq=" + seq ,						success: function()			{ 				alert("刪除成功");				$("#book"+seq).remove();				} 		});		}}

