function popUp (url, width, height, addbase) {
	
	if (parseInt(navigator.appVersion) >= 4 ) {
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;}

	args = "width=" + width + ","
	+ "height=" + height + ","
	+ "location=0," 
	+ "menubar=0,"
	+ "resizable=1,"
	+ "scrollbars=1,"
	+ "status=no," 
	+ "titlebar=1,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "screenx=" + xposition + ","  //NN Only
	+ "screeny=" + yposition + ","  //NN Only
	+ "left=" + xposition + ","     //IE Only
	+ "top=" + yposition;           //IE Only	
	
	
	if (addbase == null || addbase == undefined) addbase = true;
	
	var base = addbase ? document.getElementsByTagName('base')[0].href : '';
	
	var currentTime = new Date();
	
	newPoppedWindow = window.open(url, currentTime.getTime(), args);
	if (window.focus) { newPoppedWindow.focus() }
	
}

function closeDiv(div) {
	
	if (div != null || div != undefined)
		$(div).style.display = 'none';
	else
		return false;
			
	return true;
}

function openDiv(div) {
	
	if (div != null && div != undefined)
		$(div).style.display = 'block';
	else
		return false;
	
	return true;	
}

function goForward(page) {
	document.location.href = document.getElementsByTagName('base')[0].href + page;
}

function goBack() {
	history.go(-1);
	return false;	
}


function doAjax (url, pars, outputdiv, meth) {
			
	pars = pars + '&nocache=' + Math.random();
	
	new Ajax.Updater(outputdiv, url, {
			method: meth,
			parameters: pars, 
			evalScripts: true
	});		
}

function genPassword(trgt, len) {

	var useChars = "0123456789abcdefghijklmABCDEFGHIJKLMnopqrstuvwxyzNOPQRSTUVWYXZ";	
	var password = "";
	
	for (var j = 1; j <= len; j++) {
		password += useChars.charAt(Math.floor(Math.random() * (useChars.length - 0)) + 0);
	}
	
	$(trgt).value = password;	
}


function count_words(field_to_count, display_words)
{
		var hmm;
		hmm = $(field_to_count).value;
		
		hmm = hmm.substr(0, hmm.length - 1);		
		hmm = hmm.replace("  ", " ");	
		no_words = hmm.split(" ");
		
		$(display_words).innerHTML = "&nbsp;&nbsp;" + no_words.length + " / 500 words";
}

function toggleThese(openThese, closeThese) {
	
	if ((openThese == undefined || openThese == "") && (closeThese == undefined || closeThese == ""))
		return false;
	
	if (openThese != undefined && openThese != "") {		
		var split = openThese.split(",");		
		for (var j = 0; j <= split.length - 1; j++) {
			$(split[j]).style.display = 'block';
		}
	}
	
	if (closeThese != undefined && closeThese != "") {		
		var split = closeThese.split(",");		
		for (var j = 0; j <= split.length - 1; j++) {
			$(split[j]).style.display = 'none';
		} 		
	}
	
	return true;
	
}



function getCC( sourceObj ) {
	//credit cards
	var visa = document.getElementById("pm-visa");
	var mastercard = document.getElementById("pm-mastercard");
	var discover = document.getElementById("pm-discover");
	var amex = document.getElementById("pm-amex");
	
	//In this instance the 'sourceObj' represent the input field object from which the function is invoked
	var formName = sourceObj.form.name;
	
//toggling fx
	function amexOff() { amex.style.opacity="0.13"; 	amex.style.filter="alpha(opacity=20)"; }
	function amexOn() {	amex.style.opacity="1";	amex.style.filter="alpha(opacity=100)";	//set amex to checked
		document.forms[formName].amex.checked = true;
	}

	function discoverOff() { discover.style.opacity="0.13";	discover.style.filter="alpha(opacity=20)"; }
	function discoverOn() { discover.style.opacity="1"; discover.style.filter="alpha(opacity=100)"; //set discover to checked
		document.forms[formName].discover.checked = true;
	}

	function mastercardOff() { mastercard.style.opacity="0.13"; mastercard.style.filter="alpha(opacity=20)"; }
	function mastercardOn() {	mastercard.style.opacity="1";	mastercard.style.filter="alpha(opacity=100)";	//set mastercard to checked
		document.forms[formName].mastercard.checked = true;
	}

	function visaOff() { visa.style.opacity="0.13";	visa.style.filter="alpha(opacity=20)"; }
	function visaOn() {	visa.style.opacity="1";	visa.style.filter="alpha(opacity=100)";	//set visa to checked
		document.forms[formName].visa.checked = true;
	}

	//begin parsing logic
	if ( sourceObj.value.length > 1 ) {

	 switch (true) {
	  	case ( sourceObj.value.substring(0,1) == '3'): 
			//51 = 3 = Diners (Mastercard) (36) or Amex (34 or 37)  (7=55)
			if (  sourceObj.value.substring(1,2) == '6') {
				if (visa) {	visaOff(); }
				if (amex) {	amexOff(); }
				if (discover) { discoverOff(); }
				if (mastercard) {	mastercardOn();	}
			} else {
				if (visa) {	visaOff(); }
				if (mastercard) {	mastercardOff(); }
				if (discover) { discoverOff(); }
				if (amex) {
					amexOn();
				}
			}
		break;
		
		case (sourceObj.value.substring(0,1) == '4'): 
			//52 = 4 = visa
			if (mastercard) { mastercardOff();	}
			if (amex) {	amexOff(); }
			if (discover) { discoverOff(); }
			if (visa) {	visaOn();	}
		break;
			
		case (sourceObj.value.substring(0,1) == '5'): 
			//53 = 5 = mastercard
			if (visa) { visaOff(); }
			if (amex) { amexOff(); }
			if (discover) { discoverOff(); }
			if (mastercard) { mastercardOn();	}
		break;
		
		case (sourceObj.value.substring(0,1) == '6'): 
			//54 = 6 = discover
			if (visa) { visaOff(); }
			if (mastercard) { mastercardOff(); }
			if (amex) { amexOff(); }
			if (discover) { discoverOn(); }
		break;
	 }
	 //end switch
	}
//end if
//else reset the images
	else {
		if( visa ){ visa.style.opacity="1"; visa.style.filter="alpha(opacity=100)";	}
		if( mastercard ){	mastercard.style.opacity="1";	mastercard.style.filter="alpha(opacity=100)"; }
		if( amex ){	amex.style.opacity="1";	amex.style.filter="alpha(opacity=100)"; }
		if( discover ){	discover.style.opacity="1";	discover.style.filter="alpha(opacity=100)";	}
	}
  //end else
}
//end fx

// ajax activity - and let the user know about it

Ajax.Responders.register ({

	onCreate: function() {
		if($('showActivity') && Ajax.activeRequestCount> 0) {
			setTimeout("if(Ajax.activeRequestCount> 0) { showActivity() }", 1500);
		}
	},

	onComplete: function() {
		if($('showActivity') && Ajax.activeRequestCount == 0) {
			hideActivity();
		}
	}

});

function showActivity() {

	if($('showActivity')) {
		Effect.Appear('showActivity',{duration: 0.5, queue: {position:'front', scope:'showActivity', limit: 50}});
	}

}

function hideActivity() {

	if($('showActivity')) {
		Effect.Fade('showActivity',{duration: 0.5, queue: {position:'end', scope:'showActivity', limit: 50}});
	}

}



// add all functions to initAdd to have them run once DOM is loaded

var inits = new Array();

function initAdd(func) {
	inits[inits.length] = func;	
}

document.observe("dom:loaded", function() {
	for(var i = 0;i < inits.length;i++) {
		inits[i]();
	}
});






var floatActivityDivTop = 0;

function floatActivityDiv() {
	if(!$('showActivity')) return false;
	setInterval(function() {
		if (document.documentElement && document.documentElement.scrollTop) {
			scrollTop = document.documentElement.scrollTop;
		} else {
			scrollTop = document.body.scrollTop;
		}		

		floatActivityDivTop += (scrollTop + 20 - floatActivityDivTop) / 6;
		$('showActivity').style.top = floatActivityDivTop + 'px';
		$('showActivity').style.right = 20 + 'px';
	}, 30);

}


initAdd(floatActivityDiv);




function equalColumns(div1, div2) {

	if(!$(div1) || !$(div2)) return false;
	
	$(div1).style.height = '';
	$(div2).style.height = '';

	var maxHeightLeft = $(div1).getHeight();
	var maxHeightRight = $(div2).getHeight();

	var maxHeight = (maxHeightLeft > maxHeightRight) ? maxHeightRight : maxHeightLeft;

	$(div1).style.height = maxHeight+'px';
	$(div2).style.height = maxHeight+'px';

	return true;

}

// initAdd(equalColumns);
// Event.observe(window, 'load', equalColumns);

//because anything with target="_blank" does not validate, grr. So just apply class="extLink" and this will do the job.

function external_links_hack() {
	$$('.extLink').each(function(el) {
		el.target = "_blank";
	});
}

initAdd(external_links_hack);












function vote(id) {	
	doAjax('ajax.vote.php', 'f=vote&id=' + id, 'vote_container', 'get');	
}














