function prn()
{
var pt = $('h1:first').html()?$('h1:first').html():document.title;
$('#main_td').printElement({pageTitle:pt});
}

function fprice(e) 
	{
	if (document.all)
				{
				var key = e.keyCode;
				var ch = String.fromCharCode(key);
				var obj = e.srcElement;
				}
	else
				{
				var key = e.which;
				var ch = String.fromCharCode(key);
				var obj = e.target;
				}

	if(ch == '.' && obj.value.indexOf('.') !=-1 ) return false;
	if(ch.match(/[^0-9\.]{1}/) && key!=8 && key!=0 ) return false;
	
	//FORMATIRAY KATO HORATA
	obj.onkeyup = function(){
		tmpval = obj.value.replace(/[^\d\.]*/gi,'');
		//gid('tmpcena').innerHTML = '"'+tmpval+'" - '; 
		//kyde e tochkata
		tmpout = '';
		var dotindex = tmpval.indexOf('.');
		var tcount = 0;
		for(i=(tmpval.length-1);i>=0;i--)
			{		
			if(tcount==3)
				{
				tmpout = tmpval.substr(i,1)+' '+tmpout;
				tcount = 0;
				}
			else{
				tmpout = tmpval.substr(i,1)+tmpout;
				}
			
			if(dotindex==-1 || dotindex>i)
				{
				tcount++;
				}
			}
		
		//gid('tmpcena').innerHTML += '"'+tmpout+'"';  
		obj.value = tmpout;
		}
	}
	
function nolink()
	{
	return;
	}
	
function jqa()
	{
	//PROVERQVA ZA SYOBSHTENIQ OT AJAXA I ZA SCRIPTOVE!
	mesj = jQuery("#ajax_message");
	if(mesj.size()>0)
		{
		text = mesj.html();
		show_message(text);
		mesj.remove();
		}
		
	scrj = jQuery("#ajax_script");
	if(scrj.size()>0)
		{
		eval(scrj.html().replace(/&amp;/g,'&'));
		scrj.remove();
		}
	}

function show_loading()
	{

	dws =  find_document_size();

	limg = gid('loading_img');

	styleleft = (dws[0] - limg.width)/2;
	styletop = (dws[1] - limg.height)/2;

	limg.style.left=styleleft;
	limg.style.top=styletop;
	limg.style.display = '';

	sleft = document.all?document.body.scrollLeft:window.pageXOffset;
	stop = document.all?document.body.scrollTop:window.pageYOffset;
	
	
	gid('big_bg_div').style.top = stop;
	gid('big_bg_div').style.left = sleft;
	
	gid('big_bg_div').style.width='100%';
	gid('big_bg_div').style.height = '100%';
	gid('big_bg_div').style.display = '';
	
	
	window.onscroll = function(){
		show_loading();
		} 
	
	}

function hide_loading()
	{
	gid('loading_img').style.display = 'none';
	gid('big_bg_div').style.display = 'none';
	
	window.onscroll = function(){ 

		}
	
	}
	
function chun(id)
	{
	if(gid(id).type == 'checkbox' || gid(id).type == 'radio' )
		{
		gid(id).checked = !gid(id).checked;
		}
	}
	
function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	    obj.addEventListener(evType, fn, true)
	if(obj.attachEvent)
	    obj.attachEvent("on"+evType, fn)
}

function removeEvent(obj, type, fn){
	if(obj.detachEvent){
		obj.detachEvent('on'+type, fn);
	}else{
		obj.removeEventListener(type, fn, false);
	}
}

function show_message(mtext,wdth)
	{
	gid('message').innerHTML = mtext;
	
	if(!wdth)
		{
		wdth = 500;
		}
	
	$(function() {
		$("#message").dialog({
			title : "СЪОБЩЕНИЕ",
			bgiframe: true,
			resizable: true,
			width: wdth, 
			/* height:140, default auto ;) */
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				'ОК': function() {
					$(this).dialog('destroy');
				}
			},
			close: function(event, ui) {
					$(this).dialog('destroy');
				}

		});
	});
	}

function hide_message()
	{
	$('#message_div').fadeOut(300);
	hide_loading();
	}

function find_document_size()
	{
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }

	retval = new Array();
	retval[0] = myWidth;
	retval[1] = myHeight;

	return retval;
	}


function copy_clip(meintext)
{
 if (window.clipboardData) 
   {
   
   // the IE-manier
   window.clipboardData.setData("Text", meintext);
   
   // waarschijnlijk niet de beste manier om Moz/NS te detecteren;
   // het is mij echter onbekend vanaf welke versie dit precies werkt:
   }
   else if (window.netscape) 
   { 
   
   // dit is belangrijk maar staat nergens duidelijk vermeld:
   // you have to sign the code to enable this, or see notes below 
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   
   // maak een interface naar het clipboard
   var clip = Components.classes['@mozilla.org/widget/clipboard;1']
                 .createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;
   
   // maak een transferable
   var trans = Components.classes['@mozilla.org/widget/transferable;1']
                  .createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;
   
   // specificeer wat voor soort data we op willen halen; text in dit geval
   trans.addDataFlavor('text/unicode');
   
   // om de data uit de transferable te halen hebben we 2 nieuwe objecten 
   // nodig om het in op te slaan
   var str = new Object();
   var len = new Object();
   
   var str = Components.classes["@mozilla.org/supports-string;1"]
                .createInstance(Components.interfaces.nsISupportsString);
   
   var copytext=meintext;
   
   str.data=copytext;
   
   trans.setTransferData("text/unicode",str,copytext.length*2);
   
   var clipid=Components.interfaces.nsIClipboard;
   
   if (!clip) return false;
   
   clip.setData(trans,null,clipid.kGlobalClipboard);
   
   }
   return true;
}
	
function in_array(val,ar)
	{
	for(key in ar)
		{
		if(ar[key]==val)
			{
			return key;
			break;
			}
		}
	return false;
	}
	
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

	
function show_hide(id)
	{
	try{
		if(gid(id).style.display == 'none')
			{
			gid(id).style.display = '';
			}
		else{
			gid(id).style.display = 'none';
			}
		}
	catch(e){
		alert(e.message);
		}
	}

function get_selection(selection_obj_id)
{
	sel_obj = gid(selection_obj_id);
	sel_obj.focus();

	var $sel;
	if(document.selection)
		{
		$sel = document.selection.createRange().text;
		}
	else
		{
		$sel = sel_obj.value.substring(sel_obj.selectionStart,sel_obj.selectionEnd);
		}
	return ($sel);
}


function show_hide_tag(tag,id)
	{
	try{

		ids = document.getElementsByTagName(tag);
		for(key in ids)
			{
			if(ids[key].id == id)
				{
				if(ids[key].style.display == 'none')
					{
					ids[key].style.display = '';
					}
				else{
					ids[key].style.display = 'none';
					}

				}
			}


		}
	catch(e){
		alert(e.message);
		}
	}

function toFixed(num, round)
{
	num = parseFloat(num);

	if(num<0)
		{
		num = num*(-1);
		reverse = -1;
		}
	else{
		reverse = 1;
		}

	tempd = num*Math.pow(10,round);

	tempd1 = Math.round(tempd.toFixed(5));

	number = tempd1/Math.pow(10,round);

	number = reverse*number;

	return number.toFixed(round);
}

function nz(digit)
	{
	return parseFloat(toFixed(digit,10))
	}


function fix(obj)
	{
	if(obj.value.length>0)
		{
		obj.value = (parseFloat(obj.value)).toFixed(2);
		}
	else{
		obj.value = '0.00';
		}
	calc();
	}


function dbl(e)
	{
	if (document.all)
				{
				var key = e.keyCode;
				var ch = String.fromCharCode(key);
				var obj = e.srcElement;
				}
	else
				{
				var key = e.which;
				var ch = String.fromCharCode(key);
				var obj = e.target;
				}


	if(ch == '.' && obj.value.indexOf('.') !=-1 ) return false;
	if(ch.match(/[^0-9\.]{1}/) && key!=8 && key!=0 ) return false;



	}


function intonly(e)
	{
	if (document.all)
				{
				var key = e.keyCode;
				var ch = String.fromCharCode(key);
				var obj = e.srcElement;
				}
	else
				{
				var key = e.which;
				var ch = String.fromCharCode(key);
				var obj = e.target;
				}

	if(ch.match(/[^0-9]{1}/) && key!=8 && key!=0 ) return false;
	}



function fake_post(address_target,params)
	{

	var adrt = address_target.split('|');
	var url = adrt[0];
	var target = adrt[1];
	var method = adrt[2];

	//napravi nova forma
	var form = document.createElement( "form" );
	
	if(method)
		{
		form.method  = method;
		}
	else{
		form.method = 'POST';
		}
	

	form.action = url;

	if(target)
		{
		form.target  = target;
		}

	//Zapochi da nabivash vytre inputcheta

	//Nameri razdelitelq
	if(params.charAt(0) == '&')
		{
		var splt = '&'
		params = params.substr(1);
		}
	else{
		var splt = ',';
		}


	var params_array = params.split(splt);




	for (i=0;i<params_array.length;i++)
		{
		if(params_array[i].indexOf('=')==-1) continue;

		pma = params_array[i].split('=');
		name = pma[0];
		value = pma[1];

		//JS TRIM :)
		name = name.replace(/^[\s]+/,'');
		value = value.replace(/^[\s]+/,'');

		name = name.replace(/[\s]+$/,'');
		value = value.replace(/[\s]+$/,'');

		input_el = document.createElement( "input" );
		input_el.type = 'hidden';
		input_el.name = name;
		input_el.value = value;

		form.appendChild(input_el);

		}

	//skrii shibanata forma ot shibani FF
	form.style['display'] = 'none';

	//NAII FORMATA U DOKUMENTO
	document.body.appendChild(form);

	//ARE ZAMINAVAY
	form.submit();
	}


function mark(id)
	{
	if(gid('selected').value>0 && gid('row_'+gid('selected').value) )
		{
		gid('row_'+gid('selected').value).style.backgroundColor = '';
		gid('row_'+gid('selected').value).style.color = '';
		}

	gid('selected').value = id;
	gid('row_'+id).style.backgroundColor= '#316AC5';
	gid('row_'+id).style.color= 'white';

	return false;

	}






function gid(id_name)
	{
	if(document.getElementById(id_name))
		return document.getElementById(id_name);
	else{
		ddname=document.getElementsByName(id_name);
		return  ddname[0];
		}
		
	}
	



function trigger_f(e,trf)
	{
	if(e.keyCode == 13) //ENTER IS PRESSED
		{
		//alert ('ENter');
		eval(trf);
		}

	}


function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft: what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
	totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft: totaloffset+parentEl.offsetTop;
	parentEl=parentEl.offsetParent;
}

return totaloffset;
}


function resize_parent(iframename)
	{
	last = document.getElementById('last_image');
	hgh = getposOffset(last, 'top');
	window.parent.document.getElementById(iframename).height = hgh+50;
	}


