
var emailRegExp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
var dateRegExp = /^\d{4}-[0-1]?\d{1}-[0-3]?\d{1}$/;
var _xmlHttpRequestObj = false;
var _postXmlHttpProcessPostChangeCallBack;
var _loadingFunction;
var client_eMail;
var client_name;
var questionContent;
var languageType;
var loginId;
var channelType;
var emailErrorFlag;
var eMail;
var name;
var content;
var errorLog;
var submitFlag = true;

var commitData;

var navigatorType;

function createXMLHttpReuqest() {
	try {
		_xmlHttpRequestObj = new XMLHttpRequest();
	}
	catch (trymicrosoft) {
		try {
			_xmlHttpRequestObj = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (othermicrosoft) {
			try {
				_xmlHttpRequestObj = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				_xmlHttpRequestObj = false;
			}
		}
	}
}
function ajaxCommit() {
	var submitURL = citsNetUrlRootAddrForFAQAnswerAuto+"switchdo.do?prefix=/inbound&page=/fAQAction.do";
	_xmlHttpRequestObj.open("POST", submitURL, true);
	_xmlHttpRequestObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	_xmlHttpRequestObj.onreadystatechange = postXmlHttpProcessPostChange;
	_xmlHttpRequestObj.send(commitData);
}
function load() {
	var commitDiv = document.getElementById("commint");
	var childNodes = commitDiv.childNodes;
	var size = childNodes.length;
	if (size == 1) {
		childNodes[0].removeNode(false);
		imageNode = document.createElement("img");
		imageNode.setAttribute("src",citsNetImageRootAddrForFAQAnswerAuto+"/loading.gif");
		textNode = document.createTextNode(document.getElementById("commit_data_message").value);
		commitDiv.appendChild(textNode);
		commitDiv.insertBefore(imageNode, textNode);
		commitDiv.style.color = "black";
	}
	commitDiv.style.display = "block";
}
function unload(value) {
	removeNodes("commint");
	var commitDiv = document.getElementById("commint");
	var tempNode;
	var textArea = document.getElementById('questionContext');
	if (!value) {
		tempNode = document.createTextNode(document.getElementById("commit_data_message_failed").value);
		commitDiv.style.color = "red";
	} else {
		tempNode = document.createTextNode(document.getElementById("commit_data_message_success").value);
		commitDiv.style.color = "blue";
		textArea.value = "";
		textArea.innerText = "";
	}
	commitDiv.appendChild(tempNode);
	if(navigatorType=="N"){
		commitDiv.style.display = "";
	}else{
		commitDiv.style.display = "block";
	}
}
function showMessage() {
	var returnStr = _xmlHttpRequestObj.responseText;
	unload(returncheck(returnStr));
}
function returncheck(returnStr) {
	returnStr = returnStr.replace(/(^\s*)/g, "");
	if (returnStr == "\u95ee\u9898\u63d0\u4ea4\u5931\u8d25!") {
		return false;
	}
	return true;
}
function postXmlHttpProcessPostChange() {
	if (_xmlHttpRequestObj.readyState == 4 && _xmlHttpRequestObj.status == 200) {
		submitFlag = true;
		setTimeout("showMessage()", 2);
	} else {
		submitFlag = false;
		setTimeout("load()", 2);
	}
}

function initData(){
		languageType = document.getElementById("languageType").value;
	    loginId = document.getElementById("loginId").value;
	    channelType = document.getElementById("channelType").value;
	    
	    var route_id = document.getElementById("route_id").value;
	    var route_no = document.getElementById("route_no").value;
	    var route_name = document.getElementById("route_name").value;
	    var hotel_id = document.getElementById("hotel_id").value;
	    var hotel_ename = document.getElementById("hotel_ename").value;
	    var hotel_checkin = document.getElementById("hotel_checkin").value;
	    
	    var hotel_checkout = document.getElementById("hotel_checkout").value;
	    var product_url = document.getElementById("product_url").value;
	    //var  geturlflg = document.getElementById("geturlflg").value;
	    
	    commitData = "langId="+languageType;
	    commitData += "&loginId="+loginId;
	    commitData += "&channelType="+channelType;
	    commitData += "&questcontent="+questionContent;
	    commitData += "&username="+client_name;
	    commitData += "&useremail="+client_eMail;
	    commitData += "&route_id="+route_id;
	    commitData += "&route_no="+route_no;
	    commitData += "&route_name="+route_name;
	    commitData += "&hotel_id="+hotel_id;
	    commitData += "&hotel_ename="+hotel_ename;
	    commitData += "&hotel_checkin="+hotel_checkin;
	    commitData += "&hotel_checkout="+hotel_checkout;
	    commitData += "&product_url="+product_url;

}
function reDrawimage(){
	var commitDiv = document.getElementById("commint");
	var childNodes = commitDiv.childNodes;
	childNodes[0].removeNode(false);
	childNodes[0].removeNode(false);
	imageNode = document.createElement("img");
	imageNode.setAttribute("src",citsNetImageRootAddrForFAQAnswerAuto+"/loading.gif");
	textNode = document.createTextNode(document.getElementById("commit_data_message").value);
	commitDiv.appendChild(textNode);
	commitDiv.insertBefore(imageNode, textNode);
	commitDiv.style.color = "black";
	commitDiv.style.display = "block";
}

function getNavigatorInfo(){
	var navigatorName = navigator.appName;
	if(navigatorName=='Netscape'){
		navigatorType="N";
	}else if(navigatorName=='Microsoft Internet Explorer'){
		navigatorType="M";
	}
}

function checkMessage(id) {
	getNavigatorInfo();
	if (!submitFlag) {
		reDrawimage();
		return;
	}
	commitDiv = document.getElementById("commint");
	eMail = document.getElementById("client_email");
	client_eMail = eMail.value;
	name = document.getElementById("client_name");
	client_name = name.value;
	content = document.getElementById("questionContext");
	questionContent = content.value;
	if (!checkEmpty(client_eMail)) {
		emailErrorFlag = "isnull";
		showErrorMessage(eMail, "errorMessage_email");
		eMail.value = "";
		eMail.focus();
		commitDiv.style.display = "none";
		emailErrorCommon();
		return;
	} else {
		if (!confirmEmail(client_eMail)) {
			emailErrorFlag = "isformat";
			showErrorMessage(eMail, "errorMessage_email");
			eMail.focus();
			commitDiv.style.display = "none";
			emailErrorCommon();
			return;
		}
	}
	if (!checkEmpty(client_name)) {
		showErrorMessage(name, "errorMessage_name");
		name.value="";
		name.focus();
		commitDiv.style.display = "none";
		nameErrorCommon();
		return;
	}
	if (!checkEmpty(questionContent)) {
		showErrorMessage(content, "errorMessage_question");
		content.value="";
		content.focus();
		commitDiv.style.display = "none";
		questionErrorCommon();
		return;
	}
	createXMLHttpReuqest();
	if (!_xmlHttpRequestObj) {
		alert("Error initializing XMLHttpRequest!");
		commitDiv.style.display = "none";
		commonFunction();
		return;
	}
	initData();
	commonFunction();
	ajaxCommit();
}
function nameErrorCommon() {
	removeNodes("errorMessage_email");
	removeNodes("errorMessage_question");
	hiddenNode(eMail, "errorMessage_email");
	hiddenNode(content, "errorMessage_question");
	var objectNodes = eMail.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
	if(navigatorType=="N"){
		objectNodes.previousSibling.previousSibling.childNodes[1].style.display = "";
	}else{
		objectNodes.previousSibling.childNodes[0].style.display = "block";
	}
}
function emailErrorCommon() {
	removeNodes("errorMessage_name");
	removeNodes("errorMessage_question");
	hiddenNode(name, "errorMessage_name");
	hiddenNode(content, "errorMessage_question");
}
function questionErrorCommon() {
	removeNodes("errorMessage_email");
	removeNodes("errorMessage_name");
	hiddenNode(eMail, "errorMessage_email");
	hiddenNode(name, "errorMessage_name");
}
function commonFunction() {
	removeNodes("errorMessage_email");
	removeNodes("errorMessage_name");
	removeNodes("errorMessage_question");
	hiddenNode(name, "errorMessage_name");
	hiddenNode(content, "errorMessage_question");
	hiddenNode(eMail, "errorMessage_email");
}
function hiddenNode(objNode, objectID) {
	var parentNode = objNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
	var objectNodes;
	if(navigatorType=="N"){
		objectNodes = parentNode.previousSibling.previousSibling.childNodes;
	}else{
		objectNodes = parentNode.previousSibling.childNodes;
	}
	if (objectID == "errorMessage_email") {
		if(navigatorType=="N"){
			objectNodes[1].style.display = "none";
			objectNodes[3].style.display = "none";
		}else{
			objectNodes[0].style.display = "none";
			objectNodes[1].style.display = "none";
		}
	} else {
		if (objectID == "errorMessage_name") {
			if(navigatorType=="N"){
				objectNodes[1].style.display = "none";
				objectNodes[5].style.display = "none";
			}else{
				objectNodes[0].style.display = "none";
				objectNodes[2].style.display = "none";
			}
		} else {
			var hiddlenNode = objNode.parentNode.parentNode;
			if(navigatorType=="N"){
				hiddlenNode.previousSibling.previousSibling.previousSibling.previousSibling.childNodes[1].style.display = "none";
			}else{
				hiddlenNode.previousSibling.previousSibling.childNodes[0].style.display = "none";
			}
		}
	}
}
function showErrorMessage(bortherNode, objectID) {
	var parentNode = bortherNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
	var objectNodes;
	if(navigatorType=="N"){
		objectNodes = bortherNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.previousSibling.childNodes;
	}else{
		objectNodes = bortherNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.childNodes;
	}
	if (objectID == "errorMessage_email") {
		if(navigatorType=="N"){
			objectNodes[1].style.display = "";
			objectNodes[3].style.display = "";
		}else{
			objectNodes[0].style.display = "none";
			objectNodes[1].style.display = "block";
		}
	} else {
		if (objectID == "errorMessage_name") {
			if(navigatorType=="N"){
				objectNodes[1].style.display = "";
				objectNodes[5].style.display = "";
			}else{
				objectNodes[0].style.display = "block";
				objectNodes[2].style.display = "block";
			}
		} else {
			var errorNode = bortherNode.parentNode.parentNode;
			if(navigatorType=="N"){
				errorNode.previousSibling.previousSibling.previousSibling.previousSibling.childNodes[1].style.display = "";
			}else{
				errorNode.previousSibling.previousSibling.childNodes[0].style.display = "block";
			}
		}
	}
	adderrorMessage(objectID);
}
function adderrorMessage(objectID) {
	var objectNode = document.getElementById(objectID);
	var textNode = document.createTextNode("");
	removeNodes(objectID);
	if (objectID == "errorMessage_email") {
		if (emailErrorFlag == "isnull") {
			textNode.nodeValue = document.getElementById("show_errorMessage_email_null").value;
		} else {
			if (emailErrorFlag == "isformat") {
				textNode.nodeValue = document.getElementById("show_errorMessage_email_format").value;
			}
		}
	} else {
		if (objectID == "errorMessage_name") {
			textNode.nodeValue = document.getElementById("show_errorMessage_name").value;
		} else {
			textNode.nodeValue = document.getElementById("show_errorMessage_question").value;
		}
	}
	objectNode.appendChild(textNode);
}
function removeNodes(objectNodeName) {
	var objectNode = document.getElementById(objectNodeName);
	if (objectNode.hasChildNodes()) {
		var length = objectNode.childNodes.length;
		for (i = 0; i < length; i++) {
			objectNode.removeChild(objectNode.childNodes[0]);
		}
	}
}
function checkEmpty(value) {
	value = value.replace(/(^\s*)/g, "");
	if (value == null || value == "" || value.length == 0) {
		return false;
	}
	return true;
}
function confirmEmail(email) {
	return new RegExp(emailRegExp).test(email);
}

