// JavaScript Document

function toggle(id){ // used with direct navigation
	ul = "smt_" + id;
    img = "img_" + id;
    ulElement = document.getElementById(ul);
    imgElement = document.getElementById(img);
    if (ulElement){
            if (ulElement.className == 'closed'){
                    ulElement.className = "open";
                    imgElement.src = "/images/opened.gif";
					expandObj(ulElement.parentNode);
					
                    }else{
                    ulElement.className = "closed";
                    imgElement.src = "/images/closed.gif";
                    }
            }
}

function expandObj(idElement){ //expanding & highlighting items in navigation
    if (idElement){
		classN = idElement.className;
		if ( classN == "SubMenu") {
			idName = idElement.id;
			smt = "smt_" + idName;
		    img = "img_" + idName;
		    smtElement = document.getElementById(smt);
		    imgElement = document.getElementById(img);
	        smtElement.className = "open";
	        imgElement.src = "/images/opened.gif";
		
		} 			
		idParent = idElement.parentNode;
		if (idParent)
			expandObj(idParent);
     } 
	}
	

function focusIDwID(id, contextF, id2) {
//	alert('focusIDwID 3 ['+id+'] ['+id2+']');
//	alert("focusIDwID "+document.location+" id:"+id);
	var ulElement = document.getElementById(id);
	if (ulElement) {
//	alert('found ['+id+']');
		var shref = '';
		if (ulElement.className == 'SubMenu') { //it is a submenu 
			idx = "idx_"+id;
		    idxElement = document.getElementById(idx);
			if (idxElement) { 
				shref = idxElement.href;
				ulElement = idxElement;
				}
			}
		else { // this is item...
			shref = ulElement.href;
			}
		if (id2 != void(0)) {
		// is there a ? in the shref?
			index = shref.indexOf('?'); 
			if (index < 0)
				shref = shref+"?"+id2;
			else
				shref = shref+"&"+id2;
			}	
		if (shref != void(undefined)) { 
//			alert('loading ['+shref+']');
			if (contextF != void(0))
				contextF.location = shref;
			else
				parent.mainFrame.location = shref; // ulElement.href; //************************
			}
		}
	else {
//		alert('did not find ['+id+']');
			if (contextF != void(0))
				contextF.location =  "/errors/common/notfound.html";
			else		
				parent.mainFrame.location = "/errors/common/notfound.html"; //************************
		}
	}



function LoadNavTop(id)  { // this frame value is an object, not a text
		if (typeof top.ContextFrame=="undefined" )  {
			alert("Context frame is unknown, check 'index' for var ContextFrame = '??'");
			return;
			}

		if (typeof top.NavFrame=="undefined" )  {
			alert("Navigation frame is unknown, check 'index' for var NavFrame = '??'");
			return;
			}

		if (page.search) { // found name...
			top.frames[top.NavFrame].LoadNav2(page.search.substring(1),  top.frames[top.ContextFrame]);		
			}
		else  { // default
			if (typeof top.frames[top.NavFrame].LoadNav2 == "undefined") {
//				alert("top.frames[top.NavFrame].LoadNav2 is yet undefined, loading directly...");
				return top.frames[top.ContextFrame].location="home.php"; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
			} else
				return top.frames[top.NavFrame].LoadNav2("home", top.frames[top.ContextFrame]);		
			}
return false;
//	return LoadNav(id, top.navFrame, top.mainFrame);
}


function CheckParent(parentID, sHref, ask) {
//	alert ("Checking contex");
//		alert("Checking : frameNo:"+frameNo+" actual name "+parent.frames[frameNo].name+" requested name " + frameName);
//	 alert("CheckParent2 parentID is ["+parentID+"] parent["+((top == self) ? 'none':parent.PageID)+"] alt ["+sHref+"]");

	if (top == self) {
//		alert ("Alone :=( going to ["+sHref+"]");
		top.location.href = sHref;
		return;
		}
	if ((typeof parentID=="undefined" ) || (parentID == '')) {
		return; // can't check if ParentID was not supplied
		}
		
	if ((typeof parent.PageID=="undefined" ) || (parentID != parent.PageID)) {
//		alert("Mismatch : asked for " + parentID+" got "+parent.PageID+" going to ["+sHref+"]" );
		if (!ask || confirm('This page is out of its context. Reload the right way?'))
			parent.location.href = sHref; // + location.href;
//		 alert("Mismatch PageID is ["+PageID+"] parent["+parent.PageID+"] ");

		}
	else { 
//	 alert("Mathched  ["+parentID+"] parent["+parent.PageID+"]");
		}
}

function LoadNav2(id, contextF)  { // MAIN navigation! this frame value is an object, not a text
//	alert("Entering LoadNav2 "); //+document.location+" id:"+id);//+" contextF:"+contextF+ " ");

	var nn = id.indexOf("?");
	if (nn==-1) { // no subsets
			self.focusIDwID(id, contextF);
	}
	else { // found subnames
		var name1 = id.substring(0, nn);
		var name2 = id.substring(nn+1);
		self.focusIDwID(name1, contextF, name2);	
		}
	return false;		
}


function LoadFromNav(page) { // redirects location information into navigation frame
/* 	
var testel = frames[NavFrame]; //.getElementById('TestEl');
	if (typeof testel=="undefined" )
		alert("Test Element is missing...");
	else
		alert("Test Element is found");
*/
		if (typeof self.ContextFrame=="undefined" )  {
			alert("Context frame is unknown, check 'index' for var ContextFrame = '??'");
			return;
			}

		if (typeof self.NavFrame=="undefined" )  {
			alert("Navigatione frame is unknown, check 'index' for var NavFrame = '??'");
			return;
			}

		if (page.search) { // found name...
//				alert("frames[NavFrame].LoadNav2 found name...["+NavFrame+"] ["+ContextFrame+"] ["+page.search.substring(1)+"]");
			frames[NavFrame].LoadNav2(page.search.substring(1),  frames[ContextFrame]);		
			}
		else  { // default
			if (typeof frames[NavFrame].LoadNav2 == "undefined") {
//				alert("frames[NavFrame].LoadNav2 is yet undefined, loading directly...");
				frames[ContextFrame].location="home.php"; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
			} else {
//				alert("frames[NavFrame].LoadNav2 Loading default .....");
				if (typeof frames[NavFrame].DefaultPage == "undefined") {
//					alert("frames[NavFrame].LoadNav2 Loading default home");
					frames[NavFrame].LoadNav2("home", frames[ContextFrame]);		
					}
				else {
//					alert("frames[NavFrame].LoadNav2 Loading Predefined default " + frames[NavFrame].DefaultPage);
					frames[NavFrame].LoadNav2(frames[NavFrame].DefaultPage, frames[ContextFrame]);		
					}
				}
			}

	}


//***
// Visual feedback 
//***
function FocusParentNav(id) { // just like LoadNav, but changes class of a focused item
	if ((self == top) || (typeof parent.NavFrame == "undefined")) {
//		alert("could not find parent Nav");
		return; 
	}
	parent.frames[parent.NavFrame].FocusNav(id);
//	alert("Focusing parent Nav");
	}

function FocusNav(id) { // just like LoadNav, but changes class of a focused item
//	alert("Focusing Nav at [" +id+"]");
	ulElement = document.getElementById(id);
	if (ulElement) {
		if (ulElement.className == 'SubMenu') { //it is a submenu 
			smt = "smt_"+ id;
			smtElement = document.getElementById(smt);
			if (smtElement)
				expandObj(smtElement);
			idx = "idx_"+id;
		    idxElement = document.getElementById(idx);
			if (idxElement) 
				idxElement.className = "focused";
			}
		else { // this is item...
			expandObj(ulElement);
			ulElement.className = "focused";
			}
	}
	else {
		if (id != '')
			alert("Could not focus '" +id+"'");
		}
}

function DiffuseParentNav(id) { // just like LoadNav, but changes class of a focused item
	if ((self == top) || (typeof parent.NavFrame == "undefined"))
		return; 
	parent.frames[parent.NavFrame].DiffuseNav(id);
	}

function DiffuseNav(id) { // just like LoadNav, but changes class of a focused item
	ulElement = document.getElementById(id);
	if (ulElement) {
		if (ulElement.className == 'SubMenu') { //it is a submenu 
			idx = "idx_"+id;
		    idxElement = document.getElementById(idx);
			if (idxElement) 
				idxElement.className = "diffused";
			}
		else { // this is item...
			ulElement.className = "diffused";
			}
		}
}

function reSizeAtTop() { 
	var curSize = parent.document.body.rows.split(",");
	var myHeight = document.body.scrollHeight;
//	alert("parent.document.body.rows[0]=["+document.body.scrollHeight+"] vs ["+curSize[0]+"] is ["+(myHeight > curSize[0])+"]"); 
	if (myHeight > curSize[0]) {
		curSize[0]= myHeight;
		newSize = curSize.join(",");
		//(document.body.scrollHeight)+",*"
/*		alert("parent.document.body.rows[0]=["+document.body.scrollHeight+"]"); */
	   parent.document.body.rows = newSize;
		}
//	newSize = (document.body.scrollHeight)+",*"
   }

function AddMyTitle(add) {
//	alert ("Adding title ["+add+"]");
	if (top == self) {
//		alert ("Top level");
		if (typeof IndexTitle != 'undefined')	{
			add = IndexTitle + " - "+add; 	
//			alert ("IndexTitle is set - ["+newTitle+"]");
		}
//		else {
//			alert ("IndexTitle is undefined, stay with ["+add+"]");
//			}
/*			newTitle = IndexTitle + add; 	
		alert ("Top: - title ["+newTitle+"] instead of ["+document.title+"]");
*/
		document.title = add;
		}
	else {
		newTitle = document.title + " - " + add;
//		alert ("2 Added title ["+newTitle+"] for ["+parent.PageID+"]");
//		alert ("Parent is ["+(typeof parent.Trap == 'function')+"]");
//		if 	(typeof parent.Trap == 'function') {
//			alert ("It's there!");
//			parent.Trap();
//			parent.AddMyTitle("blank");	

//			}
//		if (typeof parent.document.AddMyTitle == "function") {
//			alert "Parent AddMyTitle exists";
//			}
//		else {
//			alert "Is not defined ";
//		}
//		alert ("Check done");
		
//		if (typeof parent.AddMyTitle != 'undefined')	
		parent.AddMyTitle(newTitle);	
//		parent.AddMyTitle("blank");	
//		else
//			alert ("But cannot find parent.AddMyTitle");
//		alert "Done";
		}
	}

function Trap() {
	alert ("Trapped");
	}

	
function HideMenu() {
	document.getElementById('HiddenTab').style.display = 'block';
	document.getElementById('VisibleTab').style.display = 'none';

	var width = document.getElementById('HiddenTab').scrollWidth;
	parent.document.getElementById('ContextCell').style.left = width +2+ "px";
	parent.document.getElementById('NavCell').style.width = width + "px";
	}

function ShowMenu() {
	document.getElementById('VisibleTab').style.display = '';
	document.getElementById('HiddenTab').style.display = 'none';
	var width = document.getElementById('VisibleTab').scrollWidth;
	parent.document.getElementById('ContextCell').style.left = width +2+ "px";
	parent.document.getElementById('NavCell').style.width = width + "px";
	}
	
	
function OnLoginEvent(source) {
	if (BrimFrame && (source != BrimFrame))	
		this.frames[BrimFrame].location.reload( true );
	if (source != NavFrame)	
		this.frames[NavFrame].location.reload( true );
	if (source != ContextFrame)	
		this.frames[ContextFrame].location.reload( true );
	}
	