var isIE = document.all ? true : false;

function $(s) { 	return	document.getElementById(s);	}

function replace(str,find,replacement) {
	if(!str)	return '';
	var strLength = str.length, txtLength = find.length;
	if ((strLength == 0) || (txtLength == 0)) return str;
	if(str.indexOf) {
		var i = str.indexOf(find);
		if ((!i) && (find != str.substring(0,txtLength))) return str;
		if (i == -1) return str;
		var newstr = str.substring(0,i) + replacement;
		if (i+txtLength < strLength)	newstr += replace(str.substring(i+txtLength,strLength),find,replacement);
		return newstr;
	}
}
function string_generator(desired_len, alpha, symbols) {
	var choose_from = '0123456789';
	if(alpha)      choose_from += 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ';
	if(symbols)    choose_from += '!@#$%^&*()_+-=';
	choose_from_len = choose_from.length;

	var str = '';
	for(var z = 0; z < desired_len; z++)
		str  += choose_from[Math.floor(Math.random()*choose_from_len)];
	return str;
}


function removeBlankChildren(rent, identifier) {
	//if(identifier=='Weather')	alert(rent.innerHTML);
	for(var x=0; x<rent.childNodes.length; x++) {
		//if(identifier=='Weather')	alert(rent.childNodes[x].nodeName+':'+rent.childNodes[x].innerHTML);
		if(rent.childNodes[x] && rent.childNodes[x].nodeName == '#text' && rent.childNodes[x].innerHTML == 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;
}
function remove(obj) {
	if(obj && obj.parentNode)	obj.parentNode.removeChild(obj);
}

/* obstrucated */
function ParseXML(XML,Tag_Label){if(typeof(Tag_Label)=='string')Tag_Label=new Array(Tag_Label);XML=replace(XML,'\n',"\\\r");var tmp=new Array();iterations=0;for(var index in Tag_Label){var aN=Tag_Label[index];aN=replace(aN,'|',"->");var regEx=new RegExp("<"+aN+".*?>(.*?)</"+aN+">","i");if(XML){tmp=XML.match(regEx);if(tmp){XML=(tmp[2]&&(tmp[2]!=undefined))?tmp[2]:tmp[1];iterations++;}}}return(iterations==Tag_Label.length)?XML:'';};function EatXML(XML,Tag_Label){if(typeof(Tag_Label)=='string')Tag_Label=new Array(Tag_Label);unsafe=Array("\n","  ");XML=XML.replace(unsafe,"");for(var index in Tag_Label){var aN=Tag_Label[index];var regEx=new RegExp("<"+aN+".*?>(.*?)</"+aN+">","i");XML=XML.replace(regEx,'');}return XML;};function ltrim(toTrim,ac){if(!ac||ac==undefined)ac="\\s";ac=ac||"\\s";return toTrim.replace(new RegExp("^["+ac+"]+","g"),"");};function rtrim(toTrim,ac){if(!ac||ac==undefined)ac="\\s";return toTrim.replace(new RegExp("["+ac+"]+$","g"),"");};function trim(toTrim,ac){return rtrim(ltrim(toTrim,ac),ac);};function ParseFirstXML(XML){var regEx=new RegExp("<(.*?)>(.*?)</\\1>");var tmp=XML.match(regEx);var ary=new Array();if(tmp){tmp.shift();return tmp;}else return false;};

function load(url,params,pZ){
	if(pZ==undefined)	pZ=true;

	if(url.indexOf('?')== -1)	url=url+'?';
	var paramStr='';
	if(params&&(params!=undefined)){
		for(var i in params){
			paramStr+=i+'='+params[i]+'&';
		}
	}
	if(typeof window.ActiveXObject!='undefined')
		requestObj=new ActiveXObject("Microsoft.XMLHTTP");
	else 	requestObj=new XMLHttpRequest();
	if(url.indexOf('?')== -1) 
		url=url+'?_inline';
	else 	url=rtrim(url,'&')+'&_inline';
	if(pZ==undefined) pZ=true;
	requestObj.open(pZ?'POST':"GET",url,false);
	requestObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	requestObj.send(pZ?paramStr:null);
	return requestObj.responseText;
}

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 isIE ? document.documentElement.scrollTop  : window.pageYOffset; }
function getScrollX() {	return isIE ? document.documentElement.scrollLeft : window.pageXOffset; }

function getWinWidth() {	return isIE ? document.body.offsetWidth : window.innerWidth; }
function getWinHeight() {	return isIE ? document.body.offsetHeight : window.innerHeight; }
function getFullWinWidth() {	return isIE ? document.body.offsetWidth : document.body.clientWidth; }
function getFullWinHeight() {	return isIE ? document.body.offsetHeight : document.body.scrollHeight; }
function getScrollHeight() {	return isIE ? document.body.scrollTop : window.pageYOffset; }

document.onmousemove = mouseMove; 
var mousePos;
function mouseMove(e){ 
    e = e || window.event; 
    mousePos = mouseCoords(e); 
} 

function mouseCoords(evt){ 
	if(evt.pageX || evt.pageY)	
		return {x:evt.pageX, y:evt.pageY}; 
	else 	return { 
			x:evt.clientX + document.body.scrollLeft - document.body.clientLeft, 
			y:evt.clientY + document.body.scrollTop  - document.body.clientTop 
		}; 
} 
function isOver(obj, x, y) {	// see if cursor is over an object
	if(x==undefined)	x = mousePos['x'];
	if(y==undefined)	y = mousePos['y'];

	//alert('('+x+'>='+Left(obj)+') && ('+y+'>='+Top(obj)+') && ('+x+'<='+(Left(obj)+obj.offsetWidth)+') && ('+y+'<='+(Top(obj)+obj.offsetHeight)+')') 
	if((x>=(Left(obj)-getScrollX())) && (y>=(Top(obj)-getScrollY())) && (x<=(Left(obj)+obj.offsetWidth-getScrollX())) && (y<=(Top(obj)+obj.offsetHeight-getScrollY())) ) 
		return true;
	else	return false;
}

function parseNumber(tmp_num) {
	if(tmp_num=='')	return 0;
	if(tmp_num == undefined) return 0;
	var num = tmp_num.toString();
	num = num.toString();
	var str = '';
	if(num.indexOf) 
		while(num.indexOf(',') != -1)
			num = num.replace(',', '');
	return parseFloat(num);
}

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);
}

var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var daysOfWeek = new Array('Sun','Mon','Tues','Wed','Thu','Fri','Sat','Sun');

function changeDate(inp) {
	var month = $(inp.id+'_month').value<10 ? '0'+$(inp.id+'_month').value : $(inp.id+'_month').value;
	var day = $(inp.id+'_day').value<10 ? '0'+$(inp.id+'_day').value : $(inp.id+'_day').value;
	inp.value = $(inp.id+'_year').value+'-'+month+'-'+day;
}

function onlyNumbers(targ) {
	var newNum = '';
	var nums = '1234567890';
	for(var x=0; x<targ.value.length; x++) 
		if(nums.indexOf(targ.value[x])!=-1)	newNum += targ.value[x];
	if(newNum!=targ.value)	targ.value = newNum;
}
