Jump to content

User:BorisTM/NatOrganicBoxInfo.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BorisTM (talk | contribs) at 17:55, 29 January 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<pre>

function build_InfoBox() {
// ------------ Get the data
   vr_Str=obj.innerHTML;
   ip=vr_Str.indexOf('^^',vr_Str.indexOf('theBoxInfo'));
   if (ip > 0) {
	na_ua=navigator.userAgent;
	tb_nf=(na_ua.indexOf("Netscape") >= 0 || na_ua.indexOf("Firefox") >= 0)?true:false;
	if (tb_nf)
		vr_Str=vr_Str.substring((ip-(-2)),vr_Str.lastIndexOf('</p',vr_Str.lastIndexOf('</div')));
	else 
      	vr_Str=vr_Str.substring((ip-(-2)),vr_Str.lastIndexOf('</P',vr_Str.lastIndexOf('</DIV')));
	var tem=vr_Str.split("^^");
	i1L=tem.length;
	for (i1=0; i1<i1L; i1++) {
         ip_eq=tem[i1].indexOf('=');
         prop_Name=clear_Spaces(tem[i1].substring(0,ip_eq));
         ip_eq += 1;
         prop_Value=clear_Spaces(tem[i1].substring(ip_eq));
         inf[prop_Name]=prop_Value;
      }
   }

// ------------ Gets the image src
	vr_Str=obj.innerHTML;
	ip=vr_Str.indexOf("/media/wikipedia/");
	if (tb_nf) {
		ip_2=vr_Str.indexOf("><a href=");
		inf['image']=vr_Str.substring(ip,(vr_Str.indexOf(" alt=",ip)-1));
		inf['path']=vr_Str.substring((ip_2-(-10)),(vr_Str.indexOf(" class=",ip_2)-1));
	}
	else {
		ip_2=vr_Str.indexOf("><A HREF=");
		inf['image']=vr_Str.substring(ip,(vr_Str.indexOf(" ALT=",ip)-1));
		inf['path']=vr_Str.substring((ip_2-(-10)),(vr_Str.indexOf(" CLASS=",ip_2)-1));
	}


// ------------ Sets the TABLE's attributes
	obj.setAttribute("align","right");
	obj.style.backgroundColor="#C0C090";
	obj.cellPadding="2";
	obj.cellSpacing="1";
	obj.style.margin="0 0 0.5em 0.5em";
	obj.setAttribute("width","326");
	obj.style.borderWidth="1px";
	obj=obj.firstChild;
	obj.removeChild(obj.firstChild);


// ------------ Builds the NAME header
	if (!inf['name'] || inf['name']=="") {
		vr_Str=document.title;
		firstIndex=vr_Str.indexOf(":")>0?vr_Str.indexOf(":")+1:0;
		inf['name']=vr_Str.substring(firstIndex,vr_Str.indexOf(" - Wikipedia, the free encyclopedia"));
	}
	build_TR(document.createTextNode(inf['name']),"4","#F8EABA");


// ------------ Builds the IMAGE section
	build_TR("","4");
	if (!inf['width'] || inf['width']=="") inf['width']=320;
	code_Storage = "<a href='"+inf['path']+"' class='internal' ";
	code_Storage += "title='The structure of "+inf['name']+"'><img style='border-width: 0px;' ";
	code_Storage += "src='"+inf['image']+"' ";
	code_Storage += "alt='The structure of "+inf['name']+"' width='"+inf['width']+"' /></a>";
	new_TD.innerHTML=code_Storage;
	


/* ---------------------------------------
          Builds the GENERAL header 
   --------------------------------------- */
	build_TR(document.createTextNode("General"),"4","#F8EABA");


// ------------ Builds the IUPAC NAME section
	if (!inf['IUPAC'] || inf['IUPAC']=="") inf['IUPAC']="?";
	build_TR(build_wiki_A("IUPAC_nomenclature","IUPAC_nomenclature","Chemical name"),"4");
	build_TR("","4");
	new_TD.innerHTML=inf['IUPAC'];

// ------------ Builds the SYNONYMS section
	if (inf['synonyms'] && !(inf['synonyms']=="")) {
		build_TR(build_wiki_A("Synonyms","Synonyms","Synonyms"),"4");
		build_TR("","4");
		new_TD.innerHTML=inf['synonyms'];
	}


// ------------ Builds the ABBREVIATION section
	if (inf['abbreviations'] && !(inf['abbreviations']=="")) {
		build_TR(build_wiki_A("Abbreviations","Abbreviations","Abbreviations"),"2");
		build_TD("");
		new_TD.innerHTML=inf['abbreviations'];
		new_TD.setAttribute("verticalAlign","top");
	}

// ------------ Builds the FORMULA section
	if (!inf['formula'] || inf['formula']=="") inf['formula']="?";
	build_TR(build_wiki_A("Chemical formula","Chemical formula","Chemical formula"),"2");
	new_TD.setAttribute("verticalAlign","top");
	new_TD.setAttribute("whiteSpace","nowrap");
	new_TD.setAttribute("width","50%");
	build_TD("");
	new_TD.innerHTML=inf['formula'];
	new_TD.setAttribute("width","50%");


/* ---------------------------------------
    Builds the PHYSICAL PROPERTIES header     
   --------------------------------------- */
	build_TR(document.createTextNode("Physical properties"),"4","#F8EABA");

// ------------ Builds the MAS, DENSITY, and TEMPERATURES sections
	new_TR=document.createElement("TR");
	obj.appendChild(new_TR);
	if (!inf['mass'] || inf['mass']=="") inf['mass']="?";
	build_TD_phys("<a id='id_M'>M</a> (g/mol)","Molecular_mass","Molecular_mass","id_M");
	if (!inf['density'] || inf['density']=="") inf['density']="?";
	build_TD_phys("<a id='id_rho'>&rho;</a> (g/mol)","Density","Density","id_rho");
	if (!inf['Tm'] || inf['Tm']=="") inf['Tm']="?";
	build_TD_phys("<a id='id_Tm'>T<sub><i>m</i></sub></a> (°C)","Melting_point","Melting point","id_Tm");
	if (!inf['Td']) {
		build_TD_phys("<a id='id_Tb'>T<sub><i>b</i></sub></a> (°C)","Boiling_point","Boiling point","id_Tb");
		t_CritVal=(!inf['Tb'] || inf['Tb']=="")?'?':inf['Tb'];
	}
	else {
		build_TD_phys("<a id='id_Td'>T<sub><i>d</i></sub></a> (°C)","Decomposition_temperature","Decomposition temperature","id_Td");
		t_CritVal=(!(inf['Td']==""))?inf['Td']:'?';
	}
	new_TR=document.createElement("TR");
	obj.appendChild(new_TR);
	build_TD_phys(inf['mass']);
	build_TD_phys(inf['density']);
	build_TD_phys(inf['Tm']);
	build_TD_phys(t_CritVal);

/* ---------------------------------------
    Builds the CHEMICAL PROPERTIES header 
   --------------------------------------- */
	build_TR(document.createTextNode("Chemical properties"),"4","#F8EABA");

// ------------ Builds the pKi section
	build_acid_base("pI","Isoelectric_point","Isoelectric point","p<i>I</i></a>");

// ------------ Builds the pKa section
	build_acid_base("pKa","Acid_dissociation_constant","Acid dissociation constant","p<i>K</i><sub>a</sub></a>");

// ------------ Builds the H-BOND ACCEPTOR section
	build_H_bond("h_bond_acceptor"," acceptors");


// ------------ Builds the H-BOND DONOR section
	build_H_bond("h_bond_donor"," donors");


// ------------ Builds the TAUTOMERS section
	if (inf['tautomers'] && !(inf['tautomers']=="")) {
		build_TR(build_wiki_A("Tautomers","Tautomer","Tautomers"),"2");
		build_TD(document.createTextNode(inf['tautomers']));
	}	

/* ---------------------------------------
       Builds the MISCELLANEOUS header 
   --------------------------------------- */
	build_TR(document.createTextNode("Miscellaneous"),"4","#F8EABA");


// ------------ Builds the CAS section
	if (!inf['CAS'] || inf['CAS']=="") inf['CAS']="?";
	build_TR(build_wiki_A("CAS_registry_number","CAS registry number","CAS"),"2");
	build_TD(build_ref_A(inf['CAS']));


// ------------ Builds the EINECS section
	if (inf['EINECS'] && !(inf['EINECS']=="")) {
		build_TR(build_wiki_A("EINECS_number","EINECS","EINECS"),"2");
		build_TD(document.createTextNode(inf['EINECS']));
	}


// ------------ Builds the PubChem section
	if (!inf['PubChem'] || inf['PubChem']=="") inf['PubChem']="?";
	build_TR(build_wiki_A("PubChem","PubChem","PubChem"),"2");
	build_TD(build_ref_A(inf['PubChem']));


/* ------------ Builds the SMILES section
	if (!inf['SMILES'] || inf['SMILES']=="") inf['SMILES']="?";
	build_TR(build_wiki_A("SMILES","SMILES","SMILES"),"4");
	build_TR(document.createTextNode(inf['SMILES']),"4");
*/

}


//</pre>