var isIE,xmlHttpObj,wrapr,wrapr2,isIE8,url,payload,emptyCallback,singleWrapr,name;


  function ajaxStart(){

	var xmlHttpObj;
	
	try{
		xmlHttpObj = new XMLHttpRequest();
		return(xmlHttpObj);		
	}
	catch(e){	
		try{
			xmlHttpObj = new ActiveXObject("MSxml3.XMLHTTP");
			return(xmlHttpObj);			
		}
			
		catch(e){	
			try{
				xmlHttpObj = new ActiveXObject("MSxml2.XMLHTTP");
				return(xmlHttpObj);
			}
			catch(e){
				try{
					xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
					return(xmlHttpObj);
				}
				catch(e){
					alert("Please use only IE 6 or higher");
					xmlHttpObj = null;
					return(false);
				}
			}
		} 
	}	 

  }
  
  
  


  function ajaxEngine(){
	
	var rnum;
	
	rnum = Math.round(((Math.random()*100)+1));
	//window.alert('rnum is: '+rnum);

	if(xmlHttpObj){		 
		 
			 xmlHttpObj.onreadystatechange = function(){	
		
/*					if(xmlHttpObj.readyState == 4)
				{*/
					switch(xmlHttpObj.readyState){
						case 0:
						
//							wrapr.innerHTML = "Please Wait ...";	

							try{
								if(typeof wrapr != "undefined" || wrapr != null){										
								
									wrapr.innerHTML = "<img src=\"../images23/wait_anime1.gif\" border=\"0\" height=\"\" width=\"\" alt=\"\">";
									
								}
							}
							catch(e){
							//
							}																		
							break;
			
						case 1:

							try{
								if(typeof wrapr != "undefined" || wrapr != null){										
														
									wrapr.innerHTML = "<img src=\"../images23/wait_anime1.gif\" border=\"0\" height=\"\" width=\"\" alt=\"\">";
								
								}
							}
							catch(e){
							//
							}											
//							wrapr.innerHTML = "Initialized and Opened, Please Wait ...";
							break;
			
						case 2:
						
							try{

								if(typeof wrapr != "undefined" || wrapr != null){										
														
									wrapr.innerHTML = "<img src=\"../images23/wait_anime1.gif\" border=\"0\" height=\"\" width=\"\" alt=\"\">";			
									
								}
							}
							catch(e){
							//
							}																		
//							wrapr.innerHTML = "Sent, Please Wait ...";
							break;
			
						case 3:

							try{
								if(typeof wrapr != "undefined" || wrapr != null){													
								
									wrapr.innerHTML = "<img src=\"../images23/wait_anime1.gif\" border=\"0\" height=\"\" width=\"\" alt=\"\">";
									
								}
							}
							catch(e){
							//
							}																										
//							wrapr.innerHTML = "Receiving, Please Wait ...";

							if(!isIE8){
							
								switch(xmlHttpObj.status)
								{
	
	
									case 404:
									    try{
											if(typeof wrapr != "undefined" || wrapr != null){																	
											
												wrapr.innerHTML = "Failure -- Code 404: "+xmlHttpObj.statusText;
												
											}											
										}
										catch(e){
										//
										}																					
										break;
									
									case 200:
									
/*										wrapr.innerHTML = "Status: Transmission Complete!";*/
											
//										wrapr2[0].innerHTML = "Response is :"+xmlHttpObj.responseText; //Debug xmlHttpObj.responseText 

										callback(JSON.parse(xmlHttpObj.responseText));
										xmlHttpObj.close;									
																			
										break;
								
									
									default:

										try{									
											if(typeof wrapr != "undefined" || wrapr != null){																			
											
												wrapr.innerHTML = "Failure -- Code "+xmlHttpObj.status+": "+xmlHttpObj.statusText;	
												
											}
										}
										catch(e){
										//
										}											
										
								}
								
							}

							break;
							
						case 4:
						
						
							if(isIE8){
									
								try{
										if(xmlHttpObj.status == 200){																		
										
											callback(JSON.parse(xmlHttpObj.responseText));
										}
										xmlHttpObj.close;
									}
									catch(e){
									 //
									}
									
							}
						
						
							break;
					}
			  };
/*			  if(isIE8){
			  
				  xmlHttpObj.timeout = 10000;
				  
			  }*/
			  xmlHttpObj.open("POST",url,true);					  
			  xmlHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");			 

			  xmlHttpObj.send(payload);
		}	  
  }






 function callback(obj)
 {
 	emptyCallback = (typeof obj.biographies == "undefined" || obj.biographies == "")? true : false;
	
	if(typeof singleWrapr != "undefined"){

		var i;

		if(!emptyCallback){

			for(i = 0; i < wrapr2.length; i++){
			
				wrapr2[i].style.display = "block";
				
				
				wrapr2[i].childNodes[0].style.display = "block";


				//window.alert("I'm in callback and wrapr2.childNodes.style.display is: "+wrapr2[i].childNodes[0].style.display);//Debug
			}
			
		}
		else{
			
			for(i = 0; i < wrapr2.length; i++){
			
				wrapr2[i].style.display = "none";
				
				
				wrapr2[i].childNodes[0].style.display = "none";
					
				
			}
			
		}
	}
	else{
	
		wrapr.innerHTML = "<div class=\"biography\">"+obj.biographies+"</div><div class=\"citations\">"+obj.citations+"</div>";		
		
	}
 }





function init(){
  
  isIE = (navigator.userAgent.indexOf("MSIE") >= 0) ? true : false;
  isIE8 = (navigator.userAgent.indexOf("MSIE 8") >= 0) ? true: false;
  
  if(typeof name != "undefined"){
  
	  wrapr2 = document.getElementsByName(name);
	  
  }
  
  wrapr = document.getElementById("wrapr");
  
  xmlHttpObj = ajaxStart();
  
  ajaxEngine();

  
 }
