


function com_eksendia_go(eksendiaCitation)
{

	function inStr(str1, str2) {return str1.indexOf(str2);}

	function replace(theStr, replaced, replacee)
	{
		for(;;)
		{
			if (inStr(theStr, replaced) == -1)
				break;
			theStr = theStr.replace(replaced, replacee);
		}
		return theStr;
	}

	function trim(sString)
	{
		while (sString.substring(0,1) == ' ')
		{
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
			sString = sString.substring(0,sString.length-1);
		}
		return sString;
	}



	if (eksendiaCitation == null)
	{
		eksendiaCitation = 0;
	}

	var author = null;
	try
	{
		if (com_eksendia_eTurabian_author == null || com_eksendia_eTurabian_author == "")
		{
			author = "";
		}
		else
		{
			author = replace(com_eksendia_eTurabian_author, "`", "'");
		}
	}
	catch(e)
	{
		author = "";
	}
	
	var postAuthor = "";
	var i = 0;
	var str = "";
	var arr = null;
	var pt = document.title;
	var bbody = document.body.innerHTML;
	var bdateIndex = bbody.indexOf("date-header");
	var index = null
	var bdate = "";
	var bday = "";
	var bmonth = "";
	var byear = "";
	var publisher = "";
	var title = "";
	var url_head="http://www.eksendia.com/";
	url_head += "turabian/school_blogger_widget.html";
	var dstamp = new Date();	
	var stamp = dstamp.valueOf().toString();
	var url = "?blogType=blogger&biblID=0_" + eksendiaCitation + "_" + stamp + "&biblSubmitted=yes";

	index = pt.indexOf(":");
	if (index != -1)
	{
		pt = pt.split(":");
		publisher = pt[0];
		title = pt[1];
		url += "&publisher=";
		url += publisher;
		url += "&title=";
		url += title;
	}
	else
	{
		url += "&publisher=";
		url += pt;
		index = bbody.indexOf("post-title");
		if (index != -1)
		{
			str = bbody.slice(index);
			try
			{
				str = str.split(">")
				str = str[2];
				str = str.split("<");
				url += "&title=";
				url += str[0];
			}
			catch(e){}
			str = '';
		}
	}


	if(bdateIndex != -1)
	{
		str = bbody.slice(bdateIndex+13,bdateIndex+60);
		bdateIndex = str.indexOf("<");
		if (bdateIndex != -1)
		{
			arr = str.split("<")
			str = arr[0];
			index = str.indexOf(",");
			if (index != -1)
			{
				arr=str.split(",");
				if (arr.length == 3)
				{
					str = arr[1] + arr[2];
					index = str.indexOf(" ");
					if (index != -1)
					{
						arr = str.split(" ");
						if (arr.length == 4)
						{
							bday = arr[2].replace(",", "");
							bmonth = arr[1].replace(",", "");
							byear = arr[3].replace(",", "");
							url += "&postedDay=";
							url += bday;
							url += "&postedMonth=";
							url += bmonth;
							url += "&postedYear=";
							url += byear;
						}
					}
				}
			}
		}
	}

	index = bbody.indexOf("post-author")
	if (index != -1)
	{
		str = bbody.slice(index, index + 100);
		index = str.indexOf("Posted by ");
		bdateIndex = str.indexOf("<");
		if (index != -1)
		{
			postAuthor = str.slice(index + 9, bdateIndex - 1);
			url += "&Author1LName=";
			url += postAuthor;
		}
	}
	
	if (postAuthor == "")
	{
		index = author.indexOf(",");
		if (index == -1)
		{
			url += "&Author1LName=";
			url += author;
		}
		else
		{
			author = author.split(",");
			for (i = 0; i < author.length; i++)
			{
				index = bbody.indexOf(author[i]);
				if (index != -1)
				{
					bdateIndex = bbody.indexOf(trim(author[i]) + ",");
					if (bdateIndex - index >= 60)
					{
						url += "&Author1LName=";
						url += author[i];
						break;
					}
					bdateIndex = bbody.indexOf(trim(author[i]) + "'");
					if (bdateIndex - index >= 60)
					{
						url += "&Author1LName=";
						url += author[i];
						break;
					}
				}
			}
		}
	}
	url += "&bookType=";
	url += document.URL;
	url = url_head + url;
	url = replace(url, "<", "{:");
	url = replace(url, ">", ":}");
	window.open(url)
}



function com_eksendia_eTurabianWidget_onLoad()
{
	var i = 0;
	var maxInst = com_eksendia_eTurabianWidget_instanceNr(true) / 2;
	for (i = 0; i <= maxInst; i++)
	{
		com_eksendia_eTurabianWidget_run(i, maxInst);
	}
}


function com_eksendia_eTurabianWidget_addOnLoad()
{
	if (window.addEventListener)
	{
		window.addEventListener("load", com_eksendia_eTurabianWidget_onLoad, false);
	}
	else 
	{
		if (window.attachEvent)
		{
			window.attachEvent("onload", com_eksendia_eTurabianWidget_onLoad);
		}
		else
		{
			//nothing
		}
	}
}


try
{
	com_eksendia_eTurabianWidget_instanceNr(false);
}
catch(e)
{
	com_eksendia_eTurabianWidget_instanceNr = (function(getLastInstance)
	{
		var instanceNr = 0;
		var lastInstance = -1;
		return function(getLastInstance)
		{
			if (getLastInstance == false)
			{
				lastInstance = instanceNr;
				return instanceNr++;
			}
			else
			{
				return lastInstance;
			}
		};
	}
	)();
	com_eksendia_eTurabianWidget_addOnLoad();
}


function com_eksendia_eTurabianWidget_runInit()
{
	this.instance = null;
	this.init = function()
	{
		var hr = '<img ';
		hr += 'src="http://www.eksendia.com/turabian/images/citeMAT_butn.gif" ';
		hr += 'alt="generate citation" border = "0">';
		var index = -1;
		var str = "";
		var etId = com_eksendia_eTurabianWidget_instanceNr(true);
		var et = document.getElementsByName("eksendia_eT_span");
		etId = etId / 2;
		str = "eksendia_eTurabian_";
		str += etId;
		if (this.widget)
		{
			et[et.length-1].setAttribute("id",str);
			index = document.title.indexOf(":");
			if (index == -1)
			{
					
					//for now is the same
				document.getElementById(str).innerHTML = hr;
			}
			else
			{
				document.getElementById(str).innerHTML = hr;
			}
		}
	}
}



function com_eksendia_eTurabianWidget_init()
{
	var inst = com_eksendia_eTurabianWidget_instanceNr(false) / 2;
	var a = new com_eksendia_eTurabianWidget_runInit();
	a.instance = inst;
	a.info = "Hey from 2 onload";
	a.widget = true;
	a.init();
}
com_eksendia_eTurabianWidget_init();



function com_eksendia_eTurabianWidget()
{
	this.instance = -1;
	this.maxInst = - 1;

	this.init = function(inst, maxInst)
	{
		this.maxInst = maxInst;
		this.instance = inst;

		var str = "We are running a test: \n";
		str = "this.maxInst = ";
		str += this.maxInst;
		str += "\n this.instance = "
		str += this.instance;
	}
}


function com_eksendia_eTurabianWidget_run(inst, maxInst)
{
	var a = new com_eksendia_eTurabianWidget();
	a.init(inst, maxInst);
}








