/* 
	Purpose: Creates the form that holds the forum entry or creates the button that will display the form when clicked
	Results: Displays a form or a button
	Page(s) of use: forum.php
*/
function new_thread_form(value)
{
	if(value == "cancel")
		document.getElementById("new_thread").innerHTML = "<button type=button onclick='new_thread_form(\"yes\");'>New Thread</button>";
	else
	{
		var response = "<button type=button onclick='new_thread_form(\"cancel\");'>Cancel</button>";
		response = response + "<table border=0 cellpadding=0 cellspacing=0 width=90%>";
			response = response + "<tr><td class=center>Creator</td><td><input type='text' name='creator' id='creator'></input></td></tr>";
			response = response + "<tr><td class=center>Topic:</td><td><input type='text' name='topic' id='topic'></input></td></tr>";
			response = response + "<tr><td class=center>Content:</td><td><textarea class=input_thread name='content' id='content' visible='visible'></textarea></td></tr>";
			response = response + "<tr><td class='center'><input type='checkbox' name='id' id='tos' value='yes'></input></td><td><a href''>TOS</a></td></tr>";
			response = response + "<tr><td><button type='button' onclick='forum_Val(document.getElementById(\"creator\"),document.getElementById(\"topic\"),document.getElementById(\"content\"),document.getElementById(\"tos\"));'>Submit</button></td></tr>";						
		response = response + "</table>";
		document.getElementById("new_thread").innerHTML = response;
	}
}

/*
	Purpose: To call the validation functions
	Results: False if any of the checks fail; else true
	Page(s) of use: functions.js
*/
function forum_Val(creator,topic,content,tos)
{
	if(valBlank(creator,"Please enter your name") && valBlank(topic,"Please enter in a topic for your post") && valBlank(content, "Please add content to your post") && checkreqired(tos, "You must accept our terms of service to continue"))
		newThread(topic, creator, content, 0);
	else
		return false;
}

/* 
	Purpose: Creates the form that holds the forum response entry or creates the button that will display the form when clicked
	Results: Displays a form or a button
	Page(s) of use: thread_display.php
*/
function new_response_form(value, parent)
{
	if(value == "cancel")
		document.getElementById("new_response").innerHTML = "<button type=button onclick='new_response_form(\"yes\"," + parent + ");'>Post Response</button>";
	else
	{
		var response = "<button type=button onclick='new_response_form(\"cancel\"," + parent + ");'>Cancel</button>";
		response = response + "<table border=0 cellpadding=0 cellspacing=0 width=90%>";
			response = response + "<tr><td>Creator</td><td><input type='text' name='creator' id='creator'></input></td></tr>";
			response = response + "<tr><td>Content:</td><td><textarea class='input_thread' name='content' id='content' visible='visible'></textarea></td></tr>";
			response = response + "<tr><td class='center'><input type='checkbox' name='id' id='tos' value='yes'></input></td><td><a href''>TOS</a></td></tr>";
			response = response + "<tr><td><button type='button' onclick='response_Val(document.getElementById(\"creator\"),document.getElementById(\"content\"),document.getElementById(\"tos\")," + parent + ");'>Submit</button></td></tr>";						
		response = response + "</table>";
		document.getElementById("new_response").innerHTML = response;
	}
}

/*
	Purpose: To call the validation functions
	Results: False if any of the checks fail; else true
	Page(s) of use: functions.js
*/
function response_Val(creator,content,tos,parent)
{
	if(valBlank(creator,"Please enter your name") && valBlank(content, "Please add content to your post") && checkreqired(tos, "You must accept our terms of service to continue"))
		newResponse(creator, content, parent);
	else
		return false;
}

/*
	Purpose: Display the mailing list entry form
	Results: The form is either displed or not.
	Page(s) of use: about.php
*/
function mail_list(value)
{
	if(value == "cancel")
		document.getElementById("mail_list").innerHTML = "<p><a class=cursorchange title=Register Now! onclick='mail_list(\"yes\");'>Register now</a> to join our <b>Mailing</b> <i>list!</i></p>";
	else
	{
		response = "<h3>Membership to the Mailing List mailer@newqueensdemocrats.com</h3>";
		response = response + "<form action=http://kundenserver.de/cgi-bin/mailinglist.cgi method=post target=_BLANK onsubmit='return(email_Val(document.getElementById(\"mailaccount_r\"),document.getElementById(\"mailaccount2_r\")))';>";
			response = response + "<input name=subscribe_r type=radio value=subscribe checked=checked> Yes, I want to become a member of the mailing list mailer@newqueensdemocrats.com.";
			response = response + "<br>";
			response = response + "<input name=subscribe_r type=radio value=unsubscribe>Please remove me from mailing list mailer@newqueensdemocrats.com.";
			response = response + "<br>";
			response = response + "Enter your e-mail address:";
			response = response + "<br>";
			response = response + "<input maxlength=51 name=mailaccount_r id=mailaccount_r size=51 text=text>";
			response = response + "<br>";
			response = response + "Please confirm your e-mail address:";
			response = response + "<br>";
			response = response + "<input maxlength=51 name=mailaccount2_r id=mailaccount2_r size=51 text=text>";
			response = response + "<br>";
			response = response + "<input type=submit value=Send>";
			response = response + "<input type=reset value=Reset>";
			response = response + "<button type=button onclick='mail_list(\"cancel\");'>Cancel</button>";
			response = response + "<input name=FBMLNAME type=hidden value=mailer@newqueensdemocrats.com>";
			response = response + "<input name=FBLANG type=hidden value=en>"
			response = response + "<input name=FBURLERROR_L type=hidden value=http://kundenserver.de/mailinglist/error.en.html>";
			response = response + "<input name=FBURLSUBSCRIBE_L type=hidden value=http://kundenserver.de/mailinglist/subscribe.en.html>";
			response = response + "<input name=FBURLUNSUBSCRIBE_L type=hidden value=http://kundenserver.de/mailinglist/unsubscribe.en.html>";
			response = response + "<input name=FBURLINVALID_L type=hidden value=http://kundenserver.de/mailinglist/invalid.en.html>";
		response = response + "</form>";	
		document.getElementById("mail_list").innerHTML = response;
	}
}

/*
	Purpose: To call the validation functions
	Results: False if any of the checks fail; else true
	Page(s) of use: functions.js
*/
function email_Val(e_addr_one, e_addr_two)
{
	if(valEmail(e_addr_one) && valEmail(e_addr_two) && match(e_addr_one, e_addr_two, "The entered emails do not match."))
	{
		mail_list("cancel");
		return true;
	}
	else
		return false;
}

/*
	Purpose: Display the news letter entry form
	Results: The form is either displed or not.
	Page(s) of use: index.php
*/
function news_letter(value)
{
	if(value == "cancel")
		document.getElementById("news_letter").innerHTML = "";
	else
	{
		var response = "<div class=special>";
			response = response + "<h3>Sign Up for New Queens Democrats News Letter</h3>";
			response = response + "<form action=http://www.newqueensdemocrats.com/tinc method=post accept-charset=utf-8 target=_BLANK onsubmit='return(news_Val(document.getElementById(\"title\"),document.getElementById(\"f_name\"),document.getElementById(\"l_name\"),document.getElementById(\"e_mail\")))';>";
				response = response + "<input type=hidden name=try value=true />";
				response = response + "<input type=hidden name=RegistrationFormID value=63237 />";
				response = response + "<input type=hidden name=key value=SQYf6f8K />";
				response = response + "<table cellpadding=2 cellspacing=1>";
				response = response + "<tr><td>Title</td><td><input type=text name=Title size=4 id=title /></td></tr>";
				response = response + "<tr><td>First name:<strong>*</strong></td><td><input type=text name=FirstName size=25 id=f_name /></td></tr>";
				response = response + "<tr><td>Last name:<strong>*</strong></td><td><input type=text name=Name size=25 id=l_name /></td></tr>";
				response = response + "<tr><td>E-mail:<strong>*</strong></td><td><input type=text name=EMail size=30 id=e_mail /></td></tr>";
				response = response + "<tr><td><button type=button onclick='news_letter(\"cancel\");'>Cancel</button></td><td colspan=3><input type=submit class=submit style=float:right value=Subscribe /></td></tr>";
				response = response + "</table>";
			response = response + "</form>";	
		response = response + "</div>";
		document.getElementById("news_letter").innerHTML = response;
	}
}

/*
	Purpose: To call the validation functions
	Results: False if any of the checks fail; else true
	Page(s) of use: functions.js
*/
function news_Val(title, f_name, l_name, e_email)
{
	if(valBlank(title,"Please enter your title") && valBlank(f_name,"Please enter your first name") && valBlank(l_name,"Please enter your last name") && valEmail(e_email))
	{
		mail_list("cancel");
		return true;
	}
	else
		return false;
}


/* -------------------------------------------------------------------------------------------- */
var map;
var geoXml;

/*
	Purpose: To load a google map
	Results: A google map is displayed showing assembly district 22.
	Page(s) of use: map.php
*/
function load() 
{
	if (GBrowserIsCompatible()) 
	{
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		var lsc = new google.maps.LocalSearch(); 
		map.addControl(new google.maps.LocalSearch());
		
		geoXml = new GGeoXml("http://newqueensdemocrats.com/images/kml/assembly.kml");
		map.addOverlay(geoXml);
		
		map.setCenter(new GLatLng(40.69616179729754,-73.81071612018749), 11);
	}
	else
		alert("Browser is not compatible");
}

/*
	Purpose: To change the map overlaw
	Results: A google map is displayed with a new overlay of user choice
	Page(s) of use: map.php
*/
function over(map_name)
{
	map.removeOverlay(geoXml);
	geoXml = new GGeoXml("http://newqueensdemocrats.com/images/kml/" + map_name);
	map.addOverlay(geoXml);
}
