  var ie = document.all ? 1 : 0;
  var ns = document.layers ? 1 : 0;
  if (document.childNodes) {
	document.write ("<style>");
	document.write (" .dblock_content { display:block; } ");
	document.write ("</style>");
  }
  function dblock_sh (obj) {
	var par = obj.parentNode;
	//var ta = par.getElementById('dblock_content');
	if (ie) {
		var ta = par.childNodes.item(1);
		var btn = obj.childNodes.item(0);
	} else {
		var ta = par.childNodes.item(1);
		var btn = obj.childNodes.item(0);
	}
	eval (ta);
	//par.childNodes.item(1).style.display = "block";
	//alert (par.childNodes.item(1).id);
	if (ta.style.display != "none") {
		ta.style.display = "none";
		btn.innerHTML = "&uarr;";
		//btn.src = "up.png"
		//btn.src = "minus.png"

	} else {
		ta.style.display = "block";
		btn.innerHTML = "&darr;";
		//btn.src = "down.png"
		//btn.src = "plus.png"
	}
  }
  function enablePeriod (b) {
	var sel_per = document.getElementById("period");  
	var sel_per_id = document.getElementById("periodtype_id");  
	b = (b==1)?false:true;
	sel_per.disabled = b;
	sel_per_id.disabled = b;
  }
  function enableWF_SpecHours (b) {
	var sel_guarantee = document.getElementById("wf_guarantee");  
	var sel_instant = document.getElementById("wf_instant");  
	b = (b==0)?false:true;
	sel_guarantee.disabled = b;
	sel_instant.disabled = b;
  }
  function enableUser_getCheckCustomerIds (b) {
	var sel_customerids = document.getElementById("div_customer_ids");  
	b = (b==0)?"none":"block";
	sel_customerids.style.display = b;	  
  }
  function update_body_extra () {
	var ret='';
	var elm = document.getElementById("sendto_body_extra_main");
	var t = elm.value;
	for (i=0; i < (document.forms.length); i++) {
		if (document.forms[i].elements["sendto_body_extra"])
		{
			document.forms[i].elements["sendto_body_extra"].value = t;
		}
	}
	updateCommentSession();
  }
  function checkWFMailBox(id) {
	  var cust_elem = document.getElementById("customer_ids_chk_"+id);
	  var wf_m_elem = document.getElementById("customer_wf_m_ids_chk_"+id);
	  
	  if (cust_elem.checked) {
		  wf_m_elem.disabled = false;
	  } else {
		  wf_m_elem.checked = false;
		  wf_m_elem.disabled = true;
	  }
	  
  }
  function update_body_extra_sms () {
	var ret='';
	var elm = document.getElementById("sendto_body_extra_sms_main");
	var t = elm.value;
	for (i=0; i < (document.forms.length); i++) {
		if (document.forms[i].elements["sendto_body_extra_sms"])
		{
			document.forms[i].elements["sendto_body_extra_sms"].value = t;
		}
	}
	updateCommentSessionsms();
  }
	function updateCommentSessionsms(){
		var elm = document.getElementById("sendto_body_extra_sms");
		if (window.parent.commentupdate)
		{
			window.parent.commentupdate.location='comment.php?t='+escape(elm.value);
		}

	}
	function updateCommentSession(){
		var elm = document.getElementById("sendto_body_extra_main");
		if (window.parent.commentupdate)
		{
			window.parent.commentupdate.location='comment.php?t='+escape(elm.value);
		}

	}

  var wnd;
  function nWindow (content) {
	//if (wnd) { wnd.close(); }
	wnd = window.open(content,'nWindow','');
	wnd.focus();
  }
  
  function getObj(name) {
    if (document.getElementById) {
      return document.getElementById(name);
    } else if (document.all) {
      return document.all[name];
    } else if (document.layers) {
      return document.layers[name];
    }
    else return false;
  }

var marked_row = new Array;

	/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @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, theRowNum, 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

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 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;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // 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 b = 2;
var i = 2;
var u = 2;
var q = 2;
var c = 2;
var url = 2;
var img = 2;

function doSubmit(form){
	var formElement = document.forms[form];
	if (formElement == null){
		return
	}

	formElement.submit();
}

			picObj = function(obj, src){
				this.obj = obj;
				this.src = src;
			}

			menuControl = function(param){
				if ( param= null ){
					this.actSubMsObj = null;				
				} else {
					this.actSubMsObj = document.getElementById(param)
				}
				this.closedImg = new Array();
				this.openImg = new Array();
			}

			menuControl.prototype.changePic = function(obj, state){
				var picId = obj + "Pic";
				var picElement = document.getElementById(picId);
				if (picElement == null){
					return;
				}
				
				if (state == 1){
					for (var i=0; i<this.closedImg.length; i++){
						if (this.closedImg[i].obj == picId){
							picElement.src = this.closedImg[i].src;
							break;
						}
					}
				} else{
					for (var i=0; i<this.openImg.length; i++){
						if (this.openImg[i].obj == picId){
							picElement.src = this.openImg[i].src;
							break;
						}
					}
				}
			}

			menuControl.prototype.showSubMs = function(obj){
				var subMsObj = document.getElementById(obj);
				if(subMsObj == null){
					return;
				}
						
				if (subMsObj.style.display == "block"){
					this.changePic(obj, 1);
					subMsObj.style.display = "none";
				}else{
					if (this.actSubMsObj != null){
//						alert(this.actSubMsObj.id);
						this.changePic(this.actSubMsObj.id, 1);
						this.actSubMsObj.style.display = "none";
					}
					this.changePic(obj, 0);
					subMsObj.style.display = "block";
				}
				this.actSubMsObj = subMsObj;	
			}
			var menuCtrl = new menuControl();

	function NewWindow(mypage,myname,w,h,scroll){
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
		var settings ='height='+h+',';
		settings +='width='+w+',';
		settings +='top='+wint+',';
		settings +='left='+winl+',';
		settings +='scrollbars='+scroll+',';
		settings +='resizable=no,toolbar=0,status=0,';
		wnd=window.open(mypage,myname,settings);
		if(parseInt(navigator.appVersion) >= 4){wnd.window.focus();}
	} 
	function MM_openBrWindow(theURL,winName,features) { 
		window.open(theURL,winName,features);
	}


  function Flags (id,to_table,object,readonly) {
    if (id == null) {
        return false;
    }
    if (readonly == null) {
      readonly = false;
    }
    if (object == null) {
      var content = "/flag.php?object_id="+id+"&to_table="+to_table;
    } else {
      var content = "/flag.php?service_id="+id+"&to_table="+to_table+"&to_record="+object;
    }
    if (readonly) {
      if (!confirm('A szolgáltatás státusza nem módosítható! Folytatja?')) return false;
    }
    NewWindow(content,'nWindow','450','400','yes');
    wnd.focus();
  }

  function flagcheck(){
	if (getObj('fd_form[to_customers]').checked || getObj('fd_form[to_vendors]').checked || getObj('fd_form[to_services]').checked
    || getObj('fd_form[to_customer_services]').checked)
	{
		return true
	} else {
		alert('Válassz kategóriát a státusznak');	
		return false;
	}
  }

  function formatCurrency(num) {

num = num.toString().replace(/\./g,'');

if (num == null || num == '')
{
	return num;
}
if (isNaN(num))
{
	return '';
}

sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)

for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+'.'+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num);
}
	function toggleFullCateg(){
		eval ("var arr =  categ_checkbox_arr");
		for (i=0;i<arr.length;i++){
			getObj('customers['+arr[i]+']').checked = getObj('toggleall').checked;	
		}
	}

	function statcontroltype(value){
		if (value == '1')
		{
			getObj('fd_form[control_value]').disabled=false;
			getObj('fd_form_control_tr').style.visible="block";
		} else {
			getObj('fd_form[control_value]').disabled=true;
			getObj('fd_form_control_tr').style.visible="none";			
		}
	}

	function changeFixType(value){
		if (value == '1')
		{
			getObj('fd_form[contr_projected_mothly_hours_fix_const]').disabled=false;
			getObj('fd_form[contr_projected_mothly_hours_const]').disabled=true;
		} else {
			getObj('fd_form[contr_projected_mothly_hours_fix_const]').disabled=true;
			getObj('fd_form[contr_projected_mothly_hours_const]').disabled=false;
		}
	}
	function remoteCheck(value)
	{
		if (value == '1')
		{
			getObj('wf_instant').selectedIndex=0;
			getObj('wf_instant').disabled=true;			
		} else {
			getObj('wf_instant').disabled=false;					
		}
	}
	function checkWorkflow(url){
		var baseRecomended = parseFloat(getObj('recomended_hidden').value);
		var operational = getObj('operational_original').value;
		var development = getObj('development_original').value;
    var overPriced = 0;
    if(getObj('overpriced_hidden')) {
      overPriced = parseFloat(getObj('overpriced_hidden').value);
      //alert("overPriced"+overPriced);
    }
//    alert(parseFloat(baseRecomended)+'+'+overPriced+' = '+parseFloat(operational)+'+'+parseFloat(development));

		if ((parseFloat(baseRecomended) + parseFloat(overPriced)) != (parseFloat(operational) +parseFloat(development)))
		{
			alert('Üzemeltetés('+parseFloat(operational)+') és fejlesztés('+parseFloat(development)+') összege nem egyenlő a javasolt('+parseFloat(baseRecomended)+') és munkaidőn kívüli('+parseFloat(overPriced)+') órák összegével!');
			return;
		}
		var subscriber = getObj('subscriber_hidden').value;;
		if (subscriber <= 0) {
		  alert('Lezárés elött kötelezző beállitani a "Munkalap aláíróját"');
		  return;
		}

		window.location.href=url;
		return true;
	}
	function checkTimeout(){
		$.get('testAjax.php', timeoutSuccess);
	}
	function timeoutSuccess(data){
		if (data  == '1')
		{ 
		} else {
			alert('Lejárt biztonsági időkorlát miatt a rendszer kiléptette!');
		}
	}
    
  function checkNotExtraPrice(obj) {
  if (obj.value != '')
    getObj('fd_form[not_extra_hours_extra_price]').checked = true;
  else
    getOnj('fd_form[not_extra_hours_extra_price]').checked = false;
  }

  function controlJobChanged(jobId) {
    if (jobId && controlJobProperties[jobId]) {
      for (i = 1; i < 4; i++) {
        nameControl = document.getElementById('customer_control_prop_'+i);
        valueControl = document.getElementById('customer_control_prop_value_'+i);
        valueInput = document.getElementById('prop_value_'+i);
        valueInput.value = '';
        if(controlJobProperties[jobId].properties[i]) {
          nameControl.style.display = '';
          nameControl.innerHTML = controlJobProperties[jobId].properties[i]+':';
          nameControl.title = controlJobProperties[jobId].properties[i]+':';
          valueControl.style.display = '';
        } else {
          nameControl.style.display = 'none';
          valueControl.style.display = 'none';
        }
      }
    }
  }
