// JavaScript Document
function GetCurrentUser ()
{
  var blnSuccess;
    blnSuccess = ajaxUpdate( "GetCurrentUser.asp", {
            params:"",
            meth:"GET",
            async:false,
            startfunc:"",
            endfunc:"",
            errorfunc:"ajaxError()",
            noauthfunc:"ajaxNoAuth()",
            callfunc:"saveusertoform()" }
           );
}

function saveusertoform()
{
	if (rText.length < 1)
	{
		window.location = "sign-in.html";
	}
}
function GISDivs (divname,buttonname)
{
	if (document.getElementById(divname).className == "hideitem")
	{
		//Show Div
		document.getElementById(divname).className = "showitem";
		//Change Button To Hide
		document.getElementById(buttonname).src = "images/icons/Hide.png";
	}
	else
	{
		//Hide Div
		document.getElementById(divname).className = "hideitem";
		//Chnage Button To Show
		document.getElementById(buttonname).src = "images/icons/Show.png";		
	}
}

function showidebuynowfields (divname)
{
					  document.getElementById('QueryLocation').innerHTML = "<input type='text' id='os0' name='os0' size='70' width='60' maxlength='70' value="+document.getElementById('Location').value.replace(/ /g,'_')+"'>";				  
					  document.getElementById('FaxLocation').innerHTML = "<input type='text' id='os0' name='os1' size='70' width='60' maxlength='70' value="+document.getElementById('Location').value.replace(/ /g,'_')+"'>";
					  document.getElementById('MapLocation').innerHTML = "<input type='text' id='os1' name='os1' size='70' width='60' maxlength='70' value="+document.getElementById('Location').value.replace(/ /g,'_')+"'>";
					  document.getElementById('MarketLocation').innerHTML = "<input type='text' id='os1' name='os1' size='70' width='60' maxlength='70' value="+document.getElementById('Location').value.replace(/ /g,'_')+"'>";					  
					  document.getElementById('SurveyLocation').innerHTML = "<input type='text' id='os1' name='os1' size='70' width='60' maxlength='70' value="+document.getElementById('Location').value.replace(/ /g,'_')+"'>";					  
					  document.getElementById('CivilLocation').innerHTML = "<input type='text' id='os1' name='os1' size='70' width='60' maxlength='70' value="+document.getElementById('Location').value.replace(/ /g,'_')+"'>";					  
					  document.getElementById('StrucLocation').innerHTML = "<input type='text' id='os1' name='os1' size='70' width='60' maxlength='70' value="+document.getElementById('Location').value.replace(/ /g,'_')+"'>";					  

					  
	if (document.getElementById(divname).className == "hideitem")
	{
		document.getElementById(divname).className = "showitem";
	}
	else
	{
		document.getElementById(divname).className = "hideitem";
	}
}

function getlogin()
{
  var enteruser = document.getElementById("UserName").value;
  
  var blnSuccess;
    blnSuccess = ajaxUpdate( "verifyuser.asp", {
            params:"user="+enteruser+"",
            meth:"GET",
            async:false,
            startfunc:"",
            endfunc:"",
            errorfunc:"ajaxError()",
            noauthfunc:"ajaxNoAuth()",
            callfunc:"letin()" }
           );

}
function letin ()
{
	var enterpass = document.getElementById("Password").value;
	var tasks;
	tasks = rText.split("|");
	if (enterpass == tasks[0])
	{
		document.getElementById("loginfields").style.backgroundColor = "GREEN";
		document.getElementById("logininlogo").src="images/GREENID.png";		
		window.location=tasks[1];
		return true;
	}
	else
	{
		document.getElementById("loginfields").style.backgroundColor = "RED";
		document.getElementById("logininlogo").src="images/REDID.png";
		alert("username and/or password is incorrect")
		return false;
	}
}

function addlandfaxtoorder()
{
	alert("Test for address, then Add Paypal Code Here");
}
function addmaptoorder()
{
	alert("Test for address, then Add Paypal Code Here");
}
function addquerytoorder()
{
	alert("Test for address, then Add Paypal Code Here");
}
function addvideotoorder()
{
	alert("Add Paypal Code Here");
}

function showvideo ()
{
//	var videocode;
//	videocode = "";
//videocode = videocode +"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='350' height='300' id='Sample' align='middle'>";
//videocode = videocode +"<param name='allowScriptAccess' value='sameDomain' />";
//videocode = videocode +"<param name='movie' value='Sample.swf' />";
//videocode = videocode +"<param name='quality' value='high' />";
//videocode = videocode +"<param name='bgcolor' value='#ffffff' />";
//videocode = videocode +"<embed src='Sample.swf' quality='high' bgcolor='#ffffff' width='350' height='300' name='Sample' align='middle' allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";                  
//videocode = videocode +"</object>";
//		document.getElementById("LandMap").innerHTML = videocode;
//		document.getElementById("mapicons").innerHTML = ""
}

function cleartheaddress()
{	
	var blnSuccess;
		blnSuccess = ajaxUpdate( "resetaddress.asp", {
		params:"",
		meth:"GET",
		async:false,
		startfunc:"",
		endfunc:"",
		errorfunc:"ajaxError()",
		noauthfunc:"ajaxNoAuth()",
		callfunc:"reloadpage()" }
	);
}

function reloadpage ()
{
	if (window.location == "http://www.landfeasibility.com/buynow.htm")
	{
		window.location = "index.html"
	}
	else
	{
		location.reload(true);

	}
}


function maptheaddress ()
{
	var Location = document.getElementById('Location').value;
	
	if (Location == "")
	{
		alert("Please Specificy An Address");
	}
	else
	{
		var browserName=navigator.appName; 
		if (browserName=="Microsoft Internet Explorer")
		{
			var blnSuccess;
			blnSuccess = ajaxUpdate( "SaveAddressIE.asp", {
			params:"Location="+Location+"",
			meth:"GET",
			async:false,
			startfunc:"",
			endfunc:"",
			errorfunc:"ajaxError()",
			noauthfunc:"ajaxNoAuth()",
			callfunc:"loadbuyitnowpage()" }
		);
		}
		else
		{
			var blnSuccess;
			blnSuccess = ajaxUpdate( "SaveAddress.asp", {
			params:"Location="+Location+"",
			meth:"GET",
			async:false,
			startfunc:"",
			endfunc:"",
			errorfunc:"ajaxError()",
			noauthfunc:"ajaxNoAuth()",
			callfunc:"loadbuyitnowpage()" }
		);
		}
	}
	
}

function loadbuyitnowpage ()
{
	window.location="buynow.htm";
}

function drawmap ()
{
var mapcode;

var street;
var city;
var state;
var Location;
var zoomfactor
mapcode = '';

if (document.getElementById("AddressHeader").innerHTML == "Current Address Of Interest:" || window.location == "http://www.landfeasibility.com/contactus.html" || window.location == "http://www.landfeasibility.com/thank-you.html")
	{
		if(window.location == "http://www.landfeasibility.com/contactus.html" || window.location == "http://www.landfeasibility.com/thank-you.html")
		{
			Location = "107 centennial street La Plata MD";	
		}
		else
		{
			Location = document.getElementById("Location").value; 
		}
		
   		   var ValidChars = "0123456789.";
		   var IsNumber=true;
		   var Char;

		   if (ValidChars.indexOf(Location.charAt(0)) == -1) 
		   {
		         zoomfactor = 14;
	       }
		   else
		   {
				zoomfactor = 19;
		   }
		
		Location =Location.replace(/ /g,"%20");
		
		if (window.location == "http://www.landfeasibility.com/contactus.html" || window.location == "http://www.landfeasibility.com/thank-you.html")
		{
			zoomfactor = 16;
			Icon = "RED START";
		}
		
		//Add Clear Button
			mapcode = mapcode + "<img src='http://maps.google.com/maps/api/staticmap?center="+Location+"&zoom="+zoomfactor+"&size=600x450&maptype=hybrid&markers=size:mid|color:0xFFFF00|label:Site|"+Location+"&sensor=false\&key=ABQIAAAAc6MK6AIvRMhUhO1wv9ivTBRzfZCe7mznx3LajBsmUwtI-osSjRRVpFI3X0LSDo88looy18xD7CKCug'>";
			document.getElementById("LandMap").innerHTML = mapcode;
		
		//remove map icon legend
		document.getElementById("mapicons").innerHTML = ""
	}
}

function pageheader ()
{
	//Check Cookie.  then load mapaddresssectiontext()
		var blnSuccess;
			blnSuccess = ajaxUpdate( "ReadAddressCookie.asp", {
			params:"",
			meth:"GET",
			async:false,
			startfunc:"",
			endfunc:"",
			errorfunc:"ajaxError()",
			noauthfunc:"ajaxNoAuth()",
			callfunc:"mapaddresssectiontext()" }
			);
}

function mapaddresssectiontext ()
{
		if (rText.length > 2 || window.location == "http://www.landfeasibility.com/contactus.html" || window.location == "http://www.landfeasibility.com/thank-you.html")
		{
			var aoi;
			document.getElementById("Location").value = rText;
			
			if (rText.length == 2)
			{
				document.getElementById("AddressHeader").innerHTML = "Location Of Interest:";
				document.getElementById("clearbutton").innerHTML = "";
			}
			else
			{
				document.getElementById("AddressHeader").innerHTML = "Current Address Of Interest:";
			}
			if (window.location == "http://www.landfeasibility.com/education.html")
			{
				showvideo ()
			}
			else
			{
				drawmap ()
			}
		}
		else
		{
			document.getElementById("AddressHeader").innerHTML = "Location Of Interest:";
			document.getElementById("clearbutton").innerHTML = "";
			if (window.location == "http://www.landfeasibility.com/education.html")
			{
				showvideo ()
			}		
		}
}

function mapitempty (field,text)
{
	var str = document.getElementById(field).value;
	if (str.length == 0)
	{
		document.getElementById(field).value = text;
	}
	
	if (field == "State")
	{
		//Do Noting - Its a PullDown
	}
	else
	{
		firstLetterUpper(field);
	}
}
function mapitaddentry (field)
{
	if (document.getElementById(field).value == "Street")
	{
		document.getElementById(field).value = "";
	}
		if (document.getElementById(field).value == "City")
	{
		document.getElementById(field).value = "";
	}
		if (document.getElementById(field).value == "")
	{
		
	}
		if (document.getElementById(field).value == "ZipCode")
	{
		document.getElementById(field).value = "";
	}
}

function firstLetterUpper(field) {
	//var fld = document.getElementById(field);
	//fld.value = fld.value.toUpperCase();
}

function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}