var uid;
var rid;
var errorAirport;
var noDate = 0;
var errorDateLength;
        function CheckForm()
        {
			if(!noDate && !CheckDate())
			{
				alert(errorDateLength);
				return false;
			}
			if (document.getElementById("radioS_1") != null)
				if (document.getElementById("radioS_1").checked)
				{
					document.searchForm.submit();
					return true;
				}
			request = new HttpRequest(window);
        	if (!request) 
		        return false;
      	//request.setEndPoint("/mptest2/Validation.aspx");
     	//request.setEndPoint("/Validation.aspx");
      	request.setEndPoint("http://www.hotels.su/newDes/eng/bookhotels_new.php?type=valid");
        	body = createBody();
			if (body == false)
				return false;
	        request.load(body, false);	        
        	responseXML = request.getXML();
        	return parseResponse(responseXML);
			if (result)
				document.searchForm.submit();
        }
        
        function createBody()
        {
	        airports = document.getElementsByName("airportCode");
			if (airports.length > 0)
			{
		        find = false;
		        for (i = 0; i < airports.length; i++)
					if (airports[i].checked) 
					{
						airportCode = airports[i].value;
						find = true;
					}
				if (!find)
				{
					alert(errorAirport);
					//document.getElementById("errorMsg").innerHTML = errorAirport;
					return false;
				}
				body = "type=valid&airportCode=" + airportCode;
				body += "&uid=" + uid;
				body += "&rid=" + rid;
			}
			else
			{
				city   = document.getElementById("city");
				cityId = document.getElementById("cityId");
				body = "type=valid";
				if (cityId != null && cityId.value != "")
					body += "&cityId=" + cityId.value;			
				else if (city != null)
					body += "&city=" + city.value;			
		        dtIn = document.getElementById("dtIn");
				if (dtIn != null)
					body += "&dtIn=" + dtIn.value;
		        mnIn = document.getElementById("mnIn");
				if (mnIn != null)
					body += "&mnIn=" + mnIn.value;
		        dtOut = document.getElementById("dtOut");
				if (dtOut != null)
					body += "&dtOut=" + dtOut.value;
		        mnOut = document.getElementById("mnOut");
				if (mnOut != null)
					body += "&mnOut=" + mnOut.value;
		        nights = document.getElementById("nights");
				if (nights != null)
					body += "&nights=" + nights.value;
		        numberOfAdults = document.getElementById("adults");
				if (numberOfAdults != null)
					body += "&NumberOfAdults=" + numberOfAdults.value;
				numberOfRooms = document.getElementById("rooms");
				if (numberOfRooms != null)
					body += "&NumberOfRooms=" + numberOfRooms.value;
				numberOfChildren = document.getElementById("children");
				if (numberOfChildren != null)
					body += "&NumberOfChildren=" + numberOfChildren.value;
				numberOfBeds = document.getElementById("beds");
				if (numberOfBeds != null)
					body += "&NumberOfBeds=" + numberOfBeds.value;				
		        airport = document.getElementById("nearAirport");
				if (airport != null)
				{
					nearAirport = (airport.checked) ? document.getElementById("nearAirport").value : '';
					body += "&nearAirport=" + nearAirport;
				}
				
				nameHotel = document.getElementById("propName");
				if (nameHotel != null)
			        body += "&propName=" + nameHotel.value;
		        adressHotel = document.getElementById("propAdress");
				if (adressHotel != null)
			        body += "&propAdress=" + adressHotel.value;
					
		        minRate = document.getElementById("minRate");
				if (minRate != null)
			        body += "&minRate=" + minRate.value;				
		        maxRate = document.getElementById("maxRate");
				if (maxRate != null)
			        body += "&maxRate=" + maxRate.value;
					
				chains = document.getElementById("chains");
				if (chains != null)
				{
		            for (i = 0; i < chains.options.length; i++)
		                if (chains.options[i].selected == true && chains.options[i].value != 10001)
			                body += "&chains=" + chains.options[i].value;
				}
				amenities = document.getElementsByName("amenities");
				for (i = 0; i < amenities.length; i++)
					if (amenities[i].checked)
						body += "&amenities=" + amenities[i].value;
		        sort = document.getElementById("sort");
				if (sort != null)
			        body += "&sort=" + sort.value;				
		        rateSearchType = document.getElementById("rateSearchType");
				if (rateSearchType != null)
			        body += "&rateSearchType=" + rateSearchType.value;				
			}
	        return body;
        }
        
        function parseResponse(xml)
        {
            response = xml.getElementsByTagName("Response");
            if (response[0].getAttribute("status") == "Success")
            {
        	    setFormAction(xml);
        	    return true;
        	}
        	else
        	{
        	    printError(xml);            	    
        	    return false;
        	}
        }
        function setFormAction(xml)
        {
            rid    = getValueNode(xml, "rid");
            action = getValueNode(xml, "action");
            uid    = getValueNode(xml, "uid");
            pid    = getValueNode(xml, "pid");
            sort   = getValueNode(xml, "sort");
            sForm = document.getElementById("searchForm");
				
            sForm.action = "http://www.hotels.su/newDes/eng/bookhotels_new.php?action=" + action + "&pid=" + pid + "&uid=" + escape(uid) + "&rid=" + escape(rid) + "&sort=" + escape(sort);
//            sForm.submit();
        }
        
        function getValueNode(xml, node)
        {
            nodeXml = xml.getElementsByTagName(node);
            return nodeXml[0].childNodes[0].nodeValue;
        }
        
        function printError(xml)
        {
			alert(getValueNode(xml, "Error"));
            //document.getElementById("errorMsg").innerHTML = getValueNode(xml, "Error") + "<br/><br/>";
        }

