/* show hide functions */

function showHide(entryID, entryLink, htmlObj, type) {
	if (type == "comments") {
		extTextDivID = ('comText' + (entryID));
		extLinkDivID = ('comLink' + (entryID));
	}
	else {
		extTextDivID = ('extText' + (entryID));
		extLinkDivID = ('extLink' + (entryID));
	}
	if( document.getElementById ) {
		if( document.getElementById(extTextDivID).style.display ) {
			if( entryLink != 0 ) {
				document.getElementById(extTextDivID).style.display = "block";
				document.getElementById(extLinkDivID).style.display = "none";
				htmlObj.blur();
			}
			else {
				document.getElementById(extTextDivID).style.display = "none";
				document.getElementById(extLinkDivID).style.display = "block";
			}
		}
		else {
			location.href = entryLink;
			return true;
		}
	}
	else {
		location.href = entryLink;
		return true;
	}
}





/* COMMENT PREVIEW FUNCTION */
function commentpreview()
{
	var NewText = document.getElementById("textinput").value;
	NewText = NewText.replace(/\n/g, '<br />');
	var DivElement = document.getElementById("textpreview");
	DivElement.innerHTML = NewText;
}





/* contact form functions */

function getLabelForId(id) {
	var label, labels = document.getElementsByTagName('label');
	for (var i = 0; (label = labels[i]); i++) {
		if (label.htmlFor == id) {
			return label;
		}
	}
	return false;
}

function checkRequired(id) {
	var formfield = document.getElementById(id);
	var label = getLabelForId(id);
	if (formfield.value.length == 0) {
		label.className = 'problem';
		formfield.className = 'problem';
	}
	else {
		label.className = 'completed';
		formfield.className = 'completed';
	}
}


/* CONTACT FORM FUNCTIONS */
function checkform() {
	var pkg = document.getElementById('package').selectedIndex;
	var designer = document.getElementById('designer').selectedIndex;
	var yourname = document.getElementById('name').value;
	var address1 = document.getElementById('address1').value;
	var address2 = document.getElementById('address2').value;
	var phone = document.getElementById('phone').value;
	var from = document.getElementById('from').value;
	var title = document.getElementById('site_title').value;
	var tagline = document.getElementById('site_tagline').value;
	var platform = document.getElementById('site_platform').selectedIndex;
	var about_site = document.getElementById('about_site').value;
	var site_expect = document.getElementById('site_expect').value;
	var sample_links = document.getElementById('sample_links').value;
	var agree = document.getElementById('agree_to_terms').checked;

	if (pkg == 0 || pkg == 1) {
		// something is wrong
		alert('Please select a package.');
		getLabelForId('package').className = 'problem';
		document.getElementById('package').className = 'problem';
		document.getElementById('package').focus;
		document.location = '#package';
		return false;
	}

	else if (designer == 0 || designer == 1) {
		// something else is wrong
		alert('Please select a designer.');
		getLabelForId('designer').className = 'problem';
		document.getElementById('designer').className = 'problem';
		document.getElementById('designer').focus;
		document.location = '#designer';
		return false;
	}

	else if (yourname == "") {
		// something else is wrong
		alert('Please enter your full name');
		getLabelForId('name').className = 'problem';
		document.getElementById('name').className = 'problem';
		document.getElementById('name').focus;
		document.location = '#name';
		return false;
	}

	else if (address1 == "") {
		// something else is wrong
		alert('Please enter your billing address');
		getLabelForId('address1').className = 'problem';
		document.getElementById('address1').className = 'problem';
		document.getElementById('address1').focus;
		document.location = '#address1';
		return false;
	}

	else if (address2 == "") {
		// something else is wrong
		alert('Please complete your billing address');
		getLabelForId('address2').className = 'problem';
		document.getElementById('address2').className = 'problem';
		document.getElementById('address2').focus;
		document.location = '#address2';
		return false;
	}

	else if (phone == "") {
		// something else is wrong
		alert('Please enter your phone number');
		getLabelForId('phone').className = 'problem';
		document.getElementById('phone').className = 'problem';
		document.getElementById('phone').focus;
		document.location = '#phone';
		return false;
	}

	else if (from == "") {
		// something else is wrong
		alert('Please enter your email address');
		getLabelForId('from').className = 'problem';
		document.getElementById('from').className = 'problem';
		document.getElementById('from').focus;
		document.location = '#from';
		return false;
	}

	else if (title == "") {
		// something else is wrong
		alert('Please enter your website title');
		getLabelForId('site_title').className = 'problem';
		document.getElementById('site_title').className = 'problem';
		document.getElementById('site_title').focus;
		document.location = '#site_title';
		return false;
	}

	else if (tagline == "") {
		// something else is wrong
		alert('Please enter your website tagline');
		getLabelForId('site_tagline').className = 'problem';
		document.getElementById('site_tagline').className = 'problem';
		document.getElementById('site_tagline').focus;
		document.location = '#site_tagline';
		return false;
	}

	else if (platform == 0 || platform == 1) {
		// something else is wrong
		alert('Please select your website platform');
		getLabelForId('site_platform').className = 'problem';
		document.getElementById('site_platform').className = 'problem';
		document.getElementById('site_platform').focus;
		document.location = '#site_platform';
		return false;
	}

	else if (about_site == "") {
		// something else is wrong
		alert('Please give us a description of your site');
		getLabelForId('about_site').className = 'problem';
		document.getElementById('about_site').className = 'problem';
		document.getElementById('about_site').focus;
		document.location = '#about_site';
		return false;
	}

	else if (site_expect == "") {
		// something else is wrong
		alert('Please explain your expectations for your site design');
		getLabelForId('site_expect').className = 'problem';
		document.getElementById('site_expect').className = 'problem';
		document.getElementById('site_expect').focus;
		document.location = '#site_expect';
		return false;
	}

	else if (sample_links == "") {
		// something else is wrong
		alert('Please enter at least 3 sample links');
		getLabelForId('sample_links').className = 'problem';
		document.getElementById('sample_links').className = 'problem';
		document.getElementById('sample_links').focus;
		document.location = '#sample_links';
		return false;
	}

	else if (!agree) {
		// something else is wrong
		alert('You must agree to our Terms and Conditions');
		getLabelForId('agree_to_terms').className = 'problem';
		document.getElementById('agree_to_terms').className = 'problem';
		document.getElementById('agree_to_terms').focus;
		document.location = '#agree_to_terms';
		return false;
	}

	// If the script gets this far through all of your fields
	// without problems, it's ok and you can submit the form

	else {
		return true;
	}
}