function roundnumber(n, d)
{
    n = n - 0;
    if (d == null) d = 2;
    var f = Math.pow(10, d);
    n += Math.pow(10, - (d + 1));
    n = Math.round(n * f) / f;
    n += Math.pow(10, - (d + 1));
    n += '';
    return d == 0 ? n.substring(0, n.indexOf('.')) :  n.substring(0, n.indexOf('.') + d + 1);
}

function popUp(URL)
{
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=660,left = 0,top = 0');");
}

function popWin(URL, width, height)
{
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + ",left = 0,top = 0');");
}

function setCellColor(theCell, thePointerColor)
{
    if (thePointerColor == '' || typeof(theCell.style) == 'undefined') {
	   return false;
	}
    theCell.style.backgroundColor = thePointerColor;
    return true;
}

function verifyNewsletterSubscribe()
{
    return_flag = true;
    tag = document.getElementById('newsletter_email');
    if (isBlank(tag.value) || tag.value == 'email address') {
        alert("Please specify a valid email address!");
        tag.focus();
        return_flag = false;
    }
    if (((!isBlank(tag.value) && !checkemail(tag.value)) || tag.value == 'email address') && return_flag) {
        alert("Please specify a valid email address!");
        tag.focus();
        return_flag = false;
    }
    if (return_flag) {
        $("#dialog-please-wait-process").dialog("open");
    }
    return return_flag;
}

function verifycellphonesForm()
{
    var tag=document.getElementById('contact_firstname');
    if (isBlank(tag.value)) {
        alert('Please specify a First Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_lastname');
    if (isBlank(tag.value)) {
        alert('Please specify a Last Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_email');
    if (!checkemail(tag.value)) {
      alert(tag.value + ' is not a valid email address!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_phone');
    if (isBlank(tag.value)) {
        alert('Please specify a Daytime Phone number!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_departure_date');
    if (isBlank(tag.value)) {
        alert('Please specify a Departure Date!'); tag.focus(); return false;
    }
    if (!checkdate2(tag.value)) { alert(tag.value + ' is not a valid date value. Please use mm/dd/yyyy format.'); document.getElementById('contact_departure_date').focus(); return false; }
    return true;
}

function verifyChangePasswdForm()
{
    regex = /^[a-zA-Z0-9]+$/;
    return_flag = true;
    current_passwd_tag = document.getElementById('form_current_passwd');
    new_passwd_tag = document.getElementById('form_new_passwd');
    retype_passwd_tag = document.getElementById('form_retype_passwd');
    if (isBlank(current_passwd_tag.value)) {
        alert("Please specify a Current Password!");
        current_passwd_tag.focus();
        return_flag = false;
    }
    if (isBlank(new_passwd_tag.value) && return_flag) {
        alert("Please specify a New Password!");
        new_passwd_tag.focus();
        return_flag = false;
    }
    if (!isBlank(new_passwd_tag.value) && return_flag && !regex.test(new_passwd_tag.value)) {
        alert("Wrong symbols in the New Password!");
        new_passwd_tag.focus();
        return_flag = false;
    }
    if (isBlank(retype_passwd_tag.value) && return_flag) {
        alert("Please specify a Verify New Password!");
        retype_passwd_tag.focus();
        return_flag = false;
    }
    if (!isBlank(retype_passwd_tag.value) && return_flag && !regex.test(retype_passwd_tag.value)) {
        alert("Wrong symbols in the Verify New Password!");
        retype_passwd_tag.focus();
        return_flag = false;
    }
    if (!isBlank(new_passwd_tag.value) && !isBlank(retype_passwd_tag.value) && new_passwd_tag.value != retype_passwd_tag.value && return_flag) {
        alert("Passwords mismatch!");
        retype_passwd_tag.focus();
        return_flag = false;
    }
    return return_flag;
}

function rLogout()
{
    frm = document.getElementById('vReservLogoutf');
    if(confirm('You are about to logout, are you sure?')) {
        frm.submit();
    }
}

function ClickItCompare()
{
    var PropIds = '';
    var boxes = document.frmProp.PropIDCompare;
    var iCount = 0;

    for (i = 0; i < boxes.length; i++) {
        if (boxes[i].checked == true) {
            PropIds = PropIds + boxes[i].value + ',';
            iCount ++;
        }
    }
	/*** check to see how many were checked ***/
    if (iCount > 4) {
        alert('You have selected too many properties to compare. Please select up to 4.');
        return false;
    } else if (iCount == 1) {
        alert('Please select at least 2 properties to compare.');
        return false;
    }
	PropIds = PropIds.substring(0, PropIds.length - 1);
    if (PropIds == 0) {
        alert('No properties were selected. Please select at least 2 properties.');
    } else {
        PopUpCompare('compare_properties.html?PropIds=' + PropIds);
    }
    return false;
}
function PopUpCompare(url)
{
    remote = window.open(url , "compare", 'align=center,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no');
    if (remote.opener == null) {
        remote.opener = window;
        remote.opener.name = "main";
    }
}

function homes_disallowBDate(date)
{
    var startdate_tag=document.getElementById('startdate');
    var filter=/^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
    if ( filter.test(startdate_tag.value)) {
      var limit_date=Date.parseDate(startdate_tag.value, "%m/%d/%Y");
      limit_date.setDate(limit_date.getDate() + 1);
      if ( date < limit_date )  return true; else return false;
    } else {
      if ( date < homes_low_limit_dateb )  return true; else return false;
    }
}

function homes_disallowADate(date)
{
    if ( date < homes_low_limit_datea )  return true; else return false;
}

function homes_AdateChanged(calendar)
{
    if (calendar.dateClicked) {
        var enddate_tag=document.getElementById('enddate');
        // OK, a date was clicked, setup the end date
        var enddate=new Date(calendar.date.getFullYear(), calendar.date.getMonth(), calendar.date.getDate() + 1 );
        enddate_tag.value = enddate.print("%m/%d/%Y");
    }
}

function iq_disallowADate(date)
{
    if ( date < iq_low_limit_datea )  return true; else return false;
}

function iq_AdateChanged(calendar)
{
    if (calendar.dateClicked) {
        var iq_enddate_tag=document.getElementById('iq_enddate');
        // OK, a date was clicked, setup the end date
        var iq_enddate=new Date(calendar.date.getFullYear(), calendar.date.getMonth(), calendar.date.getDate() +2 );
        iq_enddate_tag.value = iq_enddate.print("%m/%d/%Y");
    }
}

function iq_disallowBDate(date)
{
    var iq_startdate_tag=document.getElementById('iq_startdate');
    var filter=/^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
    if ( filter.test(iq_startdate_tag.value)) {
        var iq_limit_date=Date.parseDate(iq_startdate_tag.value, "%m/%d/%Y");
        iq_limit_date.setDate(iq_limit_date.getDate() + 2);
        if ( date < iq_limit_date )  return true; else return false;
    } else {
        if ( date < iq_low_limit_dateb )  return true; else return false;
    }
}

function current_disallowADate(date)
{
    if ( date < current_low_limit_datea )  return true; else return false;
}

function current_AdateChanged(calendar)
{
    if (calendar.dateClicked) {
        var current_enddate_tag=document.getElementById('current_enddate');
        // OK, a date was clicked, setup the end date
        var current_enddate=new Date(calendar.date.getFullYear(), calendar.date.getMonth(), calendar.date.getDate() +2 );
        current_enddate_tag.value = current_enddate.print("%m/%d/%Y");
    }
}

function current_disallowBDate(date)
{
    var current_startdate_tag=document.getElementById('current_startdate');
    var filter=/^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
    if ( filter.test(current_startdate_tag.value)) {
        var current_limit_date=Date.parseDate(current_startdate_tag.value, "%m/%d/%Y");
        current_limit_date.setDate(current_limit_date.getDate() + 2);
        if ( date < current_limit_date )  return true; else return false;
    } else {
        if ( date < current_low_limit_dateb )  return true; else return false;
    }
}

function verifyInventorForm()
{
    var tag=document.getElementById('contact_firstname');
    if (isBlank(tag.value)) {
        alert('Please specify a First Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_lastname');
    if (isBlank(tag.value)) {
        alert('Please specify a Last Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_email');
    if (!checkemail(tag.value)) {
      alert(tag.value + ' is not a valid email address!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_phone');
    if (isBlank(tag.value)) {
        alert('Please specify a Phone number!'); tag.focus(); return false;
    }
    return true;
}

function verifyOnlineRequestsForm()
{
    var tag=document.getElementById('contact_first_name');
    if (isBlank(tag.value)) {
        alert('Please specify a First Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_last_name');
    if (isBlank(tag.value)) {
        alert('Please specify a Last Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_email');
    if (!checkemail(tag.value)) {
      alert(tag.value + ' is not a valid email address!'); tag.focus(); return false;
    }
    var tag=document.getElementById('message');
    if (isBlank(tag.value)) {
        alert('Please specify a Message!'); tag.focus(); return false;
    }
    var tag = document.getElementById('secret_code');
	if (isBlank(tag.value)) {
	    alert("Please enter verification code."); tag.focus(); return false;
	}
    return true;
}

function verifyOnlineAdvertisingForm()
{
    var tag=document.getElementById('contact_first_name');
    if (isBlank(tag.value)) {
        alert('Please specify a First Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_last_name');
    if (isBlank(tag.value)) {
        alert('Please specify a Last Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_email');
    if (!checkemail(tag.value)) {
      alert(tag.value + ' is not a valid email address!'); tag.focus(); return false;
    }
    var tag=document.getElementById('message');
    if (isBlank(tag.value)) {
        alert('Please specify a Message!'); tag.focus(); return false;
    }
    var tag = document.getElementById('secret_code');
	if (isBlank(tag.value)) {
	    alert("Please enter verification code."); tag.focus(); return false;
	}
    return true;
}

function verifyNewsletterSubscribe2()
{
    return_flag = true;
    tag = document.getElementById('newsletter_email2');
    if (isBlank(tag.value) || tag.value == 'email address') {
        alert("Please specify a valid email address!");
        tag.focus();
        return_flag = false;
    }
    if (((!isBlank(tag.value) && !checkemail(tag.value)) || tag.value == 'email address') && return_flag) {
        alert("Please specify a valid email address!");
        tag.focus();
        return_flag = false;
    }
    return return_flag;
}

function verifyRealEstateForm()
{
    var tag=document.getElementById('contact_firstname');
    if (isBlank(tag.value)) {
        alert('Please specify a First Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_lastname');
    if (isBlank(tag.value)) {
        alert('Please specify a Last Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_email');
    if (!checkemail(tag.value)) {
      alert(tag.value + ' is not a valid email address!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_phone');
    if (isBlank(tag.value)) {
        alert('Please specify a Daytime Phone number!'); tag.focus(); return false;
    }
    return true;
}

function verifyUnsubLoginForm()
{
    var tag=document.getElementById('une');
    if ( isBlank(tag.value) ) {
        alert('Please enter your E-mail address !'); tag.focus(); return false;
    }
    return true;
}

function verifyComplexUnsubLoginForm()
{
    var tag=document.getElementById('une');
    if ( isBlank(tag.value) ) {
        alert('Please enter your E-mail address !'); tag.focus(); return false;
    }
    return true;
}

function verifyVotingForm()
{
    var tag=document.getElementById('voting_answer_1');
    var tag2=document.getElementById('voting_answer_2');
    if(tag.checked == false && tag2.checked == false) {
        alert('Please select an answer!'); return false;
    }
    return true;
}

function verifyWeddingsForm()
{
    var tag=document.getElementById('contact_firstname');
    if (isBlank(tag.value)) {
        alert('Please specify a First Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_lastname');
    if (isBlank(tag.value)) {
        alert('Please specify a Last Name!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_email');
    if (!checkemail(tag.value)) {
      alert(tag.value + ' is not a valid email address!'); tag.focus(); return false;
    }
    var tag=document.getElementById('contact_phone');
    if (isBlank(tag.value)) {
        alert('Please specify a Daytime Phone number!'); tag.focus(); return false;
    }
    var tag = document.getElementById('secret_code');
	if (isBlank(tag.value)) {
	    alert("Please enter verification code."); tag.focus(); return false;
	}
    return true;
}

function show_floor_plan(URL, width, height)
{
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + ",left = 0,top = 0');");
}

function display_news_comment(boxid)
{
    if(document.getElementById(boxid).style.display=='block') { document.getElementById(boxid).style.display = 'none'; }
    else { document.getElementById(boxid).style.display = 'block'; }
}
function verifyAddNewsCommentForm()
{
	var tag = document.getElementById('name');
	if (isBlank(tag.value)) { alert("Please specify a Your Name."); tag.focus(); return false; }
	var tag = document.getElementById('comment_text');
	if (isBlank(tag.value)) { alert("Please specify a Your Comment."); tag.focus(); return false; }
	var tag = document.getElementById('secret_code');
	if (isBlank(tag.value)) { alert("Please enter verification code."); tag.focus(); return false; }
	return true;
}

function random_banner() {
}

function rate_quote_disallowADate(date)
{
    if ( date < rate_quote_low_limit_datea )  return true; else return false;
}

function rate_quote_AdateChanged(calendar)
{
    if (calendar.dateClicked) {
        var rate_quote_enddate_tag = document.getElementById('res_enddate');
        // OK, a date was clicked, setup the end date
        var rate_quote_enddate = new Date(calendar.date.getFullYear(), calendar.date.getMonth(), calendar.date.getDate() +2 );
        rate_quote_enddate_tag.value = rate_quote_enddate.print("%m/%d/%Y");
    }
}

function rate_quote_disallowBDate(date)
{
    var rate_quote_startdate_tag = document.getElementById('res_startdate');
    var filter=/^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
    if ( filter.test(rate_quote_startdate_tag.value)) {
        var rate_quote_limit_date = Date.parseDate(rate_quote_startdate_tag.value, "%m/%d/%Y");
        rate_quote_limit_date.setDate(rate_quote_limit_date.getDate() + 2);
        if ( date < rate_quote_limit_date ) return true; else return false;
    } else {
        if ( date < rate_quote_low_limit_dateb ) return true; else return false;
    }
}
