function checkEmail(email) {
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.toLowerCase())) {
  return true;
 } else {
  return false;
 }
}

function toggleDisplay(object) {
 if (document.getElementById(object+'_block').style.display=="none") {
  document.getElementById(object+'_block').style.display="block";
  document.getElementById(object+'_icon').src="img/icon-minus.gif";
 } else {
  document.getElementById(object+'_block').style.display="none";
  document.getElementById(object+'_icon').src="img/icon-plus.gif";
 }
 return false;
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
    if(!radioObj)
        return "";
    var radioLength = radioObj.length;
    if(radioLength == undefined)
        if(radioObj.checked)
            return radioObj.value;
        else
            return "";
    for(var i = 0; i < radioLength; i++) {
        if(radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
    if(!radioObj)
        return;
    var radioLength = radioObj.length;
    if(radioLength == undefined) {
        radioObj.checked = (radioObj.value == newValue.toString());
        return;
    }
    for(var i = 0; i < radioLength; i++) {
        radioObj[i].checked = false;
        if(radioObj[i].value == newValue.toString()) {
            radioObj[i].checked = true;
        }
    }
}

function swapPic(property_id,pic_num,photos_num) {
 document.getElementById('mainpic').style.backgroundImage="url(img/loading.gif)";
 document.getElementById('mainpic').style.backgroundImage="url(photos_" + photos_num +"/property_"+property_id+"_pic_"+pic_num+".jpg)";
}

function urlEncode(sStr) {
 sStr = escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F');
 return sStr;
}

function toggleState(object) {
 if (document.getElementById('state')) {
  if (object.options[object.selectedIndex].value=='US' || object.options[object.selectedIndex].value=='CA') {
   document.getElementById('state').disabled=false;
  } else {
   document.getElementById('state').disabled=true;
  }
 }
}