/* '#################################################################################

'## Copyright (C) 2004 Rick Eastes

'##

'## This program is free software; you can redistribute it and/or

'## modify it under the terms of the GNU General Public License.

'##

'## The "powered by" text/logo with a link back to

'## http://www.nukedit.com in the footer of the pages MUST

'## remain visible when the pages are viewed on the internet or intranet.

'## Donations made to nukedit may waiver this requirement.

'## Speak to rick@nukedit.com

'##

'## All copyright notices regarding nukedit

'## must remain intact in the scripts and in the outputted HTML

'##

'## Support can be obtained from support forums at:

'## http://www.nukedit.com/forum

'##

'################################################################################# */



//Set Global Variables



var deactivatemenu = false;

var editorvisible = false;

var arySelected = new Array();

var aryObjSelected = new Array();

var nTimeOutId = -1;

var DHTML = (document.getElementById || document.all || document.layers);



if (navigator.appName == "Netscape") {

	layerStyleRef="layer.";

	layerRef="document.layers";

	styleSwitch="";

}

else{

	layerStyleRef="layer.style.";

	layerRef="document.all";

	styleSwitch=".style";

}



function openWindow(url) {

  popupWin = window.open(url,'new_page','width=450,height=400,scrollbars=yes')  

}



function popupWindow(url,nWidth,nHeight) {

	nWidth = parseInt(nWidth) + 20;

	nHeight = parseInt(nHeight) + 30;



	newWindow = window.open(url,"newWindow","left=0,top=70,width="+nWidth+",height="+nHeight);

}              



function CloseSoon(strDiv,delay)

{

	if(!delay)

		delay = 1000;	

	return setTimeout("HideLayer('" + strDiv + "')",delay);

}



function ShowSoonAt(strDiv,x,y)

{

	if(document.nOpenTimoutID>0)

		clearTimeout(document.nOpenTimoutID)



	document.nOpenTimoutID = setTimeout("ShowLayerAt('" + strDiv + "'," + x + "," + y + ")",400);

}



function OnMouseOverMenu(strDivId,nLevel,objDiv,tp,align)

{

	// Triggered when user mouses a menu item

	// strDivId:		If !="", then it is a parent also. We then open the child menu named strDivId

	// nLevel:			What level is this menu item at. Root = 1, 

	// objDiv:			The object of the div that the user moused over



	if(editorvisible==true || deactivatemenu==true)

	return;

	

	HideMenus(nLevel,tp);

	clearTimeout(nTimeOutId);

	

	if(objDiv.className){

		if(nLevel == 1)

		{

			objDiv.className=tp+'_me_menuover';

			arySelected[nLevel]=strDivId;

			aryObjSelected[nLevel]=objDiv;

		}else if(nLevel == 2)

		{

			objDiv.className=tp+'_me_submenuover';

			arySelected[nLevel]=strDivId;

			aryObjSelected[nLevel]=objDiv;

		}

	}



	if(strDivId!=""){//If there is a child menu

		//Fix: If there is a long menu at the bottom of the page, we need to move it up a bit so it fits

		objMenu = MM_findObj(strDivId);

		y1 = objDiv.offsetTop-1; 

		x1 = objDiv.width;

		

		if(objDiv.offsetParent){ //If we're allowed to get parent element that offset comes from

			objDivCopy = objDiv;

			y1abs = 0;	

			while(objDivCopy.offsetParent){

				objDivCopy = objDivCopy.offsetParent;

				y1abs += objDivCopy.offsetTop;

			}

			y1abs += objDiv.offsetTop;



			y2 = objMenu.clientHeight + y1abs;

			//DebugMsg("y1:" + y1 + " y2:" + y2 + "");

			if(y2>document.body.clientHeight+document.body.scrollTop)
				y1 = y1;
				//y1 = y1 - (y2-document.body.clientHeight-document.body.scrollTop) ;

		}

		

		

		if(align=="horiz" && nLevel==1){

			ShowLayerAt(strDivId,"NaN",getObj(strDivId).style.clientTop);

		}

		else{

			ShowLayerAt(strDivId,x1,y1);

		}

		

	}

}



function HideMenusSoon(nLevel,tp)

{

		nTimeOutId = setTimeout("HideMenus("+nLevel+",'"+tp+"')",1000);

}



function HideMenus(nLevel,tp)

{

//Hides All menus from current level onwards an sets the layer style back to menuout

	if(deactivatemenu==true)

	return;

	var i=nLevel;

	//for(i=nLevel;i<arySelected.length;i++)

	//{

		if(arySelected[i])

		{

			HideLayer(arySelected[i]);

			arySelected[i]=null;

		}

		

		if(aryObjSelected[i])

		{	

			if(nLevel == 1)

			{

				aryObjSelected[i].className=tp+'_me_menuout';

				aryObjSelected[i] = null;

			}else if(nLevel == 2)

			{

				aryObjSelected[i].className=tp+'_me_submenuout';

				aryObjSelected[i] = null;

			}

		}

	//}



}



function ResetStyle(nLevel,tp)

{

//Resets All menustyles from current level onwards to menuout

	

	for(i=nLevel;i<aryObjSelected.length;i++)

	{

		if(aryObjSelected[i])

		{				

			aryObjSelected[i].className=tp+'_me_menuout';

			aryObjSelected[i] = null;

		}

	}

}





function HideLayerTrans(layerName){

	obj = getObj(layerName);



	if(obj.filters[0])

		obj.filters[0].Apply();



	getObjStyle(layerName).visibility = "hidden";



	if(obj.filters[0])

		obj.filters[0].Play();	

}



function HideLayer(layerName){

	getObjStyle(layerName).visibility = "hidden";

}



function ShowLayerTrans(layerName){

	obj = getObj(layerName);



	if(obj.filters[0])

		obj.filters[0].Apply();



	getObjStyle(layerName).visibility = "visible";

	

	if(obj.filters[0])

		obj.filters[0].Play();	

}





function ShowLayer(layerName){

	getObjStyle(layerName).visibility = "inherit";

}



function DebugMsg(message)

{

	SetContent("divMessage",eval(layerRef+'["divMessage"].innerHTML') + "  " + message);  //Puts message into top of page in realtime

}



function SetContent(layerName,content){

	eval(layerRef+'["'+layerName+'"].innerHTML="' + content + '"');

}





function ShowLayerAt(layerName,x,y){

	ShowLayer(layerName);



	if(!isNaN(x))

		getObjStyle(layerName).left=x;

	

	if(!isNaN(y))

		getObjStyle(layerName).top=y;				

	

}



function showSubMenu(x,y,layertext){

	x = x + document.body.scrollLeft + 5;

	y = y + document.body.scrollTop - 5;



	divSubMenu.innerHTML = layertext;

	ShowLayerAt("divSubMenu",x,y);

}



/*

function toggleLayer(layerName){

	if(setupvisible == "false"){

		setupvisible = "true";

		showLayer(layerName);

	}

	else{

		setupvisible = "false";

		hideLayer(layerName);

	}

}

*/







function showEditLayer(parentid,menuid,x,y,site){

	deactivatemenu = true;	

	x = x + document.body.scrollLeft - 8;

	y = y + document.body.scrollTop - 8;

	

	layertext = "<a href='" + site + "utilities/menumanager.asp?action=add&parentid=" + parentid + "&menuid=" + menuid + "' class=imagelink><img src='" + site + "gfx/context-new.gif' border=0 align=top alt='Add a page under this one' vspace=0></a><br>";

	layertext += "<a href='" + site + "utilities/menumanager.asp?action=edit&menuid=" + menuid + "' class=imagelink><img src='" + site + "gfx/context-properties.gif' border=0 align=top alt='Edit this menu Item' vspace=0></a><br>";

	if(parentid != -1){

		layertext += "<a href='" + site + "utilities/menumanager.asp?action=delete&menuid=" + menuid + "' class=imagelink><img src='" + site + "gfx/context-delete.gif' border=0 align=top alt='Delete This menu Item' vspace=0></a>";

	}

	

	getObj("divEditMenu").innerHTML = layertext;



	ShowLayerAt("divEditMenu",x,y);

}



function getObjStyle(name)

{

  if (document.getElementById)

  {

    return document.getElementById(name).style;

  }

  else if (document.all)

  {

    return document.all[name].style;

  }

  else if (document.layers)

  {

    return document.layers[name];

  }

  else return false;

}



function getObj(name)

{

  if (document.getElementById)

  {

    return document.getElementById(name);

  }

  else if (document.all)

  {

    return document.all[name];

  }

  else if (document.layers)

  {

    return document.layers[name];

  }

  else return false;

}





//Cookie Helpers



function getCookieVal (offset) {

   var endstr = document.cookie.indexOf (";", offset);

   if (endstr == -1)

      endstr = document.cookie.length;

   return unescape(document.cookie.substring(offset, endstr));

}



function GetCookie (name) {

        var arg = name + "=";

        var alen = arg.length;

        var clen = document.cookie.length;

        var i = 0;

        while (i < clen) {

                var j = i + alen;

                if (document.cookie.substring(i, j) == arg)

                        return getCookieVal (j);

                i = document.cookie.indexOf(" ", i) + 1;

                        if (i == 0)

                                break;

                }

   return null;

}



function SetCookie (name, value) {

        var argv = SetCookie.arguments;

        var argc = SetCookie.arguments.length;

        var expires = (argc > 2) ? argv[2] : null;

        var path = (argc > 3) ? argv[3] : null;

        var domain = (argc > 4) ? argv[4] : null;

        var secure = (argc > 5) ? argv[5] : false;

        document.cookie = name + "=" + escape (value) +

                ((expires == null) ? "" : ("; expires=" +

expires.toGMTString())) +

                ((path == null) ? "" : ("; path=" + path)) +

                ((domain == null) ? "" : ("; domain=" + domain)) +

                ((secure == true) ? "; secure" : "");

}



// Standard Dreamweaver routines

function MM_validateForm() { //v3.0

  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);

    if (val) { nm=args[i+1];if(nm==''){nm=val.name;} if ((val=val.value)!="") {

      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');

        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';

      } else if (test!='R') { num = parseFloat(val);

        if (val!=''+num) errors+='- '+nm+' must contain a number.\n';

        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

          min=test.substring(8,p); max=test.substring(p+1);

          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';

    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }

  }



  if (errors){

    alert('The following error(s) occurred:\n'+errors);

  }



  document.MM_returnValue = (errors == '');

	

}





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];}

}