function setFocus(page) {
		if (page = 'contact') {
    document.contact.fname.focus();
    }
		else {
		document.login.user.focus();
		}
}
		
function IsFieldEmpty(field) {
   if ((field.value.length==0) || (field.value==null)) {
      return true;
   }
   else { return false; }
}

function CheckUrl(field)
{
 var theurl=field.value;
 var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
 if (tomatch.test(theurl))
 {
 return false;
 }
 else { return true; }
}

function VerifyFormValues() {
	var missing = "";
	if(CheckUrl(document.register.website) == true) { missing += "  - Your Website is not formatted correctly or is empty\n"; }
	if(document.register.terms.checked == false ) { missing += "  - You must agree to the Terms and Conditions\n"; }
	
	if(missing != '') {
		alert("__________________________________________________\n\nYour request cannot continue because of the following error(s)\nPlease fix the following error(s) and re-submit:\n__________________________________________________\n\n" + missing);
		return false;
	} 
	else {
		document.register.submit();
		return false;
	}
}

function VerifyNewsFormValues() {
	var missing = "";
	if(document.f2.cat.options[document.f2.cat.selectedIndex].value == 0) { missing += "  - Category is empty\n"; }
	if(document.f2.subcat.options[document.f2.subcat.selectedIndex].value == 0) { missing += "  - Subcategory is empty\n"; }
	if(IsFieldEmpty(document.f2.question) == true) { missing += "  - Question is empty\n"; }
	if(!document.f2.choice_a.disabled){
			if(IsFieldEmpty(document.f2.choice_a) == true) { missing += "  - Choice A is empty\n"; }
			if(IsFieldEmpty(document.f2.choice_b) == true) { missing += "  - Choice B is empty\n"; }
			if(IsFieldEmpty(document.f2.choice_c) == true) { missing += "  - Choice C is empty\n"; }
			if(IsFieldEmpty(document.f2.choice_d) == true) { missing += "  - Choice D is empty\n"; }
	}
	if(document.f2.answer.options[document.f2.answer.selectedIndex].value == '') { missing += "  - Answer is empty\n"; }
		
	if(missing != '') {
		alert("__________________________________________________\n\nYour request cannot continue because of the following error(s)\nPlease fix the following error(s) and re-submit:\n__________________________________________________\n\n" + missing);
		return false;
	} 
	else {
		document.f2.submit();
		return false;
	}
}

/* Functions for Testing Center Admin */
function toggleRow(rownum) {
	if (document.getElementById(rownum).style.display == '') {
		document.getElementById(rownum).style.display='none';
		}
		else {
		document.getElementById(rownum).style.display='';
		}
}

function verifyDelete(){
		input_box=confirm("Are you sure you want to delete this item?");
		if (input_box==true)
        { 
        return true
        }
    	  else {
    		return false
    		}
    }		

function resetPassword() {
		var passwd = prompt("Enter new password", "New Password");
    if (passwd==true)
        { 
        return true
        }
    	  else {
    		return false
    		}
		}
/* End functions for Testing Center Admin */
function openPopup(doc, width, height) {
var winl = (screen.width)/2;
var wint = (screen.height)/2;
    if (width == null) {
    width = 800;
    height = 700;
    }
    else {
    width = width + 20;
    height = height + 20;
    }
newWindow = window.open(doc, 'myWindow', 'scrollbars,resizable,top=' + wint + ',left=' + winl + ',width=' + width + ',height=' + height);
}

function bookmarksite(title, url){
    if (document.all)
    window.external.AddFavorite(url, title);
    else if (window.sidebar)
    window.sidebar.addPanel(title, url, "")
    }

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// Functions for Reminders

function download_file(id)
{
	// We'll pass these values to the script...
	var values = "action=download&file=" + escape(id);
	
	if (document.getElementById('f_name').value != "")
	{
		values = values + "&file_name=" + document.getElementById('f_name').value;
	}

	var url = "scripts/excel_export.php?"+values;

	window.open(url,"Download","menubar=no,scrollbars=yes,width=200,height=150,toolbar=no");

}
/* VALIDATE */
/* This validates forms....*/
function validate_form(field)
{
	valid = true;
	
	fn = document.getElementById(field);
	
	if (fn.value == '')
	{
		fn.className = 'field_invalid'
		alert("You must fill in the fields highlighted in red!");
		fn.focus();
		valid = false;
	}
	
	return valid;
}
/* End functions for Reminders */

function reload(form, page){
   var val=form.cat.options[form.cat.options.selectedIndex].value;
   self.location=page + '&cat=' + val;
}
function isChecked(radGroup){
for (var i=0;i<radGroup.length;i++){
if (radGroup[i].checked) return true;
}
return false;
}

function CheckRadios(numqs){
var total = numqs
var err = 0
var message = ""
for (var i=1; i <= numqs; i++){
if (!isChecked(document.quizform.elements["q_"+i])){
err++;
}
}
if (err>0){
alert("There is/are " + err + " unanswered question(s)")
return true;
}
else {
document.quizform.submit();
return false;
}
}
/* End functions for Testing Center */
