function getElem( idString ) {
	var obj = null;
	if ( document.getElementById ) {
		obj = document.getElementById( idString );
	} else if ( document.layers
				&& document.layers[idString] ) {
		obj = document.layers[idString]
	} else if ( document.all
				&& document.all[idString] ) {
		obj = document.all[idString]
	}
	return obj;
}

function showById(menuId) {
	getElem(menuId).style.display="block";
}

function hideById(menuId) {
	getElem(menuId).style.display="none";
}

function article(newUrl)
{
	opener.window.location.href = newUrl;
}

function joe(newWin) {
	var joeWin=window.open(newWin,"","width=350, height=350, scrollbars=yes, menubar=no, resizable=yes");
	joeWin.focus();
	return;
}

function isUndefined(v) {
	var undef;
	return v===undef;
}

function popper(src, w, h, features) {
	var _POPUP_FEATURES = 'location=0,statusbar=1,menubar=0';
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	if (isUndefined(features)) {
		features = _POPUP_FEATURES;
	}
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+','+features;
	win = window.open( src.getAttribute('href'), src.getAttribute('target') || '_blank', winprops);
	if (win && win.focus) { win.focus(); }
	return win;
}

function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function validateEmail(email, msg, optional)
{
	if (!email.value && optional)
	{
		return true;
	}
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	if (!re_mail.test(email.value))
	{
		alert(msg);
		email.focus();
		email.select();
		return false;
	}
	return true;
}

function val_generic_form(theForm,fieldArray)
{
	var x = 0;

	for(x=0;x<=fieldArray.length;x++)
	{
		if(!theForm.elements[fieldArray[x][0]].value)
		{
			alert("You need to fill in " + fieldArray[x][1]);
			return false;
		}

		if (fieldArray[x][2] && theForm.elements[fieldArray[x][0]].value.length > fieldArray[x][2])
		{
		alert("You are over the limit of " + fieldArray[x][2] + " characters. You typed " + theForm.elements[fieldArray[x][0]].value.length + " characters.");
		return false;
		}
	}
	return true;
}

function loadornot(){
	var pop_it = getCookie("popunder");
	if (pop_it < 1){
		loadpopunder();
		setCookie("popunder", 1, 0, "/");
	}
}

function popornot(){
	var pop_it = getCookie("popup");
	if (pop_it < 1){
		loadpopup();
		setCookie("popup", 1, 0, "/");
	}
}

/*** TODO: make the pop(up|under) code more general purpose **/
function loadpopunder(){
	var pop_url="http://vvmedia.com/pop_new.php";
	var winfeatures="width=720,height=300,scrollbars=0,resizable=0,toolbar=0,location=0,menubar=0,status=0,directories=0";
	var win2 = window.open(pop_url,"",winfeatures);
	if ( win2 ) {
		win2.blur();
	}
}

function loadpopup(){
	var pop_url="/generic/ads/hov.php";
	var winfeatures="width=550,height=480,top=100,left=120,scrollbars=0,resizable=0,toolbar=0,location=0,menubar=0,status=0,directories=0";
	var win2 = window.open(pop_url,"",winfeatures);
	if ( win2 ) {
		win2.focus();
	}
}
/**********************************
* WATCH OUT! Executable.
* Loads the popunder if applicable.
***********************************/
loadornot();
// popornot();
