// --------------------
//   JAVASCRIPT
// --------------------
// include JavaScript
function include(astrFile){
		var script = document.createElement('script');
		script.src = astrFile;
		script.type = 'text/javascript';
		script.defer = true;
		document.getElementsByTagName('head').item(0).appendChild(script);
}


// --------------------
//   Object
// --------------------
// Return Object IE/Other Compatible
function getObj(id){
	return document.all && document.all(id) || document.getElementById && document.getElementById(id);
}


// --------------------
//   Event
// --------------------
// EventListener IE/Other Compatible
function addEvent(eventTarget, eventName, func){
	if(eventTarget.addEventListener){
		eventTarget.addEventListener(eventName, func, false);
	} else if(window.attachEvent){
		eventTarget.attachEvent('on'+eventName, function(){func.apply(eventTarget);});
	}
}


// --------------------
//   Cookie
// --------------------
function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3) {
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (xx1 < len) {
        xx2 = tmp1.indexOf(";", xx1);
        tmp2 = tmp1.substring(xx1 + 1, xx2);
        xx3 = tmp2.indexOf("=");
        if (tmp2.substring(0, xx3) == key) {
            return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
        }
        xx1 = xx2 + 1;
    }
    return("");
}
function setCookie(key, val, tmp) {
    tmp = key + "=" + escape(val) + "; ";
    tmp += "path=/; ";
    tmp += "expires=Tue, 31-Dec-2030 23:59:59; ";
    document.cookie = tmp;
}
function clearCookie(key) {
    document.cookie = key + "=" + "xx; expires=Tue, 1-Jan-1980 00:00:00;";
}


// --------------------
//   Class IE/Other Compatible
// --------------------
function getClass(e){
	var c;
	if(document.all) c = e.getAttribute("className");
	else c = e.getAttribute("class");
	return (!c)?"":c;
}

function setClass(e, c){
	if(document.all) return e.setAttribute("className", c);
	else return e.setAttribute("class" , c);
}

function addClass(e, c){
	if(!getClass(e).match(c)) c = getClass(e) + " " + c;
	else c = getClass(e);
	setClass(e, c);
}

function removeClass(e, c){
	if(getClass(e)) setClass(e, getClass(e).replace(c, ""));
}




function cumulativeOffset(element) {
	var valueT = 0;
	var valueL = 0;
	do {
		valueT += element.offsetTop  || 0;
		valueL += element.offsetLeft || 0;
		element = element.offsetParent;
	} while (element);
	return [valueL, valueT];
}

//Post condition: if childNodes[n] is refChild, than childNodes[n+1] is newChild.
function DOMNode_insertAfter(newChild,refChild){
  var parent=refChild.parentNode;
  if(parent.lastChild==refChild) return parent.appendChild(newChild);
  else return parent.insertBefore(newChild,refChild.nextSibling);
}


function windowOpen(url){
	var openedWindow = window.open(url,"", 'scrollbars=yes,resizable=yes,width=850,height=700');
	addEvent(openedWindow, "load", windowOpened);
}

function windowOpened(event){
	event = event || window.event;
	if(this.window.document.body.scrollHeight < 700){
		this.window.resizeTo(850, document.body.scrollHeight);
	}
}

function windowClose(){
	window.close();
}


function addZero(n){
	if(n < 10) n = "0" + n;
	return n;
}

function removeZero(str){
	return str.replace(/^0/, "");
}

