// JavaScript Document
//Modified by atom
//2009-2-3

//Clean the cache
$.ajaxSetup ({
    cache: false 
});

//What's been loading when load the page
$(document).ready(function(){
  $("#Loginbar").html("");						   
  $("#Loginbar").load("LoginbarShowOrHidden.asp"); 
  var thisURL = document.URL;
  var aa = thisURL.split( "/" );  
  $("#menubar").find("a[href*="+aa[aa.length-1]+"]").parent().addClass("link1");
});


//Checking the email login at the top frame
function user_logintop(){
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;	
var user_name = $("#user_name").val();	
var user_password = $("#user_password").val();	
if(user_name == "" || user_name == "Input your email" || reEmail.test(user_name)==false){
	alert("Input your email");
	return false;
	}
if(user_password == ""){
	alert("Input your password");
	return false;
	}	
$.ajax({
  type: "get",
  url: "User_login_check.asp",
  data: "user_name=" + user_name + "&user_password=" + user_password,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#loginsubmit").html("l..."); 
		},
  success: function(html){
	if(html != "||"){
	alert("Successfully login");	
    $("#Loginbar").html("");
	$("#Loginbar").load("LoginbarShowOrHidden.asp");
	}else{
	 alert("Sorry,error username or password,\ncan not login");  	
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		$("#loginsubmit").html("login");  
  },
  error: function(){
		alert("error");
		}

}); 

}

//Checking the email login at the login page
function user_loginpage(){
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;	
var user_name = $("#user_name").val();	
var user_password = $("#user_password").val();	
if(user_name == "" || user_name == "Input your email" || reEmail.test(user_name)==false){
	alert("Input your email");
	return false;
	}
if(user_password == ""){
	alert("Input your password");
	return false;
	}	
$.ajax({
  type: "get",
  url: "User_login_check.asp",
  data: "user_name=" + user_name + "&user_password=" + user_password,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#loginsubmit").val("l..."); 
		},
  success: function(html){
	if(html != "||"){
	alert("Successfully login");
	//window.location.href = "index.html";
	history.back();
	}else{
	 alert("Sorry,error username or password,\ncan not login");  	
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		$("#loginsubmit").val("Login");  
  },
  error: function(){
		alert("error");
		}

}); 

}



//Loginout the email at the top frame
function user_loginout(){
if(confirm("Are you sure to logout?")){	
$.ajax({
  type: "get",
  url: "User_loginout.asp",
  data: "",
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#loginoutbutton").html("l..."); 
		},
  success: function(html){
    $("#Loginbar").html("");
	$("#Loginbar").load("LoginbarShowOrHidden.asp");
	alert("Successfully loginout");
  },
  complete: function(XMLHttpRequest, textStatus){
		$("#loginoutbutton").html("loginout");  
  },
  error: function(){
		alert("error");
		}

}); 
}
}

//Clone the enter key for checking login
function KeyDown(){
 if (event.keyCode == 13){
	 event.returnValue=false;  
     user_logintop();
	 }
}


//Clone the enter key for checking login in login.asp
function eKeyDown(){
 if (event.keyCode == 13){
	 event.returnValue=false;  
     user_loginpage();
	 }
}


//Judge if there are a original name of the login
function userclickjudge(){
var user_name = $("#user_name").val();	
if(user_name == "Input your email"){
 $("#user_name").val("");		
 return false;
}
}

//Clone the enter key for search button
function SearchKeyDown(){
 if (event.keyCode == 13){
	 event.returnValue=false;  
     Search_submit();
	 }
}

//Search form submit
function Search_submit(){
// var search_key = document.getElementById("search_key").value;  
var search_key = $("#search_key").val();  
 if(search_key == "")
	alert("Pls input the search word");	
 else
    window.location.href="search.asp?search_key="+search_key+"";
	}

/*for sign in page *****************************************************************************************************/
//sign in submit here
function signin_submit(){
var user_password = $("#user_passwords").val();
var user_repassword = $("#user_repasswords").val();
var user_name = $("#user_names").val();
var user_sex = $("input[name=sex][checked]").val(); 
var user_company = $("#user_company").val();
var user_contactperson = $("#user_contactperson").val();
var user_address = $("#user_address").val();
var user_city = $("#user_city").val(); 
var user_country = $("#user_country").val(); 
var user_tel = $("#user_tel").val();  
var user_fax = $("#user_fax").val();  
var user_website = $("#user_website").val(); 
var user_business1 = $("input[name=user_business1][checked]").val(); 
var user_business2 = $("input[name=user_business2][checked]").val(); 
var user_business3 = $("input[name=user_business3][checked]").val(); 
var user_business4 = $("input[name=user_business4][checked]").val(); 
var user_business5 = $("input[name=user_business5][checked]").val(); 
var user_business6 = $("input[name=user_business6][checked]").val(); 
var user_business7 = $("input[name=user_business7][checked]").val(); 
var user_business8 = $("input[name=user_business8][checked]").val(); 
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
if(user_name == "" || user_password == ""|| user_repassword== "" || user_password != user_repassword || reEmail.test(user_name)==false){
	alert('you should fill the form correctly');
	return false;
	}
else{
$.ajax({
  type: "get",
  url: "Singin_add.asp",
  data: "user_name=" + user_name + "&user_password=" + user_password + "&user_sex=" + user_sex + "&user_company=" + user_company + "&user_contactperson=" + user_contactperson + "&user_address=" + user_address + "&user_city=" + user_city + "&user_country=" + user_country + "&user_tel=" + user_tel + "&user_fax=" + user_fax + "&user_website=" + user_website + "&user_business1=" + user_business1 + "&user_business2=" + user_business2 + "&user_business3=" + user_business3 + "&user_business4=" + user_business4 + "&user_business5=" + user_business5 + "&user_business6=" + user_business6 + "&user_business7=" + user_business7 + "&user_business8=" + user_business8,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#subbutton").val("l..."); 
		},
  success: function(html){
	if(html == "||"){
	alert("Successfully sign in");	
    window.location.href="index.html";
	}else{
	 alert("Sorry,can not sign in now \nplease try again");  	
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		$("#subbutton").val("Submit"); 
  },
  error: function(){
		alert("error");
		}

}); 



}

}


//check the username where sign in
function registerCheck(){
var user_name = $("#user_names").val();
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
if(user_name == "" || reEmail.test(user_name)==false){
	$("#emailcheck123").html("empty or incorrect email");
	$("#emailcheck567").html("");
	$("#subbutton").attr("disabled",true); 
	}
else{
$.ajax({
  type: "get",
  url: "Singin_check.asp",
  data: "user_name=" + user_name,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#emailcheck123").val("l..."); 
		},
  success: function(html){
	if(html == "y"){
	  $("#emailcheck567").html("the email can be use");
	  $("#emailcheck123").html("");
	  $("#subbutton").attr("disabled",false); 
	}else{
	 $("#emailcheck123").html("the email can not be used"); 
	 $("#user_names").val("");
	 $("#subbutton").attr("disabled",true); 
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#subbutton").val("Submit"); 
  },
  error: function(){
		alert("error");
		}

}); 

}
}

//check if inputting the same password twice
function password_check(){
var user_password = $("#user_passwords").val();
var user_repassword = $("#user_repasswords").val();
if(user_password == "" || user_password != user_repassword){
	$("#repasswordcheck").html("Pls input the correct password");
	$("#subbutton").attr("disabled",true); 
	}	
if(user_password != "" && user_password == user_repassword){
    $("#repasswordcheck").html("&nbsp;*");
	$("#subbutton").attr("disabled",false); 
	}
}


/****************************************************************************/
/////////////////////////////////////////////////////////////////////////////
//feedback submit here
function feedback_submit(){
var feedback_sex = $("input[name=sex][checked]").val(); 
var feedback_company = $("#feedback_company").val();
var feedback_contactperson = $("#feedback_contactperson").val();
var feedback_address = $("#feedback_address").val();
var feedback_city = $("#feedback_city").val(); 
var feedback_country = $("#feedback_country").val(); 
var feedback_tel = $("#feedback_tel").val();  
var feedback_fax = $("#feedback_fax").val();  
var feedback_website = $("#feedback_website").val(); 
var feedback_email = $("#feedback_email").val();
var feedback_business1 = $("input[name=feedback_business1][checked]").val(); 
var feedback_business2 = $("input[name=feedback_business2][checked]").val(); 
var feedback_business3 = $("input[name=feedback_business3][checked]").val(); 
var feedback_business4 = $("input[name=feedback_business4][checked]").val(); 
var feedback_business5 = $("input[name=feedback_business5][checked]").val(); 
var feedback_business6 = $("input[name=feedback_business6][checked]").val(); 
var feedback_business7 = $("input[name=feedback_business7][checked]").val(); 
var feedback_memo = $("#feedback_memo").val();
var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
if(feedback_tel == "" || reEmail.test(feedback_email)==false){
	alert('you should fill the form correctly');
	return false;
	}
else{
$.ajax({
  type: "get",
  url: "Feedback_submit.asp",
  data: "feedback_sex=" + feedback_sex + "&feedback_company=" + feedback_company + "&feedback_contactperson=" + feedback_contactperson + "&feedback_address=" + feedback_address + "&feedback_city=" + feedback_city + "&feedback_country=" + feedback_country + "&feedback_tel=" + feedback_tel + "&feedback_fax=" + feedback_fax + "&feedback_website=" + feedback_website + "&feedback_email=" + feedback_email + "&feedback_business1=" + feedback_business1 + "&feedback_business2=" + feedback_business2 + "&feedback_business3=" + feedback_business3 + "&feedback_business4=" + feedback_business4 + "&feedback_business5=" + feedback_business5 + "&feedback_business6=" + feedback_business6 + "&feedback_business7=" + feedback_business7 + "&feedback_memo=" + feedback_memo,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#subbutton").val("l..."); 
		},
  success: function(html){
	if(html == "||"){
	alert("Feedback submit successfully");	
	}else{
	 alert("Sorry,can not feedback now \nplease try again");  	
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		$("#subbutton").val("Submit"); 
  },
  error: function(){
		alert("error");
		}

}); 



}

}


/******************************************************************************************************************/

//Collect add ***************************************************/
function collect_add(product_id){
var collect_product_id = product_id;	
$.ajax({
  type: "get",
  url: "Collect_add.asp",
  data: "collect_product_id=" + collect_product_id,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		
		},
  success: function(html){
	if(html == "you login first before collectting"){
	 if(confirm("you should login first before collectting,\n\nwould you like to login now?")){
	 window.location.href = "login.html";
	 }
	}else{
	 alert(html); 
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		; 
  },
  error: function(){
		alert("error");
		}

}); 

}

///************************************************************


//inquiry detail add from here/////////////////////////////
function inquiry_detail_add(product_id){
var inquery_detail_product_id = product_id;
var inquery_detail_product_counts = $("#productcounts" + product_id).val();
if(inquery_detail_product_counts == "" || isNaN(inquery_detail_product_counts) == true){
  alert("Please enter the correct qty");
  return false;
}
$.ajax({
  type: "get",
  url: "inquiry_detail_add.asp",
  data: "inquery_detail_product_id=" + inquery_detail_product_id + "&inquery_detail_product_counts=" + inquery_detail_product_counts,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		
		},
  success: function(html){
	if(html == "you login first before inquiry"){
	 if(confirm("you should login first before inquiry,\n\nwould you like to login now?")){
	 window.location.href = "login.html";
	 }
	}else{
	 if(confirm(html)){
	  window.location.href = "myaccount.html" 
	 }
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		 
  },
  error: function(){
		alert("error");
		}

}); 

}


function inquiry_detail_counts_update(inquery_detail_id){
var inquery_detail_product_counts = $("#counts" + inquery_detail_id).val();
if(inquery_detail_product_counts == "" || isNaN(inquery_detail_product_counts) == true){
	alert("please input the correct qty");
	mybasket();
	return false;
	}
 $.ajax({
  type: "get",
  url: "inquiry_detail_counts_update.asp",
  data: "inquery_detail_id=" + inquery_detail_id + "&inquery_detail_product_counts=" + inquery_detail_product_counts,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#inquirycheckout").val("updating...");
		$("#inquirycheckout").attr("disabled",true); 
		},
  success: function(html){
	if(html == "updated"){
	  //alert("updated");
	}else{
	  alert("can not update,please try again");	
	 	}
  },
  complete: function(XMLHttpRequest, textStatus){
		$("#inquirycheckout").val("Inquiry Checkout");
		$("#inquirycheckout").attr("disabled",false); 
  },
  error: function(){
		alert("error");
		}

}); 
}


function inquiry_detail_del(inquery_detail_id){
if(confirm("Are you sure to del it?")){
 $.ajax({
  type: "get",
  url: "inquiry_detail_del.asp",
  data: "inquery_detail_id=" + inquery_detail_id,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		
		},
  success: function(html){
	if(html == "deleted"){
	  mybasket();
	}else{
	  alert("can not delete,please try again");	
	 	}
  },
  complete: function(XMLHttpRequest, textStatus){
		 
  },
  error: function(){
		alert("error");
		}

}); 
}
}

function inquiry_checkout_alert(){
 if(confirm("Are you sure to checkout")){
	$("#myaccountcontainer").load("myaccount_myinfo_show.asp"); 	 
	 }	
}

function inquiry_checkout_memo(){
 $("#myaccountcontainer").load("inquiry_checkout_memo.asp"); 	 
}

function inquiry_checkout_memo_mouseover(){
 var inquery_memo = $("#inquery_memo").val();
 if(inquery_memo == "your kindly suggestion"){
	 $("#inquery_memo").val("");
	 } 
	}

function inquiry_checkout_memo_mouseout(){
 var inquery_memo = $("#inquery_memo").val();
 if(inquery_memo == ""){
	 $("#inquery_memo").val("your kindly suggestion");
	 } 
	}


function inquiry_checkout_submit(){
var inquery_memo = $("#inquery_memo").val();
 $.ajax({
  type: "get",
  url: "inquiry_checkout_submit.asp",
  data: "inquery_memo=" + inquery_memo,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#subbutton").val("l..."); 
		},
  success: function(html){
	if(html != "submited"){
	  alert("Congratuation!!\nPlease pay attention to your " + html + "\nOur service would reply you asap");
	  myinquriyhistory();
	}else{
	  alert("can not submit,please try again");	
	 	}
  },
  complete: function(XMLHttpRequest, textStatus){
		$("#subbutton").val("Ok,sent the inquiry");
  },
  error: function(){
		alert("error");
		}

}); 
}


//*********************************************************************






//My Account begig here****************************************************
//myinformation show
function myinfo(){
$("#myaccountcontainer").load("myaccount_myinfo.asp"); 	
}

//my password show 
function mypassword(){
$("#myaccountcontainer").load("myaccount_password.asp"); 		
}

//my inquiry basket show
function mybasket(){
$("#myaccountcontainer").load("myaccount_basket.asp"); 	
}

//my inquiry history
function myinquriyhistory(){
$("#myaccountcontainer").load("myaccount_history.asp"); 	
}

//my latest alert
function mylatest_alert(){
$("#myaccountcontainer").load("myaccount_latest_alert.asp");	
}

//my latest
function mylatest(){
$("#myaccountcontainer").load("myaccount_latest.asp");		
}

//my collect
function mycollect(){
$("#myaccountcontainer").load("myaccount_collect.asp");		
}



//my download
function mydownload(){
$("#myaccountcontainer").load("myaccount_download.asp");		
}


//myinfo_update here///////////////////////////////
function myinfo_update(){
var user_id = $("#user_id").val();
var user_sex = $("input[name=sex][checked]").val(); 
var user_company = $("#user_company").val();
var user_contactperson = $("#user_contactperson").val();
var user_address = $("#user_address").val();
var user_city = $("#user_city").val(); 
var user_country = $("#user_country").val(); 
var user_tel = $("#user_tel").val();  
var user_fax = $("#user_fax").val();  
var user_website = $("#user_website").val(); 
var user_business1 = $("input[name=user_business1][checked]").val(); 
var user_business2 = $("input[name=user_business2][checked]").val(); 
var user_business3 = $("input[name=user_business3][checked]").val(); 
var user_business4 = $("input[name=user_business4][checked]").val(); 
var user_business5 = $("input[name=user_business5][checked]").val(); 
var user_business6 = $("input[name=user_business6][checked]").val(); 
var user_business7 = $("input[name=user_business7][checked]").val(); 
var user_business8 = $("input[name=user_business8][checked]").val(); 
if(confirm("Are you sure to update your information?")){	
$.ajax({
  type: "get",
  url: "Singin_modify.asp",
  data: "user_id=" + user_id + "&user_sex=" + user_sex + "&user_company=" + user_company + "&user_contactperson=" + user_contactperson + "&user_address=" + user_address + "&user_city=" + user_city + "&user_country=" + user_country + "&user_tel=" + user_tel + "&user_fax=" + user_fax + "&user_website=" + user_website + "&user_business1=" + user_business1 + "&user_business2=" + user_business2 + "&user_business3=" + user_business3 + "&user_business4=" + user_business4 + "&user_business5=" + user_business5 + "&user_business6=" + user_business6 + "&user_business7=" + user_business7 + "&user_business8=" + user_business8,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#subbutton").val("l..."); 
		},
  success: function(html){
	if(html == "||"){
	alert("Successfully update");	
	}else{
	 alert("Sorry,can not update now \nplease try again");  	
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		$("#subbutton").val("Update"); 
  },
  error: function(){
		alert("error");
		}

}); 



}
}




//mypassword_update here///////////////////////////////
function mypassword_update(){
var original_password = $("#original_password").val();
var old_password = $("#old_password").val(); 
var new_password = $("#new_password").val();
var new_repassword = $("#new_repassword").val();
var user_id = $("#user_id").val();
if(original_password != old_password){
	alert("Please input the correct old password,\nOr can not change your password");
	return false;
	}
	
if(new_password == "" || new_repassword != new_password){
	alert("The twice new password are not same,\nPlease check again");
	return false;
	}
	
if(confirm("Are you sure to update your password?")){	
$.ajax({
  type: "get",
  url: "Password_change.asp",
  data: "user_id=" + user_id + "&user_password=" + new_password,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#subbutton").val("l..."); 
		},
  success: function(html){
	if(html == "||"){
	alert("Successfully changed");	
	}else{
	 alert("Sorry,can not change now \nplease try again");  	
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		$("#subbutton").val("Change"); 
  },
  error: function(){
		alert("error");
		}

}); 
}
}


//My Account end here******************************************************













