//-----------FORM HIGHLIGHT
//Highlight form element- © Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com

var highlightcolor="lightyellow"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}




//---EMAIL VERIFY
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function emailvalid(email){
	var returnval=emailfilter.test(email)
	return returnval
}





var bad_state='Answers FAQs about which state to register in.';
	var email_error='Looks like your email address is not using a valid format. Please fix it.';
	var close_me='Close Me!';
	
	var er_ND='North Dakota does not have voter registration. For more information, contact your Secretary of State at 701-328-3660 or visit http://www.nd.gov/sos';
	var er_NH='New Hampshire town and city clerks cannot accept this form as a means of voter registration. New Hampshire has Election Day voter registration. For information about registering to vote, contact your town or city clerk. These addresses are listed on the Secretary of State web site at http://www.state.nh.us/sos/clerks.htm. You can also contact your Secretary of State at 603-271-3242 or visit http://www.state.nh.us/sos/electionsnew.htm';
	var er_WY='Wyoming cannot accept the National Voter Registration Form under state law. To learn how to register in Wyoming, contact the county clerk of the county in which you reside. A list of county clerks is available at http://soswy.state.wy.us/election/clerks.htm or call 307-777-3573.';





/********************************************************************

Popup Windows - V 4.4
Author: Brian Gosselin
Site URL: http://scriptasylum.com
Read the "releasenotes.txt" for supported features and release notes.

************** EDIT THE LINES BELOW AT YOUR OWN RISK ****************/

var w3c=(document.getElementById)? true: false;
var ns4=(document.layers)?true:false;
var ie5=(w3c && document.all)? true : false;
var ns6=(w3c && !document.all)? true: false;
var d=document;
currIDb=null; xoff=0; yoff=0;
currRS=null; rsxoff=0; rsyoff=0;
oldac=null; newac=null; zdx=1; mx=0; my=0;
var currFb=null; var currFs=null; var currFID=0; var currFcnt=0;
var cidlist=new Array();

//******* START OF EXPOSED FUNCTIONS. THESE CAN BE USED IN HYPERLINKS. *******\\

function fadeboxin(id){
if((currFb==null) && w3c){
clearInterval(currFID);
currFb=d.getElementById(id+'_b');
currFs=d.getElementById(id+'_s');
if(currFb.style.display=='none'){
currFcnt=0;
if(ie5)currFb.style.filter=currFs.style.filter="alpha(opacity=0)";
else currFb.style.MozOpacity=currFs.style.MozOpacity=0;
hideAllScrollbars();
currFb.style.display=currFs.style.display='block';
changez(currFb);
currFID=setInterval('sub_fadein()',20);
}else currFb=null;
}}

function fadeboxout(id){
if((currFb==null) && w3c){
clearInterval(currFID);
currFb=d.getElementById(id+'_b');
currFs=d.getElementById(id+'_s');
if(currFb.style.display=='block'){
currFcnt=100;
if(ie5){
currFb.style.filter="alpha(opacity=100)";
currFs.style.filter="alpha(opacity=50)";
}else{
currFb.style.MozOpacity=1;
currFs.style.MozOpacity=.5;
}
hideAllScrollbars();
currFb.style.display=currFs.style.display='block';
changez(currFb);
currFID=setInterval('sub_fadeout()',20);
}else currFb=null;
}}

function hidebox(id){
if(w3c){
//if(currFb!=d.getElementById(id+'_b')){
d.getElementById(id+'_b').style.display='none';
d.getElementById(id+'_s').style.display='none';
//}
}}

function showbox(id){
if(w3c){
var bx=d.getElementById(id+'_b');
var sh=d.getElementById(id+'_s');
bx.style.display='block';
sh.style.display='block';
sh.style.zIndex=++zdx;
bx.style.zIndex=++zdx;
if(ns6){
bx.style.MozOpacity=1;
sh.style.MozOpacity=.5;
}else{
bx.style.filter="alpha(opacity=100)";
sh.style.filter="alpha(opacity=50)";
}
changez(bx);
}}

function changecontent(id,text){
if(!document.getElementById(id+'_b').isExt){
var d=document.getElementById(id+'_c');
if(ns6)d.style.overflow="hidden";
d.innerHTML=text;
if(ns6)d.style.overflow="block";
}else document.getElementById(id+'_ifrm').src=text;
}

function movePopup(ids,x,y){
if(w3c){
var idb=document.getElementById(ids+'_b');
var ids=document.getElementById(ids+'_s');
idb.style.left=x+'px';
ids.style.left=x+8+'px';
idb.style.top=y+'px';
ids.style.top=y+8+'px';
}}

function resizePopup(ids,rx,ry){
if(w3c){
if(d.getElementById(ids+'_rs').rsEnable){
d.gEl=d.getElementById;
d.gEl(ids+"_extWA").style.display="block";
d.gEl(ids+"_rs").style.left=Math.max(rx,((ie5)?88:92))+'px';
d.gEl(ids+"_rs").style.top=Math.max(ry,((ie5)?68:72))+'px';
d.gEl(ids+"_b").style.width=Math.max(rx+((ie5)?12:8),100)+'px';
d.gEl(ids+"_b").style.height=Math.max(ry+((ie5)?12:8),80)+'px';
d.gEl(ids+"_t").style.width=Math.max(rx+((ie5)?4:3),((ns6)?95:92))+'px';
d.gEl(ids+"_btt").style.left=parseInt(d.gEl(ids+"_t").style.width)-48+'px';
d.gEl(ids+"_s").style.width=Math.max(rx+12,((ie5)?100:104))+'px';
d.gEl(ids+"_s").style.height=Math.max(ry+((ie5)?12:13),((ie5)?80:86))+'px';
d.gEl(ids+"_c").style.width=Math.max(rx-((ie5)?-5:5),((ie5)?92:87))+'px';
d.gEl(ids+"_c").style.height=Math.max(ry-((ie5)?24:28),44)+'px';
d.gEl(ids+"_max").h=parseInt(d.gEl(ids+"_b").style.height);
}}}

//******* END OF EXPOSED FUNCTIONS *******\\

function hideAllScrollbars(){
if(document.all){
var id;
for(i=0;i<cidlist.length;i++){
id=cidlist[i];
if(!document.getElementById(id+'_b').isExt)document.getElementById(id+'_c').style.overflow="hidden";
}}}

function showAllScrollbars(){
if(document.all){
var id;
for(i=0;i<cidlist.length;i++){
id=cidlist[i];
if(!document.getElementById(id+'_b').isExt)document.getElementById(id+'_c').style.overflow="auto";
}}}

function sub_fadein(){
currFcnt+=4;
if(ie5){
currFb.style.filter="alpha(opacity="+currFcnt+")";
currFs.style.filter="alpha(opacity="+(currFcnt/2)+")";
}else{
currFb.style.MozOpacity=currFcnt/100;
currFs.style.MozOpacity=(currFcnt/2)/100;
}
if(currFcnt>=99){
currFb.style.display=currFs.style.display='block';
showAllScrollbars()
currFb=null;
clearInterval(currFID);
}}

function sub_fadeout(){
currFcnt=currFcnt-4;
if(ie5){
currFb.style.filter="alpha(opacity="+currFcnt+")";
currFs.style.filter="alpha(opacity="+(currFcnt/2)+")";
}else{
currFb.style.MozOpacity=currFcnt/100;
currFs.style.MozOpacity=(currFcnt/2)/100;
}
if(currFcnt<=0){
currFb.style.display=currFs.style.display='none';
showAllScrollbars()
currFb=null;
clearInterval(currFID);
}}

function preloadBttns(){
var btns=new Array();
btns[0]=new Image(); btns[0].src="https://www.govote.org/campaigns/govote/assets/min.gif";
btns[1]=new Image(); btns[1].src="https://www.govote.org/campaigns/govote/assets/max.gif";
btns[2]=new Image(); btns[2].src="https://www.govote.org/campaigns/govote/assets/close.gif";
btns[3]=new Image(); btns[3].src="https://www.govote.org/campaigns/govote/assets/resize.gif";
}
preloadBttns();

function minimize(){
if(w3c){
d.getElementById(this.cid+"_b").style.height=(ie5)? '28px':'24px';
d.getElementById(this.cid+"_s").style.height='28px';
d.getElementById(this.cid+"_c").style.display='none';
d.getElementById(this.cid+"_rs").style.display='none';
ns6bugfix();
}}

function restore(){
if(w3c){
d.getElementById(this.cid+"_b").style.height=this.h+'px';
d.getElementById(this.cid+"_s").style.height=(ie5)? this.h+'px':this.h+5+'px';
d.getElementById(this.cid+"_c").style.display='block';
d.getElementById(this.cid+"_rs").style.display='block';
ns6bugfix();
}}

function ns6bugfix(){
if(navigator.userAgent.indexOf("Netscape/6")>0)setTimeout('self.resizeBy(0,1); self.resizeBy(0,-1);', 100);
}

function trackmouse(evt){
mx=(ie5)?event.clientX+d.body.scrollLeft:evt.pageX;
my=(ie5)?event.clientY+d.body.scrollTop:evt.pageY;
if(!ns6)movepopup();
if((currIDb!=null)||(currRS!=null))return false;
}

function movepopup(){
if((currIDb!=null)&&w3c)movePopup(currIDb.cid,mx+xoff,my+yoff);
if((currRS!=null)&&w3c)resizePopup(currRS.cid,mx+rsxoff,my+rsyoff);
return false;
}

function stopRS(){
d.getElementById(this.cid+"_extWA").style.display="none";
currRS=null;
}

function startRS(evt){
var ex=(ie5)?event.clientX+d.body.scrollLeft:evt.pageX;
var ey=(ie5)?event.clientY+d.body.scrollTop:evt.pageY;
rsxoff=parseInt(this.style.left)-ex;
rsyoff=parseInt(this.style.top)-ey;
currRS=this;
if(ns6)d.getElementById(this.cid+"_c").style.overflow='hidden';
return false;
}

function changez(v){
var th=(v!=null)?v:this;
if(oldac!=null)d.getElementById(oldac.cid+"_t").style.backgroundColor=oldac.inactivecolor;
if(ns6)d.getElementById(th.cid+"_c").style.overflow='auto';
oldac=th;
d.getElementById(th.cid+"_t").style.backgroundColor=th.activecolor;
d.getElementById(th.cid+"_s").style.zIndex=++zdx;
th.style.zIndex=++zdx;
d.getElementById(th.cid+"_rs").style.zIndex=++zdx;
}

function stopdrag(){
currIDb=null;
document.getElementById(this.cid+"_extWA").style.display="none";
ns6bugfix();
}

function grab_id(evt){
var ex=(ie5)?event.clientX+d.body.scrollLeft:evt.pageX;
var ey=(ie5)?event.clientY+d.body.scrollTop:evt.pageY;
xoff=parseInt(d.getElementById(this.cid+"_b").style.left)-ex;
yoff=parseInt(d.getElementById(this.cid+"_b").style.top)-ey;
currIDb=d.getElementById(this.cid+"_b");
currIDs=d.getElementById(this.cid+"_s");
d.getElementById(this.cid+"_extWA").style.display="block";
return false;
}

function subBox(x,y,w,h,bgc,id){
var v=d.createElement('div');
v.setAttribute('id',id);
v.style.position='absolute';
v.style.left=x+'px';
v.style.top=y+'px';
v.style.width=w+'px';
v.style.height=h+'px';
if(bgc!='')v.style.backgroundColor=bgc;
v.style.visibility='visible';
v.style.padding='0px';
return v;
}

function get_cookie(Name) {
var search=Name+"=";
var returnvalue="";
if(d.cookie.length>0){
offset=d.cookie.indexOf(search);
if(offset!=-1){
offset+=search.length;
end=d.cookie.indexOf(";",offset);
if(end==-1)end=d.cookie.length;
returnvalue=unescape(d.cookie.substring(offset,end));
}}
return returnvalue;
}

function popUp(x,y,w,h,cid,text,bgcolor,textcolor,fontstyleset,title,titlecolor,titletextcolor,bordercolor,scrollcolor,shadowcolor,showonstart,isdrag,isresize,oldOK,isExt,popOnce){
var okPopUp=false;
if (popOnce){
if (get_cookie(cid)==""){
okPopUp=true;
d.cookie=cid+"=yes"
}}
else okPopUp=true;
if(okPopUp){
if(w3c){
cidlist[cidlist.length]=cid;
w=Math.max(w,100);
h=Math.max(h,80);
var rdiv=new subBox(w-((ie5)?12:8),h-((ie5)?12:8),7,7,'',cid+'_rs');
if(isresize){
rdiv.innerHTML='<img src="https://www.govote.org/campaigns/govote/assets/resize.gif" width="7" height="7">';
rdiv.style.cursor='move';
}
rdiv.rsEnable=isresize;
var tw=(ie5)?w:w+4;
var th=(ie5)?h:h+6;
var shadow=new subBox(x+8,y+8,tw,th,shadowcolor,cid+'_s');
if(ie5)shadow.style.filter="alpha(opacity=50)";
else shadow.style.MozOpacity=.5;
shadow.style.zIndex=++zdx;
var outerdiv=new subBox(x,y,w,h,bordercolor,cid+'_b');
outerdiv.style.display="block";
outerdiv.style.borderStyle="outset";
outerdiv.style.borderWidth="2px";
outerdiv.style.borderColor=bordercolor;
outerdiv.style.zIndex=++zdx;
tw=(ie5)?w-8:w-5;
th=(ie5)?h+4:h-4;
var titlebar=new subBox(2,2,tw,20,titlecolor,cid+'_t');
titlebar.style.overflow="hidden";
titlebar.style.cursor="default";
var tmp=(isresize)?'<img src="https://www.govote.org/campaigns/govote/assets/min.gif" width="16" height="16" id="'+cid+'_min"><img src="https://www.govote.org/campaigns/govote/assets/max.gif" width="16" height="16"  id="'+cid+'_max">':'';
titlebar.innerHTML='<div style="background: url(\'../campaigns/govote/assets/popbg.gif\');height:160px;"><span style="position:absolute; left:3px; top:1px; font:bold 10pt sans-serif; color:'+titletextcolor+'; height:18px; overflow:hidden; clip-height:16px;">'+title+'</span><div id="'+cid+'_btt" style="position:absolute; width:48px; height:16px; left:'+(tw-48)+'px; top:2px; text-align:right">'+tmp+'<img src="https://www.govote.org/campaigns/govote/assets/close.gif" width="16" height="16" id="'+cid+'_cls"></div></div>';
tw=(ie5)?w-7:w-13;
var content=new subBox(2,24,tw,h-36,bgcolor,cid+'_c');
content.style.borderColor=bordercolor;
content.style.borderWidth="2px";
if(isExt){
content.innerHTML='<iframe id="'+cid+'_ifrm" src="https://www.govote.org/campaigns/govote/assets/'+text+'" width="100%" height="100%"></iframe>';
content.style.overflow="hidden";
}else{
if(ie5)content.style.scrollbarBaseColor=scrollcolor;
content.style.borderStyle="inset";
content.style.overflow="auto";
content.style.padding="0px 2px 0px 0px";
content.innerHTML=text;
content.style.font=fontstyleset;
content.style.color=textcolor;
}
var extWA=new subBox(2,24,0,0,'',cid+'_extWA');
extWA.style.display="none";
extWA.style.width='100%';
extWA.style.height='100%';
outerdiv.appendChild(titlebar);
outerdiv.appendChild(content);
outerdiv.appendChild(extWA);
outerdiv.appendChild(rdiv);
d.body.appendChild(shadow);
d.body.appendChild(outerdiv);
d.gEl=d.getElementById;
if(!showonstart)hidebox(cid);
var wB=d.gEl(cid+'_b');
wB.cid=cid;
wB.isExt=(isExt)?true:false;
var wT=d.gEl(cid+'_t');
wT.cid=cid;
if(isresize){
var wRS=d.gEl(cid+'_rs');
wRS.cid=cid;
var wMIN=d.gEl(cid+'_min');
wMIN.cid=cid;
var wMAX=d.gEl(cid+'_max');
wMAX.h=h;
wMAX.cid=cid;
wMIN.onclick=minimize;
wMAX.onclick=restore;
wRS.onmousedown=startRS;
wRS.onmouseup=stopRS;
}
var wCLS=d.gEl(cid+'_cls');
var wEXTWA=d.gEl(cid+'_extWA');
wB.activecolor=titlecolor;
wB.inactivecolor=scrollcolor;
if(oldac!=null)d.gEl(oldac.cid+"_t").style.backgroundColor=oldac.inactivecolor;
oldac=wB;
wCLS.onclick=new Function("hidebox('"+cid+"');");
wB.onmousedown=function(){ changez(this) }
if(isdrag){
wT.onmousedown=grab_id;
wT.onmouseup=stopdrag;
}
}else{
if(oldOK){
var ctr=new Date();
ctr=ctr.getTime();
var t=(isExt)?text:'';
var posn=(ns4)? 'screenX='+x+',screenY='+y: 'left='+x+',top='+y;
var win=window.open(t , "abc"+ctr , "status=no,menubar=no,width="+w+",height="+h+",resizable="+((isresize)?"yes":"no")+",scrollbars=yes,"+posn);
if(!isExt){
t='<html><head><title>'+title+'</title></head><body bgcolor="'+bgcolor+'"><font style="font:'+fontstyleset+'; color:'+textcolor+'">'+text+'</font></body></html>';
win.document.write(t);
win.document.close();
}}}}}

if(ns6)setInterval('movepopup()',40);

if(w3c){
d.onmousemove=trackmouse;
d.onmouseup=new Function("currRS=null");
}


//check if the following radio buttons are checked
//-former name
//-former address
//-mailing list
//if so, show the proper fields
function doload(){
	if (get_radio_value('cu__update')=='yes'){
		manage_hiddens('reg_extras_on');
		if (get_radio_value('cu__update_type')=='name_only'){manage_hiddens('row_prev_name');}
		if (get_radio_value('cu__update_type')=='address_only'){manage_hiddens('row_home_addr_prev');}
		if (get_radio_value('cu__update_type')=='both'){manage_hiddens('both');}
	}
	if (get_radio_value('mailing_exists')=='yes'){
		set_mailing(true);
		show_or_hide('show','row_mailing_addr');
	}
}


function launch_help(width,height,url){
	var launchvars="status=yes,toolbar=no,scrollbars=no,width="+width+",height="+height;
	newWind=window.open(url,"newWindow",launchvars);
}

//---------LAZY MAN'S VAR TRACKING---
//vars that track if user wants to update or register for first time
var first_timer=true;
var old_timer=false;
var oldtimer_action="";
function set_first_timer(){
	first_timer=true;
	old_timer=false;
}
function set_old_timer(){
	old_timer=true;
	first_timer=false;
}
function set_oldtimer_action(action){
	oldtimer_action=action;
}
var mailing_exists=false;
function set_mailing(tf_switch){
	mailing_exists=tf_switch;
}
from_confirm=false;
function set_from_confirm(tf_switch){
	from_confirm=tf_switch;
}

//---------STYLE & STEP MANAGEMENT----
//combine this all into one array when not tired...

var step1_shown=false;
var step2_shown=false;
var step3_shown=false;
var step4_shown=false;
var step5_shown=false;
var step6_shown=false;
var step7_shown=false;

var step1_array= new Array();
step1_array[0]=new Array('row_eighteen','tr1');
step1_array[1]=new Array('row_citizen','tr2');
step1_array[2]=new Array('row_update','tr1');
step1_array[3]=new Array('row_update_extras','tr1');
step1_array[4]=new Array('row_optin','tr2');
step1_array[5]=new Array('row_step1_buttons','buttons');



var step2_array= new Array();
step2_array[0]=new Array('row_curr_name','tr1');
step2_array[1]=new Array('row_prev_name','tr1');
step2_array[2]=new Array('row_tele','tr2');
step2_array[3]=new Array('row_race','tr1');
step2_array[4]=new Array('row_step2_buttons','buttons');

var step3_array= new Array();
step3_array[0]=new Array('row_home_addr_curr','tr1');
step3_array[1]=new Array('row_home_addr_prev','tr2');
step3_array[2]=new Array('row_mailing_addr_toggle','tr2');
step3_array[3]=new Array('row_mailing_addr','tr2');
step3_array[4]=new Array('row_step3_buttons','buttons');

var step4_array= new Array();
step4_array[0]=new Array('row_dob','tr2');
step4_array[1]=new Array('row_id','tr1');
step4_array[2]=new Array('row_party','tr2');
step4_array[3]=new Array('row_step4_buttons','buttons');

var step5_array= new Array();
step5_array[0]=new Array('confirm_placeholder','tr1');
//step5_array[1]=new Array('row_step5_buttons','buttons');

var step6_array= new Array();
step6_array[0]=new Array('pdf_placeholder','tr1');

var step7_array= new Array();
step7_array[0]=new Array('taf','tr1');

//---DYNAMIC SCREEN UPDATES
function show_or_hide(action,elm_id){
	//alert (document.getElementById(elm_id));
	switch (action){
		case "show":
			changeOpac(0, elm_id);
			manage_css('remove',document.getElementById(elm_id),'hidden');
			opacity(elm_id, 0, 100, 500);
			break;
		case "hide":
			manage_css('add',document.getElementById(elm_id),'hidden');
	}	
}
var row_prev_name_on=false;
var row_home_addr_prev_on=false;

function manage_hiddens(action){
	switch (action){
		case "reg_extras_on":
			show_or_hide('show','row_update_extras');
				if (row_prev_name_on){show_or_hide('show','row_prev_name');}
				if (row_home_addr_prev_on){show_or_hide('show','row_home_addr_prev');}
			break;
		case "reg_extras_off":
			show_or_hide('hide','row_update_extras');
			show_or_hide('hide','row_prev_name');
			show_or_hide('hide','row_home_addr_prev');
			break;
		case "row_prev_name":
			show_or_hide('show','row_prev_name');
			show_or_hide('hide','row_home_addr_prev');
			row_prev_name_on=true;
			row_prev_name_addr=false;
			break;
		case "row_home_addr_prev":
			show_or_hide('show','row_home_addr_prev');
			show_or_hide('hide','row_prev_name');
			row_home_addr_prev_on=true;
			row_prev_name_on=false;
			break;
		case "both":
			show_or_hide('show','row_prev_name');
			show_or_hide('show','row_home_addr_prev');
			row_prev_name_on=true;
			row_home_addr_prev_on=true;
			break;
	}
}



//breadcrumb nav
function show_step_nav(step_num){
	var step_nav_handler=step_num+"_controls";
	show_or_hide('show',step_nav_handler);
}

function validate_step2(){
	clear_default_vals_step2();
	var fieldRequired = Array("na_current__prefix", "na_current__fname", "na_current__lname");
	var fieldDescription = Array(er_prefix, er_fname, er_lname);
	
	/*WA doesnt want to make this required anymore
	if (get_radio_value('cu__update')=='yes'){
		if ( (get_radio_value('cu__update_type')=="name_only") || (get_radio_value('cu__update_type')=="both") ){
			fieldRequired.push("na_previous__prefix","na_previous__fname", "na_previous__lname");
			fieldDescription.push(er_prefix,er_prevname, er_prevlname);
		}
	}
	*/
	
	var phone_num=document.regform.ph__number.value;
	if (phone_num!= ""){
		if (phone_num.length != 10){
			return (phone_num_length_er);
		}
		if (!IsNumeric(phone_num)){
			return (phone_num_length_er);
		}
	}
	return(form_fillcheck(document.regform,fieldRequired,fieldDescription));
}
function validate_step3(){
	clear_default_vals_step3();
	//check zip code length
		var zip_return="";
		var zipvalue=document.regform.ad_current__zip.value;
		if ( (zipvalue.length != 5) || (!IsNumeric(zipvalue)) ){
			zip_return=zip_length_er+"<BR>";
		}
		
	var fieldRequired_3 = Array("ad_current__line1","ad_current__city","ad_current__zip");
	var fieldDescription_3 = Array(er_adr1, er_city, er_zip)
	
	/*WA doesnt want to make this required anymore
	if (get_radio_value('cu__update')=='yes'){
		if ( (get_radio_value('cu__update_type')=="address_only") || (get_radio_value('cu__update_type')=="both") ){
			fieldRequired_3.push("ad_previous__line1", "ad_previous__city", "ad_previous__state", "ad_previous__zip");
			fieldDescription_3.push(er_prevaddr, er_prevcity, er_prevstate, er_prevzip);
			zip_array.push("ad_previous__zip");
		}
	}
	if (get_radio_value('mailing_exists')=='yes'){
		fieldRequired_3.push("ad_mailing__line1", "ad_mailing__city", "ad_mailing__state", "ad_mailing__zip");
		fieldDescription_3.push(er_mailing, er_mailcity, er_mailstate, er_mailzip);
		zip_array.push("ad_mailing__zip");
	}
	
	
	for (var i = 0; i < zip_array.length; i++){
		var ziphandler=eval("document.regform."+zip_array[i]);
		var zipvalue=ziphandler.value;
		//alert (zipvalue.length + zipvalue);
		if (zipvalue.length != 5){
			//alert ('lenght');
			return (zip_length_er);
		}
		if (!IsNumeric(zipvalue)){
			//alert ('number');
			return (zip_length_er);
		}
	}
	*/
	return(form_fillcheck(document.regform,fieldRequired_3,fieldDescription_3)+zip_return);
}

function validate_step4(){
	var fieldRequired_4 = Array("ident_num","pr__bDay","pr__bMonth","pr__bYear");
	var fieldDescription_4 = Array(er_id,er_bday,er_bmonth,er_byear);
	return(form_fillcheck(document.regform,fieldRequired_4,fieldDescription_4));
}
				
var step_now_showing="step1";
function step_display(step_num_to_show){

	//do data validations
	switch (step_num_to_show){
		case "step2":
			var eighteen_value=get_radio_value('eighteen');
			if ( (!eighteen_value) || (eighteen_value=='no')){ 
				make_pop('bad18',bad_age);
				return;
			}
			var cit_value=get_radio_value('citizen');
			if ( (!cit_value) || (cit_value=='no')){ 
				make_pop('badCit',bad_citizen);
				return;
			}
			break;
		case "step3":
			var er_msg=validate_step2();
			if (er_msg){
				make_pop('step2',er_msg);
				return;
			}
			break;
		case "step4":
			var er_msg=validate_step3();
			if (er_msg){
				make_pop('step3',er_msg);
				return;
			}
			break;
	}
	
	
	
	
	//hide current step
		var curr_step_array_handler=eval(step_now_showing+"_array");
		for (var i=0; i<curr_step_array_handler.length; i++){
			show_or_hide('hide',curr_step_array_handler[i][0]);
		}
	
	
	
	//show next step
		var next_step_array_handler=eval(step_num_to_show+"_array");
		for (var i=0; i<next_step_array_handler.length; i++){
			var row_name=next_step_array_handler[i][0];
			
			var showit=true;
			switch (row_name){
				case "row_update_extras":
					if (get_radio_value('cu__update')=='no'){showit=false;}//dont show extras options if this person is not an oldtimer
					break;
				case "row_prev_name":
					if ( (get_radio_value('cu__update')=='no') || ((get_radio_value('cu__update')=='yes') && ((get_radio_value('cu__update_type')== "address_only"))) ){showit=false;} //dont show former name options if person hasnt requested them
					break;
				case "row_home_addr_prev":
					if ( (get_radio_value('cu__update')=='no') || ((get_radio_value('cu__update')=='yes') && ((get_radio_value('cu__update_type')== "name_only"))) ){showit=false;}  //dont show former addr options if person hasnt requested them
					break;
				case "row_mailing_addr":
					if (get_radio_value('mailing_exists')=='no'){showit=false;} //dont show mailing addr if no user request
					break;	
			}
			if (showit){
				show_or_hide('show',row_name);
				manage_css('add',document.getElementById(next_step_array_handler[i][0]),next_step_array_handler[i][1]); //add the appropriate rowstyle
			}
		}					
			
	//do ONE TIME per step peculiarities
		switch (step_num_to_show){
			case "step1":
				step1_shown=true;
				break;
			case "step2":
				if (!step2_shown){show_step_nav('step2');}
				step2_shown=true;
				break;
			case "step3":
				if (!step3_shown){show_step_nav('step3');}
				step3_shown=true;
				break;
			case "step4":
				if (!step4_shown){show_step_nav('step4');}
				step4_shown=true;
				break;
			case "step5":
				if (!step5_shown){show_step_nav('step5');}
				step5_shown=true;
				break;
			case "step6":
				if (!step6_shown){show_step_nav('step6');}
				step6_shown=true;
				if (from_confirm){
					generatePDF(document.regform); //generate the PDF which will swap out with some text in the step
				}
				break;
			case "step7":
				if (!step7_shown){show_step_nav('step7');}
				step7_shown=true;
				break;
		}
	//set the image
		document.images["img_steps"].src="../campaigns/govote/assets/"+lang+"_govote_"+step_num_to_show+".gif";
		
	//reset now showing var
		step_now_showing=step_num_to_show;
		
}



//----FORM SUBMISSION----
//from index page
function goto_ui(formobj){
	var state_index=formobj.state.selectedIndex;
	state_val=formobj.state.options[state_index].value;
	if ( (state_good(state_val)) ){
		if (email_errors(formobj.em_main__email.value)){
			return;
		}else{
			formobj.submit();
		}
	}
	
}
//VOLUNTEER:
function volunteer(formobj){
	params=Form.serialize(document.volform);//&db=2";
	success_func="vol_success";
	url="sasquatcher.php";
	err_func="server_error";
	alert (params);
	//do_ajax_request(params,url,success_func,err_func);
}
function vol_success(req){
	alert ("in success" + req.responseText);
	swapHTML('volunteer_form', "TEST");
}


//TAF: tell a friend
function tell_friend(formobj){
	if (formobj.friends.value==""){return;}
	params="event=OVR_UserSubmitsTellAFriend&next_template=OVR_TAF_thanks&friends="+formobj.friends.value;//&db=2";
	success_func="tell_friend_success";
	url="sasquatcher.php";
	err_func="server_error";
	alert (params);
	do_ajax_request(params,url,success_func,err_func);

}
function tell_friend_success(req){
	alert ("in success" + req.responseText);
	swapHTML('taf', req.responseText);
}

function taf(formobj){
	document.MYFORM.friends.value=formobj.friends.value;
	document.MYFORM.submit();
}
function taf_success(req){
	alert ('taf success'+req.responseText);
	//var json_data = eval('(' + req.responseText + ')');
	//var this_filename='<p><a href="'+json_data['filename']+'" target="_blank">Your PDF is here</a></p>';
	//alert (this_filename);
	swapHTML('taf', req.responseText);
	
}

//clean out default values
function clear_default_vals_step2(){
	for(var i=0; i<default_vals_step2.length;i++){
		form_handler=eval("document.regform."+default_vals_step2[i][0]);
		//alert (default_vals_step2[i][0]+"---"+form_handler.value+"---"+default_vals_step2[i][1]);
		if (form_handler.value==default_vals_step2[i][1]){
			form_handler.value="";
		}
	}
}
//clean out default values
function clear_default_vals_step3(){
	for(var i=0; i<default_vals_step3.length;i++){
		form_handler=eval("document.regform."+default_vals_step3[i][0]);
		//alert (default_vals_step3[i][0]+"---"+form_handler.value+"---"+default_vals_step3[i][1]);
		if (form_handler.value==default_vals_step3[i][1]){
			form_handler.value="";
		}
	}
}

function do_new_ajax_request(params,url,success_func,err_func){
	success_func=eval(success_func); //make sure ajax func knows that these are scripts
	err_func=eval(err_func);
	alert (params + url);
	var myAjax = new Ajax.Request(
			url, 
			{
				method: 'post', 
				parameters: params, 
				onSuccess: confirm_success,
				onFailure: confirm_error,
				on404: do404error
			});
}
function do404error(){
	alert ('404');
}
function do_confirmation(formobj){
	var er_msg="";

	//eighteen & cit
			var eighteen_value=get_radio_value('eighteen');
			if ( (!eighteen_value) || (eighteen_value=='no')){ 
				er_msg+=bad_age+"<hr>";
			}
			var cit_value=get_radio_value('citizen');
			if ( (!cit_value) || (cit_value=='no')){ 
				er_msg+=bad_citizen+"<hr>";
			}
	//everything else
		//note: js fucks up on false - so am using ""
		var er_msg2="";
		var er_msg3="";
		var er_msg4="";
		
		var er_msg2=validate_step2();
		var er_msg3=validate_step3();
		var er_msg4=validate_step4();
		
		if (er_msg2 != ""){
			//alert ("'2"+er_msg2+"'");
			er_msg+=er_msg2;
		}
		if (er_msg3 != ""){
			//alert ("'3"+er_msg3+"'");
			er_msg+=er_msg3;
		}
		if (er_msg4 != ""){
			//alert ("'4"+er_msg4+"'");
			er_msg+=er_msg4;
		}
		if (er_msg != ""){
			make_pop('step4',er_msg);
			return;
		}
		
	//submit the damn form
		formobj.submit();
}
function get_confirmation(formobj){
	var er_msg=validate_step4();
	if (er_msg){
		make_pop('step4',er_msg);
		return;
	}
	params="next_template=OVR_confirm&event=OVR_UserSubmitsFormData&"+Form.serialize(formobj);//&db=2";
	success_func="confirm_success";
	url="http://www.govote.org/ctrl/sasquatcher.php";
	err_func="server_error";
	//alert (params);
	swapHTML('debug', params);
	do_new_ajax_request(params,url,success_func,err_func);
}
function confirm_error(req){
	alert ("confirm error"+req.status + "--" + req.statusText);
}
function confirm_success(req){
	alert (getAllResponseHeaders());
	alert ("in confirm success" + req.responseText);
	swapHTML('confirm_placeholder', req.responseText);
	step_display('step5');
}


function check_required_fields_for_values(formobj){
	var fieldRequired = Array( "em_main__email", "state", "eighteen", "citizen", "cu__update", "na_current__prefix", "na_current__fname", "na_current__lname", "ad_current__line1","ad_current__city","ad_current__state","ad_current__zip","ident_num" );
	var fieldDescription = Array(er_email, er_State, er_18, er_cit, er_update, er_prefix, er_fname, er_lname, er_adr1,er_city,er_State,er_zip,er_id);
	return(form_fillcheck(formobj,fieldRequired,fieldDescription));
}

//old function - dont think it's used anymore
function check_optional_required_fields_for_values(formobj){
	var fieldRequired = Array();
	var fieldDescription = Array();
	if (get_radio_value('mailing_exists')=='yes'){
		fieldRequired.push("ad_mailing__line1", "ad_mailing__city", "ad_mailing__state", "ad_mailing__zip");
		fieldDescription.push(er_mailing, er_mailcity, er_mailstate, er_mailzip);
	}
	//alert (old_timer);
	
	if (get_radio_value('cu__update')=='yes'){
		//alert ('checking oldtimer');
		var none_selected=true;
		switch (get_radio_value('cu__update_type')){
			case "both":
			case "name_only":
				fieldRequired.push("na_previous__prefix","na_previous__fname", "na_previous__lname");
				fieldDescription.push(er_prefix,er_prevname, er_prevlname);
				none_selected=false;
				break;
			default:
				none_selected=true;
		}
		switch (oldtimer_action){
			case "both":
			case "address_only":
				fieldRequired.push("ad_previous__line1", "ad_previous__city", "ad_previous__state", "ad_previous__zip");
				fieldDescription.push(er_prevaddr, er_prevcity, er_prevstate, er_prevzip);
				none_selected=false;
				break;
			default:
				none_selected=true;
		}
		
		var none_picked="";
		if (none_selected){
			none_picked=er_nonepicked;
		}			
	 } 
	return(form_fillcheck(formobj,fieldRequired,fieldDescription)+none_picked);
}
function submit_to_mailhouse(formobj){
	check_required_fields_for_values(formobj);
	alert ('Sending you information to the mailhouse: TEMP');

}
//MAKE PDF 
function generatePDF(formobj){
	//check_required_fields_for_values(formobj);
		alert (this_uid);
		url="sasquatcher.php";
		params="http://www.govote.org/ctrl/sasquatcher.php?&event=OVR_UserRequestsPDF&next_template=OVR_downloadPDF&"+Form.serialize(formobj);
		success_func="pdf_success";
		alert (params);
		swapHTML('debug', params);
		err_func="server_error";
		do_ajax_request(params,url,success_func,err_func);
}
function pdf_success(req){
	//alert ('pdf success'+req.responseText);
	//var json_data = eval('(' + req.responseText + ')');
	//var this_filename='<p><a href="'+json_data['filename']+'" target="_blank">Your PDF is here</a></p>';
	//alert (this_filename);
	swapHTML('pdf_placeholder', req.responseText);
	
}

function submit_step1(formobj){
	if (email_errors(formobj.em_main__email.value)){return;}
	var fieldRequired = Array("em_main__email", "state");
	var fieldDescription = Array("Email Address", "State");
	if (form_fillcheck(formobj,fieldRequired,fieldDescription)){
		url="sasquatcher.php";
		params=Form.serialize(formobj);//+"&er=on";
		success_func="success";
		err_func="server_error";
		target="m_content";
		//alert (params);
		replaceSnippetWScriptOutput(params,url,success_func,err_func,target,true);
	}
}
function success(req){
	alert (req.responseText);
	var json_data = eval('(' + req.responseText + ')');
}
	
//do an error popup if the email address is not valid
function email_errors(email_addr){
	if (!(emailvalid(email_addr))){
		mypop_text=email_error;
		make_pop('bademail',mypop_text)
		return true;
	}
	return false;
}

//MAKE PUPUPS
var popcounter=0;
function make_pop(mypopname,mytext){
	
	mypopname=mypopname+popcounter;
	var popHander=new popUp(25, posTop()+20, 300, 175, mypopname, mytext+"<p><a href=\"javascript:hidebox('"+mypopname+"');\">"+close_me+"</a></p>", "white", "black", "8pt verdana", "Alert", "white", "black", "white", "gray", "gray", false, true, true, true, false);
	showbox(mypopname);
	popcounter=popcounter+1;
	
	//posTop()is defined in browser_dimensions.js
		
}

//------------DYNAMIC CHECKS & ERRORS------------------------


function dynamic_email_check(email_addr){
	email_errors(email_addr);	
}

	
function state_good(state_val){
	switch (state_val){
		case "NH":
			make_pop('badstate',er_NH);
			return(false);
			break;
		case "WY":
			make_pop('badstate',er_WY);
			return(false);
			break;
		case "ND":
			make_pop('badstate',er_ND);
			return(false);
			break;
		default:
			return(true);
	}	
}

var is_citizen=false;
function check_citizen(formElm){
	switch (formElm.value){
		case "no":
			mypop_text=bad_citizen;
			make_pop('badcitizen',mypop_text);
			is_citizen=false;
			break;
		default:
			is_citizen=true;
			//hidebox('badcitizen');
	}	
}

var is_eighteen=false;
function check_18(formElm){
	switch (formElm.value){
		case "no":
			mypop_text=bad_age;
			make_pop('bad18',mypop_text);
			alertSet=true;
			is_eighteen=false;
			break;
		default:
			is_eighteen=true;
			//hidebox('bad18');
	}	
}


//------------CLEAR FORM------------------------
function clear_it(field_handler,initial_value){
	//alert (field_handler.value+"---"+initial_value);
	if (field_handler.value == initial_value){
		field_handler.value="";
	}
}

//------------HELPERS-----------------------



function tier2(this_copy){
	make_pop('tier2',this_copy);
}

function get_radio_value(formName)
{
formHandler=eval("document.regform."+formName);
//alert (formHandler.length);
//alert (formHandler[0].checked);
//alert (formHandler[0].value);
for (var i=0; i < formHandler.length; i++)
   {
   if (formHandler[i].checked)
      {
      return(formHandler[i].value);
      }
   }
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function has_chars(cText){
	var re = /\w(\w|\s)*/i
	var match = re.test(cText);
	return(match);
}

//---CHECK THAT ALL REQUIRED FORM FIELDS ARE FILLED
function form_fillcheck(formobj,fieldRequired,fieldDescription){
	// dialog message
	var alertMsg = er_alert;
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			
			switch(obj.type){
			case "select-one":
				if (obj.options[obj.selectedIndex].value == ""){
					alertMsg += " - " + fieldDescription[i] + "<br>\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "<br>\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null || (!has_chars(obj.value))){
					alertMsg += " - " + fieldDescription[i] + "<br>\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "<br>\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return "";
	}else{
		return(alertMsg);
		
	}
}





// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
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 posRight() {return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();}


/*
if you want to add an extra column to the right of your page if the page is over a certain width (say 800 pixels) then you include the code for that column in an if statement that tests the page width like this:
if (pageWidth() > 800) {
// code for extra column goes here
}

If you want to test if a given object has moved outside of the browser window we might use code like this:
if (obj.left < posLeft() ||
obj.right > posRight() ||
obj.top < posTop() ||
obj.bottom > posBottom()) {
// not fully visible on screen
}

Another thing you may want to do is toplace an object in a particular position in the window independently of the scroll position of the page. Let's say we want the object to be down 50 pixels and across 100 pixels from the top left corner of the window. Here's code to do this.
obj.top = posTop() + 50;
obj.left = posLeft() + 100;

*/