//-----------------------------------檢查帳號-------------------------------
	function CheckID_AJAX(InputForm){
		var xmlhttp;
		account = InputForm.value;
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		}else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url;
		url =  _Web_Url + '/index.php/M_model/M_membership/check_id/'+account+"/"+new Date().getTime();
		
		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState == 4){
					if (xmlhttp.status == 200) {
						document.getElementById('checkID').innerHTML = xmlhttp.responseText;
					}else{
						////alert('執行錯誤,代碼:'+xmlhttp.status+'\('+xmlhttp.statusText+'\)');
					}
				}
			};
		xmlhttp.send();
	}
//---------------------------------------------------------------------


function send_add_data(){
	document.getElementById('membership_loading').style.display = 'block';
	document.getElementById('membership_loadingPic').style.display = 'block';
	var_account          = document.getElementById('txt_account').value;
	var_pw               = document.getElementById('txt_pw').value;
	var_pw_again         = document.getElementById('txt_pw_again').value;
	var_pw_notes         = document.getElementById('pw_notes').value;
	var_name             = document.getElementById('txt_name').value;
	var_company_address  = document.getElementById('company_address').value;
	var_company_phone    = document.getElementById('company_phone').value;
	var_company_fax      = document.getElementById('company_fax').value;
	var_email            = document.getElementById('txt_email').value;
	var_product_number  = document.getElementById('product_number').value;


	if (document.getElementById('get_information').checked == true){
		var_get_information = 1;
	}else{
		var_get_information = 0;
	}

	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url;
	url =  _Web_Url + '/index.php/M_model/M_membership/member_save_data/'+new Date().getTime();
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {
					document.getElementById('membership_loading').style.display = 'none';
					document.getElementById('membership_loadingPic').style.display = 'none';
					if (xmlhttp.responseText ==''){
						alert('加入會員成功');
						window.location =  _Web_Url;
					}else{
						alert(xmlhttp.responseText);
					}
				}
			}
		};
		xmlhttp.open('POST',url,true);
		xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		xmlhttp.send("account="+var_account+"&pw="+var_pw+"&pw_again="+var_pw_again+"&pw_notes="+var_pw_notes+"&name="+var_name+"&company_address="+var_company_address+"&company_phone="+var_company_phone+"&company_fax="+var_company_fax+"&email="+var_email+"&product_number="+var_product_number+"&get_information="+var_get_information);
	return false;
}

function send_update_data(){
	document.getElementById('membership_loading').style.display = 'block';
	document.getElementById('membership_loadingPic').style.display = 'block';
	var_product_number   = document.getElementById('txt_product_number').value;
	var_pw               = document.getElementById('txt_pw').value;
	var_pw_again         = document.getElementById('txt_pw_again').value;
	var_pw_notes         = document.getElementById('pw_notes').value;
	var_name             = document.getElementById('txt_name').value;
	var_company_address  = document.getElementById('company_address').value;
	var_company_phone    = document.getElementById('company_phone').value;
	var_company_fax      = document.getElementById('company_fax').value;
	var_email            = document.getElementById('txt_email').value;

	if (document.getElementById('get_information').checked == true){
		var_get_information = 1;
	}else{
		var_get_information = 0;
	}
	
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url;
	url =  _Web_Url + '/index.php/M_model/M_membership/member_update_data/'+new Date().getTime();
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {
					document.getElementById('membership_loading').style.display = 'none';
					document.getElementById('membership_loadingPic').style.display = 'none';
					if (xmlhttp.responseText ==''){
						alert('修改成功!');
					}else{
						alert(xmlhttp.responseText);
					}
				}
			}
		};
		xmlhttp.open('POST',url,true);
		xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		xmlhttp.send("pw="+var_pw+"&pw_again="+var_pw_again+"&pw_notes="+var_pw_notes+"&name="+var_name+"&company_address="+var_company_address+"&company_phone="+var_company_phone+"&company_fax="+var_company_fax+"&email="+var_email+"&get_information="+var_get_information+"&product_number="+var_product_number);
		
	return false;
}

function load_membership(root){
	var bgObj   = document.createElement("input"); 
	bgObj.value = root;
	bgObj.id    = "membership_root";
	bgObj.type  = "hidden";
	document.body.appendChild(bgObj); 
	
	check_login_member();
	 var iWidth = document.body.clientWidth; 
	 var iHeight = document.body.clientHeight; 
	 var bgObj = document.createElement("div"); 
	 bgObj.id = "membership_loading";
	 bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+iHeight*2+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000;z-index:101;display:none;";
	 document.body.appendChild(bgObj); 
	
	 var iWidth  = document.body.clientWidth; 
	 var iHeight = document.body.clientHeight; 
	 var bgObj1  = document.createElement("div"); 
	 bgObj1.id="membership_loadingPic";
	 bgObj1.style.cssText = "position:absolute;left:0px;top:0px;width:auto;height:auto;padding-left:50%;padding-top:40%;text-align:center; font-size:14px; font-weight:bold; color:#FF0;display:none;";
	 document.body.appendChild(bgObj1); 
	 
	document.getElementById('membership_loadingPic').innerHTML = "<img src='"+ _Web_Url + "/system/media/model_img/M_membership/loading.gif'>";
}

function forget_PW(){
	document.getElementById('membership_loading').style.display    = 'block';
	document.getElementById('membership_loadingPic').style.display = 'block';
	a  = document.getElementById('personl_account').value;
	
	//b  = document.getElementById('personl_id').value;
	c  = document.getElementById('personl_email').value;
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url;
	url =  _Web_Url + '/index.php/M_model/M_membership/forget_PW/'+new Date().getTime();
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {
					document.getElementById('membership_loading').style.display = 'none';
					document.getElementById('membership_loadingPic').style.display = 'none';
					if (xmlhttp.responseText ==''){
						alert('驗證成功，已送出到您的信箱密碼!');
					}else{
						alert(xmlhttp.responseText);
					}
				}
			}
		};
		xmlhttp.open('POST',url,true);
		xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		xmlhttp.send("account="+a+"&email="+c);
		
	return false;

}
//-----------------------------------登入------------------------------
	function login_member(){
		id = document.getElementById('txt_login_id').value;
		pw = document.getElementById('txt_login_pw').value;
		
		loading_membership_gif();
		var xmlhttp;
		
		var xmlhttp;
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		}else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url;
		
		url=  _Web_Url + '/index.php/M_model/M_membership/login_member/'+new Date().getTime();
		xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState == 4){
					if (xmlhttp.status == 200) {
						if (xmlhttp.responseText == ''){
							alert('帳號或密碼錯誤，請重新輸入!');
							check_login_member();
						}else{
							alert('登入成功');
                            if( document.getElementById('login_con') ){
                                document.getElementById('login_con').innerHTML = xmlhttp.responseText;
                                history.go(0)
                            }
							
							try{
								guestbook_counts();
								guestbook_show(0);
							}catch(error){}
						}
								
					}
				}
			};
			xmlhttp.open('POST',url,true);
			xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			xmlhttp.send("id="+id+"&pw="+pw);
		return false;
	}
//---------------------------------------------------------------------

//---------------------登出--------------------------------------
	function member_session_distory(){
		s = confirm ('您是否要登出?');
		if (s == true){
			window.location =  _Web_Url + '/index.php/M_model/M_membership/member_session_distory/';
			
		}
	}
//--------------------------------------------------------------


function clear_data(){
	  size = $("input").length-2;
	  for(i=0;i<=size;i++){
		$("input").get(i).value = '';
	  }
	  size = $("textarea").length-1;
	  for(i=0;i<=size;i++){
			$("textarea").get(i).value = '';
	  }

}

//-----------------------------------登入狀態-------------------------------
	function check_login_member(){
		var xmlhttp;
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		}else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url;
		url =  _Web_Url + '/index.php/M_model/M_membership/show_member_status/'+new Date().getTime();
		
		xmlhttp.open('GET',url,true);
		xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState == 4){
					if (xmlhttp.status == 200) {
                        if( document.getElementById('login_con') ){
                            document.getElementById('login_con').innerHTML = xmlhttp.responseText;
                        }
					}else{
						//alert('執行錯誤,代碼:'+xmlhttp.status+'\('+xmlhttp.statusText+'\)');
					}
				}
			};
		xmlhttp.send();
	}
//---------------------------------------------------------------------

function loading_membership_gif(){

    if( document.getElementById('login_con') ){
        document.getElementById('login_con').innerHTML = "<div style=\"width:100%\" align=\"center\"><img src=\""+_Web_Url + "/system/media/model_img/M_common/loading.gif\" width=\"50\" height=\"50\"/></div>";
    }
}
