
function hide(t, id) {
  var tags = document.getElementsByTagName(t);
  for (var i = 5; i < tags.length; i++) {
    if (tags[i].style.display == 'none')
      tags[i].style.display = 'block';
    else tags[i].style.display = 'none';
  }
}

function carga() {
   document.LookingForSpaceContactInfoForm.other.style.visibility = 'hidden';
 }
  
  function toggleOther(chosen, texto) {
    var idx = chosen.selectedIndex;
    var Appr = chosen.options[idx].value;
  if (Appr == 'Other') {
    document.getElementById('Other-Choices').style.display = 'block';
    document.getElementById('Retail-Choices-T').style.display = 'none';
    document.getElementById('Office-Choices').style.display = 'none';
    document.getElementById('Retail-Choices').style.display = 'none';
    document.LookingForSpaceContactInfoForm.other.style.visibility = 'visible';
    document.LookingForSpaceContactInfoForm.other.value=texto;

  } else     
  if (Appr == 'Office') {
    document.getElementById('Office-Choices').style.display = 'block';
    document.getElementById('Retail-Choices-T').style.display = 'none';
    document.getElementById('Retail-Choices').style.display = 'none';
    document.getElementById('Other-Choices').style.display = 'none';
    document.LookingForSpaceContactInfoForm.other.style.visibility = 'hidden';
  } else     
  if (Appr == 'Retail') {
    document.getElementById('Retail-Choices-T').style.display = 'block';
    document.getElementById('Retail-Choices').style.display = 'block';    
    document.getElementById('Office-Choices').style.display = 'none';
    document.getElementById('Other-Choices').style.display = 'none';    
    document.LookingForSpaceContactInfoForm.other.style.visibility = 'hidden';
  } else {
    document.LookingForSpaceContactInfoForm.other.style.visibility = 'hidden';
    document.LookingForSpaceContactInfoForm.other.value = '';
    document.getElementById('Office-Choices').style.display = 'none';
    document.getElementById('Retail-Choices-T').style.display = 'none';
    document.getElementById('Retail-Choices').style.display = 'none';
  }
 }

function echeck(str) {

  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
   document.getElementById('email-issue').innerHTML = "Invalid E-mail or use spaces@optimalspaces.com"
     return false
  }

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
   document.getElementById('email-issue').innerHTML = "Invalid E-mail or use spaces@optimalspaces.com"
     return false
  }

  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    document.getElementById('email-issue').innerHTML = "Invalid E-mail or use spaces@optimalspaces.com"
   return false
  }

   if (str.indexOf(at,(lat+1))!=-1){
    document.getElementById('email-issue').innerHTML = "Invalid E-mail or use spaces@optimalspaces.com"
   return false
   }

   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    document.getElementById('email-issue').innerHTML = "Invalid E-mail or use spaces@optimalspaces.com"
   return false
   }

   if (str.indexOf(dot,(lat+2))==-1){
    document.getElementById('email-issue').innerHTML = "Invalid E-mail or use spaces@optimalspaces.com"
   return false
   }

   if (str.indexOf(" ")!=-1){
    document.getElementById('email-issue').innerHTML = "Invalid E-mail or use spaces@optimalspaces.com"
   return false
   }

    return true
 }

function ValidateForm(){
 var emailID=document.LookingForSpaceContactInfoForm.ClientEmail

 if ((emailID.value==null)||(emailID.value=="")){
  document.getElementById('email-issue').innerHTML = "Invalid E-mail or use spaces@optimalspaces.com"
  emailID.focus()
  return false
 }
 if (echeck(emailID.value)==false){
  emailID.value=""
  emailID.focus()
  return false
 }
 return true
 }


check = []; //this is an array that stores all the true/false values for each checkbox

function checkBox(id)
 {
 if(check[id] != true) 
  {
  document.getElementById('imgCheck' + id).src = "imagez/true.png"; //change the image
  document.getElementById('inputCheck' + id).value = "true"; //change the field value
  check[id] = true; //change the value for this checkbox in the array
  }
 else
  {
  document.getElementById('imgCheck' + id).src = "imagez/false.png";
  document.getElementById('inputCheck' + id).value = "false";
  check[id] = false;
  }
 }

function handleEnter (field, event) {
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  if (keyCode == 13) {
   var i;
   for (i = 0; i < field.form.elements.length; i++)
    if (field == field.form.elements[i])
     break;
   i = (i + 1) % field.form.elements.length;
   field.form.elements[i].focus();
   return false;
  } 
  else
  return true;
 }   

  function toggleDiv(divid){
 if(document.getElementById(divid).style.display == 'none'){
   document.getElementById(divid).style.display = 'block';
 }else{
   document.getElementById(divid).style.display = 'none';
 }
  }