// Unobtrusive Onload
function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		};
	}
};

function set_border(status){

	var frame_border = document.getElementById("content_border");

	if (status == 1){
		frame_border.style.border = "1px solid #DCDCDC";
	} else {
		frame_border.style.border = "0px solid #DCDCDC";
	}
};


// For swapping rollover image objects
function swapImage(imgDocID, imgObjName){
	if(!document.images){
		return;
	}else{
		document.images[imgDocID].src = eval(imgObjName + ".src");
	}
};

// Return an item's ID value
function getId(id){
  return document.getElementById(id);
};

// swaps the content of one block with the content of another
function swapDivContent(putThisItem, intoThisItem){ 
	var y,z;
	z = getId(putThisItem);
	y = getId(intoThisItem);
	y.innerHTML = z.innerHTML;
};

function prepareCM(){
	if(!document.getElementById("details_form")){return;} 

	var form = 	document.getElementById('details_form');	
	var showForm = location.search.replace(/\?menu_id=([0-9]+)&o=/,'');
	(showForm == 'y' ? form.style.display = 'block' : form.style.display = 'none');

	if(showForm != 'y'){
			var toggler = document.getElementById('add_details');
			var parent = document.getElementById('add_container');

			var link = document.createElement('a');
			link.href = '';
			link.id = 'add_details';
			link.innerHTML = 'Add your details here';
			link.onclick = function(){
				return toggleCM(form);
			};
			
			parent.replaceChild(link,toggler);
	}
	
};

function toggleCM(target){
	(target.style.display == 'none' ? target.style.display = 'block' : target.style.display = 'none');
	return false;
};

// Onload, prepare the highlighting effects
addLoadEvent(prepareCM);