﻿/*  Etrips JavaScript framework, version 1.0.0
 *
 *  General Etrips javascript file
 *
/*--------------------------------------------------------------------------*/

function windowOpen(url)
{
	myPopUp = window.open(url, '', 'width=700,height=600,status=yes,resizable=yes');
	if (!myPopUp.opener)
		myPopUp.opener = self;
	m_popUp = myPopUp;
}

function windowOpen2(url, title, param) {
    myPopUp = window.open(url, title, param);
    if (!myPopUp.opener)
        myPopUp.opener = self;
    m_popUp = myPopUp;
}


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 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, languageId, documentName, width, height) {
	var url;
	var options;
	var name = 'DocumentDialog';

	if (window.showModalDialog) {
		// open modal dialog
		url = 'DocumentDialogWindow.aspx?languageid=' + languageId + '&documentname=' + documentName + '&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/ImageDialogWindow.aspx?languageid=' + languageId + '&documentname=' + documentName + '&ismodal=0' + '&updocumentsid=' + upDocumentsId + '';
		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 changeText(id, text, mode)
{
	var obj = $get(id);
	obj.innerHTML = text;
	if (mode == 'out')
	{
		obj.style.color = '#265C3A';
	}
	else
	{
		obj.style.color = '#00388B';
	}
}
