function make_selection( option, poll_id ){

	//Record the selected option for each poll id
	
	if( eval( "typeof selected_option_"+poll_id+"=='undefined'" ) ){
	
		eval( "selected_option_"+poll_id+"=option;" );
		
		//Show the submit button now that an option has been selected
		document.getElementById("submit_straw_polls_container").className="show";
	
	}else{
	
		//Unselect the previously selected option and select this one
		eval( "document.getElementById('option_'+poll_id+'_'+selected_option_"+poll_id+").src='http://www.strawpolling.com/images/vote/check_grey.png';" );
		eval( "selected_option_"+poll_id+"=option;" );
	
	}

	document.getElementById("option_"+poll_id+"_"+option).src="http://www.strawpolling.com/images/vote/check_green.png";
	document.getElementById("vote_"+poll_id).value=option;

}

//Replace a string with another string
function string_replace(findChars,replacementChars,text){
	//Replace Characters
	var newText="";
	for(var r=0;r<text.length;r++){
		//Set char string to compare
		var charString="";
		//starting at r, create charString to compare findChars with (according to number of chars)
		for(var s=r;s<r+findChars.length&&s<text.length;s++){
			charString+=text.charAt(s);
		}
		//If the charString matches findChars
		if(charString==findChars){
			//add charString to nextText
			newText+=replacementChars;
			//and move on, starting at next unchecked char
			r=r+eval(findChars.length-1);
		}
		else{
			//Add letter to nextText
			newText+=text.charAt(r);
		}
	}
	return newText;
}

function change_element_value(id,type,value){
	//Make sure that the element exists
	if( document.getElementById(id)!=null ){
		eval("document.getElementById('"+id+"')."+type+"='"+value+"'");
		
		//Notify that the element does exist
		return true;
		
	}else{
		//Notify that the element doesn't exist
		return false;	
	}
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function valid_email_address(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true					
}

