function setMiles(){
		which = document.getElementById('miles').value;
		SetCookie("miles",which,0)	
		
}
function SetCookie(cookieName,cookieValue,nDays) {
		 var today = new Date();
		 var expire = new Date();
		 if (nDays==null || nDays==0) nDays=1;
		 expire.setTime(today.getTime() + 3600000*24*nDays);
		 document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
	}
	function recordCount(){
		SetCookie("records_to_show",document.getElementById('records_to_show').value,1);
		SetCookie("page","1",1)	
		document.form1.submit();	
	}
	
	function jumpToPage(){
		
		whichPage = document.getElementById('page').value;
	
		SetCookie("page",whichPage,1);
		document.form1.submit();	
	}

	function clearSearch(){
		SetCookie("search","",1)	
		document.form1.submit();	
	}
	function search(){
		whichPage = document.getElementById('search').value;
		SetCookie("search",whichPage,1);
		SetCookie("page","1",1)	
		document.form1.submit();	
	}	
function checkCleared(cleared){
		if (cleared==1){
			alert("The poll results have been cleared!");	
		}
	}

	function confirmDelete(ID,page){
		if (confirm("Delete this Question? This action cannot be undone.")){
				document.location = "deleteQuestion.asp?id=" + ID + "&page=" + page;
		}
	}
	function confirmClear(ID,page){
		if (confirm("Clear this Poll? This action cannot be undone.")){
				document.location = "clearQuestion.asp?id=" + ID + "&page=" + page;
		}
	}
	
	
function numbersonly(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=45){ //if the key isn't the period key (which we should allow)
		if (unicode!=9){ //if the key isn't the period key (which we should allow)
			//if (unicode!=46){ //if the key isn't the period key (which we should allow)
				if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
					if (unicode<48||unicode>57) //if not a number
						return false //disable key press
					}
				}
			//}
	}
}



function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}


function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML=percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}


function previewRecipe(){
	window.open('/previewRecipe.asp','preview','status=no,nomenubar,resizable=yes,width=600,height=600');
	document.form1.action = "/previewRecipe.asp"
	document.form1.target = "preview";	// Open in a new window
	document.form1.submit();			// Submit the page
	return false;
}


function submitRecipe(){
	
	document.form1.action = "/admin/recipes/addRecipe.asp";
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}
function previewSuccess(){
	window.open('/admin/successStories/previewSuccess.asp','preview','status=no,nomenubar,resizable=yes,width=600,height=600');
	document.form1.action = "/admin/successStories/previewSuccess.asp"
	document.form1.target = "preview";	// Open in a new window
	document.form1.submit();			// Submit the page
	return false;
}
function submitSuccess(){
	
	document.form1.action = "/admin/successStories/addSuccess.asp";
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}
function updateSuccess(){
	
	document.form1.action = "/admin/successStories/updateSuccess.asp";
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}
function updateGoGreen(){
	
	document.form1.action = "/admin/gogreen/update.asp";
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}
function submitGoGreen(){
	
	document.form1.action = "/admin/gogreen/add.asp";
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}
function submitIdea(){
	
	document.form1.action = "/admin/ideas/addIdea.asp";
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}
function updateIdea(){
	
	document.form1.action = "/admin/ideas/updateIdea.asp";
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}

function updateRecipe(){
	
	document.form1.action = "/admin/recipes/updateRecipe.asp";
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}

function printCommit(){
	window.open('/printCommit.asp','commit','status=no,scrollbars=yes,nomenubar,resizable=yes,width=800,height=600');
	document.form1.action = "/printCommit.asp";
	document.form1.target = "commit";
	document.form1.submit();			// Submit the page
	return false;
}

function submitRecipeSite(){
	
	document.form1.action = "/cookies_recipes.asp?tab=submit";
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}

function submitUpdate(which){
	
	document.form1.action = "/catchgoals.asp?tab=mygoals&section=" + which;
	document.getElementById('done').value = "1"
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}

function updateCouncils(){
	state = document.getElementById('state').value
	document.form1.action = "/createAccount.asp?state=" + state;
	document.getElementById('done').value = "1"
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}
function updateCouncilsEdit(){
	state = document.getElementById('state').value
	document.form1.action = "/catchgoals.asp?tab=info&mystate=" + state;
	document.getElementById('done').value = "1"
	document.form1.target = "_self";
	document.form1.submit();			// Submit the page
	return false;
}
function printBrandYou(){
	window.open('/printBrandYou.asp','brandYou','status=no,scrollbars=yes,nomenubar,resizable=yes,width=800,height=600');
	document.form1.action = "/printBrandYou.asp"
	document.form1.target = "brandYou";	// Open in a new window
	document.form1.submit();			// Submit the page
	return false;
}

function checkTroopNumber(){
	
	if (document.form1.troopMember.value=='Yes'){
		document.form1.troopNumber.disabled = false;
	}else{
		document.form1.troopNumber.value='';
		document.form1.troopNumber.disabled = true;
	}
}
