var queryString = new Array();

function getLastChild(el) {
  return (el.lastChild && el.lastChild.nodeName != '#text') ? getLastChild(el.lastChild) : el;
}

var query = getLastChild(document.lastChild).getAttribute('src').replace(/.*\?/, '');

//var parameters = query.substring(1).split('&');
var parameters = query.split('&');

//document.write('PARMS0-'+parameters[0]);
// For each element in the array, find the equal sign that separates the parameter
// name from the parameter value.  If there is one, divide the expression into
// the parameter name
for (var i=0; i<parameters.length; i++) {
    var pos = parameters[i].indexOf('=');
    // If there is an equal sign, separate the parameter into the name and value,
    // and store it into the queryString array.
    if (pos > 0) {
        var paramname = parameters[i].substring(0,pos);
        var paramval = parameters[i].substring(pos+1);
        queryString[paramname] = unescape(paramval.replace(/\+/g,' '));
    } else {
        //special value when there is a querystring parameter with no value
        queryString[parameters[i]]="" 
    }
}

//document.write('QNAME IS'+queryString['q']);

//q format is NNSIIIII... 
//	NN=2chars for quizname (hc=heidelberg catechism, etc.)
//	S=1char for form (w, n, c)
//  III... = unique widget ID "EGP23556..." where 23556... is timestamp

var qn = queryString['q'].substring(0,2);
var qs = queryString['q'].substring(2,3);
var qi = "EGP"+queryString['q'].substring(3);

var qname = "";
switch (qn)
{
	case "hc": 	qname = "heidelberg&act=question";					break;
	case "lc": 	qname = "luthersmall&act=question";					break;
	case "sc": 	qname = "shortercatechism&act=question";			break;
	case "bc": 	qname = "baptist&act=question";						break;
	case "cc": 	qname = "catechism&act=question";					break;
	case "95": 	qname = "95Theses&act=info";						break;
	case "ed": 	qname = "edres&act=info";							break;
	case "gw": 	qname = "gw110&act=info";							break;
	case "br": 	qname = "billrights&act=info";						break;
	case "cq": 	qname = "composer&act=info";						break;
	case "hk": 	qname = "haiku&act=info";							break;
	case "pr": 	qname = "proverbs&act=info";						break;
	case "gk": 	qname = "gkc&act=info";								break;
	case "wc": 	qname = "woc&act=info";								break;
	default: 	qname = "billrights&act=info";
}

var fsize = "";
switch (qs)
{
	case "w": 	fsize = "width=\"216\" height=\"290\"";				break;
	case "n": 	fsize = "width=\"156\" height=\"370\"";				break;
	case "c": 
	default:	fsize = "width=\"156\" height=\"250\"";
}	

/*
var d = new Date();
qi = 'EGPJs'+Math.round(d.getTime()/1000);
*/

//document.write('QN-'+qname+'QS-'+qs+'QI-'+qi+'END');

if (qname=="") 
	document.write('<iframe width="156" height="250" frameborder="0" scrolling="no" src="http://www.everygoodpath.net/Quiz/WidgetQuiz.php"></iframe>');
else 	
	document.write('<iframe allowtransparency="true" '+fsize+' frameborder="0" scrolling="no" src="http://www.everygoodpath.net/Quiz/WidgetQuiz.php?f='+qs+'&quiz='+qname+'&id='+qi+'"></iframe>');
	

