// ----------------------------
// 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~
	eval("document.location='"+func+":"+user+"@"+domain+"."+ext+"'");
}
// 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();">