//2010-1-30 by aron
//contact email aronwoo@hotmail.com

//Clean the cache
$.ajaxSetup ({
    cache: false 
});

$(document).ready(function(){
  var thisURL = document.URL;
  var aa = thisURL.split( "/" );  
  $(".m-menubar").find("a[href*="+aa[aa.length-1]+"]").parent().addClass("menubg");

});

//错误提示函数
function errshow(){
	alert("database link error");
	history.back();
	}
//清除提示
function errclear(){
	$("#resultshow").html("");  
	}


//搜索
function getsearch(){
	var searchkey = $.trim($('#searchkey').val());
	if(searchkey == "" || searchkey == "keywords"){$('#searchkey').val("keywords"); return false;}else{
		window.location.href="search.asp?searchkey="+searchkey;
		}
	}
function clearsearch(){
	var searchkey = $.trim($('#searchkey').val());
	if(searchkey == "" || searchkey == "keywords"){
	$('#searchkey').val(""); 
	}
	}	
	

//邮件订阅
function emailsubscribe(){
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;	
var emailsubmit_name = $("#emailsubmit_name").val();	
if(emailsubmit_name == "" || reEmail.test(emailsubmit_name)==false){
	$('#resultshow').html("<font color='#ff0000'>Please enter the correct e-mail address</font>");
	return false;
	}
$.ajax({
  type: "get",
  url: "action.asp",
  data: "emailsubmit_name=" + emailsubmit_name + "&action=emailsubmit",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#resultshow").html("<font color='#006633'>submitting...</font>"); 
		},
  success: function(html){
	if($.trim(html)=="ok"){
		$("#resultshow").html("<font color='#006633'>Congratulations! E-mail subscription success!</font>");
	}else{
        $("#resultshow").html("<font color='#ff0000'>Data submitted to the error, please re-submit</font>");
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		$("#resultshow").fadeOut("slow");  
  },
  error: function(){
		errshow();
		}

}); 

}

//询盘提交
function inquirysubmit(){
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;	
var user_id = $('#user_id').val();
var user_name = $('#user_name').val();
var inquiry_memo = $('#inquiry_memo').val();
var inquiry_company = $('#inquiry_company').val();
var inquiry_tel = $('#user_tel').val();
var inquiry_email = $('#user_email').val();
var inquiry_title = $('#inquiry_title').val();
var product_id = $('#product_id').val();
var product_itemno = $('#product_itemno').val();
var product_name = $('#product_name').val();
var product_img = $('#product_img').val();
var user_mobile = $('#user_mobile').val();
var selectedStr = "";   
var $sendMail = $("input[name='kproductinfo']");   
        $sendMail.each( function() {   
            if ($(this).attr("checked")) {   
                selectedStr += $(this).val() + ",";   
            }   
        });   
inquiry_memo += "<br>I want to know:"+selectedStr+"<br>";
if(user_name == ""){
	$('#resultshow').html("<font color='#ff0000'>Please enter your name</font>");
	return false;
	}
if(inquiry_email == "" || reEmail.test(inquiry_email)==false){
	$('#resultshow').html("<font color='#ff0000'>Please enter the correct e-mail address</font>");
	return false;
	}	
$.ajax({
  type: "get",
  url: "action.asp",
  data: "user_id=" + user_id +"&user_name="+ user_name +"&inquiry_memo="+ inquiry_memo +"&inquiry_company=" + inquiry_company +"&inquiry_tel=" + inquiry_tel +"&inquiry_email=" + inquiry_email +"&inquiry_title="+ inquiry_title + "&product_id="+ product_id + "&product_itemno=" + product_itemno +"&product_name="+ product_name +"&product_img=" + product_img + "&user_mobile=" + user_mobile + "&action=inquirysubmit",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#resultshow").html("<font color='#006633'>submitting...</font>"); 
		},
  success: function(html){
	if($.trim(html)=="ok"){
		$("#resultshow").html("<font color='#006633'>Congratulations! Inquiry sent successfully! We will reply to you as soon as possible</font>");
		$('#inbutton').attr("disabled",true);
	}else{
		alert(html);
        $("#resultshow").html("<font color='#ff0000'>Data submitted to the error, please re-submit</font>");
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#resultshow").fadeOut("slow");  
  },
  error: function(){
		errshow();
		}

}); 

}




//用户注册
function useregister(){
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;	
var user_name = $('#user_name').val();   
var user_password = $('#user_password').val();
var user_password1 = $('#user_password1').val();
var user_tel = $('#user_tel').val();
var user_mobile = $('#user_mobile').val();
var user_email = $('#user_email').val();
var user_msn = $('#user_msn').val();
var user_qq = $('#user_qq').val();
if(user_name == ""){
	$('#resultshow').html("<font color='#ff0000'>Please enter your name</font>");
	return false;
	}
if(user_email == "" || reEmail.test(user_email)==false){
	$('#resultshow').html("<font color='#ff0000'>Please enter the correct e-mail address</font>");
	return false;
	}
if(user_password == "" || user_password1== ""){
	$('#resultshow').html("<font color='#ff0000'>Password can not be empty</font>");
	return false;
	}	
if(user_password !=user_password1){
	$('#resultshow').html("<font color='#ff0000'>Not the same password twice</font>");
	return false;
	}	
$.ajax({
  type: "get",
  url: "action.asp",
  data: "user_name=" + user_name +"&user_password="+ user_password +"&user_tel="+ user_tel +"&user_mobile=" + user_mobile +"&user_email=" + user_email +"&user_msn=" + user_msn +"&user_qq="+ user_qq + "&action=userregister",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#resultshow").html("<font color='#006633'>submitting...</font>"); 
		},
  success: function(html){
	if($.trim(html)=="ok"){
		$("#resultshow").html("<font color='#006633'>Congratulations! Successful registration</font>");
		window.location.href="index.asp";
	}else{
        $("#resultshow").html("<font color='#ff0000'>Data submitted to the error, please re-submit</font>");
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#resultshow").fadeOut("slow");  
  },
  error: function(){
		errshow();
		}

}); 

}



function usercheck(){
var user_name = $('#user_name').val();   
if(user_name != ""){
$.ajax({
  type: "get",
  url: "action.asp",
  data: "user_name=" + user_name + "&action=usercheck",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#resultshow").html("<font color='#006633'>User Name inspection...</font>"); 
		},
  success: function(html){
	if($.trim(html)=="ok"){
		$("#resultshow").html("<font color='#006633'>Congratulations! This user name can be used</font>");
	}else{
        $("#resultshow").html("<font color='#ff0000'>This username is not available</font>");
		$('#user_name').val(""); 
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#resultshow").fadeOut("slow");  
  },
  error: function(){
		errshow();
		}

}); 

}

}


function useraccept(){
if($("input[name='regiestcheck']").attr("checked")){
	$("#regiestbutton").attr("disabled",false);
	}else{
	$("#regiestbutton").attr("disabled",true);	
		}
}

function userlogin(){
var user_name = $('#user_name').val(); 
var user_password = $('#user_password').val(); 
if(user_name == "" || user_password ==""){
	$("#resultshow").html("<font color='#ff0000'>Please enter your username and password</font>");
	return false;
	}
$.ajax({
  type: "get",
  url: "action.asp",
  data: "user_name=" + user_name +"&user_password=" + user_password + "&action=userlogin",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#resultshow").html("<font color='#006633'>User log in...</font>"); 
		},
  success: function(html){
	if($.trim(html)=="ok"){
		$("#resultshow").html("<font color='#006633'>Congratulations! Successful login</font>");
		window.location.href="index.asp";
	}else{
        $("#resultshow").html("<font color='#ff0000'>Login failed, please check the user name and password</font>");
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#resultshow").fadeOut("slow");  
  },
  error: function(){
		errshow();
		}

}); 

}


//用户更新
function userupdate(){
var user_id = $('#user_id').val();	
var user_company = $('#user_company').val();	
var user_contactperson = $('#user_contactperson').val();	
var user_address = $('#user_address').val();	
var user_tel = $('#user_tel').val();
var user_mobile = $('#user_mobile').val();
var user_email = $('#user_email').val();
var user_msn = $('#user_msn').val();
var user_qq = $('#user_qq').val();

$.ajax({
  type: "get",
  url: "action.asp",
  data: "user_id=" + user_id +"&user_company="+ user_company +"&user_contactperson="+ user_contactperson +"&user_address=" + user_address +"&user_tel=" + user_tel +"&user_mobile=" + user_mobile +"&user_email="+ user_email +"&user_msn=" + user_msn+ "&user_qq="+ user_qq + "&action=userupdate",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#resultshow").html("<font color='#006633'>submitting...</font>"); 
		},
  success: function(html){
	if($.trim(html)=="ok"){
		$("#resultshow").html("<font color='#006633'>Congratulations! update  success</font>");
	}else{
        $("#resultshow").html("<font color='#ff0000'>Data submitted to the error, please re-submit</font>");
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#resultshow").fadeOut("slow");  
  },
  error: function(){
		errshow();
		}

}); 

}

//用户密码更新
function userpasswordupdate(){
var user_id = $('#user_id').val();	
var user_password = $('#user_password').val();	
var user_password1 = $('#user_password1').val();	
if(user_password == "" || user_password1 == ""){
	$("#resultshow").html("<font color='#ff0000'>Password can not be empty</font>");
	return false;
	}
if(user_password != user_password1){
	$("#resultshow").html("<font color='#ff0000'>Not the same password twice</font>");
	return false;
	}
$.ajax({
  type: "get",
  url: "action.asp",
  data: "user_id=" + user_id +"&user_password="+ user_password + "&action=userpasswordupdate",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#resultshow").html("<font color='#006633'>submitting...</font>"); 
		},
  success: function(html){
	if($.trim(html)=="ok"){
		$("#resultshow").html("<font color='#006633'>Congratulations! update success</font>");
		window.location.href="user.asp?act=login";
	}else{
		alert(html)
        $("#resultshow").html("<font color='#ff0000'>Data submitted to the error, please re-submit</font>");
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#resultshow").fadeOut("slow");  
  },
  error: function(){
		errshow();
		}

}); 

}

//反馈提交
function feedbacksubmit(){
var user_id = $('#user_id').val();	
var feedback_title = $('#feedback_title').val();	
var feedback_memo = $('#feedback_memo').val();	
var feedback_name = $('#feedback_name').val();	
var feedback_tel = $('#feedback_tel').val();	
var feedback_email = $('#feedback_email').val();	
var feedback_others = $('#feedback_others').val();	

if(feedback_title == "" || feedback_name == "" || feedback_email==""){
	$("#resultshow").html("<font color='#ff0000'>Required items can not be empty</font>");
	return false;
	}
$.ajax({
  type: "get",
  url: "action.asp",
  data: "user_id=" + user_id +"&feedback_title="+ feedback_title +"&feedback_memo=" + feedback_memo +"&feedback_name=" + feedback_name +"&feedback_tel=" + feedback_tel +"&feedback_email=" + feedback_email +"&feedback_others=" + feedback_others + "&action=feedbacksubmit",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#resultshow").html("<font color='#006633'>submitting...</font>"); 
		},
  success: function(html){
	if($.trim(html)=="ok"){
		$("#resultshow").html("<font color='#006633'>Congratulations! Successfully submitted</font>");
        $('#fbtn').attr("disabled",true);
	}else{
		alert(html)
        $("#resultshow").html("<font color='#ff0000'>Data submitted to the error, please re-submit</font>");
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#resultshow").fadeOut("slow");  
  },
  error: function(){
		errshow();
		}

}); 

}

//找回密码
function getpassword(){
	var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
	var user_password = $('#user_password').val();
	if(user_password == "" || reEmail.test(user_password)==false){
	$('#resultshow').html("<font color='#ff0000'>Please enter the correct e-mail address</font>");
	return false;
	}
    $("#upp").attr("disabled",true);
	$("#resultshow").html("<font color='#006633'>Password has been sent to your mailbox, please check</font>"); 
}


