// functions for image 'rollovers'

// image 'preloading' is accomplished by forcing the browser to reference all of the image urls at pageload.
function preloadImages() {
	var i, args = preloadImages.arguments;
	for( i = 0; i < args.length; ++i ) {
		dummy = new Image;
		dummy.src = args[i];
	}
}

// recursive search of layers/frames for image object by id
// deobfuscated from a commonly-found template function
function findObj( id, d ) {
	var i, obj;
	var p = id.indexOf("?");
	if ( !d ) d = document;
	if ( p > 0 && parent.frames.length ) {
		d = parent.frames[id.substring(p+1)].document;
		id = id.substring(0,p);
	}
	if ( !( obj = d[id] ) && d.all ) obj = d.all[id];
	for ( i = 0; !obj && i < d.forms.length; i++ ) obj = d.forms[i][id];
	for ( i = 0; !obj && d.layers && i < d.layers.length; i++ ) obj = findObj( id, d.layers[i].document );
	if ( !obj && d.getElementById ) obj = d.getElementById(id);
	return obj;
}

function set_field_value(id,value) {
	obj = findObj(id);
	if ( obj != null ) obj.value = value;
}

function swapImage(id,path) {
	image = findObj(id);
	if ( image != null ) image.src = path;
}

// for enabling a button only when fields are full
function fields_full_button_enable() {
	var args = fields_full_button_enable.arguments;
	var l = args.length;
	if ( l <= 1 ) return;
	var argi = 0;
	button = findObj( args[argi++] );
	if ( button == null ) return;
	var enable = 1;
	while ( argi < l ) {
		fieldval = findObj( args[argi++] ).value;
		if ( fieldval == null || fieldval == '' ) enable = 0;
	}
	if ( enable == 1 ) button.disabled = false;
	else button.disabled = true;
}

function timed_form_submit(id,time) {
	setTimeout( "submit_form('"+id+"')", time*1000 );
}
function submit_form(id) {
	// page refresh is accomplished by submitting back to self, preserving name and comment field values
	formobj = findObj(id);
	formobj.submit();
}

function deny_ip( $ip ) {
	$ipfile = fopen("ipdeny",'r');
	while ( $badip = trim( fgets( $ipfile ) ) ) {
		if ( $ip == $badip ) { return 1; }
	}
	fclose($ipfile);
	return 0;
}

function redirect(url,delay) {
	setTimeout("seturl('"+url+"')",delay*1000);
}

function seturl(url) {
	window.location = url;
}
