// --------------------------------------------------------------------
//
//      AUTHOR :  Roman Zhovtulya
//
// JavaScript Library for Uportal CMS
// --------------------------------------------------------------------
//
//      Versions :
//
//      date         version         By whoom and what was done
// --------------------------------------------------------------------
//      20.10.2002    V 1.0	     Roman, optimizing
//      
//                                  
//     
//
// --------------------------------------------------------------------



// function for displaying hidden layers
// added 2006-12-17 by Christian


var menuStates = new Object();
function displayMenu(id, inputFieldName) {
	if (menuStates[id] == 'visible') {
		document.getElementById(id).style.visibility = 'hidden';
		menuStates[id] = 'hidden';
	}
	else {
		for (var menuId in menuStates) {
			menuStates[menuId] = 'hidden';
			document.getElementById(menuId).style.visibility = 'hidden';
		}
		document.getElementById(id).style.visibility = 'visible';
		menuStates[id] = 'visible';
		document.getElementById(inputFieldName).select();
		
	}
}


//function that closes the current window:

  function closewindow()
{
    window.close();
}





//function that refreshes the target window to the location (LocString) provided
// (used for automatic refresh when select box value is changed):


function popUpNav(LocString,wTarget) 
{
	if (LocString != "") {
		wTarget.location.href = LocString;
	}
}




//function that checkes user input:

function ValidForm(theForm)
{
  if (theForm.team_name.value == "")
  {
    alert("Please enter the team name!");
    theForm.team_name.focus();
    return (false);
  }

  if (theForm.student1.value == "")
  {
    alert("Please enter the name of the 1st memeber!");
    theForm.student1.focus();
    return (false);
  }

  if (theForm.student2.value == "")
  {
    alert("Please enter the name of the 2nd memeber!");
    theForm.student2.focus();
    return (false);
  }

}



//function opens a window based on the provided information:

function openwindow (url, w, h, name) 
{

window.open(url,name,'toolbar=no,resizable=yes, directories=no,status=no,scrollbars=yes,resize=no,menubar=no,width='+w+',height='+h);

}


function openwindow2 (url, w, h, name)
{


window.resizeTo(700, 800);
window.location.href=url;


}





// function for loading the URL content into the parent window (used in FHO Portal search engine):

function loadIntoParent(url) {
 opener.location.href=url;
}




// new function used to open a window in CMS editor in such a way that it would later be possible to close it and reload the parent page in Mozilla as well

function openwindowNew(url, w, h, name) 
{

child = window.open(url,name,'toolbar=no,resizable=yes,directories=no,status=no,scrollbars=yes,resize=no,menubar=no,width='+w+',height='+h);

}


// new function used to open a window in CMS editor in such a way that it would later be possible to close it and reload the parent page in Mozilla as well
// one more set of the same functionality to have the two independent windows with the above mentioned functionality:

function openwindowNewExtra(url, w, h, name) 
{

childExtra = window.open(url,name,'toolbar=no,resizable=yes,directories=no,status=no,scrollbars=yes,resize=no,menubar=no,width='+w+',height='+h);

}



// function for closing the edit window and refreshing the parent
// (in administration "edit data" scrips):

//function closeChild() {

//child.close();
 
// self.location.reload();
//}


function closeChild() {

child.close();

parent.location.reload();


}





function closeChildExtra() {

 childExtra.close();
 
 parent.location.reload();
}




// function for closing the child window from within the child window
// (for administration "edit data" scrips):

function endNow() {
 opener.location.href="JavaScript:closeChild()";
}


function endNowExtra() {
 opener.location.href="JavaScript:closeChildExtra()";
}



// the same as "endNow()", but it reloads the window specified:

function endNowWindow(winName) {

window.close();

var win = window.open('', winName); 

win.location.reload();

}



function endNowUrl(urlToUpdateTo) 
{


opener.location.href=urlToUpdateTo;

// parent.location.href=urlToUpdateTo;


 window.close();

}


// reloads the window specified to the given url:


function endNowUrlWin(urlToUpdateTo, winName) 
{

// closing the current window: 
	window.close();

// getting the window by its name:
	var win = window.open('', winName); 

// updating the window to the url passed:
	win.location.href=urlToUpdateTo;



}



// function for keeping the windows open:


function open_popup(page) {

     top.window_handle = open(page,'popupWindowName', "width=750,height=400");
    top.window_handle.focus();
    if (!top.window_handle.opener) top.window_handle.opener = self;
    return false;
}










// function for loading the URL content into the specified target frame
// (used in previewing while browsing files in upload window)

function loadIntoFrame(url) {
 parent.fhoportalSelectFilePreview.location.href=url;
}








// function that checks whether everything is correct for the upload:


function validFormUploadFile(theForm)
{


var filePath=theForm.FILE1.value;

// checking if the file name has been entered:

	//if (filePath.match(/ /))
	//{
	//   alert("Please select the file - Bitte wählen Sie die Datei!");
	//   alert(filePath);
	   
	//   return (false);
	//}


// checking if the file name contains forbidden characters (space, +, etc):
	
	// looking for a file name substring:
		// getting the index of the last occurance of "\":
		
		var lastSlashIndex=0;

		// looping through the file path and checking for "\" position:
		// (we've got to use "\\", since a single "\" is interprited as an escape character only:
		
		for(i=0; i<filePath.length; i++)
			{
		  	
		  	if ( filePath.charAt(i)=='\\')
		  		{
		  		
		  		lastSlashIndex=i;
		  		
		  		}
		  	
			}
		
		
	// getting the file name:
	

	var fileName=filePath.substring(lastSlashIndex+1, filePath.length);


	if (fileName.match(/ /))
	{

	   alert("Sorry spaces are not allowed in file names - Sorry, Lehrzeichen in Dateinamen sind nicht erlaubt!");
	   
	   return (false);
	}

	if (fileName.match(/\+/))
	{

	   alert("Sorry plus signs are not allowed in file names - Sorry, plus Zeichen in Dateinamen sind nicht erlaubt!");
	   
	   return (false);
	}



}





// functions for left menu

  function MM_findObj(n, d) { //v4.0
      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 && document.getElementById) x=document.getElementById(n); return x;
    }
    
    function MM_showHideLayers() { //v3.0
      var i,p,v,obj,args=MM_showHideLayers.arguments;
      for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
        if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
        obj.visibility=v; }
    }
    
    function MM_openBrWindow(theURL,winName,features) { //v2.0
      window.open(theURL,winName,features);
    }



    var isDOM      = (typeof(document.getElementsByTagName) != 'undefined'
                      && typeof(document.createElement) != 'undefined')
                   ? 1 : 0;
    var isIE4      = (typeof(document.all) != 'undefined'
                      && parseInt(navigator.appVersion) >= 4)
                   ? 1 : 0;
    var isNS4      = (typeof(document.layers) != 'undefined')
                   ? 1 : 0;
    var capable    = (isDOM || isIE4 || isNS4)
                   ? 1 : 0;
    // Uggly fix for Opera and Konqueror 2.2 that are half DOM compliant
    if (capable) {
        if (typeof(window.opera) != 'undefined') {
            capable = 0;
        }
        else if (typeof(navigator.userAgent) != 'undefined') {
            var browserName = ' ' + navigator.userAgent.toLowerCase();
            if (browserName.indexOf('konqueror') > 0) {
                capable = 0;
            }
        } // end if... else if...
    } // end if
    var fontFamily = 'arial, geneva, sans-serif';
    var fontSize   = 'small';
    var fontBig    = 'large';
    var fontSmall  = '12';
    var fontLarge  = '12';    
    
    var isServer   = true;





// methods for calender window:

var auxiliarValue;

function openCalendar(field, year, month, day)
{
	
	var left = 300;
	var top = 300;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		left = e.pageX;
		top = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		left = e.clientX + document.body.scrollLeft;
		top = e.clientY + document.body.scrollTop;
	}


	month --;

	calendar = window.open('core/calendar/calendar.jsp?year='+year+'&month='+month+'&day='+day+'&action=2','calendar','toolbar=no,location=no,directories=no,resizable=yes,status=no,scrollbars=no,left=' + left + ',top=' + top + ',width=200,height=145');
	//calendar.field = field;
	auxiliarValue = field;

	if (window.focus) {calendar.focus()}
}

