function flipElem(elemId) {
    var elem = document.getElementById(elemId);

    if (elem.style.display == 'none') {
        elem.style.display = 'block';
        elem.style.visibility = 'visible';
    } else {
        elem.style.display = 'none';
        elem.style.visibility = 'hidden';
    }

    return false;
}

function flipBg(elem, colorValue) {
    elem.style.background = '#'+colorValue;
    return false;
}

function flipBgImg(elem, onOff) {
    if (onOff == 'on') {
        elem.style.background = 'transparent url(img/thumb_bg_on.gif)';
    } else {
        elem.style.background = 'transparent url(img/thumb_bg_off.gif)';
    }
    return false;
}

function flipImg(elem, imgName, onOff) {
    elem.src = 'img/'+imgName+'_'+onOff+'.gif';
    return false;
}

function showConfirm(showText) {
  var r=confirm(showText);
  if (r==true)
    {
    return true;
    }
  else
    {
    return false;
    }
}


function showCountry(elemId, optionCountry) {
  var elem = document.getElementById(elemId);
  if (optionCountry == 'other') {
    elem.style.display = 'block';
    elem.style.visibility = 'visible';
  } else {
    elem.style.display = 'none';
    elem.style.visibility = 'hidden';
  }
}


function showProvince(textElemId, optionCountry) {
  var textElem = document.getElementById(textElemId);
  var dropUS = document.getElementById('provinceUS');
  var dropCA = document.getElementById('provinceCA');
  var dropMX = document.getElementById('provinceMX');
  var dropOther = document.getElementById('provinceOther');
  if (optionCountry == 'CA') {
    textElem.innerHTML = 'Province';

    dropCA.style.display = 'block';
    dropCA.style.visibility = 'visible';
    dropUS.style.display = 'none';
    dropUS.style.visibility = 'hidden';
    dropMX.style.display = 'none';
    dropMX.style.visibility = 'hidden';
    dropOther.style.display = 'none';
    dropOther.style.visibility = 'hidden';

  } else if (optionCountry == 'US') {
    textElem.innerHTML = 'State';
    dropUS.style.display = 'block';
    dropUS.style.visibility = 'visible';
    dropCA.style.display = 'none';
    dropCA.style.visibility = 'hidden';
    dropMX.style.display = 'none';
    dropMX.style.visibility = 'hidden';
    dropOther.style.display = 'none';
    dropOther.style.visibility = 'hidden';

  } else if (optionCountry == 'MX') {
    textElem.innerHTML = 'State';
    dropMX.style.display = 'block';
    dropMX.style.visibility = 'visible';
    dropCA.style.display = 'none';
    dropCA.style.visibility = 'hidden';
    dropUS.style.display = 'none';
    dropUS.style.visibility = 'hidden';
    dropOther.style.display = 'none';
    dropOther.style.visibility = 'hidden';

  } else if (optionCountry == 'other') {
    textElem.innerHTML = 'Province/State/etc.';
    dropMX.style.display = 'none';
    dropMX.style.visibility = 'hidden';
    dropCA.style.display = 'none';
    dropCA.style.visibility = 'hidden';
    dropUS.style.display = 'none';
    dropUS.style.visibility = 'hidden';
    dropOther.style.display = 'block';
    dropOther.style.visibility = 'visible';

  } else {
    textElem.innerHTML = 'Province';
    dropOther.style.display = 'none';
    dropOther.style.visibility = 'hidden';
    dropCA.style.display = 'none';
    dropCA.style.visibility = 'hidden';
    dropUS.style.display = 'none';
    dropUS.style.visibility = 'hidden';
    dropMX.style.display = 'none';
    dropMX.style.visibility = 'hidden';
  }
}

function checkWholeForm(theForm) {
    var why = "";
    why += checkName(theForm.rname.value, 'Name');
    why += checkEmail(theForm.remail.value);
    why += checkName(theForm.rphone.value, 'Phone');

    if (why != "") {
        alert(why);
        return false;
    } else {
        return true;
    }
}

function checkName (strng, strngName) {
    var error = "";
    if (strng == "") {
       error = "You didn't enter "+strngName+".\n";
    }
    return error;
}

function checkEmail (strng) {
    var error = "";

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) {
       error = "Please enter a valid email address.\n";
    }

    var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
    if (strng.match(illegalChars)) {
       error = "The email address contains illegal characters.\n";
    }
    return error;
}


