function toggle_Layer( whichLayer ){
	var elem, vis; 
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );  
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];  
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];  
	if( vis = elem.style ) {
		// if the style.display value is blank we try to figure it out here
		if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
			vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
		vis.display = (vis.display==''||vis.display=='block')?'none':'block';
	}
}

function show_Layer( whichLayer ){
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );  
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];  
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];  
	if( vis = elem.style ) {
		vis.display = 'block';
	}
}

function hide_Layer( whichLayer ){
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );  
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];  
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];  
	if( vis = elem.style ) {
		vis.display = 'none';
	}
}

function update_content( whichLayer, newHTML ){
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );  
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];  
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];  

	elem.innerHTML = newHTML;
}

function urlencode (str) {
	str = (str+'').toString();
	return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
} 

function check_email_form( form ) {
	var error_string = '', pattern = '';
	if( form['name'].value == null || form['name'].value == '' )
		error_string = error_string + "<br />Name cannot be blank.";

	pattern = /(^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$)|(^$)/;
	if( !pattern.test( form['from'].value ) || form['from'].value == null || form['from'].value == '' )
		error_string = error_string + "<br />Not a valid email.";

	if( form['subject'].value == null || form['subject'].value == '' )
		error_string = error_string + "<br />Subject cannot be blank.";

	if( form['body'].value == null || form['body'].value == '' )
		error_string = error_string + "<br />Please type a message to send.<br />";

	if( error_string != '' ) {
		show_Layer( 'email_errors' );
		update_content( 'email_errors', error_string );
		return false;
	} else {
		hide_Layer( 'email_errors' );
		hide_Layer( 'email_send' );
		show_Layer( 'email_sending' );
		return true;
	}
}
