// JavaScript Document
//請先宣告wwwbase這個變數



//取得左方功能列表
function get_left_list(login_chk){
	login_chk = login_chk || 0;//分類
		$.ajax({
				type: "POST",
				//dataType:'json',
				url: wwwbase+"index.php/fun_c/index_left_prolist/index/"+login_chk,
				data:{
					//'MovieOn':0, 'script':'getHotMovie'
				},
				success: function(data){
					$('#left_list').html(data);
				}
			});
	

}


//取得左方會員功能列表
function get_left_memlist(login_chk){
	login_chk = login_chk || 0;//分類
		$.ajax({
				type: "POST",
				//dataType:'json',
				url: wwwbase+"index.php/fun_c/index_left_memlist",
				data:{
					//'MovieOn':0, 'script':'getHotMovie'
				},
				success: function(data){
					$('.login').html(data);
				}
			});
	

}


//登入
function login(){
	var msg="";
	if($('#acc').val()==""){
		msg+="帳號未填\n";
	}
	
	if($('#pwd').val()==""){
		msg+="密碼未填\n";
	}
	
	if(msg!=""){
		alert(msg);
	}
	else{
		$.ajax({
			type: "POST",
			//dataType:'json',
			url: wwwbase+"index.php/fun_c/login/",
			data:{
				'acc':$('#acc').val(),
				'pwd':$('#pwd').val()
			},
			success: function(data){
				if(data=='ok'){
					alert('登入成功');
					location.reload();
				}
				else{
					alert('登入失敗');
				
				}
			}
		}); 		
	}

}

//登出
function logout(){
		$.ajax({
			type: "POST",
			//dataType:'json',
			url: wwwbase+"index.php/fun_c/logout/",
			data:{
				//'acc':$('#acc').val(),
				//'pwd':$('#pwd').val()
			},
			success: function(data){
				if(data=='ok'){
					//alert('登入成功');
					location.reload();
				}
				else{
					//alert('登入失敗');
				
				}
			}
		}); 		


}

//取得首頁最新消息區塊
function getIndexNews(nt){
	nt = nt || 0;//分類
	
	
	$('#show_news').html(ajax_gif);
	$.ajax({
		type: "POST",
		//dataType:'json',
		url: wwwbase+"index.php/show_index_news/index/"+nt,
		data:{

		},
		success: function(data){
			$('#show_news').html(data);
		}
	}); 
}

function getIndexPic(nt){
	nt = nt || 1;//分類

	
	$('#pro_bg').html(ajax_gif);
	$.ajax({
		type: "POST",
		//dataType:'json',
		url: wwwbase+"index.php/show_index_product/index/"+nt,
		data:{

		},
		success: function(data){
			$('#pro_bg').html(data);
		}
	}); 
}



function profile_upd(){
	var msg="";
	if($('#opwd').val==""){
		msg+="\n";	
	}
	
	
	
	if(msg!=""){
		alert(msg);	
	}
	else{
		alert($('input[name=epaper_ap]:checked').val() );
			
	}
}


function accpwd_query(q_item){
	var msg="";
	

	
	if($("#pk").val()==""){
		
		if(q_item=="acc"){
			msg+="姓名未填\n";
		}
		else{
			msg+="信箱未填\n";
		}
	}
	
	if($("#b_year").val()=="" || $("#b_month").val()=="" || $("#b_day").val()==""){
		msg+="生日不完整\n";
	
	}	
	if(msg!=""){
		alert(msg);
	}
	else{
		$.ajax({
			type: "POST",
		//dataType:'json',
			url: wwwbase+"index.php/fun_c/send_accpwd/",
			data:{
				'q_item':q_item,
				'pk':$("#pk").val(),
				'y':$("#b_year").val(),
				'm':$("#b_month").val(),
				'd':$("#b_day").val()
			},
			success: function(data){
				alert(data);
			}
		}); 
	}
	

}


function search_pro(){
	var pname2="";
	
	if(browser_chk()=="msie"){
		//pname2=encodeURIComponent($("#search_str").val());
		pname2=$("#search_str").val();


	}
	else{
		pname2=unescape($("#search_str").val());
	}

	location.href=wwwbase+'index.php/product/index/1/0/0/'+pname2;
}


function browser_chk(){
	if($.browser.msie) {
		return "msie";
	}
	else if($.browser.safari)
	{
		return "safari";
	}
	else if($.browser.mozilla)
	{
		return "mozilla!";
	}
	else if($.browser.opera)
	{
		return "opera";
	}
	else
	{
		return "i don't konw!";
	}
}

function checkid(sid){
	var e,s,re,hi,sum;
	sid=String(sid);//document.form1.name.value
	sid=sid.toUpperCase();
	while(sid.match(" ")){
		sid=sid.replace(" ","");
	}
	//alert(sid);
	e="ABCDEFGHJKLMNPQRSTUVXYWZIO";
	s=new Array(8,7,6,5,4,3,2,1,1);
	re = new RegExp("^[A-Z][0-9]{9}$");
	// 或 re=/^[A-Z]{1}\d{9}$/ 
	//或re=/^[A-Z]{1}[0-9]{9}$/
 
 
	if (re.test(sid)){
		hi=e.search(sid.substring(0,1));
		hi=hi+10;
		hi=String(hi).toString();
		sum=Number(hi.substring(0,1)) + Number(hi.substring(1,2))*9;
		for (i=0; i<9; i=i+1){
			y=Number(sid.substr(i+1,1));
			sum=sum+y*s[i];
		}
  
  
		if(sum%10!=0){
      
     //alert("sum check fail,sum value=" + sum);
	 
  			return false;
		}
		else{
			return true;
		}

	}
	//alert("id 格式錯誤!!");
	return false;

}


function add_sell_mem(){
		$.ajax({
			type: "POST",
		//dataType:'json',
			url: wwwbase+"index.php/fun_c/add_sell_mem/",
			data:{

			},
			success: function(data){
				alert(data);
			}
		}); 	
	
}
