function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function SubmitForm(form_name)
{
    if (form_name == "reservations")
    {   
        /*var startDate = new Date(document.forms[0].year.value, (parseInt(document.forms[0].month.value,10) - 1), document.forms[0].day.value);
        var oneDay = 24*60*60*1000;
        var endDate = new Date(startDate.valueOf() + (parseInt(document.forms[0].nights.value,10) * oneDay));
        var endYear = endDate.getFullYear();
        var endMonth = endDate.getMonth() + 1;
        if (endMonth < 10)
        {
            endMonth = '0' + endMonth;
        }
        var endDay = endDate.getDate();
        if (endDay < 10)
        {
            endDay = '0' + endDay;
        }*/
        //window.location.href = "laplaya_reservations.aspx?INDATE_YM=" + document.forms[0].year.value + ":" + document.forms[0].month.value + "&INDATE_DD=" + document.forms[0].day.value + "&OUTDATE_YM=" + endYear + ":" + endMonth + "&OUTDATE_DD=" + endDay + "&ADULTS=" + document.forms[0].adults.value;
        window.location.href = "laplaya_reservations.aspx";
        return;
    }
    
    if (form_name == "offers")
    {
        //window.location.href = "laplaya_offers.aspx?email=" + document.forms[0].offers_email.value;
        window.location.href = "laplaya_offers.aspx";
        return;
    }

    if (form_name == "giftcertificate")
    {
        if (document.forms[0].OILB_EMAIL.value.length == 0)
        {
            alert("email address is required");
            return false;
        }
        if (!isEmail(document.forms[0].OILB_EMAIL.value))
        {
            alert("email address is invalid");
            return false;
        }
        //window.location.href = "laplaya_offers.aspx?email=" + document.forms[0].offers_email.value;
        return;
    }

    if (form_name == "travelpro")
    {
        if (document.forms[0].OILB_EMAIL.value.length == 0)
        {
            alert("email address is required");
            return false;
        }
        if (!isEmail(document.forms[0].OILB_EMAIL.value))
        {
            alert("email address is invalid");
            return false;
        }
        //window.location.href = "laplaya_offers.aspx?email=" + document.forms[0].offers_email.value;
        return;
    }
}
