function isblank(s)
{
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function CheckEmail(strEmail) {
	var i;
	var getChar;


	if ((Left(strEmail, 1) == "@") || (Right(strEmail, 1) == "@") )
		return false;
	

		getChar = 0;
	for (i = 0 ; i < strEmail.length ; i++ ) {
		if (strEmail.charAt(i)=='@'){
			getChar++;
		}
	}	    

	if ( getChar != 1 )
		return false;

	var email1;
	var email2;
	var temail;
	
	temail = strEmail.split('@')
	email1 = temail[0].replace(/\s/g, "");
	email2 = temail[1].replace(/\s/g, "");	
	
	var cemail;
	cemail = strEmail;
	cemail = cemail.replace(/\@/g, "");	
	cemail = cemail.replace(/\./g, "");	
	
	if (cemail.length == 0)
		return false;
	
	var allow;
	allow = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-";
	for(i = 0 ; i < cemail.length; i++ )
		if (allow.indexOf(cemail.charAt(i)) < 0 )
			return false;

	if (Left(email1, 1) == '.')
		return false;

	
	if (Left(email2, 1) == '.' || Right(email2, 1) == '.' || email2.replace(/\./g, "").length == email2.length)
		return false;

	if (email2.indexOf("..") >= 0 )
		return false;

	if (Left(email2, 1) == '-' || Right(email2, 1) == '-')
		return false;

	if (Left(email2, 1) == '_' || Right(email2, 1) == '_')
		return false;
	
	return true;
}	

function Left( sourceStr, charIdx ) {
	if((sourceStr==null) || (sourceStr=="")) return "";
	return sourceStr.substring(0, charIdx);
}

function Right( sourceStr, charIdx ) {	
	if((sourceStr==null) || (sourceStr=="")) return "";
	return sourceStr.substring(sourceStr.length-charIdx, sourceStr.length);
}



// Check Register
function check_info(e)
{
	var msg;
	var textAll = "请填写您的个人信息.";
	var textu_userName="";
	var textu_Email="";
	var textu_userPw="";
	var textr_u_userPw="";
	var vg=1;
	var fg=1;
	
	if ((e.u_userName.value == null) || (e.u_userName.value == "") || isblank(e.u_userName.value)) { textu_userName = "请填写您的用户名.\n";}	
	if ((e.u_Email.value == null) || (e.u_Email.value == "") || isblank(e.u_Email.value)) { textu_Email = "请填写您的邮箱.\n"; fg=0;}
	if (fg) {
		 if (!CheckEmail(e.u_Email.value)) { textu_Email = "请确认您的邮箱格式是否正确. \n";} 
		}
	if ((e.u_userPw.value == null) || (e.u_userPw.value == "") || isblank(e.u_userPw.value)) { textr_u_userPw = "请填写您的密码.\n"; vg=0;}
	if (vg) {
	 if (e.u_userPw.value != e.r_u_userPw.value) { textr_u_userPw = "您两次输入的密码不匹配，请检查.\n"; }
	}	

	if (e.u_userName.style) e.u_userName.style.backgroundColor = textu_userName != "" ? '#ffffcc':'#FFFFFF';
	if (e.u_Email.style) e.u_Email.style.backgroundColor = textu_Email != "" ? '#ffffcc':'#FFFFFF';
	if (e.u_userPw.style) e.u_userPw.style.backgroundColor = textr_u_userPw != "" ? '#ffffcc':'#FFFFFF';
	
	if ((textu_userName == "") && (textu_Email == "") && (textr_u_userPw == "")) 
		{ 
			registerCheck();
			return true;
		}
	
	if (textu_userName && textu_Email && textr_u_userPw) {
		msg = textu_userName + textu_Email + textr_u_userPw;
	} else {
		msg = textu_userName + textu_Email + textr_u_userPw;
	}		
	alert(msg);
	return false;
}


// Check Buy
function check_buy(e)
{
	var msg;
	var text_cart_p_url="";
	var text_cart_p_name="";
	var text_cart_p_price="";
	var text_cart_p_shipping_fee="";
	var text_cart_p_num="";
	var text_cart_p_note="";
	var text_cart_p_saler='';
	var fg=1;

	var show_saler_style = document.getElementById('show_saler_input').style.display;

	if ((e.cart_p_url.value == null) || (e.cart_p_url.value == "") || isblank(e.cart_p_url.value)) { text_cart_p_url = "请填写商品页网址.\n"; fg=0;}
	if ((e.cart_p_name.value == null) || (e.cart_p_name.value == "") || isblank(e.cart_p_name.value)) { text_cart_p_name = "请填写商品名称.\n"; }
	if ((e.cart_p_price.value == null) || (e.cart_p_price.value == "") || isblank(e.cart_p_price.value) || e.cart_p_price.value < 0.01) { text_cart_p_price = "请填写商品价格.\n"; }
	if ((e.cart_p_shipping_fee.value == null) || (e.cart_p_shipping_fee.value == "") || isblank(e.cart_p_shipping_fee.value)) { text_cart_p_shipping_fee = "请填写国内运费.\n"; }
	if ((e.cart_p_num.value == null) || (e.cart_p_num.value == "") || isblank(e.cart_p_num.value) || e.cart_p_num.value < 1) { text_cart_p_num = "请填写商品数量.\n"; }
	//if ((e.cart_p_note.value == null) || (e.cart_p_note.value == "") || isblank(e.cart_p_note.value)) { text_cart_p_note = "请填写您的备注.\n"; }

	if (e.cart_p_url.style) e.cart_p_url.style.backgroundColor = text_cart_p_url != "" ? '#ffffcc':'#FFFFFF'; 
	if (e.cart_p_name.style) e.cart_p_name.style.backgroundColor = text_cart_p_name != "" ? '#ffffcc':'#FFFFFF';
	if (e.cart_p_price.style) e.cart_p_price.style.backgroundColor = text_cart_p_price != "" ? '#ffffcc':'#FFFFFF';
	if (e.cart_p_shipping_fee.style) e.cart_p_shipping_fee.style.backgroundColor = text_cart_p_shipping_fee != "" ? '#ffffcc':'#FFFFFF';
	if (e.cart_p_num.style) e.cart_p_num.style.backgroundColor = text_cart_p_num != "" ? '#ffffcc':'#FFFFFF';
	//if (e.cart_p_note.style) e.cart_p_note.style.backgroundColor = text_cart_p_note != "" ? '#ffffcc':'#FFFFFF';

	if(show_saler_style != 'none')
	{
		if ((e.cart_p_saler.value == null) || (e.cart_p_saler.value == "") || isblank(e.cart_p_saler.value) || e.cart_p_saler.value == '0') { text_cart_p_saler = "请填写卖家名称.\n"; }
		if (e.cart_p_saler.style) e.cart_p_saler.style.backgroundColor = text_cart_p_saler != "" ? '#ffffcc':'#FFFFFF';
	}

	
	if (text_cart_p_url == "" && text_cart_p_name == "" && text_cart_p_price == "" && text_cart_p_shipping_fee == "" && text_cart_p_num == "" && text_cart_p_saler == "") 
	{ 
		e.submit(); 
		return true; 
	}
	else { msg = text_cart_p_url+text_cart_p_saler+text_cart_p_name+text_cart_p_price+text_cart_p_shipping_fee+text_cart_p_num;	} 
	
	alert(msg);
	return false;
}


// Check Login
function check_login(e)
{
	var msg;
	var textun="";
	var textpw="";
	var textzc="";
	var fg=1;

	if ((e.u_userName.value == null) || (e.u_userName.value == "") || isblank(e.u_userName.value)) { textun = "请填写您的用户名或邮箱.\n"; fg=0;}
	if ((e.u_userPw.value == null) || (e.u_userPw.value == "") || isblank(e.u_userPw.value)) { textpw = "请填写您的密码.\n"; }
	if ((e.gd_code.value == null) || (e.gd_code.value == "") || isblank(e.gd_code.value)) { textzc = "请填写验证码.\n"; }
	
	if (textun == "" && textpw == "" && textzc == "") 
	{ 
		//e.submit(); 
		loginCheckEmail();
		return true; 
	}
	else { msg = textun+textpw+textzc;	} 
	
	alert(msg);
	return false;
}


// add address
function check_add_address(e)
{
	var msg;
	var text_u_a_name="";
	var text_u_a_country="";
	var text_u_a_address="";
	var text_u_a_zip="";
	var text_u_a_phone="";
	
	if ((e.u_a_name.value == null) || (e.u_a_name.value == "") || isblank(e.u_a_name.value)) { text_u_a_name = "请填写收货人.\n";}
	if ((e.u_a_country.value == null) || (e.u_a_country.value == "") || isblank(e.u_a_country.value)) { text_u_a_country = "请填写收货国家.\n";}	
	if ((e.u_a_address.value == null) || (e.u_a_address.value == "") || isblank(e.u_a_address.value)) { text_u_a_address = "请填写收货地址.\n";}
	if ((e.u_a_zip.value == null) || (e.u_a_zip.value == "") || isblank(e.u_a_zip.value)) {text_u_a_zip = "请填写收货人邮编.\n";}
    if ((e.u_a_phone.value == null) || (e.u_a_phone.value == "") || isblank(e.u_a_phone.value)) { text_u_a_phone = "请填写收货人电话.\n"; }	

	if (e.u_a_name.style) e.u_a_name.style.backgroundColor = text_u_a_name != "" ? '#ffffcc':'#FFFFFF';
	if (e.u_a_country.style) e.u_a_country.style.backgroundColor = text_u_a_country != "" ? '#ffffcc':'#FFFFFF';
	if (e.u_a_address.style) e.u_a_address.style.backgroundColor = text_u_a_address != "" ? '#ffffcc':'#FFFFFF';
	if (e.u_a_zip.style) e.u_a_zip.style.backgroundColor = text_u_a_zip != "" ? '#ffffcc':'#FFFFFF'; 
	if (e.u_a_phone.style) e.u_a_phone.style.backgroundColor = text_u_a_phone != "" ? '#ffffcc':'#FFFFFF';
	
	if ((text_u_a_name == "") && (text_u_a_country == "") && (text_u_a_address == "")  && (text_u_a_zip == "") && (text_u_a_phone == "")) 
		{ 
			e.submit();
			return true;
		}
	
	if (text_u_a_name && text_u_a_country && text_u_a_address  && text_u_a_zip && text_u_a_phone) {
		msg = text_u_a_name + text_u_a_country + text_u_a_address  + text_u_a_zip + text_u_a_phone;
	} else {
		msg = text_u_a_name + text_u_a_country + text_u_a_address  + text_u_a_zip + text_u_a_phone;
	}		
	alert(msg);
	return false;
}


function check_change_pw(e)
{
	var msg;
	var text_o_pw="";
	var text_n_pw="";
	var text_r_pw="";
	
	if ((e.o_pw.value == null) || (e.o_pw.value == "") || isblank(e.o_pw.value)) { text_o_pw = "请填写您的旧密码.\n";}
	if ((e.n_pw.value == null) || (e.n_pw.value == "") || isblank(e.n_pw.value)) { text_n_pw = "请填写您的新密码.\n";}	
	if ((e.r_pw.value == null) || (e.r_pw.value == "") || isblank(e.r_pw.value)) { text_r_pw = "请填写再次输入新密码.\n";}
	if(text_n_pw == '' && text_r_pw == '')
	{
		if(e.n_pw.value != e.r_pw.value)
		{
			alert('您两次输入的新密码不匹配,请重新输入.');
			return false;
		}
	}

	if (e.o_pw.style) e.o_pw.style.backgroundColor = text_o_pw != "" ? '#ffffcc':'#FFFFFF';
	if (e.n_pw.style) e.n_pw.style.backgroundColor = text_n_pw != "" ? '#ffffcc':'#FFFFFF';
	if (e.r_pw.style) e.r_pw.style.backgroundColor = text_r_pw != "" ? '#ffffcc':'#FFFFFF';
	
	if ((text_o_pw == "") && (text_n_pw == "") && (text_r_pw == "")) 
	{ 
		//e.submit();
		checkPw();
		return true;
	}
	
	if (text_o_pw && text_n_pw && text_r_pw) {
		msg = text_o_pw + text_n_pw + text_r_pw;
	} else {
		msg = text_o_pw + text_n_pw + text_r_pw;
	}		
	alert(msg);
	return false;
}

function check_change_email(e)
{
	var msg;
	var text_n_email="";
	var text_pw="";
	var fg=1;
	
	if ((e.pw.value == null) || (e.pw.value == "") || isblank(e.pw.value)) { text_pw = "请填写您的密码.\n";}	
	if ((e.n_email.value == null) || (e.n_email.value == "") || isblank(e.n_email.value)) { text_n_email = "请填写您的邮箱.\n"; fg=0;}
	if (fg) {
		 if (!CheckEmail(e.n_email.value)) { text_n_email = "请确认您的邮箱格式是否正确. \n";} 
		}

	if (e.pw.style) e.pw.style.backgroundColor = text_pw != "" ? '#ffffcc':'#FFFFFF';
	if (e.n_email.style) e.n_email.style.backgroundColor = text_n_email != "" ? '#ffffcc':'#FFFFFF';
	
	if ((text_pw == "") && (text_n_email == "")) 
	{ 
		//e.submit();
		updateInfoCheckEmail();
		return true;
	}
	
	if (text_pw && text_n_email) {
		msg = text_pw + text_n_email;
	} else {
		msg = text_pw + text_n_email;
	}		
	alert(msg);
	return false;
}


function check_shipping_address(e)
{
	var u_a_id = document.getElementsByName('u_a_id[]');
	var u_a_num = u_a_id.length;
	var u_a_status = 0;
	for(i=0;i<u_a_num;i++)
	{
		if(u_a_id[i].checked == true)
		{
			u_a_status = 1;
			var u_a_value = u_a_id[i].value;
			if(u_a_id[i].value != 'other')
			{
				var u_a_area = document.getElementById('u_a_area_'+i).value;
				var pg_deliver_id = document.getElementById('pg_deliver_id').value;
				if(u_a_area != pg_deliver_id)
				{
					alert("配送区域所选国家与收货人国家不一致,请修改后提交.");
					return false;
				}
			}
		}
	}
	if(u_a_status == 0)
	{
		alert('请选择收货人信息');
		return false;
	}
	//alert(u_a_value);
	if(u_a_value == 'other')
	{
		var text_u_a_name="";
		var text_u_a_address="";
		var text_u_a_phone="";
		var text_u_a_city="";
		var text_u_a_zip="";
		var text_pg_content='';
		var text_u_a_input_country='';
		
		if ((e.u_a_name.value == null) || (e.u_a_name.value == "") || isblank(e.u_a_name.value)) { text_u_a_name = "请填写收货人姓名.\n";}	
		if ((e.u_a_address.value == null) || (e.u_a_address.value == "") || isblank(e.u_a_address.value)) { text_u_a_address = "请填写地址.\n"; }
		if ((e.u_a_phone.value == null) || (e.u_a_phone.value == "") || isblank(e.u_a_phone.value)) { text_u_a_phone = "请填写电话.\n"; }
		if ((e.u_a_city.value == null) || (e.u_a_city.value == "") || isblank(e.u_a_city.value)) { text_u_a_city = "请填写城市.\n"; }
		if ((e.u_a_zip.value == null) || (e.u_a_zip.value == "") || isblank(e.u_a_zip.value)) { text_u_a_zip = "请填写邮编.\n"; }
		//if ((e.pg_content.value == null) || (e.pg_content.value == "") || isblank(e.pg_content.value)) { text_pg_content = "请填写运单备注.\n"; }

		if(e.country_status.value == 'input')
		{
			if ((e.u_a_input_country.value == null) || (e.u_a_input_country.value == "") || isblank(e.u_a_input_country.value)) { text_u_a_input_country = "请填写国家.\n"; }
			if (e.u_a_input_country.style) e.u_a_input_country.style.backgroundColor = text_u_a_input_country != "" ? '#ffffcc':'#FFFFFF';

		}


		if (e.u_a_name.style) e.u_a_name.style.backgroundColor = text_u_a_name != "" ? '#ffffcc':'#FFFFFF';
		if (e.u_a_address.style) e.u_a_address.style.backgroundColor = text_u_a_address != "" ? '#ffffcc':'#FFFFFF';
		if (e.u_a_phone.style) e.u_a_phone.style.backgroundColor = text_u_a_phone != "" ? '#ffffcc':'#FFFFFF';
		if (e.u_a_city.style) e.u_a_city.style.backgroundColor = text_u_a_city != "" ? '#ffffcc':'#FFFFFF';
		if (e.u_a_zip.style) e.u_a_zip.style.backgroundColor = text_u_a_zip != "" ? '#ffffcc':'#FFFFFF';
		//if (e.pg_content.style) e.pg_content.style.backgroundColor = text_pg_content != "" ? '#ffffcc':'#FFFFFF';

		if ((text_u_a_name == "") && (text_u_a_address == "") && (text_u_a_phone == "") && (text_u_a_city == "") && (text_u_a_zip == "") && (text_u_a_input_country == "")) 
		{ 
			e.submit();
			return true;
		}
		
		msg = text_u_a_name + text_u_a_address + text_u_a_phone + text_u_a_city + text_u_a_zip + text_u_a_input_country;
		alert(msg);
		return false;
	}
	else
	{
		var text_pg_content=''

		//if ((e.pg_content.value == null) || (e.pg_content.value == "") || isblank(e.pg_content.value)) { text_pg_content = "请填写运单备注.\n"; }

		//if (e.pg_content.style) e.pg_content.style.backgroundColor = text_pg_content != "" ? '#ffffcc':'#FFFFFF';

		//if (text_pg_content == "") 
		//{ 
			e.submit();
			return true;
		//}
		
		//msg = text_pg_content;
		//alert(msg);
		//return false;
	}
}


function check_send_help(e)
{
	var msg;
	var text_help_title="";
	var text_help_content="";
	
	if ((e.help_title.value == null) || (e.help_title.value == "") || isblank(e.help_title.value)) { text_help_title = "请输入咨询主题.\n";}	
	if ((e.help_content.value == null) || (e.help_content.value == "") || isblank(e.help_content.value)) { text_help_content = "请输入咨询内容.\n";}

	if (e.help_title.style) e.help_title.style.backgroundColor = text_help_title != "" ? '#ffffcc':'#FFFFFF';
	if (e.help_content.style) e.help_content.style.backgroundColor = text_help_content != "" ? '#ffffcc':'#FFFFFF';
	
	if ((text_help_title == "") && (text_help_content == "")) 
	{ 
		e.submit();
		return true;
	}
	
	msg = text_help_title + text_help_content;	
	alert(msg);
	return false;
}

function check_send_comment(e)
{
	var msg;
	var text_com_content="";
	var text_com_title="";
	if ((e.com_title.value == null) || (e.com_title.value == "") || isblank(e.com_title.value)) { text_com_title = "请输入评价标题.\n";}
	if ((e.com_content.value == null) || (e.com_content.value == "") || isblank(e.com_content.value)) { text_com_content = "请输入评价内容.\n";}

	if (e.com_title.style) e.com_title.style.backgroundColor = text_com_title != "" ? '#ffffcc':'#FFFFFF';
	if (e.com_content.style) e.com_content.style.backgroundColor = text_com_content != "" ? '#ffffcc':'#FFFFFF';

	if ((text_com_content == "") && (text_com_title == "") ) 
	{ 
		e.submit();
		return true;
	}
	
	msg = text_com_title+text_com_content;	
	alert(msg);
	return false;
}


function check_money_back(e)
{
	var msg;
	var text_mb_name="";
	var text_mb_account="";
	var text_mb_money="";
	var text_mb_type="";
	if ((e.mb_account.value == null) || (e.mb_account.value == "") || isblank(e.mb_account.value)) { text_mb_account = "请输入账号.\n";}
	if ((e.mb_money.value == null) || (e.mb_money.value == "") || isblank(e.mb_money.value)) { text_mb_money = "请输入退款金额.\n";}
	if ((e.mb_type.value == null) || (e.mb_type.value == "") || isblank(e.mb_type.value)) { text_mb_type = "请输入退款方式.\n";}
	if ((e.mb_name.value == null) || (e.mb_name.value == "") || isblank(e.mb_name.value)) { text_mb_name = "请输入户名.\n";}

	if (e.mb_name.style) e.mb_name.style.backgroundColor = text_mb_name != "" ? '#ffffcc':'#FFFFFF';
	if (e.mb_account.style) e.mb_account.style.backgroundColor = text_mb_account != "" ? '#ffffcc':'#FFFFFF';
	if (e.mb_money.style) e.mb_money.style.backgroundColor = text_mb_money != "" ? '#ffffcc':'#FFFFFF';
	if (e.mb_type.style) e.mb_type.style.backgroundColor = text_mb_type != "" ? '#ffffcc':'#FFFFFF';

	if ((text_mb_account == "") && (text_mb_money == "")&& (text_mb_type == "")&& (text_mb_name == "") ) 
	{ 
		e.submit();
		return true;
	}
	
	msg = text_mb_name+text_mb_account+text_mb_money+text_mb_type;	
	alert(msg);
	return false;
}