<!-- 

var colourNum = 0;
var logoWin;
function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object 
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to 
      // build the message. Message includes i (the object's property name) 
      // then the object's property value on a new line 
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they 
      // click "CANCEL" then quit this level of recursion 
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object 
      if (typeof obj[i] == "object") { 
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getDate()
{
    var m = new Array(
                     "January",
                     "February",
                     "March",
                     "April",
                     "May",
                     "June",
                     "July",
                     "August",
                     "September",
                     "October",
                     "November",
                     "December"
                     );
    
    today = new Date();
    day = today.getDate();
    year = today.getYear();
    
    if (year < 2000)    // Y2K Fix, Isaac Powell
        year = year + 1900; // http://onyx.idbsu.edu/~ipowell
     end = "th";
    if (day==1 || day==21 || day==31) end="st";
    if (day==2 || day==22) end="nd";
    if (day==3 || day==23) end="rd";
    day+=end;
    
    window.document.write(m[today.getMonth()]+" ");
    window.document.write(day+", " + year);
}

function getIFrameDocument(aID){
  // if contentDocument exists, W3C compliant (Mozilla)
  if(document.getElementById(aID) != null)
  {
   if (document.getElementById(aID).contentDocument){
     return document.getElementById(aID).contentDocument;
   } else {
    // IE
     return document.frames[aID].document;
   }
  }
  return false;
}

function getIFrame(aID) {
	return document.getElementById(aID);
}

function settingColour(tmpColourNum)
{
	colourNum = tmpColourNum;
}

function setColour(theColour)
{
	
	var formTxt = "";

	//determine which colour we are updating.
	//update the current display
	//then add a hidden field to the hidden iframe for the colour updated.
	switch(colourNum)
	{
	case 0:
		document.getElementById("leftPane").bgColor = theColour;
		formTxt += '<input type="hidden" name="leftColour" value="'+theColour+'">';
		break;
	case 1:
		document.getElementById("topPane").bgColor = theColour;
		formTxt += '<input type="hidden" name="topColour" value="'+theColour+'">';
		alterEditorColour(theColour);
		break;
	case 2:
		document.getElementById("rightPane").bgColor = theColour;
		formTxt += '<input type="hidden" name="rightColour" value="'+theColour+'">';
		break;
	case 3:
		document.getElementById("middlePane").bgColor = theColour;
		formTxt += '<input type="hidden" name="middleColour" value="'+theColour+'">';
		break;
	default:
		alert("there was no colour to change.");
		return;
	}

	//create the form header in the hidden iframe
	formTxt = '<form name="colourUpdater" action="../index.php">' + formTxt;
	formTxt += '<input type="hidden" name="fuseaction" value="updateStyle">';
	formTxt += '<input type="hidden" name="noindex" value="true">';
    
	//set the invisible IFrame source to be the form
	getIFrameDocument("invisibleIframe").body.innerHTML = formTxt;

	//submit the form in the hidden iframe to make the change live
	if (getIFrameDocument("invisibleIframe").forms[0].name == "colourUpdater")
	{
		getIFrameDocument("invisibleIframe").forms[0].submit();
	}
}

function setHorizontalBg(URL)
{
	var formTxt = "";

	//alert(URL);
	document.getElementById("navHoriz").background = "http://www.admin.weblite.com.au/images/" + URL;
	formTxt += '<form name="horizontalBgUpdater" action="../index.php">';
	formTxt += '<input type="hidden" name="horizontalBg" value="' + URL + '">';
	formTxt += '<input type="hidden" name="fuseaction" value="updateStyle">';
	formTxt += '<input type="hidden" name="noindex" value="true">';
	formTxt += '</form>';
	//alert(formTxt);

	//set the invisible IFrame source to be the form
	getIFrameDocument("invisibleIframe").body.innerHTML = formTxt;

	//alert(getIFrameDocument("invisibleIframe").forms[0].name);

	//submit the form in the hidden iframe to make the change live
	if (getIFrameDocument("invisibleIframe").forms[0].name == "horizontalBgUpdater")
	{
		//alert('Submitting...');
		getIFrameDocument("invisibleIframe").forms[0].submit();
	}
}

function deleteFromDOM(elementID)
{
	var table = document.getElementById(elementID);
	var tBody = table.getElementsByTagName("tbody")[0];
	var rows = tBody.getElementsByTagName("tr");  
	var row = rows[0];
 
	while (rows.length() > 0)
	{
		tBody.removeChild(row);
	}
}

//
function removeMenu(pageId)
{
	var formTxt = "";
	formTxt = '<form name="navUpdater" action="../index.php">' + formTxt;
	formTxt += '<input type="hidden" name="fuseaction" value="delPage">';
	formTxt += '<input type="hidden" name="noindex" value="true">';
	formTxt += '<input type="hidden" name="pageId" value="'+pageId+'">';
	formTxt += '</form>';
	/*if(getIFrameDocument('invisibleIframe') == false)
	{
//			var link = document.createElement('a');
//			link.setAttribute('href', 'mypage.htm');
			var ilink = document.createElement('iframe');
			ilink.setAttribute('id', 'invisibleIframe');
			document.appendChild(ilink);
		//	ilink.location.href = 'blank.html';
		//	var ihtml = ilink.document.createElement('html'); 
			var ibody = ilink.document.createElement('body');
			//ibody.appendChild(ibody);
			ilink.document.appendChild(ibody);
			//ilink.document.body.innerHTML = formTxt;
			
			
	}*/

	getIFrameDocument("invisibleIframe").body.innerHTML = formTxt;

	//Hide("nav"+pageId);
		
	if (getIFrameDocument("invisibleIframe").forms[0].name == "navUpdater")
	{
		//alert("deleting this nav item nav"+pageId);
		getIFrameDocument("invisibleIframe").forms[0].submit();
	}

	
}

function moveMenuDown(pageId)
{
	var elem = document.getElementById("nav"+pageId);
	var parentN = elem.parentNode;
	var siblingN = elem.nextSibling;
	var pageid2 = "";

		if (!document.all)
		{
			siblingN = siblingN.nextSibling;
			/**************************************						
			alert(parentN);
			alert("elem id "+elem.id);
			alert("parent id "+parentN.id);
			alert("sibling id1 "+siblingN.id);
			var siblingN = siblingN.nextSibling;
			alert("sibling id2 "+siblingN.id);
			var siblingN = siblingN.nextSibling;
			alert("sibling id3 "+siblingN.id);
			var siblingN = siblingN.nextSibling;
			**************************************/
		}	


	//var pageid2 = siblingN.id.substring(3);	 //remove the "nav"

	//27102004added id length to ensure that the last item is not the add a page bit.
	if (siblingN != null && siblingN.id != null)
	{
		pageid2 += siblingN.id;
		pageid2 = pageid2.substring(3);

		var formTxt = "";
		formTxt = '<html><body><form id="navUpdaterForm" name="navUpdater" action="../index.php" method="post">' + formTxt;
		formTxt += '<input type="hidden" name="fuseaction" value="swapOrder">';
		formTxt += '<input type="hidden" name="noindex" value="true">';
		formTxt += '<input type="hidden" name="pageId1" value="'+pageId+'">';
		formTxt += '<input type="hidden" name="pageId2" value="'+pageid2+'">';
		formTxt += '<input type="hidden" name="direction" value="down">';
		formTxt += '<input type="hidden" name="object" value="Page">';
		formTxt += '<input type="hidden" name="id" value="'+pageId+'">';
		formTxt += '</form></body></html>';

		//another case of the mozilla docs being wrong
		//getIFrameDocument("invisibleIframe").user_pref("capability.policy.trustable.sites", "http://www.admin.weblite.com.au");
		//getIFrameDocument("invisibleIframe").user_pref("capability.policy.trustable.sites", "http://www.admin.weblite.knowit.com.au");		
		if(getIFrameDocument('invisibleIframe') == false)
		{
//			var link = document.createElement('a');
//			link.setAttribute('href', 'mypage.htm');
			var ilink = document.createElement('iframe');
			ilink.setAttribute('id', 'invisibleIframe');
			var ihtml = ilink.document.createElement('html'); 
			var ibody = ilink.document.createElement('body');
			//ibody.appendChild(ibody);
			ilink.document.appendChild(ibody);
			document.appendChild(ilink);
			
		}

		getIFrameDocument("invisibleIframe").body.innerHTML = formTxt;

		if (getIFrameDocument("invisibleIframe").getElementById("navUpdaterForm") != null)
		{
			parentN.insertBefore(siblingN, elem);	
			if (!document.all)
			{
				//formTxt += "<script language='javascript'>";
				//formTxt += "function submitFormGodDamnit() {";
				//formTxt += "getElementById('navUpdaterForm').submit();";
				//formTxt += "}";
				//formTxt +=/script>';
				//getIFrameDocument("invisibleIframe").body.innerHTML = formTxt;

				//document.getElementById("invisibleIframe").submitFormGodDamnit();
				var f = getIFrameDocument("invisibleIframe").getElementById("navUpdaterForm");
				//var f = getIFrameDocument("invisibleIframe").forms["navUpdater"];
				//alert(f);

				f.target = 'invisibleIframe';
				alert("submitting navUpdaterForm");
				//getIFrameDocument("invisibleIframe").body.innerHTML = formTxt + "<script language='javascript'>var f = document.getElementById('navUpdaterForm'); f.submit();/script>";				
				alert(f.action);
				f.submit();
				alert("submited navUpdaterForm");
			} 
			else
			{
				getIFrameDocument("invisibleIframe").getElementById("navUpdaterForm").submit();
			}
		} 
	}

	
}

function moveMenuUp(pageId)
{
	var elem = document.getElementById("nav"+pageId);
	var parentN = elem.parentNode;
	var siblingP = elem.previousSibling;
	var pageid2 = "";

	//added on 16/12/04 for mozilla compatibility - however HTMLFormElement.submit() is still not working
	//with Mozilla. must do some research into this.
	if (!document.all)
		siblingP = siblingP.previousSibling;

	if (siblingP != null && siblingP.id != null)
	{
		pageid2 += siblingP.id;
		//alert(siblingP);
		pageid2 = pageid2.substring(3);    //remove the "nav"

		var formTxt = "";
		formTxt = '<form id="navUpdaterForm" name="navUpdater" action="../index.php">' + formTxt;
		formTxt += '<input type="hidden" name="fuseaction" value="swapOrder">';
		formTxt += '<input type="hidden" name="noindex" value="true">';
		formTxt += '<input type="hidden" name="pageId1" value="'+pageId+'">';
		formTxt += '<input type="hidden" name="pageId2" value="'+pageid2+'">';
		formTxt += '<input type="hidden" name="direction" value="up">';
                formTxt += '<input type="hidden" name="object" value="Page">';
                formTxt += '<input type="hidden" name="id" value="'+pageId+'">';


		if(getIFrameDocument('invisibleIframe') == false)
		{
//			var link = document.createElement('a');
//			link.setAttribute('href', 'mypage.htm');
			var ilink = document.createElement('iframe');
			ilink.setAttribute('id', 'invisibleIframe');
			var ihtml = ilink.document.createElement('html'); 
			var ibody = ilink.document.createElement('body');
			//ibody.appendChild(ibody);
			ilink.document.appendChild(ibody);
			document.appendChild(ilink);
			
		}
		getIFrameDocument("invisibleIframe").body.innerHTML = formTxt;
		

		if (getIFrameDocument("invisibleIframe").getElementById("navUpdaterForm") != null)
		{
			parentN.insertBefore(elem, siblingP);	
			getIFrameDocument("invisibleIframe").getElementById("navUpdaterForm").submit();
		} 
	}

}

/********************************
* this function is designed to update the logo on both the front & back end
* it does this by popping up a window for the change logo button
* and asking for the new logo
* the new logo is then uploaded & passed to the "setLogo" function defined below
********************************/

function changeLogo()
{
   logoWin = popUp("setLogo.php");
}

/********************************
* This function updates the DOM
* to reflect the new logo that has
* been uploaded.
* 
* 
********************************/
function setLogo(logo)
{
	if (document.getElementById("logoImg") && document.getElementById("logoImg").src)
	{
		if (logo != "")
		{
			document.getElementById("logoImg").src = logo;
			//document.getElementById("logoImg").style = "";
			Show("logoImg");
		}
		else 
		{
			//alert ("hiding logoImg");
			//document.getElementById("logoImg").visibility = "hidden";
			Hide("logoImg");
		}
	}	
	
	if (logoWin.document.forms.length > 0)
	{
		logo = logo.replace(/\\/g, '\\\\');
		setTimeout('setLogo(\''+logo+'\')', 200);
	}
	else
	{
		if (document.getElementById("logoImg").height > 80)
		{
			var newHeight = 80;
			var oldHeight = document.getElementById("logoImg").height;
			var oldWidth  = document.getElementById("logoImg").width;
			document.getElementById("logoImg").height = parseInt(newHeight);
			if (document.getElementById("logoImg").width == oldWidth)
			{
				var newWidth = (newHeight * document.getElementById("logoImg").width) / oldHeight;
				document.getElementById("logoImg").width = parseInt(newWidth);
			}
		}
		
		logoWin.close();
	}

}

function popUp(URL) {
  day = new Date();
  id = day.getTime();
  var width = 490;
  var height = 270;

  if (URL.indexOf("color") >= 0)
  {
	width = 192;
	height = 203;
  }

  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+"');");
  id.parent = window;
  return eval("page"+id);
}

function horiChooser(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=205,height=198');");
  id.parent = window;
  return eval("page"+id);
}

function alterEditorButtons()
{

    if (getIFrameDocument("editorIframe") && getIFrameDocument("editorIframe").getElementById("buttonTable"))
	{
		var btnTable = getIFrameDocument("editorIframe").getElementById("buttonTable");

		while (btnTable.nodeName != 'TABLE')
		{
			btnTable = btnTable.parentNode;
		}
		btnTable.bgColor = '';

		var subelem = btnTable;

		while (subelem.nodeName != "TD" && subelem.hasChildNodes())
		{
			subelem = subelem.firstChild;
			
		}
		
		if (subelem.nodeName == "TD")
		{
			subelem = subelem.parentNode;
			while (subelem.firstChild != subelem.lastChild)
			{
				subelem.removeChild(subelem.firstChild);
			}
			subelem = subelem.firstChild;
			subelem.innerHTML = '<input type="image" src="../images/saveChanges.gif" name="next" onClick="nextButton()" value="Save Changes">';
			//var txtNode = document.createElement('<input type="button" name="next" onClick="nextButton()" value="Save Changes">');
			//subelem.firstChild.appendChild(txtNode);
		}

		
		
	} 
	else 
	{
		//alert("running");
		setTimeout("alterEditorButtons()", 200);
	}
	

	//alert(getIFrameDocument("editorIframe").getElementById("buttonTable"));
}

function alterEditorColour(theColour)
{
	if (getIFrameDocument("editorIframe") && getIFrameDocument("editorIframe").getElementById("pagecreate"))
	{
		getIFrameDocument("editorIframe").getElementById("pagecreate").bgColor = theColour;
		//autoShade(3);
	} 
	
	else setTimeout("alterEditorColour("+theColour+")", 200);

}

function startupBackColor(theColour)
{
	var editor = getIFrameDocument("editorIframe");
	var main;
	if (!document.all) //NOT IE
	{
		if (editor.getElementById("maineditor") != null)
		{
			main = editor.getElementById("maineditor").contentDocument;
			if (main == null) 
			{
				alert("error in Mozilla compatibility.");
			}
		}
	}
	else { //IE
		main = document.frames["editorIframe"].getIFrameDocument("maineditor");
	}
	if (editor != null && main != null)
	{
		main.body.bgColor = theColour;
	} 
	else 
	{
		setTimeout("startupBackColor('"+theColour+"')", 200);
	}
}

function editTopFrame()
{
	//alert(document.getElementById("editorIframe").src);
	//alert(document.addForm.fuseaction.value);
	topPaneWindow = popUp("../editor/customeditor.htm");
	//window.document.addForm.body.value = '';
	//window.document.addForm.title.value = '';
	//window.document.addForm.pictureList.value = '';
	//window.document.addForm.paragraphId.value = '-1';
	//window.document.addForm.pageId.value = '-1';
		//what if i change the fuseaction instead... this way the index can deal with
		//the update properly.
	//window.document.addForm.fuseaction = 'updateTopFrame';
	//document.getElementById("editorIframe").src = "../editor/minieditor.htm";
	//alert('done');
}

function setTopText(topText)
{
	window.document.addForm.topText.value = topText;
}

function autoShade(shadeQty)
{
	var theColour = getIFrameDocument("editorIframe").getElementById("pagecreate").bgColor;
	
	//alert(colour1);
	
	
	var colour1 = theColour.substring(1,3);
	var colour2 = theColour.substring(3,5);
	var colour3 = theColour.substring(5,7);

	
    colour1 = hexToDec(colour1);
	colour2 = hexToDec(colour2);
	colour3 = hexToDec(colour3);
	
	
	colour1 = colour1+shadeQty;
	colour2 = colour2+shadeQty;
	colour3 = colour3+shadeQty;

	theColour = '#'+decToHex(colour1)+""+decToHex(colour2)+""+decToHex(colour3);
	
	
	getIFrameDocument("editorIframe").getElementById("pagecreate").bgColor = theColour;
	//update red


}

function hexToDec(hex)
{
	return parseInt(hex,16);
	/*
	var total;
	for(i=hex.length-1;i>=0;i--)
	{
		idx = hex.charAt(i);
		if (idx = 'F') {
			idx = '15';
		} else if (idx = 'E') {
			idx = '14';
		} else if (idx = 'D') {
			idx = '13';
		} else if (idx = 'C') {
			idx = '12';
		} else if (idx = 'B') {
			idx = '11';
		} else if (idx = 'A') {
			idx = '10';
		}
		idx = idx * (hex.length-i);
		total += idx;
	}
	return total;
	*/
}

function decToHex(dec)
{
	
	var hex = "";
	var max = 1;
	var pow = 0;

	if (dec == 0)
	{
		return "0";
	}
	while ((max*16) <= dec)
	{
		max = max*16;
		pow = pow+1;
	}
	
	while (pow >= 0)
	{
		var digit;
		if (dec == 0)
		{
			hex = hex+"0";
		}
		else 
		{
			
			var digit = Math.floor(dec / (Math.pow(16,pow)));
            var hdigit = digit;
			
			if (digit == '15')
			{
				hdigit = 'F';
			}
			else if (digit == '14')
			{
				hdigit = 'E';
			}
			else if (digit == '13')
			{
				hdigit = 'D';
			}
			else if (digit == '12')
			{
				hdigit = 'C';
			}
			else if (digit == '11')
			{
				hdigit = 'B';
			}
			else if (digit == '10')
			{
				hdigit = 'A';
			}
			
			hex = hex+""+hdigit;
	        dec = dec - (digit * (Math.pow(16,pow)));
			
		}
		pow--;

	}

	return hex;
}

function add1Hex(singleHexDigit)
{
	

}

function remove1Hex()
{

}

function areYouSure(str)
{
	doyou = confirm(str); 
	if (doyou == true)
	{
		return true
	}			
	else
	{
		return false
	}
}

function areYouSureDelete()
{
	return areYouSure("Are you sure you wish to delete this page?"); 
}

function unsavedChanges()
{
	//check if the content in the iframe is the same as the content in the form.
	//alert (frames["editorIframe"].frames["maineditor"].document.body.innerHTML);
		   //maineditor.innerHTML);
	//alert (window.document.addForm.body.value);
	var editor = getIFrameDocument("editorIframe");
	//this will let the editor 2 work
	//however will not check for unsaved changes
	if(editor == false)
	{
		return true;
	}
	var editorTxt;
	if (document.all){
		editorTxt = frames["editorIframe"].frames["maineditor"].document.body.innerHTML;
	} else 	{
		editorTxt = editor.getElementById("maineditor").contentDocument.body.innerHTML;
	}
	var formTxt = window.document.addForm.body.value;

    //remove the single speech mark problem.
	var re1 = new RegExp ("'", 'gi');
	editorTxt = editorTxt.replace(re1, '&#39;');
	
	/*if (xxbodyxx != null)
	{
		formTxt = xxbodyxx;
	} */
	

    //remove &nbsp; from content and replace with a space.
	//var re3 = new RegExp ('&nbsp;', 'gi');
	//var re4 = new RegExp (' ', 'gi');
	//var re5 = new RegExp ('&#32;', 'gi');

	//editorTxt = editorTxt.replace(re3, '');
	//editorTxt = editorTxt.replace(re4, '');
	//formTxt = formTxt.replace(re3, '3');
    //formTxt = formTxt.replace(re4, '4');
	//formTxt = formTxt.replace(re5, '5');


	//this bit for replacing the html ver of ' with ' is no longer used.
		//var re2 = new RegExp ("&#39;", 'gi');
		//formTxt = formTxt.replace(re2, "'");

    
	
	/*
	if (editorTxt != formTxt)
	{
		//alert("Testing -- "+editorTxt);
		//alert("testing -- "+formTxt);
		return areYouSure("All unsaved changes will be lost \nAre you sure you wish to continue?"); 
	}
	else return true;
	*/

	return true;
	
}

function launchCenter(url, name, width, height, winstyle) 
{
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;  if (window.screen) {
    var ah = screen.availHeight - 30;    var aw = screen.availWidth - 10;
    var xc = (aw - width) / 2;    var yc = (ah - height) / 2;
    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;  }src="styles/shopTemplates/popup.js"
        return window.open(url, name, str + "," + winstyle);
}
function PopWindow(strURL, width, height)
{               
  launchCenter(strURL, '_blank', width, height, 'scrollbars=yes,toolbar=no,location=no,menubar=no,resizable=yes')
}

// -->

