function navRollOver(obj, state, mstyle) {
  document.getElementById(obj).className = (state == 'on') ? 'nav-highlight' : mstyle;
}
function closeRefresh(){
	opener.location.reload();
	window.close();
}
function go(url){
	parent.location=url;
}
function userPop(mjobid, refresh, url, mwidth, mheight){
	if(!url)url='jobgroup.php?action=invite&pop=true&jobid=' + mjobid;
	if(!mwidth)mwidth = 800;
	if(!mheight)mheight = 450;
	featureString='scrollbars,width='+mwidth+',height='+mheight;
	window.open(url,'admin',featureString);

}
function goSearch(){
	msearch=document.msearch1.search.value;
	if(msearch!='Search'&&msearch!='')
		document.forms.msearch1.submit()
	else
		alert('Please enter a search term or $mtask Id');
}
function clearSearch(){
	msearch=document.msearch1.search.value;
	if(msearch=='Search'||msearch=='')
		document.msearch1.search.value='';

}

function uploadButton(elementId, size, buttonText){
	mButton=document.getElementById(elementId);
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    // true if we're on ie
	if(isIE)
		mButton.outerHTML='<span class=\"submitDiv loadingButton\" style=\''+size+'\'>'+buttonText+'</span>';
	else
		mButton.innerHTML=buttonText;
}

//flag to show whehter a toggle has happened
var toggleFlag="unset";
var mDiv="";
var mState="";
function showHide(szDivID, iState, displayType) {

	if(displayType==null)displayType="block"

	//set basic match
    if(iState==1)
    	viewState = displayType;
    if(iState==0)
    	viewState = "none";

    //check for toggle
    if(mDiv==szDivID){
		if(mState==1){
			viewState = "none";
			iState=0
		}
		if(mState==0){
			viewState = displayType;
			iState=1
		}
	}
    //save inital request
    mDiv=szDivID;
    mState=iState;
    //alert('view:'+szDivID + " " +viewState)
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].style.display= viewState;
       toggleFlag=toggleFlag?false:true;

    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.display = viewState;
        toggleFlag=toggleFlag?false:true;
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.display = viewState;
        toggleFlag=toggleFlag?false:true;

    }
}
function ajaxPost(strURL, divId, vars) {

	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('GET', strURL, true);
	//self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	self.xmlHttpReq.onreadystatechange = function() {

		if (self.xmlHttpReq.readyState == 4) {
			//opacity(divId, 20, 100, 1000)//fade in
			//alert(self.xmlHttpReq.responseText)
			updatepage(self.xmlHttpReq.responseText, divId);
		}
	}
	self.xmlHttpReq.send(vars);
}
function updatepage(str, divId){
	if(divId=='mtable'){
		addRow(divId)
	}else {
		//opacity(divId, 100, 0, 0)
		//newdiv = document.createElement("div");
		//alert('divId: '+divId)
		document.getElementById(divId).innerHTML = str;
	}
}
function addRow(id){
	var tbody = document.getElementById
	(id).getElementsByTagName("TBODY")[0];
	var row = document.createElement("TR")
	var td1 = document.createElement("TD")
	td1.appendChild(document.createTextNode("column 1"))
	var td2 = document.createElement("TD")
	td2.appendChild (document.createTextNode("column 2"))
	row.appendChild(td1);
	row.appendChild(td2);
	tbody.appendChild(row);
}
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
    	//hide item first
    	changeOpac(0, id)
    	//show with style
    	var mObject = document.getElementById(id).style;
    	mObject.visibility="visible";
    	//show with filters
        for(i = opacStart; i <= opacEnd; i++)
            {
            //i+=i+2;
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
//resize text area
function sz(t) {
//alert('this='+t)
a = t.value.split('\n');
b=1;
for (x=0;x < a.length; x++) {
 if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
 }
b+= a.length;
if (b > t.rows) t.rows = b;
}
