﻿/*  HT JavaScript framework, version 1.0.0
 *
 *  General HT javascript file
 *
/*--------------------------------------------------------------------------*/

function OpenMap(address) {

    var url = "http://zemljevid.najdi.si/search_maps.jsp?q={0}&tab=maps";

    address = Url.encode(address)
    url = String.format(url, address);

    myPopUp = window.open(url, '', 'width=700,height=600,location=no,status=yes,resizable=yes');
    if (!myPopUp.opener) {
        myPopUp.opener = self;
    }
}

function TextLengthExceeded(text, textMaxLength, message) 
{
  var maxlength = new Number(textMaxLength); // Change number to your max length.
  if (text.value.length > maxlength)
  {
	  text.value = text.value.substring(0,maxlength);
	  alert(message);
  }
}

function elementContainsString(elementId, containedString)
{
  var pos = 0;
  
  pos = elementId.indexOf(containedString);
  if (pos >= 0)
  {
    if (elementId.substring(pos) == containedString)
    {
      return true;
    }
  }
  
  return false;
}

function openWindow(url, width, height)
{
	// funkcija, ki odpre novo okno, dolocenih dimenzij brez vsega razen vertikalnega drsnika
	var top, left;
	if (arguments.length > 3)
	{
		if (arguments[3] == 'browser')
		{
			left = window.screenLeft + document.body.clientWidth/2 - width/2;
			top = window.screenTop + document.body.clientHeight/2 - height/2;
		}
	}
	else
	{
		left = window.screen.availWidth / 2 - width / 2;
		top = window.screen.availHeight / 2 - height / 2;
	}
	window.open(url, '', 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=auto,width='+ width +',height='+ height +',left=' + left + ',top=' + top + '', '');
}

function openPhotoDialog(upPhotosId, photoType, languageId, bannerMode, showComments, photoName, width, height)
{
  var url;
  var options;
  var name = 'PhotoDialog';
  
  if (window.showModalDialog)
  {
    // open modal dialog
    url = '../../common/ImageDialogWindow.aspx?ptype=' + photoType + '&languageid=' + languageId + '&bannermode=' + bannerMode + '&comments=' + showComments + '&photoname=' + photoName + '&ismodal=1';
    options = 'dialogwidth: '+ width +'px; dialogheight: '+ height +'px';
    
    var result = window.showModalDialog(url, name, options);
    updatePanel(upPhotosId, result);
  }
  else
  {
    // open new window
    url = '../../common/ImageDialogWindow.aspx?ptype=' + photoType + '&languageid=' + languageId + '&bannermode=' + bannerMode + '&comments=' + showComments + '&photoname=' + photoName + '&ismodal=0' + '&upphotosid=' + upPhotosId + '';
    options = 'width='+ width +',height='+ height +',location=no, menubar=no'
    
    window.open(url, name, options);
  }
}

function openDocumentDialog(upDocumentsId, width, height)
{
  var url;
  var options;
  var name = 'DocumentDialog';
  
  if (window.showModalDialog)
  {
    // open modal dialog
    url = '../../common/DocumentDialogWindow.aspx?ismodal=1';
    options = 'dialogwidth: '+ width +'px; dialogheight: '+ height +'px';
    
    var result = window.showModalDialog(url, name, options);
    updatePanel(upDocumentsId, result);
  }
  else
  {
    // open new window
    url = '../../common/DocumentDialogWindow.aspx?ismodal=0' + '&upfilesid=' + upDocumentsId + '';
    options = 'width='+ width +',height='+ height +',location=no, menubar=no'
    
    window.open(url, name, options);
  }
}

function openItemsDialog(upItemsId, itemType, width, height)
{
  var url;
  var options;
  var name = 'ItemDialog';
  
  if (window.showModalDialog)
  {
    // open modal dialog
    url = '../../common/ItemDialogWindow.aspx?itemtype=' + itemType + '&ismodal=1';
    options = 'dialogwidth: '+ width +'px; dialogheight: '+ height +'px';
    
    var result = window.showModalDialog(url, name, options);
    updatePanel(upItemsId, result);
  }
  else
  {
    // open new window
    url = '../../common/ImageDialogWindow.aspx?itemtype=' + itemType + '&ismodal=0' + '&upitemsId=' + upItemsId + '';
    options = 'width='+ width +',height='+ height +',location=no, menubar=no'
    
    window.open(url, name, options);
  }
}

function updatePanel(upanelId, result)
{
  if (result != null)
  {
    if (result[0] == 'ok')
    {
      __doPostBack(upanelId, '');
    }
    else if (result[0] == 'error')
    {
      // show error message
      alert(result[1]);
    }
  }
}

function showHide(panelId, imgExpandId)
{
  var panel = $get(panelId);
  var img = $get(imgExpandId);
  
  if (panel.style.display == '')
  {
    panel.style.display = 'none';
    img.src = '/main/images/design/plus.gif';
  }
  else
  {
    panel.style.display = '';
    img.src = '/main/images/design/minus.gif';
  }
}

    