// JavaScript Document

function ValidateContactForm()
{
    var name = document.ContactForm.Name;
    var email = document.ContactForm.Email;
    var phone = document.ContactForm.Telephone;
    var nocall = document.ContactForm.DoNotCall;
    var what = document.ContactForm.Subject;
    var comment = document.ContactForm.Comment;

    if (name.value == "")
    {
        window.alert("Please enter your name.");
        name.focus();
        return false;
    }
    
    if (email.value == "")
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }
    if (email.value.indexOf("@", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }
    if (email.value.indexOf(".", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }

    /* if ((nocall.checked == false) && (phone.value == ""))
    {
        window.alert("Please enter your telephone number.");
        phone.focus();
        return false;
    }
	*/

    if (what.value == "")
    {
        alert("Please tell us how we can help you.");
        what.focus();
        return false;
    }

    if (comment.value == "")
    {
        window.alert("Please provide a detailed description or comment.");
        comment.focus();
        return false;
    }
    return true;
}

function ValidateContactForm2()
{
    var name = document.ContactForm.Name;
    var email = document.ContactForm.Email;
    var phone = document.ContactForm.Telephone;
    var nocall = document.ContactForm.DoNotCall;
    var what = document.ContactForm.Subject;
    var comment = document.ContactForm.Comment;

    if (name.value == "")
    {
        window.alert("Please enter your name.");
        name.focus();
        return false;
    }
    
    if (email.value == "")
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }
    if (email.value.indexOf("@", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }
    if (email.value.indexOf(".", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }
    /* if ((nocall.checked == false) && (phone.value == ""))
    {
        window.alert("Please enter your telephone number.");
        phone.focus();
        return false;
    }

    if (what.value == "")
    {
        alert("Please tell us how we can help you.");
        what.focus();
        return false;
    }

    if (comment.value == "")
    {
        window.alert("Please provide a detailed description or comment.");
        comment.focus();
        return false;
    }
	*/
    return true;
}

function EnableDisable(chkbx)
{
    if(chkbx.checked == true)
    {
        document.ContactForm.Telephone.disabled = true;
    }
    else
    {
        document.ContactForm.Telephone.disabled = false;
    }
}

function UpdateResume() 
{
	var thecontent = "";
	var report = "<br/>";
	
	thecontent = document.ContactForm.Name.value;
	
	if(thecontent!="") { report += "Name: " + thecontent + "<br />"; }

	thecontent = document.ContactForm.Telephone.value;
	if(thecontent!="") { report += "Telephone: " + thecontent + "<br />"; }

	thecontent = document.ContactForm.Email.value;
	if(thecontent!="") { report += "Email: " + thecontent + "<br />"; }

	thecontent = document.ContactForm.yarrival.value;
	if(thecontent!="") { report += "Arrival: " + thecontent + "<br />"; }

	thecontent = document.ContactForm.ydeparture.value;
	if(thecontent!="") { report += "Departure: " + thecontent + "<br />"; }

	thecontent = document.ContactForm.yroomtype.value;
	if(thecontent!="") { report += "Room: " + thecontent + "<br />"; }

	if(document.ContactForm.Smoking[0].checked==true) { report += "Smoking: non-smoking room." + "<br />"; } else { report += "Smoking: smoking room." + "<br />"; }	
	thecontent = document.ContactForm.ynumber.value;
	if(thecontent!="") { report += "Nr. of Persons: " + thecontent + "<br />"; }

	thecontent = document.ContactForm.yrequests.value;
	if(thecontent!="") { report += "Requests: " + thecontent + "<br />"; }

	UpdatePricing();
	
	document.getElementById("Resume").innerHTML = report;

	return;
}
function UpdatePricing() {
	var val = 1
	var output = "<pre>Room type:       "
  var price = 0
	var theval = document.ContactForm.yroomtype.value
	var totnet = 0
	var totsrv = 0
	var totvat = 0
	var tottot = 0

  if(theval=="Superior Room at 1,800 Baht ++") { 
	  price = 1800 
    output = output + "Superior" + "<br/>"
		output = output + "Price:           " + price + " per day<br/>"
	}
	else if(theval=="Deluxe Room at 2,600 Baht ++") { 
	  price = 2600
    output = output + "Deluxe" + "<br/>"
		output = output + "Price:           " + price + " per day<br/>"
	} 
	else if(theval=="Junior Suite at 3,200 Baht ++") {
		price = 3200
    output = output + "Junior Suite" + "<br/>"
		output = output + "Price:           " + price + " per day<br/>"
	} 
	else { 
	  price = 0
		output = " -- Not enough data for calculation -- "
		val = 0
	}
	var ONE_DAY = 1000 * 60 * 60 * 24
	var date1 = Date.parse(document.ContactForm.ydeparture.value)
	var date2 = Date.parse(document.ContactForm.yarrival.value)
  var difference_ms = Math.abs(date1 - date2)

  if(difference_ms<=0) { 
		output = " -- Please check date / date format -- "
		val = 0
	}
  var days = Math.round(difference_ms/ONE_DAY)
	output = output + "Number of days:  " + days + "<br/><br/>"
  totnet = price * days
  output = output + "Net price:       " + totnet + "<br/>"
	totsrv = totnet / 10
	output = output + "Service ch. 10%: " + totsrv + "<br/>"
	totvat = Math.round((totnet+totsrv) * .07)
	output = output + "VAT 7%:          " + totvat + "<br/>"
	tottot = totnet+totsrv+totvat
	output = output + "<b>Total:           " + tottot + "</b><br/></pre>"
	
	document.getElementById("Pricing").innerHTML = output
}

