function lock(item,button,id)
{
  brat = document.getElementById(button);
  var pos = brat.src.indexOf('lock');
	//if(dd.elements[button].text == '<img  border=0 src="/images/unlock.gif">'){
	if( pos >= 0 ){
		//dd.elements[button].swapImage(dd.elements[button].defsrc);
		dd.elements[item].setDraggable(false);
		dd.elements[item].setResizable(false);
	//	dd.elements[item].style.border=none;
		dd.elements[item].setCursor(CURSOR_DEFAULT); 
		dd.elements[button].setCursor(CURSOR_HAND);
		
		if ((dd.elements[item].x != dd.elements[item].defx) || 
		    (dd.elements[item].y != dd.elements[item].defy) || 
		    (dd.elements[item].h != dd.elements[item].defh) || 
		    (dd.elements[item].w != dd.elements[item].defw)){
		 location.href="/Modules/update/admin.php?x="+dd.elements[item].x+"&y="+dd.elements[item].y+"&h="+dd.elements[item].h+"&w="+dd.elements[item].w+"&id="+id;
		} else {
		brat.src = "/Interface/Images/move.png";
		}

	}else{
 		//dd.elements[button].swapImage('/images/lock.png');
		dd.elements[item].setDraggable(true);
		dd.elements[item].setResizable(true); 
		dd.elements[item].setCursor(CURSOR_MOVE);
		brat.src = "/Interface/Images/lock.png";
}			
}

function bar(bar,button)
{
	bar1 = document.getElementById(bar);
	button1 = document.getElementById(button);

	if(bar1.style.display==''){	
		bar1.style.display='none';
		button1.style.display = '';
	}else{	
		bar1.style.display='';
		button1.style.display = 'none';
    }			
    return false;
}

function hidden_app(form, name, value)
{  
	var input = document.createElement("input"); 
	input.setAttribute("name", "get_val["+name+"]");
	input.setAttribute("type", "hidden");
	input.setAttribute("value", value); 
	form.appendChild(input); 
}

function checkAllBoxes(form) {
	for(i = 0; i < form.elements.length; i++) {
		if(form.elements[i].className == "checky" && form.elements[i].disabled != true) {
			form.elements[i].checked = true;
		}
	}
}

function unCheckAllBoxes(form) {
	for(i = 0; i < form.elements.length; i++) {
		if(form.elements[i].className == "checky" && form.elements[i].disabled != true) {
			form.elements[i].checked = false;
		}
	}
}

function checkSectionBoxes(form, name) {
	for(i = 0; i < form.elements.length; i++) {
		if(form.elements[i].className == "checky" && form.elements[i].name.indexOf(name) != -1 && form.elements[i].disabled != true) {
			form.elements[i].checked = true;
		}
	}	
}

function unCheckSectionBoxes(form, name) {
	for(i = 0; i < form.elements.length; i++) {
		if(form.elements[i].className == "checky" && form.elements[i].name.indexOf(name) != -1 && form.elements[i].disabled != true) {
			form.elements[i].checked = false;
		}
	}	
}

function disable_enable(input_name) {
	document.getElementById(input_name).disabled = !document.getElementById(input_name).disabled;
}

function toggle_end_date() {
	label = document.getElementById("end_date_label");
	options = document.getElementById("end_date_options");
	toggle = document.getElementById("show_hide_date");
	
	if(toggle.checked) {
		label.style.display = '';
		options.style.display = '';
		toggle.nextSibling.innerHTML = " Uncheck to Remove End Date";
	}
	else {
		label.style.display = 'none';
		options.style.display = 'none';
		toggle.nextSibling.innerHTML = " Check to Add End Date";
	}
}

function AllowVisibility() {
	if(AddToList('vis_users[]', 'allow_vis[]')) {
		AddToList('vis_users[]', 'reg_users[]');
		DelFromList('vis_users[]');
	}
	
	if(AddToList('vis_groups[]', 'allow_vis[]')) {
		AddToList('vis_groups[]', 'reg_groups[]');
		DelFromList('vis_groups[]');
	}
}

function confirm_action(msg, form) {
	answer = confirm(msg);
	
	if (answer)
		form.submit();
	else
		return false;	
}


/*
selected = new Array();
for (var i = 0; i < ob.options.length; i++)
	if (ob.options[ i ].selected)
		selected.push(ob.options[ i ].value);
*/

function DenyVisibility() {
	DelFromList('allow_vis[]');
}

function AllowRegistration() {
	AddToList('reg_users[]', 'allow_reg[]');
	
	AddToList('reg_groups[]', 'allow_reg[]');
}

function DenyRegistration() {
	DelFromList('allow_reg[]');
}

function AddToCurrent(form) {
	AddToList('available_feeds[]', 'current_feeds[]');
	
	form.submit();
}

function RemoveFromCurrent(form) {
	AddToList('current_feeds[]', 'available_feeds[]');
	
	form.submit();
}

function AddToList(source, destination) {
   var menu_list = document.getElementById(source);
   var index =  menu_list.selectedIndex;
   if (index<0) return false;  
   var menu_name = menu_list.options[index].text;   
   var menu_id = menu_list.options[index].value;
   var add_menu = document.getElementById(destination);
  
   var newOption = document.createElement("OPTION");
   newOption.text = menu_name;
   newOption.value = menu_id;
   (add_menu.options.add) ? add_menu.options.add(newOption) : add_menu.add(newOption, null);
//   menu_list.selectedIndex=-1;
   return true;
}


function DelFromList(destination) {
   var list = document.getElementById(destination);
   var index =  list.selectedIndex;
   if (index<0) false;  
   list.options[index]=null;   
   return true;
}

function ChangeMoveLocation(loc) {
    var to_loc = document.getElementById("to_location");
    to_loc.innerHTML = loc;
    document.forms['frm_move'].elements['move_to'].value = loc;
}

// script used in the file repository module
function addUpload(num) {

		// change "add another file" link
	add_link = document.getElementById("add_link")
	
	if(num < 4) {
		num += 1
		add_link.setAttribute("onclick", "addUpload(" + num + ")")
	}
	else {
		hrefattr = add_link.getAttributeNode("href")
		add_link.removeAttributeNode(hrefattr)
		add_link.innerHTML = ""
	}
	
	// get the table
	table = document.getElementById("upload_table")
	
	// add separator
	hr = document.createElement("hr")
			
	td = document.createElement("td")
	td.setAttribute("colspan", "2")
	
	tr = document.createElement("tr")
	
	td.appendChild(hr)
	tr.appendChild(td)
	table.appendChild(tr)
	
	// create elements for the first row
	input = document.createElement("input")
	input.setAttribute("type", "file")
	input.setAttribute("name", "files[]")
	input.setAttribute("size", "25")
	input.setAttribute("style", "margin-bottom:4px;")
	
	td = document.createElement("td")
	td.setAttribute("colspan", "2")
	
	tr = document.createElement("tr")
	
	// add elements for first row
	td.appendChild(input)
	tr.appendChild(td)
	table.appendChild(tr)
	
	// create elements for the second row
	tr = document.createElement("tr")
	
	text = document.createTextNode("Title: ")
	td = document.createElement("td")
	td.appendChild(text)
	tr.appendChild(td)
	table.appendChild(tr)
	
	input = document.createElement("input")
	input.setAttribute("type", "text")
	input.setAttribute("name", "title[]")
	input.setAttribute("size", "22")
	input.setAttribute("style", "margin-bottom:4px;")
	
	td = document.createElement("td")
	td.appendChild(input)
	tr.appendChild(td)
	table.appendChild(tr)
	
	// create elements for the third row
	tr = document.createElement("tr")
	
	text = document.createTextNode("Description: ")
	td = document.createElement("td")
	td.appendChild(text)
	tr.appendChild(td)
	table.appendChild(tr)
	
	input = document.createElement("input")
	input.setAttribute("type", "text")
	input.setAttribute("name", "desc[]")
	input.setAttribute("size", "22")
	input.setAttribute("style", "margin-bottom:4px;")
	
	td = document.createElement("td")
	td.appendChild(input)
	tr.appendChild(td)
	table.appendChild(tr)
}

