// JavaScript Document
function showdetails(element)
	{
		var element1=(element);
		element1 = element.id+"x";
		//alert(element1);
		if (document.getElementById(element1).style.display=="none") {
			document.getElementById(element1).style.display="block";
		}
		else
		{
			document.getElementById(element1).style.display="none";
		}
	}
// check that radio button is checked
function checkRadio(theForm) {
var error = "";
var myOption = "deletefile";
var answer = "";
	for (i=theForm.radiobutton.length-1; i > -1; ) {
		if (theForm.radiobutton[i].checked) {
		//alert (theForm.radiobutton[i].value);
		myOption = (theForm.radiobutton[i].value);
		//alert (theForm.radiobutton[i].value);
		//alert (myOption);
			if (myOption =="deletefile"){
			answer=confirm ("Are you sure you want to delete this file");
				if (answer !=0){
				theForm.mode.value = (theForm.radiobutton[i].value); //theForm.radiobutton[i].value; 
				return error;
				}
				else {
				theForm.mode.value = "cancel"; //theForm.radiobutton[i].value;
				return error;
				}
			}
		theForm.mode.value = (theForm.radiobutton[i].value);
		//i = -1;
		return error;
		}
	i--;
	}
	error = "Please select a radio button either, create or delete a page. \n";
	return error;
}

// username - 4-20 chars, uc, lc, and underscore only.
function checkFilename (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a valid filename. \n";
}
    //var illegalChars = /\W/; // allow letters, numbers, and underscores
	var illegalChars = /\W[-]/; 
	//var illegalChars =  /^[^\\\/\:\*\?\"\<\>\|\.]+(\.[^\\\/\:\*\?\"\<\>\|\.]+)+$/;
    if ((strng.length < 4) || (strng.length > 60)) {
       error = "The filename is not valid. \n";
    }
    else if (illegalChars.test(strng)) {
    error = "The filename contains illegal characters. \n";
    } 
return error;
}    

function checkForm(theForm) {
	//alert("in formcheck");
	var why = "";
	why=why + checkFilename(theForm.filename.value);
	why=why + checkRadio(theForm);
		if (why != "") {
		document.getElementById("feedback").innerHTML=why;	   	
		document.getElementById("mode").value="null";
		return false;
		}
	//theForm.mode.value="createfile";
return true;
}

function checkchkb(theForm) {
	var error = "";
   	if (!theForm.tc.checked) {
       error = "Please indicate you have read our terms and conditions by clicking the checkbox.\n";
	   alert(error);
	   return false;
    	}
return true;
}