// index JS

document.write("<script language='javascript' src='/js/public.js'></script>");
document.write("<script language='javascript' src='/js/asynchronous.js'></script>");

<!--加入收藏-->
function addFavorite()
{
	var strFullPath=window.document.location.href;
   window.external.addFavorite(strFullPath,"chipsmall.com");
   return false;
}

<!--设为首页-->
function setHomePage()
{
	var strFullPath=window.document.location.href;
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage(strFullPath);
   return false;
}

<!--搜索关键字录入检查-->
function quickSearch(){
	
	if(trim(document.forms["quickSearchForm"].hotSearchKey.value).length<3){
		alert("Please input more than 3 characters !");
		document.forms["quickSearchForm"].hotSearchKey.focus();
		return false;
	}else if(trim(document.forms["quickSearchForm"].hotSearchKey.value).length >30){
		alert("Part No. must comprise 0-30 characters!");
		document.forms["quickSearchForm"].hotSearchKey.value = "";
		document.forms["quickSearchForm"].hotSearchKey.focus();
		return false;
	}
	
	this.document.forms["quickSearchForm"].submit();
}

<!-- 用户登陆信息录入校验-->
function indexUserLogin(){
	
	var loginType = "userName";
	var userName = document.forms["indexUserLoginForm"].userName.value;
	var userPassword = document.forms["indexUserLoginForm"].userPassword.value;
	
	if(trim(userName) == ""){
		alert("Please input Username");
		return false;
	}else{
		if(trim(userName).indexOf("@") != -1){
			loginType = "emailAddress";
			if(!isEmail(userName)){
				alert("Please input a correct Email address.");
				return false;
			}
		}
	}
	
	if(trim(userPassword) == ""){
		alert("Please input Password!");
		return false;
	}
	
	if(trim(document.forms["indexUserLoginForm"].validateValue.value) == ""){
		alert("Wrong Verify Codes!");
		return false;
	}else if(trim(document.forms["indexUserLoginForm"].validateValue.value) != trim(getCookie("validateCode"))){
		alert("Wrong Verify Codes!");
		return false;
	}
	
	document.forms["indexUserLoginForm"].action = "/public/loginoperator.asp?loginType=" + loginType + "&checkType=indexlogin&operatorType=login";
	this.document.forms["indexUserLoginForm"].submit();
} 

<!--找回密码-->
function getPassword(){
	
	var userName = document.forms["indexUserLoginForm"].userName.value;
	
	if (userName == ""){
		alert("Please input Username");
		return false;
	}else{
		if(trim(userName).indexOf("@") == -1){
			alert("Please input your Email!");
			return false;
		}else{
			if(!isEmail(userName)){
				alert("Please input a correct Email address.");
				return false;
			}
		}
	}
	
	document.forms["indexUserLoginForm"].action = "/public/loginoperator.asp?operatorType=getPWD";
	this.document.forms["indexUserLoginForm"].submit();
}

<!--设置密码-->
function setPasswordCheck(){
	
	var userPassword = document.forms["getPasswordForm"].userPassword.value;
	var reUserPassword = document.forms["getPasswordForm"].reUserPassword.value;
	var returnValue = true;
	
	if (userPassword == ""){
		document.getElementById("userPasswordError").innerHTML="Please input your new Password!";
		returnValue = false;
	}else{
		if(!userPasswordCheck(userPassword)){
			document.getElementById("userPasswordError").innerHTML="Please input 6-20 characters!";
			returnValue = false;
		}
	}
	
	if(trim(userPassword) != trim(reUserPassword)){
		document.getElementById("reUserPasswordError").innerHTML="Different Passwords!";
		returnValue = false
	}
	
	return returnValue;
}

<!--搜索关键字录入检查-->
function quickInquiry(){
	
	var partNo = trim(document.forms["quickInquiryForm"].partNo.value);
	var QTY = trim(document.forms["quickInquiryForm"].QTY.value);
	var MFT = trim(document.forms["quickInquiryForm"].MFT.value);
	var packageType = trim(document.forms["quickInquiryForm"].packageType.value);
	var DC = trim(document.forms["quickInquiryForm"].DC.value);
	
	location.href = "/public/inquiry.asp?quck=fast&partNo=" + URLencode(partNo) + "&QTY=" + URLencode(QTY) + "&MFT=" + URLencode(MFT) + "&packageType=" + URLencode(packageType) + "&DC=" + URLencode(DC);
}

<!--发运跟踪查询录入检查-->
function checkUserInput()
{
	var PO = document.forms["expressForm"].PO.value;
	var userId = getCookie("userId");
	var userType = getCookie("userType");
	
	if(PO == ""){
		window.alert("Please input a PO/PI #!");
		return false;
	}
	
	if(userId == "" ||userType != "normalUser" ){
		window.alert("Please log in as Buyer");
		return false;
	}
	return true;
}

function URLencode(sStr) 
{
    return escape(sStr).
             replace(/\+/g, '%2B').
                replace(/\"/g,'%22').
                   replace(/\'/g, '%27').
                     replace(/\//g,'%2F');
}


