Your IP : 216.73.216.34


Current Path : /home/zqegovsj/www/us3web.haibo.com.cn/biguo/js/
Upload File :
Current File : /home/zqegovsj/www/us3web.haibo.com.cn/biguo/js/inquiryForm.js

function toLeftTrim(str) {
	var whitespace = " \t\n\r";
	if (whitespace.indexOf(str.charAt(0)) != -1) {
		var j = 0, i = str.length;
		while (j < i && whitespace.indexOf(str.charAt(j)) != -1) {
			j++;
		}
		str = str.substring(j, i);
	}
	return str;
}
function toRightTrim(str) {
	var whitespace = " \t\n\r";
	if (whitespace.indexOf(str.charAt(str.length - 1)) != -1) {
		var i = str.length - 1;
		while (i >= 0 && whitespace.indexOf(str.charAt(i)) != -1) {
			i--;
		}
		str = str.substring(0, i + 1);
	}
	return str;
}
function toTrim(str) {
	return toRightTrim(toLeftTrim(str));
}
function isEmpty(str) {
	if ((str == null) || (toTrim(str).length == 0)) {
		return true;
	} else {
		return false;
	}
}
function isNotEmpty(str) {
	return isEmpty(str) ? false : true;
}
function minLength(str, length) {
	if (!isEmpty(str)) {
		if (toTrim(str).length < length) {
			return true;
		} else {
			return false;
		}
	}
	return false;
}
function maxLength(str, length) {
	if (!isEmpty(str)) {
		if (toTrim(str).length > length) {
			return true;
		} else {
			return false;
		}
	}
	return false;
}
function isLength(str, minLength, maxLength) {
	if (!isEmpty(str)) {
		var tmp = toTrim(str);
		if (tmp.length > maxLength || tmp.length < minLength) {
			return false;
		} else {
			return true;
		}
	}
	return false;
}
function regExp(pattern, str) {
	str = toTrim(str);
	if (pattern.test(str)) {
		return true;
	} else {
		return false;
	}
}
function isNumber(str) {
	var pattern = /^[\-]?[\d]+$/;
	return regExp(pattern, str);
}
function isEmail(str) {
	var pattern = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	return regExp(pattern, str);
}
function isURL(str) {
	str = str.toLowerCase();
	var pattern = /[a-zA-z]+:\/\/[^\s]*/;
	return regExp(pattern, str);
}
function isChecked(box_name) {
	var box = document.getElementsByName(box_name);
	for (var i = 0; i < box.length; i++) {
		if (box[i].type == "checkbox" && box[i].checked) {
			return true;
		}
	}
	return false;
}
function getUploadFileName(path) {
	var fileName = "";
	var len = path.length;
	if (len <= 0) {
		return "";
	}
	var start = path.lastIndexOf("/");
	if (start >= 0) {
		fileName = path.substring(start + 1);
	}
	var start2 = path.lastIndexOf("\\");
	if (start2 >= 0) {
		fileName = path.substring(start2 + 1);
	}
	return fileName;
}
var checkOk = new Array();
checkOk[0] = "12288";
checkOk[1] = "8364";
function isOkChar(ch) {
	for (j = 0; j < checkOk.length; j++) {
		if (ch == checkOk[j]) {
			return true;
		}
	}
	return false;
}
function checkChineseChar(str) {
	var flag = false;
	for (i = 0; i < str.length; i++) {
		var char = str.charCodeAt(i);
		if (char > 256 && !isOkChar(char)) {
			flag = true;
			break;
		}
	}
	return flag;
}
function textLimitCheck(thisArea, showArea, maxLength) {
	if (thisArea.value.length > maxLength) {
		alert(maxLength + " characters limit. \r Excessive data will be truncated.");
		thisArea.value = thisArea.value.substring(0, maxLength - 1);
		thisArea.focus();
	}
	showArea.value = thisArea.value.length;
}
function showUpload() {
	if (document.getElementById("uploadSwitch").checked) {
		document.getElementById("uploadBar").style.display = "";
	} else {
		document.getElementById("uploadBar").style.display = "none";
	}
}
function validateInquiryForm(form) {
	//checkValidateCode();
	var HI_validateMsgBuffer = new Array();
	var HI_validateFlag = "";
	try {
		var subject = toTrim(form.elements["subject"].value);
//		var country = toTrim(form.elements["country"].value);
//		var company = toTrim(form.elements["company"].value);
		var email = toTrim(form.elements["email"].value);
//		var tel = toTrim(form.elements["tel"].value);
		var name = toTrim(form.elements["name"].value);
		var content = form.elements["content"].value;
//		var fax = toTrim(form.elements["fax"].value);
//		var replyDays = toTrim(form.elements["replyDays"].value);
//		var address = toTrim(form.elements["address"].value);
//		var website = toTrim(form.elements["website"].value);
//		var HI_vc_value = toTrim(form.elements["HI_vc_value"].value);
       if (isEmpty(email)) {
			HI_validateMsgBuffer.push("Please input email address.");
			if (HI_validateFlag == "") {
				HI_validateFlag = "email";
			}
		}else if(!isEmail(email)){
			HI_validateMsgBuffer.push("Please input a valid email address.");
			if (HI_validateFlag == "") {
				HI_validateFlag = "email";
			}	
		}
//		if (isEmpty(tel)) {
//			HI_validateMsgBuffer.push("Please input a valid telephone number.");
//			if (HI_validateFlag == "") {
//				HI_validateFlag = "tel";
//			}
//		}else if(tel.length<6 || tel.length>30){
//			HI_validateMsgBuffer.push("Tel must be between 6~30 characters.");
//			if (HI_validateFlag == "") {
//				HI_validateFlag = "tel";
//			}
//		}
		if (isEmpty(name)) {
			HI_validateMsgBuffer.push("Please input your name.");
			if (HI_validateFlag == "") {
				HI_validateFlag = "name";
			}
		}else if(name.length<2 || name.length>30){
			HI_validateMsgBuffer.push("Name must be between 2~30 characters.");
			if (HI_validateFlag == "") {
				HI_validateFlag = "name";
			}
		}
		if (isEmpty(content)) {
			HI_validateMsgBuffer.push("Please input your message.");
			if (HI_validateFlag == "") {
				HI_validateFlag = "content";
			}
		}else if(content.length<5 || content.length>3000){
			HI_validateMsgBuffer.push("Message must be between 5~3000 characters..");
			if (HI_validateFlag == "") {
				HI_validateFlag = "content";
			}
		}
		
//		if (isEmpty(country)) {
//			HI_validateMsgBuffer.push("Please input Country.");
//			if (HI_validateFlag == "") {
//				HI_validateFlag = "country";
//			}
//		}
//		if (isEmpty(fax)) {
//			HI_validateMsgBuffer.push("Please input a valid fax number.");
//			if (HI_validateFlag == "") {
//				HI_validateFlag = "fax";
//			}
//		}
		
//		if (isEmpty(HI_vc_value)) {
//			HI_validateMsgBuffer.push("Please input Verification Code.");
//			if (HI_validateFlag == "") {
//				HI_validateFlag = "HI_vc_value";
//			}
//		}
//		if (isEmpty(website)) {
//			HI_validateMsgBuffer.push("Please input a valid Website.");
//			if (HI_validateFlag == "") {
//				HI_validateFlag = "website";
//			}
//		}		
		/*if (!isNumber(HI_vc_value) || HI_vc_value.length < 4) {
			HI_validateMsgBuffer.push("Please input a valid validate code.");
			if (HI_validateFlag == "") {
				HI_validateFlag = "HI_vc_value";
			}
		}*/
		
		if (HI_validateMsgBuffer.length > 0) {
			alert(HI_validateMsgBuffer.join("\n\n"));
			form.elements[HI_validateFlag].focus();
			return false;
		} else {
			form.elements["submit"].value = "Please wait";
			form.elements["submit"].disabled = "disabled";
			return true;
		}
	}
	catch (e) {
		alert(e);
		return false;
	}
}
var xmlhttp = null;
/**
 * 兼容AJAX的XMLHttpRequest对象创建
 *
 * @return bool;
 */
function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			return true;
		}
		catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				return true;
			}
			catch (ex) {
				return false;
			}
		}
	} else {
		if (window.XMLHttpRequest) {
			try {
				xmlhttp = new XMLHttpRequest();
				return true;
			}
			catch (e) {
				return false;
			}
		} else {
			return false;
		}
	}
}