	
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
	//alert(1);
var cityRequestObj;
var mBrowserType='windows';
function AddCityData()
{
//alert('hello--11111111');
var AT;
var x =0 ;
for (var i=0;i<document.w2stay.radiobutton1.length;i++) 
		{ 
			if (document.w2stay.radiobutton1[i].checked) 
			{ 
				AT = document.w2stay.radiobutton1[i].value;
				x =1 ;	
			}
		}
	AT = AT.trim();AT = AT.rtrim();AT = AT.ltrim();	
		if(x==1)
		{
		  var url = '/servlet/W2StaySendLoc?stateName=null&destinationName=null&accommType='+AT;
			//alert(url);
			sendCityRequest(url);
		}
		
		//alert(url);
}	
function sendCityRequest(url)
	{//alert(1);
		if(window.ActiveXObject)
		{
			cityRequestObj = new ActiveXObject('Microsoft.XMLHTTP');	
		}
		else
		{
			cityRequestObj = new XMLHttpRequest();
			mBrowserType = 'nonWindows';
		}
		//alert(2);
		if(cityRequestObj)
		{
			cityRequestObj.onreadystatechange = putCityData;
			cityRequestObj.open('get',url);
			try
			{
				if(mBrowserType == 'nonWindows')
				{
					cityRequestObj.send('');
				}
				else
				{
					cityRequestObj.send();
				}
			}
			catch(ex)
			{
				alert(ex);
			}
		}
	}
	function putCityData()
	{
		//alert('cityRequestObj.readyState:-> '+cityRequestObj.readyState);
		
		if(cityRequestObj.readyState == 4)
		{
			//alert('cityRequestObj.status:-> '+cityRequestObj.status);
			if(cityRequestObj.status == 200)
			{
				var serverResponse = cityRequestObj.responseText.split(',');				
				//alert('serverResponse:-> '+serverResponse);
				
				if(serverResponse=='noDataFound')
				{
					try
					{
						removeOption(document.getElementById('city'));
						//removeOption(document.getElementById('starValue'));
					}
					catch(ex)
					{
						alert('exception in removing Loc option');
						alert(ex);
					}
				}
				else
				{
					try
					{
						removeOption(document.getElementById('city'));
					}
					catch(ex)
					{
						alert('exception in removing Loc option');
						alert(ex);
					}
					for(var i=0;i<serverResponse.length;i++)
					{																														
						//alert('in for loop');
						var newEle;
							newEle = document.createElement('option');
							newEle.text = removeSpaces(serverResponse[i]);
							newEle.value = removeSpaces(serverResponse[i]);						
						try
						{	
							//document.getElementById('destination').add(newEle);
							if(mBrowserType=='windows')
							{
								document.getElementById('city').add(newEle);
							}
							else
							{
								var destinationComboObj = document.getElementById('city');
								destinationComboObj.add(newEle,null);
							}
						}						
						catch(ex)
						{
							//alert('ex:-> '+ex);
							break;
						}
					}					
				}								
			}
		}
	}

/*
function getStarType()
	{
		//alert('1');		
		var x =0 ;
		var CityName;
for (var i=0;i<document.w2stay.radiobutton1.length;i++) 
		{ 
			if (document.w2stay.radiobutton1[i].checked) 
			{ 
				AT = document.w2stay.radiobutton1[i].value;
				x =1 ;	
			}
		}
for (var i=0;i<document.w2stay.radiobutton2.length;i++) 
		{ 
			if (document.w2stay.radiobutton2[i].checked) 
			{ 
				CityName = document.w2stay.radiobutton2[i].value;
				//x =1 ;	
			}
		}	
		if((x==0))
		{
			alert('!!select accommType!! ');
			return 0;
		}	
		
		alert(2);	
		   CityName = CityName.trim();CityName = CityName.ltrim();CityName = CityName.rtrim();
		   alert('CityName-----------------------'+CityName);
		   if((CityName=='Other'))
		   {
		    CityName = document.getElementById('city').value;
		   }
		   if((CityName=='Select'))
		     {
			alert('!!select City Name!!');
			return 0;
		    }	
			var url = '/servlet/W2StaySendStarValue?stateName='+stateName+'&destinationName='+CityName+'&accommType='+AT;
			alert(url);
			sendStarRequest(url);
		//}
	}	
*/



function getStarType()
	{
		//alert('1');		
		var x =0 ;
		
		var x =0 ;
		var CityName;
for (var i=0;i<document.w2stay.radiobutton1.length;i++) 
		{ 
			if (document.w2stay.radiobutton1[i].checked) 
			{ 
				AT = document.w2stay.radiobutton1[i].value;
				x =1 ;	
			}
		}
/*for (var i=0;i<document.w2stay.radiobutton1.length;i++) 
		{ 
			if (document.w2stay.radiobutton1[i].checked) 
			{ 
				AT = document.w2stay.radiobutton1[i].value;
				x =1 ;	
			}
		}*/
		if(x==0||document.getElementById('city').value=='Select')
		{			
			try
			{
				//removeOption(document.getAccomInnerPageElementById('starValue'));
				removeOption(document.getElementById('city'));
			}
			catch(ex)
			{
				alert('exception in removing option');
				alert(ex);
			}			
			return 0;
		}
		else
		{	//alert(00);
		
	      CityName = document.getElementById('city').value;
		  CityName = CityName.trim();CityName = CityName.ltrim();CityName = CityName.rtrim();
		   if((CityName=='Select'))
		     {
			alert('!!select City Name!!');
			return 0;
		    }	
			var url = '/servlet/W2StaySendStarValue?stateName=null&destinationName='+CityName+'&accommType='+AT;
			//alert(url);
			sendStarRequest(url);
		}
	}	

var starTypeReqObj;
function sendStarRequest(url)
	{
		//alert(url);
		if(window.ActiveXObject)
		{
			starTypeReqObj = new ActiveXObject('Microsoft.XMLHTTP');
		}
		else
		{
			if(window.XMLHttpRequest)
			{
				starTypeReqObj = new XMLHttpRequest();
				mBrowserType = 'nonWindows';
			}
		}
		if(starTypeReqObj)
		{
			starTypeReqObj.onreadystatechange = putStarValue;
			starTypeReqObj.open('GET',url);
			if(mBrowserType == 'nonWindows')
			{
				starTypeReqObj.send('');
			}
			else
			{
				starTypeReqObj.send();
			}
		}
	}
	
	function putStarValue()
	{
		if(starTypeReqObj.readyState == 4)
		{
			if(starTypeReqObj.status == 200)
			{
				var serverResponse = starTypeReqObj.responseText.split(',');
				if(serverResponse=='noDataFound')
				{
					//removeOption(document.getElementById('Loc'));
					//removeOption(document.getElementById('starValue'));
				}
				else
				{
					//alert(serverResponse);
					var s3=0;
					var s4=0;
					var s5=0;
					var s7=0;
					var res;
					for(var i=0;i<serverResponse.length;i++)
					{
					  //alert(serverResponse[i]);
					  res = serverResponse[i];res=res.trim();res=res.rtrim();res=res.ltrim();
					 //alert('res'+res);
					  if(res=='7 Star')
					  {
		                s7 =1;	
						window.document.w2stay.radiobutton3[4].disabled=false;		  
					   ///alert('s7---->'+serverResponse[i]);
					  }
					  if(res=='5 Star')
					  {
					   s5=1;
					   window.document.w2stay.radiobutton3[3].disabled=false;	
					  //alert('s5--->'+serverResponse[i]);
					  }
					  if(res=='4 Star')
					  {
					  s4=1;
					  window.document.w2stay.radiobutton3[2].disabled=false;	
					  //alert('s4--->'+serverResponse[i]);
					  }
					  if(res=='3 Star')
					  {
					  s3=1;
					  window.document.w2stay.radiobutton3[1].disabled=false;
					  //alert('s3----->'+serverResponse[i]);
					  }
					 
					  
					}
					if(s7==0)
					   {
					      window.document.w2stay.radiobutton3[4].disabled="disabled";
					   }
					if(s5==0)
					   {
					      window.document.w2stay.radiobutton3[3].disabled="disabled";
					   }
					if(s4==0)
					   {
					      window.document.w2stay.radiobutton3[2].disabled="disabled";
					   }
					if(s3==0)
					   {
					      window.document.w2stay.radiobutton3[1].disabled="disabled";
					   }         
		
				}
				//alert('severResponse:-> '+serverResponse);				
			}
		}
	}

var AccoType;
var star;	
	
function submitData()
    {
    	var location;
       var x1=0;var x2=0;var x3=0;
		for (var i=0;i<document.w2stay.radiobutton1.length;i++) 
		{ 
			if (document.w2stay.radiobutton1[i].checked) 
			{ 
				AccoType = document.w2stay.radiobutton1[i].value;
				x1 =1 ;	
			}
		}
		
		
		for (var i=0;i<document.w2stay.radiobutton3.length;i++) 
		{ 
			if (document.w2stay.radiobutton3[i].checked) 
			{ 
				star = document.w2stay.radiobutton3[i].value;
				x3 =1 ;	
			}
		}
		if((x1==0))
		{
			alert('!!select accommType!! ');
			return 0;
		}
		//if((x2==0))
		//{
		//	alert('!!select Location!!');
		//	return 0;
		//}
		if((document.w2stay.city.value=='Select'))
			{
				alert('!!select Location!!');
				return 0;
			}
		if((x3==0))
		{
			alert('!!select Star Category!!');
			return 0;
		}
		
		//alert(AccoType);
		//alert("loc"+location);
		//alert(star);
		   // alert("locxxxxxxxx"+location);
		location = document.w2stay.city.value;
		/* if((location=='Select'))
		 {
			alert('!!select City Name!!');
			return 0;
		 }*/
		AccoType = AccoType.trim();AccoType = AccoType.ltrim();AccoType = AccoType.rtrim();
		location = location.trim();location = location.ltrim();location = location.rtrim();
		star = star.trim();star = star.ltrim();star = star.rtrim();
		var url='/servlet/W2StayResult?accommType='+AccoType+'&destinationName='+location+'&starValue='+star+'&stateName=null&HotelId=null';
		//var url='/servlet/W2StayResultTest?accommType='+AccoType+'&destinationName='+location+'&starValue='+star+'&stateName=null&HotelId=null';
		//window.open(url,'','scrollbars=yes,resizable=yes');
		//alert(1);
		//document.w2stay.submit();
		//location.replace(url);
		//location.replace('/servlet/W2StayResultTest?accommType='+AccoType+'&destinationName='+location+'&starValue='+star+'&stateName=null&HotelId=null');
		//document.w2stay.action=url;
		//alert(1);
		//document.w2stay.submit()
		//alert(2);
		//window.open(url,'','scrollbars=yes,resizable=yes');
                 //window.location.replace(url,'','');
              //// if (navigator.appName.indexOf("Microsoft Internet")==-1)
                // {
                      window.location.replace(url,'','');
                // }
             //else
              //  {
               //  window.open(url,'','scrollbars=yes,resizable=yes');
               // }
	
}	
function removeSpaces(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return'';
	}
	var v_length = VALUE.length;
	var strTemp = '';

	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
}
//   remove select tag option    ///
function removeOption(selectbox)
{
	//alert('removeOption function');
	var i;
	for(i=selectbox.options.length-1;i>0;i--)
	{
		selectbox.remove(i);
	}
}  	

