function makeDays(month,inout){
if (month== "Month"){var dayno=0}
if (inout==1){var g=1;}else{var g=4;}
if (month== "Feb"){dayno=29;}
else{if (month=="Apr"||month=="Jun"||month=="Sep"||month=="Nov"){dayno=30;}
else{dayno=31;}}
if (month== "Month"){var dayno=0}
for (i=1;i<=31;i++){
if (i<=dayno){
document.book.elements[g].options[i].text=i;
document.book.elements[g].options[i].value=i;}
else{
document.book.elements[g].options[i].text="--";
document.book.elements[g].options[i].value="Day";
}}
}
function makePrice(category){
var month=document.book.Month1[document.book.Month1.selectedIndex].value;
if (month=="Month"){alert("Sorry, you forgot to select the month");document.book.Category.selectedIndex=0;document.book.Month1.focus();return false;}
var price;
for (i=0;i<myCat.length;i++){if (category==myCat[i]){for (j=stamon;j<=endmon;j++){if (month==myMonth[j]){price=lowPrice[i];j=endmon}else{price=myPrice[i]}}}}
document.book.Price.value=price;
}
function calculatehotel(){
if(document.book.elements[0].value=="Feb" & document.book.elements[1].value==29 & (document.book.elements[2].value!=2012 & document.book.elements[2].value!=2016))
{alert("Sorry, "+ document.book.elements[2].value+" is not a leap year\n"+ document.book.elements[0].value + ". " + document.book.elements[1].value);
document.book.elements[1].focus();return false;}
if(document.book.elements[3].value=="Feb" & document.book.elements[4].value==29 & (document.book.elements[5].value!=2012 & document.book.elements[5].value!=2016))
{alert("Sorry, "+ document.book.elements[5].value+" is not a leap year\n"+ document.book.elements[3].value + ". " + document.book.elements[5].value);
document.book.elements[4].focus();return false;}
var check= new Array("Month","Day","Year","Month","Day","Year","Category");
var date= new Array;
for (i=0;i<=6;i++){if (document.book.elements[i].value==check[i]){alert("Sorry, you forgot to select the "+check[i]);document.book.elements[i].focus();return false;}}
for (i=0;i<=3;i++){date[i]= new Date(document.book.elements[i+2].value,document.book.elements[i].selectedIndex-1,document.book.elements[i+1].value);}
var intime=(date[0].getTime()/ 1000);
var outtime=(date[3].getTime()/ 1000);
var today=new Date();
var timenow=(today.getTime()/ 1000);
if (intime < (timenow+172800)){alert("Sorry, the date must be at least 3 days\nfrom the day you submit the order");return false}
if (outtime<=intime){alert("Sorry, the check out date must be later than the check in date");return false}
document.book.Nights.value=(outtime-intime)/86400;
document.book.Baht.value=document.book.Price.value*(outtime-intime)/86400;
document.book.Foreign.value=Math.ceil(document.book.Price.value*(outtime-intime)/86400/document.book.ExchangeRate.value);
return true}
function booking(){
if (calculatehotel()==true){
for (i=7;i<=19;i++){if (document.book.elements[i].value==""){alert("Sorry, you forgot to enter the "+document.book.elements[i].name);document.book.elements[i].focus();return false;}if (i==8){i=13}}
document.book.submit();}
}

function reloadCAPTCHA() {


document.getElementById('CAPTCHA').src='/cgi-bin/captcha.cgi?randomnumber?'+Date();
;
}

function writebegfor(){
var anf="<h2 class='chiangmai'>To make a room reservation please complete the form below:<br><small>Payment on check-out!</small></h2><p>(*) = not required; &nbsp;  (~) = readonly</p><div align='center'><center><form method='post' name='book' action='/cgi-bin/check-captcha-book.cgi'><table width='95%'>";
return anf;
}
function writedates(){
var back="";
for (j=1;j<=2;j++){
var selmon="";
var selday="";
if (j==1){var einin="<tr><td class='ce'>Check-in date: ";var ein="document.book.Category.selectedIndex=0,document.book.Price.value=\"\","}
if (j==2){var einin="<td class='ce'>Check-out date: ";ein="";}
var einmon="<select name='Month"+j+"' size='1' onChange='"+ein+"makeDays(document.book.Month"+j+".options[document.book.Month"+j+".selectedIndex].value,"+j+")'><option value='Month'>Month</option>";
for (i=1;i<=12;i++){selmon=selmon+"<option value='"+myMonth[i]+"'>"+myMonth[i]+"</option>\n";}
var endsel="</select>&nbsp;";
var einday="<select name='Day"+j+"' size='1'><option value='Day'>Day</option>";
for (i=1;i<=31;i++){selday=selday+"<option value='Day'></option>\n";}
var einyear="<select name='Year"+j+"' size='1'><option value='Year'>Year</option><option value='2011'>2011</option><option value='2012'>2012</option></select></td>";
back=back+einin+einmon+selmon+endsel+einday+selday+endsel+einyear;}
return back+"</tr>";
}
function writeForm(page){
var loc= new Array("Select","Airport","Railway Station","Bus Station");
var pickup="";
for (i=0;i<=3;i++){pickup=pickup+"<option value='"+loc[i]+"'>"+loc[i]+"</option>";}
var cat="<tr><td class='ce'>Category: <select name='Category' size='1' onChange='makePrice(document.book.Category[document.book.Category.selectedIndex].value)'>";
for (i=0;i<myCat.length;i++){cat=cat+"<option value='"+myCat[i]+"'>"+myCat[i]+"</option>";}
cat=cat+"</select>&nbsp;&nbsp;";
var more1="Rooms: <input type='text' name='NoOfRooms' size='2' value='1'></td><td class='ce'>*Exchange Rate: Baht / Your Currency: <input type=text name='ExchangeRate' size='5' value='1'></td></tr><tr><td colspan='2' align='right'>Don't know the exchange rate of Thai Baht to your currency? <a href='../chiang_mai/currency.shtml'><b>Click Here!</b></a></td></tr><tr><td class='ce'>~Price: Baht/night: <input type='text' name='Price' size='5' readonly></td><td class='ce'>~Nights: <input type=text name='Nights' size='2' readonly></td></tr>";
var more2="<tr><td class='ce'>~Amount: Baht: <input type='text' name='Baht' size='5' readonly></td><td class='ce'>~Your Currency: <input type='text' name='Foreign' size='5' readonly></td></tr><tr><td class='ri' colspan='2'>Click to calculate the total amount in Thai Baht and Your Currency: <INPUT class='button' onClick='calculatehotel()' TYPE='button' VALUE='Calculate'></td></tr>";
var more3="<tr><td class='ce'>First Name: <input type='text' name='FirstName' size='30'></td><td class='ce'>Last Name: <input type='text' name='LastName' size='30'></td></tr><tr><td colspan='2' class='ce'>Street Address: <input type='text' name='Street' size='60'></td></tr><tr><td class='ce'>City: <input type='text' name='City' size='30'></td><td class='ce'>Postal Code: <input type='text' name='PostalCode' size='30'></td></tr>";
var more4="<tr><td class='ce'>Country: <input type='text' name='Country' size='30'></td><td class='ce'>*Email: <input type='text' name='Email' size='30'></td></tr><tr><td class='ce'>*Tel: <input type='text' name='Tel' size='30'></td><td class='ce'>*Fax: <input type='text' name='Fax' size='30'></td></tr>";
var more5="<tr><td class='ce'>*Pick up at <input type='text' name='Time' size='5'> hours</td><td class='ce'>*at the <select name='Location' size='1'>"+pickup+"</select></td></tr><tr><td colspan='2' class='ce'>Message: <input type='text' name='Message' size='70'></td></tr></table>";
var more6="<p><input type='hidden' name='Owner' Value='"+page+"'></table></center></div><img class='CAPTCHA' id='CAPTCHA' src=\"/cgi-bin/captcha.cgi?$randomnumber\"> <input type=\"text\" size=\"20\" name=\"verifytext\"> <input type='button' value='Make Room Reservation' class='button' onClick='booking()'> <INPUT NAME='Get new Image' onClick='reloadCAPTCHA()' TYPE='button' VALUE='Get new Image' class='button'><br>Enter the text of the image and click \"Make Room Reservation\"</p></form>";
var back=cat+more1+more2+more3+more4+more5+more6;
return back
}
