/*********************************
utils.js for EA.com
js code for EA.com redesign prototype
excerpts from
http://www.obliquemotion.com/js/utilsDHTML.js
license: http://creativecommons.org/licenses/by/2.0/
code by Byron Tredwell (byron(AT)blastradius.com)
*********************************/
//simple object validation
function check(e){
if(typeof e == "string"){elm = getElm(e);}else{elm = e;}
if(elm == null || typeof elm != "object") throw Error("Element "+e+" does not exist. It is type "+typeof elm);
return elm;
}
function getElm(e,f){
if (f == null) f = self;
return f.document.getElementById(e);
}
/***
GET/CREATE/DELETE/WRITE
***/
function createElm(t,id,p){
if (p == null)
p = document.body;
p = check(p);
var elm = document.createElement(t);
if (id != null && id != "") elm.id = id;
p.appendChild(elm);
return elm;
}
function deleteElm(e){e = check(e); e.parentNode.removeChild(e);}
function clearElm(e){
e = check(e);
while (e.hasChildNodes()) { e.removeChild(e.lastChild) };
}
function writeTo(e,c){
e = check(e);
if(c == null) c = " ";
var tNode = document.createTextNode(c);
e.appendChild(tNode);
}
// portions of this function ripped from http://wsabstract.com/javatutors/dynamiccontent4.shtml by Rey Nunez
function writeHTML(e,c){
e = check(e);
if(c == null) c = "
";
if(document.innerHTML != -1){
e.innerHTML = c;
}else if(document.createRange != -1){
rng = document.createRange();
rng.setStartBefore(e);
htmlFrag = rng.createContextualFragment(c);
clearElm(e);
e.appendChild(htmlFrag);
}else{
e.document.open();
e.document.writeln(c);
e.document.close();
}
}
/***
CLIPPING
***/
function setClip(e,t,r,b,l)
{
if(t==null) t=0;
if(r==null) r=0;
if(b==null) b=0;
if(l==null) l=0;
e.style.clip='rect('+t+'px '+r+'px '+b+'px '+l+'px)';
}
function getClip(e,s)
{
var clipv = e.style.clip.split('rect(')[1].split(')')[0].split(' ');
for(i=0;i