// JavaScript Document
//Modified by atom
//2009-2-3

//Clean the cache
$.ajaxSetup ({
    cache: false 
});

//模拟回车键--邮件订阅
function KeyDown(){
 if (event.keyCode == 13){
	 event.returnValue=false;  //不刷新界面
     //document.form1.loginsubmit.click(); //使用表单提交
     Subscribe(0);
	 }
}

//模拟回车键--用户登录
function LoginKeyDown(){
 if (event.keyCode == 13){
	 event.returnValue=false;  //不刷新界面
     //document.form1.loginsubmit.click(); //使用表单提交
     Js_userloginlocal();
	 }
}

//function orderQuery(){
//var order_sn = $("#order_sn").val();
//$.ajax({
//  type: "get",
//  url: "function/checkorderno.php",
//  data: "order_sn=" + order_sn,
//  cache: false,
//  beforeSend: function(XMLHttpRequest){
//		//$("#registeradd_state").val("loading..."); 
//		},
//  success: function(html){
//	if(html != "ok"){
//	 alert("success"+html);
//	 // $("#registeradd_state").html("<font color=green><br />恭喜您,注册成功!<br /></font>");
//	 // history.back();
//	  //$("#subbutton").attr("disabled",true); 
//	}else{
//	// $("#registeradd_state").html(html+"<font color=red><br />对不起,注册不成功!<br /></font>"); 
//	alert("error");
//	// $("#subbutton").attr("disabled",true); 
//	}
//  },
//  complete: function(XMLHttpRequest, textStatus){
//		//$("#subbutton").val("Submit"); 
//  },
//  error: function(){
//		alert("error");
//		}
//
//}); 
// 	
//}

//帐号长度检测开始
function Js_registerchecklocal(){
 var user_name = $("#user_name").val();

 if(user_name == "" || user_name.length < 5 || user_name.length > 30){
	
	 $("#usernamewrong").html('<font color=red><img src="images/27.gif" align="absmiddle">Please input your email</font>');
	$("#subbutton").attr("disabled",true);
	 return false;
 }else{
	 $("#usernamewrong").html("");
	 registerCheck();
	 }
 
}
//帐号长度检测结束
//用户注册，邮箱检测  2008-10-27 修改 by 李聪颖
function checkuser(){
	//alert("adasd");
 var email =$("#email").val();
 document.getElementById("username2").value =email;
 //var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
 var reEmail = /([A-Za-z0-9_-]+@[A-Za-z0-9-]+\.\w+)(\.{0,1}\w*)(\.{0,1}\w*)/;
 if(email == "" || reEmail.test(email)==false){
	 $("#username_notice").html('Please enter your email address.');
	 $("#username_img").html('<img src="themes/wholesale2010/images/wrong.gif" align="absmiddle">');
	$("#subbutton").attr("disabled",true);
	 return false;
 }else
	 {
	 $("#username_notice").html("");
	 Js_registeremailcheck();
	 }
 
}

//邮箱唯一性检测开始
function Js_registeremailcheck(){
var email =$("#email").val();
if(email == "" ){
	$("#username_notice").html('Please input a email as your passport.Example:abc@whosalesale-dress.net.');
	$("#username_img").html('<img src="themes/wholesale2010/images/wrong.gif" align="absmiddle">');
	$("#subbutton").attr("disabled",true); 
	}
else{
$.ajax({
  type: "get",
  url: "function/checkusername.php",
  data: "email=" + email,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		$("#username_notice").val("Checking..."); 
		},
  success: function(html){
	if(html == "ok"){
	 
	  $("#username_notice").html('');
	  $("#username_img").html('<img src="themes/wholesale2010/images/right.gif" align="absmiddle">');
	  $("#subbutton").attr("disabled",false); 
	}else{
	 $("#username_notice").html('The email address has been registered.Please enter another one.'); 
	 $("#username_img").html('<img src="themes/wholesale2010/images/wrong.gif" align="absmiddle">');
	 $("#subbutton").attr("disabled",true); 
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#subbutton").val("Submit"); 
  },
  error: function(){
		alert("error");
		}

}); 

}
}


//检测im选中状态
function Js_Checkim(){
	var imtype = $('[name="imtype"][checked=true]:radio').val();   
	var imvalue = $("#imvalue").val();
	
	if (imtype=="msn"  && imvalue!=''){
		document.getElementById("other[msn]").value=imvalue;
		document.getElementById("other[skype]").value="";
		document.getElementById("other[qq]").value="";
		document.getElementById("other[yahoo]").value="";
		}
		
	else if(imtype=="skype" && imvalue!=''){
		document.getElementById("other[msn]").value="";
		document.getElementById("other[skype]").value=imvalue;
		document.getElementById("other[qq]").value="";
		document.getElementById("other[yahoo]").value="";
		}
	else if(imtype=="yahoo" && imvalue!=''){
		document.getElementById("other[msn]").value="";
		document.getElementById("other[skype]").value="";
		document.getElementById("other[qq]").value="";
		document.getElementById("other[yahoo]").value=imvalue;
		}
	else if(imtype=="qq" && imvalue!=''){
		document.getElementById("other[msn]").value="";
		document.getElementById("other[skype]").value="";
		document.getElementById("other[qq]").value=imvalue;
		document.getElementById("other[yahoo]").value="";
		}
	else
	{
		
		}

}

//密码长度检测开始
function PasswordLongCheck(){
 var password = $("#password2").val();
 if(password == "" || password.length < 6 || password.length > 20){
	
	 $("#UserPasswordCheck").html("Your password must between 6-20 characters.");
	 $("#userpassword_img").html('<img src="themes/wholesale2010/images/wrong.gif" align="absmiddle">');
	 $("#subbutton").attr("disabled",true);
	 return false;
 }else{
	 $("#UserPasswordCheck").html("");
	 $("#userpassword_img").html('<img src="themes/wholesale2010/images/right.gif" align="absmiddle">');
	 
	 }
 
}
//密码长度检测结束

//验证密码长度检测开始
function RePasswordLongCheck(){
// var conform_password = $("#conform_password").val();
 var conform_password = $("#conform_password2").val();
 if(conform_password == "" || conform_password.length < 6 || conform_password.length > 20){
	
	 $("#UserPasswordCheck").html("Your password must between 6-20 characters.");
	 $("#userpassword_img").html('<img src="themes/wholesale2010/images/wrong.gif" align="absmiddle">');
	$("#subbutton").attr("disabled",true);
	 return false;
 }else{
	 $("#UserPasswordReCheck").html("");
	 $("#userpassword_img").html('<img src="themes/wholesale2010/images/right.gif" align="absmiddle">');
	
	 }
  password_check(); 
}
//验证密码长度检测结束

//密码合法性检测开始
function password_check(){
var password = $("#password2").val();
var conform_password = $("#conform_password2").val();
if(password == "" || password != conform_password){
	$("#UserPasswordCheck").html("The two passwords you entered don't match. Please try again.");
	$("#userpassword_img").html('<img src="themes/wholesale2010/images/wrong.gif" align="absmiddle">');
	$("#subbutton").attr("disabled",true); 
	}	
if(password != "" && password == conform_password){
    $("#UserPasswordCheck").html("");
	$("#userpassword_img").html('<img src="themes/wholesale2010/images/right.gif" align="absmiddle">');
	$("#subbutton").attr("disabled",false); 
	}
}
//密码合法性检测结束

//添加购物车
function addToCart2(goods_id){

$.ajax({
  type: "get",
  url: "function/goods_status.php",
  data: "goods_id=" + goods_id,
  cache: false,
  beforeSend: function(XMLHttpRequest){
	 // alert("adad");
	  
		//$("#registeradd_state").val("loading..."); 
		},
  success: function(html){
	if(html == "outofstock"){

	  alert("out of stock...");

	}else{
 

	$("#hezctitle").html("<li style=\"background-color:#F90; line-height:25px;\" >Please select the goods attribute</li>");
	$("#hezcsmall").html(html);
	showDiv();
	
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#subbutton").val("Submit"); 
  },
  error: function(){
		alert("error");
		}

}); 
 	
}

//添加购物车3
function addToCart3(goods_id){
var number = $("#number").val();	
var spec_arr     = new Array();
var formBuy      = document.forms['ECS_FORMBUY'];
if (formBuy)
  {
    spec_arr = getSelectedAttributes(formBuy);

    if (formBuy.elements['number'])
    {
      number = formBuy.elements['number'].value;
    }
  }

$.ajax({
  type: "get",
  url: "function/goods_addtocart.php",
  data: "goods_id="+ goods_id+"&number="+number+"&spec_arr="+spec_arr,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		//$("#registeradd_state").val("loading..."); 
		},
  success: function(html){
	if(html == "outofstock"){
	  alert("out of stock...");
	}else{

	$("#hezctitle").html("<li style=\"background-color:#F90; line-height:25px;\" >The product has been added to your cart.</li>");
	$("#hezcsmall").html("<li style=\" padding-left:5px; margin-top:10px\" >Thanks for your order, Now you can:</li><li><table align=\"center\"><tr><td><A href=\"Javascript::\"  style=\"cursor:pointer\" ><input type=\"button\" name=\"continue\" value=\"Continue Shopping\" onClick=\"javascript:closeDiv()\" ></A></td><td>&nbsp;</td><td><A href=\"flow.php\"><input type=\"button\" name=\"viewcart\" value=\"View Cart\"  onclick=\"gocart()\"></A></td></tr></table></li>");
	showDiv();
	
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#subbutton").val("Submit"); 
  },
  error: function(){
		alert("error");
		}

}); 
 	
}


//order tracking 检测
function checktracking(){
 var ordernum = $("#ordernum").val();
 var tracknum = $("#tracknum").val();
 alert(ordernum);
 return false;
 if(ordernum == "" && tracknum == ""){
	
	 alert("Please enter your order number or your order\'s tracking number to view order status.");

	 return false;
 }else{
	 //$("#UserPasswordCheck").html("");
	 //$("#userpassword_img").html('<img src="themes/wholesale2010/images/right.gif" align="absmiddle">');
	 
	 }
 
}

//优惠码检测检测
function CheckVoucherCode(){
 var voucher_code = $("#verify-box").val();
 var re = /[\r\n]+/mg; //替换换行符

 if(voucher_code == "" ){
	
	 $("#vouchercodestatus").html('Please input your voucher code.');

	 return false;
 }else{
	
		$.ajax({
		  type: "get",
		  url: "function/checkvouchercode.php",
		  data: "voucher_code="+ voucher_code,
		  cache: false,
		  beforeSend: function(XMLHttpRequest){
				},
		  success: function(html){
			 html =html.replace(re, ""); 
			if(html == "The promotional voucher has been expired.")
			{
				$("#verify-box").attr("value","");//设置优惠码为空
				}
			$("#vouchercodestatus").html(html);
			
		  },
		  complete: function(XMLHttpRequest, textStatus){
		  },
		  error: function(){
				alert("error");
				}
		
		}); 
	 
	 }
 
}

function invoice_query_show()
	{
$("#invoice_query_list").load("function/invoice_query.php"); 
}



function get_user_info(){
	//alert("asdsad");
//$("#invoice_query_list").load("function/invoice_query.php"); 
$("#head-login").load("function/head_user_info.php");
}

//处理投票 20100816
function vote(vote_id){
 
	 var re = /[\r\n]+/mg; //替换换行符
		$.ajax({
		  type: "get",
		  url: "vote1.php",
		  data: "vote_id="+ vote_id,
		  cache: false,
		  beforeSend: function(XMLHttpRequest){
				},
		  success: function(html){
			 html =html.replace(re, ""); 
			if(html == "login")
			{
				 alert("Please login.");
	             window.open("../../user.php?act=login","","","");
				}
			else if(html == "done")
			{
				 alert("You have voted already.");
	            // window.open("../../user.php?act=login","","","");
				}
			else
			{
			//$('vote_val').innerHTML = updated_result;
			$("#vote_val").html(html);
			}
			
		  },
		  complete: function(XMLHttpRequest, textStatus){
		  },
		  error: function(){
				alert("error");
				}
		
		}); 
	 
	 }
	 
function change_shipping_list()
{
	//alert("asdsad");

$("#flow-shipping-list").load("c.php");

}


//优势专题验证
function check_todayoffer(){
var textfield =$("#textfield").val();
var textfield2 =$("#textfield2").val();
var textfield3 =$("#textfield3").val();
var re = /[\r\n]+/mg; //替换换行符 
if(textfield == "" ){
	alert("Item number and link blanks should be filled out");
	return false;
	}
if(textfield2 == "" ){
	alert("Item number and link blanks should be filled out");
	return false;
	}
if(textfield3 == "" ){
	alert("Please enter the price of the linked product");
	return false;
	}
if(isNaN(textfield3)){
            alert('You need to fill in a digital price');
			 document.getElementById("textfield3").value='';
	  		document.getElementById("textfield3").focus();
            return false;
    }
$.ajax({
  type: "get",
  url: "function/todayoffer_check_goods_sn.php",
  data: "textfield=" + textfield+"&textfield2="+textfield2+"&textfield3="+textfield3,
  cache: false,
  beforeSend: function(XMLHttpRequest){
		
		},
  success: function(html){
			//document.write(html);
	  html =html.replace(re, ""); 
	 
	if(html == "login")
	{
		alert('If not yet a member in wholesale-dress,please register first.');
		window.open("user.php?act=login","","","");
		
		}
    else if(html == "1"){
       
		$("#todayoffer_note").fadeIn("3000",function(){
		offer_oc('close');
		setTimeout('change_hidden()', 4000);
		}); 

	}else{
		
	  alert('Invalid product number');
	   document.getElementById("textfield").value='';
	  document.getElementById("textfield").focus();
	 
	}
  },
  complete: function(XMLHttpRequest, textStatus){
		//$("#subbutton").val("Submit"); 
  },
  error: function(){
		alert("error");
		}

}); 

}
function change_hidden()
{

$("#todayoffer_note").fadeOut("6000",function(){
  
 });

//document.getElementById("abc").style.display="none";
}


function footer_ctg(){
	$(".category_box").load("footer_category.php");
}
