function submitForm()
{
 document.forms[0].elements["destinationInput"].value = document.forms[0].elements["destinationInput"].value.replace(/"/g, '')
 document.forms[0].elements["originInput"].value = document.forms[0].elements["originInput"].value.replace(/"/g, '')
 removeInvalidCharacterStrings()
 if(checkLocationFields())
 {
  submitForm2()
 }
 else
 {
  openMessageWindow()
 }
}



function submitForm2()
{
 document.forms[0].elements["destinationInput"].value = document.forms[0].elements["destinationInput"].value.replace(/"/g, '')
 document.forms[0].elements["originInput"].value = document.forms[0].elements["originInput"].value.replace(/"/g, '')
 removeInvalidCharacterStrings()
 if(checkDirectionalWords())
 {
  submitForm3()
 }
 else
 {
  openMessage2Window()
 }
}


function submitForm3()
{
 document.forms[0].elements["destinationInput"].value = document.forms[0].elements["destinationInput"].value.replace(/"/g, '')
 document.forms[0].elements["originInput"].value = document.forms[0].elements["originInput"].value.replace(/"/g, '')
 removeInvalidCharacterStrings()
 if(checkIntersectionWords())
 {
  document.forms[0].submit()
 }
 else
 {
  openMessage2Window()
 }
}



function removeInvalidCharacterStrings()
{
 var trimmedOriginInput
 trimmedOriginInput = document.forms[0].elements["originInput"].value
 trimmedOriginInput = trimmedOriginInput.replace(/\\/g, '')
 trimmedOriginInput = trimmedOriginInput.replace(/ /g, '')
 if(trimmedOriginInput == "")
 {
 document.forms[0].elements["originInput"].value = ""
 }

 var trimmedDestinationInput
 trimmedDestinationInput = document.forms[0].elements["destinationInput"].value
 trimmedDestinationInput = trimmedDestinationInput.replace(/\\/g, '')
 trimmedDestinationInput = trimmedDestinationInput.replace(/ /g, '')
 if(trimmedDestinationInput == "")
 {
 document.forms[0].elements["destinationInput"].value = ""
 }
}



function checkLocationFields()
{
if(document.forms[0].elements["originInput"].value != "" && document.forms[0].elements["destinationInput"].value != "")
   {
   return true
   }
else
   {
   window.frames[0].document.open()
   window.frames[0].document.write("<body style='border:solid red 5px; width:440; height:140; margin:0px; color:black; font-family:verdana; font-weight:bold; font-size:14px;'></body>")
   window.frames[0].document.close()
   window.frames[0].document.body.innerHTML = "<div style='padding:10px; text-align:center;'>Custom Planner<br /><br />You must enter both a Starting Location<br /> and a Destination Location.<br /><br /><input type=button value='OK' onclick='javascript:parent.closeMessageWindow()'></div>"
   return false
   }
}

function openMessageWindow()
{
document.getElementById("messageDiv").style.height = "150px"
document.getElementById("messageDiv").style.width = "450px"
document.getElementById("messageDiv").style.left = ((pageWidth()/2 - 225) + posLeft()) + "px"
document.getElementById("messageDiv").style.top = ((pageHeight()/2 - 75) + posTop()) + "px"
document.getElementById("messageDiv").style.visibility = "visible"
}




function closeMessageWindow()
{
   document.getElementById("messageDiv").style.left = "-500px"
   document.getElementById("messageDiv").style.top = "-500px"
   document.getElementById("messageDiv").style.visibility = "hidden"
   window.frames[0].document.body.innerHTML = ""
}


function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}



function checkDirectionalWords()
{
 var combinedInput
 combinedInput = " " + document.forms[0].elements["destinationInput"].value + " " +  document.forms[0].elements["originInput"].value + " "
 if(combinedInput.toLowerCase().indexOf(" west ") != -1 || combinedInput.toLowerCase().indexOf(" north ") != -1 || combinedInput.toLowerCase().indexOf(" east ") != -1  || combinedInput.toLowerCase().indexOf(" south ") != -1)
 {
  var messageHTML
  window.frames[0].document.open()
  window.frames[0].document.write("<body style='border:solid red 5px; width:590; height:440; margin:0px; color:black; font-family:verdana; font-weight:bold; font-size:14px;'></body>")
  window.frames[0].document.close()
  messageHTMl = ""
  messageHTMl = messageHTMl + '<div style="padding:10px; text-align:left; font-size:12px">When the words "North", "East", "South" and "West" are used as a prefix or suffix to a street name, the abbreviated form "N", "E", "W" or "S"  must be used.<br /><br />SEE EXAMPLES BELOW:'
  messageHTMl = messageHTMl + '<br /><br /><span style="color:red; font-size:14px; font-weight:bold; font-family:arial">WRONG:<br />EAST 72ND STREET <img src="images/redXMark.gif" alt="red X mark" /><br />CENTRAL PARK WEST <img src="images/redXMark.gif" alt="red X mark" /></span><br /><br /><span style="color:green; font-size:14px; font-weight:bold; font-family:arial;">RIGHT:<br />E 72ND STREET <img src="images/greenCheckMark.gif" alt="green check mark" /><br />CENTRAL PARK W <img src="images/greenCheckMark.gif" alt="green check mark" /></span>'
  messageHTMl = messageHTMl + '<br /><br />However when used as part of the proper name as in "SOUTH STREET SEAPORT"<br /> or "WEST STREET" use the full word.'
  messageHTMl = messageHTMl + '<br /><br />How do you want to proceed?'
  messageHTMl = messageHTMl + '<br /><br /><input style="width:350px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Automatically convert to abbrievated format and submit" onclick="javascript:parent.fixAndSubmit()">'
  messageHTMl = messageHTMl + '<br /><br /><input style="width:250px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Leave it as I typed it and submit" onclick="javascript:parent.leaveAndSubmit()">'
  messageHTMl = messageHTMl + '<br /><br /><input style="width:400px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Close this message window. I will check my inputs and try again." onclick="javascript:parent.closeMessageWindow()"></div>'

  window.frames[0].document.body.innerHTML = messageHTMl
  return false
 }
 else
 {
  return true
 }
}



function checkIntersectionWords()
{
 var combinedInput
 combinedInput = " " + document.forms[0].elements["destinationInput"].value + " " +  document.forms[0].elements["originInput"].value + " "
 if(combinedInput.toLowerCase().indexOf(" and ") != -1 || combinedInput.toLowerCase().indexOf(" at ") != -1)
 {
  var messageHTML
  window.frames[0].document.open()
  window.frames[0].document.write("<body style='border:solid red 5px; width:590px; height:440px; margin:0px; color:black; font-family:verdana; font-weight:bold; font-size:14px;'></body>")
  window.frames[0].document.close()
  messageHTMl = ""
  messageHTMl = messageHTMl + '<div style="padding:10px; text-align:left; font-size:12px">To indicate an intersection use the "&" or "@" symbols in place of the words "AND" or "AT".<br /><br />SEE EXAMPLES BELOW:'
  messageHTMl = messageHTMl + '<br /><br /><span style="color:red; font-size:14px; font-weight:bold; font-family:arial;">WRONG:<br />E 42ND STREET AND 3RD AVE <img src="images/redXMark.gif" alt="red X mark" /><br />E 42ND STREET AT 3RD AVE <img src="images/redXMark.gif" alt="red X mark" /></span><br /><br /><span style="color:green; font-size:14px; font-weight:bold; font-family:arial;">RIGHT:<br />E 42ND STREET & 3RD AVE <img src="images/greenCheckMark.gif" alt="green check mark" /><br />E 42ND STREET @ 3RD AVE <img src="images/greenCheckMark.gif" alt="green check mark" /></span>'
  messageHTMl = messageHTMl + '<br /><br />How do you want to proceed?'
  messageHTMl = messageHTMl + '<br /><br /><input style="width:390px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Automatically convert to proper intersection format and submit" onclick="javascript:parent.fixAndSubmit2()">'
  messageHTMl = messageHTMl + '<br /><br /><input style="width:250px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Leave it as I typed it and submit" onclick="javascript:parent.leaveAndSubmit2()">'
  messageHTMl = messageHTMl + '<br /><br /><input style="width:400px; padding-left:5px; text-align:left; border:solid black 1px" type=button value="Close this message window. I will check my inputs and try again." onclick="javascript:parent.closeMessageWindow()"></div>'

  window.frames[0].document.body.innerHTML = messageHTMl
  return false
 }
 else
 {
  return true
 }
}




function findTopPos(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop
		}
	}
	return curtop;
}

function findLeftPos(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
		}
	}
	return curleft;
}


function showWalkMessage(x,y)
{
//alert(x)
document.getElementById("walkMessage").style.visibility = "visible"
document.getElementById("walkMessage").style.top = (x + 0) + "px"
document.getElementById("walkMessage").style.left = (y - (document.getElementById("walkMessage").offsetWidth/2)) + "px"
document.forms[0].elements["Walkdist"].blur()
}

function hideWalkMessage()
{
document.getElementById("walkMessage").style.visibility = "hidden"
}



function openMessage2Window()
{
document.getElementById("messageDiv").style.height = "450px"
document.getElementById("messageDiv").style.width = "600px"
document.getElementById("messageDiv").style.left = ((pageWidth()/2 - 300) + posLeft()) + "px"
document.getElementById("messageDiv").style.top = ((pageHeight()/2 - 225) + posTop()) + "px"
document.getElementById("messageDiv").style.visibility = "visible"
}

function fixAndSubmit()
{
 document.forms[0].elements["destinationInput"].value = document.forms[0].elements["destinationInput"].value.replace(/"/g, '')
 var correctedDestinationInput
 correctedDestinationInput = "%%% " + document.forms[0].elements["destinationInput"].value + " %%%"
 correctedDestinationInput = correctedDestinationInput.toUpperCase().replace(/ WEST /g, ' W ')
 correctedDestinationInput = correctedDestinationInput.toUpperCase().replace(/ EAST /g, ' E ')
 correctedDestinationInput = correctedDestinationInput.toUpperCase().replace(/ NORTH /g, ' N ')
 correctedDestinationInput = correctedDestinationInput.toUpperCase().replace(/ SOUTH /g, ' S ')
 correctedDestinationInput = correctedDestinationInput.toUpperCase().replace(/%%% /g, '')
 correctedDestinationInput = correctedDestinationInput.toUpperCase().replace(/ %%%/g, '')
 document.forms[0].elements["destinationInput"].value = correctedDestinationInput

 document.forms[0].elements["originInput"].value = document.forms[0].elements["originInput"].value.replace(/"/g, '')
 var correctedOriginInput
 correctedOriginInput = "%%% " + document.forms[0].elements["originInput"].value + " %%%"
 correctedOriginInput = correctedOriginInput.toUpperCase().replace(/ WEST /g, ' W ')
 correctedOriginInput = correctedOriginInput.replace(/ EAST /g, ' E ')
 correctedOriginInput = correctedOriginInput.replace(/ NORTH /g, ' N ')
 correctedOriginInput = correctedOriginInput.replace(/ SOUTH /g, ' S ')
 correctedOriginInput = correctedOriginInput.toUpperCase().replace(/%%% /g, '')
 correctedOriginInput = correctedOriginInput.toUpperCase().replace(/ %%%/g, '')
 document.forms[0].elements["originInput"].value = correctedOriginInput
 submitForm3()
}



function fixAndSubmit2()
{
 document.forms[0].elements["destinationInput"].value = document.forms[0].elements["destinationInput"].value.replace(/"/g, '')
 var correctedDestinationInput
 correctedDestinationInput = "%%% " + document.forms[0].elements["destinationInput"].value + " %%%"
 correctedDestinationInput = correctedDestinationInput.toUpperCase().replace(/ AND /g, ' & ')
 correctedDestinationInput = correctedDestinationInput.toUpperCase().replace(/ AT /g, ' @ ')
 correctedDestinationInput = correctedDestinationInput.toUpperCase().replace(/%%% /g, '')
 correctedDestinationInput = correctedDestinationInput.toUpperCase().replace(/ %%%/g, '')
 document.forms[0].elements["destinationInput"].value = correctedDestinationInput

 document.forms[0].elements["originInput"].value = document.forms[0].elements["originInput"].value.replace(/"/g, '')
 var correctedOriginInput
 correctedOriginInput = "%%% " + document.forms[0].elements["originInput"].value + " %%%"
 correctedOriginInput = correctedOriginInput.toUpperCase().replace(/ AND /g, ' & ')
 correctedOriginInput = correctedOriginInput.toUpperCase().replace(/ AT /g, ' @ ')
 correctedOriginInput = correctedOriginInput.toUpperCase().replace(/%%% /g, '')
 correctedOriginInput = correctedOriginInput.toUpperCase().replace(/ %%%/g, '')
 document.forms[0].elements["originInput"].value = correctedOriginInput
 document.forms[0].submit()
}





function leaveAndSubmit()
{
 document.forms[0].elements["destinationInput"].value = document.forms[0].elements["destinationInput"].value.replace(/"/g, '')
 document.forms[0].elements["originInput"].value = document.forms[0].elements["originInput"].value.replace(/"/g, '')
 submitForm3()
}


function leaveAndSubmit2()
{
 document.forms[0].elements["destinationInput"].value = document.forms[0].elements["destinationInput"].value.replace(/"/g, '')
 document.forms[0].elements["originInput"].value = document.forms[0].elements["originInput"].value.replace(/"/g, '')
 document.forms[0].submit()
}