document.domain = "chinatour360.com";
$(document).ready(function(){
	/*
		Site Search Box
	*/
	$("#siteSearch input").hover(
		function(){$("#siteSearch .btn").addClass("btnH");
		//$("#siteSearch .btn").css({'background-position':' -25px -37px'});
		},
		function(){
			$("#siteSearch .btn").removeClass("btnH");
			
		}
	);
	$(".greyBtn,.redBtn").click(function(){
	 			var obj=this;
	 			var qaid=this.getAttribute("qaid");
	 			var replyto=this.getAttribute("replyto");
	 		  $.ajax({
			   type: "get",
			   url: "/com/js/qareplyajax/index.asp",
			   data: "id="+ qaid +"&v="+ Math.random(),
			   success: function(msg){
				   
				   $("#qareply"+qaid).html(msg);
				   $("#qareply"+qaid).show();			 
				  $(".close").click(function(){
				  	$(this).parent().hide();
				  });
				  $("#qaid").val(qaid);
				  $("#replyto").val(replyto);
				  if($(obj).attr("class")=="redBtn")$(".answer").hide();
				  CT.Emails.show();
			  }
	 	});
	 });

	
	$("#siteSearch .txt").click(function(){if ($(this).val()=="Site Search") $(this).val("");});
	$("#siteSearch .txt").blur(function(){if ($(this).val()=="") $(this).val("Site Search");});

	/*
		 swicth the flight, train and tour search box of right 
	*/
	$(".searchT a").eq(0).addClass("current");
	$(".searchT a").click(function(){
		var index=$(".searchT a").index($(this)[0]);
		$(this).addClass("current").siblings().removeClass("current");
		$(this).blur(); 
		//$(".searchB div").eq(index).css({'display':'block','border':'1px solid red','height':'1000px;'}).siblings().css({'display':'none','border':'0px solid red','height':'1000px;'});
		switch(index)
		{
		 case 0:
		 $("#tourCon").show(); $("#flightCon").hide(); $("#trainCon").hide();
		 break;
		 
		 case 1:
		 $("#tourCon").hide(); $("#flightCon").show(); $("#trainCon").hide();
		 break;
		 
		 case 2:
		 $("#tourCon").hide(); $("#flightCon").hide(); $("#trainCon").show();
		 break;
		 default: ;
	
		}

		//$(".searchB div").eq(index).css({'display':'block'}).siblings().css({'display':'none'});

	});
	$(".commttitle").before("<form name=\"qaSch\" method=\"get\" action=\"http://answers.chinatour360.com/search.aspx\" id=\"qaSch\">Q &amp; A Search:<input type=\"text\" class=\"txt\" name=\"q\" id=\"qaId\" /><input type=\"submit\" class=\"submit\" value=\"Search\"></form>");	
	
	$("#qaSch").submit(function(){
		var isTrue=checkTxtOfCommtSearch();
		return isTrue;
	});	
	
});

function checkTxtOfCommtSearch()
{
			var tmp=$("#qaId");
			if(tmp.val().length==0)
			{
				alert("Sorry, please enter the key words.");
				tmp.focus();
				return false;
			}
			//search log
			$.post('/inc/ajax/logCommtAjax.asp?op=savesearchkeyword&searchkey='+escape(tmp.val())+'&rn='+Math.random());
			return true;
};

function checkd(){
	var la = document.tt.f.length;
	var ff ="";
	for(var i=0;i<la;i++){
		if(document.tt.f[i].checked)ff=ff+document.tt.f[i].value+", ";
	}
	document.tt.d.value=ff+document.tt.c.value;
	document.tt.dd.value=ff+document.tt.c.value;
}

function emotArrClick() {
	if($("#moreEmot:visible").length>0) {
		$("#moreEmot").hide("normal");
	}
	else {
		$("#moreEmot").show("normal");
	}
}

function imgClick(n) {
	var index, imgSrc;
	index = n;
	if (index<10) index="0"+index;
	imgSrc="http://image.chinatour360.com/icon/emot/emot0"+index+".png";
	$("#emot").val(imgSrc);							//fred 2010-3-29
	$("#picL").attr("src",imgSrc);
	if (index>6) $("#moreEmot").hide("normal");	// hide the moreEmot div
}

function closeWin() {
	art.dialog({id:'comment_repley'}).close();
}

var comid = 0;


/*
	show reply result
*/
function showReplyResult() {
	art.dialog({id:'comment_reply'}).close();
	var reval = "";
	reval += "<div id=\"comForm2\">";
	reval += "  <div class=\"content\">Successful! <br/>Thank you for using ChinaTour360.com!</div>";
	reval += "</div>";
	
	try {
		showMask();	
		art.dialog({
				   title:"http://www.chinatour360.com",
				   content:reval,
				   width:"400px",
				   id:"comment_reply_result"
		}).close(function() { hideMask(); });
	}
	catch(e) {}
}

/*
	show result
*/		
function showResult(qaid) {
	art.dialog({id:'comment_reply'}).close();
	var reval = "";
	reval += "<div>";
	reval += "  <div class=\"content\">Successful! <br />Thank you for using ChinaTour360.com! <br /><a href=\"http://answers.chinatour360.com/qa/"+qaid+".htm\">See My Question</a>  |  <a href=\"javascript:;\" onclick=\"art.dialog({id:'comment_reply_result'}).close();hideMask();\">Stay at this Page</a></div>";
	reval += "</div>";
	try {
		showMask();	
		art.dialog({
				   title:"http://www.chinatour360.com",
				   content:reval,
				   width:"400px",
				   id:"comment_reply_result"
		}).close(function() { hideMask(); });
	}
	catch(e) {}
}


/*
	create mask
	fred 2010-5-9 
*/
function myMask(divid,iframeid) {
	/* get document width and height */
	var W = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
	var H = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
	var obj_bg = document.createElement("div");
	obj_bg.id = divid;
	with(obj_bg.style) {
		margin = 0;
		padding = 0;
		backgroundColor = "#000000";
		filter = "alpha(opacity=50)";
		opacity = 0.5;
		position = "absolute";
		top = 0;
		left = 0;
		width = W + "px";
		height = H + "px";
		zIndex = 999;
	}
	/* ie iframe not be mask  */
	if (document.all) {
		if(!obj_iframe) {
			var obj_iframe  = document.createElement("iframe");
			obj_iframe.id = iframeid;
			obj_iframe.frameborder="0";
			with(obj_iframe.style) {
				backgroundColor = "#000000";
				filter = "alpha(opacity=50)";
				opacity = 0.5;
				position = "absolute";
				top = 0;
				left = 0;
				width = W + "px"
				height = H + "px"
				zIndex = 998;
			}
			obj_bg.appendChild(obj_iframe);
	    }
	}
	document.body.appendChild(obj_bg);
}

/*
	show mask
*/
function showMask() {
	myMask("div_id","iframe_id");
}

/*
	hide mask
*/
function hideMask() {
	var div = document.getElementById("div_id");
	var iframe = document.getElementById("iframe_id");
	if(div) {
		if(iframe) {
			iframe.style.display = "none";
			div.removeChild(iframe);
		}
		div.style.display = "none";
		document.body.removeChild(div);
	}
}

/*
	refresh imgcode
*/
function refresh_code(id) {
	var o_img = document.getElementById(id);
	o_img.src = "http://www.chinatour360.com/safecode/getcode.asp?d=" + Math.random();
}


/*
	font size
*/
var fontsizeary=2;
function zoom(obj,type){
	var arySize=['18px','16px','14px','12px','10px'];
	if(type==1){
		if(fontsizeary>0)	fontsizeary=fontsizeary-1;
	}
	else{
		if(fontsizeary<4)	fontsizeary=fontsizeary+1;
	}
	document.getElementById(obj).style.fontSize=arySize[fontsizeary];
}
function checksearch()
{
	var searchbox = document.getElementById("q");
	if(searchbox)
	{
		var txt=searchbox.value.Trim();
		if(txt=="" || txt=="Site Search")
			return false;
		else
			return true;
	}
}
String.prototype.Trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
