function validate_form()
{
    var valid = true;
    var message = 'Please correct the following:\n\n';
    document.getElementById('errorFrom').className = "mailHeading" ;
    document.getElementById('errorReply').className = "mailHeading" ;
    document.getElementById('errorSub').className = "mailHeading" ;
    document.getElementById('errorMsg').className = "mailHeading" ;
    var replyto = document.email.replyto.value;
    var emailRegex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    
	if ( document.email.from.value == "" )
    {
        valid = false;
    	document.getElementById('errorFrom').className += " error" ;
    	message += '-Your name cannot be blank.\n';
    }
    
    if (replyto == "" )
    {
        valid = false;
        document.getElementById('errorReply').className += " error" ;
        message += '-You must provide a valid email address for Twiz to reach you.\n';
    }
    if (replyto != "" )
    {
    
    	if (!replyto.match(emailRegex)) //email present but not valid address)
    	{
   		document.getElementById('errorReply').className += " error" ;
        message += '-You must provide a valid email address for Twiz to reach you.\n';
        valid = false;
    	}

    }
    
    if ( document.email.subject.value == "" )
    {
        valid = false;
        document.getElementById('errorSub').className += " error" ;
        message += '-Provide a subject for your message.\n';
    }
    
    if ( document.email.message.value == "" )
    {
        valid = false;
        document.getElementById('errorMsg').className += " error" ;
        message += '-You cannot send a blank message.\n';
    }
    
    if (valid == false) 
    {
    	
    	
    	alert(message);
    }
    
    
    
    return valid;
}

function validate_addgb_form()
{
    var valid = true;
    var message = 'Please correct the following:\n\n';
    document.getElementById('From').className = "mailHeading" ;
    document.getElementById('Sub').className = "mailHeading" ;
    document.getElementById('Msg').className = "mailHeading" ;
    
	if ( document.GuestbookAdd.from.value == "" )
    {
        valid = false;
    	document.getElementById('From').className += " error" ;
    	message += '-Your name cannot be blank.\n';
    }
    
    if ( document.GuestbookAdd.subject.value == "" )
    {
        valid = false;
        document.getElementById('Sub').className += " error" ;
        message += '-Provide a subject for your message.\n';
    }
    
    if ( document.GuestbookAdd.message.value == "" )
    {
        valid = false;
        document.getElementById('Msg').className += " error" ;
        message += '-You cannot leave a blank guestbook entry.\n';
    }
    
    if (valid == false) 
    {
    	alert(message);
    }
    
    
    
    return valid;
}

function validate_seriesadd_form()
{
    var valid = true;
    var message = 'You cannot enter blanks into series data! Provide a name and a description for the series.';
    document.getElementById('seriesName').className = "add" ;
    document.getElementById('description').className = "add2" ;
    
	if ( document.add.seriesName.value == "" )
    {
        valid = false;
    	document.getElementById('seriesName').className += " error" ;
    }
    
    if ( document.add.description.value == "" )
    {
        valid = false;
        document.getElementById('description').className += " error" ;
    }
    
    if (valid == false) 
    {
    	alert(message);
    }
    
    if (valid) {document.add.submit();} else {return valid;}
}

function showImage( tableCell,thumbnail )
{
	var imageString = '<img src="' + thumbnail + '" onclick="javascript:hideImage(this.parentNode,\'' + thumbnail + '\');"/>';
	tableCell.innerHTML = imageString;	
}

function hideImage( tableCell,thumbnail ) 
{
	var cellString = '<a href="#" onclick="javascript:showImage(this.parentNode,\'' + thumbnail + '\');">CLICK TO SHOW</a>';
	tableCell.innerHTML = cellString;
}

function validate_addartwork_form()
{
    var valid = true;
    var message = 'Title must not be blank!';
    document.getElementById('title').className = "" ;
    
	if ( document.add.title.value == "" )
    {
        valid = false;
    	document.getElementById('title').className += " error" ;
    }
    
    if (valid == false) 
    {
    	alert(message);
    }
    
    if (valid) {document.add.submit();} else {return valid;}
}

function validate_addartworkform_form()
{
    var valid = true;
    var message = 'Required fields must be filled in!\n\n';
    document.getElementById('title').className = "" ;
    document.getElementById('file').className = "" ;
    
	if ( document.add.title.value == "" )
    {
        valid = false;
    	document.getElementById('title').className += " error" ;
    	message += '-Title Required\n';
    }
    
    if ( document.add.file.value == "" )
    {
        valid = false;
    	document.getElementById('file').className += " error" ;
    	message += '-Image File required\n';
    }
    
    if (valid == false) 
    {
    	alert(message);
    }
    
    if (valid) {document.add.submit();} else {return valid;}
}

function validate_changeimage_form()
{
    var valid = true;
    var message = 'Please provide an alternate image!\n\n';
    document.getElementById('file').className = "" ;
    
	if ( document.add.file.value == "" )
    {
        valid = false;
    	document.getElementById('file').className += " error" ;
    }
    
    if (valid == false) 
    {
    	alert(message);
    }
    
    if (valid) {document.add.submit();} else {return valid;}
}

function showImage( tableCell,thumbnail )
{
	var imageString = '<img src="' + thumbnail + '" onclick="javascript:hideImage(this.parentNode,\'' + thumbnail + '\');"/>';
	tableCell.innerHTML = imageString;	
}

function hideImage( tableCell,thumbnail ) 
{
	var cellString = '<a href="#" onclick="javascript:showImage(this.parentNode,\'' + thumbnail + '\');">CLICK TO SHOW</a>';
	tableCell.innerHTML = cellString;
}

function confirmDelete() 
{
	if (confirm('Are you sure you wish to delete this artwork?\nThis move is permanent, unrecoverable, and the image file associated with the art will be removed from the webserver to conserve space for future work.\n\nEnsure you have backed up the file if you still need it before deleting by visiting the artwork and saving the thumbnail and the fullsize image!!'))
	{
		return true;	
	}
	else
	{
		return false;
	}
}
