/*
	display.js
	
	Javascripts for ~~ website
*/
// Only activates the 'Submit' button if the required fields are completed. Requires jQuery
function jQforceSubmit() {
//	jQuery('#text').prepend(jQuery('.mailnotice'));
	jQuery('.mailnotice').prependTo('.post');
	document.getElementById('submit').disabled = true;
	jQuery('#submit').addClass('nonactive');
	inputset = jQuery('#webmail .req input,#webmail .req textarea').get();
	for (var a=0;a<inputset.length;a++) { // for some reason the usual process ain't hackin it, no more time to debug
		inputset[a].onkeyup = function() {
//			alert(jQuery('#webmail .req select[value=""],#webmail .req input[value=""],#webmail .req textarea[value=""]').length);
			if (jQuery('#webmail .req select[value=""],#webmail .req input[value=""],#webmail .req textarea[value=""]').length==0) {
				document.getElementById('submit').disabled = false;
				jQuery('#submit').removeClass('nonactive');
			} else {
				document.getElementById('submit').disabled = true;
				jQuery('#submit').addClass('nonactive');
			}
		}
	}
}
// jiggery-pokery to position the webmail form near the appropriate mail recipient.
// Requires jQuery.
function ccfpMailPos() {
	jQuery('.formcont').css('display','none');
	jQuery('#text p').css('position','relative');
	jQuery('.cf').mouseup(function() {
		thisparent = jQuery(this).parent().get(0); // the actual parent object
		contactee = jQuery(this).attr('title');
		cfp = "contact ";
		contactee = contactee.substr(cfp.length);
		jQuery('#recipient_name').val(contactee); // The title of the 'Contact...' pseudolink must exactly match the SELECT option!
		jQuery('.formcont').css({
			background:'#DFE5D4',
			border:'solid #fff 3px',
			padding:'1em',
			width:'400px',
			position:'absolute',
			top:'3em',
			left:'3em',
			zIndex:'2'
		}).remove().appendTo(jQuery(thisparent)).fadeIn(500);
	});
	document.getElementById('cancel').onclick = function() {
		jQuery('.formcont').fadeOut(500);
	}
	return;
}

// Tests for MSIE version. Returns version whole number
function isIE() {/*@cc_on
if(@_jscript_version < 5.6){return 5;}if(@_jscript_version < 5.7){return 6;}if(@_jscript_version < 5.8){return 7;}if(@_jscript_version < 5.9){return 8;}
@*/ return 0;}

jQuery(document).ready(launchAll);

function launchAll() {
	if (document.getElementById('webmail')) {
		jQforceSubmit();
		ccfpMailPos();
//		forceSubmit();
	}
}
//window.onload = launchAll;

/* EOF */
