// ----------------------------
// Bandit Javascript Library.
// Copyright: © morBandit 2005.
// Version: 22.06.05
// URL: www.bandit.co.nz
// ----------------------------

// New Window Picture Viewer
// Note you want to add about 40px to the actual width and height of each image for a snug fit.
function p(l, w, h, c) { // By morbandit.
	if(x) x.close(); // Required for window resize . .
	x = window.open(l, "newWin", "width=" + w + ", height=" + h + ", fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no");
	//x = window.open(l, '_blank', 'dialog, width=' + w + ', height=' + h + '');
	x.focus();
	if(c==true) { // If they want to centre the window on the screen
		var winx = (screen.width/2)-(w/2);
		var winy = (screen.height/2)-(h/2);
		x.moveTo(winx,winy);
	}
}
// Example p('images/myMother.jpg','640','480',true);

// Anti-spam E-mail Linker
function antispamstz(user, domain, func, ext) { // proBandit la~
	url = func+":"+user+"@"+domain+"."+ext;
	document.location=url;
}
// Example: antispamstz('resonance','bandit','mailto','co.nz');

// Image Changer With Caption
// Note that the caption <div> tag must have its id attribute as "caption"
function doChange(cptn, newimge, currentimg, cptnClass) { // By morBandit
	if(document.all) { var it = document.all("caption"); }
	else { var it = document.getElementById("caption"); }
	currentimg.src=newimge;
	it.innerHTML=cptn;
	if(doChange.arguments.length>3) it.className=cptnClass; // :D
}
// Example: doChange('This is my mother','images/myMother.jpg',this,'green');

// Changes page title to the selected option of a dropdown menu
function changeTitle(selObj) { // By morBandit ~
	if(selObj == "contact.php" || selObj == "affiliates.php") {
		eval("document.title='. . / . . / r e s o n a n c e / "+selObj+"'");
		if(document.all) eval("document.all.selectstz.value='"+selObj+"'");
		else eval("document.getElementById('selectstz').value='"+selObj+"'");
	}
	else if (selObj.options[selObj.selectedIndex].value == "select.php") {
		eval("document.title='. . / . . / r e s o n a n c e /'");
	}
	else {
		eval("document.title='. . / . . / r e s o n a n c e / "+selObj.options[selObj.selectedIndex].value+"'");
	}
}
// Example: <select onChange="changeTitle(this)">

// Expand or collapse text
function bandixPand(x,y,msgex,msgcl) { // by morBandit
	if(document.all) {
		var divvy = document.all(x);
		var xpand = document.all(y);
	}
	else {
		var divvy = document.getElementById(x);
		var xpand = document.getElementById(y);		
	}
	if(divvy.style.display=="none") { 
		divvy.style.display="block";
		xpand.innerHTML=msgcl;
	}
	else {
		divvy.style.display="none";
		xpand.innerHTML=msgex;
	}
}
// Example: bandixPand('expandme', 'clickmetoexpand', 'Expand', 'Collapse');

// Popup javascript errors
function ShowError (msg,url,linenumber)	{
	alert(msg + " at line " + linenumber);
}
// Example: onerror = ShowError;

// Checks if a page is inside a frame, if it's not, it forwards to the designated page
function frameCheck(fwpage) { // by morBandit
	if (top.frames.length==0) eval("document.location='" + fwpage + "'");
}
// Example: frameCheck('index.php');

// Displays a layer saying "loading"
function isLoading(bool,layer) { // by morbandit
	if(document.all) var lay = document.all(layer);
	else var lay = document.getElementById(layer);
	if(bool=='yes') lay.style.visibility='visible';
	else lay.style.visibility='hidden';
}
// Example: isLoading('yes','loadingLayer');
// And isLoading('no','loadingLayer'); at bottom

// Displays a message if the client is using IE
function ieMessage(msg) { // by morbandit, the hater of IE
	if(document.all) { 
		if(ieMessage.arguments.length==0) document.write("Internet Explorer sucks. <a href='http://www.getfirefox.com' target='_blank'>Get Firefox</a>");
		else document.write(msg);
		return true;
	}
	else return false;
}
// Example: ieMessage('this is my custom ie user message');

// Swaps an image on mouseover
function imgSwap(from,to) { // morb05
	from.src=to;
}
// Example: imgSwap(this,'yourMother.jpg');

// Revamp by morBandit so it works properly with set-width rows and columns
// Originally by GwynforWeb @ www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21232651.html
// Thanks a bundle, this is a very difficult project
function toggle(obj,tgl) {
	if(tgl!="") tab=document.getElementById(tgl);
	Id=obj.id;
	objLink = document.getElementById('a' + Id);
	if (obj.className=='closed') {
		obj.className='open';
		objLink.innerHTML="~";
		reg=new RegExp('^'+Id+'\\.\\d+$');
		for (i=1;i<tab.rows.length;i++) {
			if (reg.test(tab.rows[i].id)) {
				//tab.rows[i].style.display=(tab.rows[i].style.display=='block')?'none':'block'; // This was messy, didn't understand it, so I removed it . . 
				if(document.all) tab.rows[i].style.display='block'; // Okay so like, IE works good with block
				else tab.rows[i].style.display='table-row'; // But Firefox hates it, so we use table-row, which doesn't appear to be supported by IE
				// As for the other browsers, meh, who cares . .
			}
		}
	}
	else {
		reg=new RegExp('^'+Id+'\\.\\d+');
		obj.className='closed';
		objLink.innerHTML="+";
		for (i=1;i<tab.rows.length;i++) {
			if (reg.test(tab.rows[i].id)) {
				tab.rows[i].style.display='none'; // 'none' works fine for both browsers
				//tab.rows[i].className='closed'; // No need to be changing the classname . . right ?
			}
		}
	}
}

// Check if all elements in a form have been completed
function doValidate() { // bandit.co.nz
	var df,dfe,i,j,x,y;
	df=document.forms;
	//for(i=0;i<df.length;i++) {
	x=df[0];
	dfe=x.elements;
	for(j=0;j<dfe.length;j++){
		y=dfe[j];
		if(y.value==""){
			alert("Please Complete All Required Fields");
			y.focus();
			return false;
		}
	}
	//}
	//df[0].submit(); // the submit is all f**ked up
	return true;
}
// Example: <input type="submit" name="Submit" value="Submit" onClick="return doValidate();">

// Better anti-spam e-mail script
/////////////////////////////////
// This script is (c) copyright 2006 Jim Tucek under the
// GNU General Public License (http://www.gnu.org/licenses/gpl.html)
// For more information, visit http://www.jracademy.com/~jtucek/email/ 
// Leave the above comments alone!

var decryption_cache = new Array();

function decrypt_string(crypted_string,n,decryption_key,just_email_address) {
	var cache_index = "'"+crypted_string+","+just_email_address+"'";

	if(decryption_cache[cache_index])					// If this string has already been decrypted, just
		return decryption_cache[cache_index];				// return the cached version.

	if(addresses[crypted_string])						// Is crypted_string an index into the addresses array
		var crypted_string = addresses[crypted_string];			// or an actual string of numbers?

	if(!crypted_string.length)						// Make sure the string is actually a string
		return "Error, not a valid index.";

	if(n == 0 || decryption_key == 0) {					// If the decryption key and n are not passed to the
		var numbers = crypted_string.split(' ');			// function, assume they are stored as the first two
		n = numbers[0];	decryption_key = numbers[1];			// numbers in crypted string.
		numbers[0] = ""; numbers[1] = "";				// Remove them from the crypted string and continue
		crypted_string = numbers.join(" ").substr(2);
	}

	var decrypted_string = '';
	var crypted_characters = crypted_string.split(' ');

	for(var i in crypted_characters) {
		var current_character = crypted_characters[i];
		var decrypted_character = exponentialModulo(current_character,n,decryption_key);
		if(just_email_address && i < 7)				// Skip 'mailto:' part
			continue;
		if(just_email_address && decrypted_character == 63)	// Stop at '?subject=....'
			break;
		decrypted_string += String.fromCharCode(decrypted_character);
	}
	
	decryption_cache[cache_index] = decrypted_string;			// Cache this string for any future calls

	return decrypted_string;
}

function decrypt_and_email(crypted_string,n,decryption_key) {
	if(!n || !decryption_key) { n = 0; decryption_key = 0; }
	if(!crypted_string) crypted_string = 0;

	var decrypted_string = decrypt_string(crypted_string,n,decryption_key,false);
	parent.location = decrypted_string;
}

function decrypt_and_echo(crypted_string,n,decryption_key) {
	if(!n || !decryption_key) { n = 0; decryption_key = 0; }
	if(!crypted_string) crypted_string = 0;

	var decrypted_string = decrypt_string(crypted_string,n,decryption_key,true);
	document.write(decrypted_string);
	return true;
}

// Finds base^exponent % y for large values of (base^exponent)
function exponentialModulo(base,exponent,y) {
	if (y % 2 == 0) {
		answer = 1;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	} else {
		answer = base;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	}
	return answer;
}
// -->

if(!addresses) var addresses = new Array();
addresses.push("3841 2435 612 2356 1484 3705 1450 235 3062 306 2356 612 913 3680 956 147 2356 2014 1340 1484 1450 1311 2367 235 1311 2014 2896");
addresses.push("3841 2435 612 2356 1484 3705 1450 235 3062 3292 913 3705 3705 235 956 147 2356 2014 1340 1484 1450 1311 2367 235 1311 2014 2896");

// Example: <a href="javascript:decrypt_and_email(1)">hello@bandit</a>