// JavaScript Document
//Function change link to view default hotels in each country
function viewdefaulthotels(frm){
	if(frm.txtcountname.selectedIndex != 0){
		frm.action = 'defaulthotels.php?count=' + frm.txtcountname.options[frm.txtcountname.selectedIndex].value;
		frm.submit();
	}
	else{
		frm.action = 'defaulthotels.php';
		frm.submit();
	}
}

function viewHotel()
{
	with (window.document.frmListHotel) {
		if (cboCountry.selectedIndex == 0) {
			window.location.href = 'index.php';
		} else {
			window.location.href = 'index.php?count=' + cboCountry.options[cboCountry.selectedIndex].value;
		}
	}
}

function checkAddHotelForm()
{
	with (window.document.frmAddHotel) {
		/*
		if (txttourcat.selectedIndex == 0) {
			alert('Choose the package tours category');
			txttourcat.focus();
			return;
		} else if (isEmpty(txttourcode, 'Enter package tours code', true)) {
			return;
		} else if (isEmpty(txttourname, 'Enter package tours name', true)) {
			return;
		} else if (isEmpty(txttourdurat, 'Enter package tours duration', true)) {
			return;
		} else if (isEmpty(txttouritine, 'Enter package tours itineraries', true)) {
			return;
		} else if (isEmpty(txttourdescrpt, 'Enter package tours description', true)) {
			return;
		} else if (isEmpty(txttourothers, 'Enter package tours others', true)) {
			return;
		} else {
			txttourcode.value = trim(txttourcode.value);
			txttourname.value = trim(txttourname.value);
			txttourdurat.value = trim(txttourdurat.value);
			txttouritine.value = trim(txttouritine.value);
			txttourdescrpt.value = trim(txttourdescrpt.value);
			txttourothers.value = trim(txttourothers.value);
			submit();
		}
		*/
		
		if(txthotname.value == ""){
			alert("Please enter hotel name!");
			txthotname.focus();
			return;
		}
		else
			if(txthotdescrpt.value == ""){
				alert("Please enter hotel description!");
				txthotdescrpt.focus();
				return;
			}
			else
				if(txthotaddress.value == ""){
					alert("Please enter hotel address!");
					txthotaddress.focus();
					return;
				}
				else{
					if(txthotemail.value != ""){
						if(txthotemail.value.indexOf ('@',0) == -1 || txthotemail.value.indexOf ('.',0) == -1) {
							alert ("The Email field requires a \"@\" and a \".\" be used. \n\nPlease re-enter the Email address.")
							txtcustemail.select();
							txtcustemail.focus();
							return;
						}
					}				
					if(txthoturl.value != ""){
						if(txthoturl.value.indexOf ('http://',0) == -1 || txthoturl.value.indexOf ('.',0) == -1) {
							alert ("The URL field requires a \"http://\" and a \".\" be used. \n\nPlease re-enter the URL address.")
							txthoturl.select();
							txthoturl.focus();
							return;
						}
					}
					if(txthotloc.selectedIndex == 0){
						alert("Please select hotel location!");
						txthotloc.focus();
						return;
					}
					else
						if(txthotcat.selectedIndex == 0){
							alert("Please select hotel category!");
							txthotcat.focus();
							return;
						}
						else{
							txthotname.value = trim(txthotname.value);
							txthotdescrpt.value = trim(txthotdescrpt.value);
							txthotaddress.value = trim(txthotaddress.value);
							txthottelno.value = trim(txthottelno.value);
							txthotfaxno.value = trim(txthotfaxno.value);
							txthotemail.value = trim(txthotemail.value);
							txthoturl.value = trim(txthoturl.value);
							txthotnote.value = trim(txthotnote.value);
							txthotnumroom.value = trim(txthotnumroom.value);
							submit();
						}
					}
	}
}

function checkAddRoomForm()
{
	with (window.document.frmAddRoomHotel) {
		if(txtroomname.value == ""){
			alert("Please enter room category name!");
			txtroomname.focus();
			return;
		}
		else {
			txtroomname.value = trim(txtroomname.value);
			txtroomdescrpt.value = trim(txtroomdescrpt.value);
			submit();
		}
	}
}

function checkAddHotelRateForm()
{
	with (window.document.frmAddHotelRate) {
		if (s_day.selectedIndex == 0) {
			alert('Choose the start date');
			s_day.focus();
			return;
		} else if (s_mnth.selectedIndex == 0) {
			alert('Choose the start month');
			s_mnth.focus();
			return;
		} else if (s_year.selectedIndex == 0) {
			alert('Choose the start year');
			s_year.focus();
			return;
		} else if (e_day.selectedIndex == 0) {
			alert('Choose the end date');
			e_day.focus();
			return;
		} else if (e_mnth.selectedIndex == 0) {
			alert('Choose the ent month');
			e_mnth.focus();
			return;
		} else if (e_year.selectedIndex == 0) {
			alert('Choose the end year');
			e_year.focus();
			return;
		} else if (txtUserType.selectedIndex == 0) {
			alert('Choose the user type');
			txtUserType.focus();
			return;
		} else {
			submit();
		}
	}
}

function addHotel(locId,countId,pageNum)
{
	window.location.href = 'index.php?view=add&page='+ pageNum + '&count=' + countId + '&loc=' + locId;
}

function modifyHotel(hotId,locId,countId,pageNum)
{
	window.location.href = 'index.php?view=add&page=' + pageNum + '&count=' + countId + '&loc=' + locId + '&hot=' + hotId;
}

function deleteHotel(hotId, locId, pageNum)
{
	if (confirm('Delete this hotel?')) {
		window.location.href = 'processHotel.php?action=delete&page=' + pageNum + '&hot=' + hotId + '&loc=' + locId;
	}
}

function deleteHotelImage(hotId,imageId)
{
	if (confirm("Delete this image")) {
		window.location.href = "processHotel.php?action=deleteImage&hot=" + hotId + "&img=" + imageId;
	}
}

function deleteHotelPrice(hotId,priceId)
{
	if (confirm("Delete this price")) {
		window.location.href = "processHotel.php?action=deletePrice&hot=" + hotId + "&prc=" + priceId;
	}
}

function deleteHotelValidDate(hotId,validId)
{
	if (confirm("Delete this validation date")) {
		window.location.href = "processHotel.php?action=deleteDate&hot=" + hotId + "&valid=" + validId;
	}
}

function addRoom(hotId, locId,countId,pageNum)
{
	window.location.href = 'index.php?view=addroom&page='+ pageNum + '&count=' + countId + '&loc=' + locId + '&hot=' + hotId;
}

function modifyRoom(roomId, hotId,locId,countId,pageNum)
{
	window.location.href = 'index.php?view=addroom&page=' + pageNum + '&count=' + countId + '&loc=' + locId + '&hot=' + hotId + '&room=' + roomId;
}

function deleteRoom(roomId, hotId, locId, pageNum)
{
	if (confirm('Delete this room type?')) {
		window.location.href = 'processHotel.php?action=deleteroom&page=' + pageNum + '&room=' + roomId + '&hot=' + hotId + '&loc=' + locId;
	}
}