//--Submit email function
function NewsletterPopup() {
	 if(document.getElementById("txtEmail").value == "") {
		 alert("You must enter your email address");
		 window.focus();
		 document.getElementById("txtEmail").focus();
		 return;
	 }
	 if(new String(document.getElementById("txtEmail").value).indexOf("@") == -1) {
		 alert("You must first enter a valid email address");
		 window.focus();
		 document.getElementById("txtEmail").focus();
		 return;
	 }
	 if(new String(document.getElementById("txtEmail").value).indexOf(".") == -1) {
		 alert("You must first enter a valid email address");
		 window.focus();
		 document.getElementById("txtEmail").focus();
		 return;
	 }
	 window.open("sendmail.php?email=" + document.getElementById("txtEmail").value, null, "left=" + (screen.availWidth/2-225) + ",top=" + (screen.availHeight/2-150) + ",height=300,width=450,location=no,menubar=no,resizable=no,toolbar=no");
}
//------------------------------------




function changeroom()
{
    var roomnum = document.getElementById("ddlroom").value;
    var adultnum = document.getElementById("ddladult").value
    
    roomnum = parseInt(roomnum);
    adultnum = parseInt(adultnum);
    
    if(roomnum > adultnum)
    {
        document.getElementById("ddladult").selectedIndex = (roomnum - 1);
    }
}

function changeadult()
{
    var roomnum = document.getElementById("ddlroom").value;
    var adultnum = document.getElementById("ddladult").value
    
    roomnum = parseInt(roomnum);
    adultnum = parseInt(adultnum);
    
    if(adultnum < roomnum)
    {
        document.getElementById("ddlroom").selectedIndex = (adultnum - 1);
    }
}

function submitform()
{
    if(document.getElementById("txtcalendarin").value != "" && document.getElementById("txtcalendarout").value != "" && document.getElementById("ddlroom").value != "" && document.getElementById("ddladult").value != "" && document.getElementById("ddlchild").value != "")
    { 
        /*var dayin = document.getElementById("txtcalendarin").value;
        var dayout = document.getElementById("txtcalendarout").value;
        var night = document.getElementById("ddlnight").value;
        
        inday = dayin.substring(8,10);
        
        var dayoutcount = parseInt(inday) + parseInt(night);
        var dayout;
        
        //merge string to send
        if(dayoutcount < 10)
        {
            dayout = dayin.substring(0,7) + '-' + '0' + dayoutcount;
        }
        else
        {
            dayout = dayin.substring(0,7) + '-'  + dayoutcount;
        }*/
        
        var url = "https://reservation.travelanium.net/propertyibe/?propertyId=SRTRJP&onlineId=6677423181" + 
			"&checkin=" + document.getElementById("txtcalendarin").value + 
			"&checkout=" + document.getElementById("txtcalendarout").value + 
			"&numofroom=" + document.getElementById("ddlroom").value + 
			"&numofadult=" + document.getElementById("ddladult").value + 
			"&numofchild=" + document.getElementById("ddlchild").value;
        //parent.location.href = url;
		window.open(url,'bookingEngineWindow');
		return false;
    } else {
	    alert("Please select your preferred Check-in date, Check-out date, Number of room, Number of adult, and Number of child for your stay");
    }
	return false;
}
