// JavaScript Document
function getMore()
{
	if(!validateForm())
		return;
		
	var id = new Array();
	var caption = new Array();
	var description = new Array();
	id[0] = "cds";
	caption[0] = "Content Deployment System (CDS)<br />";
	description[0] = caption[0] + "This feature allows you to easily add, or deploy, text and photos to the your site via ";
	description[0] += "an online web interface.";
	
	id[1] = "photo";
	caption[1] = "Photo Gallery<br />";
	description[1] = caption[1] + "Allows you to upload photos and display in albums/categories that you specify.  It can be ";
	description[1] += "designed so as to use clickable thumbnails or the original pictures.";
	
	id[2] ="blog";
	caption[2] = "Blog<br />";
	description[2] = caption[2] + "A quick and easy way to post articles, chronicle progress, or keep an onine diary. ";
	description[2] += "The feature provides you with a interface for easy and frequent updating.";
	
	id[3] = "specialforms";
	caption[3] = "Specialized Forms<br />";
	description[3] = caption[3] + "Custom coded forms that allow for backend processing. Potential Uses include secure ";
	description[3] += "applications, anything that requires complex or conditinal processing, and data submission that requires ";
	description[3] += "error checking and/or data validation.";
	
	id[4] = "fup";
	caption[4] = "File Uploading<br />";
	description[4] = caption[4] + "This feature provides an area for visitors and/or clients to upload files to a secure directory ";
	description[4] += "on your server, or optionally send them as a file attachment to your email address.";
	
	id[5] = "guestbook";
	caption[5] = "Guest Book<br />";
	description[5] = caption[5] + "This feature will allow visitors to your website to leave a &quot;message&quot; which can be ";
	description[5] += "instantly displayed within your Guestbook or displayed only after the &quot;message&quot; is given your approval.";
	
	id[6] = "news";
	caption[6] = "News/Article Posting<br />";
	description[6] = caption[6] + "Allows you to easily add, edit and delete news articles and &quot;teaser text&quot; that is ";
	description[6] += "clickable to a page containing the full story.";
	
	id[7] = "feedback";
	caption[7] = "Feedback Forms<br />";
	description[7] = caption[7] + "Allows for your visitor to send you an email directly from your website by filling out a form. ";
	description[7] += "Feedback forms are custom coded for your website to include the input fields that you need.";
	
	id[8] = "letter";
	caption[8]="Newsletter Signup/Dispersal<br />";
	description[8]= caption[8] + "Allows for your website visitors to sign up for email newsletters from your website. Included will be the ";
	description[8] += "ability to create and send email newsletters to subscribers from the Newsletter Admin page of your website.";
	
	id[9] = "unlisted";
	caption[9] = "Unlisted Feature<br />";
	description[9] = caption[9] + "Not seeing what you are looking for?  Describe your need in the concept description and ";
	description[9] += "we will endeavor to accomodate.";
	

	output = "<center><br /><h2> Additional Information </h2>";
	output +="<table>\n";
	output += "<tr><td align='right'>Do you need a domain registered?</td>\n";
    output += "<td align='left'>\n";
    output += "<select name='domain' onFocus='this.style.background=\"#ECEDF2\";' ";
	output += "onBlur='this.style.background=\"#FFFFFF\"' />\n";
    output += "<option value=''>Please Select</option>\n";
    output += "<option value='yes'>Yes, I do</option>\n";
    output += "<option value='no'>No, I do not</option>\n";
    output += "<option value='huh'>What is a domain?</option>\n";
    output += "</select>\n";
    output += "</td></tr><tr><td align='right'>\n";
    output += "Do you need hosting?</td>\n";
    output += "<td align='left'>\n";
    output += "<select name='hosting' onFocus='this.style.background=\"#ECEDF2\";' ";
	output += "onBlur='this.style.background=\"#FFFFFF\"' />\n";
    output += "<option value=''>Please Select</option>\n";
    output += "<option value='yes'>Yes, I do</option>\n";
    output += "<option value='no'>No, I do not</option>\n";
    output += "<option value='huh'>What is this 'hosting'?</option>\n";
    output += "</select> ";
    output += "</td></tr><tr><td align='left'>\n";
    output += "Are there any websites you would <br />like us to use to guide the design?\n";
    output += "</td><td align='left'>\n";
    output += "<input name='site1' type='text' value='http://' onFocus='this.style.background=\"#ECEDF2\";' ";
	output += "onBlur='this.style.background=\"#FFFFFF\"' /><br />\n";
    output += "<input name='site2' type='text' value='http://' onFocus='this.style.background=\"#ECEDF2\";' ";
	output += "onBlur='this.style.background=\"#FFFFFF\"' /><br />\n";
    output += "<input name='site3' type='text' value='http://' onFocus='this.style.background=\"#ECEDF2\";' ";
	output += "onBlur='this.style.background=\"#FFFFFF\"' />\n";
	output += "</td></tr></table>\n";
	
	//add-on features
	output += "<br /><h2>Desired Add-ons &amp; Features</h2>\n";
	output += "<div class='notes'>Note: add-ons and extra features will increase the quote.</div><br />\n";
	
	output += "<table cellpadding='10'>\n";

	output += extraOptions(id, description, caption);
	output += "</table></center>\n";
	node = document.getElementById('temp');
	while(node.hasChildNodes())
	{
		node.removeChild(node.firstChild);
	}
	//node.removeChild(node.childNodes[1]);
	document.getElementById('moreoptions').innerHTML = output;
	document.getElementById('moreoptions').style.visibility='visible';
	//document.getElementById('extra').style.visibility='hidden';
}

function extraOptions(optionid, description, caption)
{
	var returnValue = "<tr>";
	
	for(i=0;i<optionid.length; i++)
	{
		if(i!=0 && i%3==0)
			returnValue += "</tr><tr>";

		returnValue += "<td width='20'><input name='features[]' id='"+optionid[i]+"' type='checkbox' value='"+optionid[i]+"' /></td>";
		returnValue += "<td style='text-align:left' onMouseover=\"ddrivetip(\'" + description[i] + "','#506473', 300)\" \n";
		returnValue += "onMouseout=\"hideddrivetip()\"><label for='"+optionid[i] +"'>"+caption[i]+"</label></td>\n";
	}
	
	returnValue += "</tr>";
	
	return returnValue;
}

function validateForm()
{
	//variable the keep track of error instances
    var errorCount = 0;
	var error = "";

    //if statements are self-explanatory
    if(!checkEmail()) 
	{
		errorCount++;
		error += "Email Error: Email Address is missing or invalid\n";
	}
	
	if(!checkName())
	{
		errorCount++;
		error += "Name Error: A contact name (first, last, or both) is required so that we can have a person ";
		error += "to reference when offering the quote or contacting for more information\n";
	}
	
	if(!checkPackage()) 
	{
		errorCount++;
		error += "Package Error: You must select some package option (selection is not binding ";
		error += "but will provide a rough idea to guide the quote)\n";
	}
	
	if(!checkPages())
	{
		errorCount++;
		error += "Page Count Error: You must select the approximate number of pages your site will require ";
		error += "(selection is not binding but will provide a rough idea to guide the quote)\n";
	}
	
	if(!checkDescription()) 
	{
		errorCount++;
		error += "Description Error: A reasonably detailed description of what you want/expect is needed to formulate the quote\n";
	}
	
	//error results acted upon
	if (errorCount > 0)
	{
		alert("The following errors were noted and must be addressed before continuing: \n" + error);
		return false;
	}
	else return true;
		
}
	
function checkEmail()
{
 //clearing bookend spacing but not spaces from the middle
    var email = document.getElementById("email").value;//
	email = email.replace(/(^\s+|\s+$)/g,"");
    
    //regular expression to do most of the testing
    //allows for alpha-numeric charters and a period on the left of the @ symbol
    //and the same for the other.  verifies that there are at least 2 trailing
    //characters after the . (also verifies there is a .
    var expr = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-z]{2,7}$/;
    
    //regular expression that tests for invalid bookend dashes and underscores
    var bookEnd = /[_\-]/gi;
   

    //format test
    if (!expr.test(email))
    {
        return false;
    }
    
    //breaking up the email addy into left and right halves for testing
    email = email.split("@");
    
    //meaningful names
    leftSide = email[0];
    rightSide = email[1];
    
    //testing for invalid leading dash or underscore
    if (bookEnd.test(leftSide.substring(0,1)) || 
        bookEnd.test(leftSide.substring(leftSide.length - 1,leftSide.length)))
        return false;
        
    //splitting on periods
    leftSide = leftSide.split(".");
    rightSide = rightSide.split(".");
    
    //guaranteeing left and right side are not too long and in the case of the 
    //right side, not too short
    if(leftSide.length > 3 || rightSide.length > 3 || rightSide < 2)
       return false;
       
    
    return true;
}

function checkName()
{
	var name = document.getElementById('name').value;
	name = name.replace(/(^\s+|\s+$)/g,"");
	
	if( name.length > 1 )
		return true;
		
	return false;
}

function checkPackage()
{
	if (document.getElementById('package').value != "") return true;
	return false;
}

function checkPages()
{
	if(document.getElementById('pages').value != "") return true;
	return false;
}

function checkDescription()
{
	var description = document.getElementById("message").value;
	description = description.replace(/(^\s+|\s+$)/g,"");
	
	if(description.length != "")
		return true;
	
	return false;
}
