var bo = true;
var n , Lastn;
var FirstTDID;
var SecondTDID;
var LastFirstTDID;
var LastSecondTDID;
var NextA,ClearA,PrevA;
var TurnDayArray;
var ErrorMinStay,ErrorMaxStay;
var NextOrPrevious; //to know which button was clicked -1 if next and 1 if previos.

function InitializeCalender()
{	
	var CheckInDate , CheckOutDate , MonthDifference , CheckInDay , CheckOutDay
	
	FirstTDID = document.getElementById('FirstTDID').value;
	SecondTDID = document.getElementById('SecondTDID').value;
	//////////Adjust dates and offset after select alternative properies or iBookingResults(SP)(date search)////////////
	if (FirstTDID == "" && SecondTDID == "")
	{
		//Preload images
		if (document.images) 
		{
			imgPreLoad = new Image();
			imgPreLoad.src = "/Images/checkoutonly.gif";			
		}
		if (document.getElementById('CheckInDateTxt').value != "" && document.getElementById('CheckOutDateTxt').value != "")
		{
			/////////////Preparing dates////////////////////////////
			FirstTDID = "AvailTD_1";
			SecondTDID = "AvailTD_";
			CheckInDate = new Date(Date.parse(document.getElementById('CheckInDateTxt').value));
			CheckOutDate = new Date(Date.parse(document.getElementById('CheckOutDateTxt').value));
			
			CheckInDay = CheckInDate.getDate().toString();
			if (CheckInDay.length == "1")
			{CheckInDay = "0" + CheckInDay;}
			
			FirstTDID = FirstTDID + CheckInDay;
			CheckOutDay = CheckOutDate.getDate().toString();
			if (CheckOutDay.length == "1")
			{CheckOutDay = "0" + CheckOutDay;}
			MonthDifference = GetDateDiffrenceInMonth(CheckOutDate.toString(),CheckInDate.toString())
			SecondTDID = SecondTDID + (parseInt(MonthDifference) + 1) + CheckOutDay;
			/////////////Preparing offset////////////////////////////
			if (GetDateDiffrenceInMonth(CheckInDate.toString(),Date().toString()) > 0)
			{n = 1;}
		}
	}
	//////////////////////////////////////////////////////////////////
	LastFirstTDID = FirstTDID;
	LastSecondTDID = SecondTDID;	
	NextOrPrevious = document.getElementById('NextOrPrevious').value;

	if (n == null)
	{
		if (document.getElementById("offset").value == "")
		{n = 1;}
		else
		{n=parseInt(document.getElementById("offset").value);}
	}
	else
	{n = n+1;}
	document.getElementById("offset").value=n;
	HideShowPrev();		
	GetCalendar(n,vr_PropertyCode);
}

function GetDateDiffrenceInMonth(strBigDate , strSmallDate)
{
	var BigDate , SmallDate , YearDifference , MonthDifference
	
	BigDate = new Date(Date.parse(strBigDate));
	SmallDate = new Date(Date.parse(strSmallDate));
	
	YearDifference = BigDate.getFullYear() - SmallDate.getFullYear();
	MonthDifference = BigDate.getMonth() + YearDifference * 12 - SmallDate.getMonth();
	return parseInt(MonthDifference)
}
function GetCalendar(offset,propertyid)
{	
	document.getElementById("ClearA").style.display="none";
	document.getElementById("LoadDiv").style.display="";
	var rd = new Date()
	var r = document.location.toString()
	var requestUrl , port
	if ( location.port == "80" || location.port == "" )
	{port = "";}
	else
	{port = ":" + location.port;}
	if(r.indexOf('https')==-1)
	{requestUrl = 'http://' + document.domain + port + "/calendar.aspx?offset="+offset+"&propertyid="+propertyid+"&rd="+rd;}
	else
	{requestUrl = 'https://' + document.domain + port + "/calendar.aspx?offset="+offset+"&propertyid="+propertyid+"&rd="+rd;}	
		CreateXmlHttp();
	xmlhttp.onreadystatechange=CalendarReady
	xmlhttp.open("GET", requestUrl, true);
	xmlhttp.send(null);	
}

function CalendarReady()
{
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4)
	{
		// if "OK"
		if (xmlhttp.status==200)
		{
			var Calendar = document.getElementById("res1");	
			Calendar.innerHTML=xmlhttp.responseText;	
			document.getElementById("LoadDiv").style.display="none";			
			if (document.getElementById('CheckInDateTxt').value != "" && document.getElementById('CheckOutDateTxt').value != "")
			{setBackgroundColorForAllSelectedPeriod()}			
		}
		else
		{alert("Problem retrieving availability calender.");}
	}
}

function tdclick(td,thedate,MinStay,DOW,CheckInOnlyOrCheckOutOnly,Cal_MinStay,Cal_MaxStay,Cal_TurnDay)
{
/////////////////////////////////Start Handle Third Click//////////////////////////////////
	if(SecondTDID != "" && FirstTDID != "")
	{
		a1 = document.getElementById(FirstTDID).attributes["Date"].value;
		a2 = document.getElementById(SecondTDID).attributes["Date"].value;
		a3 = td.attributes["Date"].value;
		
		if(dateCompare(a3,a2) > 0)
		{			
			SecondTDID = "";	
			bo = false;
			tdclick(td,thedate,MinStay,DOW,CheckInOnlyOrCheckOutOnly,Cal_MinStay,Cal_MaxStay,Cal_TurnDay);
		}
		else if(dateCompare(a1,a3) > 0 && a1 != a2)
		{	
			FirstTDID = "";		
			bo = true;
			tdclick(td,thedate,MinStay,DOW,CheckInOnlyOrCheckOutOnly,Cal_MinStay,Cal_MaxStay,Cal_TurnDay);
		}
		else if(dateCompare(a1,a3) > 0 && a1 == a2)
		{
			if (td.title == "Check-Out-Only")
			{
				alert('This Day Is Check-Out-Only');
				return false;
			}
			else
			{
				ResetCheckInAndCheckOut()
				bo = true;
				tdclick(td,thedate,MinStay,DOW,CheckInOnlyOrCheckOutOnly,Cal_MinStay,Cal_MaxStay,Cal_TurnDay);
			}
		}
		else if(dateCompare(a3,a1) > 0 && dateCompare(a2,a3) > 0)
		{
			if(dateCompare(a3,a1) < dateCompare(a2,a3))
			{	
				FirstTDID = "";			
				bo = true;
				tdclick(td,thedate,MinStay,DOW,CheckInOnlyOrCheckOutOnly,Cal_MinStay,Cal_MaxStay,Cal_TurnDay);
			}
			else if(dateCompare(a3,a1) >= dateCompare(a2,a3))
			{			
				SecondTDID = "";	
				bo = false;
				tdclick(td,thedate,MinStay,DOW,CheckInOnlyOrCheckOutOnly,Cal_MinStay,Cal_MaxStay,Cal_TurnDay);
			}
		}				
		return false;
	}
/////////////////////////////////End Handle Third Click//////////////////////////////////
/////////////////////////////////Start Handle First Click//////////////////////////////////
	if (FirstTDID == td.id){return false;} // click on the same cell(date)
	if(bo)
	{
		FirstTDID=td.id;		
		if (CheckAvailability() == false)
		{FirstTDID = LastFirstTDID;}
		else 
		{
			if (CheckRules() == false)
			{		
				if (ErrorMinStay != "")
				{
					alert('This property requires a MINIMUM of  ' + ErrorMinStay + ' nights in order to book this property at this period. Please select alternative dates. ')
					FirstTDID = LastFirstTDID;
					checkcheckmouseout(td)
					return false;
				}
				else if (ErrorMaxStay != "")
				{
					alert('This property requires a MAXIMUM of  ' + ErrorMaxStay + ' nights in order to book this property at this period. Please select alternative dates. ')			
					FirstTDID = LastFirstTDID;
					checkcheckmouseout(td)
					return false;
				}				
			}
			else
			{
				if(CheckInOnlyOrCheckOutOnly == "CheckOutOnly")
				{
					alert('This Day Is Check-Out-Only');
					FirstTDID = LastFirstTDID;		
					return false;
				}
				TurnDayArray = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
				var CheckOutDate = document.getElementById('CheckOutDateTxt').value;

				if(Cal_TurnDay != TurnDayArray[DOW] && Cal_TurnDay != "-1"  && Cal_TurnDay != "Any")
				{
					alert('This Property requires [' + Cal_TurnDay + '] to be Check-In at this period.');
					FirstTDID=LastFirstTDID;
					checkcheckmouseout(td)
					return false;
				}
				
				
				document.getElementById('CheckInDateTxt').value = thedate;				
				document.getElementById('CheckInDiv').innerHTML = thedate;				
				bo = false
			}
		}
					
		document.getElementById("ClearA").style.display="";	
		if(SecondTDID == "")
		{
			SecondTDID = td.id;
			document.getElementById('CheckOutDateTxt').value = thedate;
			document.getElementById('CheckOutDiv').innerHTML = thedate;
		}
	}
/////////////////////////////////End Handle First Click//////////////////////////////////
	else
/////////////////////////////////Start Handle Second Click//////////////////////////////////
	{
		SecondTDID = td.id;		
		if (td.id.split("_")[1] <  FirstTDID.split("_")[1])
		{//If the second click before first click
			bo = true;
			ResetCheckInAndCheckOut();
			tdclick(td,thedate,MinStay,DOW,CheckInOnlyOrCheckOutOnly,Cal_MinStay,Cal_MaxStay,Cal_TurnDay);
			return false
		}
		if (CheckAvailability() == false)
		{SecondTDID = LastSecondTDID;}
		else
		{
			if (CheckRules() == false)
			{
				if (ErrorMinStay != "")
				{
					alert('This property requires a MINIMUM of  ' + ErrorMinStay + ' nights in order to book this property at this period. Please select alternative dates. ')
					SecondTDID = LastSecondTDID;
					checkcheckmouseout(td)
					return false;
				}
				else if (ErrorMaxStay != "")
				{
					alert('This property requires a MAXIMUM of  ' + ErrorMaxStay + ' nights in order to book this property at this period. Please select alternative dates. ')
					SecondTDID = LastSecondTDID;
					checkcheckmouseout(td)
					return false;
				}
			}
			else
			{				
				document.getElementById('CheckOutDateTxt').value = thedate;
				document.getElementById('CheckOutDiv').innerHTML = thedate;
				bo = true
			}
		}
	}
/////////////////////////////////End Handle Second Click//////////////////////////////////
///////////////////////////////Dates are valid//////////////////////////////////////////////
	NextOrPrevious = 0;
	setBackgroundColorForAllSelectedPeriod();
	document.getElementById('FirstTDID').value = FirstTDID;
	document.getElementById('SecondTDID').value = SecondTDID;	
	LastSecondTDID = SecondTDID;
	LastFirstTDID = FirstTDID;
}
//---------------Check Availability---------------------------
function CheckAvailability()
{
	var CheckInDayTD , CheckOutDayTD , CurrentTD , CheckInDay , CheckOutDay
	
	if(FirstTDID != "" && SecondTDID == "")
	{return true}
	CheckInDayTD = document.getElementById(FirstTDID);
	CheckOutDayTD = document.getElementById(SecondTDID);	
	
	CheckInDay = CheckInDayTD.attributes["Date"].value;
	CheckOutDay = CheckOutDayTD.attributes["Date"].value;	
	
	CurrentTD = CheckInDayTD
	
	while (CurrentTD != CheckOutDayTD)
	{
		if(CurrentTD.id.split("_")[0] == "NotAvailTD")
		{return false}
		else
		{CurrentTD = GetNextTD(CurrentTD)}
	}
	return true
}
//---------------Check Rules---------------------------
function CheckRules()
{
	var CheckInDayTD , CheckOutDayTD , CurrentTD , CheckInDay , CheckOutDay , Nights , MinStay , MaxStay	
	
	if(FirstTDID != "" && SecondTDID == "")
	{return true}
	CheckInDayTD = document.getElementById(FirstTDID);
	CheckOutDayTD = document.getElementById(SecondTDID);	
	
	CheckInDay = CheckInDayTD.attributes["Date"].value;
	CheckOutDay = CheckOutDayTD.attributes["Date"].value;	
	
	Nights = dateCompare(CheckOutDay,CheckInDay)	
	CurrentTD = CheckInDayTD
	
	while (CurrentTD != CheckOutDayTD)
	{
		MinStay = CurrentTD.attributes["MinStay"].value;
		MaxStay = CurrentTD.attributes["MaxStay"].value;	
		if(MinStay != "-1" && MinStay > Nights)
		{		
			ErrorMinStay = MinStay;
			ErrorMaxStay = "";
			return false
		}
		else if(MaxStay != "-1" && MaxStay < Nights)
		{		
			ErrorMinStay = "";
			ErrorMaxStay = MaxStay;
			return false
		}
		else
		{CurrentTD = GetNextTD(CurrentTD)}
	}
	return true
}
//-----------------------------------------------------
function GetNextTD(TD)
{
	var nextTD , part1 , part2 , MonthPos
	
	part1 = TD.id.split("_")[0];
	part2 = TD.id.split("_")[1];
	nextTD = document.getElementById(part1+"_"+(parseInt(part2)+1));
	if(!nextTD)
	{
		if (part1 == "AvailTD")
		{part1 = "NotAvailTD"}
		else if (part1 == "NotAvailTD")
		{part1 = "AvailTD"}
		nextTD = document.getElementById(part1+"_"+(parseInt(part2)+1));
		if(!nextTD)
		{
			MonthPos = TD.id.split("_")[1].slice(0,1);
			nextTD = document.getElementById(part1+"_"+(parseInt(MonthPos)+1)+"01");
			if(!nextTD)
			{
				if (part1 == "AvailTD")
				{part1 = "NotAvailTD"}
				else if (part1 == "NotAvailTD")
				{part1 = "AvailTD"}
				nextTD = document.getElementById(part1+"_"+(parseInt(MonthPos)+1)+"01");
				if(!nextTD)
				{return null}			
			}			
		}
	}	
	return nextTD
}
//-----------------------------------------------------
function setBackgroundColorForAllSelectedPeriod()
{
	var LastCheckInDayTD , LastCheckOutDayTD , CheckInDayTD , CheckOutDayTD , CurrentTD	
	
	if (LastFirstTDID != "" && LastSecondTDID != "")
	{		
		/////////////////////////////////////////////////		
		LastFirstTDID = AdjustTDidAfterNext(LastFirstTDID);
		LastSecondTDID = AdjustTDidAfterNext(LastSecondTDID);
		FirstTDID = AdjustTDidAfterNext(FirstTDID);
		SecondTDID = AdjustTDidAfterNext(SecondTDID);
		
		document.getElementById('FirstTDID').value = FirstTDID;
		document.getElementById('SecondTDID').value = SecondTDID;		
		/////////////////////////////////////////////////
		
		LastCheckInDayTD = document.getElementById(LastFirstTDID);
		LastCheckOutDayTD = document.getElementById(LastSecondTDID);	
		
		/////////////////////////////////////////////////
		if (!LastCheckInDayTD || ! LastCheckOutDayTD)
		{
			ResetCheckInAndCheckOut()
			return false;
		}
		else
		{document.getElementById("ClearA").style.display="";}
		/////////////////////////////////////////////////
		CurrentTD = LastCheckInDayTD;
		
		
		while (CurrentTD != LastCheckOutDayTD)
		{
			if (CurrentTD.attributes["Type"].value == "Check-In-Only" || CurrentTD.attributes["Type"].value == "Check-Out-Only")
			{CurrentTD.style.backgroundImage = "url('/Images/checkoutonly.gif')";}
			else
			{CurrentTD.style.backgroundColor = "#EFE9C7";}
			CurrentTD = GetNextTD(CurrentTD)			
		}
		if (LastCheckOutDayTD.attributes["Type"].value == "Check-In-Only" || LastCheckOutDayTD.attributes["Type"].value == "Check-Out-Only")
		{LastCheckOutDayTD.style.backgroundImage="url('/Images/checkoutonly.gif')";}
		else
		{LastCheckOutDayTD.style.backgroundColor = "#EFE9C7";}
	}
	
	CheckInDayTD = document.getElementById(FirstTDID);
	CheckOutDayTD = document.getElementById(SecondTDID);
	/////////////////////////////////////////////////
		if (!CheckInDayTD || ! CheckOutDayTD)
		{
			ResetCheckInAndCheckOut()	
			return false;
		}
		/////////////////////////////////////////////////
	CurrentTD = CheckInDayTD;
	
	
	while (CurrentTD != CheckOutDayTD)
	{
		if (CurrentTD.attributes["Type"].value == "Check-In-Only" || CurrentTD.attributes["Type"].value == "Check-Out-Only")
		{CurrentTD.style.backgroundImage = "url('/Images/checkoutonlygreen.gif')";}
		else
		{CurrentTD.style.backgroundColor = "#B4D500";}
		CurrentTD = GetNextTD(CurrentTD)			
	}	
	if (CheckOutDayTD.attributes["Type"].value == "Check-In-Only" || CheckOutDayTD.attributes["Type"].value == "Check-Out-Only")
	{CheckOutDayTD.style.backgroundImage = "url('/Images/checkoutonlygreen.gif')";}
	else
	{CheckOutDayTD.style.backgroundColor = "#B4D500";}
}
//-----------------------------------------------------
function AdjustTDidAfterNext(TDid)
{
	var part1 , part2 , CurrentMonthPos
	
	part1 = TDid.split("_")[0];
	part2 = TDid.split("_")[1];	
	
	CurrentMonthPos = part2.slice(0,1);
	CurrentMonthPos = parseInt(CurrentMonthPos) + NextOrPrevious;
		
	part2 = CurrentMonthPos + part2.substr(1)
	TDid = part1 + "_" + part2
	
	return TDid
}
//-----------------------------------------------------
function ResetCheckInAndCheckOut()
{
	var CurrentTD , CheckInDayTD , CheckOutDayTD
	try
	{
		if (FirstTDID != "" && SecondTDID != "")
		{
			CheckInDayTD = document.getElementById(FirstTDID);
			CheckOutDayTD = document.getElementById(SecondTDID);
			
			CurrentTD = CheckInDayTD;
			
			while (CurrentTD != CheckOutDayTD)
			{			
				if (CurrentTD.attributes["Type"].value == "Check-In-Only" || CurrentTD.attributes["Type"].value == "Check-Out-Only")
				{CurrentTD.style.backgroundImage = "url('/Images/checkoutonly.gif')";}
				else
				{CurrentTD.style.backgroundColor = "#EFE9C7";}
				CurrentTD = GetNextTD(CurrentTD)
			}
			if (CheckOutDayTD.attributes["Type"].value == "Check-In-Only" || CheckOutDayTD.attributes["Type"].value == "Check-Out-Only")
			{CheckOutDayTD.style.backgroundImage = "url('/Images/checkoutonly.gif')";}
			else
			{CheckOutDayTD.style.backgroundColor = "#EFE9C7";}
		}
	}
	catch (ex)
	{}
		
	document.getElementById('CheckOutDateTxt').value = "";
	document.getElementById('CheckInDateTxt').value = "";
	document.getElementById('CheckOutDiv').innerHTML = "";
	document.getElementById('CheckInDiv').innerHTML = "";
	document.getElementById('FirstTDID').value = "";	
	document.getElementById('SecondTDID').value = "";
	
	FirstTDID = "";
	SecondTDID = "";
	LastFirstTDID = "";
	LastSecondTDID = "";
	
	document.getElementById("ClearA").style.display = "none";
	
	bo = true;
}
//-----------------------------------------------------
function dateCompare(date1 , date2)
{
   date1 = new Date(Date.parse(date1)).getTime();
   date2 = new Date(Date.parse(date2)).getTime();
   datediff = date1 - date2;
   datediff = (datediff  /86400000);
   return datediff;
}
//-----------------------------------------------------
//Handle mouseover
function checkcheck(td)
{	
	if (td.attributes["Type"].value == "Check-In-Only" || td.attributes["Type"].value == "Check-Out-Only")
	{td.style.backgroundImage="url('/Images/checkoutonlygreen.gif')";}
	else
	{
		if(bo)
		{td.title = "Check-in";}
		else
		{td.title = "Check-out";}	
		td.style.backgroundColor = "#B4D500";
	}
}
//-----------------------------------------------------
//Handle mouseout
function checkcheckmouseout(td)
{ 
	var i , j , CheckInDayTD , CheckOutDayTD , CurrentTD
	
	if (FirstTDID != "" && SecondTDID != "")
	{	
		if(td.id == SecondTDID || td.id == FirstTDID)
		{return false;}		
		
		CheckInDayTD = document.getElementById(FirstTDID);
		CheckOutDayTD = document.getElementById(SecondTDID);
		
		CurrentTD = CheckInDayTD;
		
		while (CurrentTD != CheckOutDayTD)
		{
			if (td == CurrentTD)
			{return false}
			CurrentTD = GetNextTD(CurrentTD)			
		}
	}
	if (td.attributes["Type"].value == "Check-In-Only" || td.attributes["Type"].value == "Check-Out-Only")
	{td.style.backgroundImage = "url('/Images/checkoutonly.gif')";}
	else
	{td.style.backgroundColor = "#EFE9C7";}
}
//-----------------------------------------------------
function nextCal()
{
	if (n == null)
	{
		if (document.getElementById("offset").value == "")
		{
			n = 0;
			n = n + 1;
		}
		else
		{n = parseInt(document.getElementById("offset").value);}
	}
	else
	{n = n+1;}
	document.getElementById("offset").value = n;
	HideShowPrev();	
	NextOrPrevious = -1;
	GetCalendar(n,vr_PropertyCode);
}
//-----------------------------------------------------
function prevCal()
{	
	n = n - 1;
	document.getElementById("offset").value = n;
	HideShowPrev();	
	NextOrPrevious = 1;
	GetCalendar(n,vr_PropertyCode);
}
//-----------------------------------------------------
function HideShowPrev()
{
	if(n == 1)
	{document.getElementById('PrevA').style.display = 'none';}
	else
	{document.getElementById('PrevA').style.display = '';}
}
//-----------------------------------------------------
function validateinputs()
{
	var a = document.getElementById("CheckInDateTxt").value;
	var b = document.getElementById("CheckOutDateTxt").value;
	var now = new Date();
	if(a == "")
	{alert("Please select check-in date.");}
	else if(b == "")	
	{alert("Please select check-out date.");}
	else if(a == b)
	{alert("You can not CheckIn/CheckOut in the same day.");}
	else if (CheckRules() == false)
	{
		if (ErrorMinStay != "" && ErrorMaxStay == "")
		{alert('This property requires a MINIMUM of  ' + ErrorMinStay + ' nights in order to book this property at this period. Please select alternative dates.')}
		else
		{alert('This property requires a MAXIMUM of  ' + ErrorMaxStay + ' nights in order to book this property at this period. Please select alternative dates.')}
	}
	else if (CheckOccupants() == false)
	{alert("Number of occupants exceeds the limit for this property");}
	else
	{return true;}
	return false;
}
//-------------------Max Occupants--------------------------------
function CheckOccupants()
{
	var AdultsNum , ChildrenNum
	
	AdultsNum = document.getElementById("Adults").value;
	ChildrenNum = document.getElementById("Children").value;
	if(parseInt(vr_Sleeps) < parseInt(AdultsNum) + parseInt(ChildrenNum))
	{return false;}
}
//-------------------Maps Area--------------------------------
var map;
var selStyle; // a: Aerial , r: Road , h: Hybrid , o: Oblique
var selMode; // VEMapMode.Mode3D
var zoom; // 1-19
var fixed; // 1: no user control , 0: allow user control
var showSwitch;

function InitializeMap()
{
	map = null;
	selStyle = "r"; // a: Aerial , r: Road , h: Hybrid , o: Oblique
	selMode = VEMapMode.Mode2D; // VEMapMode.Mode3D
	zoom = 17; // 1-19
	fixed = 0; // 1: no user control , 0: allow user control
	showSwitch = 1;
}
	   
function GetMap()
{
    if (vr_PropertyLat != "" && vr_PropertyLon != "" && vr_PropertyLat != "0" && vr_PropertyLon != "0")
    {
    	try
    	{
    		map = new VEMap('myMap'); 
     		//var latLon = new VELatLong(36.13371559517861,-115.16238212585449); 
     		var latLon = new VELatLong(vr_PropertyLat,vr_PropertyLon); 
     		map.LoadMap(latLon, zoom, selStyle, fixed, selMode, showSwitch);
     		var pin = map.AddPushpin(map.GetCenter());
			pin.SetTitle(vr_PropertyTitle);
			pin.SetDescription(vr_CityName +', ' + vr_StateCode +',' + vr_PropertyTitle + ' ,PropertyID: ' + vr_PropertyCode + ' ,' + vr_Address);
    	}
    	catch(e){}
    }
}
//-----------------------------------------------------