Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

function array_key_exists ( key, obj ) {
	if( !obj || (obj.constructor !== Array && obj.constructor !== Object) ){
		return false;
	}
	return key in obj;
}

function bdiv() {
	if(document.getElementById('playerdiv')) {
		if(document.getElementById('playerdiv').style.visibility = 'visible') {
			document.getElementById('daclor').innerHTML = '';
		}
	}
	document.getElementById('gback').className = 'gback';
	document.getElementById('ginfo').className = 'ginfo';
}

function checktypes() {
	var cpost = 'checktypes=';
	var ctype = document.getElementsByClassName('ctype');
	for(i=0; i < ctype.length; i++) {
		var idbox = ctype[i].id;
		var idkey = ctype[i].id;
		if( document.getElementById(idbox).checked ) {
		/*	if(cpost.indexOf('checktypes') == -1) {
				cpost = cpost + (cpost.indexOf('?') == -1 ? '?' : '&') + 'checktypes=';
			}
		*/	cpost = cpost + idkey + '|';
		}
	}
	var obj = false;
	var our = this;
	if(window.XMLHttpRequest) {
		our.obj = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		our.obj = new ActiveXObject('Microsoft.XMLHTTP');
	}
	our.obj.open('POST', 'ajax/checktypes.php', false);
	our.obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	our.obj.onreadystatechange = function() {
		if (our.obj.readyState == 4 && our.obj.status == 200) {
			return our.obj.responseText;
		}
	}
	our.obj.send(cpost);
}

function chmap(type, zoom) {
	if(type) {
		var index = new Array('Normal','Satellite','Hybrid','Physical');
		var count = 0;
		while(count <= 3) {
			document.getElementById('id' + index[count]).className = 'off';
			count++;
		}
		document.getElementById('id' + type.id).className = 'on';

		if(map) { map.setMapType(type.obj); }

		var obj = false;
		var our = this;
		if(window.XMLHttpRequest) {
			our.obj = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			our.obj = new ActiveXObject('Microsoft.XMLHTTP');
		}
		our.obj.open('POST', 'ajax/chmap.php?type=' + type.id.toLowerCase(), true);
		our.obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		our.obj.onreadystatechange = function() {
			if (our.obj.readyState == 4 && our.obj.status == 200) {
				return our.obj.responseText;
			}
		}
		our.obj.send(null);
	}
	if(zoom) {
		var obj = false;
		var our = this;
		if(window.XMLHttpRequest) {
			our.obj = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			our.obj = new ActiveXObject('Microsoft.XMLHTTP');
		}
		our.obj.open('POST', 'ajax/chmap.php?zoom=' + zoom, true);
		our.obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		our.obj.onreadystatechange = function() {
			if (our.obj.readyState == 4 && our.obj.status == 200) {
				return our.obj.responseText;
			}
		}
		our.obj.send(null);
	}
}

function circload(id) {
	document.getElementById(id).innerHTML = '<p><img src="images/otc/circload.gif" alt="" /></p>';
}

function daembed() {
	player = document.getElementById('daembedsrc');
	player.height	= (player.height / player.width) * 370;
	player.width	= 370;
}

function divver(div,url) {
	var obj = false;
	var our = this;
	if(window.XMLHttpRequest) {
		our.obj = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		our.obj = new ActiveXObject('Microsoft.XMLHTTP');
	}
	our.obj.open('POST', url, true);
	our.obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	our.obj.onreadystatechange = function() {
		if (our.obj.readyState == 4 && our.obj.status == 200) {
			updatepage(our.obj.responseText, div);
		}
	}
	our.obj.send(null);
}

function emailuser(ibuid,cuid) {
	if(!document.emailuser.iname.value) {
		window.alert('Please enter your name.');
		document.emailuser.iname.focus();
	} else if(!isEMailAddress(document.emailuser.email.value)) {
		window.alert('Please enter a valid email address.');
		document.emailuser.email.focus();
	} else if(!document.emailuser.iemsg.value) {
		window.alert('Please enter a message.');
		document.emailuser.iemsg.focus();
	} else {
		divver('ginfo', 'ajax/emailuser.php?uuid='+ibuid+'&cuid='+cuid+'&iname='+document.emailuser.iname.value.replace("'","\'")+'&email='+document.emailuser.email.value+'&iemsg='+document.emailuser.iemsg.value.replace("'","\'"));	
	}
}

function getElementPosition(id){
	var offset		= document.getElementById(id);
	var offsetLeft	= 0;
	var offsetTop	= 0;
	while(offset) {
		offsetLeft	+= offset.offsetLeft;
		offsetTop	+= offset.offsetTop;
		offset		 = offset.offsetParent;
	}
	if(navigator.userAgent.indexOf('Mac') != -1 
	&& typeof document.body.leftMargin != 'undefined') {
		offsetLeft	+= document.body.leftMargin;
		offsetTop	+= document.body.topMargin;
	}
	return {left:offsetLeft,top:offsetTop};
}

function ibu_about(ibuid,cuid){
	overlay(); divver('ginfo', 'ajax/ibu_about.php?uuid='+ibuid+'&cuid='+cuid);
}
function ibu_email(ibuid,cuid){
	overlay(); divver('ginfo', 'ajax/ibu_email.php?uuid='+ibuid+'&cuid='+cuid);
}

function inout(level, bool) {

	var zoom = map.getZoom();
	zoom = parseInt(zoom) + parseInt(level);

	if(zoom >= 1 && zoom < 14) {
		map.setZoom(zoom);
		if(bool) { chmap(null, zoom); }

		var lefty = Math.round((105 / 14) * (zoom - 1));
		document.getElementById('ctrlzoom').style.left = lefty + 'px';
	}

}

function ipopup(url) {
	overlay(); divver('ginfo', 'includes/' + url);
}

function isEMailAddress(email) {
	return isValidText(email,"^([\\w\\._-]+)@([\\w_-]+\\.)+([\\w_]+)$");
}

function isValidText(input,expr) {
	if (window.RegExp){
		if(typeof(expr) == 'string')
			expr = new RegExp(expr);
		return expr.test(input);
	} else {
		return true;
	}
}

function overlay() {

	document.getElementById('gback').className = 'gback_on';
	document.getElementById('ginfo').className = 'ginfo_on';

	var dimh = document.body.getDimensions().height;
	if( dimh < screen.height) { dimh = screen.height; }
	dimh = parseInt(dimh);

	document.getElementById('gback').style.height = dimh + 'px';

	var dimw = document.body.getDimensions().width;
	dimw = parseInt(dimw);

	var ourwidth = 1020;
	if(dimw > ourwidth) { var extra = (dimw - ourwidth) / 2; } else { var extra = 0; }
	var overlayw = 540;

	var left = (ourwidth - overlayw) / 2;
	left += extra;
	left = parseInt(left);

	var top = window.pageYOffset || document.documentElement.scrollTop || 0;
	top += 80;
	if(top < 100) { top = 100; }
	top = parseInt(top);

	document.getElementById('ginfo').style.top	= top + 'px';	
	document.getElementById('ginfo').style.left	= left + 'px';	

}

function playaud(id) {
	var pawindow = window.open('ajax/playaud.php?uid=' + id, '', 'height=300,location=0,menubar=0,resizable=1,scrollbars=0,status=0,titlebar=0,toolbar=0,width=500'); pawindow.focus();
}
function playemb(id) {
	overlay(); divver('ginfo', 'ajax/playemb.php?uid=' + id); setTimeout('daembed()', 1000);
}
function playvid(id) {
	overlay(); divver('ginfo', 'ajax/playvid.php?uid=' + id);
}

function updatepage(ihtml,ident){
	document.getElementById(ident).innerHTML = ihtml;
}