﻿function openDialogWindow(cUrl, nWidth, nHeight, lFullScreen) {
    var nTop;
    var nLeft;
    
	if (lFullScreen) {
	    nWidth = screen.width - 8;
	    nHeight = screen.height - 80;
	    nTop = 0;
	    nLeft = 0;
	} else {
	    if (!nWidth) nWidth = 600;
	    if (!nHeight) nHeight = 250;
	    nTop = (screen.height / 2) - (nHeight / 2);
	    nLeft = (screen.width / 2) - (nWidth / 2);
	}
	window.open(cUrl,'','width='+nWidth+',height='+nHeight+',top='+nTop+',left='+nLeft+',status=1,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0');
	return false;
}


function setDialogWindowHeight() {
	var oBottom = window.document.getElementById('divBottom');
	if (oBottom) {
		nHeight = findPosY(oBottom);
		window.resizeTo(getDocumentWidth() + 12, nHeight + 80);
	}
}

function resizeEditorBox(editor) {
    // Have this function executed via TinyMCE's init_instance_callback option!
    // requires TinyMCE3.x
    var container = editor.contentAreaContainer, /* new in TinyMCE3.x -
        for TinyMCE2.x you need to retrieve the element differently! */
        formObj = document.forms[0], // this might need some adaptation to your site
        dimensions = {
            x: 0,
            y: 0,
            maxX: 0,
            maxY: 0
        }, doc, docFrame;

    dimensions.x = formObj.offsetLeft; // get left space in front of editor
    dimensions.y = formObj.offsetTop; // get top space in front of editor

    dimensions.x += formObj.offsetWidth; // add horizontal space used by editor
    dimensions.y += formObj.offsetHeight; // add vertical space used by editor

    // get available width and height
    if (window.innerHeight) {
        dimensions.maxX = window.innerWidth - 0;
        dimensions.maxY = window.innerHeight - 35;
    } else {
        // check if IE for CSS1 compatible mode
        doc = (document.compatMode && document.compatMode == "CSS1Compat")
            ? document.documentElement
            : document.body || null;
        dimensions.maxX = doc.offsetWidth - 0;
        dimensions.maxY = doc.offsetHeight - 20;
    }

    // extend container by the difference between available width/height and used width/height
    docFrame = container.children [0] // doesn't seem right : was .style.height;
    docFrame.style.width = container.style.width = (container.offsetWidth + dimensions.maxX - dimensions.x - 10) + "px";
    docFrame.style.height = container.style.height = (container.offsetHeight + dimensions.maxY - dimensions.y) + "px";
}    

function confirmationDelete(langConfirmationDelete) {
	return window.confirm(langConfirmationDelete);
}

function confirmationClose() {
	return window.confirm(langConfirmationClose);
}

function getDocumentHeight() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function getDocumentWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  } else if (obj.x)
  curleft += obj.x;
  return curleft;
}

function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  } else if (obj.y)
  curtop += obj.y;
return curtop;
}

function changeDate(cType) {
  var oDay = window.document.getElementById('cboDay'+cType);
  var oMonth = window.document.getElementById('cboMonth'+cType);
  var oYear = window.document.getElementById('cboYear'+cType);

  if (((oMonth.selectedIndex == "3")||(oMonth.selectedIndex == "5")||(oMonth.selectedIndex == "8")||(oMonth.selectedIndex == "10")) && (oDay.selectedIndex == "30")) {
    oDay.selectedIndex="29";
  }
  if ((oMonth.selectedIndex == "1") && (oDay.selectedIndex > "27")) {
	if (oYear.value / 4 == parseInt(oYear.value / 4)) {
		oDay.selectedIndex = "28";
    } else {
		oDay.selectedIndex = "27";
	}
  }
}

/********************* article edit **************************/

var nStatusWindow = 0;

function minimizeArticle(oThis) {
    if (nStatusWindow == 1) {
        restoreArticle(oThis);
        oThis.src = '/avista/images/ico-minimize.gif';
    } else {
        parent.document.getElementById('frmArticle').rows = '24,*,24';
        document.getElementById('content').style.display = 'none';
        oThis.src = '/avista/images/ico-restore.gif';
        nStatusWindow = 1;
    }
}

function maximizeArticle(oThis) {
    if (nStatusWindow == 2) {
        restoreArticle(oThis);
        oThis.src = '/avista/images/ico-maximize.gif';
    } else {
        parent.document.getElementById('frmArticle').rows = '24,0,*';
        document.getElementById('content').style.display = 'block';
        oThis.src = '/avista/images/ico-restore.gif';
        nStatusWindow = 2;                
    }
}

function restoreArticle(oThis) {
    parent.document.getElementById('frmArticle').rows = '24,20%,*';
    document.getElementById('content').style.display = 'block';
    nStatusWindow = 0;
}

/********************* section menu **************************/

function confirmSectionDelete(cURL) {
     if (confirm('Smazat ?')) {
        window.location = cURL;
     }
}