var IE = document.all ? true : false;
var misc = new Array();
var popup = false;
function openWin(file, width, height) {
	if(!width)	width = 100;
	if(!height)	height = 100;
        x = (screen.width / 2) - (width / 2) - 150;
        y = (screen.height / 2) - (height / 2) - 150;
        var i = Math.round(100*Math.random());
	var win = window.open(file, i,'close=no,width='+width+',height='+height+',top='+y+',left='+x+',top=1,resizable=yes,status=no,scrollbars=yes');
	popup = win;
        return win;
}
function init_dd(dropset) {
	dropset = removeBlankChildren(dropset);
	for(var x=0; x<dropset.childNodes.length; x++) {
		removeBlankChildren(dropset.childNodes[x]);
		dropset.childNodes[x].onmouseover=function() { over(this); };
		dropset.childNodes[x].onmouseout=function() { out(this); };
	}
}
var dropped = false;
function over(obj) {
	if(dropped)	out($(dropped).parentNode);
	var header = obj.firstChild;
	var drop = obj.lastChild;
	drop.style.visibility='visible';
	drop.style.display='block';
	drop.style.left=Left(header)+'px';
	drop.style.top=Top(header)+header.offsetHeight+'px';
	header.className='hover'; 
}
function out(obj) {
	dropped = false;
	obj.firstChild.className = obj.firstChild.className.replace('hover','');
	obj.lastChild.style.visibility='hidden';
}
function draw(at_obj, url, sep_win, w, h) {
	var top = Top(at_obj);
	var left = Left(at_obj);
	var popin = $('popin');
	if(!popin) {
		var tmp_div = document.createElement('div');
		tmp_div.setAttribute('id','popin');
		popin = document.body.appendChild(tmp_div);
		popin.innerHTML = "<div id='popin_top'><a href='javascript:popout();'><img border=1 src='images/ui/x.gif'></div></a><div id='popin_content'></div><div id='popin_bottom'></div>";
	}

	popin.style.display = 'none';
	popin.className = "popin";
	popin.style.left = left+'px';
	if(((parseInt(at_obj.offsetHeight)-window.scrollY + top + h) > window.innerHeight) && (top > h)) // display above
		popin.style.top = (top - h- parseInt(at_obj.offsetHeight))+'px';
	else	popin.style.top = (parseInt(at_obj.offsetHeight) + top)+'px';
	popin.style.display = 'block';
	$('popin_content').style.width = w+'px';
	$('popin_content').style.height = '0px';
	rolldown('popin_content', h);
	if(sep_win) {
		$('popin_content').innerHTML = "<iframe width=100% height=100% frameborder=2 src='"+url+"'></iframe>";
	} else {
		$('popin_content').innerHTML = "<iframe width=0 height=0 frameborder=0 src='/components/load.php?targ=popin_content&url="+url+"'></iframe>";
	}
}
function popout() {
	rollup('popin_content', "$('popin').style.display='none';");
}




function nothing() {	return;	}
var drop_stepper = 4;
var roll_dir = false;
var orig_overflow;
function rolldown(i, h, post, initiated) {
	if(roll_dir != 'up') {
		roll_dir = 'down';
		var w = $(i);
		if(!initiated || (initiated == undefined)) {
			orig_overflow = w.style.overflow;
			w.style.overflow='hidden';
		}
		if(parseInt(w.offsetHeight) < h) {
			w.style.height = parseInt(w.offsetHeight) + drop_stepper+'px';
			setTimeout('rolldown("'+i+'",'+h+',\''+post+'\',1);', 10);
			return;
		} else {
			roll_dir = false;
			//w.style.height = h;
			setTimeout(replace(post, '`', '\\\''),1);
			w.style.overflow=orig_overflow;
		}
	}
}
function rollup(i, post, initiated) {
	if(roll_dir != 'down') {
		roll_dir = 'up';
		var obj = $(i);
		if(parseInt(obj.style.height) > drop_stepper) {
			obj.style.height = parseInt(obj.offsetHeight) - drop_stepper+'px';
			setTimeout('rollup("'+i+'","'+post+'");', 10);
			return;
		} else {
			roll_dir = false;
			obj.style.height = 0+'px';
			obj.style.dispaly='none';
			eval(post);
		}
	}
}
function $(i) {
	return document.getElementById(i);
}
function replace(string,text,by) {
	if(!string)	return '';
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;
	if(string.indexOf) {
		var i = string.indexOf(text);
		if ((!i) && (text != string.substring(0,txtLength))) return string;
		if (i == -1) return string;
		var newstr = string.substring(0,i) + by;
		if (i+txtLength < strLength)	newstr += replace(string.substring(i+txtLength,strLength),text,by);
		return newstr;
	}
}

function Left(obj) {
	if(obj) {
		var x = eval(obj).offsetLeft;
		elem = eval(obj).offsetParent;
		while (elem != null) {
			x += elem.offsetLeft;
			elem = elem.offsetParent;
		}
		return x;
	}
}
function Top(obj) {
	y = eval(obj).offsetTop;
	elem = eval(obj).offsetParent;
	while (elem != null) {
		y += parseFloat(elem.offsetTop);
		elem = elem.offsetParent;
	}
	return y;
}
function getScrollY() {	return IE ? document.documentElement.scrollTop  : window.pageYOffset; }
function getScrollX() {	return IE ? document.documentElement.scrollLeft : window.pageXOffset; }



function debug(elem) {
	var properties = "<HEAD><link href='/styles/sections.css' rel='stylesheet' type='text/css'></HEAD><BODY><TABLE WIDTH='100%'><TR><TH>Element<TH>Document<TH>Window</TR><TD VALIGn=TOP>";
	for(var e in elem) 
		properties += '<LI>'+e + ": " + elem[e]+"</LI>\n";
	properties += "<TD VALIGn=TOP>";
	for(var e in document) 
		properties += '<LI>'+e+(document.e ? ' = '+document.e : '')+"</LI>\n";
	properties += "<TD VALIGn=TOP>";
	for(e in window) 
		properties += '<LI>'+e;
	properties += "</TR></TABLE></BODY>";

	var newwindow=window.open('','name','height=700,width=750,scrollbars=yes,scroll=yes');
	var tmp = newwindow.document;
	tmp.write(properties);
}

/* admin functions */
function is_numeric(val) {
	var valid = '1234567890';
	for(var x in val) {
		if(valid.indexOf(val[x]) == -1) {
			return false;
		}
	}
	return true;
}
function Pad(num,intPlaces) {
    var str = String(num);
    var intLength = str.length;
    var intDifference = intPlaces-intLength;
    while (intDifference>0) {
	str = "0"+str;
	intDifference--;
    }
    return str;
}

function Mask(id, mask) {
	var sections = mask.split(/[^#]/g);
	var delimiters = mask.replace(/[#]/g, '');
	var start  = document.getElementById(id).value.replace(/[^a-z0-9A-Z*%^ ]/g, '');
	var result = '';
	var place = 0;
	for(var i in sections) {
		if(place+sections[i].length > start.length) {
			document.getElementById(id).value = result.concat(start.substring(place));
			return;
		}
		if(start.substring(place, place+(sections[i].length) != undefined))
			result = result.concat(start.substring(place, place+(sections[i].length))+delimiters.charAt(i));
		place += sections[i].length;
	}
	document.getElementById(id).value = result.concat(start.substring(place));
}


function view(src,obj) {
	if($('image_viewer')) {
		document.body.removeChild($('image_viewer'));
	}
	if(!src)	return;
	var tmp = document.createElement('div');
	tmp.setAttribute('id','image_viewer');
	var viewer = document.body.appendChild(tmp);
	viewer.className = 'floater';
	viewer.style.height = '200px';
	viewer.style.width = '200px';
	viewer.style.top = Top(obj)+10+'px';
	viewer.style.left = Left(obj)+'px';
	viewer.style.overflow = 'auto';
	viewer.innerHTML = '<img src="'+src+'"></div>';
}
function removeBlankChildren(rent) {
	for(var x=0; x<rent.childNodes.length; x++) {
		if(rent.childNodes[x] && rent.childNodes[x].nodeName == '#text' && rent.childNodes[x].innnerHTML == undefined) {
			//if(rent.className==nav_listing nav1) 
			rent.removeChild(rent.childNodes[x]);
		}
		if(rent.childNodes[x] && rent.childNodes[x].nodeName == '#comment') 
			rent.removeChild(rent.childNodes[x]);
	}
	return rent;
}
