/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// basic.js 1.0.0
// erstellt durch Dockland SA, Horgen, Schweiz
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Einstellungen
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Optionen: Standard-Popupfensters.
var optionsPopup0 = "scrollbars=yes,resizable=yes,menubar=yes,location=no,width=604,height=480";
//
// Optionen: Erstes Popupfensters.
var optionsPopup1 = "scrollbars=yes,resizable=yes,menubar=no,location=no,width=240,height=360";
//
// Optionen: Zweites Popupfensters.
var optionsPopup2 = "scrollbars=yes,resizable=yes,menubar=no,location=no,width=160,height=160";
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Variablen (Global)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
var ScrollID;
var Previews = new Array();
var PHeights = new Array();

var DOM = (document.getElementById) ? true : false;
var OP = (window.opera)? true : false;
//var OP5+ = (OP && DOM)? true : false;
var NS = (window.outerWidth && !OP)? true : false;
//var NS6+ = (NS && DOM)? true : false;
var NS4 = (NS && !DOM)? true : false;
var IE = (document.all && !OP)? true : false;
//var IE5+ = (IE && DOM)? true : false;
var IE4 = (IE && !DOM)? true : false; 
   
function GetElement(id)
{
   var obj;
   
	if(DOM)
		obj = document.getElementById(id);
   
   return obj;
  
}

function OpenCourse(theURL,winName,features) { //v2.0
  
  window.open(theURL,winName,features);
}

function OpenContent(id, path, type, folder) {

	var url = 'content.aspx?id='+id+'&type='+type+'&path='+path+"&folder="+folder;
	var name = 'Content';
	var attributes = 'width=607,height=755';
	
	window.open(url , name, attributes);
}

function ContentClose() {
	
	if (document.location.href.indexOf('close=1') > -1)
		window.close();
}


function OpenHelp() { 

	var url = 'help.aspx';
	var name = 'Help';
	var attributes = 'width=550,height=440';
	
	window.open(url , name, attributes);
}


function OpenNotes(query) { 

	var url = 'notes.aspx?' + query;
	var name = 'Annotations';
	var attributes = 'width=550,height=440';
	
	window.open(url , name, attributes);
}

function OpenPrint(query) { 

	var url = 'print.aspx' + query;
	var name = 'Printer friendly';
	var attributes = 'width=550,height=440';
	
	window.open(url , name, attributes);
}

function CMD()
{
	var url = 'cmd.aspx?100:1:1';
	var name = 'Dockland | Administration';
	
	window.open(url , name, optionsPopup0);
}

function CloseCourse(courseWin) {
	courseWin.close();
}


function categories(num)
{
	
	ToggleLayer("cats");
				
}

function coach()
{
	// placeholder for Coach start
}

function CategoryClick(id)
{ 
   var row = "_ctl1_Editor__ctl0__ctl16__ctl0_" + id;
   var obj = GetElement(row);
    
   if(obj.style.display == 'none'){ 
      obj.style.display =''; 
   }else{ 
      obj.style.display ='none'; 
   } 
   
}

function ToggleTableRow(id)
{ 

   var trs = "TRS" + id;
   var trb = "TRB" + id;  
   

   /*
   var obj = GetElement(trs);
    
   if(obj.style.display == 'none'){ 
      obj.style.display =''; 
   }else{ 
      obj.style.display ='none'; 
   } 
*/

   var obj = GetElement(trb);
    
   if(obj.style.display == 'none'){ 
      obj.style.display =''; 
   }else{ 
      obj.style.display ='none'; 
   } 


}

function ToggleMoverRow(id)
{
	var i = id+"i";
	var a = id+"a";
	var r = id+"r";  

   	var obj = GetElement(id);
   	var obji = GetElement(i);
   	var obja = GetElement(a);
	var objr = GetElement(r);
   
   	if (obj.style.visibility == 'hidden') {
	  	
		obj.style.visibility ='visible';
		objr.innerHTML = obja.innerHTML;
		
   	} else {
	
	  	obj.style.visibility ='hidden';
		objr.innerHTML = obji.innerHTML;
   	}
}

	
function ToggleLayer(id) { //v6.0
	
	var layer = GetElement(id);
	
	if(layer)
	{
		if(layer.style.visibility == "visible")
			layer.style.visibility = "hidden";		
		else
			layer.style.visibility = "visible";
	}

}



function AddPreview(preview, height)
{
	Previews[Previews.length] = preview;
	PHeights[PHeights.length] = height;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Desc: Scrolling im Preview 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

function scrollV(id, direction)
{
	//var current = document.getElementById(id).style.top;
	var object  = document.getElementById(id);
	var height  = parseInt(object.style.height);
	
	var base = parseInt(object.style.top) + (1 * direction);
	
	if(base < (-1 * height))
		base = (-1 * height);
	if(base > 0)
		base = 0;
				
	window.status=height + " " + base;
		
 	object.style.top = base + "px" ;
	
	var functionstring = "scrollV('" + id + "'," + direction + ")";
	
	ScrollID = setTimeout(functionstring, 0);
	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Desc: Schliesst ein Preview 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

function closePV(id, ht)
{
	//var current = document.getElementById(id).style.top;
	var object  = document.getElementById(id);
	
	if(parseInt(object.style.height) > 30)
 		object.style.height = 30 + "px" ;
	else
 		object.style.height = ht + "px" ;	

	Validate(0);
	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Desc: Stop des Scrolling im Previews 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

function scrollStop()
{
	clearTimeout(ScrollID);
	ScrollID = 0;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Desc: Validiert die Positionen der Previews 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

function Validate(initialize)
{
	
	var moretop = 118;
	
	for (var i=0; i<Previews.length; i++) {
		
		var id = Previews[i];
		var hg = PHeights[i];
		
		var object  = document.getElementById(id);
		
		object.style.top = moretop + "px" ;
		
		if((initialize == 1 && i < 1) || (initialize == 1 && Previews.length < 4))
				object.style.height = hg + "px" ;
				
		moretop = moretop + parseInt(object.style.height) + 5;
		
	}
	
	SetPageHeight(moretop - 118);
	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Desc: Setzt die Höhe des Inhaltelements
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

function SetPageHeight(height)
{
		var object  = document.getElementById("pageheight");
		if(object != null)
		{
			if(height > 500)	
				object.style.height = height + "px" ;
			else
				object.style.height = 500 + "px" ;
		}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Desc: Delete
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

function Delete(layerid) { //v6.0
	
	GetDeletableItems();
	
	var layer = GetElement(layerid);
		
	if(layer) {
		if(layer.style.visibility == "visible")
			layer.style.visibility = "hidden";		
		else
			layer.style.visibility = "visible";
	}
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Desc: Funktion zur Darstellung der Daten beim Löschen 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

function GetDeletableItems()
{
	var items = "";
	var arrCheckboxes = document.getElementsByTagName("input");
	
	for (var i=1;i<arrCheckboxes.length;i++) {
		
		if (arrCheckboxes[i].name.indexOf(":chkRep") > -1) {
			
			if (arrCheckboxes[i].checked) {
				
				if (arrCheckboxes[i+2].name == "hdnRepItem") {
				
					items += "- " + arrCheckboxes[i+2].value + "\n";
				}
			}
		}
	}
	var layer = GetElement("dispdelitems");
	if (layer) { layer.innerText = items; }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Desc: De/Selektiert Checkboxen im Explorer
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Funktion fürs JavaScript Menu verwendet im Dockland Framework Explorer
// mode 0 = normal
// mode 1 = umkehren
// mode 2 = alle aktiven
// mode 3 = alle inaktiven

function CheckBoxSelAll(mode)
{
	var arrCheckboxes = document.getElementsByTagName("input");
	var selected = false;
	for (var i=1;i<arrCheckboxes.length;i++) {
		// hiddenfield zum aktuellen check status zw. speichern
		if (arrCheckboxes[i].name == "checkboxSel") {
			selected = (arrCheckboxes[i].value == 1) ? true : false;
			
			if (selected) {
				arrCheckboxes[i].value = 0;
			} else {
				arrCheckboxes[i].value = 1;
			}
		}
		
		// falls im UI eine checkbox benutzt wird
		if (arrCheckboxes[i].name != "checkboxall") {
			
			if (mode == 0) {
				if (arrCheckboxes[i].name.indexOf(":chkRep") > -1) {
					arrCheckboxes[i].checked = selected;
				}
			}
			
			if (mode == 1) {
				if (arrCheckboxes[i].name.indexOf(":chkRep") > -1) {
					arrCheckboxes[i].checked = !arrCheckboxes[i].checked;
				}
			}
			
			if (mode == 2) {
				if (arrCheckboxes[i].name.indexOf(":chkRep") > -1) {
					if (arrCheckboxes[i+1].name == "hdnRep") {
						if (arrCheckboxes[i+1].value == "True") {		
							arrCheckboxes[i].checked = true;
						} else {
							arrCheckboxes[i].checked = false;
						}
					}
				}
			}
			
			if (mode == 3) {
				if (arrCheckboxes[i].name.indexOf(":chkRep") > -1) {
					if (arrCheckboxes[i+1].name == "hdnRep") {
						if (arrCheckboxes[i+1].value == "False") {		
							arrCheckboxes[i].checked = true;
						} else {
							arrCheckboxes[i].checked = false;
						}
					}
				}
			}
		}
	}
}