
function externalUrl(sUrl)
{
//  frameUrl(sUrl);
    window.location.href = encodeURI(sUrl);
//  window.open(encodeURI(sUrl));

  // Return false so that the href is not called.
  return false;
}

function frameUrl(sMainUrl)
{
  var sNewUrl;
	
  sNewUrl = 'frame_set.php?1=1';
  sNewUrl += '&mainurl=' + encodeURIComponent(sMainUrl);
  sNewUrl += '&returnurl=' + encodeURIComponent(document.URL);
  sNewUrl = encodeURI(sNewUrl);

  window.location.href = sNewUrl;
  return true;
}

function windowStatus(sMsg)
{
  window.status = sMsg;
  return true;
}

function refreshWindow()
{
  window.location.reload();
}

function navOver(navCell, sName)
{
  navCell.className='td_nav_on';
  navCell.style.cursor='hand';
  document.getElementById(sName).className='nav_hover';
  return true;
}

function navOut(navCell, sName)
{
  navCell.className='td_nav';
  document.getElementById(sName).className='nav';
  return true;
}

function showMap(sStreet, sCity, sState, sZip)
{
  var sMapUrl;

  sMapUrl = 'http://maps.yahoo.com/maps_result?addr=' + sStreet;
  sMapUrl += '&csz=' + sCity + ', ' + sState + ' ' + sZip;
  sMapUrl += '&country=us';

  window.open(encodeURI(sMapUrl));
  return true;
}

function zoomPic(sImgSrc, sImgDesc)
{
  var eImg;

  eImg = document.zoomPicImg;
  if (eImg)
    eImg.src = sImgSrc;

  zoomPicDesc.innerText = sImgDesc;
  return true;
}

function emailAddrTest(sEmailAddr, bShowMessage) 
{
  var aRules = [
  /\,/,     false,  "Comma (,) found", 
  /\s/,     false,  "Spaces not allowed", 
  /@/,      true,   "No @ sign", 
  /@.*@/,   false,  "More than one @", 
  /^@/,     false,  "Nothing preceding @", 
  /\.@/,    false,  "@ preceded by '.'", 
  /@\./,    false,  "@ followed by '.'", 
  /@.+\./,  true,   "No '.' anywhere after @", 
  /\.\./,   false,  "=>..", 
  /^\./,    false,  "Cannot start with '.'", 
  /\.$/,    false,  "Cannot end with '.'", 
  /.+\.[a-z]{2,}$/i, true, "Must end with 2 or more letters" 
 ]; 

  var bRetVal, aL, ii; 

  bRetVal = true;
  aL = aRules.length;
  
  sEmailAddr = sEmailAddr.replace(/^\s+|\s+$/g,''); 

  for(ii=0; ii<aL && ( aRules[ii].test( sEmailAddr ) ^ !aRules[ii+1] ); ii+=3) 
  ; 

  if(ii != aL) 
  { 
    bRetVal = false; 
    if(bShowMessage) 
      alert("Invalid email address.\n\n" + sEmailAddr + "\n\n" + aRules[ii+2]); 
  } 

  return bRetVal; 
}

function valueSanityTest(sValue, bShowMessage) 
{
  var aRules = [
  /^(.)\1+$/,    false,  "Repeat of same character (i.e. xxxx)" 
 ]; 

  var bRetVal, aL, ii; 

  bRetVal = true;
  aL = aRules.length;
  
  sValue = sValue.replace(/^\s+|\s+$/g,''); 

  for(ii=0; ii<aL && ( aRules[ii].test( sValue ) ^ !aRules[ii+1] ); ii+=3) 
  ; 

  if(ii != aL) 
  { 
    bRetVal = false; 
    if(bShowMessage) 
      alert("Invalid value.\n\n" + sValue + "\n\n" + aRules[ii+2]); 
  } 

  return bRetVal; 
}

function submitRegForm()
{
	if (checkContactForm())
	{
		// document.getElementById('SubmitButton').disabled = true; // Won't submit the form in IE
		document.getElementById('SubmitStatus').innerHTML = 'Submitting form...';
		return true;
	}
	else
	{
		return false;
	}
}

function checkContactForm()
{
  var bShowAlert = false;
    
  if (document.contactform.ContactName.value == '' || !valueSanityTest(document.contactform.ContactName.value, bShowAlert))
  {
    alert("Please enter Your Name.");
    document.contactform.ContactName.focus();
    return false;
  }
  else if (document.contactform.Phone.value == '' || !valueSanityTest(document.contactform.Phone.value, bShowAlert))
  {
    alert("Please enter a valid Phone number.");
    document.contactform.Phone.focus();
    return false;
  }
  else if (document.contactform.Email.value == '' || !emailAddrTest(document.contactform.Email.value, bShowAlert))
  {
    alert("Please enter a valid Email address.");
    document.contactform.Email.focus();
    return false;
  }
  else if (document.contactform.BusinessName.value == '' || !valueSanityTest(document.contactform.BusinessName.value, bShowAlert))
  {
    alert("Please enter your Business Name.");
    document.contactform.BusinessName.focus();
    return false;
  }
  else if (document.contactform.Address.value == '' || !valueSanityTest(document.contactform.Address.value, bShowAlert))
  {
    alert("Please enter a valid Address.");
    document.contactform.Address.focus();
    return false;
  }
  else if (document.contactform.City.value == '' || !valueSanityTest(document.contactform.City.value, bShowAlert))
  {
    alert("Please enter a valid City.");
    document.contactform.City.focus();
    return false;
  }
  else if (document.contactform.State.value == '' || !valueSanityTest(document.contactform.State.value, bShowAlert))
  {
    alert("Please enter a valid State.");
    document.contactform.State.focus();
    return false;
  }
  else if (document.contactform.ZipCode.value == '' || !valueSanityTest(document.contactform.ZipCode.value, bShowAlert))
  {
    alert("Please enter a valid Zip Code.");
    document.contactform.ZipCode.focus();
    return false;
  }
  else
    return true;
}
