<!-- 
/* 
Author: Jojo Ampia - Addison
name: admin.js
Function: Administrative scripts to handle choices and events in 
	  the Member Management tool.
Company: Xmserv.org
Comments: Use with great care! Steal with even greater care!

<script id="markSetter" type="text/javascript"  LANGUAGE="JavaScript" >
*/
--> 

function checkInput(inputp, minp, maxp){
		if(inputp.length < minp){alert(inputp+' is less than the required input minimum of '+minp);return false;}
		if(inputp.length > maxp){alert(inputp+' is greeater than the required input maximum of '+maxp);return false;}
		return true;
}
// privatised confirm for the case where nothing is yet selected.
function confirmAll(foo){
  //alert('No entries selected!\n Assuming the all case');
//  return confirm(foo + " all the records?\n\n1. OK to continue...\n\n2. Cancel to return and make some selection");
  if(confirm (foo + " all the records?\n\n1. OK to continue...\n\n 2. Cancel to return and make some selection")==1){
			  return true;
			  } else {
				  return false;
			  }
}

// Confirms wheter we have some selected entries in either of our forms
function confirmSelected(){
  for(var i=0; i < document.NAVIGATOR_FORM.elements.length; i++){
    //alert(document.NAVIGATOR_FORM.elements[i].name);
    if((document.NAVIGATOR_FORM.elements[i].name).charAt(0) == '_' &&
       document.NAVIGATOR_FORM.elements[i].value=="marked"){     
      return true;
    }
    if( document.group.elements[i] != null && 
       (document.group.elements[i].name).charAt(0) == '_' &&
        document.group.elements[i].value == "marked"){
	  return true;
	}

  } 
  return false;
}

// Sets all entries in group form as marked and uses setAllChecked to add entries to navigator_form
function checkAll(){
  setAllChecked();
  for (i=0; i< document.group.elements.length;i++){
      if(document.group.elements[i].name.charAt(0)== '_'){
      if( document.group.elements[i].value=="marked"){
	document.group.elements[i].value="";
      }else  document.group.elements[i].value=="marked";
      }//if
  }//for
 
}

// If All is checked or unckecked this runs within checkAll to ensure entries are created
// in NAVIGATOR for use later. works like addMark in cascading style
function setAllChecked(){
  var inputTags = document.getElementsByTagName("INPUT");
  var flag = false; var box = false; var theMark;
  for(var i=0; i < inputTags.length; i++){
    //        alert(inputTags[i].getAttribute("TYPE"));
    box=false;
    if(inputTags[i].getAttribute("TYPE") == "checkbox" &&  inputTags[i].getAttribute("name")=="checkAll"){
      if (inputTags[i].checked == true){
	flag = true; 
	}
    }
    if(inputTags[i].getAttribute("TYPE") == "checkbox" && inputTags[i].getAttribute("name").charAt(0)=="_"){      
      	if(inputTags[i].checked){
	inputTags[i].checked = false;
	theMark=inputTags[i];
	}else{
	inputTags[i].checked = flag;
	theMark=inputTags[i];
	}
	//	if(theMark.checked)inputTags[i].checked=false;
	//	if(!theMark.checked)inputTags[i].checked=true;
	//	if(!flag && theMark.checked == true)theMark.checked=false;
	//	if(!flag && theMark.checked ==false)theMark.checked=true;
      box = true;
    }
    if(box){
      entry = document.createElement("INPUT");
      entry.setAttribute("type","hidden");
      entry.setAttribute("name",theMark.name);
      if(theMark.checked == true){
	entry.setAttribute("value", "marked");   
      }else {
	entry.setAttribute("value", "");
      }   	
     if(markExist(entry)){
	// toggled do nothing
	}else{ document.NAVIGATOR_FORM.appendChild(entry);  }
      box=false; //i++;
    }
        
  }
}

// Appends all checked entries from previous pages in navigator_form into the group form
function selectAllChecked(){
//alert('selecting all checked!');
   for (var i=0; i<document.NAVIGATOR_FORM.elements.length;i++){
     if(document.NAVIGATOR_FORM.elements[i].getAttribute("TYPE") == "hidden"  && 
	    document.NAVIGATOR_FORM.elements[i].name.charAt(0) == '_' && 
	    document.NAVIGATOR_FORM.elements[i].value == "marked"){
       //       alert("selected element " + document.NAVIGATOR_FORM.elements[i].name);
      selectedEntry = document.createElement("input");
      selectedEntry.setAttribute("type", "hidden");
      selectedEntry.setAttribute("name",   document.NAVIGATOR_FORM.elements[i].name);
      selectedEntry.setAttribute("value", "marked");
      document.group.appendChild(selectedEntry);
    }
  }
}

// add an entry to the navigator form for a selected entry
// we will need it later before we submit the form
function addMark(theMark){	
     entry = document.createElement("input");
     entry.setAttribute("type","hidden");
     entry.setAttribute("name",theMark.name);
     if(theMark.checked == true){
     entry.setAttribute("value", "marked");   
     }else {entry.setAttribute("value", "");}
	if(markExist(entry)){
	// toggled do nothing
	}else{ document.NAVIGATOR_FORM.appendChild(entry);  }
}

// remove an entry from the navigator form for a deselected entry
function markExist(theMark){
  for(var i=0; i < document.NAVIGATOR_FORM.elements.length; i++){
    //alert(document.NAVIGATOR_FORM.elements[i].name);
    if(document.NAVIGATOR_FORM.elements[i].name == theMark.name){     
        document.NAVIGATOR_FORM.elements[i].value=theMark.value;
	/*if(document.NAVIGATOR_FORM.elements[i].value == "marked"){
	document.NAVIGATOR_FORM.elements[i].value = "";
	}else if(document.NAVIGATOR_FORM.elements[i].value == ""){
	document.NAVIGATOR_FORM.elements[i].value = "marked";
	}*/ 
	//alert(theMark.value + document.NAVIGATOR_FORM.elements[i].value);
	 return true;	
    }
  } 
return false;
}

// handles the label button
function handleLabel(){
  if(confirmSelected()){
    //Submit group labelling
    document.group.action='label.php';
     selectAllChecked();
    document.group.command.value = "selectedOnly";
    document.group.target='_blank';
    document.group.submit();
  }else  if(document.group.filter.value != ""){
    //alert('Filter mode is on');
    document.group.action='label.php';
    document.group.command.value = "search";
    document.group.target='_blank';
    document.group.submit();
  }else if(confirmAll('Label out')){
    document.group.action='label.php';
    document.group.command.value = "all";
    document.group.target='_blank';
    document.group.submit();
  }
}
// handles the group button
function handleGroup(){
  if(confirmSelected()){
    document.group.command.value = "selectedOnly";
    selectAllChecked();
    document.group.action='group.php'; 
	document.group.method='post';
    document.group.submit();
  }else if(document.group.filter.value != "" ){
    //  alert('Filter mode is on');
    document.group.command.value="search";
    document.group.action='group.php'; 
	document.group.method='post';   
    document.group.submit();    
  }else if(confirmAll('Group ')){
    document.group.command.value="all";
    document.group.action='group.php'; 
	document.group.method='post';   
    document.group.submit();    
  }
}

function handlePrint(){
  if(confirmSelected()){
    document.group.command.value = "selectedOnly";
    selectAllChecked();
    document.group.target='_blank';
    document.group.action='print.php';    
    document.group.submit();
  }else if(document.group.filter.value != "" ){
    //  alert('Filter mode is on');
    document.group.command.value="search";
    document.group.target='_blank';
    document.group.action='print.php';    
    document.group.submit();    
  }else if(confirmAll('Print ')){
    document.group.command.value="all";
    document.group.action='print.php';    
    document.group.target='_blank';
    document.group.submit();    
  }
}

function handleExport(){
  if(confirmSelected()){
    document.group.command.value = "selectedOnly";
    selectAllChecked();
    document.group.target='_blank';
    document.group.action='export.php';    
    document.group.submit();
  }else if(document.group.filter.value != "" ){
    //  alert('Filter mode is on');
    document.group.command.value="search";
    document.group.target='_blank';
    document.group.action='export.php';    
    document.group.submit();    
  }else if(confirmAll('Export ')){
    document.group.command.value="all";
    document.group.target='_blank';
    document.group.action='export.php';    
    document.group.submit();    
  }
}

function iPrint( pTarget ){
pTarget.focus();
pTarget.print();
}

function winpop(w,h,u,n){
		window.open(u,"_blank","HEIGHT="+h+",WIDTH="+w+",dependent=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,menubar=no,left=0,top=0");
	}
	
	function winpop_noscroll(w,h,u,n){
		window.open(u,"_blank","HEIGHT="+h+",WIDTH="+w+",dependent=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,copyhistory=no,menubar=no,left=0,top=0");
	}

	function winpopcenter(w,h,u,n){
	    function winWid(){ return ( (ns4||ns6) ? window.innerWidth:document.body.clientWidth ); }
	    function winHei(){ return (ns4||ns6) ? window.innerHeight:document.body.clientHeight; }
	    function centerX(){ return (ns4||ns6) ? parseInt((screen.width/2)-(width/2)):parseInt((screen.availWidth/2)-(width/2)); }
	    function centerY(){ return (ns4||ns6) ? parseInt((screen.height/2)-(height/2)):parseInt((screen.availHeight/2)-(height/2)); }
	    var ns4 = (document.layers) ? 1 : 0;
	    var ie4 = (document.all) ? 1 : 0;
	    var ns6 = (document.getElementById && !document.all) ? 1 : 0;
	    var width=winWid();
	    var height=winHei();
	    var difx=w-winWid();
	    var dify=h-winHei();
	    width+=(difx);
	    height+=(dify);
		window.open(u,"_blank","HEIGHT="+h+",WIDTH="+w+",dependent=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,menubar=no,left="+centerX()+",top="+centerY());
	}
	
<!--
/*
</script>
*/
-->