function getHtmlObject(myNameId) {
// returns document HTML object, if exists. 
// Usage: if getHtmlObject(myNameId) do_something();
	try {
		return (document.getElementById(myNameId));
	} catch(e) {}
}

/***************************************
Preklaplanje med div elementi
***************************************/
function switchTab(obj, obj2, obj3) {
	if (document.all) {
		var ob1 = eval(obj);
		var ob2 = eval(obj2);
		var ob3 = eval(obj3);
		ob1.style.display = 'block';
		ob2.style.display = 'none';
		if(obj3)
			ob3.style.display = 'none';
	} else {
		document.getElementById(obj).style.display = 'inherit';
		document.getElementById(obj2).style.display = 'none';
		if(obj3)
		  document.getElementById(obj3).style.display = 'none';
	}
}


/*

*/
function setRadio(obj){
	document.getElementById(obj).checked = true;
}

/************************************************************
String stevilski formater
*************************************************************/
function formatThousand(value) {

	var outValue = '';
	var svalue = '';
	var iValue = parseInt(value); //cel del
	var rValue = RoundResult(parseFloat(value) - iValue); //ostanek
	
	//celostevilski del
	svalue = iValue.toString();
	cntplus = 0;
	for (cnt = svalue.length - 1; cnt >= 0; cnt--) 
	{
		cntplus++;
		outValue = svalue.charAt(cnt) + outValue;
		if (cntplus % 3 == 0 && cnt > 0) outValue = '.' + outValue;
	}
	
	//decimalni del
	if (rValue > 0)
	{
		outValue = outValue +',';
		svalue = rValue.toString();
	
		for (cnt = 2; (cnt < svalue.length & cnt < 4); cnt++) 
		{
			outValue = outValue + svalue.charAt(cnt) ;
		}
		
		for (cnt; cnt < 4; cnt++) 
		{
			outValue = outValue + '0' ;
		}
	}
	else
	{
		outValue = outValue + ',00' ;
	}
	return outValue;
}

function getHeight() {
	var varHeight;
	
	if (window.innerHtml) varHeight = window.innerHtml;
	else varHeight = document.body.clientHeight;
	
  return varHeight;
}

function setRoomId(curItem, maxItems, itemId) {
/*************************************************************************
	Funkcija prenese število id v sobo
*************************************************************************/
//	alert(curItem + ' ' + maxItems + ' ' + itemId);
	var fo = window.top.document.forms["frmSobe"];
	var objSobaId
	if (curItem < maxItems) {
		objSobaId = fo.statSobaId;
		if (!objSobaId.name) objSobaId = fo.statSobaId[curItem];
	} else {
		objSobaId = fo.sobaId;
	}
	objSobaId.value = itemId;
//	alert(objSobaId.value);
}

function checkValue(obj) {
	if (obj.value == 'vnesite e-naslov') obj.value = '';
}

function mNumberFormat(number) {
    number = '' + number
    if (number.length > 3) {
        var mod = number.length%3;
        var output = (mod > 0 ? (number.substring(0,mod)) : '');
        for (i=0 ; i < Math.floor(number.length/3) ; i++) {
            if ((mod ==0) && (i ==0))
                output+= number.substring(mod+3*i,mod+3*i+3);
            else
                output+= '.' + number.substring(mod+3*i,mod+3*i+3);
        }
        return (output);
    }
    else return number;
}

function showLogin() {
	if (document.all) {
		top.prijava.style.display='block';
		top.nprijava.style.display='none';
		if (top.selObj != null) {
			obj2 = eval('top.'+top.selObj)
			obj2.style.display = 'none';
		} 
		if (top.selSubObj != null) {
			obj2 = eval('top.'+top.selSubObj)
			obj2.style.display = 'block';
		} 
	} else {
		top.document.getElementById('prijava').style.display='inherit';
		top.document.getElementById('nprijava').style.display='none';
		if (top.selObj != null) top.document.getElementById(top.selObj).style.display = 'none';
		if (top.selSubObj != null) top.document.getElementById(top.selSubObj).style.display = 'inherit';
	}
	
	top.selObj = 'prijava';
	top.selSubObj = 'nprijava';
}

function reloadGeo(geoId, wType) {
	top.window.location.href='destinacije-koncna.asp?geoid='+geoId+'&wt='+wType;
}

function prepareDDObj(objItem) {
	while (objItem.length > 0) objItem.remove(0);
	objItem.options[objItem.length] = new Option('Berem podatke...', '');
}

function showPayChecks(reqorderid) {
	window.open('poloznice.asp?reqorderid='+reqorderid, 'Poloznica', 'toolbar=no,width=680,height=430,titlebar=no,scrollbars=yes,resizable=no,location=no');
}

function ISremoveAll(objItem) {
	while (objItem.length > 0) objItem.remove(0);
}

function ISaddItem(objItem, id, value) {
	objItem.options[objItem.length] = new Option(value, id);
}

function isPassword(value) {
/*
	Dovoljeni characterji:
			65 - 90		a..z
			97 - 122	A..Z
			48 - 57		0..9
			dodatni		_,.-
*/
	if (isEmpty(value)) return false;
	value = String(value)
	for (cnt = 0; cnt < value.length; cnt ++) {
		if	(!(	(value.charCodeAt(cnt) >= 49 && value.charCodeAt(cnt) <= 57) || 
				(value.charCodeAt(cnt) >= 65 && value.charCodeAt(cnt) <= 90) || 
				(value.charCodeAt(cnt) >= 97 && value.charCodeAt(cnt) <= 122) || 
				(value.charCodeAt(cnt) == '-') || (value.charCodeAt(cnt) == '_') ||
				(value.charCodeAt(cnt) == '.') || (value.charCodeAt(cnt) == ',')	)) {
			return false;
		}
	}

	return true;
}
	
function isEmail(value) {
    if (isEmpty(value)) return false;
	    
    var afna = value.indexOf('@');
    var rightafna = value.lastIndexOf('@');
    var pika = value.indexOf('.');
    var rightpika = value.lastIndexOf('.');
    var length = value.length;

    if ((afna == -1) || (pika == -1) || (length < 6) || (rightpika < afna) || (rightpika - 1 == afna) || (pika + 1 == afna) || (rightafna != afna)) return false;
    return true;
}

function lTrim(value) {
	if (value == '' || value=='undefined') return '';
	value = String(value);		
	var i = 0;
	while (value.charAt(i) == ' ' && i < value.length) i++;
		
	return value.substr(i, value.length - i);
}
	
function rTrim(value) {
	if (value == '' || value=='undefined') return '';
	value = String(value);		
	var i = value.length - 1;
	while (value.charAt(i) == ' ' && i >= 0) i--;
		
	return value.substr(0, i + 1);
}
	
function trim(value) {
	return rTrim(lTrim(value));
}

function isEmpty(value) {
	var valueOut = '';
	value = String(value);
	if (value == '' || value=='undefined') return true;
	value = trim(value)
	if (value.length == 0 || value == '' || value=='undefined') return true;
	return false;
}

function hideDiv(obj) {
	if (document.all) {
		if (document.getElementById(obj) ) {
			obj1 = eval(obj);
			obj1.style.display = 'none';
		}
	} else if (document.getElementById(obj) ) {
		document.getElementById(obj).style.display = 'none';
	}
}


function showDiv(obj) {
	if (document.all) {
		if (document.getElementById(obj) ) {
			obj1 = eval(obj);
			obj1.style.display = 'block';
		}
	} else if (document.getElementById(obj)) {
		document.getElementById(obj).style.display = 'block';
	}	
}

function changeContent(wpid, frmName, dateid, period, prefix){
	frmName.document.location.href = prefix + 'rezervacijeSobe.asp?datumper=' + dateid + '|' + period + '&wpid=' + wpid;
}

function changeSubContent(wpid, frmName, dateid, period, prefix, isoba){
	frmName.document.location.href = prefix + 'rezervacijeNovaSoba.asp?datumper=' + dateid + '|' + period + '&wpid=' + wpid + '&isoba=' + isoba;
}

function submitDestination(frmName, vGeoid, vWT) {
	var fo = document.forms[frmName];
	var objGeoID = fo.geoid;
	var objWT = fo.wt;
	objGeoID.value = vGeoid;
	objWT.value = vWT;
	fo.submit();
}

function submitLastMinute(frmName, vWpid, vPID, vDatum, vDays, pageID, fAction) {
  var fo = document.forms[frmName];
  var objWPID = fo.wpid;
  var objPID = fo.pid;
  var objDatum = fo.datum;
  var objDays = fo.days;
  var objPageID = fo.pageid;
  objWPID.value = vWpid;
  objPID.value = vPID;
  objDatum.value = vDatum;
  objDays.value = vDays;
  objPageID.value = pageID;
  fo.action = fAction;
  fo.target = '_parent';
  fo.submit();
}

function submitPageForm(vWpid, vDatum, vDays, vPID, vDID, pageID) {
	var fo = document.forms['pocNaprej'];
	var objWPID = fo.wpid;
	var objDatum = fo.datum;
	var objPID = fo.pid;
	var objDID = fo.did;
	var objPageID = fo.pageid;
	var objDays = fo.days;
	objWPID.value = vWpid;
	objDatum.value = vDatum;
	objPID.value = vPID;
	objDID.value = vDID;
	objPageID.value = pageID;
	objDays.value = vDays;
	fo.submit();
}

function GoTo(sLink)
{
	sLink = unescape(sLink);	
	document.location.href = sLink;
}

function getDaysPerMonth(sDate) {
		
	var monthNo = sDate.substring(3,5);
	var p_year = sDate.substring(6,10);
	var DOMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
	var lDOMonth = [31,29,31,30,31,30,31,31,30,31,30,31];

	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)	
			return DOMonth[monthNo - 1];
		return lDOMonth[monthNo - 1];
	} else 
		return DOMonth[monthNo - 1];
}
	
function fillDaysList(objItem, maxdays) {
	var index = objItem.selectedIndex;
	while (objItem.length > 0) objItem.remove(0);
	objItem.options[objItem.length] = new Option("-", "-1");
	for (i = 1; i <= getDaysPerMonth(maxdays); i++) objItem.options[objItem.length] = new Option(i + ".", i);
	if (index > objItem.length - 1) index = 0;
	objItem.selectedIndex = index;
}

function reloadPeriod(frm, subObj, id, subId, wizpid) {
	top.footer.document.location.href = '../bottom.asp?formName=' + frm + '&objName=' + subObj + '&useSub=2&id=' + id + '&subId=' + subId + '&wpid=' + wizpid;
}

function reloadPeriod2(frm, subObj, id, subId, wizpid, ipos) {
	top.footer.document.location.href = 'bottom.asp?formName=' + frm + '&objName=' + subObj + '&useSub=2&id=' + id + '&subId=' + subId + '&wpid=' + wizpid + '&ipos=' + ipos;
}

function reloadRootPeriod(frm, subObj, id, subId, wizpid, ipos) {
	var footerdoc = eval('top.footer'+ipos);
	footerdoc.document.location.href = 'bottom.asp?formName=' + frm + '&objName=' + subObj + '&useSub=4&id=' + id + '&subId=' + subId + '&wpid=' + wizpid;
}

function reloadRootPeriod2(frm, subObj, id, subId, wizpid, ipos) {
	var footerdoc = eval('top.footer'+ipos);
	footerdoc.document.location.href = 'bottom.asp?formName=' + frm + '&objName=' + subObj + '&useSub=4&id=' + id + '&subId=' + subId + '&wpid=' + wizpid + '&ipos=' + ipos;
}

function reloadRootPeriodR(frm, subObj, id, subId, wizpid, ipos) {
	var footerdoc = eval('top.footer'+ipos);
	footerdoc.document.location.href = '../bottom.asp?formName=' + frm + '&objName=' + subObj + '&useSub=4&id=' + id + '&subId=' + subId + '&wpid=' + wizpid;
}

function reloadRootPeriod2R(frm, subObj, id, subId, wizpid, ipos) {
	fo = document.forms['izbDatumper']
	fo.datumper.value = id + '|' + subId;
	fo.action = 'rezervacije-1_korak.asp';
	fo.submit();
	
	//var footerdoc = eval('top.footer'+ipos);
	//footerdoc.document.location.href = '../bottom.asp?formName=' + frm + '&objName=' + subObj + '&useSub=4&id=' + id + '&subId=' + subId + '&wpid=' + wizpid + '&ipos=' + ipos;
}

function reloadContent(frm, subObj, id, subId) {
	top.footer.document.location.href = '../bottom.asp?formName=' + frm + '&objName=' + subObj + '&useSub=3&id=' + id + '&subId=' + subId;
}
	
function reloadsub(frm, subObj, id, subId, wtid, sPortalBase) {
	top.footer.document.location.href = sPortalBase + '/bottom.asp?formName=' + frm + '&objName=' + subObj + '&useSub=1&id=' + id + '&subId=' + subId + '&wtid=' + wtid;
}

function reloadsub2(frm, subObj, id, subId, wtid, sPortalBase) {
	top.footer2.document.location.href = sPortalBase + '/bottom.asp?formName=' + frm + '&objName=' + subObj + '&useSub=1&id=' + id + '&subId=' + subId + '&wtid=' + wtid;
}

function getMe() {
	if (!document.layers) {
		a = parent.document.getElementsByTagName('iframe');
		var strClass = "";
		for (var i=0;i < a.length; i++) {
			id = a[i].id;
			frm = parent.frames[id];
			if ((frm != undefined) && (a[i].src.indexOf('facebook') <= 0))
			{
				
				if (frm.document && frm.document.body) {
					var inrHtml = frm.document.body.innerHTML;
					if (inrHtml == document.body.innerHTML && a[i]) {
						return a[i];
					}
				}
			}
		}
		return null;
	}
	return null;
}
//onload = resizeMe;

function resizeMe() {
	var sh;
	var isNav = false;
	if (navigator.appName.indexOf("Netscape") >= 0) isNav = true;

	if (document.body && document.body.scrollHeight && document.body.offsetHeight) sh = Math.max(document.body.scrollHeight,document.body.offsetHeight);
	/*else sh = document.height;*/
	else sh = document.body.scrollHeight;
	
	sh = sh + 10;
//	if (isNav == true) sh = sh + 10;
	
	var o = getMe();
	if (o) {
		
		sh = sh - 10;
		if (o.height) o.height = sh;
	} else if (document.layers) {
		var layer = '';
		if (parent.document.layers['roomContent']) layer = 'roomContent';
		else if (parent.document.layers['room2Content']) layer = 'room2Content';
		else if (parent.document.layers['roomContent2']) layer = 'roomContent2';
		else if (parent.document.layers['roomContent3']) layer = 'roomContent3';
		else if (parent.document.layers['roomContent4']) layer = 'roomContent4';
		if (layer!='') {
			sh = sh - 10;
			ph = parent.document.layers[layer].top + sh;
			parent.document.height = (ph>window.innerHeight)? ph : window.innerHeight;
		}
	}
}

function getMe() {
	if (!document.layers) {
		a = parent.document.getElementsByTagName('iframe');
		var strClass = "";
		for (var i=0;i < a.length; i++) {
			id = a[i].id;
			frm = parent.frames[id];
			if ((frm != undefined) && (a[i].src.indexOf('facebook') <= 0))
			{
				
				if (frm.document && frm.document.body) {
					var inrHtml = frm.document.body.innerHTML;
					if (inrHtml == document.body.innerHTML && a[i]) {
						return a[i];
					}
				}
			}
		}
		return null;
	}
	return null;
}
//onload = resizeMe;

function resizeMe() {
	var sh;
	var isNav = false;
	if (navigator.appName.indexOf("Netscape") >= 0) isNav = true;

	if (document.body && document.body.scrollHeight && document.body.offsetHeight) sh = Math.max(document.body.scrollHeight,document.body.offsetHeight);
	/*else sh = document.height;*/
	else sh = document.body.scrollHeight;
	
	sh = sh + 10;
//	if (isNav == true) sh = sh + 10;
	
	var o = getMe();
	if (o) {
		
		sh = sh - 10;
		if (o.height) o.height = sh;
	} else if (document.layers) {
		var layer = '';
		if (parent.document.layers['roomContent']) layer = 'roomContent';
		else if (parent.document.layers['room2Content']) layer = 'room2Content';
		else if (parent.document.layers['roomContent2']) layer = 'roomContent2';
		else if (parent.document.layers['roomContent3']) layer = 'roomContent3';
		else if (parent.document.layers['roomContent4']) layer = 'roomContent4';
		if (layer!='') {
			sh = sh - 10;
			ph = parent.document.layers[layer].top + sh;
			parent.document.height = (ph>window.innerHeight)? ph : window.innerHeight;
		}
	}
}


function openMinWindow(name, url, wwidth, wheight) {
	var w = window.open(url, name, 'width=' + wwidth +', height=' + wheight + ', left=0, top=0, menubar=no, status=no, location=no, toolbar=no, scrollbars=no, resizable=no');
}

function SendToFriend(url)
{
	window.open('/priporoci_prijatelju.asp?'+url, 'priporoci', 'width=600, height=673, left=450, top=0, menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=yes');
}
function Poslji()
{
	var fo = document.forms['frmSend'];
	fo.submit();
}

function HideShowDiv(divname) {

	var obj = document.all(divname);
	
	if (obj.style.display == 'none')
	{
		obj.style.display = 'block';
	}
	else
	{
		obj.style.display = 'none';
	}
	
}
/* NOTE: podvojena funkcija LN:239
function showDiv(obj) {
	if (document.all) {
		obj1 = eval(obj);
		obj1.style.display = 'block';
	} else {
		document.getElementById(obj).style.display = 'block';
	}	
}
*/


/* CheckInput checks for empty input and shows message */
function CheckInput(frmName, txtInput, lnkAction) {
	var fo = document.forms[frmName];
	var strIn = fo.sstring;
	//alert('!' + strIn.value.length + '!' + strIn.value + '!');
	if (strIn.value.length < 3 ) { 
		alert('Prosimo, vnesite iskalne kriterije (najmanj 3 črke).');
		//document.getElementById(txtInput).focus();

		fo.action = 'JavaScript:CheckInput('+ "'" + frmName + "','" + txtInput + "','" + lnkAction + "');";
		//document.all(txtInput).focus();
		document.all(txtInput).focus();
	} else {
		//alert(strIn.value + ' ! ' + lnkAction);
		fo.action = lnkAction;
		fo.submit();
	}
}


/* Trap Enter Key */
function fnTrapBtn(btn){
 if (document.all){
   if (event.keyCode == 13)
   { 
     event.returnValue=false;
     event.cancel = true;
     //btn.click();
     CheckInput('frmSearch', 'sstring', 'destinacijeRezultat.asp');
   } 
 } 
}


function OpenPopupWH(lnkName, lnkTitle, width, height){
	win = window.open(lnkName, 'lnkTitle',"WIDTH=" + width + ",HEIGHT=" + height + ",resizable=1,SCROLLBARS=YES");
	win.focus();
};


// disables all fields in given form
function disableFields(frmName) {
	var fo = document.forms[frmName];
	
	for (var i=0; i < fo.elements.length; i++) {
    	fo.elements[i].disabled = true;
    }
	
}

// enables all fields in given form
function enableFields(frmName) {
	var fo = document.forms[frmName];
	
	for (var i=0; i < fo.elements.length; i++) {
    	fo.elements[i].disabled = false;
    }
	
}

// disables all fields in given form of parent page
function disableParentFields(frmName) {
	var fo = parent.document.forms[frmName];
	
	for (var i=0; i < fo.elements.length; i++) {
    	fo.elements[i].disabled = true;
    }
	
}

// enables all fields in given form on parent page
function enableParentFields(frmName) {
	var fo = parent.document.forms[frmName];
	
	for (var i=0; i < fo.elements.length; i++) {
    	fo.elements[i].disabled = false;
    }	
}

function showLink(loc) {
	var locid = document.getElementById('preview');
	window.open(loc, null, 'height=800,width=900,left=200,status=yes,toolbar=no,menubar=no,location=no,channelmode=0');
}


function SearchFieldFocus() {
	if (getHtmlObject('sstring')) try {getHtmlObject('sstring').focus();} catch(e) {}
}

function showRadioSection(obj,type){
	if(type==null)
		document.getElementById(obj).style.display = 'inherit';
	else //type: none
		document.getElementById(obj).style.display = type;
}

function autoIFrameResize(id){
    var newheight;
    var newwidth;

    if(document.getElementById){
        newheight=document.getElementById(id).contentWindow.document.body.offsetHeight;
    }

    document.getElementById(id).height= (newheight) + "px";
    
}

// gallery
function checkUser(){

	jQuery.ajax({
		url: "program/gallery/ajax.asp",
		success: function(html){
			if (html === "false"){
				$("#galadm").html('');
				$("#galadm").remove();
			}
			else{
				$("#galadm").html(html);
			}
		}
	});

}


