﻿// Searches a given comboBox for a value
// if the value is found, it selects the value and returns true
// otherwise false is retured
//
// Parameters:
//	comboBox: the ComboBox (SELECT element) in which to search for the value
//	value		: the (string) value to search for
//
// Return Type: boolean
function SetComboBoxSelected(comboBox, value){
	var found=false;
	if (comboBox.type!='select-one')
		return false;
	comboBox.selectedIndex=-1;
	for (var i=0;i<comboBox.length;i++){
		if (comboBox.options[i].value==value) {
			comboBox.selectedIndex=i;
			found=true;
			break;
		}
	}
	return found;
}

// Clears a given comboBox
//
// Parameters:
//	comboBox: the ComboBox (SELECT element) to clear
//
// Return Type: boolean
function ClearComboBox(comboBox){
	if (comboBox.type!='select-one')
		return false;
	while (comboBox.length!=0){
		comboBox.remove(0);
	}
	return true;
}

// Formats a date from 'dd.mm.yyyy' format to 'yyyymmdd' format
//
// Parameter: dateString - the string in the dd.mm.yyyy format
//
// Return Type: string
function FormatDateReverse(dateString){
	var result=dateString.substr(6,4);
	result+=dateString.substr(3,2);
	result+=dateString.substr(0,2);
	return result;
}

//Pads the source string from the left for up to count characters of lenght with padChar
// Parameter: dateString - the string in the dd.mm.yyyy format
//
// Return Type: string
function PadFront(source, count, padChar){
	var result=source.toString();
	while (result.length<count) {
		result=padChar+result;
	}
	return result;
}

/* A helper function, returns an javascript object given its name
// Parameters:
//		objName - The design-time name of the component
//		prefix - 
//			Usage1 (boolean): 
//				If false, returns the object with the same name as objName
//				If true or undefined, adds a prefix to the name, defined by the global variable ctrlPrefix
//			Usage2 (string) :
//				Appends the provided prefix string to the control name and returns the so-called object.
// Return Type: object
*/
function getObject(objName,prefix){
	if ((prefix==undefined)||(prefix==true)){
		return document.getElementById(ctrlPrefix+objName);
	}else if (prefix==false){
		return document.getElementById(objName);
	}else{
		return document.getElementById(prefix+objName);
	}
}

function alertDebug(message){
	if (debug!=undefined)
		if (debug==true)
			alert(message);
}

function ShowDateOnClock(){
	var clock=document.getElementById("Clock");
	var timeDisplay=formatDate(new Date())
	clock.innerHTML=timeDisplay;
	setTimeout('ShowDateOnClock()',1000);
}


function formatDate(date){
	var result;
	try {
		var month=date.getMonth()+1;
		result="<strong>"
					+PadFront(date.getDate(),2,'0')+"."
					+PadFront(month,2,'0')+"."
					+date.getFullYear()+"</strong><br />"
					+PadFront(date.getHours(),2,'0')+":"
					+PadFront(date.getMinutes(),2,'0')+":"
					+PadFront(date.getSeconds(),2,'0');
	} catch(e) {
		result="<strong>--.--.----</strong><br />--:--:--";
	}
	return result;
}

function getWindowSize() {
	var windowWidth = 0, windowHeight = 0;
	if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//Standards Compliant Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if( typeof(window.innerWidth) == 'number' ) {
		//Most Non-IE Browsers
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	var windowSize=new Object();
	windowSize.X=windowWidth;
	windowSize.Y=windowHeight;
	return windowSize;
}
	
function getWindowPos(width, height){
	var windowPos=new Object();
	var windowSize=getWindowSize();
	windowPos.left=(windowSize.X-width)/2;
	windowPos.top=(windowSize.Y-height)/2;
	return windowPos;
}

function getText(el){
	if ('string' == typeof el.textContent) return el.textContent;
	if ('string' == typeof el.innerText) return el.innerText;
	return el.innerHTML.replace(/<[^>]*>/g,'');
}

/*
//Functions for ToolTips

//var offsetxpoint=-60 //Customize x offset of tooltip
//var offsetypoint=20 //Customize y offset of tooltip
//var ie=document.all
//var ns6=document.getElementById && !document.all
var ShowTip=false
var ToolTip=document.getElementById("ToolTip");

//function ietruebody(){
//	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
//}

function ShowToolTip(Text, backColor){
	ToolTip.style.backgroundColor=backColor
	ToolTip.innerHTML=Text
	ShowTip=true
	return false;
}

function MoveToolTip(e){
	if (ShowTip){
		var X=e.pageX : event.clientX+ietruebody().scrollLeft;
		var Y=e.pageY : event.clientY+ietruebody().scrollTop;
		tipobj.style.left=curX+offsetxpoint+"px"
		tipobj.style.top=curY+offsetypoint+"px"
		tipobj.style.visibility="visible"
	}
}

function hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

document.onmousemove=positiontip
*/

//function FillComboHours(comboBox,startHour){
// if (startHour==null) startHour=0;
// ClearComboBox(comboBox);
//	for (var i=startHour;i<24;i++){
//		var opt=document.createElement('option');
//		opt.text=PadFront(i.toString(),2,'0')+':';
//		opt.value=PadFront(i.toString(),2,'0');
//		comboBox.add(opt);
//	}
//}

//function FillComboMins(comboBox, startMin){
//	if (startMin==null) startMin=0;
//	ClearComboBox(comboBox);
//	for (var i=startMin;i<60;i+=5){
//		var opt=document.createElement('option');
//		opt.text=PadFront(i.toString(),2,'0')+':';
//		opt.value=PadFront(i.toString(),2,'0');
//		comboBox.add(opt,null);
//	}
//}