//-----------------------------------------------
// Funkcija spremeni označen del v LEVEM meniju
//-----------------------------------------------
function select_left_menu(id_selected, style_name) {
//alert(id_selected);
	if (id_selected=='')
		return false;

	var MenuItem = document.getElementById(id_selected);

	if (MenuItem!=null) {
		eval("document.all." + id_selected + ".className='current';");
		
		/*
		 * Če se naredi moving gif za obrobje označenega dela v meniju.
		 * /
		/*
		if (style_name=='Styles1.css') 
			eval("document.all." + id_selected + ".background='../../images/rzs_okvir.gif';");
		else
			eval("document.all." + id_selected + ".background='../../images/rzs_okvir_big.gif';");
		*/

	}
	
	return true;
}


//-----------------------------------------------
// Funkcija spremeni označen del v ZGORNJEM meniju
//-----------------------------------------------
function select_top_menu(id_selected) {
	if (id_selected=='')
		return false;

	var MenuItem = document.getElementById(id_selected);

	if (MenuItem!=null)
		eval("document.all." + id_selected + ".className='current';");
		
	return true;
}

//-----------------------------------------------
//simulacija vbscript funkcij v javascriptu
//-----------------------------------------------
var vbCr = "\r";
var vbLf = "\n";
var vbCrLf = vbCr + vbLf;
var vbTab = "\t";

function Left(s, n){
	if(n > s.length)
		n = s.length;
	return s.substring(0, n);
}

function Right(s, n){
	var t = s.length;
	if(n > t)
		n = t;
	return s.substring(t - n, t);
}

function Mid(s, n, c){
	var numargs = Mid.arguments.length;
	if(numargs < 3)
		c = s.length - n + 1;
	if(c < 1)
		c = s.length - n + 1;
	if(n + c > s.length)
		c = s.length - n + 1;
	if(n > s.length)
		return "";
	return s.substring(n - 1, n + c - 1);
}

function LTrim(s){
	var i = 0;
	var j = 0;
	for(i = 0; i <= s.length - 1; i++)
		if(s.substring(i, i + 1) != ' '){
			j = i;
			break;
		}
	return s.substring(j, s.length);
}

function RTrim(s){
	var j = 0;
	for(var i = s.length - 1; i > -1; i--)
		if(s.substring(i, i + 1) != ' '){
			j = i;
			break;
		}
	return s.substring(0, j + 1);
}

function Trim(s){
	return LTrim(RTrim(s));
}

function InStr(n, s1, s2){
	var numargs = InStr.arguments.length;
	if(numargs < 3)
		return n.indexOf(s1) + 1;
	else
		return s1.indexOf(s2, n) + 1;
}

function RInStr(n, s1, s2){
	var numargs = RInStr.arguments.length;
	if(numargs < 3)
		return n.lastIndexOf(s1) + 1;
	else
		return s1.lastIndexOf(s2, n) + 1;
}

function Space(n){
	var t = "";
	for(var i = 1; i <= n; i++)
		t = t + " ";
	return t;
}

//j je zaradi rezervirane besede String
function jString(n, c){
	var t = "";
	for(var i = 1; i <= n; i++)
		t = t + c;
	return t;
}

function UCase(s){
	return s.toUpperCase();
}

function LCase(s){
	return s.toLowerCase();
}

function Len(s){
	return s.length;
}

function StrReverse(s){
	var i = s.length;
	var t = "";
	while(i > -1){
		t = t + s.substring(i, i + 1);
		i--;
	}
	return t;
}

//j je zaradi rezervirane besede String
function jReplace(s1, s2, s3) { 
	while(s1.indexOf(s2) != -1) {
		s1 = s1.replace(s2, s3);
	}
	return s1;
}
//-----------------------------------------------


//-----------------------------------------------
// Funkcija vrne vrednost radio button arraya
//-----------------------------------------------
function get_radio_value(radio_name, form_name) {
	
	len = eval("document." + form_name + "." + radio_name + ".length");
	
	for (i=0;i<len;i++) {
	
		tmp = eval("document." + form_name + "." + radio_name + "[" + i + "].checked");
		if (tmp)
			return eval("document." + form_name + "." + radio_name + "[" + i + "].value");
	
	}
		
	return 0;
}

//-----------------------------------------------
//funkcije pri post-anju strani
//ohranjajo vertikalno pozicijo okna s pomočjo zapisa v cookiju.
//uporaba: <body onload="loadScroll();" onunload="saveScroll();">
//-----------------------------------------------
var scroll = (window.scrollTo) ? 1 : 0;

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function saveScroll() {
	if (!scroll) return;
	var now = new Date();
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	var x = document.body.scrollLeft;
	var y = document.body.scrollTop;
	setCookie("xy", x + "_" + y, now);
}

function loadScroll() {
	if (!scroll) return;
	var xy = getCookie("xy");
	if (!xy) return;
	var ar = xy.split("_");
	if (ar.length == 2) scrollTo(parseInt(ar[0]), parseInt(ar[1]));
}
//-----------------------------------------------


//-----------------------------------------------
//	Funkcije za combo box
//-----------------------------------------------

var combo_objects = Array();

function add_combo(field, select, width) {
	combo_objects[combo_objects.length] = Array(field, select, width);
}

function init_combos() {
	for (i=0; i<combo_objects.length;i++) {
		comboBox(combo_objects[i][0], combo_objects[i][1], combo_objects[i][2]);
		//alert(combo_objects[i][0] + ' ' + combo_objects[i][1] + ' ' + combo_objects[i][2]);	
	}
	
}

var ie = document.all? true : false;
var moz = document.getElementById && !document.all ? true : false;
var ns4 = document.layers? true : false;

function get_OT(object){
	
	parent_offset = 0

	if (object.offsetParent!=null)
		parent_offset = get_offsetTop(object.offsetParent)	

	return parent_offset + object.offsetTop;
}


function get_offsetTop(objekt) {

	if (objekt.offsetParent!=null){
		val = get_offsetTop(objekt.offsetParent);
		return val + objekt.offsetTop;
	} else
		return 0;
}

function get_OL(object){
	
	parent_offset = 0

	if (object.offsetParent!=null)
		parent_offset = get_offsetLeft(object.offsetParent)	

	return parent_offset + object.offsetLeft;
}


function get_offsetLeft(objekt) {

	if (objekt.offsetParent!=null){
		val = get_offsetLeft(objekt.offsetParent);
		return val + objekt.offsetLeft;
	} else
		return 0;
}


function getObject(nameStr) {
    if (moz) {
        return document.getElementById( nameStr );
    }
    else if (ie) {
        return document.all[nameStr];
    }
}
function comboBox(inputBox, selectBox, width) {

	cBoxInput = getObject(inputBox);
	cBoxSelect = getObject(selectBox);

	// set combo box functions
	var func_onkeyup = new Function("autoComplete(this,'" + selectBox + "','text',false);");
    cBoxInput.onkeyup = func_onkeyup;
	
	var func_onblur = new Function("this.style.backgroundColor = 'transparent';");
    cBoxSelect.onBlur = func_onblur;

	var func_onChange = new Function("updateInput('" + inputBox + "','" + selectBox + "');");
    cBoxSelect.onchange = func_onChange;

	var func_onKeyDown = new Function("" + inputBox + ".focus();");
    cBoxSelect.onkeydown = func_onKeyDown;

	var func_onFocus = new Function("" + inputBox + ".focus();");
    cBoxSelect.onFocus = func_onFocus;
	// end: set combo box functions

	offset_top = get_OT(cBoxInput);
	offset_left = get_OL(cBoxInput);

	cBoxInput.style.width = width - 16;
	cBoxInput.style.marginRight = 16;
	if(moz) {
		cBoxSelect.style.left = offset_left;
		cBoxSelect.style.top = offset_top;
	}
	else if(ie) {
		cBoxSelect.style.left = offset_left;
		cBoxSelect.style.top = offset_top;
	}
	cBoxSelect.style.width = cBoxInput.offsetWidth + 16;	
	cBoxSelect.style.clip="rect(0,"+(cBoxInput.offsetWidth+18)+","+(cBoxInput.offsetHeight)+","+ (cBoxInput.offsetWidth - 2) + ")";
	cBoxSelect.style.display="block";
	//cBoxSelect.selectedIndex = -1;
	//cBoxInput.focus();

	if (cBoxSelect.selectedIndex!=-1)
		cBoxInput.value = cBoxSelect.options[cBoxSelect.selectedIndex].text;

}

function updateInput(inputBox, selectBox) {
	cBoxInput = getObject(inputBox);
	cBoxSelect = getObject(selectBox);
	cBoxInput.focus();
	cBoxInput.value = cBoxSelect.options[cBoxSelect.selectedIndex].text;
}


function autoComplete (field, select_name, property, forcematch) {
	var found = false;

	select = getObject(select_name);

	for (var i = 0; i < select.options.length; i++) {
		if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
			found=true; break;
		}
	}
	
	if (found) { select.selectedIndex = i; }
	else { select.selectedIndex = -1; }
	
	if (field.createTextRange) {
		if (forcematch && !found) {
			field.value=field.value.substring(0,field.value.length-1); 
			return;
		}
		
		var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
			
		if (cursorKeys.indexOf(event.keyCode+";") == -1) {
			var r1 = field.createTextRange();
			var oldValue = r1.text;
			var newValue = found ? select.options[i][property] : oldValue;
					
				if (newValue != field.value) {
					field.value = newValue;
					var rNew = field.createTextRange();
					rNew.moveStart('character', oldValue.length) ;
					rNew.select();
				}
		}
		
	}
}
//-----------------------------------------------


/*-----------------------------------------------
 funkcija simulira masked-edit-input-box za vnos datuma
 uporaba:
 <form>
 <input type="text" name="testDateFormat" size='10' maxlength="10" onFocus="javascript:vDateType='3'" onKeyUp="DateFormat(this,this.value,event,false,'3')" onBlur="DateFormat(this,this.value,event,true,'3')">
 </form>
 opomba:vDateType='3' pomeni zapis dd/mm/yyyy
*/
//-----------------------------------------------
// Check browser version
var isNav4 = false, isNav5 = false, isIE4 = false
var strSeperator = "."; 
// If you are using any Java validation on the back side you will want to use the / because 
// Java date validations do not recognize the dash as a valid date separator.
var vDateType = 3; // Global value for type of date format
//                1 = mm/dd/yyyy
//                2 = yyyy/dd/mm  (Unable to do date check at this time)
//                3 = dd/mm/yyyy
var vYearType = 4; //Set to 2 or 4 for number of digits in the year for Netscape
var vYearLength = 2; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.
var err = 0; // Set the error code to a default of zero
if(navigator.appName == "Netscape") {
	if (navigator.appVersion < "5") {
		isNav4 = true;
		isNav5 = false;
	}
	else
		if (navigator.appVersion > "4") {
			isNav4 = false;
			isNav5 = true;
		}
}
else {
	isIE4 = true;
}

function DateFormat(vDateName, vDateValue, e, dateCheck, dateType) {
	vDateType = dateType;
	// vDateName = object name
	// vDateValue = value in the field being checked
	// e = event
	// dateCheck 
	// True  = Verify that the vDateValue is a valid date
	// False = Format values being entered into vDateValue only
	// vDateType
	// 1 = mm/dd/yyyy
	// 2 = yyyy/mm/dd
	// 3 = dd/mm/yyyy
	//Enter a tilde sign for the first number and you can check the variable information.
	if (vDateValue == "~") {
		alert("AppVersion = "+navigator.appVersion+" \nNav. 4 Version = "+isNav4+" \nNav. 5 Version = "+isNav5+" \nIE Version = "+isIE4+" \nYear Type = "+vYearType+" \nDate Type = "+vDateType+" \nSeparator = "+strSeperator);
		vDateName.value = "";
		vDateName.focus();
	
		return true;
	}

	var whichCode = (window.Event) ? e.which : e.keyCode;

	// Check to see if a seperator is already present.
	// bypass the date if a seperator is present and the length greater than 8
	if (vDateValue.length > 8 && isNav4) {
		if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
			return true;
	}

	//Check for repeated pattern
	if (vDateValue.indexOf(strSeperator) < 1 && dateCheck && vDateValue.length > 0) {
		alert("Error:0\nNepravilen datum\nPonovi vpis\n\nPravilna oblika: 21.12.2004");
		vDateName.select();
		return false;
	}

	//Eliminate all the ASCII codes that are not valid
	var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
	if (alphaCheck.indexOf(vDateValue) >= 1) {
		if (isNav4) {
			vDateName.select();
			return false;
		}
		else {
			vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
			return false;
	   }
	}

	if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
		return false;
	else {
		//Create numeric string values for 0123456789/
		//The codes provided include both keyboard and keypad values
		var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';

		if (strCheck.indexOf(whichCode) != -1) {
			if (isNav4) {
				if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >=1)) {
					alert("Error:1\nNepravilen datum\nPonovi vpis\n\nPravilna oblika: 21.12.2004");
					vDateName.select();
					return false;
				}
				
				if (vDateValue.length == 6 && dateCheck) {
					var mDay = vDateName.value.substr(2,2);
					var mMonth = vDateName.value.substr(0,2);
					var mYear = vDateName.value.substr(4,4)
					
					//Turn a two digit year into a 4 digit year
					if (mYear.length == 2 && vYearType == 4) {
						var mToday = new Date();
						//If the year is greater than 30 years from now use 19, otherwise use 20
						var checkYear = mToday.getFullYear() + 30; 
						var mCheckYear = '20' + mYear;
						if (mCheckYear >= checkYear)
							mYear = '19' + mYear;
						else
							mYear = '20' + mYear;
					}

					var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
					if (!dateValid(vDateValueCheck)) {
						alert("Error:2\nNepravilen datum\nPonovi vpis\n\nPravilna oblika: 21.12.2004");
						vDateName.select();
						return false;
					}
					
					return true;
				}
				else {
					// Reformat the date for validation and set date type to a 1
					if (vDateValue.length >= 8  && dateCheck) {
						if (vDateType == 1) // mmddyyyy
						{
							var mDay = vDateName.value.substr(2,2);
							var mMonth = vDateName.value.substr(0,2);
							var mYear = vDateName.value.substr(4,4)
							vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
						}
						if (vDateType == 2) // yyyymmdd
						{
							var mYear = vDateName.value.substr(0,4)
							var mMonth = vDateName.value.substr(4,2);
							var mDay = vDateName.value.substr(6,2);
							vDateName.value = mYear+strSeperator+mMonth+strSeperator+mDay;
						}
						if (vDateType == 3) // ddmmyyyy
						{
							var mMonth = vDateName.value.substr(2,2);
							var mDay = vDateName.value.substr(0,2);
							var mYear = vDateName.value.substr(4,4)
							vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
						}

						//Create a temporary variable for storing the DateType and change
						//the DateType to a 1 for validation.
						var vDateTypeTemp = vDateType;
						vDateType = 1;
						var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;

						if (!dateValid(vDateValueCheck)) {
							alert("Error:3\nNepravilen datum\nPonovi vpis\n\nPravilna oblika: 21.12.2004");
							vDateType = vDateTypeTemp;
							vDateName.select();
							return false;
						}

						vDateType = vDateTypeTemp;
						return true;
					}
					else {
						if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
							alert("Error:4\nNepravilen datum\nPonovi vpis\n\nPravilna oblika: 21.12.2004");
							vDateName.select();
							return false;
						}
					}
				}
			}
			else {

// Non isNav Check
if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
alert("Error:5\nNepravilen datum\nPonovi vpis.\n\nPravilna oblika: 21.12.2004");
vDateName.select();
return true;
}
// Reformat date to format that can be validated. mm/dd/yyyy
if (vDateValue.length >= 8 && dateCheck) {
// Additional date formats can be entered here and parsed out to
// a valid date format that the validation routine will recognize.
if (vDateType == 1) // mm/dd/yyyy
{
var mMonth = vDateName.value.substr(0,2);
var mDay = vDateName.value.substr(3,2);
var mYear = vDateName.value.substr(6,4)
}
if (vDateType == 2) // yyyy/mm/dd
{
var mYear = vDateName.value.substr(0,4)
var mMonth = vDateName.value.substr(5,2);
var mDay = vDateName.value.substr(8,2);
}
if (vDateType == 3) // dd/mm/yyyy
{
var mDay = vDateName.value.substr(0,2);
var mMonth = vDateName.value.substr(3,2);
var mYear = vDateName.value.substr(6,4)
}
if (vYearLength == 4) {
if (mYear.length < 4) {
alert("Error:6\nNepravilen datum\nPonovi vpis\n\nPravilna oblika: 21.12.2004");
vDateName.select();
return true;
   }
}
// Create temp. variable for storing the current vDateType
var vDateTypeTemp = vDateType;
// Change vDateType to a 1 for standard date format for validation
// Type will be changed back when validation is completed.
vDateType = 1;
// Store reformatted date to new variable for validation.
var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
if (mYear.length == 2 && vYearType == 4 && dateCheck) {
//Turn a two digit year into a 4 digit year
var mToday = new Date();
//If the year is greater than 30 years from now use 19, otherwise use 20
var checkYear = mToday.getFullYear() + 30; 
var mCheckYear = '20' + mYear;
if (mCheckYear >= checkYear)
mYear = '19' + mYear;
else
mYear = '20' + mYear;
vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
// Store the new value back to the field.  This function will
// not work with date type of 2 since the year is entered first.
if (vDateTypeTemp == 1) // mm/dd/yyyy
vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
if (vDateTypeTemp == 3) // dd/mm/yyyy
vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
} 
if (!dateValid(vDateValueCheck)) {
alert("Error:7\nNepravilen datum\nPonovi vpis\n\nPravilna oblika: 21.12.2004");
vDateType = vDateTypeTemp;
vDateName.select();
return true;
}
vDateType = vDateTypeTemp;
return true;
}
else {
if (vDateType == 1) {
if (vDateValue.length == 2) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 5) {
vDateName.value = vDateValue+strSeperator;
   }
}
if (vDateType == 2) {
if (vDateValue.length == 4) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 7) {
vDateName.value = vDateValue+strSeperator;
   }
} 
if (vDateType == 3) {
if (vDateValue.length == 2) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 5) {
vDateName.value = vDateValue+strSeperator;
   }
}
return true;
   }
}
if (vDateValue.length == 10&& dateCheck) {
if (!dateValid(vDateName)) {
// Un-comment the next line of code for debugging the dateValid() function error messages
//alert(err);  
alert("Error:8\nNepravilen datum\nPonovi vpis\n\nPravilna oblika: 21.12.2004");
vDateName.select();
   }
}
return false;
}
else {
// If the value is not in the string return the string minus the last
// key entered.
if (isNav4) {
vDateName.select();
return false;
}
else
{
if ((whichCode!=37) && (whichCode!=39) && (whichCode!=46))
	vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));

return false;
         }
      }
   }
}


function dateValid(objName) {
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
// var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "Maj";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Avg";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Okt";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
//strDate = datefield.value;
strDate = objName;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
//Adjustment for short years entered
if (strYear.length == 2) {
strYear = '20' + strYear;
}
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
   }
}
else {
if (intday > 28) {
err = 10;
return false;
      }
   }
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

//-----------------------------------------------
//konec datumske validacije
//-----------------------------------------------
//-----------------------------------------------
// Funkkcija gre zaradi entra na naslednji input
//-----------------------------------------------
function keyDown(DnEvents) { 

	k = (ns4) ? DnEvents.which : window.event.keyCode;

	if (k == 13) {
		form = document.activeElement.form;
		active = document.activeElement;

		if ((active.tagName.toUpperCase()=="TEXTAREA") && (window.event.shiftKey))
			return;

		for (i=0; i<form.all.length; i++) {
			//alert(form.all.item(i).tagName);
			
			if (form.all.item(i)==active) {
				break;
			}
		}

		if (i<form.all.length) {
			// find next INPUT, SELECT OR TEXTAREA
			for (j=i+1; j<form.all.length; j++) {
			
				if ((form.all.item(j).tagName.toUpperCase()=="INPUT") ||
				  (form.all.item(j).tagName.toUpperCase()=="SELECT") ||
				  (form.all.item(j).tagName.toUpperCase()=="SELECT") ||
				  (form.all.item(j).tagName.toUpperCase()=="TEXTAREA") ) {
				  
					//alert("R:" + form.all.item(j).tagName);
					form.all.item(j).focus();
					break;
				}
					
			}
		}
		
		return false;
   }
   
}

document.onkeydown = keyDown; // work together to analyze keystrokes
if (ns4) document.captureEvents(Event.KEYDOWN|Event.KEYUP);


//-------------------------------------------------------------// funkcije za premik itemov iz enega selecta v drugega
//-------------------------------------------------------------
// Funkcija vrne id-je optionov selecta, ki ima izbrane iteme
function id_izbrani() {

	vsi = document.form1.izbrani.length;
	izbrani = "";
	
	for (i=0;i<vsi;i++) {
		value = document.form1.izbrani.options[i].value;
		izbrani += value + ",";	
	}
	
	return izbrani;
}

// vrze vse iz levega v desni select
function desno_vse() {
	
	vsi = document.form1.ostali.length;
	
	for (i=0;i<vsi;i++) {
		value = document.form1.ostali.options[0].value;
		text = document.form1.ostali.options[0].text;
		
		opt = new Option(text,value);
		document.form1.izbrani.options.add(opt);
		opt = null;
		
		document.form1.ostali.options[0] = null;
	}

}

// vrze oznacenega iz levega v desni select
function desno() {

	i = document.form1.ostali.selectedIndex;

	if (i==-1) return;
	
	// prenesemo označenega
	value = document.form1.ostali.options[i].value;
	text = document.form1.ostali.options[i].text;
		
	opt = new Option(text,value);
	document.form1.izbrani.options.add(opt);
	opt = null;

	// zbrišemo ga iz prvotnega selecta (sedaj je v drugem)
	document.form1.ostali.options[i] = null;
	
	// v prvem selectu označimo naslednjega (če obstaja)
	if (document.form1.ostali.options[i]!=null)
		document.form1.ostali.selectedIndex=i;
}

// vrze vse iz desnega v levi select
function levo_vse() {

	vsi = document.form1.izbrani.length;
	
	for (i=0;i<vsi;i++) {
		value = document.form1.izbrani.options[0].value;
		text = document.form1.izbrani.options[0].text;
		
		opt = new Option(text,value);
		document.form1.ostali.options.add(opt);
		opt = null;

		document.form1.izbrani.options[0] = null;
	}
}

// vrze oznacenega iz desnega v levi select
function levo() {

	i = document.form1.izbrani.selectedIndex;
	
	if (i==-1) return;

	// prenesemo označenega
	value = document.form1.izbrani.options[i].value;
	text = document.form1.izbrani.options[i].text;
		
	opt = new Option(text,value);
	document.form1.ostali.options.add(opt);
	opt = null;

	// zbrišemo ga iz prvotnega selecta (sedaj je v drugem)
	document.form1.izbrani.options[i] = null;

	// v prvem selectu označimo naslednjega (če obstaja)
	if (document.form1.izbrani.options[i]!=null)
		document.form1.izbrani.selectedIndex=i;
}

// tu odstranimo duplikate optionov:
// tisti optioni, ki so med izbranimi ligami, ne smejo biti v selectu vseh lig
function odstrani_duplikate() {
	vse_izbrane = document.form1.izbrani.length;
	
	if (vse_izbrane==0) return;
	
	for (i=0;i<vse_izbrane;i++) {
		value = document.form1.izbrani.options[i].value;

		vse = document.form1.ostali.length;
		
		for (v=0;v<vse;v++) {
			if (document.form1.ostali.options[v].value == value) {
				document.form1.ostali.options[v] = null;
				break;
			}
		}

	}

}
//-------------------------------------------------------------
/*-----------------------------------------------
formatira HTML za tiskanje iz IE browserja
uporaba:
1. v headu določi style
	<STYLE TYPE="text/css">
		P.breakHere {page-break-before: always}
		BODY {font-family:tahoma; font-size:11px; font-weight:bold;}
		TD {font-family:tahoma; font-size:11px;}
	</STYLE>
2. v script daj to funkcijo
3. v body daj
	- header <div id="myHeader">...</div>
	- tabelo <table id="myTable">...</table> lahko je generirana z asp-jem (naslovna vrstica ne sme biti v for-next zanki)
	- footer <div id="myFooter">...</div>
4. na koncu kliči to funkcijo
	formatPageBreaks('normal', 'myTable', 'myHeader', 'myFooter')
	parametri:
		- strType - preddefinirani stili tabele
		- strTable - id tabele za formatiranje
		- strHeader - id headerja, ki se bo natisnil pred tabelo (če id-ja ni ne napiše ničesar)
		- strFooter - id footerja, ki se bo natisnil pod tabelo (če id-ja ni ne napiše ničesar)
*/
function formatPageBreaks(strType, strTable, strHeader, strFooter){
	intPageHeight=1024; //višina papirja v px - odvisno tudi od printer margins (1024 ustreza A4 s printer margins 10px)
	//privzeta oblika tabele-repeaterja POZOR:cellspacing=0, cellpadding=1, border=1 (če so vrednosti drugačne, funkcija ne deluje pravilno)
	if(strType == "normal"){
		strBreak = "<table width='100%' style='border-collapse: collapse' cellspacing='0' cellpadding='1' border='1' bordercolor='#000000'>";
		strBreak += document.getElementById(strTable).rows[0].outerHTML;
		intFirstRow = 1;
	}
	//ostale custom oblike
	if(strType == "custom"){
		strBreak = "<table width='100%' cellspacing='0' cellpadding='1' border='0'>";
		intFirstRow = 0;
	}

	var pageTop = 0;
	var elBase = 0;
	newContent = strBreak;

	//zanka zavrti vse vrstice tabele, pomeri kumulativno višino in jo primerja z višino strani
	//po potrebi prišteje še header
	//če višina tabele (skupaj s headerjem) presega višino strani jo prelomi in na novi strani doda naslovno vrstico
	for(x = intFirstRow; x < document.getElementById(strTable).rows.length; x++){
		el = document.getElementById(strTable).rows[x];
		//prišteje header samo če obstaja
		if (x == 1 && document.getElementById(strHeader)){
			pageTop = pageTop - document.getElementById(strHeader).offsetHeight;
		}

		elBasePrevRow = elBase;
		elBase = el.offsetTop + el.offsetHeight;

		//višina tabele (skupaj s headerjem) presega višino strani zato vrine page-break
		if(parseInt(elBase - pageTop) > intPageHeight){
			newContent += "</table><p class='breakHere'></p>" + strBreak;
			pageTop = elBasePrevRow;
		}

		newContent += document.getElementById(strTable).rows[x].outerHTML;
	}
	//konec zanke
	newContent += "</table>";
	
	//doda header (če je)
	var oHeader = '';
	if (document.getElementById(strHeader)){
		oHeader = document.getElementById(strHeader).outerHTML;
	}
	//doda footer (če je)
	var oFooter = '';
	if (document.getElementById(strFooter)){
		oFooter = document.getElementById(strFooter).outerHTML;
	}

	//formatirano vsebino prepiše čez staro
	document.body.innerHTML= oHeader + newContent + oFooter;
}
//-----------------------------------------------