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;
}

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 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;
}
//the function which does some magic to the date fields
// return non-zero if it is the last day of the month
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
        {
        Dt.options.selectedIndex=numDays - 1;
        //check for leap year
        if (numDays==29)
            {
            return 99;
            }
        else
            {
            return 1;
            }
        }
    }
if (Dt.options.selectedIndex + 1 < numDays)
    {
    value=0;
    }
else
    {
    if (Dt.options.selectedIndex + 1 > numDays)
        {
        Dt.options.selectedIndex--;
        value=3;
        }
    else
        {
        //index is 31 or 30
        value=2;
        }
    }
return value;
}

//changes departure month when arrival month is changed
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{
            outM.options.selectedIndex=inM.options.selectedIndex + 1;
           }
    }
else
    {
    outM.options.selectedIndex = inM.options.selectedIndex;
    outD.options.selectedIndex = inD.options.selectedIndex+1;
    }
return;
}

function dmddChange(outM,outD,inM,inD)
{
if (!isBrowserSupp())
    {
    return;
    }

adjustDate(outM.options.selectedIndex,outD);
if (((outM.options.selectedIndex < inM.options.selectedIndex) && (inM.options.selectedIndex != 11)) || ((outM.options.selectedIndex == inM.options.selectedIndex) && (outD.options.selectedIndex <= inD.options.selectedIndex)))
	{
		amadChange(inM,inD,outM,outD);
	}
return;
}

function chk()
           {
           var totalroom;
           var maxRooms ;
    	
 
 singalval = parseInt(document.frm_Search.singlesid.options[document.frm_Search.singlesid.selectedIndex].value);
 doubleval = parseInt(document.frm_Search.doublesid.options[document.frm_Search.doublesid.selectedIndex].value);
 twinval = parseInt(document.frm_Search.twinsid.options[document.frm_Search.twinsid.selectedIndex].value);
 tripleval = parseInt(document.frm_Search.tripleid.options[document.frm_Search.tripleid.selectedIndex].value);
 quadval = parseInt(document.frm_Search.quadid.options[document.frm_Search.quadid.selectedIndex].value);
 dblchd1val = parseInt(document.frm_Search.dblchld1.options[document.frm_Search.dblchld1.selectedIndex].value);
 dblchd2val = parseInt(document.frm_Search.dblchld2.options[document.frm_Search.dblchld2.selectedIndex].value); 
 
 maxRooms = 3;
 totalroom = singalval + doubleval + twinval + tripleval + quadval + dblchd1val + dblchd2val;
 

            
 if (totalroom > maxRooms)  {		
          alert("Total no. of rooms cannot be more than 3.");			
	
	return false;
	}
 if  (totalroom == 0)  {		
          alert("Please select the no. of room(s).");			
		
	return false;
	} 
        
	am=parseInt(document.frm_Search.am[document.frm_Search.am.selectedIndex].value);
	ad=parseInt(document.frm_Search.ad[document.frm_Search.ad.selectedIndex].value);
	yr=parseInt(document.frm_Search.yr[document.frm_Search.yr.selectedIndex].value);

	dm=parseInt(document.frm_Search.dm[document.frm_Search.dm.selectedIndex].value);
	dd=parseInt(document.frm_Search.dd[document.frm_Search.dd.selectedIndex].value);
	dyr=parseInt(document.frm_Search.dyr[document.frm_Search.dyr.selectedIndex].value);
		
	currday = parseInt(document.frm_Search.dayvar.value);
	currmonth = parseInt(document.frm_Search.monthvar.value);
	curryear = parseInt(document.frm_Search.yearvar.value);

	var arrDate = new Date(yr,am-1,ad);
	var depDate = new Date(dyr,dm-1,dd);
	var currDate = new Date(curryear,currmonth-1,currday);
	
	if (arrDate >= depDate)
	{
		alert("Date selection invalid");
		return false;
	}
	
	if(currDate >= arrDate)
	{
		alert("Date selection invalid");
		return false;
	}
	if (am < 9)
	{
		am="0"+am;
	}
	if (ad < 9) 
	{
		ad="0"+ad;
	}
	if (dm < 9) 
	{
		dm="0"+dm;
	}
	if (dd < 9) 
	{
		dd="0"+dd;
	}
	
	/* Date Difference function to validate the two days booking will no made during new year*/
	   date1 = new Date(yr,am-1,ad);
	   date2 = new Date(dyr,dm-1,dd); 
	   diff = new Date(); 
		diff.setTime(Math.abs(date1.getTime() - date2.getTime())); 
		timediff = diff.getTime(); 
		days = Math.floor(timediff / (1000 * 60 * 60 * 24));
   		timediff -= days * (1000 * 60 * 60 * 24);
		//alert(days);		
						
		if ((am == 12) && (ad >= 28) || (am == 1) && (ad <= 1))
		{
			if  (days < 3)
			{
			alert("For New Year's eve, a minimum hotel stay of 3 nights is required. Please re-select the dates.");
			return false;
			
		}	
		
		/*
		if (days > 15)
		{
			alert("Cannot Book More Than 15 Days");
			return false;
		}
		*/	
	}
    /* End Of Function*/
		
	arrDateStr = yr+"-"+am+"-"+ad;
	depDateStr = dyr+"-"+dm+"-"+dd;
	document.frm_Search.arrdate.value = arrDateStr;
	document.frm_Search.depdate.value = depDateStr;

	chkdblroom = dblchd1val + (dblchd2val * 2);
	
	if ( chkdblroom > 0 )
	{
		//alert(document.frm_Search.currency_sel.value);
		document.frm_Search.action = "result.asp";
		
	}	
	
	document.frm_Search.Submit.style.fontWeight="bold";
//	openPopup();
}

function changePriceRage(cmb_value)
{
if(cmb_value == "GBP") 
{
document.frm_Search.pricerange.options[0].value = "0";
document.frm_Search.pricerange.options[0].text = "ALL » ";
document.frm_Search.pricerange.options[1].value = "1";
document.frm_Search.pricerange.options[1].text = "Under £ 50 ";
document.frm_Search.pricerange.options[2].value = "2";
document.frm_Search.pricerange.options[2].text = "Between £ 50 and £ 70  ";
document.frm_Search.pricerange.options[3].value = "3";
document.frm_Search.pricerange.options[3].text = "Between £ 70 and £ 90  ";
document.frm_Search.pricerange.options[4].value = "4";
document.frm_Search.pricerange.options[4].text = "Between £ 90 and £ 110  ";
document.frm_Search.pricerange.options[5].value = "5";
document.frm_Search.pricerange.options[5].text = "£ 110 and over ";

}
else if(cmb_value == "USD") 
{
document.frm_Search.pricerange.options[0].value = "0";
document.frm_Search.pricerange.options[0].text = "ALL »  ";
document.frm_Search.pricerange.options[1].value = "1";
document.frm_Search.pricerange.options[1].text = "Under $ 90  ";
document.frm_Search.pricerange.options[2].value = "2";
document.frm_Search.pricerange.options[2].text = "Between $ 90 and $ 126  ";
document.frm_Search.pricerange.options[3].value = "3";
document.frm_Search.pricerange.options[3].text = "Between $ 126 and $ 162  ";
document.frm_Search.pricerange.options[4].value = "4";
document.frm_Search.pricerange.options[4].text = "Between $ 162 and $ 198  ";
document.frm_Search.pricerange.options[5].value = "5";
document.frm_Search.pricerange.options[5].text = "$ 198 and over ";

}
else if(cmb_value == "EURO") 
{

document.frm_Search.pricerange.options[0].value = "0";
document.frm_Search.pricerange.options[0].text = "ALL » ";
document.frm_Search.pricerange.options[1].value = "1";
document.frm_Search.pricerange.options[1].text = "Under &#8364; 73  ";
document.frm_Search.pricerange.options[2].value = "2";
document.frm_Search.pricerange.options[2].text = "Between &#8364; 73 and &#8364; 102  ";
document.frm_Search.pricerange.options[3].value = "3";
document.frm_Search.pricerange.options[3].text = "Between &#8364; 102 and &#8364; 131  ";
document.frm_Search.pricerange.options[4].value = "4";
document.frm_Search.pricerange.options[4].text = "Between &#8364; 131 and &#8364; 160  ";
document.frm_Search.pricerange.options[5].value = "5";
document.frm_Search.pricerange.options[5].text = "&#8364; 160 and over  ";

}

}
