

function in_array( val, arr ) {
	var arrlen = arr.length;
	if ( arrlen == undefined ) {
		return false;
	}
	for ( var i = 0; i < arrlen; i++ ) {
		if ( val == arr[i] ) {
			return true;
		}
	}

	return false;
}

/* This is deprecated code
function facebook_publish_feed_story(form_bundle_id, template_data) {
  // Load the feed form
  FB.ensureInit(function() {
		FB.Connect.showFeedDialog(form_bundle_id, template_data);
  });
}*/

function publish_facebook( usermessage, attachment, actionlinks, target,
	messageprompt, callback, autopublish, actorid )
{
	FB.ensureInit(function() {
	FB.Connect.streamPublish( usermessage, attachment, actionlinks, target,
		messageprompt, callback, autopublish, actorid );
	});
}

function resizeRecaptcha( width, height ) {
	$('#recaptcha_image').children().each( function() {
		if ( this.tagName == 'IMG' ) {
			this.height = height;
			this.width = width;
		}
	} );
	$('#recaptcha_image').width( width );
}

/**
 * Iterates over the poll form and binds click events to the various
 * form elements to implement AJAX and ui effects.
 */
function hookPoll() {
	var pf = document.getElementById( 'pollForm' );

	if ( pf != null ) {
		pf.setAttribute( 'onsubmit', 'javascript: return false;' );

		for ( var i = 0; i < pf.elements.length; i++ ) {
			if ( pf.elements[i].name.indexOf('submitBtn') != -1 ) {
				$(pf.elements[i]).click(function() {
					sendPoll();
					return false;
				});
			}
		}
	}
}

function adjustContentColumns() {
	var clc = document.getElementById('contentLeftColumn');
	var crc = document.getElementById('contentRightColumn');

	if ( clc != null && crc != null ) {
		var crcheight = $(crc).height();
		var clcheight = $(clc).height();
		if ( clcheight < crcheight ) {
			$(clc).height( crcheight );
		} else if ( crcheight < clcheight ) {
			$(crc).height( clcheight );
		}
	}
}

function limitText(Event, Object, MaxLen) {
	/*if ( ta.value.length > limit ) {
		//ta.value = ta.value.substring(0, limit);
		return false;
	}

	return true;*/
	return (Object.value.length <= MaxLen)||(Event.keyCode == 8 ||Event.keyCode==46||(Event.keyCode>=35&&Event.keyCode<=40));
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
		";path=/" +
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function hideBrowserNotice() {
	var bnd = document.getElementById('browserNoticeDiv');
	var body = document.getElementsByTagName('body');
	body = body[0];
	setCookie('hideBrowserNotice', 'true', 10);

	body.removeChild(bnd);
}

$(document).ready( function() {
	hookPoll();
	adjustContentColumns();
	if ( typeof buildPbStates == 'function' ) {
		buildPbStates();
	}

	// Modify all external links to open in a new window.
	$('a').each(function() {
		var httppat = /^http(s){0,1}:\/\/(?!(www\.){0,1}all\.org)/;
		var pdfpat = /([\s\S]*?)\.pdf$/;

		//if ( this.href.indexOf('all.org') == -1 && this.href.match(httppat) != -1 ) {
		if ( this.href.match(httppat) ) {
			var loc = this.href;
			this.href = 'javascript:;';
			this.onclick = function() {
				window.open(loc);
			}
			this.target = '';
		} /*else if ( this.href.match(pdfpat) ) {
			var pdf = this.href;
			this.href = WEB_ROOT + '/download/res/id/' + Base64.encode(pdf);
		}*/
	});

	if ( getCookie('ejtest') == 'true' ) {
		//alert($('#fbc').html());
	}

} );

