///////////////////////////////////
// VALIDATE COMMENT FORM    //
/////////////////////////////////

function checkComments() {
	if (document.myForm.comment_name.value == ''){
	alert("Sorry, but you need to enter a name. Make one up.");
	document.myForm.comment_name.focus();
	return;
	}
	if (document.myForm.comment_body.value == ''){
	alert("Um, the point of posting a comment is to \n ACTUALY POST A COMMENT. \n \n Sorry. It's been a long day.");
	document.myForm.comment_body.focus();
	return;
	}
	if (document.myForm.comment_body.value.length > 3500){
		alert("You have exceeded the character count for a comment. \n Didn't you see the cool little counter? \n Do some self-editing...")
		document.myForm.comment_body.focus();
		return;
	}
	document.myForm.submit();	
}

//////////////////////////////
// VALIDATE EMAIL FORM    //
////////////////////////////

function validateEmailForm(type) {
	if (type == 'friend'){
		 if ( document.emailForm.email_friend.value.indexOf( "@" ) == -1 || document.emailForm.email_friend.value.indexOf( "." ) == -1 || document.emailForm.email_friend.value.indexOf( " " ) != -1 || document.emailForm.email_friend.value == "") {
				alert( "That is not a valid email address. \n Please enter a valid email address for your friend." );
				document.emailForm.email_friend.focus();
				return;				
			}
	if ( document.emailForm.email_you.value.indexOf( "@" ) == -1 || document.emailForm.email_you.value.indexOf( "." ) == -1 || document.emailForm.email_you.value.indexOf( " " ) != -1 || document.emailForm.email_you.value == "") {
				alert( "That is not a valid email address. \n Please enter a valid email address for yourself." );
				document.emailForm.email_you.focus();
				return;				
			}
		document.emailForm.submit();
	}
}

//////////////////////////////
// PRINT THIS ARTICLE       //
////////////////////////////

function printArticle() {
	var x = (screen.width - 700) -15;
   var details = 'height=500,width=700,menubar=yes,status=no,toolbar=no,left='+x+',screenx='+x+',top=0,screeny=0,resizable=yes,scrollbars=yes';
   var printWindow = window.open( "", "printWindow", details );
   printWindow.document.open();
   printWindow.document.writeln( "<title>PRINTABLE PAGE: " );
   printWindow.document.writeln( self.document.printForm.title.value );
   printWindow.document.writeln( " | ");
   printWindow.document.writeln( self.document.printForm.article_title.value );
   printWindow.document.writeln( " | ");
   printWindow.document.writeln( self.document.printForm.cat.value );
   printWindow.document.writeln( " | ");
   printWindow.document.writeln( self.document.printForm.date.value ); 
   printWindow.document.writeln( "</title>" );
	 printWindow.document.writeln( "<style>img { float: right; margin-left: 10px;}</style>" );
   printWindow.document.writeln( "<body bgcolor=#ffffff text=#000000 style='font-family: Arial, Helvetica, sans-serif; font-size: 12px;'>" );
	 printWindow.document.writeln( "<h1 style='background: black; color: white; font-size: 14px; padding: 5px;'>" );
   printWindow.document.writeln( self.document.printForm.title.value );
   printWindow.document.writeln( " - ");
   printWindow.document.writeln( self.document.printForm.article_title.value );
   printWindow.document.writeln( " <span style='font-size: 12px; font-weight: normal;'>[ ");
   printWindow.document.writeln( self.document.printForm.cat.value );
   printWindow.document.writeln( " | ");
   printWindow.document.writeln( self.document.printForm.date.value );
	 printWindow.document.writeln( " ] </span>");
	 printWindow.document.writeln( "</h1>");
   printWindow.document.writeln( self.document.printForm.body.value );
   printWindow.document.writeln( "</body>" );
   printWindow.document.close();
   printWindow.print();

   return;   
}

function sizeImage(){
d=document;
var bodyDiv = d.getElementsByTagName('DIV');
for(i=0;i<bodyDiv.length;i++){ 
if(bodyDiv[i].id=='artimg'){
tempwidth = bodyDiv[i].getElementsByTagName('IMG')[0].width;
bodyDiv[i].style.width = tempwidth + 'px';

}
}
}
window.onload = function(){sizeImage();}
