// Design.js	2007-APR-19
window.onerror = trapErrors;
addStyleSheet('/inc/js/css/fixit.css');
showDesign(myDesign);

function myDesign() {
	// The following code block is required
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	if (_timer) {
		clearInterval(_timer);
		_timer = null;
	}
	
	// Do DOM manipulation for this site
	mn('div','tmp1','after','p',2);
	mv('ppc','tmp1');
	sa('tmp1','id','ppc');
	
	// Important: uncloak any DIVs that were cloaked in the stylesheet
	cs('content','display','block');
}


// utility.js 
function cs(id,property,val) { // Change style
	var elm = document.getElementById(id);
	if(elm) elm.style[property] = val;
}

function rm(id) { // Remove
	var elm = document.getElementById(id);
	if(elm) elm.parentNode.removeChild(elm);
}

function mk(elmType,elmId,id1,pos) { // Make
	var newElm = document.createElement(elmType);
	newElm.setAttribute("id",elmId);
	var obj = document.getElementById(id1);
	if(obj) {
		if((pos == 999) || (obj.childNodes.length == 0)) {
			obj.appendChild(newElm);
		} else {
			obj.insertBefore(newElm,obj.childNodes[pos]);
		}
	}
}

function mv(id1,id2) { // Move
	var elm1 = document.getElementById(id1);
	var elm2 = document.getElementById(id2);
	if(elm1 && elm2) {
		elm2.innerHTML = elm1.innerHTML;
		rm(id1);
	}
}

function pt(obj,id) { // Put
	var elm = document.getElementById(id);
	if(elm) elm.innerHTML = obj;
}

function sa(id,attrName,attrValue) { // Switch ID
	var elm = document.getElementById(id);
	if(elm) elm.setAttribute(attrName,attrValue);
}

function mn(elmType,elmId,seq,tag,idx) { // Make new (slightly differnet version of Make)
	var newElm = document.createElement(elmType);
	newElm.setAttribute("id",elmId);
	var obj = document.getElementsByTagName(tag)[idx];
	if(obj) {
		var pos = (seq == 'after') ? obj.nextSibling : obj;
		obj.parentNode.insertBefore(newElm,pos);
	}
}

function sz(id,wd,ht) { // Size
	sa(id,"width",wd);
	sa(id,"height",ht);
}

function showDesign(func) {
	if(typeof func != 'function') return;
	_timer = null; // Set global var
	/* for Mozilla */
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", func, false);
	}
	
	/* for Internet Explorer */
	/*@cc_on @*/
	/*@if (@_win32)
		document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
		var script = document.getElementById("__ie_onload");
		script.onreadystatechange = function() {
			if (this.readyState == "complete") {
				func(); // call the onload handler
			}
		};
	/*@end @*/
	
	/* for Safari */
	if (/WebKit/i.test(navigator.userAgent)) { // sniff
		_timer = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				func(); // call the onload handler
			}
		}, 10);
	}
	
	/* for other browsers */
	attachOnloadEvent(func);
}

// attach func function to window onload event (crossbrowser compatible)
function attachOnloadEvent(func) {
	if(typeof window.addEventListener != 'undefined') {
		// moz, saf1.2, ow5b6.1
		window.addEventListener('load', func, false);
	} else if (typeof document.addEventListener != 'undefined') {
		// MSN/OSX, op7.50, saf1.2, ow5b6.1
		document.addEventListener('load', func, false);
	} else if (typeof window.attachEvent != 'undefined') {
		// ie5.0w, ie5.5w, ie6w
		window.attachEvent('onload', func);
	} else {
		// all other browsers
		if (typeof window.onload == 'function') {
			var oldonload = onload;
			window.onload = function() {
				oldonload();
				func();
			};
		} else {
			window.onload = func;
		}
	}
}

function trapErrors() { return true; }

function includeScript(src) {
	document.write('<sc' + 'ript src="' + src + '" type="text/javascript"></sc' + 'ript>');
}

function addStyleSheet(uri) {
	document.write('<link rel="stylesheet" href="' + uri + '" type="text/css" media="all" />');
}
