var cols;
var sel = new Array;

var editPage="";

function go(formId) {
	form = document.getElementById(formId);
	form.submit();
}

function closePopWin() {
//	hidePopWin(false);
	var actionField = document.getElementById("action");
	var form = actionField.form;
	form.submit();
}

function showEditPage(page) {
	if(editPage!="") {
		var lastPage = document.getElementById("subPage_"+editPage);
		lastPage.style.display = 'none';
	}
	showPage = document.getElementById("subPage_"+page);
	showPage.style.display = '';
	editPage = page;

	var currentPage = document.getElementById("pageName");
	currentPage.value = page;

}

function dispSubClass(field,action,urn) {
	var actionField = document.getElementById("action");
	actionField.value = "dispSubClass";
	var subField = document.getElementById("subField");
	subField.value = field;
	var subAction = document.getElementById("subAction");
	subAction.value = action;
	var subUrnField = document.getElementById("subUrn");
	subUrnField.value = urn;
	var form = actionField.form;
	form.submit();
}


function dispSelect(field) {
	var action = document.getElementById("action");
	var subField = document.getElementById("subField");
	action.value = "dispSelect";
	subField.value = field;
	var form = action.form;
	form.submit();
}


function removePick(field,pickUrn) {
	var action = document.getElementById("action");
	var pickField = document.getElementById("pickField");
	var pickUrnField = document.getElementById("pickUrn");
	action.value = "removePick";
	pickField.value = field;
	pickUrnField.value = pickUrn;
	var form = action.form;
	form.submit();
}

function addPick(field,pickUrn) { 
	var docParent = window.frameElement.ownerDocument;
	var action = docParent.getElementById("action");
	var pickField = docParent.getElementById("pickField");
	var pickUrnField = docParent.getElementById("pickUrn");
	action.value = "addPick";
	pickField.value = field;
	pickUrnField.value = pickUrn;
	var form = action.form;
	form.submit();
}

function submitListForm(formName,listfield) {
	var action = document.getElementById("action_"+formName);
	if(action=="moveTo") {
		var moveTo  = document.getElementById("moveTo_"+formName);
		moveTo.value = listfield.option[listfield.value].id;
	}
	action.value = listfield.value;
	action.form.submit();
}

function submitForm(action,formName) { 
	var actionField = document.getElementById("action_"+formName);
	actionField.value = action;

	actionField.form.submit();
}

function submit(action) { 
	var actionField = document.getElementById("action");
	actionField.value = action;
	form = actionField.form;
	form.submit();
}

function doSubmit(action) { 
	var actionField = document.getElementById("action");
	actionField.value = action;

	form = actionField.form;
	form.submit();
}


function highlightRow(row,on) {
	var cell;
	for(i=0;i<cols;i++) {
		name = "cell"+row+"_"+i;
		cell = document.getElementById(name);
		if(on) {
			if(sel[row]) {
				cell.className="tableDataSelected";
			} else {
				cell.className="tableDataOver";
			}
		} else {
			if(sel[row]) {
				cell.className="tableDataSelected";
			} else {
				if((row%2)==0) {
					end="Even";
				} else {
					end = "Odd";
				}
				cell.className="tableData"+end;
			}
		}
	}
}

function selectRow(row) {
	if(sel[row]) {
		sel[row]=false;
	} else {
		sel[row]=true;
	}
	for(i=0;i<cols;i++) {
		name = "cell"+row+"_"+i;
		cell = document.getElementById(name);
		if(sel[row]) {
			cell.className="tableDataSelected";
		} else {
			if((row%2)==0) {
				end="Even";
			} else {
				end = "Odd";
			}
			cell.className="tableData"+end;
		}
	}
	
}


function showHide(id) {
	var searchBox = document.getElementById(id);
	if(searchBox.style.display=="none") {
		searchBox.style.display="";
	} else {
		searchBox.style.display="none";
	}
}

function hide(id) {
	var searchBox = document.getElementById(id);
	if(searchBox == undefined) { return; }
	searchBox.style.display="none";
}

function minMax(id,minImg,maxImg) {

	showHide(id);
	var imgId = "img"+id;
	
	var searchBox = document.getElementById(id);
	var img = document.getElementById(imgId);
	if(searchBox.style.display=="none") {
		img.src=maxImg;
	} else {
		img.src=minImg;
	}

}

function updateField(field,value,disp) {
	var searchBox = window.frameElement.ownerDocument.getElementById(field);
	searchBox.value = value;
	var dispBox = window.frameElement.ownerDocument.getElementById("disp_"+field);
	dispBox.value = disp;
	parent.hidePopWin(false);
}

function resizeFrame(width,height) {
//alert(width+":"+height);
	if(width!="same") {
		window.frameElement.style.width = width;
	}
	if(height!="same") {
		window.frameElement.style.height = height;
	}
}



function pick_select(id, all) {
	var target = document.getElementById(id+"_selected");
	var source = document.getElementById(id+"_avail");	
	
	var tpos = target.options.length;
	
	
	for(i=0;i<source.options.length;) {
		if(source.options[i].selected || all) {
			target.options[tpos] = new Option(source.options[i].text,source.options[i].value);
			target.options[tpos].selected = true;
			
			tpos++;
		    
			source.options[i] = null;
			i=0;
		} else {
			i++;
		}
	}
	updateSelectHidden(id);
}

function updateSelectHidden(id) {

	var target = document.getElementById(id+"_selected");
	var hidden = document.getElementById(id);
	
	hidden.value = "";
	for(i=0;i<target.options.length;i++) {
		hidden.value = hidden.value + "," +target.options[i].value;
	}

}

function pick_unselect(id, all) {
	var source = document.getElementById(id+"_selected");
	var target = document.getElementById(id+"_avail");	
	
	var tpos = target.options.length;
	
	for(i=0;i<source.options.length;) {
		if(source.options[i].selected || all) {
			target.options[tpos++] = new Option(source.options[i].text,source.options[i].value);
			source.options[i] = null;
			i=0;
		} else {
			i++;
		}
	}
	updateSelectHidden(id);
}

function minimizeWin() 
{
window.resizeTo(100,100);
window.moveTo(screen.width,screen.height);
}

function maximizeWin() 
{
window.resizeTo(screen.width,screen.height);
window.moveTo(0,0);
}

function openWindow(url,name,height,width,xpos,ypos) {
	window.open(url,name,"scrollbars=1,width="+width+",height="+height+",top="+ypos+",left="+xpos);
}

function changeActionAndSubmitForm (formName,url) {
	var form = document.getElementById(formName);
	form.action=url; 
	form.submit();
}


function printPage() {
    window.print();
}

function embeddedSoundFix() {
	//put this function straight after your embedded sound object
	objects = document.getElementsByTagName('object');
	for (var i = 0; i < objects.length; i++)
	{
		objects[i].outerHTML = objects[i].outerHTML;
	}
}

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent('on'+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

function multi_select(id, all) {
	var target = document.getElementById("selected_"+id);
	var source = document.getElementById("avail_"+id);	
	
	var tpos = target.options.length;
	
	
	for(i=0;i<source.options.length;) {
		if(source.options[i].selected || all) {
			target.options[tpos] = new Option(source.options[i].text,source.options[i].value);
			target.options[tpos].selected = true;
			
			tpos++;
		    
			source.options[i] = null;
			i=0;
		} else {
			i++;
		}
	}
	updateMultiSelectHidden(id);
}

function updateMultiSelectHidden(id) {

	var target = document.getElementById("selected_"+id);
	var hidden = document.getElementById(id);
	
	hidden.value = "";
	for(i=0;i<target.options.length;i++) {
		hidden.value = hidden.value + "," +target.options[i].value;
	}

}

function multi_unselect(id, all) {
	var source = document.getElementById("selected_"+id);
	var target = document.getElementById("avail_"+id);	
	
	var tpos = target.options.length;
	
	for(i=0;i<source.options.length;) {
		if(source.options[i].selected || all) {
			target.options[tpos++] = new Option(source.options[i].text,source.options[i].value);
			source.options[i] = null;
			i=0;
		} else {
			i++;
		}
	}
	updateMultiSelectHidden(id);
}


function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }


function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( name ) {
		
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function rowChangeClass(table,cols,row,classname) {
        for(i=0;i<cols;i++) {
                document.getElementById(table+row+"_"+i).className = classname;
        }
}

function claimActionEdit(){
	
	var actions=document.getElementById("actionType");
	var users=document.getElementById("actionFor");
	var dueDate=document.getElementById("dueDate");
	var dueTime=document.getElementById("dueTime");
	var actionText=document.getElementById("actionText");
	if(actions.value==1)
	{
		users.disabled=true;
		dueDate.disabled=true;
		dueTime.disabled=true;
		actionText.disabled=true;
	}else{
		users.disabled=false;
		dueDate.disabled=false;
		dueTime.disabled=false;
		actionText.disabled=false;
	}
}

function showSubMenu(id) {

	menuBoxId = "child_" + id;
	var menuBox = document.getElementById(menuBoxId);
	imageBoxId = "img_" + id;
	var imageBox = document.getElementById(imageBoxId);
	if(menuBox.style.display=="none") {
		menuBox.style.display="";
		imageBox.src="/images/minus.gif";
	} else {
		menuBox.style.display="none";
		imageBox.src="/images/plus.gif";
	}

}