User:BorisTM/SynOrganicBoxInfo.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

//<pre>

function build_synInfoBox() {

	vr_Str=obj.innerHTML; /* obj=document.getElementById('synChemInfoBox'); */
	if (obj.attributes.length < 3 && document.getElementById('synChemInfoBox')) {
// ------------ Get the data
		ip=vr_Str.indexOf('^^',vr_Str.indexOf('theBoxInfo'));
		if (ip > 0) {
			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("http://upload.wikimedia.org/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.style.margin="0 0 0.5em 0.5em";
	obj.style.backgroundColor="RoyalBlue";
	obj.style.borderWidth="0px";
	obj.style.borderCollapse="separate";
	obj.style.padding="0px";
	obj.style.fontSize="95%";
	obj.style.float="right";
	obj.setAttribute("align","right");
	obj.cellPadding="2";
	obj.cellSpacing="1";
	obj.setAttribute("border","0");
	obj.setAttribute("width","326");
	obj=obj.firstChild;

	while (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","#dfefff");


// ------------ Builds the IMAGE section
	build_TR("","4");
	_html = "<img style='border-width: 0px;' ";
	_html += "src='http://www.molbiology.com/wiki/"+_f+"/f1.png' ";
	_html += "alt='The structure of "+inf['name']+"' width='"+inf['width']+"' />";
	new_TD.innerHTML=_html;

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


// ------------ 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");
		if (!(inf['num_syn'] == undefined)) {
		   if (inf['num_syn'] == "small") new_TD.innerHTML=inf['synonyms'];
		   else build_the_synonyms(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","#dfefff");

// ------------ 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("<sup>&nbsp;</sup><a id='id_M'>M</a> (g/mol)<sub>&nbsp;</sub>","Molecular_mass","Molecular_mass","id_M");
	if (!inf['density'] || inf['density']=="") inf['density']="?";
	build_TD_phys("<sup>&nbsp;</sup><a id='id_rho'>&rho;</a> (g/cm<sup>3</sup>)<sub>&nbsp;</sub>","Density","Density","id_rho");
	if (!inf['Tm'] || inf['Tm']=="") inf['Tm']="?";
	build_TD_phys("<sup>&nbsp;</sup><a id='id_Tm'>T<sub><i>m</i></sub></a> (&deg;C)<sub>&nbsp;</sub>","Melting_point","Melting point","id_Tm");
	if (!inf['Td']) {
		build_TD_phys("<sup>&nbsp;</sup><a id='id_Tb'>T<sub><i>b</i></sub></a> (&deg;C)<sub>&nbsp;</sub>","Boiling_point","Boiling point","id_Tb");
		t_CritVal=(!inf['Tb'] || inf['Tb']=="")?'?':inf['Tb'];
	}
	else {
		build_TD_phys("<sup>&nbsp;</sup><a id='id_Td'>T<sub><i>d</i></sub></a> (&deg;C)<sub>&nbsp;</sub>","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","#dfefff");

// ------------ 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","#dfefff");


// ------------ 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>