function toggleLayer (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];
	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 echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("You must enter a valid email address")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("You must enter a valid email address")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	   alert("You must enter a valid email address")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	   alert("You must enter a valid email address")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	   alert("You must enter a valid email address")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	   alert("You must enter a valid email address")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	   alert("You must enter a valid email address")
	    return false
	 }

	 return true					
}

function validate() {
	var name = document.getElementById('cName');
	var name_lbl = document.getElementById('cNameLabel');
	var email = document.getElementById('cEmail');
	var email_lbl = document.getElementById('cEmailLabel');
	var comment = document.getElementById('cComment');
	var comment_lbl = document.getElementById('cCommentLabel');
	var error = 0;

	if (name.value == null || name.value == "") {
		var answer = confirm('Are you sure you don\'t want to enter your name?');
		
		if (answer) {
			name.value = "Anonymous";
			name_lbl.className = "normal";
		} else {
			alert('Please enter your name');
			name_lbl.className = "error";
			name.focus();
			error++;
		}
	} else {
		name_lbl.className = "normal";
	}
	
	if (email.value != null && email.value != "") {
		if (echeck(email.value)==false) {
			email_lbl.className = "error";
			email.focus();
			error++;
		} else {
			email_lbl.className = "normal";
		}
	}

	if (comment.value == null || comment.value == "") {
		alert('You must enter feedback');
		comment_lbl.className = "error";
		comment.focus();
		error++;
	} else {
		comment_lbl.className = "normal";
	}
	
	if (error > 0) {
		return false;
	} else {
		return true;
	}
	
}

function submitComment() {
	if (validate()) {
		document.addCommentForm.submit();
	}
}
