
// BLOG DISPLAY FUNCTIONS


function BlogDisplay(json) 
{
			var sHeadLines;
			var sPostURL;
			var objPost;
			var sPostLinkLocation;
			var sDate = new Date();
			var sTeaser;
			
			
			try
			{			
			
					
			sHeadLines = "";
			
			for(var nFeedCounter = 0; nFeedCounter < nMaxPosts; nFeedCounter++)
			{
				objPost = json.feed.entry[nFeedCounter];
               
					  
				for (var nCounter = 0; nCounter < objPost.link.length; nCounter++) 
			   	{
                	if (objPost.link[nCounter].rel == 'alternate') 
					{
                  		sPostURL = objPost.link[nCounter].href;
                  		break;
    				}
    			}
				
			   var sStyle1 =  "\<span style=\"font-family : 'verdana'; font-size: 14px; color: #666666; font-weight: 200; text-decoration: none;\">"	
			   var sStyle2 =  "\<span style=\"font-family : 'verdana'; font-size: 12px; color: #333333; font-weight: 200; text-decoration: none;\">"	
			   var sStyle3 =  "\<span style=\"font-family : 'verdana'; font-size: 14px; color: #333333; font-weight: 200; text-decoration: none;\">"	


			   
			//   alert(sHeadLines);
			   
			   sHeadLines = sHeadLines + "\<a " + sPostLinkLocation + " href=\"" + sPostURL + "\" target=\"_new\">"  + sStyle1 + objPost.title.$t + "\</span\>\</a\> " ;
			}
			

			 // extract month, day, year of post

			sDate = sStyle2 + eval(sDate.getMonth(objPost.published.$t) + 1)  + "-" + sDate.getDate(objPost.published.$t)  + "-" + eval(sDate.getYear(objPost.published.$t)) + "\</span\>"


			//extract first 125 characters of the content

			var sContent = objPost.content.$t

			sTeaser = sStyle3 + sContent.substr(5,125) + "...</span\><br/><br/><a href=\"" + sPostURL + "\">\<span style=\"font-family : 'verdana'; font-size: 12px; color: #666666; font-weight: 200; text-decoration: underline;\">read more\>></span\></a\>"
			


			sHeadLines = sHeadLines +  "&nbsp;(" +  sDate + ")<br>" + sTeaser
			
			document.write(sHeadLines )

			
			}
			catch(exception)
			{
				alert(exception);
			}
}



// EMAIL FORM FUNCTIONS

if (document.location.protocol === "https:")

	document.icpsignup.action = "https://app.icontact.com/icp/signup.php";

// check email address

//function echeck(str) {
function verifyRequired() {
		var str = document.icpsignup["fields_email"].value
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

 		 return true					
	}


function clearField(field) {
	var theField = "your " + field
	var whichField
	
	if (field == "name") 
	{whichField = document.icpsignup["fields_fname"]}
	else if (field = "email")
	{whichField = document.icpsignup["fields_email"]} 
	
	if (whichField.value == theField) {
	whichField.value = ""; 
	theField = ""
    }
}


function resetField(field) {
	var theField = "your " + field
	var whichField
	
	if (field == "name") 
	{whichField = document.icpsignup["fields_fname"]}
	else if (field = "email")
	{whichField = document.icpsignup["fields_email"]} 

	if (whichField.value == "") {
	whichField.value = "your " + field;
	theField = ""
	}
}

// LIGHTBOX
 
function showSizedOverlay(location, width, height) {
  // setup so that clicking back will hide the frame
  document.getElementById("overlayFrame").setAttribute("src", "empty.html");
  // hide flash objects which will overwrite the overlay frame
//  var objects = document.getElementsByTagName("object");
 // for(var i = 0; i < objects.length; i++) {
  //  objects[i].style.visibility = 'hidden';
 // }
  // position based on scroll
  var yPos = (document.all)?document.body.scrollTop:window.pageYOffset;
  setOverlaySize(width, height);
  document.getElementById("overlaySizer").style.marginTop = (yPos+50)+"px";
  document.getElementById("overlayLayer").style.visibility = "visible";
  // set background up properly
//  setTimeout('document.getElementById("overlayBackground").style.height = "500px"', 2000);
  setBackHeight();
  setTimeout("setBackHeight()", 1000); // call again later... in case the page gets longer as a result of our display
  document.getElementById("overlayFrame").setAttribute("src", location);
}
function setOverlaySize(width, height) {
  document.getElementById("overlaySizer").style.width = width+"px";
  document.getElementById("overlaySizer").style.height = height+"px";
  // if the frame does not get its size set directly, IE does not size it right
  document.getElementById("overlayFrame").style.width = width+"px";
  document.getElementById("overlayFrame").style.height = height+"px";
}
function showOverlay(location) {
  showSizedOverlay(location, 700, 450);
}
function hideOverlayNoContentChange() {
  document.getElementById("overlayBackground").style.height = "0px"; // resize this layer to nothing so it does not affect the scrollbar size
  // resize the overlay layer so it does not scroll invisibly (IE bug)
  setOverlaySize(0, 0);
  document.getElementById("overlayLayer").style.visibility = "hidden";
  var objects = document.getElementsByTagName("object");
  for(var i = 0; i < objects.length; i++) {
    objects[i].style.visibility = 'visible';
  }
}
function hideOverlay() {
	hideOverlayNoContentChange();
  // set the location to an empty location so that content inside does not continue to execute 
  document.getElementById("overlayFrame").setAttribute("src", "empty.html");
}
function showImageOverlay(imageLocation, width, height) {
  if(document.all) {
    // IE needs bigger frames
    width += 4;
    height += 4;
  }
// CHANGE AS SOON AS I FIGURE OUT WHAT IT IS
  showSizedOverlay('http://www.thebrain.com/site/helpers/showImage.html?loc='+imageLocation, width, height);
}
function setBackHeight() {
  var height = document.getElementById("edges").offsetHeight;
  document.getElementById("overlayBackground").style.height = height;
}
 


//GOOGLE TRACKING CODE


var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));


try {
var pageTracker = _gat._getTracker("UA-10463543-2");
pageTracker._trackPageview();
} catch(err) {}