try { 
$('document').ready(function ready() {
    $('#widthTest').val($('#container').width());
    $('#togLeft').click(function togLeftClick() { 
         if($(this).text() == "+ Left") { $(this).text("- Left"); } else { $(this).text("+ Left"); }
         $('#leftContent').toggle('slow'); 
    }); 
    $('#togCenter').click(function togCenterClick() {
		var plus = "<img id='plusCenter' style='float: right;' class='collapse' src='../images/plus.gif'>";
		var minus = "<img id='minusCenter' style='float: right;' class='collapse' src='../images/minus.gif'>";
		if($("#plusCenter")) { 
			$("#plusCenter").detach();
			plus.appendTo("#togCenter"); 
		} else { 
			$("#minusCenter").detach(); 
			minus.appendTo("#togCenter"); 
		}
		$('#centerContent').toggle('slow'); 
    }); 
    $('#togRight').click(function togRightClick() { 
        if($(this).text() == "+ Right") { $(this).text("- Right"); } else { $(this).text("+ Right"); }
        $('#rightContent').toggle(function() {
            $('#rightContent').css('border-radius:', '1em 1em 1em 1em');
        },
        function() {
            $('#rightContent').css('border-radius:', '4em 1em 1em 1em');
        });
        $('#rightContent').toggle('slow'); 
    }); 
    $('#showNotes').click(function showNotesClick() { 
        $(this).hide(); 
        $('#showNotes1').show(); 
        $('#sNotes').toggle('slow'); 
    }); 
    $('#showNotes1').click(function showNotes1Click() { 
        $(this).hide(); 
        $('#showNotes').show(); 
        $('#sNotes').toggle('slow'); 
    });
    $('#showQLinks').click(function showQLinksClick() {
        $(this).hide();
        $('#showQLinks1').show(); 
        $('#qLinks').toggle('slow'); 
    });
    $('#showQLinks1').click(function showQLinks1Click() {
        $(this).hide();
        $('#showQLinks').show(); 
        $('#qLinks').toggle('slow');     
    });
    $('#curWidth').append($('#container').width()); 
    $('#widthTest').keypress(function widthKeyPress(event) {
        if(event.which == '13') { 
            var newW = $(this).val();
            $('#container').width(newW+'px'); 
            $('#curWidth').text('Container W:'+$('#container').width());
        }
    });
    $('#emlForm').click(function emlForm() {
        $(this).toggle();
        $('#emlForm1').toggle(); 
        var newDiv = '<div id="CurveoEmailLoginForm" style="display: block;"><form method="post" action="http://mail.curveo.net/src/redirect.php" target=""><table width="95%" cellpadding="1" cellspacing="1" align="left" border="1"><tr><td><b><font class="linkdecor">Email</font></b></td><td><input type="text" size="6" name="login_username" value=""></td></tr><tr><td><b><font class="linkdecor">Pass</font></b></td><td><input type="password" size="6" name="secretkey" value=""></td></tr><tr><td colspan=2 align="center"><input type="submit" value="Go"><input type="reset" value="Clear"></td></tr><tr></table></form></div>';
        $('#emailLoginDiv').append(newDiv); 
        $('#emailLoginDiv').slideDown("slow"); 
    }); 
    $('#emlForm1').click(function emlForm1() {
        $(this).toggle();
        $('#emlForm').toggle(); 
        $('#emailLoginDiv').slideUp(); 
        $('#emailLoginDiv').empty(); 
    }); 
});
function todoHL(obj,color) { 
	var tmp = $(obj).parent();
	$(tmp).children().css("background-color",color);
}
function mouseOver(me) {
	me.style.color='#003366';
	me.style.textDecoration='underline';
}
function mouseOut(me) {
	me.style.color='#000000';
	me.style.textDecoration='none';
}
function showHideEmailPost(obj,dLink) { 
	$('#smokeglass').toggle();
	$(obj).toggle();
	if ($(obj).css("display") == "none")
	{
		location.replace("#downLink"+dLink);
	}	
}
function showHideGeneric(obj) {
	if (obj.style.display=="none") {
		obj.style.display = "block";
		}  else if (obj.style.display=="block"){		
		obj.style.display = "none";
		} 		
}

//original below
function swapVisibility(obj) {
    var element = document.getElementById(obj);
    if (element.style.display=="none") {
        element.style.display="block";
    } else { element.style.display="none";  } 
}

function swapVisible(hideId,showId) {
    var hideElement = document.getElementById(hideId); 
    var showElement = document.getElementById(showId); 

try {
   if (hideElement.style.display!="none" && showElement.style.display=="none") {
        hideElement.style.display="none"; 
        showElement.style.display="block";
    } else { 
        hideElement.style.display="block"; 
        showElement.style.display="none";
    }
 } catch (e) { alert("caught an error: "+e); }
}

function todoDo(me,meDiv) {
	var theDiv = document.getElementById(meDiv);
	if (me.checked) {
		theDiv.style.textDecoration="line-through";
	} else {
		theDiv.style.textDecoration="";
	}
}
function updateToDoFirst(me) {
	var me1 = me;
	window.setTimeout(submitFormToPopup(me),0); 
}
function genericShowHide(noteID) {
var noteID1 = document.getElementById(noteID);
	if (noteID1.style.display== "none" || noteID1.display=="") {
		noteID1.style.display="block";
	} else {
		noteID1.style.display="none";
	}
}
//
var tempGlobalArray = new Array(); 

//LIVE Update stickys
function updateStickys(sDiv,sSpan,stickID) { 
    var curSticky = document.getElementById(sDiv);
    var curSpan = document.getElementById(sSpan); 
    var subject = curSticky.childNodes[0].innerHTML; 
    var body = document.createTextNode(curSpan.innerHTML);  
   
    //Save copy of sticky
    var saveOldSticky = curSticky.cloneNode(true); 
    tempGlobalArray[curSticky.id] = curSticky.cloneNode(true); 
   
   //create form to edit data 
    var newDiv = document.createElement("div"); newDiv.setAttribute("style","overflow: visible;"); newDiv.setAttribute("class","stickyNotes"); newDiv.setAttribute("id",curSticky.id); 
    var newInput = document.createElement("input"); newInput.setAttribute("size","10"); newInput.setAttribute("value",subject); newInput.setAttribute("name","subject"); 
    var newTxtA = document.createElement("textarea"); newTxtA.setAttribute("cols","35"); newTxtA.setAttribute("rows","5");newTxtA.setAttribute("name","details");
        newTxtA.appendChild(body); 
	var newStickID = document.createElement("input"); newStickID.setAttribute("type","hidden");newStickID.setAttribute("name","theStickiesIDN");newStickID.setAttribute("value",stickID);
	var newFuncCall = document.createElement("input");newFuncCall.setAttribute("type","hidden");newFuncCall.setAttribute("name","editStickies2");newFuncCall.setAttribute("value","TRUE");
	var newGo = document.createElement("input"); newGo.setAttribute("type","Submit"); newGo.setAttribute("value","Go"); 
    var newCancel = document.createElement("input"); newCancel.setAttribute("type","Reset"); newCancel.setAttribute("value","Cancel"); newCancel.setAttribute("onclick","cancelStickyUpdate('"+curSticky.id+"');");  

	var newForm = document.createElement("form");newForm.setAttribute("style","margin: 0; padding: 0;");newForm.setAttribute("action"," ");newForm.setAttribute("method","get");
	newForm.setAttribute("id","stickEditForm"+curSticky.id); newForm.setAttribute("onSubmit","submitFormToPopup('stickEditForm"+curSticky.id+"');");
    newForm.appendChild(newInput); newForm.appendChild(newTxtA); newForm.appendChild(newGo); newForm.appendChild(newCancel);newForm.appendChild(newStickID);newForm.appendChild(newFuncCall);
	newDiv.appendChild(newForm); 
    
    //replace sticky with new div form
    $(curSticky).replaceWith(newDiv); 
}

//Cancel stiky update 
function cancelStickyUpdate(divID) { 
   $("#"+divID+"").replaceWith(tempGlobalArray[divID]); 
} 

//remove and replace nodes for live editing
function removeReplaceNodes(td1,td2,toDoId) {
	var currentTD1 = document.getElementById(td1);
	var currentTD2 = document.getElementById(td2);
	var selectGroup = document.getElementById("dateSelectGroup");
	var theForm = currentTD1.firstChild;
		var theFormID = theForm.id;
	
//*******Save copies of current elements********
	//save copy of first TD (form,date,span)
	var saveOldtd1 = currentTD1.cloneNode(true);
		tempGlobalArray['previousTD1'+td1] = saveOldtd1;
		//window['previousTD1'+td1] = saveOldtd1;
	//save copy of second TD (check box span)
	var saveOldtd2 = currentTD2.cloneNode(true);
        tempGlobalArray['previousTD2'+td2] = saveOldtd2;
		//window['previousTD2'+td2] = saveOldtd2;
	//save copy of form 
	var saveOldForm = theForm.cloneNode(false);
		tempGlobalArray['previousForm'+theFormID] = saveOldForm; 
	    //window.previousForm = saveOldForm;		
	//Clone of copy of date select
		newSelectGroup = selectGroup.cloneNode(true);
//*******end save********

	var newForm = document.createElement("form");newForm.setAttribute("style","margin: 0; padding: 0;");newForm.setAttribute("action"," ");newForm.setAttribute("method","get");newForm.setAttribute("id",""+theFormID+"");newForm.setAttribute("onSubmit","submitFormToPopup(\'"+theFormID+"\');"); 
	var newInputHiddenPst = document.createElement("input"); newInputHiddenPst.setAttribute("name", "postPoneToDo"); 	newInputHiddenPst.setAttribute("type", "hidden"); newInputHiddenPst.setAttribute("value", "true");
	var newInputHiddenID = document.createElement("input");	newInputHiddenID.setAttribute("name", "toDoID"); newInputHiddenID.setAttribute("type", "hidden"); newInputHiddenID.setAttribute("value", ""+toDoId+"");
		newForm.appendChild(newSelectGroup);
		newForm.appendChild(newInputHiddenPst);
		newForm.appendChild(newInputHiddenID);
	var newInputGo = document.createElement("input"); newInputGo.setAttribute("type","Submit");	newInputGo.setAttribute("value","Go");	newInputGo.setAttribute("onclick", "setTimeout(\'location.reload()\',1800); updateToDoFirst('"+theFormID+"');");
	var newInputCancel = document.createElement("input"); newInputCancel.setAttribute("type","Submit"); newInputCancel.setAttribute("value","Cancel"); newInputCancel.setAttribute("onclick", "cancelPostPone('"+td1+"', '"+td2+"', '"+theFormID+"');"); 
	var newImagesSpace = document.createElement("img"); newImagesSpace.setAttribute("src","../images/spacer5.gif"); newImagesSpace.setAttribute("valign","center"); newImagesSpace.setAttribute("border","0"); 
	var newTD = document.createElement("td"); newTD.setAttribute("colspan","3");
		
//Remove child nodes 
	with (currentTD2) {
		for (var i=0; i<=childNodes.length; i++) {
			removeChild(firstChild);
			}
		}
	with (currentTD1) {
		for (var i=0; i<=childNodes.length; i++) { 
			removeChild(firstChild);
			}
		}

//Add elements to document	
    currentTD1.appendChild(newForm);
	currentTD2.appendChild(newInputGo);
	currentTD2.appendChild(newImagesSpace); 
	currentTD2.appendChild(newInputCancel);
}
function removeReplaceNodesNew(span1,span2,toDoId) {
	var currentSpan1 = document.getElementById(span1);
	var currentSpan2 = document.getElementById(span2);
	var selectGroup = document.getElementById("dateSelectGroup");
	var theForm = currentSpan2.firstChild;
		var theFormID = theForm.id;
	
//*******Save copies of current elements********
	//save copy of first TD (form,date,span)
	var saveOldtd1 = currentSpan1.cloneNode(true);
		tempGlobalArray['previousSpan1'+span1] = saveOldtd1;
	//save copy of second TD (check box span)	   
	var saveOldtd2 = currentSpan2.cloneNode(true);
        tempGlobalArray['previousSpan2'+span2] = saveOldtd2;
	//save copy of form 
	var saveOldForm = theForm.cloneNode(false);
		tempGlobalArray['previousForm'+theFormID] = saveOldForm; 
	//Clone of copy of date select
		newSelectGroup = selectGroup.cloneNode(true);
//*******end save********
	var newSpan1 = document.createElement("span"); newSpan1.setAttribute("class","eventBoxSpanDate"); newSpan1.setAttribute("id",span1);
	var newSpan2 = document.createElement("span"); newSpan2.setAttribute("class","eventBoxSpanCheck"); newSpan2.setAttribute("id",span2);
	var newForm = document.createElement("form");newForm.setAttribute("style","margin: 0; padding: 0;");newForm.setAttribute("action"," ");newForm.setAttribute("method","get");newForm.setAttribute("id",""+theFormID+"");newForm.setAttribute("onSubmit","submitFormToPopup(\'"+theFormID+"\');"); 
	var newInputHiddenPst = document.createElement("input"); newInputHiddenPst.setAttribute("name", "postPoneToDo"); 	newInputHiddenPst.setAttribute("type", "hidden"); newInputHiddenPst.setAttribute("value", "true");
	var newInputHiddenID = document.createElement("input");	newInputHiddenID.setAttribute("name", "toDoID"); newInputHiddenID.setAttribute("type", "hidden"); newInputHiddenID.setAttribute("value", ""+toDoId+"");
		newForm.appendChild(newSelectGroup);
		newForm.appendChild(newInputHiddenPst);
		newForm.appendChild(newInputHiddenID);
	var newInputGo = document.createElement("input"); newInputGo.setAttribute("type","Submit");	newInputGo.setAttribute("value","Go");	newInputGo.setAttribute("onclick", "setTimeout(\'location.reload()\',1800); updateToDoFirst('"+theFormID+"');");newInputGo.setAttribute("style","width:55%;"); 
	var newInputCancel = document.createElement("input"); newInputCancel.setAttribute("type","Submit"); newInputCancel.setAttribute("value","X"); newInputCancel.setAttribute("onclick", "cancelPostPone('"+newSpan1.id+"', '"+newSpan2.id+"', '"+theFormID+"');");newInputCancel.setAttribute("style","float:right;"); 
	var newImagesSpace = document.createElement("img"); newImagesSpace.setAttribute("src","../images/spacer5.gif"); newImagesSpace.setAttribute("valign","center"); newImagesSpace.setAttribute("border","0"); 
		
//Replace span nodes 
	$(currentSpan1).replaceWith(newSpan1); 
	$(currentSpan2).replaceWith(newSpan2); 
//Add elements to document
  	newSpan1.appendChild(newForm);
	newSpan2.appendChild(newInputGo);
	//newSpan2.appendChild(newImagesSpace); 
	newSpan2.appendChild(newInputCancel);
//Resize the spans in the row
    $(newSpan1).prev().css("width","40%"); 
    $(newSpan1).css("width","40%"); 
    $(newSpan1).next().css("width","15%"); 
}

//Restore to previous nodes
function cancelPostPone(span1,span2,formID) {
	//alert("entering cancelPostPone"); 
	var currentSpan1 = document.getElementById(span1);
	var currentSpan2 = document.getElementById(span2);
	//var tdParents = currentSpan1.parentNode;
	var orgSpan1 = tempGlobalArray['previousSpan1'+span1]; delete tempGlobalArray['previousSpan1'+span1];
	var orgSpan2 = tempGlobalArray['previousSpan2'+span2]; delete tempGlobalArray['previousSpan2'+span2];

	var orgForm = tempGlobalArray['previousForm'+formID]; delete tempGlobalArray['previousForm'+formID];
    //Replace nodes with old nodes	
    //tdParents.replaceChild(orgTD1, tdParents.lastChild.previousSibling); 
    //tdParents.replaceChild(orgTD2, tdParents.lastChild);
//fix widths 
    $(currentSpan1).next().css("width","5%"); 
    $(currentSpan1).css("width","18%");    
    $(currentSpan1).prev().css("width","72%"); 
    
	$(currentSpan1).replaceWith(orgSpan1); 
	$(currentSpan2).replaceWith(orgSpan2); 

}

function editNotesClick(noteSpan,taskID) {
  var noteSpanRef = document.getElementById(noteSpan);
//Save a copy of the object being replaced. 
  tempGlobalArray['oldTaskNote'+noteSpan] = noteSpanRef.cloneNode(true); 
  var strInputCode = noteSpanRef.innerHTML;
  var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, ""); //Strips any html from textarea
  var objRefText = strTagStrippedText; 	
  var newForm = document.createElement("form"); newForm.setAttribute("style","margin: 0; padding: 0; width: 305px;"); newForm.setAttribute("action",""); newForm.setAttribute("method","post"); newForm.setAttribute("id","editNotesNewForm"); newForm.setAttribute("onSubmit","submitFormToPopup(\'editNotesNewForm\'); window.focus();"); 
  var newNode = document.createElement("textarea"); newNode.setAttribute("cols","35"); newNode.setAttribute("rows","5");newNode.setAttribute("name","noteDate");
  var newTextAreaContents = document.createTextNode(objRefText); 
	  newNode.appendChild(newTextAreaContents); 
  var newGo = document.createElement("input"); newGo.setAttribute("type","submit"); newGo.setAttribute("value","Go"); newGo.setAttribute("onclick","window.focus();");
  var newInputH = document.createElement("input"); newInputH.setAttribute("name","toDoID"); newInputH.setAttribute("value",""+taskID+""); newInputH.setAttribute("type","hidden");
  var newInputH1 = document.createElement("input"); newInputH1.setAttribute("name","addNoteTask"); newInputH1.setAttribute("value","true"); newInputH1.setAttribute("type","hidden"); 
  var newInputCancel = document.createElement("input"); newInputCancel.setAttribute("type","Reset"); newInputCancel.setAttribute("value","Cancel"); newInputCancel.setAttribute("onclick","removeAllReplaceOrgNodes(\""+noteSpan+"\",\""+'oldTaskNote'+noteSpan+"\");");
	//build table for buttons
  var newTable = document.createElement("table");
      newTable.setAttribute("width","25%");
  var newTableTR = document.createElement("tr");
  var newTableTRTDLeft = document.createElement("td");newTableTRTDLeft.setAttribute("align","left");newTableTRTDLeft.appendChild(newGo);
  var newTableTRTDRight = document.createElement("td");newTableTRTDRight.setAttribute("align","right"); newTableTRTDRight.appendChild(newInputCancel);
	  newTableTR.appendChild(newTableTRTDLeft); 
	  newTableTR.appendChild(newTableTRTDRight); 
  	  newTable.appendChild(newTableTR); 
  	  newForm.appendChild(newNode); 		
      newForm.appendChild(newInputH);
      newForm.appendChild(newInputH1);
	  newForm.appendChild(newTable);

   //Remove child nodes 
    $("#"+noteSpan).empty(); 
   noteSpanRef.appendChild(newForm);
   noteSpanRef.setAttribute("onclick","");
}
//Removes new nodes and replaces with OLD node(deep copy)
function removeAllReplaceOrgNodes(objs, oldObj) {
    //var renewed = window[oldObj];
	var renewed = tempGlobalArray[oldObj];  
	var objRefs = document.getElementById(objs);
        for (var i=0; i <= objRefs.childNodes.length;i++) {            
            objRefs.removeChild(objRefs.childNodes[0]);            
        }
    objRefs.parentNode.replaceChild(renewed, objRefs.parentNode.lastChild);
	delete tempGlobalArray[oldObj];
}
//construct url to submit to popup window
function submitFormToPopup(form) { 
    var newWin = window.open("","TestWindow","width=700,height=200"); //window.blur();
    var theForm = document.getElementById(form);
    var adhocForm = document.createElement("div");
	var adhocFormIE = document.createElement("div"); 
	
    newWin.document.write('<html><head><title>Popup</title>');
    newWin.document.write('</head><body onload="document.getElementById(\'formSubmit\').submit();">');
	//newWin.document.write('</head><body>'); 
	newWin.document.write('<form action="AccountEditConf.php" id="formSubmit" method="GET" style="display: none;">');
			
	 	for (var i=0;i<theForm.length;i++) {
	 	    if (theForm.elements[i].type == "textarea") { 
	 	        var newElement = document.createElement("textarea");
	 	        newElement.setAttribute("rows","5");
	 	        newElement.setAttribute("cols","35");
				newElement.setAttribute("name",theForm.elements[i].name); 
	 	        var newTextAreaContents = document.createTextNode(theForm.elements[i].value); 
                    newElement.appendChild(newTextAreaContents); 
	 	    } else { var newElement = document.createElement("input");  
				newElement.setAttribute("type","text");
				newElement.setAttribute("name",theForm.elements[i].name); 
				newElement.setAttribute("value",theForm.elements[i].value);
			}
			adhocForm.appendChild(newElement);
		}
		var ad = adhocForm.innerHTML; 
		newWin.document.write(ad)

    newWin.document.write('</form>');
	newWin.document.write('</body></html>');
	newWin.document.close();
	window.blur();
	setTimeout("window.reload()",1600);
    return true; 
 }
 /*Proposed new OO re-write of popup window
 var FormToPopup = { 
	newWindow: window.open("","TestWindow","width=700,height=200"),
	theForm: document.getElementById(form),
	adHocForm: document.createElement("div"),
	buildVars: function() { 
	 	for (var i=0;i<theForm.length;i++) {
	 	    if (theForm.elements[i].type == "textarea") { 
	 	        var newElement = document.createElement("textarea");
	 	        newElement.setAttribute("rows","5");
	 	        newElement.setAttribute("cols","35");
	 	        var newTextAreaContents = document.createTextNode(theForm.elements[i].value); 
                    newElement.appendChild(newTextAreaContents); 
	 	    } else { var newElement = document.createElement("input");  
				newElement.setAttribute("type","text");
				newElement.setAttribute("name",theForm.elements[i].name); 
				newElement.setAttribute("value",theForm.elements[i].value);
			}
			adhocForm.appendChild(newElement);
		}	 
	},
	ad: FormToPopup.adhocForm.innerHTML,
	writeDoc: function() { 
		newWin.document.write('<html><head><title>Popup</title>');
		newWin.document.write('</head><body onload="document.getElementById(\'formSubmit\').submit();">');
		//newWin.document.write('</head><body>'); 
		newWin.document.write('<form action="AccountEditConf.php" id="formSubmit" method="POST" style="display: none;">');		
		newWin.document.write(ad)
		newWin.document.write('</form>');
		newWin.document.write('</body></html>');
		newWin.document.close();
		window.blur();
		setTimeout("window.reload()",1600);
	},	
} */

//Submit link to a popup window 
function submitLinkToPopup(link) {
    window.open(link,"Confirmation Popup","width=700,height=200,modul");
	window.blur();
    setTimeout("location.reload()",1800); 
 }
} catch (e) { alert("Error in utils.js: "+e); }
