function setFormAllowCookie() {
        var cookieName = "f_a";
        var cookieValue = "true";
        document.cookie= cookieName + "=" + escape(cookieValue) + "; domain=ic.org; path=/";
        return true;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		//no @
		if (lat==-1){
		   return false
		}

		//@ can't be first, last or one from last
		if (lat==0 || lat==lstr || lat==lstr-1 ){
		   return false
		}

		//dot can't be not found, first, last, or one from last, or two from last
		if (ldot==-1 || ldot==0 || ldot==lstr || ldot==lstr-1 || ldot==lstr-2 ){
		    return false
		}
		
		//more than one @	
		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 //dot is right before or after @
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }
		
		 //dot must be at least two chars after @
		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		//must not have spaces
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


function event_form_validator(theForm) {
	if (theForm.event_name.value == "") { 
	 	alert("Please enter a value for the \"Event Name\" field."); 
		theForm.event_name.focus();
		return (false); 
	}   
	if (theForm.start_date.value == "") { 
		alert("Please enter a value for the \"Start Date\" field.");
		theForm.start_date.focus(); 
		return (false); 
	}   
	return (true); 
} 




var arImages=new Array();
function Preload() {
 var temp = Preload.arguments; 
 for(x=0; x < temp.length; x++) {
  arImages[x]=new Image();
  arImages[x].src=Preload.arguments[x];
 }
}


function W(s) { document.writeln(s); }

function anti_spam_mail_to(e) {
	r='';
	for(i=0;i<e.length;i++) {
		if(e.substring(i,i+1)=='!')
			r+='@';
		else
			r+=e.substring(i,i+1);
	}
	W('<a h'+'ref="mai'+'lto:'+r+'">'+r+'</a>');
}

function UnitChange(){
	f=document.form1;
	area = f['area'];
	u = f.area_units;
	
	e=new Date(); e.setTime(e.getTime()+40000000000);
	document.cookie='area_units='+u.value+'; expires='+e.toGMTString();
	
	if(area.value){
		if (u.value =="acres"){
			area.value=Math.round(area.value * 2.47105381 * 10) / 10;
		} else{ /*hectares*/
			area.value=Math.round(area.value * 0.404685642  * 10) / 10;
		}
	}
}

function setContactPage(name){
	document.addForm.page.value=name;
}

function traits1_validator(theForm) {

if (theForm['trait[5][number]'].value.length > 0 && !is_numeric(theForm['trait[5][number]'].value)){
		alert('Please enter a valid number for Year Formed.');
		theForm['trait[5][number]'].focus();
 			return (false);
	}
	
	if (theForm['trait[6][number]'].value.length > 0 && !is_numeric(theForm['trait[6][number]'].value)){
		alert('Please enter a valid number for Year Established.');
		theForm['trait[6][number]'].focus();
 			return (false);
	}
	
		if (theForm['trait[8][number]'].value.length > 0 && !is_numeric(theForm['trait[8][number]'].value)){
		alert('Please enter a valid number for Year Ended.');
		theForm['trait[8][number]'].focus();
 			return (false);
	}
	
	return true;
}

function traits2_validator(theForm) {

if (theForm['trait[11][number]'].value.length > 0 && !is_numeric(theForm['trait[11][number]'].value)){
		alert('Please enter a valid number for Adult Members.');
		theForm['trait[11][number]'].focus();
 			return (false);
	}
	
	if (theForm['trait[12][number]'].value.length > 0 && !is_numeric(theForm['trait[12][number]'].value)){
		alert('Please enter a valid number for Child Members.');
		theForm['trait[12][number]'].focus();
 			return (false);
	}
	
		if (theForm['trait[13][number]'].value.length > 0 && !is_numeric(theForm['trait[13][number]'].value)){
		alert('Please enter a valid number for Non-member Residents.');
		theForm['trait[13][number]'].focus();
 			return (false);
	}
	
			if (theForm['trait[14][percent]'].value.length > 0 && !is_numeric(theForm['trait[14][percent]'].value)){
		alert('Please enter a valid number for Percent Men.');
		theForm['trait[14][percent]'].focus();
 			return (false);
	}
	
				if (theForm['trait[15][percent]'].value.length > 0 && !is_numeric(theForm['trait[15][percent]'].value)){
		alert('Please enter a valid number for Percent Women.');
		theForm['trait[15][percent]'].focus();
 			return (false);
	}
	
	return true;
}


function traits5_validator(theForm) {

if (theForm['trait[9][number]'].value.length > 0 && !is_numeric(theForm['trait[9][number]'].value)){
		alert('Please enter a valid number for Area.');
		theForm['trait[9][number]'].focus();
 			return (false);
	}

if (theForm['trait[25][number]'].value.length > 0 && !is_numeric(theForm['trait[25][number]'].value)){
		alert('Please enter a valid number for Number of Residences.');
		theForm['trait[25][number]'].focus();
 			return (false);
	}
	
	return true;
}

function image_validator(theForm) {

if (theForm['year'].value.length > 0 && !is_numeric(theForm['year'].value)){
		alert('Please enter a valid number for Year.');
		theForm['year'].focus();
 			return (false);
	}

	return true;
}

function is_numeric(checkStr){
		// allow ONLY alphanumeric keys, no symbols or punctuation
	// this can be altered for any "checkOK" string you desire
	var checkOK = "0123456789.,";
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}
	if (!allValid)	return (false);
	
	return true;
}


function UnitChange(){
	f=document.form1;
	area = f['trait[9][number]'];
	u = f.area_units;
	
	e=new Date(); e.setTime(e.getTime()+40000000000);
	document.cookie='area_units='+u.value+'; expires='+e.toGMTString();
	
	//alert ('area_units='+u.value+'; expires='+e.toGMTString());
	//units = u.options[u.selectedIndex].value;
	/*
	if(area.value){
		if (u.value =="acres"){
			area.value=Math.round(area.value * 2.47105381 * 10) / 10;
		} else{ //hectares
			area.value=Math.round(area.value * 0.404685642  * 10) / 10;
		}
	}*/
}
function makeAcres(f){
	area = f['trait[9][number]'];
	
	if (area.value.length > 0 && !is_numeric(area.value)){
		return (false);
	}
	
	
	u = f.area_units;
	
	//units = u.options[u.selectedIndex].value;
	
	if(area.value){
		if (u.value =="hectares"){
			area.value=Math.round(area.value *  2.47105381  * 10) / 10;
		}
	}
	//alert("area" + area.value);

}

function feedback_validator(theForm) {
	if (theForm.name.value == "") { 
	 	alert("Please enter your name."); 
		theForm.name.focus();
		return (false); 
	}   
	if (echeck(theForm.email.value)==false){
		alert('Please enter a valid email address');
		theForm.email.focus()
		return false
	}
	
	if (theForm.comments.value==""){
		alert('Please enter your comment or question in the comments or questions field');
		theForm.comments.focus()
		return false
	}
	return true;
}

 function classified_form_validator(theForm) {
	if (theForm.classified_title.value == "") { 
	 	alert("Please enter a value for the \"Classified Title\" field."); 
		theForm.classified_title.focus();
		return (false); 
	}   
	if (theForm.duration.value == "") { 
		alert("Please choose a value for the \"Duration\" field.");
		theForm.duration.focus(); 
		return (false); 
	}   
	if (echeck(theForm.email.value)==false){
		alert('Please enter a valid email address');
		theForm.email.focus()
		return false
	}
	
		return (true); 
} 

 function reach_form_validator(theForm) {
	if (theForm.contact_name.value == "") { 
	 	alert("Please enter a value for the \"Your Name\" field."); 
		theForm.contact_name.focus();
		return (false); 
	}   
	if (theForm.category.value == "") { 
		alert("Please choose a value for the \"Category\" field.");
		theForm.category.focus(); 
		return (false); 
	}   
	
		return (true); 
} 

function hit(squirrel,artist,landing) {
squirrel += ' ';
var punishment = squirrel.length;
var opposite = 0;
var corporation = '';
for(var waste = 0; waste < punishment; waste++) {
opposite = 0;
while(squirrel.charCodeAt(waste) != 32) {
opposite = opposite * 10;
opposite = opposite + squirrel.charCodeAt(waste)-48;
waste++;
}
corporation += String.fromCharCode(shoot(opposite,artist,landing));
}
parent.location = 'm'+'a'+'i'+'l'+'t'+'o'+':'+corporation;
}

function leap(speech,structure,extravagance) {
speech += ' ';
var flore = speech.length;
var human = 0;
for(var lake = 0; lake < flore; lake++) {
human = 0;
while(speech.charCodeAt(lake) != 32) {
human = human * 10;
human = human + speech.charCodeAt(lake)-48;
lake++;
}
//document.write('&');
//document.write('#');
//document.write(shoot(human,structure,extravagance));
document.write(String.fromCharCode(shoot(human,structure,extravagance)));
}
}

function shoot(moon,male,magic) {
if (magic % 2 == 0) {
movement = 1;
for(var optician = 1; optician <= magic/2; optician++) {
music = (moon*moon) % male;
movement = (music*movement) % male;
}
} else {
movement = moon;
for(var somethingawful = 1; somethingawful <= magic/2; somethingawful++) {
music = (moon*moon) % male;
movement = (music*movement) % male;
}
}
return movement;
}

 function enews_form_validator(theForm) {
	if (theForm.I_Name.value == "") { 
	 	alert("Please enter a value for the \"Name\" field."); 
		theForm.I_Name.focus();
		return (false); 
	}   
	if (echeck(theForm.I_Email.value)==false){
		alert('Please enter a valid email address');
		theForm.I_Email.focus()
		return false
	}
	
		return (true); 
} 

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);







function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
} 


function popUpProperties(inobj) {
        op = window.open();
        op.document.open('text/plain');
        for (objprop in inobj) {
        op.document.write(objprop + ' => ' + inobj[objprop] + '\n');
        }
        op.document.close();
}

function textCounter(field, countfield ) {
	var aText = document.getElementById('alertText');
	countfield.value = field.value.length;
	if (field.value.length > 2500) aText.innerHTML = 'Description is longer than the 2500 character limit.';
	if (field.value.length <= 2500) aText.innerHTML = '';
}

function textCounter1000(field, countfield,maxchar ) {
	var aText = document.getElementById('alertText');
	countfield.value = field.value.length;
	if (field.value.length > maxchar) aText.innerHTML = 'Comment is longer than the 1000 character limit.';
	if (field.value.length <= maxchar) aText.innerHTML = '';
}

function textLengthValidator(field){
	if (field.value.length > 2510){
		alert("Your Basic Description text is too long. Please shorten it to under 2500 characters.");
		return false;
	} else {
		return true;
	}
}



var arImages=new Array();
function Preload() {
 var temp = Preload.arguments; 
 for(x=0; x < temp.length; x++) {
  arImages[x]=new Image();
  arImages[x].src=Preload.arguments[x];
 }
}


function W(s) { document.writeln(s); }

function anti_spam_mail_to(e) {
	r='';
	for(i=0;i<e.length;i++) {
		if(e.substring(i,i+1)=='!')
			r+='@';
		else
			r+=e.substring(i,i+1);
	}
	W('<a h'+'ref="mai'+'lto:'+r+'">'+r+'</a>');
}

function UnitChange(){
	f=document.form1;
	area = f['area'];
	u = f.area_units;
	
	e=new Date(); e.setTime(e.getTime()+40000000000);
	document.cookie='area_units='+u.value+'; expires='+e.toGMTString();
	
	if(area.value){
		if (u.value =="acres"){
			area.value=Math.round(area.value * 2.47105381 * 10) / 10;
		} else{ /*hectares*/
			area.value=Math.round(area.value * 0.404685642  * 10) / 10;
		}
	}
}

function setContactPage(name){
	document.addForm.page.value=name;
}

function traits1_validator(theForm) {

if (theForm['trait[5][number]'].value.length > 0 && !is_numeric(theForm['trait[5][number]'].value)){
		alert('Please enter a valid number for Year Formed.');
		theForm['trait[5][number]'].focus();
 			return (false);
	}
	
	if (theForm['trait[6][number]'].value.length > 0 && !is_numeric(theForm['trait[6][number]'].value)){
		alert('Please enter a valid number for Year Established.');
		theForm['trait[6][number]'].focus();
 			return (false);
	}
	
		if (theForm['trait[8][number]'].value.length > 0 && !is_numeric(theForm['trait[8][number]'].value)){
		alert('Please enter a valid number for Year Ended.');
		theForm['trait[8][number]'].focus();
 			return (false);
	}
	
	return true;
}

function traits2_validator(theForm) {

if (theForm['trait[11][number]'].value.length > 0 && !is_numeric(theForm['trait[11][number]'].value)){
		alert('Please enter a valid number for Adult Members.');
		theForm['trait[11][number]'].focus();
 			return (false);
	}
	
	if (theForm['trait[12][number]'].value.length > 0 && !is_numeric(theForm['trait[12][number]'].value)){
		alert('Please enter a valid number for Child Members.');
		theForm['trait[12][number]'].focus();
 			return (false);
	}
	
		if (theForm['trait[13][number]'].value.length > 0 && !is_numeric(theForm['trait[13][number]'].value)){
		alert('Please enter a valid number for Non-member Residents.');
		theForm['trait[13][number]'].focus();
 			return (false);
	}
	
			if (theForm['trait[14][percent]'].value.length > 0 && !is_numeric(theForm['trait[14][percent]'].value)){
		alert('Please enter a valid number for Percent Men.');
		theForm['trait[14][percent]'].focus();
 			return (false);
	}
	
				if (theForm['trait[15][percent]'].value.length > 0 && !is_numeric(theForm['trait[15][percent]'].value)){
		alert('Please enter a valid number for Percent Women.');
		theForm['trait[15][percent]'].focus();
 			return (false);
	}
	
	return true;
}


function traits5_validator(theForm) {

if (theForm['trait[9][number]'].value.length > 0 && !is_numeric(theForm['trait[9][number]'].value)){
		alert('Please enter a valid number for Area.');
		theForm['trait[9][number]'].focus();
 			return (false);
	}

if (theForm['trait[25][number]'].value.length > 0 && !is_numeric(theForm['trait[25][number]'].value)){
		alert('Please enter a valid number for Number of Residences.');
		theForm['trait[25][number]'].focus();
 			return (false);
	}
	
	return true;
}

function image_validator(theForm) {

if (theForm['year'].value.length > 0 && !is_numeric(theForm['year'].value)){
		alert('Please enter a valid number for Year.');
		theForm['year'].focus();
 			return (false);
	}

	return true;
}

function is_numeric(checkStr){
		// allow ONLY alphanumeric keys, no symbols or punctuation
	// this can be altered for any "checkOK" string you desire
	var checkOK = "0123456789.,";
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}
	if (!allValid)	return (false);
	
	return true;
}


function UnitChange(){
	f=document.form1;
	area = f['trait[9][number]'];
	u = f.area_units;
	
	e=new Date(); e.setTime(e.getTime()+40000000000);
	document.cookie='area_units='+u.value+'; expires='+e.toGMTString();
	
	//alert ('area_units='+u.value+'; expires='+e.toGMTString());
	//units = u.options[u.selectedIndex].value;
	/*
	if(area.value){
		if (u.value =="acres"){
			area.value=Math.round(area.value * 2.47105381 * 10) / 10;
		} else{ //hectares
			area.value=Math.round(area.value * 0.404685642  * 10) / 10;
		}
	}*/
}
function makeAcres(f){
	area = f['trait[9][number]'];
	
	if (area.value.length > 0 && !is_numeric(area.value)){
		return (false);
	}
	
	
	u = f.area_units;
	
	//units = u.options[u.selectedIndex].value;
	
	if(area.value){
		if (u.value =="hectares"){
			area.value=Math.round(area.value *  2.47105381  * 10) / 10;
		}
	}
	//alert("area" + area.value);

}





	
	function getCookie(name) {
	    var dc = document.cookie;
	    var prefix = name + "=";
	    var begin = dc.indexOf("; " + prefix);
	    if (begin == -1) {
	        begin = dc.indexOf(prefix);
	        if (begin != 0) return null;
	    } else {
	        begin += 2;
	    }
	    var end = document.cookie.indexOf(";", begin);
	    if (end == -1) {
	        end = dc.length;
	    }
	    return unescape(dc.substring(begin + prefix.length, end));
	}
	
	
	function setDispForming(){
		var disp_forming = getCookie('disp_forming');
		//alert (disp_forming);
		 if (disp_forming==2){
			changecss('.cTF','display','block');
			changecss('.cT','display','none');
			e=document.disp_form['disp_forming2'];
			e.checked=true;
		} else if (disp_forming==3){
			changecss('.cTF','display','none');
			changecss('.cT','display','block');
			e=document.disp_form['disp_forming3'];
			e.checked=true;
		} else {
			changecss('.cTF','display','block');
			changecss('.cT','display','block');
			e=document.disp_form['disp_forming1'];
			e.checked=true;
		}
	}
	
	
	function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

	
	//Code Below from: Custom JavaScript Functions by Shawn Olson
//Copyright 2004
//http://www.shawnolson.net
//Courtesy of Shawn Olson & http://www.shawnolson.net
//*******************************************


		function changecss(theClass,element,value) {
		//documentation for this script at http://www.shawnolson.net/a/503/
		
		 var cssRules;
		 if (document.all) {
		  cssRules = 'rules';
		 }
		 else if (document.getElementById) {
		  cssRules = 'cssRules';
		 }
		 
		 for (S = 0; S < document.styleSheets.length; S++){
		  if (cssRules =='rules' || strposition(document.styleSheets[S].href, window.location.host,0)!= false){
		  for (R = 0; R < document.styleSheets[S][cssRules].length; R++) {
		   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
		    document.styleSheets[S][cssRules][R].style[element] = value;
		   }
		  }
		  }
		 }	
		}
		
function strposition( haystack, needle, offset){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
    var i = (haystack+'').indexOf( needle, offset ); 
    return i===-1 ? false : i;
}

function email_cmty_validator(theForm) {
	

	if (theForm.name.value == "") { 
	 	alert("Please enter a value for the \"Name\" field."); 
		theForm.name.focus();
		return (false); 
	}   
	if (echeck(theForm.email.value)==false){
		alert('Please enter a valid email address');
		theForm.email.focus()
		return false
	}
	if (theForm.subject.value == "") { 
	 	alert("Please enter a value for the \"Subject\" field."); 
		theForm.subject.focus();
		return (false); 
	}  
	
	return true;
}


var selected;

function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.checkout_address.address[0]) {
    document.checkout_address.address[buttonSelect].checked=true;
  } else {
    document.checkout_address.address.checked=true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function check_form_optional(form_name) {
  var form = form_name;

  var firstname = form.elements['firstname'].value;
  var lastname = form.elements['lastname'].value;
  var street_address = form.elements['street_address'].value;

  if (firstname == '' && lastname == '' && street_address == '') {
    return true;
  } else {
    return check_form(form_name);
  }
}


function edit_user_validator(theForm) {
		
	
	if (echeck(theForm.email.value)==false){
		alert('Please enter a valid email address');
		theForm.email.focus()
		return false
	}
	
	if (theForm.email.value != theForm.email_confirmation.value){
		alert('Your Email Address Confirmation does not match your Email Address');
		theForm.email.focus()
		return false
	}
	

	if (theForm.password.value != theForm.password_confirmation.value){
		alert('Your Password Confirmation does not match your Password ');
		theForm.password.focus()
		return false
	}
	
	return true;
}


function login_sf(){
	if (document.login_form!= null){
		if (document.login_form.user.value.length <1 ) document.login_form.user.focus();
		else document.login_form.password.focus()
	}
}

function signup_sf(){
	if (document.signup!= null){
		document.signup.user.focus();
	}
}

function lostit_sf(){
	if (document.lostit!= null){
		 document.lostit.email.focus();
	}
}

//Verify's that an email address is reasonable


function is_alpha_numeric(checkStr){
		// allow ONLY alphanumeric keys, no symbols or punctuation
	// this can be altered for any "checkOK" string you desire
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}
	if (!allValid)	return (false);
	
	return true;
}


	



function signup_validator(theForm) {
		
	//Need better error checking
	if (theForm.user.value.length < 3 || theForm.user.length > 20 || !is_alpha_numeric(theForm.user.value)){
		alert('Please enter a valid username. It must be between 3 and 20 characters and contain only numbers and letters.');
		theForm.user.focus();
 			return (false);
	}
	
	if (echeck(theForm.email.value)==false){
		alert('Please enter a valid email address');
		theForm.email.focus()
		return false
	}
	
	if (theForm.email.value != theForm.email_confirmation.value){
		alert('Your Email Address Confirmation does not match your Email Address');
		theForm.email.focus()
		return false
	}
	
	if (theForm.password.value.length < 4 ){
		alert('Please enter a valid password. It must be at least 4 characters.');
		theForm.password.focus();
 			return (false);
	}
	
	if (theForm.password.value != theForm.password_confirmation.value){
		alert('Your Password Confirmation does not match your Password ');
		theForm.password.focus()
		return false
	}
	

/*	e=new Date(); e.setTime(e.getTime()+40000000000);
	document.cookie='user='+theForm['user'].value+'; expires='+e.toGMTString()+'; path=/; domain=ic.org';
*/	return true;
}

