/* $Id: functions.js,v 1.21 2002/04/21 11:48:34 loic1 Exp $ */
var popWindow;


function idValue(idv){
  var docum = document.getElementById(idv);
  if (docum){
     return docum.value;
  } else{
     return null;
  }
}

function setIdValue(idv, value){
  var docum = document.getElementById(idv);
  if (docum){
     docum.value = value;
  } 
}

function setCheckbox(idv){
  var docum = document.getElementById(idv);
  if (docum.value == 1){
     docum.value = 0;
  } else {
    docum.value = 1;
  }
}

function getPageSize(idv){
  var docum = document.getElementsByTagName('html');
  if (docum){
  	docum=docum[0];
     return docum.offsetWidth+'x'+docum.scrollHeight+'x'+docum.scrollLeft+'x'+docum.scrollTop;
  } else{
     return '';
  }
}


function openBlock(idv){
  var docum = document.getElementById(idv);
  if (docum){
     return docum.style.display = "block";
  } else{
     return '';
  }
}
function closeBlock(idv){
  var docum = document.getElementById(idv);
  if (docum){
     return docum.style.display = "none";
  } else{
     return '';
  }
}
function openCloseBlock(idv){
  var docum = document.getElementById(idv);
  if (docum.style.display == "none"){
     return docum.style.display = "block";
  } else{
     return docum.style.display = "none";
  }
}
function hoverclass(id,t){
  var theElementStyle = document.getElementById(id);
  var theEdit = document.getElementById('ed'+id);
  var theEditB = document.getElementById('edb'+id);
  if(t == 'txt') {
     theElementStyle.style.border = "1px solid #FF6600";
  }else{
     theElementStyle.style.border = "1px solid #A90000";
  }
      if(theEdit){
        theEdit.style.display = "block";
        theEditB.style.display = "block";
        theEditB.style.background = "#FFF";
        theEditB.style.filter = "alpha(opacity=40)";
        theEditB.style.opacity = ".40";
        theEditB.style.mozopacity = ".40";
      }
}
function hoverclassend(id){
  var theElementStyle = document.getElementById(id);
  var theEdit = document.getElementById('ed'+id);
  var theEditB = document.getElementById('edb'+id);
  theElementStyle.style.border = '';
  theElementStyle.style.background = "";
  theElementStyle.style.filter = "";
  theElementStyle.style.opacity = "";
  theElementStyle.style.mozopacity = "";

    if(theEdit){
        theEdit.style.display = "none";
        theEditB.style.display = "none";
      }
}

function showHelp() {
  var theElementStyle = document.getElementById("openhelpdescr");

  if(theElementStyle.style.display == "none")
  {
   theElementStyle.style.display = "block";
  }
  else
  {
  theElementStyle.style.display = "none";
  }
}

function openDClose(id, skin, idclose) {
  var theElementStyle = document.getElementById('deboxvalue'+id);
  var theImage = document.getElementById('di'+id);

  if(idclose != ""){
     var CloseID = idclose.split("|");
           for(no=0;no<CloseID.length;no++){
                if(CloseID[no] == id){
                } else {
                   var theCl  = document.getElementById('deboxvalue'+CloseID[no]);
                   var theImg = document.getElementById('di'+CloseID[no]);
                    theCl.style.display = "none";
                    theImg.src = 'skin/'+skin+'/editor/e_close.png';
                }
           }
  }
 
  if(theElementStyle.style.display == "none")
  {
   theElementStyle.style.display = "block";
   theImage.src = 'skin/'+skin+'/editor/e_open.png';
  }
  else
  {
  theElementStyle.style.display = "none";
  theImage.src = 'skin/'+skin+'/editor/e_close.png';
  }
}

function moveToNotice() {
	var link = window.location.href;
	link = link.split("#");
	window.location.replace(link[0]+'#notice');
	link = window.location.href;
	link = link.split("#");
	window.location.replace(link[0]+'#noticed');
	return true;
}
/**theImage.innerHTML = '<img src="skin/'+skin+'/editor/e_close.png" alt="Otwórz" />';
 * Opens a window with the data of the specified postcards
 *
 * @param integer    unique id of the postcard
 *
 * @return  boolean  whether to run the query or not
 */
function TEMP_zatwierdz_odrzuc_previewJobOrder(w_num,zatwodrz)
{
	 var winURL = "zoom.php?j=" + w_num + "&zatwodrz=" + zatwodrz ; 
	 if (! popWindow || popWindow.closed) {
	   popWindow = window.open(winURL,"popWindow","dependent,width=565,height=510,scrollbars=yes");
	 } else {
	   popWindow.focus();
		 popWindow.location = winURL;
	 }
	 return false;
} // end of the previewPostcard() function

function previewJobOrder(w_num)
{
	 var winURL = "zoom.php?j=" + w_num; 
	 if (! popWindow || popWindow.closed) {
	   popWindow = window.open(winURL,"popWindow","dependent,width=565,height=510,scrollbars=yes");
	 } else {
	   popWindow.focus();
		 popWindow.location = winURL;
	 }
	 return false;
} // end of the previewPostcard() function

function previewJobType(pr_uid)
{
	 var winURL = "zoom.php?jt=" + pr_uid; 
	 if (! popWindow || popWindow.closed) {
	   popWindow = window.open(winURL,"popWindow","dependent,width=565,height=510,scrollbars=yes");
	 } else {
	   popWindow.focus();
		 popWindow.location = winURL;
	 }
	 return false;
} 

function previewInfo(info_id)
{
	 var winURL = "info_popup.php?id=" + info_id; 
	 if (! popWindow || popWindow.closed) {
	   popWindow = window.open(winURL,"popWindow","dependent,width=626,height=450,scrollbars=yes");
	 } else {
	   popWindow.focus();
		 popWindow.location = winURL;
	 }
	 return false;
} // end of the previewInfo() function

function paymentWindow(pay_url)
{
	 if (! popWindow || popWindow.closed) {
	   popWindow = window.open(pay_url,"popWindow","dependent,width=565,height=450,scrollbars=yes");
	 } else {
	   popWindow.focus();
	   popWindow.close();
	   popWindow = window.open(pay_url,"popWindow","dependent,width=565,height=450,scrollbars=yes");
	 }
	 return false;
} // end of the paymentWindow() function

/**
 * Displays an confirmation box beforme to submit an action.
 * This function is called while clicking links
 *
 * @param   object   the link
 * @param   object   the action description
 *
 * @return  boolean  whether to run the query or not
 */
function confirmLink(theLink, theAction)
{

    var is_confirmed = confirm('Czy na pewno wykonać :\n' + theAction);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
} // end of the 'confirmLink()' function

/**
 * Displays an confirmation box beforme to submit an action.
 * This function is called while clicking buttons
 *
 * @param   object   the action description
 *
 * @return  boolean  whether to run the query or not
 */
function confirmButton(theAction)
{

    var is_confirmed = confirm('Czy na pewno wykonać :\n' + theAction);
		if (is_confirmed) {
        
				theForm1.elements['is_js_confirmed'].value = '1';
    }
    
    return is_confirmed;
} // end of the 'confirmLink()' function

/**
 * Displays an confirmation box beforme to submit an action.
 * This function is called while clicking links
 *
 * @param   object   the link
 * @param   object   the action description
 *
 * @return  boolean  whether to run the query or not
 */
function confirmForm(theLink, theAction)
{

    var is_confirmed = confirm('Czy na pewno wykonać :\n' + theAction);
    if (is_confirmed) {
      return true;
    }

    return false;
} // end of the 'confirmForm()' function


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object   the table row
 * @param   string   the action calling this script (over, out or click)
 * @param   string   the default background color
 * @param   string   the color to use for mouseover
 * @param   string   the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function



var popFaktWindow;

function openFaktoringInfo(theInv)
{
     var winURL = "faktoring_info.php?id=" + theInv; 
	 if (! popFaktWindow || popFaktWindow.closed) {
	   popFaktWindow = window.open(winURL,"popWindow","dependent,width=600,height=400,scrollbars=no");
	 } else {
	   popFaktWindow.focus();
	   popFaktWindow.location = winURL;
	 }
} // end

function openSendSMS(theKlient)
{
	 var winURL = "sendsms.php?klient=" + theKlient; 
	 if (! popWindow || popWindow.closed) {
	   popWindow = window.open(winURL,"popWindow","dependent,width=300,height=240,scrollbars=yes");
	 } else {
	   popWindow.focus();
		 popWindow.location = winURL;
	 }
} // end o


function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
  	}
  	return false;
} 

function openKlientStick(theKlient)
{
    var winURL = "stick.php?idklienta=" + theKlient;
    if (! popWindow || popWindow.closed) {
      popWindow = window.open(winURL,"popWindow","width=300,height=334,scrollbars=yes");
    } else {
      popWindow.focus();
        popWindow.location = winURL;
    }
} // end o

function openZamStick(theKlient, theZam)
{
    var winURL = "stick.php?idklienta=" + theKlient + "&zam=" + theZam;
    if (! popWindow || popWindow.closed) {
      popWindow = window.open(winURL,"popWindow","width=400,height=334,scrollbars=yes");
    } else {
      popWindow.focus();
        popWindow.location = winURL;
    }
} // end 