
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
ns6 = (document.getElementById) ? true:false

function layerWrite(id,nestref,text) {
	if (ns4) {
		var lyr = (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document;
		lyr.open()
		lyr.write(text)
		lyr.close()
	}else if (ie4) document.all[id].innerHTML = text
}



function popup(url,xtr) {
	window.open(url,'',xtr);
}

function erase(obj,msg) {
    if(confirm(msg)) {
        obj.submit();
    }
}

function selection(obj) {
	for(var i=0; i < obj.options.length; i++) {
		obj.options[i].selected = 1;
	}
}

function deltomenu(obj)
{
	if(obj.selectedIndex==-1) return false;
	if (obj.options.length < 1) return 0;

	var itemNo = obj.selectedIndex;
	obj.options[itemNo]=null;
}


function remove(objsource) {
	deltomenu(objsource)
}

function empty(obj) {
    obj.options.length = 0;
}

function reset(obj) {
    	alert("FUNCTION reset MUST NOT BE USED. USED empty instead");
    	for(var i=0;;i++) {
        if(obj.options.length==0) break;
        obj.options[0].selected = 1
        var itemNo = obj.selectedIndex;
        obj.options[itemNo]=null;
      }
}

function move(objsource,objtarget) {
	if(objsource.selectedIndex==-1) return false;
	var pos = objsource.selectedIndex;
	var value = objsource[objsource.selectedIndex].value;
	var text  = objsource[objsource.selectedIndex].text;

  objsource[objsource.selectedIndex] = null;

  opt = new Option(text,value)
  objtarget.options.add(opt);
}

function moveUp(objsource) {
	if(objsource.selectedIndex==-1) return false;
	var pos = objsource.selectedIndex;
	var value = objsource[objsource.selectedIndex].value;
	var text  = objsource[objsource.selectedIndex].text;
	if(pos!=0) {
		var value2 = objsource[objsource.selectedIndex-1].value;
		var text2  = objsource[objsource.selectedIndex-1].text;
		objsource[objsource.selectedIndex-1].value = value;
		objsource[objsource.selectedIndex-1].text = text;
		objsource[objsource.selectedIndex].value = value2;
		objsource[objsource.selectedIndex].text = text2;
		objsource.selectedIndex = pos-1;
	}else
		objsource.selectedIndex = pos;
}

function moveDown(objsource) {
	if(objsource.selectedIndex==-1) return false;
	var pos = objsource.selectedIndex;
	var value = objsource[objsource.selectedIndex].value;
	var text  = objsource[objsource.selectedIndex].text;
	if(objsource.length!=pos+1) {
		var value2 = objsource[objsource.selectedIndex+1].value;
		var text2  = objsource[objsource.selectedIndex+1].text;
		objsource[objsource.selectedIndex+1].value = value;
		objsource[objsource.selectedIndex+1].text = text;
		objsource[objsource.selectedIndex].value = value2;
		objsource[objsource.selectedIndex].text = text2;
		objsource.selectedIndex =pos+1;
	}else
		objsource.selectedIndex =pos;
}

function addtomenuFromText(objsource,objdest) {
    if(objsource.value=='') return false;

	var value = objsource.value;
	var name  = objsource.value;

	//you have to make the item into an array to add to select box
	var opt = new Option(name, value);
	objdest.options[objdest.options.length]=opt;

}

function addtomenu(objsource,objdest)
{
	if(objsource.selectedIndex==-1) return false;

	var value = objsource[objsource.selectedIndex].value;
	var name  = objsource[objsource.selectedIndex].text;

	//you have to make the item into an array to add to select box
	var opt = new Option(name, value);
	objdest.options[objdest.options.length]=opt;
}


function addXmlOption(tagname,objsource1,attr1,objsource2,attr2,objdest)
{


  if(objsource1.type=='text') {
    var value1 = objsource1.value;
    var name1  = objsource1.value;
  } else {
    if(objsource1.selectedIndex==-1) return false;

    var value1 = objsource1[objsource1.selectedIndex].value;
    var name1  = objsource1[objsource1.selectedIndex].text;
  }

  if(objsource2.type=='text' || objsource2.type=='hidden') {
    var value2 = objsource2.value
    var name2= objsource2.value
  } else {
    if(objsource2.selectedIndex==-1) return false;
    var value2 = objsource2[objsource2.selectedIndex].value;
    var name2  = objsource2[objsource2.selectedIndex].text;
  }
	var xmlstr='<'+ tagname + ' ' + attr1 + '="' + value1 + '" ' + attr2 + '="' + value2 + '"/>';

  var name = name1 + ' (' + name2 + ')';

	//you have to make the item into an array to add to select box
	var opt = new Option(name, xmlstr);
	objdest.options[objdest.options.length]=opt;

}

function popupCenter(URL,width,height,xtr) {
  var top=(screen.height-height)/2;
  var left=(screen.width-width)/2;
  window.open(URL,"","top="+top+",left="+left+",width="+width+",height="+height+","+xtr);
}

function popupImageCenter(winURL, width, height, winFeatures) {
  var top=(screen.height-height)/2;
  var left=(screen.width-width)/2;
	w=open('',"popup","top="+top+",left="+left+",width="+width+",height="+height+","+'toolbar=no,scrollbars=no,resizable=yes');
	w.document.write("<TITLE>Image</TITLE>");
	w.document.write("<BODY leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><img src="+winURL+">");
	w.document.write("</BODY>");
	w.document.close();
}
function  formatDate(str) {
    val = str.split("/");
    if (val.length!=3) {
        return false;
    }
    str2= val[2]+ '-' + val[1] + '-' + val[0];
    return str2
}

/**
 * for the list
 */
function levelUp(obj) {
    var value = obj.options[obj.selectedIndex].value;
    window.location=link ="list.php?"+value;
}

/**
 * for the list
 */
function PopuplevelUp(obj) {
    var value = obj.options[obj.selectedIndex].value;
    window.location=link ="choose.php?"+value;
}

function addObject(obj) {
    var link="";
    var value = obj.options[obj.selectedIndex].value;
    if(value!="-1") {
        window.location=link ="view.php?action=add&grcltype="+value;
    }
}


var strColumns_Current = "215,*";
var TreeVisible=0;


function displayTree() {
	TreeVisible = (TreeVisible==1) ? 0 : 1;

	if(TreeVisible) {
      strColumns_Current = top.mainframeset.cols
      top.mainframeset.cols = "1,*";
	} else {
      top.mainframeset.cols = strColumns_Current;
  }
}

function openMainarea(link,link2,from) {
    top.frames['mainarea'].location.href = link;
    if(from=='top') {
        if(link2!="") {
            top.frames['left'].location.href = link2;
            top.mainframeset.cols = strColumns_Current;
        } else {
            top.mainframeset.cols = "1,*";
        }
    }
    //if(TreeVisible) displayTree()
}

function dumpProps(obj, parent) {
   for (var i in obj) {
      if (parent) { msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      if (!confirm(msg)) { return; }
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}


// Disable the right mouse button
function right(e) {
return true;
	var msg = "Sorry, right-click has been disabled.";
	if (navigator.appName == 'Netscape' && e.which == 3) {
		alert(msg);  // Delete this line to disable but not alert user
		return false;
	}
	else
		if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
			alert(msg); // Delete this line to disable but not alert user
		return false;
	}

	return true;
}
//document.onmousedown = right;

// Key Press data	IE			NETSCAPE
//	0 - 9			48 - 57		48 - 97
//	a - z			97 - 122	97 - 122
//	A - Z			65 - 90		65 - 90
//	Space			32			32
//	Cursors						0
//	Backspace					8
//	Delete						0
//  Hyphen						45

// For fields where only numbers are accepted
function NumOnly ( evnt ) {
   var key = ( navigator.appName == "Netscape" ) ? evnt.which : evnt.keyCode;
   //      cursor   Backsapce        0          9
      if ( key==0 || key==8 || (key>=48 && key<=57) )
		return true;
   else return false;
}

// For fields where only Alpha chars are accepted
function AlphaOnly ( evnt )
{
   var key = ( navigator.appName == "Netscape" ) ? evnt.which : evnt.keyCode;
   //      cursor   Backspace  Space     Hyphen(-)       a            b              A            Z
      if ( key==0 || key==8 || key==32 || key==45 || (key >=97 && key <= 122) || (key >=65 && key <= 90) )
		return true;
   else return false;
}

// For fields where only Alphanumeric chars are allowed
function AlphaNumOnly ( evnt )
{
   var key = ( navigator.appName == "Netscape" ) ? evnt.which : evnt.keyCode;
   //      cursor   Backsapce  Space             a            b             0          9             A            Z
      if ( key==0 || key==8 || key==32 || (key >=97 && key <= 122) || (key>=48 && key<=57) || (key >=65 && key <= 90) )
		return true;
   else return false;
}