var numSelHot = 0;

function checkCity()
{
	if (document.f.city.value == "" || document.f.city.value == "null")
	{
	  setCountryCode(valueOfCodeAutoComplete(_highlightedSuggestionDiv));
  	  setCityNameEn(valueOfCityEnAutoComplete(_highlightedSuggestionDiv));
	}
	if (document.f.city.value == "" || document.f.city.value == "null")
	{
		alert("The Incorrect city name!")
		return false;
	}
	document.f.submit();
	return true;
}

function clickOther(doc)
{
	var totalChecked = 0;
	for (var i = 0; i < doc.form.elements.length; i++)
	{
		if (doc.form.elements[i].name == "facil")
		{
			if (doc.form.elements[i].checked)
			{
				totalChecked++;
			}
		}
	}
	if (totalChecked > 3)
	{
		doc.checked = false;
		alert("You cannot select more than three Facilities. Please uncheck a Facility before checking a different one.");
	}
	return;
}

function showNew(obj)
{
	if (obj.checked)
	{
		numSelHot++;
		frmN.thisSelPCodes.value = frmN.thisSelPCodes.value + obj.value + ' ';
		//alert(frmN.thisSelPCodes.value);
	}
	
	else
	{
		numSelHot = numSelHot - 1;
		frmN.thisSelPCodes.value = frmN.thisSelPCodes.value.replace(obj.value + ' ', '');
		//alert(frmN.thisSelPCodes.value);
	}

if (numSelHot == 0)	
{
	document.all["numSelHot"].innerHTML = "";
	document.all["numSelHot"].innerText = "";
	document.getElementById('compareHotels').style.display = 'none';
	document.all["numSelHot1"].innerHTML = "";
	document.all["numSelHot1"].innerText = "";
	document.getElementById('compareHotels1').style.display = 'none';
}
else
{
	document.all["numSelHot"].innerHTML = "View & Compare " + numSelHot + " selected hotel(s)";
	document.all["numSelHot"].innerText = "View & Compare " + numSelHot + " selected hotel(s)";
	document.getElementById('compareHotels').style.display = 'block';
	document.all["numSelHot1"].innerHTML = "View & Compare " + numSelHot + " selected hotel(s)";
	document.all["numSelHot1"].innerText = "View & Compare " + numSelHot + " selected hotel(s)";
	document.getElementById('compareHotels1').style.display = 'block';
}

}


function showNew1(obj)
{
	if (obj.checked)
	{
		numSelHot--;
		//frmN.thisSelPCodes.value = frmN.thisSelPCodes.value + obj.value + ' ';
		//alert(frmN.thisSelPCodes.value);
	}
	
	else
	{
		numSelHot = numSelHot + 1;
		//frmN.thisSelPCodes.value = frmN.thisSelPCodes.value.replace(obj.value + ' ', '');
		//alert(frmN.thisSelPCodes.value);
	}

if (numSelHot == 0)	
{
	document.all["numSelHot"].innerHTML = "";
	document.all["numSelHot"].innerText = "";
	document.getElementById('compareHotels').style.display = 'none';
	document.all["numSelHot1"].innerHTML = "";
	document.all["numSelHot1"].innerText = "";
	document.getElementById('compareHotels1').style.display = 'none';
}
else
{
	document.all["numSelHot"].innerHTML = "View & Compare " + numSelHot + " selected hotel(s)";
	document.all["numSelHot"].innerText = "View & Compare " + numSelHot + " selected hotel(s)";
	document.getElementById('compareHotels').style.display = 'block';
	document.all["numSelHot1"].innerHTML = "View & Compare " + numSelHot + " selected hotel(s)";
	document.all["numSelHot1"].innerText = "View & Compare " + numSelHot + " selected hotel(s)";
	document.getElementById('compareHotels1').style.display = 'block';
}

}


function citySelect(cCode, sCode, cName)

{

	frm1.countryCode.value = cCode;
	frm1.stateCode.value = sCode;
	if (cName.length != 0)
		frm1.city.value = cName;
}

function fromSel(cityName, stateCode, countryCode)
{
	document.searchForm.city.value = cityName;
	document.searchForm.stateCode.value = stateCode;
	document.searchForm.countryCode.value = countryCode;
}

function clearAmenity(count)
{
	for (i = 0; i <	 count; i++)
		document.searchForm.amenities.item(i).checked = false;
}

function show_hide()
{
	document.getElementById('layer1').style.visibility = 'hidden';
	document.getElementById('layer1').style.display = 'none';
	document.getElementById('layer2').style.display = 'block';
	document.getElementById('layer2').style.visibility = 'visible';
}


function setNameAirport(airName)
{
	document.searchForm.airportName.value = airName;
}


function warning()
{
	if (frm1.nearAirport.checked)
	{
		frm1.amenities.item(0).checked = true;
		clearAmenity(10);
		frm1.propName.value = '';
		alert('Note! When searching for hotels near an airport you will not be able to use the Optional Fields section.');
	}
}

function warningAdv()
{
	if (frm1.nearAirport.checked)
	{
		frm1.amenities.item(0).checked = true;
		clearAmenity(10);
		frm1.propName.value = '';
		frm1.propAdress.value = '';
		frm1.chains.item(0).selected = true;
		j = frm1.chains.length;
		for (i = 1; i < j; i++)
		{
			frm1.chains.item(i).selected = false;
		}
		alert('Note! When searching for hotels near an airport you will not be able to use the Optional Fields section.');
	}
}

function checkCompare(numSelect)
{
if (typeof mainForm.thisSelPCodes == "undefined") {
	return;
	}
	j = mainForm.thisSelPCodes.length;
	//numSelHot = 0;
	numSelHot = numSelect;

if (mainForm.thisSelPCodes.value == "noScript")
{

}
else
{
	for (i = 0; i < j; i++)
	{
		if (mainForm.thisSelPCodes[i].checked)
		{
			numSelHot++;
		}
	}

	if (numSelHot == 0)	
	{
		document.all["numSelHot"].innerHTML = "";
		document.all["numSelHot"].innerText = "";
		document.getElementById('compareHotels').style.display = 'none';
		document.all["numSelHot1"].innerHTML = "";
		document.all["numSelHot1"].innerText = "";
		document.getElementById('compareHotels1').style.display = 'none';
	}
	else
	{
		document.all["numSelHot"].innerHTML = "View & Compare " + numSelHot + " selected hotel(s)";
		document.all["numSelHot"].innerText = "View & Compare " + numSelHot + " selected hotel(s)";
		document.getElementById('compareHotels').style.display = 'block';
		document.all["numSelHot1"].innerHTML = "View & Compare " + numSelHot + " selected hotel(s)";
		document.all["numSelHot1"].innerText = "View & Compare " + numSelHot + " selected hotel(s)";
		document.getElementById('compareHotels1').style.display = 'block';
	}
}
}


function checkCompare1(numSelect)
{
	j = mainForm.thisSelPCodes.length;
	//numSelHot = 0;
	numSelHot = numSelect;

if (mainForm.thisSelPCodes.value == "noScript")
{

}
else
{
	for (i = 0; i < j; i++)
	{
		if (mainForm.thisSelPCodes[i].checked)
		{
			numSelHot--;
		}
	}

	if (numSelHot == 0)	
	{
		document.all["numSelHot"].innerHTML = "";
		document.all["numSelHot"].innerText = "";
		document.getElementById('compareHotels').style.display = 'none';
		document.all["numSelHot1"].innerHTML = "";
		document.all["numSelHot1"].innerText = "";
		document.getElementById('compareHotels1').style.display = 'none';
	}
	else
	{
		document.all["numSelHot"].innerHTML = "You've selected " + numSelHot + " hotel(s)";
		document.all["numSelHot"].innerText = "You've selected " + numSelHot + " hotel(s)";
		document.getElementById('compareHotels').style.display = 'block';
		document.all["numSelHot1"].innerHTML = "You've selected " + numSelHot + " hotel(s)";
		document.all["numSelHot1"].innerText = "You've selected " + numSelHot + " hotel(s)";
		document.getElementById('compareHotels1').style.display = 'block';
	}
}
}


function clickThis(pc, action)
{	
	document.mainForm.action = '?action=' + action + '&uid=' + uid + '&rid=' + rid;
	pcElem = NBGetElementById("pc");
	if (pcElem != null)
		pcElem.value = pc;
	document.mainForm.submit();
}

function NBGetElementById(element_id)
{
	var elems = document.getElementsByName(element_id);
	for (i = 0; i < elems.length; i++)
		if (elems[i].id == element_id)
			return elems[i];
	return document.getElementById(element_id);
}

function whoRadio(cur_radio)
{
	action       = cur_radio.getAttribute('value')
	cur_form     = document.getElementById('searchForm');
	cur_form.setAttribute ('action', '?action=' + action);
}

//FOR MAIN FORM
function clearInput() 
{
	var city = document.getElementById("city").value;
	
	if (city == defaultWordInput)
		document.getElementById("city").value = "";
}

//START DATE SCRIPT
function getDaysInMonth( mthIdx, YrStr ) {
	// all the rest have 31
	var maxDays = 31
	// expect Feb. (of course)
	if( mthIdx == 1 ) {
		if( isLeapYear( YrStr ) ) {
			maxDays=29;
		} else {
			maxDays=28;
		}
	}

	// thirty days hath...
	if( mthIdx == 3 || mthIdx == 5 || mthIdx == 8 || mthIdx == 10 ) {
		maxDays=30;
	}
	return maxDays;
}
    
function isLeapYear( yrStr ) {
    var leapYear = false;
    var year = parseInt( yrStr, 10 );
    // every fourth year is a leap year
    if ( year % 4 == 0 ) {
        leapYear = true;
        // unless it's a multiple of 100
        if( year % 100 == 0 ) {
            leapYear = false;
            // unless it's a multiple of 400
            if( year % 400 == 0 ) {
                leapYear=true;
            }
        }
    }
    return leapYear;
}

function CheckDate()
{	
	
	var dtIn  = parseInt(document.getElementById("dtIn").value);
	var dtOut = parseInt(document.getElementById("dtOut").value);
	var mnIn  = document.getElementById("mnIn").value - 1;
	var mnOut = document.getElementById("mnOut").value - 1;

	var today = new Date();
	var theYear = parseInt( today.getYear(), 10 );
	var YearIn  = theYear;
	var YearOut = theYear;
	var mthToday = today.getMonth();
	var days_duration = 0;
	if(mthToday > mnOut ){
		YearOut = theYear + 1;
	}
	if(mthToday > mnIn ){
		YearIn  = theYear + 1;
		YearOut = theYear + 1;
	}
	
	var numDays = getDaysInMonth( mnIn, YearIn );
	if(YearIn == YearOut)
	{	
		if(mnOut == mnIn)
		{
			days_duration = dtOut - dtIn;
			if(days_duration > 29) return false 
		}		
		else	
		{		
			if((mnOut - mnIn) == 1)
			{
				days_duration = numDays - dtIn + dtOut;
				if(days_duration > 29) return false 
			}
			
			else	
			{					
				return false 
			}
		}
	}
	else 	
	{
		if(mnOut == mnIn)
		{
			return false 
		}
		if((mnIn - mnOut) == 11)
		{
			days_duration = 31 - dtIn + dtOut;
			if(days_duration > 29) return false 
		}
		else
		{
			return false 
		}
	}
	return true;
}

function setTodayDate()
{
	var d = new Date();
	var dtIn = document.getElementById("dtIn");
	if (dtIn != null && typeof(dtIn) != 'undefined')
	{
		var mnIn = document.getElementById("mnIn");
		if (mnIn)
		{
			date31 = d.getDate();
			if (date31 >= 31)
			{
				date31 = 1;
				dtIn.options.selectedIndex = 0;
				if(d.getMonth() != 11)
				{
					mnIn.options.selectedIndex = d.getMonth()+1;
				}
				else
				{
					mnIn.options.selectedIndex = 0;
				}
				//dmddChange( mnIn, dtIn )
				amadChange(document.searchForm.mnIn, document.searchForm.dtIn, document.searchForm.mnOut, document.searchForm.dtOut);
			}
			else
			{
				dtIn.options.selectedIndex = date31;
				mnIn.options.selectedIndex = d.getMonth();
				dmddChange( mnIn, dtIn );
				if (document.searchForm.mnOut != null && typeof(document.searchForm.mnOut) != 'undefined')
					amadChange(document.searchForm.mnIn, document.searchForm.dtIn, document.searchForm.mnOut, document.searchForm.dtOut);
			}
		}
	}
}

//changes departure month when arrival month is changed
       function adjustDate( mthIdx, Dt ) {
        var value = 0;

        var today = new Date()
        var theYear = parseInt( today.getYear(), 10 )
        if( mthIdx < today.getMonth() ) {
            theYear = ( parseInt( today.getYear(), 10 ) + 1 )
        }
        if( theYear < 100 ) {
            theYear = "19" + theYear
        } else {
            if( ( theYear - 100 ) < 10 ) {
                theYear = "0" + ( theYear - 100 )
            } else {
                theYear = ( theYear - 100 ) + ""
            }
            theYear = "20" + theYear
        }

        var numDays = getDaysInMonth( mthIdx, theYear );
        if( mthIdx == 1 ) {
            if( Dt.options.selectedIndex + 1 < numDays ) {
                return 0;
            } else {
                if( Dt.options.selectedIndex + 1 > numDays) {
                    Dt.options.selectedIndex=numDays - 1;
                }
                //check for leap year
                if( (Dt.options.selectedIndex + 1) == numDays ) {
                    return 1;
                } else {
                    return 4;
                }
            }
        }
        if( Dt.options.selectedIndex + 1 < numDays ) {
            value = 0;
        } else {
            if ( Dt.options.selectedIndex + 1 > numDays ) {
                Dt.options.selectedIndex--;
                value = 3;
            } else if ( Dt.options.selectedIndex + 1 == numDays ) {
                //index is 31 or 30
                value = 2;
            } else {
                value = 4;
            }
        }
        return value;
    }
	
 function amadChange( inM, inD, outM, outD ) 
	{
        if ( !isBrowserSupp() ) 
		{
            return;
        }
        var res = adjustDate( inM.options.selectedIndex, inD );
        if( res != 0 ) 
		{
               outD.options.selectedIndex = 0;
               if ( inM.options.selectedIndex == 11 ) 
			   {
                    outM.options.selectedIndex = 0
               } 
			   else if( res == 4 ) 
			   {
                    outM.options.selectedIndex=inM.options.selectedIndex + 1;
                    outD.options.selectedIndex = 0;
               } 
			   else 
			   {
                    outM.options.selectedIndex=inM.options.selectedIndex + 1;
                    outD.options.selectedIndex = 0;
               }
        } 
		else 
		{
            outM.options.selectedIndex = inM.options.selectedIndex;
          	outD.options.selectedIndex = inD.options.selectedIndex + 1;
        }
        return;
    }


    function dmddChange( outM, outD ) {
        if ( !isBrowserSupp() ) {
            return;
        }

        adjustDate( outM.options.selectedIndex, outD );
        return;
    }
    //script date        
    //start new script code
    // Checks if browser is Netscape 2.0x since the options array properties don't work with Netscape 2.0x
    function isBrowserSupp() {
        // Get the version of the browser
        version =  parseFloat( navigator.appVersion );

        if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
            return false;
        } else {
            return true;
        }

        return true;
    }
