<!--
//**************************************************/
//  © 1997-2004  Nortia Technologies.   All rights reserved.
//
//	File:			incInitPageEvents.js		
//	Author(s):		ks
//  Created:		5/03/2004	
//	Description:	Page load events
//	Dependencies:
//	Functions:		
//	Notes:
//	TODO:		
//	History:
//		
//**************************************************/


// globalsvar g_LinkArray = new Array() // list of all links on the page
var g_TargetArray = new Array() // list of all targets on the page
// stuff to do once the page is loaded
function loadInitEvents(mode) {

	init();
	
	
	// apply scroll styles to the content area in Netscape
	if (navigator.appName=="Netscape")
	{
		var arrDivContent = document.getElementsByTagName("DIV");

		for (var i=0; i<arrDivContent.length; i++)
		{
			if (arrDivContent[i].className.indexOf("ContentBlock") !=-1) // found a content block
			{
				arrDivContent[i].style.overflow = "auto";
			}
		}
	}	
	
}

/* CONTENT EDITOR FUNCTIONS */

function EditChangeStyle(Object,StyleClass)
{
	Object.className=StyleClass;
}

function EditArea(Object,PageID,RegionID)
{	
	var win;
	var address="http://192.168.0.59/ResourceCentre"; // assign the default path
	//var OrgID='<%=session("OrgID")%>';
	//var LangID='<%=session("strLanguageID")%>';
	
	if (typeof(OrgID)=='undefined' || typeof(LangID)=='undefined') return;
	
	//check if we are not on the local server
	if (document.location.href.indexOf("192.168.0.59")==-1 && document.location.href.toLowerCase().indexOf("iis-01")==-1) {
	
		address=document.location.href; // get the entire server address
		address=address.slice(7); // remove the http
		address="http://" + address.slice(0, address.indexOf("/")) // extract the server name and add the http back in
	}

    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - 640)/2;
    var yOffset = (yMax - 480)/2;
    var URL
    URL=address + "/Common/ContentManagement/FCKEditor/index.asp?PageID="+PageID+"&RegionID="+RegionID+"&folder=/Images"; 	
	URL+="&OrgID=" + OrgID + "&LangID=" + LangID;
	EditObject=Object;
	win=window.open(URL,"Editor","width=640,height=480,screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset+"");	
	win.focus();
	
}

function AddResource(PageID, RegionID)
{
	var win;
	var address="http://192.168.0.59/ResourceCentre"; // assign the default path
	
	//check if we are not on the local server
	if (document.location.href.indexOf("192.168.0.59")==-1 && document.location.href.indexOf("IIS-01")==-1) {
		address="http://wm.p80.ca"
	}	
	var URL
    URL=address + "/Resources/conAddResource.asp?PageID="+PageID+"&RegionID="+RegionID;	

	win=window.open(URL,"Resources", "width=450,height=300,scrollbars=yes");	
	//win=window.open(URL, "Resources");
	win.focus();
}

//--------------------------------------------------------------------------------------
//Public Function SaveHREF()
//Usage:	Temporarily stores all the link locations.
//
//Input:	None
//Output:	None
//Notes:	
	
function SaveHREF()
{
	for (var i=0; i<document.links.length; i++) {
		g_LinkArray[i]=document.links[i].toString()
		g_TargetArray[i]=document.links[i].target.toString()
	}
}

//--------------------------------------------------------------------------------------
//Public Function RestoreHREF()
//Usage:	Resets all links back to their original values
//
//Input:	None
//Output:	None
//Notes:	

function RestoreHREF()
{
	var prefix;
	
	for (var i=0; i<document.links.length; i++) 
		{    
        // Takes first 3 chars from the name
        //prefix=document.links[i].name.slice(0,3);
        //if (prefix!="NEL") { // All links that remain clickable are named using the NEL prefix
			//document.links[i].onclick = '';
			document.links[i].href = g_LinkArray[i];
			document.links[i].target = g_TargetArray[i];
		//}
    }

}

//--------------------------------------------------------------------------------------
//Public Function DisableHREF()
//Usage:	Changes all links without a NEL prefix in their name to links that do nothing.
//          This is to prevent errors that occured when trying to edit content that had links
//          embedded in it.
//
//Input:	None
//Output:	None
//Notes:	

function DisableHREF() 
{
	var prefix;
	
	for (var i=0; i<document.links.length; i++) 
		{    
        /*if (document.links[i].name!=null) {
			prefix=document.links[i].name.slice(0,3); // looks for the NEL prefix
        } else
			prefix="";
		}
        if (prefix!="NEL") {*/
			//document.links[i].onclick = '';		
			document.links[i].href = 'javascript:;'; //nullifies the link
			document.links[i].target = '';
		//}
    }
	
}

//--------------------------------------------------------------------------------------
//Public Function Init()
//Usage:	Saves all links and disables them.
//
//Input:	None
//Output:	None
//Notes:	

function init()
{	
	// disabled links if in page edit mode
	if (document.location.href.indexOf("designmode=1")!=-1) {
		// Save all the links if the user is in design mode
			SaveHREF()
		// Disable all links 
		DisableHREF()
	}

}


