function JSONscriptRequest(fullUrl) {
    this.fullUrl = fullUrl; 
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    this.headLoc = document.getElementsByTagName("head").item(0);
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

JSONscriptRequest.scriptCounter = 1;

JSONscriptRequest.prototype.buildScriptTag = function () {
    this.scriptObj = document.createElement("script");
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
JSONscriptRequest.prototype.removeScriptTag = function () {
    this.headLoc.removeChild(this.scriptObj);  
}

JSONscriptRequest.prototype.addScriptTag = function () {
    this.headLoc.appendChild(this.scriptObj);
}

//-----------------------------------------
var bObj;  
var fVar;
var FORM_HTML_ROW =  new Array(10);

FORM_HTML_ROW[0] = '';
FORM_HTML_ROW[1] = '<form name="main_biomedtalk">';
FORM_HTML_ROW[2] = '<a title="Enter Author name into the form and click the \'Go\' button to retrieve the Articles Rank. Please, see details by following this link at BioMedTalk.com." target="_blank" href="http://www.biomedtalk.com/showthread.php?t=1432">';
FORM_HTML_ROW[3] = '<font color="#000099" size="3" face="Times New Roman"><b><u>Bio & Med Science</u></b></font></a><br/>';
FORM_HTML_ROW[4] = '<a target="_blank" href="http://www.biomedtalk.com/showthread.php?t=1432">';
FORM_HTML_ROW[5] = '<img border="0" alt="Enter Author name into the form and click the \'Go\' button to retrieve the Articles Rank. Please, see details by following this link at BioMedTalk.com." src="http://www.biomedtalk.com/images/misc/ar2anim.gif"/>';
FORM_HTML_ROW[6] = '</a>';
FORM_HTML_ROW[7] = '<br/>';
FORM_HTML_ROW[8] = '<input type="text" value="FamilyName Initials, e.g. Smith JH" name="message_biomedtalk" size="17"/><br/> ';
FORM_HTML_ROW[9] = '<img onclick="download()" alt="Enter Author name into the form and click the \'Go\' button to retrieve the Articles Rank."src="http://www.biomedtalk.com/images/misc/ar1.gif"/><div id="reply_biomedtalk"></div>';
FORM_HTML_ROW[10] = '</form>';
FORM_HTML_ROW[11] = '';

function setCaretPosition(obj, caretPos) {
    if(obj != null) {
        if(obj.createTextRange) {
            var range = obj.createTextRange();
            range.move('character', caretPos);
            range.select();
        } else {
            if (obj.selectionStart) {
                obj.setSelectionRange(caretPos, caretPos);
                obj.focus();
                var evt = document.createEvent("KeyboardEvent");
                evt.initKeyEvent("keypress", true, true, null, false, false, false, false, 0, 32);
                obj.dispatchEvent(evt);
                evt = document.createEvent("KeyboardEvent");
                evt.initKeyEvent("keypress", true, true, null, false, false, false, false, 8, 0);
                obj.dispatchEvent(evt);
            } else {
                obj.focus();
            }
        }
    }
}

function put( value ){
	try{
		document.getElementById('reply_biomedtalk').innerHTML = value;
	}catch(e){}
}

function getGeo(jsonData) {
    var html = '<span style=\"color: #22229c; font-weight: bold;\">is:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>';
       html = html + '<span style=\"color: '+jsonData.Result.color+'; font-weight: bold;\">'+jsonData.Result.family+'</span>';   
	 put(html);
     bObj.removeScriptTag(); 
     setCaretPosition(document.main_biomedtalk.message_biomedtalk, document.main_biomedtalk.message_biomedtalk.value.length);
}

function download(){
	var familyName;
	if (fVar==null){
		familyName = document.main_biomedtalk.message_biomedtalk.value;
	} else {
		familyName = fVar;
	}
	
    put('Processed...');
	
	var req  = 'http://www.biomedtalk.com/arfn.php?familyName='+escape(familyName)+'&output=json&callback=getGeo';
	fVar = null;
	bObj = new JSONscriptRequest(req);
	bObj.buildScriptTag(); 
	bObj.addScriptTag();
}

function defaultFamilyName(FamilyName){
   for (var i = 0; i <= 9; i++) {
	    document.write(FORM_HTML_ROW[i]);
   }

   document.main_biomedtalk.message_biomedtalk.value = FamilyName;
   download();
}