function rs(n,u,w,h,x) {
	remote=window.open(u,n,'width='+w+',height='+h+',resizable=yes,scrollbars=yes,status=0');
	if (remote != null) {
		if (remote.opener == null )
		remote.opener = self;
		remote.location.href=u;
	}
	if (x==1){return remote;}
}

function isValidDate(dateStr) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		return false;
	}
	if (day < 1 || day > 31) {
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		return false
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			return false;
		}
	}
	return true;  // date is valid
}


function changeYear0(){
	var today = new Date()
	var day1 = new Date ((document.forms[0].depmm.selectedIndex+1) + "/"+ (document.forms[0].depdd.selectedIndex+1) +"/" + (document.forms[0].depyy.options[(document.forms[0].depyy.selectedIndex)].value))
	if (((day1 - today)/86400000 <0)) {
		document.forms[0].depyy.selectedIndex = 1
	}
	return
}

function changeYear1(){
	var today = new Date()
	var day1 = new Date ((document.forms[0].arrmm.selectedIndex+1) + "/"+ (document.forms[0].arrdd.selectedIndex+1) +"/" + (document.forms[0].arryy.options[(document.forms[0].arryy.selectedIndex)].value))
	if ((day1 - today)/86400000 <0) {
		document.forms[0].arryy.selectedIndex = 1
	}
}

function isNumeric(inputStr){
	for (var i = 0; i < inputStr.length; i++){
		var oneChar = inputStr.substring(i,i+1)
		if (oneChar < "0" || oneChar > "9"){
			return false
		}
	}
	return true
}
function isEmpty(inputStr) {
	if (inputStr == "" || inputStr == null) {
		return true
	}
	return false
}

function checkform(form){
	var today = new Date()

	var sDate0 = (form.depmm.selectedIndex+1) + "/" + (form.depdd.selectedIndex+1) + "/" + form.depyy.options[(form.depyy.selectedIndex)].value
	var sDate1 = (form.arrmm.selectedIndex+1) + "/" + (form.arrdd.selectedIndex+1) + "/" + form.arryy.options[(form.arryy.selectedIndex)].value

	if (isEmpty(form.name.value) || isEmpty(form.email.value) || isEmpty(form.phone.value)
 || isEmpty(form.pass_first0.value) || isEmpty(form.pass_last0.value)){
		alert ("Please enter your name, email address, your phone number and Passenger name(s).")
		return false;
	}else{
	
		if (!isEmpty(form.pass_age0.value) && !isEmpty(form.pass_inf0.value) || 
		    !isEmpty(form.pass_age1.value) && !isEmpty(form.pass_inf1.value) ||
		    !isEmpty(form.pass_age2.value) && !isEmpty(form.pass_inf2.value) ||	
		    !isEmpty(form.pass_age3.value) && !isEmpty(form.pass_inf3.value) ||
		    !isEmpty(form.pass_age4.value) && !isEmpty(form.pass_inf4.value) ||
		    !isEmpty(form.pass_age5.value) && !isEmpty(form.pass_inf5.value) )
			{
				alert ("Invalid input of child's age.")
				return false;
			}
		
		//alert(sDate0 + "\n" + sDate1)
		if (! (isValidDate( sDate0 ) && isValidDate(sDate1))){
			alert("Invalid date(s)")
			return false;
		}else{
			var DfromDate = new Date(sDate0)
			var DtoDate = new Date(sDate1)
			var dateDiff = ( (DtoDate - DfromDate) /86400000 )+1
			if (dateDiff < 1){
				alert("Invalid date sequency!")
				return false
			}
			var today = new Date()
			if (  (today - DfromDate) > 86400000   ){
				alert("Invalid date!")
				return false
			}
		}
	}
	return true;
}
function getSelectedRadio(buttonGroup){
	if (buttonGroup[0]) {
		for (var i=0; i<buttonGroup.length; i++) {
			if (buttonGroup[i].checked) {
            				return i
         			}
      		}
	} else {
		if (buttonGroup.checked) { return 0; } 
	}
	return -1;
}

function getSelectedRadioValue(buttonGroup) {
	var i = getSelectedRadio(buttonGroup);

	if (i == -1) {
		return -1;
	} else {
		if (buttonGroup[i]) { 
			return buttonGroup[i].value;
		} else { 
			return buttonGroup.value;
		}
	}
}


//(c) Tiglion Travel Services Company Limited 2006/12/14 module used by pkg.php, http://www.tiglion.com/package/pkg_main.htm


