function setDefaultDate(aform,offset)
{
//	offset = 6;
	listStartYear = 2004;

	date = new Date();
	date.setDate(date.getDate() + offset);
	dToCheck = date.getDate();
	mToCheck = date.getMonth()+1;
	yToCheck = date.getFullYear();
	setSelectValue(aform.CheckinDateDay, dToCheck);
	setSelectValue(aform.CheckinDateMonth, mToCheck);
	setSelectValue(aform.CheckinDateYear, yToCheck);
	setOutDate(aform);
}

function setOutDate(aform)
{
	offsetCheckout = 2;

	dToCheck = aform.CheckinDateDay.options[aform.CheckinDateDay.selectedIndex].value;
	mToCheck = aform.CheckinDateMonth.options[aform.CheckinDateMonth.selectedIndex].value;
	yToCheck = aform.CheckinDateYear.options[aform.CheckinDateYear.selectedIndex].value;
	date = new Date(yToCheck, mToCheck-1, dToCheck);
	date.setDate(date.getDate() + offsetCheckout);

	dToCheck = aform.CheckoutDateDay.options[aform.CheckoutDateDay.selectedIndex].value;
	mToCheck = aform.CheckoutDateMonth.options[aform.CheckoutDateMonth.selectedIndex].value;
	yToCheck = aform.CheckoutDateYear.options[aform.CheckoutDateYear.selectedIndex].value;

    if (!isNaN(dToCheck) && !isNaN(mToCheck) && !isNaN(yToCheck))
    {
        oldOutDate = new Date(yToCheck, mToCheck-1, dToCheck);

        if (oldOutDate.valueOf() < date.valueOf())
        {
            dToCheck = date.getDate();
            mToCheck = date.getMonth()+1;
            yToCheck = date.getFullYear();
            setSelectValue(aform.CheckoutDateDay, dToCheck);
            setSelectValue(aform.CheckoutDateMonth, mToCheck);
            setSelectValue(aform.CheckoutDateYear, yToCheck);
        }
    }
    else
    {
        dToCheck = date.getDate();
        mToCheck = date.getMonth()+1;
        yToCheck = date.getFullYear();
        setSelectValue(aform.CheckoutDateDay, dToCheck);
        setSelectValue(aform.CheckoutDateMonth, mToCheck);
        setSelectValue(aform.CheckoutDateYear, yToCheck);
    }
}
/*function setOutDate(aform)
{
	offsetCheckout = 2;
	dToCheck = aform.CheckinDateDay.options[aform.CheckinDateDay.selectedIndex].value;
	mToCheck = aform.CheckinDateMonth.options[aform.CheckinDateMonth.selectedIndex].value;
	yToCheck = aform.CheckinDateYear.options[aform.CheckinDateYear.selectedIndex].value;
	date = new Date(yToCheck, mToCheck-1, dToCheck);
	date.setDate(date.getDate() + offsetCheckout);
	dToCheck = date.getDate();
	mToCheck = date.getMonth()+1;
	yToCheck = date.getFullYear();
	setSelectValue(aform.CheckoutDateDay, dToCheck);
	setSelectValue(aform.CheckoutDateMonth, mToCheck);
	setSelectValue(aform.CheckoutDateYear, yToCheck);
}*/

function setSelectValue(obj, val)
{
	for (var i = 0; i < obj.options.length; i++) {
		if (obj.options[i].value == val)
		{
			obj.selectedIndex = i;
			break;
		}
	}
}

function validateDate(aform)
{
	var obj;
	sd = aform.CheckinDateDay.options[aform.CheckinDateDay.selectedIndex].value;
	sm = aform.CheckinDateMonth.options[aform.CheckinDateMonth.selectedIndex].value;
	sy = aform.CheckinDateYear.options[aform.CheckinDateYear.selectedIndex].value;
	indate = new Date(sy, sm-1, sd);

	ed = aform.CheckoutDateDay.options[aform.CheckoutDateDay.selectedIndex].value;
	em = aform.CheckoutDateMonth.options[aform.CheckoutDateMonth.selectedIndex].value;
	ey = aform.CheckoutDateYear.options[aform.CheckoutDateYear.selectedIndex].value;
	odate = new Date(ey, em-1, ed)
	
	if ( odate <= indate ) {
		alert("Invalid check-out date.");
		return false;
	}

	cdate = new Date();
	if ( indate < cdate ) {
		alert("Invalid check-in date.");
		return false;
	}
	if ( aform.CityCode.value == '' )
	{
		alert("Please select your city");
		return false;
	}

	if ( aform.SingleRooms.selectedIndex == 0 && aform.TwinRooms.selectedIndex == 0 && aform.DoubleRooms.selectedIndex == 0 && aform.TripleRooms.selectedIndex == 0 )
	{
		alert("At lease one room must be specified");
		return false;
	}

	return true;
}

/**********************************************************************/ 
/*Function name :isDigit(theDigit) */ 
/*Usage of this function :test for an digit */ 
/*Input parameter required:thedata=string for test whether is digit */ 
/*Return value :if is digit,return true */ 
/* else return false */ 
/**********************************************************************/ 
function isDigit(theDigit) 
{ 
	var digitArray = new Array('0','1','2','3','4','5','6','7','8','9'),j; 

	for (j = 0; j < digitArray.length; j++) 
	{
		if (theDigit == digitArray[j]) 
			return true 
	} 
	return false 
} 
/*************************************************************************/ 
/*Function name :isPositiveInteger(theString) */ 
/*Usage of this function :test for an +ve integer */ 
/*Input parameter required:thedata=string for test whether is +ve integer*/ 
/*Return value :if is +ve integer,return true */ 
/* else return false */ 
/*function require :isDigit */ 
/*************************************************************************/ 
function isPositiveInteger(theString) 
{ 
	var theData = new String(theString) 

	if (!isDigit(theData.charAt(0))) 
	if (!(theData.charAt(0)== '+')) 
		return false 

	for (var i = 1; i < theData.length; i++) 
		if (!isDigit(theData.charAt(i))) 
			return false 
	return true 
} 
/**********************************************************************/ 
/*Function name :isDate(s,f) */ 
/*Usage of this function :To check s is a valid format */ 
/*Input parameter required:s=input string */ 
/* f=input string format */ 
/* =1,in mm/dd/yyyy format */ 
/* else in dd/mm/yyyy */ 
/*Return value :if is a valid date return 1 */ 
/* else return 0 */ 
/*Function required :isPositiveInteger() */ 
/**********************************************************************/ 
function isDate(s,f) 
{
	var a1=s.split("/"); 
	var a2=s.split("-"); 
	var e=true; 
	if ((a1.length!=3) && (a2.length!=3)) 
	{ 
		e=false; 
	} 
	else 
	{
		if (a1.length==3) 
			var na=a1; 
		if (a2.length==3) 
			var na=a2; 
		if (isPositiveInteger(na[0]) && isPositiveInteger(na[1]) && isPositiveInteger(na[2])) 
		{ 
			if (f==1) 
			{
				var d=na[1],m=na[0]; 
			} 
			else 
			{
				var d=na[0],m=na[1]; 
			} 
			var y=na[2]; 
			if (((e) && (y<1000)||y.length>4)) 
				e=false 
			if (e) 
			{ 
				v=new Date(m+"/"+d+"/"+y); 
				if (v.getMonth()!=m-1) 
					e=false; 
			} 
		} 
		else 
		{ 
			e=false; 
		} 
	} 
	return e 
} 
