function OpenDialogWindow( sUri, iWidth, iHeight ) {
	var sWindowName = 'win' + Math.floor( Math.random()*1000 );
	var iRealWidth = iWidth ? iWidth : 600;
	var iRealHeight = iHeight ? iHeight : screen.height - 300;
	
	var iLeft = Math.round( (screen.width-iRealWidth)/2 );
	var iTop =  Math.round( (screen.height-iRealHeight)/2 ) - 35;

	var sWindowOptions = 'status=yes,menubar=no,toolbar=no,resizable=no,scrollbars=yes,location=no';
    sWindowOptions += ',width='  + iRealWidth;
    sWindowOptions += ',height=' + iRealHeight;
    sWindowOptions += ',left='   + iLeft;
    sWindowOptions += ',top='    + iTop;

    var oWindow = window.open( sUri, sWindowName, sWindowOptions );
    oWindow.focus();

    return oWindow;
}

function size(){
	//alert(document.body.clientWidth);
	var W = document.body.clientWidth;
	var nWidth = "940";
	if(W < nWidth){
		document.getElementById('base').style.width = nWidth + "px";
	}else{
		document.getElementById('base').style.width = "100%";
	}
	window.status = document.body.clientWidth + "x" + document.body.clientHeight + " | " + document.getElementById('base').style.width;
}

function setPrintParams(val)
{
	if (document.print_form){
		document.print_form.parametrs.value=val;
	}
}

function PrintVersion(){
	if (document.print_form){
		PR=window.open("","wndPrint","alwaysRaised=yes,left=0,top=0,height=500,width=730,menubar=yes,toolbar=yes,resizable=yes,status=yes,scrollbars=yes");
		document.print_form.submit();
	}else{
		alert("No print version for this page!");
	}

}

// Atention!!! Link on this function insert into FCk-editor!!!--------------------------
function wo(_wurl,_ww,_wh,_wscrl){

/***************
	wurl: window URL
	wh: window height
	ww: window width
	wsr: scrollbars 1 - yes, 0 - no
***************/
 if(screen.width){
  wpos_x = (screen.width-_ww)/2;
  if (wpos_x < 0){ wpos_x = 0;}
  wpos_y = (screen.height-_wh)/2;
  if (wpos_y < 0){ wpos_y = 0;}
 }else{
  wpos_x = 0;
  wpos_y = 0;
 }
// if(_wscrl==undefined){ _wscrl = 0;}
 wind_desc = window.open(_wurl,"","alwaysRaised=0,top="+wpos_y+",left="+wpos_x+",height="+_wh+",width="+_ww+",menubar=0,resizable=1,scrollbars="+_wscrl+",status=1");
 wind_desc.focus();
}
///-------------------------------------------------------------------------------------

function wopen(_wurl,_wn,_ww,_wh,_wscrl) {	
	/***************
	wurl: window URL
	wh: window height
	ww: window width
	wsr: scrollbars 1 - yes, 0 - no
	***************/
	if(screen.width){
	wpos_x = (screen.width-_ww)/2;
	if (wpos_x < 0){ wpos_x = 0;}
	wpos_y = (screen.height-_wh)/2;
	if (wpos_y < 0){ wpos_y = 0;}
	}else{
	wpos_x = 0;
	wpos_y = 0;
	}
	// if(_wscrl==undefined){ _wscrl = 0;}
	if(_wn==""){ _wn = "w_test";}
	wind_desc = window.open(_wurl,_wn,"alwaysRaised=0,top=0,left="+wpos_x+",height="+_wh+",width="+_ww+",menubar=0,resizable=0,scrollbars="+_wscrl+",status=0");
	wind_desc.focus();
}

function PNG(element) {
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
		var src;
		if (element.tagName=='IMG') {
			if (/\.png$/.test(element.src)) {
				src = element.src;
				element.src = "/img/t.gif";
			}
		} else {
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
			if (src) {
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	}
}


function checkPressedKey(event, obj, type){
		/*
		e-mail
		text
		number
		*/
		if (document.all){
			Key = event.keyCode;
		}else{
			Key = event.which;
		}
		switch(type){
			case "not numder":
				if ( (Key>47 && Key<58)){
					obj.value = obj.value;
					return false;
				}
			break;

			case "numder":
				if ( (Key>47 && Key<58) || Key == 8 || Key == 0 || Key == 46 ){
					return true;
				}else{	
					obj.value = obj.value;
					return false;
				}
			break;
		}
	
	}

function calculate(id){
	var count = document.getElementById('num_'+id).value;
	count = Math.round(count);
	document.getElementById('num_'+id).value = count;
	var price = document.getElementById('cost_'+id).innerHTML;
	var price_vat = document.getElementById('cost_vat_'+id).innerHTML;

	//alert(count + " * " + price +" = " + count * price)
	document.getElementById('sum_'+id).innerHTML = round(count * price);
	document.getElementById('sum_vat_'+id).innerHTML = round(count * price_vat);
}

var count_s;

function total(){
	//alert(count_s)
	var sum=0;
	var sum_vat=0;

	for (i=1; i<=count_s; i++){
		sum += document.getElementById('sum_'+i).innerHTML*1;
		sum_vat += document.getElementById('sum_vat_'+i).innerHTML*1;
	}
	document.getElementById('sum').innerHTML = round(sum);
	document.getElementById('sum_vat').innerHTML = round(sum_vat);
}

function check_prod(){
	prod = false;
	for (i=1; i<=count_s; i++){
		if(document.getElementById('num_'+i).value != 0)
			prod = true;
	}
	return prod;
}

function round(val){
	return Math.round(val*100)/100;
}

function paint(therow) {
	therow.className = "over"
}

function unpaint(therow) {
	therow.className = "out"
}

function showdiv(id) {
	var el=document.getElementById(id);

	if (el.style.display=='block')   {
	    el.style.display = 'none';
	}
	else   {
	   el.style.display='block';
	}
}
