function showGroupData1(str,containerid){
	var suffix = containerid.substr(containerid.lastIndexOf("_"));	
	var day_overnight = document.getElementById("overnight"+suffix).value;
	if(day_overnight!="1"){	
		var tmpStr = containerid.substring(0, containerid.lastIndexOf("_"));
		var seq = tmpStr.substring(tmpStr.lastIndexOf("_"));
		var sel = document.getElementById("chk_1ist"+suffix).value;
		var xmlHttp1=GetXmlHttpObject();
		if (xmlHttp1==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="getData.php";
		var params="str="+str+"&divid="+containerid+"&seq="+seq+"&suffix="+suffix+"&sel="+sel;
		params=params+"&sid="+Math.random();
		xmlHttp1.open("POST",url,true);
		xmlHttp1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp1.setRequestHeader("Content-length", params.length);
		xmlHttp1.onreadystatechange=function(){
			if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete")
			{ 
				document.getElementById(containerid).innerHTML= 'Categories: '+xmlHttp1.responseText;
				document.getElementById("item_1ist"+seq+suffix).innerHTML = "";
			} 		
		}
		xmlHttp1.send(params);
	}
}
function showGroupData2(str,containerid){	
	var suffix = containerid.substr(containerid.lastIndexOf("_"));	
	var day_overnight = document.getElementById("overnight"+suffix).value;
	if(day_overnight!="1"){	
		var tmpStr = containerid.substring(0, containerid.lastIndexOf("_"));
		var seq = tmpStr.substring(tmpStr.lastIndexOf("_"));
		var sel = document.getElementById("chk_1ist"+suffix).value;
		var xmlHttp2=GetXmlHttpObject();
		if (xmlHttp2==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="getData.php";
		var params="str="+str+"&divid="+containerid+"&seq="+seq+"&suffix="+suffix+"&sel="+sel;
		params=params+"&sid="+Math.random();
		xmlHttp2.open("POST",url,true);
		xmlHttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp2.setRequestHeader("Content-length", params.length);
		xmlHttp2.onreadystatechange=function(){
			if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")
			{ 
				document.getElementById(containerid).innerHTML=xmlHttp2.responseText;
				document.getElementById("item_1ist"+seq+suffix).innerHTML = "";
			} 		
		}
		xmlHttp2.send(params);
	}
}
function showGroupData3(str,containerid){
	var suffix = containerid.substr(containerid.lastIndexOf("_"));	
	var day_overnight = document.getElementById("overnight"+suffix).value;
	if(day_overnight!="1"){		
		var tmpStr = containerid.substring(0, containerid.lastIndexOf("_"));
		var seq = tmpStr.substring(tmpStr.lastIndexOf("_"));
		var sel = document.getElementById("chk_1ist"+suffix).value;
		var xmlHttp3=GetXmlHttpObject();
		if (xmlHttp3==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="getData.php";
		var params="str="+str+"&divid="+containerid+"&seq="+seq+"&suffix="+suffix+"&sel="+sel;
		params=params+"&sid="+Math.random();
		xmlHttp3.open("POST",url,true);
		xmlHttp3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp3.setRequestHeader("Content-length", params.length);
		xmlHttp3.onreadystatechange=function(){
			if (xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete")
			{ 
				document.getElementById(containerid).innerHTML='Categories: '+xmlHttp3.responseText;
				document.getElementById("item_1ist"+seq+suffix).innerHTML = "";
			} 		
		}
		xmlHttp3.send(params);
	}
}
function showGroupData4(str,containerid){
	var suffix = containerid.substr(containerid.lastIndexOf("_"));	
	var day_overnight = document.getElementById("overnight"+suffix).value;
	if(day_overnight!="1"){		
		var tmpStr = containerid.substring(0, containerid.lastIndexOf("_"));
		var seq = tmpStr.substring(tmpStr.lastIndexOf("_"));
		var sel = document.getElementById("chk_1ist"+suffix).value;
		var xmlHttp4=GetXmlHttpObject();
		if (xmlHttp4==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="getData.php";
		var params="str="+str+"&divid="+containerid+"&seq="+seq+"&suffix="+suffix+"&sel="+sel;
		params=params+"&sid="+Math.random();
		xmlHttp4.open("POST",url,true);
		xmlHttp4.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp4.setRequestHeader("Content-length", params.length);
		xmlHttp4.onreadystatechange=function(){
			if (xmlHttp4.readyState==4 || xmlHttp4.readyState=="complete")
			{
				document.getElementById(containerid).innerHTML=xmlHttp4.responseText;
				document.getElementById("item_1ist"+seq+suffix).innerHTML = "";
			} 		
		}
		xmlHttp4.send(params);
	}
}
function showGroupData5(str,containerid){
	var suffix = containerid.substr(containerid.lastIndexOf("_"));	
	var day_overnight = document.getElementById("overnight"+suffix).value;
	if(day_overnight!="1"){	
		var tmpStr = containerid.substring(0, containerid.lastIndexOf("_"));
		var seq = tmpStr.substring(tmpStr.lastIndexOf("_"));
		var sel = document.getElementById("chk_1ist"+suffix).value;
		var xmlHttp5=GetXmlHttpObject();
		if (xmlHttp5==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="getData.php";
		var params="str="+str+"&divid="+containerid+"&seq="+seq+"&suffix="+suffix+"&sel="+sel;
		params=params+"&sid="+Math.random();
		xmlHttp5.open("POST",url,true);
		xmlHttp5.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp5.setRequestHeader("Content-length", params.length);
		xmlHttp5.onreadystatechange=function(){
			if (xmlHttp5.readyState==4 || xmlHttp5.readyState=="complete")
			{ 
				document.getElementById(containerid).innerHTML=xmlHttp5.responseText;
				document.getElementById("item_1ist"+seq+suffix).innerHTML = "";
			} 		
		}
		xmlHttp5.send(params);
	}
}
function showData(str,containerid){	
	var suffix = containerid.substr(containerid.lastIndexOf("_"));	
	var tmpStr = containerid.substring(0, containerid.lastIndexOf("_"));
	var seq = tmpStr.substring(tmpStr.lastIndexOf("_"));
	var sel = document.getElementById("chk_1ist"+suffix).value;
	var xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="getData.php";
	sel = encodeURIComponent(sel);
	var params="str="+str+"&divid="+containerid+"&seq="+seq+"&suffix="+suffix+"&sel="+sel;
	params=params+"&sid="+Math.random();
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			document.getElementById(containerid).innerHTML=xmlHttp.responseText;
		} 		
	}
	xmlHttp.send(params);
}
function GetXmlHttpObject(){
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e) 
	{		
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
var block_cal = 0;
var block_day = 0;
function addTour(containerid,o_act_str,overnight,o_str){
	block_day = 1;
	document.getElementById("plus").style.display = "block";
	document.getElementById("addBtn").style.display = "none";
	var new_num = 0;	
	if(overnight=="1"){
		var in_array = o_str.split(",");
		new_num = in_array.length-1; 
	}
	else{
		document.getElementById("templateNum").value++;
	}	
	var num = document.getElementById("templateNum").value;		
	var xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}	
	var url="addTour.php";
	var sel = "";
	var sel_h = "";
	var sel_t = "";
	var sel_trip = "";
	var sel_o = "";
	var sel_o_seq = "";
	var l_t= "";
	var html="";
	if(overnight=="0"){
		for(var i=1;i<num;i++){																 
			sel += document.getElementById("chk_1ist_"+i).value;
			html = document.getElementById("r_"+i).innerHTML + "---";
			sel_h += html;		
			html = document.getElementById("date_"+i).value + ",";
			sel_t += html;
			html = document.getElementById("dayTrip_"+i).value + ",";
			sel_trip += html;
			html = document.getElementById("overnight_"+i).value + ",";
			sel_o += html;
			html = document.getElementById("overnight_seq_"+i).value + ",";
			sel_o_seq += html;
		}
	}
	else{
		for(var i=1;i<=num;i++){														
			sel += document.getElementById("chk_1ist_"+i).value;
			html = document.getElementById("r_"+i).innerHTML + "---";
			sel_h += html;		
			html = document.getElementById("date_"+i).value + ",";
			sel_t += html;
			html = document.getElementById("dayTrip_"+i).value + ",";
			sel_trip += html;
			html = document.getElementById("overnight_"+i).value + ",";
			sel_o += html;
			html = document.getElementById("overnight_seq_"+i).value + ",";
			sel_o_seq += html;
		}
	}
	f_t = document.getElementById("date_1").value;
	if (l_t == ""){
		if(overnight=="0"){
			for(var i=1;i<num;i++){
				if(document.getElementById("date_"+i).value != "" )
					l_t = document.getElementById("date_"+i).value;
			}
		}
		else{
			for(var i=1;i<=num;i++){
				if(document.getElementById("date_"+i).value != "" )
					l_t = document.getElementById("date_"+i).value;
			}
		}
	}	
	var h = encodeURIComponent(sel);
	var h1 = encodeURIComponent(sel_h);
	var params="num="+num+"&sel="+h+"&sel_h="+h1+"&sel_t="+sel_t+"&sel_trip="+sel_trip+"&sel_o="+sel_o+"&sel_o_seq="+sel_o_seq+"&f_t="+f_t+"&o_act_str="+o_act_str+"&overnight="+overnight+"&o_str="+o_str;	
	params=params+"&sid="+Math.random();
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById(containerid).innerHTML=xmlHttp.responseText;
			block_cal = 0;
			block_day = 0;
			if(overnight=="0"){
				changeCity(document.getElementById("city_list_select_1_"+num),"_1","_"+num);
			}
			else{
				document.getElementById("templateNum").value = parseInt(num) + parseInt(new_num) - 1;
			}
			setPrice();
			document.getElementById("addBtn").style.display = "block";
		} 		
	}
	xmlHttp.send(params);
}
function delTour(num,o_act_str,overnight,o_str){
	block_day = 1;
	var day_overnight = document.getElementById("overnight_"+num).value;
	if(day_overnight=="1"){
		alert("You've selected overnight activity this day, please uncheck that first");
	}
	else{
		var oNum = document.getElementById("templateNum").value;
		
		for(var i=2;i<=oNum;i++){
			if(document.getElementById("close_"+i)!=null){
				document.getElementById("close_"+i).style.display = "none";
			}
		}
		var new_num = 0;
		if(overnight=="1"){
			var in_array = o_str.split(",");
			new_num = in_array.length-1; 
		}
		else{
			document.getElementById("templateNum").value-- ;
		}
		var tNum = document.getElementById("templateNum").value;	
		var xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}	
		var url="delTour.php";
		var sel = "";
		var sel_h = "";
		var sel_t = "";
		var sel_trip = "";
		var sel_o = "";
		var sel_o_seq = "";
		if(overnight=="0"){
			for(var i=1;i<=oNum;i++){
				if(i!= num){
					var str = "";
					str = document.getElementById("chk_1ist_"+i).value;
					var html="";
					sel += document.getElementById("chk_1ist_"+i).value;
					html = document.getElementById("r_"+i).innerHTML + "---";
					sel_h += html;
					html = document.getElementById("date_"+i).value + ",";
					sel_t += html;
					html = document.getElementById("dayTrip_"+i).value + ",";
					sel_trip += html;
					html = document.getElementById("overnight_"+i).value + ",";
					sel_o += html;
					html = document.getElementById("overnight_seq_"+i).value + ",";
					sel_o_seq += html;
				}
				else{
					resetPrice("_"+i);
				}
			}
		}
		else{
			var o_start = parseInt(num);
			var o_end = o_start + new_num - 1;
			
			
			
			for(var i=1;i<=oNum;i++){
				if( i<=o_start || i>o_end ){
					var str = "";
					str = document.getElementById("chk_1ist_"+i).value;
					var html="";
					sel += document.getElementById("chk_1ist_"+i).value;
					html = document.getElementById("r_"+i).innerHTML + "---";
					sel_h += html;
					html = document.getElementById("date_"+i).value + ",";
					sel_t += html;
					html = document.getElementById("dayTrip_"+i).value + ",";
					sel_trip += html;
					html = document.getElementById("overnight_"+i).value + ",";
					sel_o += html;
					html = document.getElementById("overnight_seq_"+i).value + ",";
					sel_o_seq += html;
				}
				else{
					--tNum;
					if(i==o_end){
						resetPrice("_"+i);
					}
				}
			}
		}	
		var h = encodeURIComponent(sel);
		var h1 = encodeURIComponent(sel_h);
		var params="num="+tNum+"&sel="+h+"&sel_h="+h1+"&sel_t="+sel_t+"&sel_trip="+sel_trip+"&sel_o="+sel_o+"&sel_o_seq="+sel_o_seq;
		params=params+"&sid="+Math.random();
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.onreadystatechange=function(){
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{ 
				document.getElementById("exTour").innerHTML=xmlHttp.responseText;
				block_cal = 0;
				block_day = 0;
				if(overnight=="1"){
					document.getElementById("templateNum").value = oNum - new_num + 1 ;
				}
				setPrice();				
				for(var i=2;i<=tNum;i++){
					if(document.getElementById("close_"+i)!=null){
						document.getElementById("close_"+i).style.display = "block";
					}
				}
			} 		
		}
		xmlHttp.send(params);
	}
}
function h_o_c(seq,suffix){
	document.getElementById("hours"+seq+suffix+"R").innerHTML = "";
	document.getElementById("hours"+seq+suffix+"T").innerHTML = "";
	for(var i=1;i<6;i++){
		if(i > parseInt(seq.substr(1))){
			document.getElementById("r_group_"+i+suffix+"H").style.display = "none";
			document.getElementById("r_group_"+i+suffix+"R").style.display = "none";
		}
	}
}
function s_o_c(seq,suffix){
	document.getElementById("hours"+seq+suffix+"R").innerHTML = "0";
	document.getElementById("hours"+seq+suffix+"T").innerHTML = "hours";
	for(var i=1;i<6;i++){
		if( i >= parseInt(seq.substr(1)) ){
			document.getElementById("r_group_"+i+suffix+"H").style.display = "block";
			document.getElementById("r_group_"+i+suffix+"R").style.display = "block";
		}
	}
}
function close_group_item(suffix){
	//for(var i=1;i<6;i++){
	//	if(document.getElementById("group_list_select_" + i + suffix)!=null){
	//		document.getElementById("group_list_select_"+ i + suffix).selectedIndex = 0;
	//	}
	//	if(document.getElementById("item_1ist_" + i + suffix)!=null){
	//		document.getElementById("item_1ist_" + i + suffix).innerHTML = '';
	//	}
	//}
}
function getChk_id(obj,seq,suffix,id, price, groupid, pos, mul_select, group_member, hours,override,dayTrip,base_price,profit,overnight,o_str){
	var e = obj.checked;	
	if(block_cal == 1 || block_day == 1){
		if(e==true){
			obj.checked = false;
		}
		alert("Please wait while the price is being calculated");
	}
	else{
		block_cal = 1;
		document.getElementById("plus").style.display = "block";
		var newGroup = decodeURIComponent(group_member);
		var t_g = newGroup.split(",");
		if(pos=="L"){
			n = obj.value;
			m = obj.name;
		}else{
			n = obj.value.substr(2);
			m = obj.name.substr(2,obj.name.length-3);
			suffix = suffix.substr(0,suffix.length-1);
			groupid = groupid.substr(0, groupid.length-1);
		}
		var numOfGuest = document.getElementById("numOfGuest").value;
		if(numOfGuest == "" || numOfGuest == "0"){
			numOfGuest = "1";				
		}
		var numOfChildren = document.getElementById("numOfChildren").value;
		if(numOfChildren == ""){
			numOfChildren = "0";				
		}
		if(e==true){
			var pre_Str = "";
			if(price=="-1"){
				var str = n+"_price_select"+seq+suffix;			
				var newValue =  n+"_"+document.getElementById(str).value;
				if( mul_select == '1'){	
					
					rv = checkhours(hours,seq,suffix,override,dayTrip,overnight);
					if(rv==false){
						obj.checked = false;
						block_cal = 0;
						return;
					}
					document.getElementById("chk_1ist"+suffix).value += newValue;
					document.getElementById("chk_1ist"+suffix).value += ',';
					//document.getElementById("r_group_"+groupid+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';
					document.getElementById("r_group"+seq+suffix+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';
				}
				if( mul_select == '0'){
					
					var tempStr = document.getElementById("chk_1ist"+suffix).value;
					var startIndex = -1;
					var preObjStr = "";
					var preObjName = "";
					for(var i=0;i<(t_g.length-1);i++){
						startIndex = tempStr.indexOf(t_g[i]);
						if(  startIndex != -1){
							preObjStr = t_g[i];
							preObjName = preObjStr.substring(0,preObjStr.indexOf("_"));
							break; 
						}
					}
					if(startIndex == -1){	
						
						rv = checkhours(hours,seq,suffix,override,dayTrip,overnight);
						if(rv==false){
							obj.checked = false;
							block_cal = 0;
							return;
						}
						document.getElementById("chk_1ist"+suffix).value += newValue;
						document.getElementById("chk_1ist"+suffix).value += ',';
						//document.getElementById("r_group_"+groupid+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';					
						document.getElementById("r_group"+seq+suffix+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';					
					}
					else{
						
						rv = checkhours(hours,seq,suffix,override,dayTrip,overnight);
						if(rv==false){
							obj.checked = false;
							block_cal = 0;
							return;
						}
						var t = document.getElementById(preObjName+seq+suffix+"_h").value;					
						var t_hours = parseFloat(document.getElementById("hours"+seq+suffix+"R").innerHTML)-parseFloat(t);
						document.getElementById("hours"+seq+suffix+"R").innerHTML = t_hours;
						var commIndex = tempStr.indexOf(",",startIndex);							
						var endIndex = commIndex + 1;
						var preStr = tempStr.substring(0, startIndex);
						var newStr = "";
						if(endIndex < tempStr.length){
							var nextStr = tempStr.substr(endIndex);
							newStr = preStr + newValue + "," + nextStr;
						}
						else{
							newStr = preStr + newValue + ",";
						}					
						var preObj = "chk_"+preObjName+seq+suffix;
						document.getElementById("chk_1ist"+suffix).value = newStr;
						document.getElementById(preObj).checked = false;
						var preObjR = "r_"+preObjName+seq+suffix+"R";
						var x = document.getElementById(preObjR);
						//document.getElementById("r_group_"+groupid+"R").removeChild(x);
						//document.getElementById("r_group_"+groupid+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';
						document.getElementById("r_group"+seq+suffix+"R").removeChild(x);
						document.getElementById("r_group"+seq+suffix+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';
						pre_Str = preObjStr;
					}
				}
				var v = "";
				if(pre_Str!=""){	
					
					var pre_item = preObjStr.split("_");
					v = pre_item[3];//price						
					var pre_b = pre_item[4];//base_price
					var pre_p = pre_item[5];//price
					var timesOfPrePrice = 1 + parseInt(pre_p)/100;				
					//alert("v="+v+" timesOfPrePrice="+timesOfPrePrice);
					document.getElementById("bprice").value = parseInt(document.getElementById("bprice").value) - parseInt(parseInt(v) * timesOfPrePrice) * (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(parseInt(pre_b) * timesOfPrePrice);
					document.getElementById("bcost").value = parseInt(document.getElementById("bcost").value) - parseInt(v) * (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(pre_b);
				}
				var pre_value = document.getElementById(str).value;
				var cur_item = pre_value.split("_");
				v = cur_item[2];//price	
				var curPrice = document.getElementById("bprice").value;
				var curCost = document.getElementById("bcost").value;
				var totalPrice = 0;
				var totalCost = 0;
				var timeOfCurPrice = 1 + parseInt(profit)/100;
				totalPrice = parseInt(curPrice) + parseInt(parseInt(v) * timeOfCurPrice) * (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(parseInt(base_price)*timeOfCurPrice);
				totalCost = parseInt(curCost) + parseInt(v)  * (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(base_price);
				document.getElementById("bprice").value =  totalPrice;
				document.getElementById("bcost").value =  totalCost;
				if(overnight=="0"){
					block_cal = 0;
				}					
				setPrice();
				var t_hours = parseFloat(document.getElementById("hours"+seq+suffix+"R").innerHTML)+parseFloat(hours);
				if(overnight=="1"){
					h_o_c(seq,suffix);
					addTour('exTour',newValue,overnight,o_str);
				}
				else{
					document.getElementById("hours"+seq+suffix+"R").innerHTML = t_hours;
				}
				close_group_item(suffix);
			}
			else{			
				var newValue =  n +'_'+id+seq+'_'+price+'_'+base_price+'_'+profit+suffix;
				if( mul_select == '1'){	
					
					rv = checkhours(hours,seq,suffix,override,dayTrip,overnight);
					if(rv==false){
						obj.checked = false;
						block_cal = 0;
						return;
					}
					document.getElementById("chk_1ist"+suffix).value += newValue;
					document.getElementById("chk_1ist"+suffix).value += ',';
					//document.getElementById("r_group_"+groupid+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';
					document.getElementById("r_group"+seq+suffix+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';				
					var curPrice = document.getElementById("bprice").value;
					var curCost = document.getElementById("bcost").value;
					var totalPrice = 0;
					var totalCost = 0;
					var timeOfCurPrice = 1 + parseInt(profit)/100;
					totalPrice = parseInt(curPrice) + parseInt(parseInt(price) * timeOfCurPrice) *  (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(parseInt(base_price)*timeOfCurPrice);
					totalCost = parseInt(curCost) + parseInt(price) * (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(base_price);
					document.getElementById("bprice").value =  totalPrice;
					document.getElementById("bcost").value =  totalCost;
					if(overnight=="0"){
						block_cal = 0;
					}					
					setPrice();
					var t_hours = parseFloat(document.getElementById("hours"+seq+suffix+"R").innerHTML)+parseFloat(hours);
					if(overnight=="1"){
						h_o_c(seq,suffix);
						addTour('exTour',newValue,overnight,o_str);
					}
					else{
						document.getElementById("hours"+seq+suffix+"R").innerHTML = t_hours;
					}
					close_group_item(suffix);
					//document.getElementById("group_list_select"+seq+suffix).selectedIndex = 0;
					//document.getElementById("item_1ist"+seq+suffix).innerHTML = '';
				}
				if( mul_select == '0'){					
					
					var tempStr = document.getElementById("chk_1ist"+suffix).value;
					var startIndex = -1;
					var preObjStr = "";
					var preObjName = "";
					for(var i=0;i<(t_g.length-1);i++){
						startIndex = tempStr.indexOf(t_g[i]);
						if(  startIndex != -1){
							preObjStr = t_g[i];
							preObjName = preObjStr.substring(0,preObjStr.indexOf("_"));
							break; 
						}
					}				
					if(startIndex == -1){
						
						rv = checkhours(hours,seq,suffix,override,dayTrip,overnight);
						if(rv==false){
							obj.checked = false;
							block_cal = 0;
							return;
						}
						document.getElementById("chk_1ist"+suffix).value += newValue;
						document.getElementById("chk_1ist"+suffix).value += ',';
						//document.getElementById("r_group_"+groupid+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';					
						document.getElementById("r_group"+seq+suffix+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';					
					}
					else{
						
						rv = checkhours(hours,seq,suffix,override,dayTrip,overnight);
						if(rv==false){
							obj.checked = false;
							block_cal = 0;
							return;
						}
						var t = document.getElementById(preObjName+seq+suffix+"_h").value;					
						
						var t_hours = parseFloat(document.getElementById("hours"+seq+suffix+"R").innerHTML)-parseFloat(t);
						document.getElementById("hours"+seq+suffix+"R").innerHTML = t_hours;
						var commIndex = tempStr.indexOf(",",startIndex);							
						var endIndex = commIndex + 1;					
						var preStr = tempStr.substring(0, startIndex);
						var newStr = "";
						if(endIndex < tempStr.length){
							var nextStr = tempStr.substr(endIndex);
							newStr = preStr + newValue + "," + nextStr;
						}
						else{
							newStr = preStr + newValue + ",";
						}					
						var preObj = "chk_"+preObjName+seq+suffix;
						document.getElementById("chk_1ist"+suffix).value = newStr;
						document.getElementById(preObj).checked = false;
						var preObjR = "r_"+preObjName+seq+suffix+"R";
						var x = document.getElementById(preObjR);
						//document.getElementById("r_group_"+groupid+"R").removeChild(x);
						//document.getElementById("r_group_"+groupid+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';
						document.getElementById("r_group"+seq+suffix+"R").removeChild(x);
						document.getElementById("r_group"+seq+suffix+"R").innerHTML += '<div id="r_'+m+'R" class="commonFont smallTxt whiteTxt">'+n+'<input onclick = getChk_id(this,"'+seq+'","'+suffix+'R","'+id+'","'+price+'","'+groupid+'R","R","'+mul_select+'","'+group_member+'","'+hours+'","'+override+'","'+dayTrip+'","'+base_price+'","'+profit+'","'+overnight+'","'+o_str+'") type="checkbox" value="r_'+n+'" name="r_'+n+seq+suffix+'R" checked></div>';
						pre_Str = preObjStr;
					}
					var v = "";
					if(pre_Str!=""){
						
						var pre_item = preObjStr.split("_");
						v = pre_item[3];//price						
						var pre_b = pre_item[4];//base_price
						var pre_p = pre_item[5];//price
						var timesOfPrePrice = 1 + parseInt(pre_p)/100;
						//alert("v="+v+" timesOfPrePrice="+timesOfPrePrice);
						document.getElementById("bprice").value = parseInt(document.getElementById("bprice").value) - parseInt(parseInt(v) * timesOfPrePrice) * (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(parseInt(pre_b) * timesOfPrePrice);
						document.getElementById("bcost").value = parseInt(document.getElementById("bcost").value) - parseInt(v) * (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(pre_b);
					}
					var curPrice = document.getElementById("bprice").value;
					var curCost = document.getElementById("bcost").value;
					var totalPrice = 0;
					var totalCost = 0;
					var timeOfCurPrice = 1 + parseInt(profit)/100;
					totalPrice = parseInt(curPrice) + parseInt(parseInt(price) * timeOfCurPrice) *  (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(parseInt(base_price)*timeOfCurPrice);
					totalCost = parseInt(curCost) + parseInt(price)  *  (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(base_price);
					document.getElementById("bprice").value =  totalPrice;
					document.getElementById("bcost").value =  totalCost;
					if(overnight=="0"){
						block_cal = 0;
					}										
					setPrice();
					var t_hours = parseFloat(document.getElementById("hours"+seq+suffix+"R").innerHTML)+parseFloat(hours);
					if(overnight=="1"){
						h_o_c(seq,suffix);
						addTour('exTour',newValue,overnight,o_str);
					}
					else{
						document.getElementById("hours"+seq+suffix+"R").innerHTML = t_hours;
					}
					close_group_item(suffix);
				}						
			}
		}
		else{
			var p = "";
			var timeOfCurPrice = 1 + parseInt(profit)/100;
			if(overnight == "1"){
				document.getElementById("overnight"+suffix).value = "0";
				document.getElementById("overnight_seq"+suffix).value = "0";
			}
			if(dayTrip == "1"){
				document.getElementById("dayTrip"+suffix).value = "0";
				document.getElementById("tr"+suffix).style.display ="block";
			}
			if(pos=="R"){
				if(document.getElementById("chk_"+n+seq+suffix)!= null){
					document.getElementById("chk_"+n+seq+suffix).checked = false;
				}	
			}
			if(price=="-1"){
				
				var v="";
				var str = n+"_price_select"+seq+suffix;
				if(document.getElementById(str) == null){
					
					var tempStr = document.getElementById("chk_1ist"+suffix).value;
					var newStr = "";								
					var strArray = tempStr.split(",");
					for(var i=0;i<strArray.length-1;i++){	
						var t_index = strArray[i].indexOf(n);				
						if(t_index!=-1 ){
							var pre_item = strArray[i].split("_");
							v = pre_item[3];
							var t_seq = pre_item[2];
							var t_suffix = pre_item[6];
							if(t_seq == seq.substring(1) && t_suffix == suffix.substring(1)){
								p = strArray[i];
								var startIndex = tempStr.indexOf(strArray[i]);
								var commIndex = tempStr.indexOf(",",startIndex);							
								var endIndex = commIndex + 1;							
								var preStr = tempStr.substring(0, startIndex);
								if(endIndex < tempStr.length){
									var nextStr = tempStr.substr(endIndex);
									newStr = preStr + nextStr;
								}
								else{
									newStr = preStr;
								}							
								document.getElementById("chk_1ist"+suffix).value = newStr;
								var x = document.getElementById("r_"+m+"R");
								//document.getElementById("r_group_"+groupid+"R").removeChild(x);
								document.getElementById("r_group"+seq+suffix+"R").removeChild(x);
								var curPrice = document.getElementById("bprice").value;
								var curCost = document.getElementById("bcost").value;
								var totalPrice = 0;
								var totalCost = 0;
								//alert("v="+v+" timeOfCurPrice="+timeOfCurPrice);
								totalPrice = parseInt(curPrice) - parseInt(parseInt(v) * timeOfCurPrice) *  (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(parseInt(base_price)*timeOfCurPrice);
								totalCost = parseInt(curCost) - parseInt(v)  * (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(base_price);
								document.getElementById("bprice").value =  totalPrice;
								document.getElementById("bcost").value =  totalCost;
								
								if(overnight=="0"){
									block_cal = 0;
								}													
								setPrice();
								var t_hours = parseFloat(document.getElementById("hours"+seq+suffix+"R").innerHTML)-parseFloat(hours);
								if(overnight=="1"){
									s_o_c(seq,suffix);
									delTour(suffix.substring(1),p,overnight,o_str);
								}
								else{
									document.getElementById("hours"+seq+suffix+"R").innerHTML = t_hours;
								}
								close_group_item(suffix);
								break;
							}
						}
					}
					return;
				}
				else{
					
					p =  n+"_"+document.getElementById(str).value;
					var pre_value = document.getElementById(str).value;
					var cur_item = pre_value.split("_");
					v = cur_item[2];//price	
					var curPrice = document.getElementById("bprice").value;
					var curCost = document.getElementById("bcost").value;
					var totalPrice = 0;
					var totalCost = 0;
					totalPrice = parseInt(curPrice) - parseInt(parseInt(v) * timeOfCurPrice) *  (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(parseInt(base_price)*timeOfCurPrice);
					totalCost = parseInt(curCost) - parseInt(v)  * (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(base_price);
					document.getElementById("bprice").value =  totalPrice;
					document.getElementById("bcost").value =  totalCost;
				}
			}
			else{
				
				p =  n +'_'+id+seq+'_'+price+'_'+base_price+'_'+profit+suffix;
				var curPrice = document.getElementById("bprice").value;
				var curCost = document.getElementById("bcost").value;
				var totalPrice = 0;
				var totalCost = 0;
				totalPrice = parseInt(curPrice) - parseInt(parseInt(price) * timeOfCurPrice) *  (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(parseInt(base_price)*timeOfCurPrice);
				totalCost = parseInt(curCost) - parseInt(price)  * (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(base_price);
				document.getElementById("bprice").value =  totalPrice;
				document.getElementById("bcost").value =  totalCost;
			}				
			var tempStr = document.getElementById("chk_1ist"+suffix).value;
			var newStr = "";
			var startIndex = tempStr.indexOf(p+",");
			var strLength = p.length+1;	
			var endIndex = startIndex + strLength;		
			var preStr = tempStr.substring(0, startIndex);
			if(endIndex < tempStr.length){
				var nextStr = tempStr.substr(endIndex);
				newStr = preStr + nextStr;
			}
			else{
				newStr = preStr;
			}
			document.getElementById("chk_1ist"+suffix).value = newStr;
			var x = document.getElementById("r_"+m+"R");
			//document.getElementById("r_group_"+groupid+"R").removeChild(x);
			document.getElementById("r_group"+seq+suffix+"R").removeChild(x);
			if(overnight=="0"){
				block_cal = 0;
			}					
			setPrice();
			var  t_hours = parseFloat(document.getElementById("hours"+seq+suffix+"R").innerHTML)-parseFloat(hours);
			if(overnight=="1"){
				s_o_c(seq,suffix);
				delTour(suffix.substring(1),p,overnight,o_str);
			}
			else{
				document.getElementById("hours"+seq+suffix+"R").innerHTML = t_hours;
			}
			close_group_item(suffix);
		}
	}
}

function checkhours(hours,seq,suffix,override,dayTrip,overnight){	
	var t_hours = document.getElementById("hours"+seq+suffix+"R").innerHTML;
	var t1_hours = document.getElementById("hours_1"+suffix+"R").innerHTML;
	var t2_hours = document.getElementById("hours_2"+suffix+"R").innerHTML;
	var t3_hours = document.getElementById("hours_3"+suffix+"R").innerHTML;
	var t4_hours = document.getElementById("hours_4"+suffix+"R").innerHTML;
	var t5_hours = document.getElementById("hours_5"+suffix+"R").innerHTML;
	
	var day_trip = document.getElementById("dayTrip"+suffix).value;
	var day_overnight = document.getElementById("overnight"+suffix).value;
	
	
	var day_overnight_seq = document.getElementById("overnight_seq"+suffix).value;
	var t_h = parseFloat(t1_hours)+parseFloat(t2_hours)+parseFloat(t3_hours);
	var o_h1 = parseFloat(t1_hours)+parseFloat(t2_hours)+parseFloat(t3_hours)+parseFloat(t4_hours)+parseFloat(t5_hours);
	var o_h3 = parseFloat(t3_hours)+parseFloat(t4_hours)+parseFloat(t5_hours);
	
	var new_hours = parseFloat(hours) + parseFloat(t_hours);	
	var a_hours = parseFloat(hours)+parseFloat(t4_hours)+parseFloat(t5_hours);
	
	
	switch(seq)
	{	
		case "_1":
			if( overnight=="0" ){
				if(day_overnight == "1" && (seq.substr(1) == day_overnight_seq)){
					alert("Can not select activity, alreay select a overnight");
					return false;						
				}
				if( dayTrip=="0" ){
					if(day_trip == "1"){
						alert("Can not select activity, alreay select a day trip");
						return false;						
					}
					if( override=="0" ){
						if( new_hours > 4 ){
							alert("Can not select activity, hours for Morning limited to 4 hours");
							return false;
						}
					}
					if( override=="1" ){
						if( t_hours != 0 ){
							alert("Can not select this one, please uncheck other activities of this morning first ");
							return false;
						}
					}
				}
				else{
					if( t_h != 0 ){
						alert("This activity is day trip, please uncheck all other activities of morning, lunch and afternoon of this day");
						return false;
					}
					else{
						document.getElementById("dayTrip"+suffix).value = "1";
						document.getElementById("tr"+suffix).style.display ="none";
					}
				}
			}
			else{
				if( day_overnight == "1" ){
						alert("This day already includes overnight activtiy, please select other non-overnight activities");
						return false;
				}
				else{
					if( o_h1 != 0 ){
						alert("This activity is overnight, please uncheck all other activities of morning, lunch, afternoon, dinner and after dinner of this day");
						return false;
					}
					else{
						document.getElementById("overnight"+suffix).value = "1";
						document.getElementById("overnight_seq"+suffix).value = "1";
					}
				}
			}
			break;
		case "_2":			
			if( new_hours > 2 ){
				alert("Can not select activity, hours for Lunch limited to 1.5 hours");
				return false;
			}
			break;
		case "_3":
			if( overnight=="0" ){
				if(day_overnight == "1" && (seq.substr(1) == day_overnight_seq)){
					alert("Can not select activity, alreay select a overnight");
					return false;						
				}
				if( dayTrip=="0" ){
					if(day_trip == "1"){
						alert("Can not select activity, alreay select a day trip");
						return false;						
					}
					if( override=="0" ){
						if( new_hours > 5 ){
							alert("Can not select activity, hours for Afternoon limited to 5 hours");
							return false;
						}
					}
					if( override=="1" ){
						if( t_hours != 0 ){
							alert("Can not select this one, please uncheck other activities of this afternoon first ");
							return false;
						}
					}
				}
				else{
					if( t_h != 0 ){
						alert("This activity is day trip, please uncheck all other activities of morning, lunch and afternoon of this day");
						return false;
					}
				}
			}
			else{
				if( day_overnight == "1" ){
					alert("This day already includes overnight activtiy, please select other non-overnight activities");
					return false;
				}
				else{
					if( o_h3 != 0 ){
						alert("This activity is overnight, please uncheck all other activities of afternoon, dinner and after dinner of this day");
						return false;
					}
					else{
						document.getElementById("overnight"+suffix).value = "1";
						document.getElementById("overnight_seq"+suffix).value = "3";
					}
				}
			}
			break;
		case "_4":
				if( a_hours > 3 ){
					alert("Can not select activity, hours for Dinner and After Dinner limited to 3 hours");
					return false;
				}
			break;
		case "_5":
				if( a_hours > 3 ){
					alert("Can not select activity, hours for Dinner and After Dinner limited to 3 hours");
					return false;
				}
			break;
		default:
			alert("got error");
			return false;
	}	
}
function changeCity(obj,seq,suffix){
	tempStr = document.getElementById("chk_1ist"+suffix).value;
	var temp_chk_Str = tempStr.substr(tempStr.indexOf("city_"));	
	var ori_city_str = temp_chk_Str.substring(5,temp_chk_Str.indexOf(","));
	
	if(block_cal == 1 || block_day == 1){
		if(tempStr.indexOf("city_")==-1){
			obj.selectedIndex = 0;
		}
		else{
			for (i=0;i<obj.length;i++)
			{	
				if(obj.options[i].value == ori_city_str){
					obj.selectedIndex = i;
				}
			}
		}
		alert("Please wait while the price is being calculated");
	}
	else{
		var day_overnight = document.getElementById("overnight"+suffix).value;
		if(day_overnight=="1"){
			alert("You've selected overnight activity this day, please uncheck that first");
			for (i=0;i<obj.length;i++)
			{	
				if(obj.options[i].value == ori_city_str){
					obj.selectedIndex = i;
				}
			}
		}
		else{
			resetPrice(suffix);
			document.getElementById("chk_1ist"+suffix).value = "";
			var n = (obj.name).substring(0,(obj.name).indexOf("_"));
			//startIndex = tempStr.indexOf(n);	
			//if(startIndex==-1 && obj.value != 0){
				document.getElementById("chk_1ist"+suffix).value += n+"_"+obj.value;
				document.getElementById("chk_1ist"+suffix).value += ',';
			//}	
			document.getElementById("item_1ist"+seq+suffix).innerHTML = "";
			document.getElementById("r"+suffix).innerHTML = "";
			//document.getElementById("r"+suffix).innerHTML += '<div class="commonFont smallTxt yellowTxt ">ACTIVITIES SELECTED</div>';
			
			document.getElementById("r"+suffix).innerHTML += '<div id="r_group_1'+suffix+'H" class="commonFont smallTxt redTxt"><div class="floatLeft">Morning</div><div id="hours_1'+suffix+'R" name="hours_1'+suffix+'R" class="floatLeft whiteTxt hour">0</div><div id="hours_1'+suffix+'T" class="floatLeft whiteTxt">hours</div></div>';
			document.getElementById("r"+suffix).innerHTML += '<div id="r_group_1'+suffix+'R" class="commonFont smallTxt redTxt rightTxt clearboth"></div>';		
			document.getElementById("r"+suffix).innerHTML += '<div id="r_group_2'+suffix+'H" class="commonFont smallTxt redTxt"><div class="floatLeft">Lunch</div><div id="hours_2'+suffix+'R" name="hours_2'+suffix+'R" class="floatLeft whiteTxt hour">0</div><div id="hours_2'+suffix+'T" class="floatLeft whiteTxt">hours</div></div>';
			document.getElementById("r"+suffix).innerHTML += '<div id="r_group_2'+suffix+'R" class="commonFont smallTxt redTxt rightTxt clearboth"></div>';		
			document.getElementById("r"+suffix).innerHTML += '<div id="r_group_3'+suffix+'H" class="commonFont smallTxt redTxt"><div class="floatLeft">Afternoon</div><div id="hours_3'+suffix+'R" name="hours_3'+suffix+'R" class="floatLeft whiteTxt hour">0</div><div id="hours_3'+suffix+'T" class="floatLeft whiteTxt">hours</div></div>';
			document.getElementById("r"+suffix).innerHTML += '<div id="r_group_3'+suffix+'R" class="commonFont smallTxt redTxt rightTxt clearboth"></div>';		
			document.getElementById("r"+suffix).innerHTML += '<div id="r_group_4'+suffix+'H" class="commonFont smallTxt redTxt"><div class="floatLeft">Dinner</div><div id="hours_4'+suffix+'R" name="hours_4'+suffix+'R" class="floatLeft whiteTxt hour">0</div><div id="hours_4'+suffix+'T" class="floatLeft whiteTxt">hours</div></div>';
			document.getElementById("r"+suffix).innerHTML += '<div id="r_group_4'+suffix+'R" class="commonFont smallTxt redTxt rightTxt clearboth"></div>';		
			document.getElementById("r"+suffix).innerHTML += '<div id="r_group_5'+suffix+'H" class="commonFont smallTxt redTxt"><div class="floatLeft">After Dinner</div><div id="hours_5'+suffix+'R" name="hours_5'+suffix+'R" class="floatLeft whiteTxt hour">0</div><div id="hours_5'+suffix+'T" class="floatLeft whiteTxt">hours</div></div>';
			document.getElementById("r"+suffix).innerHTML += '<div id="r_group_5'+suffix+'R" class="commonFont smallTxt redTxt rightTxt clearboth"></div>';
			setPrice();
		}
	}
}
function changeGroup(obj,seq,suffix){
	var n = (obj.name).substring(0,(obj.name).indexOf("_"));
	var tempStr = document.getElementById("chk_1ist"+suffix).value;
	var newStr = "";
	var startIndex = tempStr.indexOf(n);
	var newGroupStr = "";
	var curGroupStr = "";

	if(startIndex==-1){
		newGroupStr = n+"_"+obj.value+",";
		document.getElementById("chk_1ist"+suffix).value = newGroupStr +  document.getElementById("chk_1ist"+suffix).value ;
	}
	else{
		curGroupStr = n + "_" + obj.value;
		var curGroupIndex = tempStr.indexOf(curGroupStr);
		if(curGroupIndex == -1){ 
			newGroupStr = n+"_"+obj.value+",";
			document.getElementById("chk_1ist"+suffix).value = newGroupStr +  document.getElementById("chk_1ist"+suffix).value ;
		}
		else{
			if(curGroupIndex != 0){
				var commIndex = tempStr.indexOf(",",curGroupIndex);
				var endIndex = commIndex + 1;
				var preStr = tempStr.substring(0, curGroupIndex);
				var nextStr = "";
				if(endIndex < tempStr.length){
					nextStr = tempStr.substr(endIndex);
					newStr = curGroupStr + "," + preStr + nextStr;
				}
				else{
					newStr = curGroupStr + "," + preStr;
				}
				document.getElementById("chk_1ist"+suffix).value = newStr;
			}
		}
	}
	//var html = '<div id="r_'+ n + "_" + obj.value+'R" class="commonFont smallTxt redTxt rightTxt clearboth">'+obj.options[obj.selectedIndex].text+'</div>';
	//var searchStr = document.getElementById("r_group"+seq+suffix+"R").innerHTML;
	//var selectTxt = obj.options[obj.selectedIndex].text;
	//selectTxt = selectTxt.replace(/&/, "&amp;");
	//if(searchStr.indexOf(selectTxt) == -1 && obj.value != ""){
	//	document.getElementById("r_group"+seq+suffix+"R").innerHTML += html;
	//}
}

function changePrice(obj,seq,suffix){
	var n = (obj.name).substring(0,(obj.name).indexOf("_"));
	
	var tempStr = document.getElementById("chk_1ist"+suffix).value;
	var temp_chk_Str = tempStr.substr(tempStr.indexOf(n+"_"));	
	var ori_price_str = temp_chk_Str.substring(n.length+1,temp_chk_Str.indexOf(","));
	if(block_cal == 1 || block_day == 1){
		if(tempStr.indexOf(n+"_")==-1){
			obj.selectedIndex = 0;
		}
		else{
			for (i=0;i<obj.length;i++)
			{	
				if(obj.options[i].value == ori_price_str){
					obj.selectedIndex = i;
				}
			}
		}
		alert("Please wait while the price is being calculated");
	}
	else{
		var numOfGuest = document.getElementById("numOfGuest").value;
		if(numOfGuest == "" || numOfGuest == "0"){
			numOfGuest = "1";				
		}
		
		
		var newStr = "";
		var strArray = tempStr.split(",");
		for(var i=0;i<strArray.length;i++){	
			var t_index = strArray[i].indexOf(n);				
			if(t_index!=-1 ){
				var pre_item = strArray[i].split("_");
				var t_seq = pre_item[2];
				var v = pre_item[3];//price						
				var pre_b = pre_item[4];//base_price
				var pre_p = pre_item[5];//price
				var timesOfPrePrice = 1 + parseInt(pre_p)/100;
				//alert("will del pre price"); TESTED OK
				document.getElementById("bprice").value = parseInt(document.getElementById("bprice").value) - parseInt(parseInt(v) * timesOfPrePrice) *  (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(parseInt(pre_b) * timesOfPrePrice);
				document.getElementById("bcost").value = parseInt(document.getElementById("bcost").value) - parseInt(v) * (parseInt(numOfGuest)+parseInt(numOfChildren)) - parseInt(pre_b);
				if(t_seq == seq.substring(1)){
					//alert("new price"); TESTED OK
					var startIndex = tempStr.indexOf(strArray[i]);
					var commIndex = tempStr.indexOf(",",startIndex);				
					var endIndex = commIndex + 1;				
					var preStr = tempStr.substring(0, startIndex);
					var nextStr = "";
					if(endIndex < tempStr.length){
						nextStr = tempStr.substr(endIndex);
						newStr = preStr + n + "_" + obj.value  + "," + nextStr;
					}
					else{
						newStr = preStr + n + "_" + obj.value  + ",";
					}
					document.getElementById("chk_1ist"+suffix).value = newStr;			
					var cur_item = (obj.value).split("_");
					v = cur_item[2];//price						
					pre_b = cur_item[3];//base_price
					pre_p = cur_item[4];//price
					timesOfCurPrice = 1 + parseInt(pre_p)/100;
					var curPrice = document.getElementById("bprice").value;
					var curCost = document.getElementById("bcost").value;
					document.getElementById("bprice").value =  parseInt(curPrice) + parseInt(parseInt(v) * timesOfCurPrice) * (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(parseInt(pre_b) * timesOfCurPrice);
					document.getElementById("bcost").value =  parseInt(curCost) + parseInt(v) * (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(pre_b);
					setPrice();
				}
			}
		}
	}
}
function setNumOfGuest(){
	var num = document.getElementById("templateNum").value;
	var ori_numOfGuest = parseInt(document.getElementById("ori_numOfGuest").value);
	if(block_cal == 1 || block_day == 1){
		document.getElementById("numOfGuest").value = ori_numOfGuest;
		document.getElementById("ori_numOfGuest").value = ori_numOfGuest;		
		alert("Please wait while the price is being calculated");
	}
	else{
		var numOfGuest = document.getElementById("numOfGuest").value;	
		if(numOfGuest!='2'){
			document.getElementById("plus").style.display = "block";
		}
		var numOfChildren = document.getElementById("numOfChildren").value;
		if(numOfChildren == ""){
			numOfChildren = "0";				
		}	
		if(notNum(numOfGuest) || numOfGuest == "0" ){
			document.getElementById("v_cost").value = 0;
			document.getElementById("vprice").value = 0;
			setPrice();
			return;
		}
		var total_num = parseInt(numOfGuest) + parseInt(numOfChildren);
		if( total_num > 40 ){
			alert("The number of people is > 40, Please contact us and we'll make a special itinerary for you");
			document.getElementById("numOfGuest").value = ori_numOfGuest;
			return;
		}	
		document.getElementById("ori_numOfGuest").value = numOfGuest;
		resetBPrice(parseInt(numOfGuest),parseInt(numOfChildren),num);
		getV(total_num);
	}
}
function setNumOfChildren(){
	document.getElementById("plus").style.display = "block";
	var num = document.getElementById("templateNum").value;
	var ori_numOfChildren = parseInt(document.getElementById("ori_numOfChildren").value);
	//alert("block_cal="+block_cal+" block_day="+block_day);
	if(block_cal == 1 || block_day == 1){
		document.getElementById("numOfChildren").value = ori_numOfChildren;
		document.getElementById("ori_numOfChildren").value = ori_numOfChildren;		
		alert("Please wait while the price is being calculated");
	}
	else{
		 var numOfChildren = document.getElementById("numOfChildren").value;	
		var numOfGuest = document.getElementById("numOfGuest").value;
		if(numOfGuest == "" || numOfGuest == "0"){
			numOfGuest = "1";				
		}
		if(notNum(numOfChildren)){
			alert("Please enter a number");
			document.getElementById("numOfChildren").value = "";
			document.getElementById("ori_numOfChildren").value = "";
			resetBPrice(parseInt(numOfGuest),0,num);
			getV(parseInt(numOfGuest));
			return;
		}
		if(numOfChildren == "0" ){
			resetBPrice(parseInt(numOfGuest),0,num);
			getV(parseInt(numOfGuest));
			return;
		}
		var total_num = parseInt(numOfGuest) + parseInt(numOfChildren);
		if( total_num > 40 ){
			alert("The number of people is > 40, Please contact us and we'll make a special itinerary for you");
			document.getElementById("numOfChildren").value = ori_numOfChildren;
			return;
		}		
		document.getElementById("ori_numOfChildren").value = numOfChildren;
		resetBPrice(parseInt(numOfGuest),parseInt(numOfChildren),num);
		getV(total_num);
	}
}

function resetBPrice(numOfGuest,numOfChildren,num){
	var bprice = 0;
	var bcost = 0;
	for(var i=1;i<=num;i++){
		var search_str = document.getElementById("chk_1ist_"+i).value;		
		var t_Array = search_str.split(",");
		for(var j=0;j<t_Array.length-1;j++){
			var item_str =t_Array[j];
			var i_name = item_str.substring(0, item_str.indexOf("_"));
			if(i_name!="city" && i_name!="group"){
				var pre_item = item_str.split("_");
				var v = pre_item[3];//price						
				var pre_b = pre_item[4];//base_price
				var pre_p = pre_item[5];//price
				var timesOfPrePrice = 1 + parseInt(pre_p)/100;
				bprice = bprice + parseInt(parseInt(v) * timesOfPrePrice) * (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(parseInt(pre_b) * timesOfPrePrice);
				bcost = bcost + parseInt(v) * (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(pre_b);
			}
		}
	}
	document.getElementById("bprice").value =	bprice;
	document.getElementById("bcost").value =	bcost;
}
function getV(str)
{	
	var xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="getV.php";
	var params="str="+str;
	params=params+"&sid="+Math.random();
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{	
			var v_str = xmlHttp.responseText;
			var v_id = v_str.substr(0,v_str.indexOf("_"));
			if(v_id==""){
				document.getElementById("v_cost").value = 0;
				document.getElementById("variable").value = 0;
				document.getElementById("v_profit").value = 0;
			}
			else{
				document.getElementById("v_profit").value = v_str.substr(v_str.lastIndexOf("_")+1);
				v_str = v_str.substr(0,v_str.lastIndexOf("_"));
				document.getElementById("v_cost").value = v_str.substr(v_str.indexOf("_")+1);
				document.getElementById("variable").value = v_id;
			}
			setPrice();
		} 		
	}
	xmlHttp.send(params);
}

function setPrice(){
	var ori_price		= parseInt(document.getElementById("ori_price").value);
	var ori_Uprice		= parseInt(document.getElementById("ori_Uprice").value);
	var guide_cost		= parseInt(document.getElementById("guide_cost").value);
	var v_cost			= parseInt(document.getElementById("v_cost").value);	
	var day_num			= parseInt(document.getElementById("templateNum").value);
	var guide_profit	= parseInt(document.getElementById("guide_min_profit").value);
	var vehicle_profit	= parseInt(document.getElementById("v_profit").value);
	var timesOfgprice	= (1+ guide_profit/100);
	var timesOfvprice	= (1+ vehicle_profit/100);
	document.getElementById("gprice").value = parseInt(guide_cost * timesOfgprice) * parseInt(day_num);
	document.getElementById("vprice").value = parseInt(v_cost * timesOfvprice) * parseInt(day_num);	
	var bprice			= parseInt(document.getElementById("bprice").value);
	var bcost			= parseInt(document.getElementById("bcost").value);
	var gprice			= parseInt(document.getElementById("gprice").value);
	var vprice			= parseInt(document.getElementById("vprice").value);
	//alert("bprice="+bprice+" gprice="+gprice+" vprice="+vprice);
	var numOfGuest = document.getElementById("numOfGuest").value;
	if(numOfGuest == "" || numOfGuest == "0"){
		numOfGuest = "1";				
	}
	var numOfChildren = document.getElementById("numOfChildren").value;
	if(numOfChildren == ""){
		numOfChildren = "0";				
	}	
	var children_discount = parseInt(document.getElementById("children_discount").value)/100;	
	// cost
	var total_guide_cost = parseInt(guide_cost) * parseInt(day_num);
	var total_v_cost = parseInt(v_cost) * parseInt(day_num);	
	if(bcost==0){
		total_guest_cost = 0;
	}
	var total_cost = bcost + total_guide_cost + total_v_cost
	var numOfGuestAndChildren = parseInt(numOfGuest)+parseInt(numOfChildren);
	var price_perAdult = parseInt((bprice+gprice+vprice) / parseInt(numOfGuestAndChildren));	
	var price_perChild = parseInt(price_perAdult * (1 - children_discount)) ;		
	var total_adult_price = price_perAdult * parseInt(numOfGuest);
	var total_children_price = price_perChild * parseInt(numOfChildren);
	var total_price = total_adult_price + total_children_price;
	//alert("price_perAdult="+price_perAdult+" price_perChild="+price_perChild+" total_adult_price="+total_adult_price + " total_children_price="+total_children_price);
	var total_discount = parseInt(document.getElementById("itinerary_discount").value)/100;
	var timesOftotal = (1-total_discount);
	total_price = parseInt(total_price * timesOftotal);
	//alert("after discount total_price="+total_price+" total_children_price="+total_children_price);
	//profit
	var total_profit = total_price - total_cost;
	//alert("after discount total_profit="+total_profit);
	var itinerary_min_profit = parseInt(document.getElementById("itinerary_min_profit").value)/100;
	var itinerary_min_profit_amount = parseInt(document.getElementById("itinerary_min_profit_amount").value);	
	var profit = parseInt(total_cost * itinerary_min_profit);

	if(total_profit < profit){
		if(total_profit < itinerary_min_profit_amount){
			//alert("---"+total_price);
			total_profit = itinerary_min_profit_amount;
			total_price = total_cost + total_profit;
			//alert(">>>"+total_price);
		}
	}
	else{
		if(total_profit < itinerary_min_profit_amount){
			//alert("---"+total_price);
			total_profit = itinerary_min_profit_amount;
			total_price = total_cost + total_profit;
			//alert(">>>"+total_price);
		}
	}	
	document.getElementById("price").innerHTML = total_price + " RMB";
	var currency = document.getElementById("currency").value;
	var rate = parseFloat(document.getElementById("rate").value);
	document.getElementById("Uprice").innerHTML = parseInt(total_price/rate) + " " +currency;
		
	//alert("total_price="+total_price+" ori_price="+ori_price);
	if(block_cal ==0){
		var rmb_plus = total_price - ori_price;
		var usd_plus = parseInt(total_price/rate) - ori_Uprice;
		if(rmb_plus>=0){
			document.getElementById("plus").innerHTML = 'Price changed by <br/>+ '+ rmb_plus +' RMB / '+ usd_plus +' '+currency;
		}
		if(rmb_plus<0){
			document.getElementById("plus").innerHTML = 'Price changed by <br/>'+ rmb_plus +' RMB / '+ usd_plus +' '+currency;
		}
		document.getElementById("ori_price").value = total_price;
		document.getElementById("ori_Uprice").value = parseInt(total_price/rate);
	}
	document.getElementById("total_cost").value = total_cost;
	document.getElementById("total_price").value = total_price;
	document.getElementById("totalPrice").value = total_price;
	document.getElementById("total_profit").value = parseInt(total_profit/total_price*100);
}
function resetPrice(suffix){
	var numOfGuest = document.getElementById("numOfGuest").value;
	if(numOfGuest == "" || numOfGuest == "0"){
		numOfGuest = "1";				
	}
	var tempStr = document.getElementById("chk_1ist"+suffix).value;
	var strArray = tempStr.split(",");
	var del_price = 0;
	var del_cost = 0;
	for(var i=0;i<strArray.length-1;i++){
		var item_str = strArray[i];
		var pre_name = item_str.substring(0, item_str.indexOf("_"));
		if(pre_name!="group" && pre_name!="city"){
			
			
			var pre_item = item_str.split("_");
			var v = pre_item[3];//price						
			var pre_b = pre_item[4];//base_price
			var pre_p = pre_item[5];//price			
			
			var timesOfPrePrice = 1 + parseInt(pre_p)/100;
			del_price = del_price + (parseInt(v) * timesOfPrePrice) * (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(parseInt(pre_b) * timesOfPrePrice);
			del_cost = del_cost + parseInt(v) * (parseInt(numOfGuest)+parseInt(numOfChildren)) + parseInt(pre_b);
		}
	}
	document.getElementById("bprice").value = parseInt(document.getElementById("bprice").value) - del_price ;
	document.getElementById("bcost").value = parseInt(document.getElementById("bcost").value) - del_cost ;
}
function addExtra(){
	var extra_html = '';
	//extra_html +='<div class="commonFont normalTxt whiteTxt bold floatLeft">Fill in this info at your leisure.  Build your tour below</div><br/>';
	//extra_html +='<br class="clearboth"/>';


	extra_html +='<div class="inputLabel1 commonFont normalTxt whiteTxt bold floatLeft" >Hotel name :</div>';
	extra_html +='<div><input type="text" id="hotelName" name="hotelName" class="itineraryInput"  maxlength = "32"></div>';
	extra_html +='<div class="inputLabel1 commonFont normalTxt whiteTxt bold floatLeft" >Hotel address :</div>';
	extra_html +='<div><input type="text" id="hotelAddress" name="hotelAddress" class="itineraryInput"  maxlength = "64"></div>';
	extra_html +='<div class="inputLabel1 commonFont normalTxt whiteTxt bold floatLeft" >Hotel phone 1 :</div>';
	extra_html +='<div><input type="text" id="hotelPhone1" name="hotelPhone1" class="itineraryInput"  maxlength = "32"></div>';

	
	extra_html +='<div class="inputLabel1 commonFont normalTxt whiteTxt bold floatLeft">Mobile phone :</div>';
	extra_html +='<div><input type="text" id="localMobile" name="localMobile" class="itineraryInput"  maxlength = "32"></div>';

	extra_html +='<div class="inputLabel1 commonFont normalTxt whiteTxt bold floatLeft" style="display:none">Pickup time :</div>';
	extra_html +='<div style="display:none"><input type="text" id="pickupTime" name="pickupTime" class="itineraryInput"  maxlength = "32"></div>';
	extra_html +='<div class="inputLabel1 commonFont normalTxt whiteTxt bold floatLeft"   style="display:none">Dropoff time :</div>';
	extra_html +='<div style="display:none"><input type="text" id="dropoffTime" name="dropoffTime" class="itineraryInput"  maxlength = "32"></div>';
	extra_html +='<div class="clearboth margin1" style="display:none">';		
	extra_html +='	<div class="inputLabel1 commonFont normalTxt whiteTxt bold floatLeft" >Airport pickup :</div>';
	extra_html +='	<div><input type="radio" id="airportPickupY" name="airportPickup" class="airportPickup" value="1" >Yes <input type="radio" id="airportPickupN" name="airportPickup" class="airportPickup" value="0" checked> No</div>';
	extra_html +='</div>';			
	extra_html +='<div class="clearboth margin1" style="display:none">';
	extra_html +='	<div class="inputLabel1 commonFont normalTxt whiteTxt bold floatLeft" >Airport dropoff :</div>';
	extra_html +='	<div><input type="radio" id="airportDropOffY" name="airportDropOff" class="airportDropOff" value="1" >Yes <input type="radio" id="airportDropOffN" name="airportDropOff" class="airportDropOff" value="0" checked> No</div>';
	extra_html +='</div>';			
	extra_html +='<div class="inputLabel1 commonFont normalTxt whiteTxt bold floatLeft" >Flight details :</div>';
	extra_html +='<div><textarea id="flightNotes" name="flightNotes" class="itineraryInput" rows="2" ></textarea></div>';


	extra_html +='<div class="inputLabel1 commonFont normalTxt whiteTxt bold floatLeft" >Notes or special requests :</div>';
	extra_html +='<div><textarea id="Notes" name="Notes" class="itineraryInput" rows="5" ></textarea></div>';	
	document.getElementById("extra_info").innerHTML = extra_html;
	document.getElementById("extra_info").style.display = "block";
	document.getElementById("extra_container").removeChild(document.getElementById("add_btn"));
}


function email_send(){	
	var agency_name			= document.getElementById("agency_name").value;
	var agency_logo			= encodeURIComponent(document.getElementById("agency_logo").value);
	var agency_website		= encodeURIComponent(document.getElementById("agency_website").value);
	var agency_info			= encodeURIComponent(document.getElementById("agency_info").value);
	var adults				= document.getElementById("adults").value;
	var children			= document.getElementById("children").value;
	var infants				= document.getElementById("infants").value;
	var payment				= encodeURIComponent(document.getElementById("payment").value);
	var inc					= encodeURIComponent(document.getElementById("inc").value);
	var agency_cancel		= encodeURIComponent(document.getElementById("agency_cancel").value);
	var extra_content		= encodeURIComponent(document.getElementById("extra_content").innerHTML);
	var activity_content	= encodeURIComponent(document.getElementById("activity_content").innerHTML);

	var from				= document.getElementById("from").value;
	var entry_email			= document.getElementById("email").value;	
	var subject				= document.getElementById("subject").value;	
	var email_header		= encodeURIComponent(WYSIWYG.getEditorWindow("email_header").document.body.innerHTML);



	
	
	
	
	var errorStr = "";
	if(!validateEmail(entry_email)){
		errorStr = errorStr + "* Please enter valid email " + "\n";
	}
	if(notValidName(subject)){
		errorStr = errorStr + "* Please enter subject " + "\n";
	}
	if(errorStr != ""){
		alert(errorStr);
	}
	else{	
		var xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="email_send.php";
		var params=	"agency_name="+agency_name+
					"&agency_logo="+agency_logo+
					"&agency_website="+agency_website+
					"&agency_info="+agency_info+
					"&adults="+adults+
					"&children="+children+
					"&infants="+infants+
					"&payment="+payment+
					"&inc="+inc+
					"&agency_cancel="+agency_cancel+
					"&extra_content="+extra_content+
					"&activity_content="+activity_content+
					"&from="+from+
					"&entry_email="+entry_email+
					"&subject="+subject+
					"&email_header="+email_header;
		params=params+"&sid="+Math.random();
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.onreadystatechange=function(){
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{
				alert(xmlHttp.responseText);
			} 		
		}
		xmlHttp.send(params);
	}
}
function comment_send(){
	var itinerary_id	= document.getElementById("itinerary_id").value;
	var customer_id		= document.getElementById("customer_id").value;
	var entry_email		= document.getElementById("entry_email").value;
	var toowner			= '0';
	if(document.getElementById("toowner").checked){
		toowner = '1';
	}
	var post_comments	= encodeURIComponent(WYSIWYG.getEditorWindow("post_comments").document.body.innerHTML);
	var errorStr = "";
	if(notValidName(post_comments) || post_comments == "%3Cbr%3E"){
		errorStr = errorStr + "* Please enter your comments " + "\n";
	}
	if(errorStr != ""){
		alert(errorStr);
	}
	else{	
		var xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="comments_out_process.php";
		var params="itinerary_id="+itinerary_id+"&customer_id="+customer_id+"&entry_email="+entry_email+"&toowner="+toowner+"&post_comments="+post_comments;
		params=params+"&sid="+Math.random();
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.onreadystatechange=function(){
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
				alert(xmlHttp.responseText)
		}
		xmlHttp.send(params);
	}
}


function out_func(str){
	alert("This will open in a new window. To save any changes you have made please press 'Save Itinerary'");
	document.itinerary_content.action = "out_func_process.php?func="+str;
	document.itinerary_content.method = "post";
	document.itinerary_content.target = "_blank"
	var allowSubmit = check_itinerary_form(document.itinerary_content);
	if(allowSubmit!=false){
		document.itinerary_content.submit();
	}
}