// JavaScript Document for ProjectsDatabase

//detect browser settings for showing and hiding DIVs
     isNS4 = (document.layers) ? true : false;
     isIE4 = (document.all && !document.getElementById) ? true : false;
     isIE5 = (document.all && document.getElementById) ? true : false;
     isNS6 = (!document.all && document.getElementById) ? true : false;
	 
	 
	 function getFormNum (formName) {
		formNum =-1;
		for (i=0;i<document.forms.length;i++){
			tempForm = document.forms[i];
			if (formName == tempForm) {
				formNum = i;
				correctForm = tempForm;
				break;
   			}
		}
		return formNum;
	}
	 
	function showHide(element){
	arr = new Array("a","b","c","d");
		for(i=0; i<arr.length; i++){
			if(arr[i] == element){
 				switchDiv([arr[i]],true);
			} else {
 				switchDiv([arr[i]],false);
			}
		}
		return false;
	} 
	 
	 function switchDiv(strDivName,bolVisible){
 		if (isNS4) { 
   			objElement = document.layers[strDivName];
 		} else if (isIE4) {
   			objElement = document.all[strDivName];
 		} else if (isIE5 || isNS6) {
   			objElement = document.getElementById(strDivName);
 	}
 
 		if(isNS4){
     		if(!bolVisible) {
       			objElement.visibility ="hidden"
     		} else {
       			objElement.visibility ="visible"
     		}     
 		}else{
     		if(!bolVisible) {
       			objElement.style.visibility = "hidden";
     		} else {
       			objElement.style.visibility = "visible";
     		}
 		}
	}
	
	function jmp(formName,elementNum) {
		getFormNum(formName);
		if (formNum>=0) {
			with (document.forms[formNum].elements[elementNum]) {
				i=selectedIndex;
				if (i>=0) $thisvar=0; //location=options[i].value;
      		}
   		}
	}
	
	
	function O(txt,url) {
		a[k]=new Option(txt,url);k++;
	}
	
	///////////////////////////////////////////////////////////////
	
	function openWindow(theURL,winName,features) { //v2.0
  		URL = 'explain.php?m=' + theURL;		
		window.open(URL,winName,features);
	}
	
	function oW(theURL) { //v2.0
  		URL = theURL;		
		window.open(URL,'ReportWin','status=yes,scrollbars=yes,resizable=yes,width=550,height=350');
	}
	
	function selOld() {
		var isopen = oW('sel_file.php');
	}	
	
	function upNew() {
		var isopen = oW('up_file.php');
	}
	
	///////////////////////////////////////////////////////////////
	
	function isempty(val) {
		var empty = /^\s*$/
		return empty.test(val)
	}

	///////////////////////////////////////////////////////////////

	function sortby(val) {
		if(!isempty(val)) { document.searchForm.sb.value = val; } else { alert('You have not selected a valid value to sort by!'); }
	}
	
	function orderby(val) {
		if(!isempty(val)) { document.searchForm.ob.value = val; } else { alert('You have not selected a valid value to sort by!'); }
	}
	
	function doPost(ploc,id) {
		var theform; 
		if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {	theform = document.fp; }
		else { theform = document.forms["fp"]; } 
		if(!isempty(ploc) || !isempty(id)) {
			document.getElementById('ploc').value = ploc;
			document.getElementById('id').value = id;
			theform.submit();
		}
	}
	
	///////////////////////////////////////////////////////////////
	
	function addimage(imgname) {
		if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {	theform = window.opener.document.pdform.report; }
		else { theform = window.opener.document.forms["pdform"].report; }
		theform.value = (imgname);
		this.window.close();
	}

	
	///////////////////////////////////////////////////////////////
	
	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.id; 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('You have not filled in the following required fields in this form:\n'+errors);
  //document.MM_returnValue = (errors == '');
  return false; } else {
  return true;
  }
}

function goValProj() {
	if(MM_validateForm('name','','R','type','','R','abstract','','R')) {
		return true;
	} else {
		return false;
	}
}

function goValMod() {
	if(MM_validateForm('name','','R','type','','R')) {
		return true;
	} else {
		return false;
	}
}

function goValSt() {
	if(MM_validateForm('name','','R','type','','R','projecttypeid','','R')) {
		return true;
	} else {
		return false;
	}
}
	
	///////////////////////////////////////////////////////////////////////////
	
	
