
function isIE(){
	 return document.all?true:false
}

function editperson(){
				$("#pf2").addClass("default-tab current");
				$("#pf1").removeClass();
				$("#persontab1").hide();
				$("#persontab2").show();
}

function displayselect(o){
}

//profile 
function onSel(o,p,pn){
	$(".profliephoto li").removeClass();
	$(o).addClass("active");
	$("#profilephotoid").val(p);
	$("#profilephotoname").val(pn);
	
}
function saveSelProfilePhoto(){
	_ppn = $("#profilephotoid").val();
	_rtxt = $.ajax({async:false,type:"GET", url:"/community/profile/updateprofile.asp?action=upicon&ppn="+_ppn}).responseText;
	if (_rtxt.replace(/\s+/g,"").toLowerCase().substring(0,4)=="true"){
		$("#customerpic").attr("src","/community/profile/profilephoto/"+$("#profilephotoname").val());
	}
	generalDivWinClose();
}


//remove user msg
function removeMsg(_n){
	
	_rtxt = $.ajax({async:false,type:"GET", url:"/community/include/delmessages.asp?m="+_n}).responseText;
	//alert(_rtxt);
	location.reload();
	//$("#msg"+_n).hide();
	
//	generalDivWinClose();
}

function doWinLogin(_s){
		_r = location.href;
		ShowIFrame('','/community/login-win.asp?r='+_r+'&s='+_s,630,350,'bottom');
}

function Keydown(evt,me,pe,se)
{
    var keycode = window.event ? evt.keyCode : evt.which;
    if(keycode==13)doLogin(me,pe,se);
}

function doLogin(formsign){ 
	
  var ec,cc,me,pe,se;//rc,
   
	if(typeof formsign =="string")
	{
		me="loginmail"+formsign;
	    pe="loginpass"+formsign;
	    se="loginErrTips"+formsign;
	}
	else
	{
		me="loginmail";
	    pe="loginpass";
	    se="loginErrTips";
		
 
	}
	 
    ec = RegCkElement(me,"The email or password you've entered is incorrect.","/^(([\\u4E00-\\u9FA5]|[\\uFE30-\\uFEFF]|[\\d]|[a-zA-Z]|[\\_\\-\\.])+[\\@])(((([\\d]|[a-zA-Z]|[\\_\\-]|[\\[\\]\{\\}\>\\<])+[\\.])+)([\\d]|[a-zA-Z\\_\\-])+)$/","Email",se,false);
	
	if(!ec)return false; 
    cc = StrIsNullOrEmpty(pe,"The email or password you've entered is incorrect.","",se,false);
	if(!cc)return false;
	 
		 webLoginAuth($("#"+me).val(),$("#"+pe).val(),$("input[name='s']").val(),se,$("#rememberme").attr("checked"))  ;
		 //showLoginErrMsg("Login,please wait.",se);
 
	}
	
	function doLoginHref(){
		if (!doLogin()) return;
	}
	
	
	function doWinLoginHref(){
		
		var ole,olp;
		
		ole = document.loginForm.loginmail.value;
		olp = document.loginForm.loginpass.value;
		if (ole == "" || olp == "" || ole.length<6) {
			showLoginErrMsg("The email or password you've entered is incorrect.","loginErrTips");
			return false;
		}
		if (!webWinLoginAuth(ole,olp)){
			showLoginErrMsg("The email or password you've entered is incorrect.","loginErrTips");
			return false;
		}
		return true;
	}
	
	
	function getPass(){
	}
	
	function webLoginAuth(le,lp,ls,se,rm){
		$.post("/community/logincheck.asp", {loginmail:le,loginpass:lp,rememberme:rm},function(_sf){
  				if (_sf == "true"){
  					if (typeof ls =="string"){
  						location.href=ls;
  					}else{ 
  						location.href="/community/customer-center/";
  				}
  					//return true;
  				}else{
  					showLoginErrMsg("The email or password you've entered is incorrect.","loginErrTips");
  				}
		});  
	}
	

//qa right login 
	function qaRightBaseMain(le,lp){
		parent.$("#personid").fadeOut(300);
		parent.$("#qabody").focus();
	}
	
	//qa-list login 
	function qawinreplyMain(_n){
		nArray = _n.split("-");
		nid = nArray[1];
		parent.$("#replydivimg"+nid).hide();
		parent.$("#div"+nid).slideDown(300);
	}
		
		function webWinLoginAuth(le,lp){
		$.post("/community/logincheck.asp", {loginmail:le,loginpass:lp},function(_sf){
  				if (_sf == "true"){
  					sourcediv1 = sourcediv; 
  					if (sourcediv.indexOf("-")){
  						sourcediv1 = sourcediv.split("-")[0];
  					} 
  					switch (sourcediv1){
  						case "qarightbase":
  							qaRightBaseMain(le,lp);
  							break;
  						case "qawinreply":
  							qawinreplyMain(sourcediv);
  							break;
  							
							default:
							  							
  					}
  					
  					//parent.$("#"+sourcediv).html();
  					for (i=0;i<parent.$(".boxy_bottom").size();i++) parent.Boxy.get(parent.$(".boxy_bottom").eq(i)).hide();
  					return true;
  				}else{
  					return false;
  				}
		}); 
		return false;
	}
	
	function showLoginErrMsg(_s,_d){
		$("#"+_d).html(_s);
		$("#"+_d).show();
	}
	
	
	function doWinLoginCheck(){
		var ole,olp;
		ole = document.winLoginForm.loginmail.value;
		olp = document.winLoginForm.loginpass.value;
		if (ole == "" || olp == "" || ole.length<6) {
			showLoginErrMsg("The email or password you've entered is incorrect.");
			return false;
		}
		if (!webLoginAuth(ole,olp)){
			showLoginErrMsg("The email or password you've entered is incorrect.");
			return false;
		}
		
	}	
	
	
	
	function doCreateAccountHref(){
		if (!doCreateAccount()) return;
	}
	
	function doCreateAccount(){
		var ole,olp;
		ole = document.createAccountForm.cloginmail.value;
		olp1 = document.createAccountForm.cloginpass1.value;
		olp2 = document.createAccountForm.cloginpass2.value;
		oln = document.createAccountForm.nickname.value;
		vcode = document.createAccountForm.verifycode.value;
		if (document.createAccountForm.termsFlag.checked != true){
			showLoginErrMsg("I have read and accept the Terms and conditions?","createAccountErrTips");
			return false;			
		}
		if (vcode.length<4){
			showLoginErrMsg("Please enter Verify Code?","createAccountErrTips");
			return false;			
		}	 
    ec = RegCkElement("cloginmail","The email  you've entered is incorrect.","/^(([\\u4E00-\\u9FA5]|[\\uFE30-\\uFEFF]|[\\d]|[a-zA-Z]|[\\_\\-\\.])+[\\@])(((([\\d]|[a-zA-Z]|[\\_\\-]|[\\[\\]\{\\}\>\\<])+[\\.])+)([\\d]|[a-zA-Z\\_\\-])+)$/","","createAccountErrTips",false);
		if(!ec)return false; 
		if (olp1 != olp2) {
			showLoginErrMsg("Your password confirmation does not match.","createAccountErrTips");
			return false;
		}		
		if (olp1.length<6) {
			showLoginErrMsg("Your Password must be more than 6 characters.","createAccountErrTips");
			return false;
		}			
		
			
	rtxt = $.ajax({async:false,type:"POST", url:"/community/save-create-account.asp",data: "cemail="+ole+"&cpass="+olp1+"&cname="+oln+"&vc="+vcode}).responseText;

	if (rtxt.replace(/\s+/g,"").toLowerCase()=="true"){
			loginFlag = true;
			location.href="/community/customer-center/";
		}
		else if(rtxt.replace(/\s+/g,"").toLowerCase()=="000"){
			showLoginErrMsg("Please enter the correct Verify Code","createAccountErrTips");
			return false
		}
		else{
			showLoginErrMsg("The email you've entered is not available.","createAccountErrTips");
			return false;
		}	
	}
	
	
	function webCreateAccount(_u,_p,_n){
		return false;
	}
	
	
	
function isLogin(){
	var loginFlag;
	loginFlag = false;
	rtxt = $.ajax({async:false,type:"GET", url:"/community/islogin.asp"}).responseText;
	if (rtxt.replace(/\s+/g,"").toLowerCase()=="true"){
		loginFlag = true;
	}
	return loginFlag;
}	

function qaReply(n){
	if (!isLogin()){
		doWinLogin("qawinreply-"+n);
		return;
	}
	
	$("#replydivimg"+n).hide();
	$("#div"+n).slideDown(300);
}

function qaSave(n){
	
	$("#replydivimg"+n).show();
	$("#div"+n).slideUp(300);
	writeQAtoA(n);
}


function qaCancel(n){
	$("#replydivimg"+n).show();
	$("#div"+n).slideUp(300);
}




//save question
//_n name
//_e email
//_mf mailflag
//_wf  isweb flag
//_b question body
function writeQAtoQ(_n,_e,_mf,_wf,_b)	{
	_title = document.title;
	_h1 = isIE()?document.getElementsByTagName("H1")[0].innerText:document.getElementsByTagName("H1")[0].textContent;
	_url = location.href.replace("http://","");
	_url = _url.substring(_url.indexOf("/"),_url.length);
	if (!isLogin()){
			if (_n==""){
				alert("please input your name???");
				return false;
			}
			if (_e==""){
				alert("please input your email");
				return false;
			}
		}
	var o = {
		name : _n,
		email: _e,
		mailflag: _mf,
		webflag:  _wf,
		surl:_url,
		stitle:_title,
		body:_b
	};

	$.post("/community/include/saveQA.inc.asp?action=q",{qaname:o.name,qaemail:o.email,qamailflag:o.mailflag,qawebflag:o.webflag,qasourceurl:o.surl,qasourcetitle:o.stitle,qabody:o.body,h1:_h1},function(_sf){
  				if (parseInt(_sf)>0){ 
  					//alert("ok");
  					location.href="/faq/";
  				}else{
  					alert("The content cannot be null");
  				}
	});
}

//save question  on div form

function saveQAtoQonDiv(_n,_e,_mf,_wf,_b){
	alert(_n);
	writeQAtoQ(_n,_e,_mf,_wf,_b);
	generalDivWinClose();
}

//save answer
function writeQAtoA(o)	{
	
	a_body = document.getElementById("reply"+o).value;
	$.post("/community/include/saveQA.inc.asp?action=a", {qaqid:o,qaabody:a_body},function(_sf){
  				if (parseInt(_sf)>0){ 
  					alert("Submit Successful");
  				}else{
  					alert("The content cannot be null");
  				}
	});
}


function faqindexTab(_n){
	$(".qaNav ul li").eq(1).removeClass();
	$(".qaNav ul li").eq(2).removeClass();
	$("#lastquestion").hide();
	$("#Unanswered").hide();
	if (_n==1){
		$(".qaNav ul li").eq(1).addClass("active");
			$("#lastquestion").show();
	}else{
		$(".qaNav ul li").eq(2).addClass("active");
		$("#Unanswered").show();
	}
}
//update newsletter select
function updateNewsLetter(){
	//alert($("#editNewsLetter_newslettertype").size());
	var tmpt;
	tmpt = "";
	for (i=0;i<document.ul[1].newslettertype.length;i++){
		if (document.ul[1].newslettertype[i].checked){
			tmpt = tmpt + document.ul[1].newslettertype[i].value+",";
		}
	}
	rtxt = $.ajax({async:false,type:"GET", url:"/community/customer-center/save-newsletter.asp?ntid="+tmpt}).responseText;
	top.location.reload();
	//location.href="/community/customer-center/index.asp";
	generalDivWinClose();
}

//save comments
function saveComments(_c){
	_url = location.href.replace("http://","");
	_url = _url.substring(_url.indexOf("/"),_url.length);
	_cmmid = document.writeComments.cmmid.value;
	_cname = document.writeComments.fullname.value;
	_cemail = document.writeComments.email.value;
	_cmsg = document.writeComments.commentMsg.value;
	if (!isLogin()){
		if (_cname.length<2 || _cemail.length<6){
			alert("Please input your name & email");
			return false;
		}
		
	}
 dt = new Date();
	$.post("/community/include/save-comments.asp",{surl:_url,cname:_cname,cemail:_cemail,cmsg:_cmsg,cmmid:_cmmid},function(_sf){
//  				alert(_sf);
  				if (_sf.replace(/\s+/g,"").toLowerCase()=="true"){
  					$(".addComment.roundCorner").hide();
						tmpHtmlStr = "<div class=\"publishInfo\"><div class=\"publisher\">"+_cname+"<br />on "+['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'][dt.getMonth()]+"."+dt.getDate()+","+dt.getFullYear()+" said </div>";
						tmpHtmlStr = tmpHtmlStr + "<div class=\"clear\"></div></div><div class=\"customerReview roundCorner\"><div class=\"say\"></div>";
						tmpHtmlStr = tmpHtmlStr + _cmsg + "<div class=\"clear\"></div><a href=\"#wc\" class=\"addCom\">Add Now Comment</a>";
						tmpHtmlStr = tmpHtmlStr + "<div class=\"clear\"></div></div>"  					
  					$(".commentList.roundCorner").append(tmpHtmlStr);
  				}else{
  					alert("System error!");
  				}
	});		
	

}

//close win(div)
function generalDivWinClose(){
	$(document).trigger('close.facebox');
}

function stroyBack(){
	generalDivWinClose();
	location.href="index.asp";
}
//send messages
function smtu(n){
	if (!isLogin()){
		alert("Please first login");
		return false;
	}
	_divid = "sendmessages";
	_msg = document.getElementById(_divid+ "_msg").value;
	if (_msg.length<10){
		alert("please input Messages,the message must be more than 10 characters long.");
		return false;
	}
	if (_msg.length>500){
		alert("The message must be less than 500 characters long.");
		return false;
	}	
//	rt = $.get("/community/include/sendmessages.asp?u="+n+"&m="+_msg).responseText;
	rt = $.ajax({async:false,type:"GET", url:"/community/include/sendmessages.asp?u="+n+"&m="+_msg}).responseText;
	generalDivWinClose();
	//alert(_msg);
	//alert(rt);
	//alert(n);
	
}
function hideNewsLetter(){
	generalDivWinClose();
}
//delete travel story
function deleteTravelStory(n){
	generalDivWinClose();
	$.post("/community/travel-story/del-story.asp?sid="+n,function(_sf){
  				//alert(_sf);
	});	
	$("#trid"+n).fadeOut(300);
}

//delete travel notes
function deleteTravelNotes(n){
	generalDivWinClose();
	$.post("/community/travel-story/save-story.asp?action=delcity&nid="+n,function(_sf){
  				//alert(_sf);
	});	
	$("#trid"+n).fadeOut(300);
}

//save story new Itinerary
function saveStoryNewCity(_ac){
	_divid = "newItinerary";
	_cityname = document.getElementById(_divid+ "_newcityname").value;
	if (_cityname.length<2){
			alert("please input city name");
			return;
		}
	_tourdate = document.getElementById(_divid+ "_newtourdate").value;
	if (_tourdate.length<2){
			alert("please input tour date");
			return;
		}
	_citynote = document.getElementById(_divid+ "_newnotesbody").value;
	if (_citynote.length<100){
			alert("please input Trip Journal,the story must be more than 100 characters long.");
			return ;
		}	
	_days = document.getElementById(_divid+ "_tourdays").value;
	_sid = document.getElementById("sid").value;
	$.post("/community/travel-story/save-story.asp?action="+_ac, {cityname:_cityname,tourdate:_tourdate,citynote:_citynote,sid:_sid,days:_days},function(_sf){
  				if (parseInt(_sf)>0){ 
  					generalDivWinClose();
  					location.reload();
  				}else{
  					alert("The content cannot be null");
  				}
	});	
	
}

//add story submit Checkbox
function storycheck(){
	
	st = document.getElementById("storytitle").value;
	sb = document.getElementById("storybody").value;
	if (st=="" || st.length>60){
		document.getElementById("stitleErrTips").style.display='';
		$("#stitleErrTips").css("opacity","100");
		$("#stitleErrTips").focus();
		return false;
	}
	
	if (sb=="" || sb.length<100){
		$("#storyBodyErrTips").show();
		$("#storyBodyErrTips").css("opacity","100");
		$("#storyBodyErrTips").focus();
		return false;
	}	
	
	if (document.addStory.tourdate.length == undefined){
			if (document.addStory.city.value==""){
					alert("please input cityname?");
					return false;
					}
				if (document.addStory.tourdate.value==""){
						alert("please input arrival date?");
						return false;
					}					
	}else{
				for (n=0;n<document.addStory.tourdate.length;n++)
				{
						if (document.addStory.city[n].value==""){
							alert("please input cityname?");
							return false;
						}
						if (document.addStory.tourdate[n].value==""){
								alert("please input arrival date?");
								return false;
							}
				}
		}
	//alert("testcheck");
	return true;
}
//update Story City notes
function updateStoryCity(_n){
	_divid = "writeJournal"+_n;
	_notes = document.getElementById(_divid+ "_notesbody").value;
	$.post("/community/travel-story/save-story.asp?action=updatecity&nid="+_n,{notesbody:_notes},function(_sf){
					generalDivWinClose();
					location.reload();
  				
	});	
	
}
//write story add city js function
function addPlace(){
				tabObj = document.getElementById("placeTable");
				nnn = tabObj.rows.length;
				ggg=tabObj.insertRow(tabObj.rows.length);
				ggg.id = "tr"+nnn.toString();
				ggg.insertCell(0).innerHTML= "City "+(tabObj.rows.length - 1);
				ggg.insertCell(1).innerHTML=tabObj.rows[1].cells[1].innerHTML;
				
				newTmpHtml = tabObj.rows[1].cells[2].innerHTML.replace(new RegExp("tourdate1","gm"),"tourdate"+(tabObj.rows.length - 1));
				newTmpHtml = newTmpHtml.replace(new RegExp("dateImage1","gm"),"dateImage1"+(tabObj.rows.length - 1));
				ggg.insertCell(2).innerHTML=newTmpHtml;
				ggg.insertCell(3).innerHTML=tabObj.rows[1].cells[3].innerHTML;
				ggg.insertCell(4).innerHTML="<a href='javascript:delPlace("+nnn+")'>Delete This Place</a>";
				if (tabObj.rows.length % 2==0)  isIE()?ggg.setAttribute("className","alt-row"):ggg.setAttribute("class","alt-row");
			}
			
function delPlace(o){
	rn = document.getElementById("tr"+o).rowIndex;
//	alert(n.parentNode);
	tabObj = document.getElementById("placeTable");
tabObj.deleteRow(rn);

for (u=1;u<tabObj.rows.length;u++){
	tabObj.rows[u].cells[0].innerHTML= "City "+ u.toString();
	if (u % 2==0)  {
		isIE()?tabObj.rows[u].setAttribute("className",""):tabObj.rows[u].setAttribute("class","");
	}
	else{
		isIE()?tabObj.rows[u].setAttribute("className","alt-row"):tabObj.rows[u].setAttribute("class","alt-row");
		}
}


	
}
//other question.asp
function qatab(_s){
	$(".viewOrderLab li").removeClass();
	//$(".viewOrderLab li").eq(1).removeClass();
	if (_s=="q"){
		$(".viewOrderLab li").eq(0).addClass("current");
		$("#questionList").show();
		$("#answerList").hide();
	}else{
		$(".viewOrderLab li").eq(1).addClass("current");
		$("#questionList").hide();
		$("#answerList").show();
	}
	
	
}			