if (typeof console == 'undefined')
	var console = { debug: function() {}, info: function(txt) {
			if($('#ieconsole')[0]){
				var cons=$('#ieconsole').append(txt.replace('\n','<br>')+'<div class="chatDiv"></div>')[0];
				cons.scrollTop = cons.scrollHeight; 
			}
		}
	}
$$ = console.debug
$.MSHTML = $.browser.msie;
$.GECKO = $.browser.mozilla;
$.PRESTO = $.browser.opera;
$.SAFARI = $.browser.safari;

$(document).ready(function(){
	InfoBox.init()
	if (!$.MSHTML)
		Draugiem.Tooltip.load();
})
if ($.MSHTML)
	$(window).load(function(){
		Draugiem.Tooltip.load(); 
	})

var Draugiem={
	version:'0.1'
}	
	
Draugiem.Tooltip = {
	version: '0.1',
	load: function(el_id){
		if(typeof($.fn.Tooltip)!='undefined'){
			if(!el_id){
				if($('div[title], li[title], a[title], span[title]').size()){
					console.info($('div[title], li[title], a[title][rel!=\'popup\'][rel!=\'infobox\'], span[title]').Tooltip({delay: 0,track: true, showURL: false}).size()+' tooltips added');
				}
				$('#tooltip').hide();
			}else{
				if($('div[title], li[title], a[title], span[title]', $('#'+el_id)).size()){
					console.info($('div[title], li[title], a[title][rel!=\'popup\'][rel!=\'infobox\'], span[title]', $('#'+el_id)).Tooltip({delay: 0, track: true, showURL: false}).size()+' tooltips added');
				}
				$('#tooltip',$('#'+el_id)).hide();
			}
		}
	}
}




// +++ DOM +++
function O2O( obj1, obj2 ){
  if( typeof( obj1 ) == 'undefined' ) return false;
  if( typeof( obj2 ) == 'undefined' ) return false;       
  for( var key in obj2 ){                                                  
		if( typeof obj2[ key ] == 'undefined' ) console.error( obj2, key );
    if( obj2[ key ].constructor == Object ){
      if( ! obj1[ key ] ) obj1[ key ] = {};                                    
      O2O( obj1[ key ], obj2[ key ] );
    } else {
			obj1[ key ] = obj2[ key ];      
    }
  }
  return true;  
};

function mkE( par ){ 
	if( ! par.tag && ! par.text ) return false;
	if( par.tag ){
		var elm = document.createElement( par.tag );    	
		if( par.attr ) for( key in par.attr ) elm.setAttribute( key, par.attr[ key ] );			
		// append childs
		if( par.els && par.els instanceof Array ) for( ii = 0; ii < par.els.length; ii++ ) if( par.els[ ii ] ){
			if( par.els[ ii ].append ) par.els[ ii ].append( elm ); else elm.appendChild( par.els[ ii ] );
		} 
		if( par.els && ! par.els instanceof Array ) elm.appendChild( par.els );
		// set properties
		if( par.prop ) O2O( elm, par.prop );	
		if( par.id ) elm.id = par.id;
		if( par.className ) elm.className = par.className;	
		if( par.style )	O2O( elm.style, par.style );	
		if( par.text ) elm.appendChild( document.createTextNode( par.text ) );
		elm.append = mkE.append;
		return elm;
	}
	if( par.text ){
		elm = document.createTextNode( par.text );
		elm.append = mkE.append;
		return elm;
	}
}
mkE.append = function( node ){ node.appendChild( this ); return this; };

function removeNode( node ){
	if( node.parentNode ) return node.parentNode.removeChild( node ); else return false;
	return node;
} 
function clearNode( node ){
	var n;
	while( n = node.firstChild ) removeNode( n );
	return node;
}
function addClassName( node, className ){
	var cn = node.className.split( ' ' );		
	var is = false;
	for( var i = 0; i < cn.length; i ++ ) if( cn[ i ] == className ) is = true;	
	if( ! is ) cn.push( className );
	node.className = cn.join( ' ' );
	return node;
};
function removeClassName( node, className ){
	var cn = node.className.split( ' ' );
	var cnr = [];	
	for( var i = 0; i < cn.length; i ++ ) if( cn[ i ] !== className ) cnr.push( cn[ i ] );	
	node.className = cnr.join( ' ' );
	return node;
};
function existsClassName( node, className ){
	var cn = node.className.split( ' ' );
	for( var i = 0; i < cn.length; i ++ ) if( cn[ i ] == className ) return true;	
	return false;
};
// --- DOM ---



// +++ infobox v3 +++
var InfoBox3 = {
	defaults:{
		width:600,
		height:300
	}, // defaults
	init:function(){
		var this_ = this;
		if( ! this._ ){
			this._ = {};
			var td;
			this._.node = mkE( {
				tag:'div',
				prop:{
					id:'infobox3'
				},
				els:[
					this._.overlay = mkE( {
						tag:'div',
						prop:{
							id:'infobox3_overlay'
						}						
					} ),
					mkE( {
						tag:'table',						
						id:'infobox3_content_table',
						els:[
							mkE( {
								tag:'tbody',
								els:[
									mkE( {
										tag:'tr',
										els:[
											td = mkE( {
												tag:'td',
												attr:{
													align:'center',
													valign:'middle'
												}
											} )
										]
									} )
								]
							} )
						]
					} )
				]
			} );
			mkE( {
				tag:'table',
				id:'infobox3_content_table2',
				prop:{
					cellSpacing:'0'
				},
				els:[
					mkE( {
						tag:'tbody',
						els:[
							mkE( {
								tag:'tr',
								els:[
									mkE( {
										tag:'td',
										id:'infobox3_tl'
									} ),
									mkE( {
										tag:'td',
										id:'infobox3_tm'
									} ),
									mkE( {
										tag:'td',
										id:'infobox3_tr',
										els:[
											mkE( {
												tag:'div',
												prop:{
													style:{
														position:'relative',
														fontSize:'1px'
													}
												},
												els:[
													this._.closeButton = mkE( {
														tag:'div',
														id:'infobox3_closeButton',
														prop:{
															onclick:function(){
																this_.close();
															},
															onmouseover:function(){															
																addClassName( this, 'hover' );
															},
															onmouseout:function(){
																removeClassName( this, 'hover' );
															}
														}
													} ) // div.closeButton
												]
											} ) // div
										]
									} )
								]
							} ), // tr
							mkE( {
								tag:'tr',
								els:[
									mkE( {
										tag:'td',
										id:'infobox3_l'
									} ),
									this._.td = mkE( {
										tag:'td',
										els:[
											this._.box = mkE( {
												tag:'div',												
												id:'infobox3_box',												
												els:[
													this.content = this._.box_content = mkE( {
														tag:'div',
														id:'infobox3_box_content',
														els:[
															this.contentLite = this._.box_lite = mkE( {
																tag:'div',
																id:'infobox3_box_lite'
															} )
														]
													} )
												]
											} )
										]
									} ),
									mkE( {
										tag:'td',
										id:'infobox3_r'
									} )
								]
							} ), // tr
							mkE( {
								tag:'tr',
								els:[
									mkE( {
										tag:'td',
										id:'infobox3_bl'
									} ),
									mkE( {
										tag:'td',
										id:'infobox3_bm'
									} ),
									mkE( {
										tag:'td',
										id:'infobox3_br'
									} )
								]
							} )
						]
					} ) // tbody
				]
			} ).append( td );
		}
		this.setDefaults();
		this.append();
	}, // init:function
	
	setStyle:function( p ){
		document.body.style.overflow = p ? 'hidden' : '';		
	},
	
	removeBaffle:function(){
		this.addBaffle(); 
		if( navigator.userAgent.indexOf( 'MSIE' ) != -1 ){
			var sel = document.getElementsByTagName( 'select' );
			for( var i = 0; i < sel.length; i ++ ){
				sel.item( i ).visibility_ = sel.item( i ).style.visibility;
				sel.item( i ).style.visibility = 'hidden';
			}
		}		
		var sel = document.getElementsByTagName( 'embed' );
		for( var i = 0; i < sel.length; i ++ ){
			sel.item( i ).parentNode.visibility_ = sel.item( i ).parentNode.style.visibility;
			sel.item( i ).parentNode.style.visibility = 'hidden';
		}
		var sel = document.getElementsByTagName( 'object' );
		for( var i = 0; i < sel.length; i ++ ){
			sel.item( i ).parentNode.visibility_ = sel.item( i ).parentNode.style.visibility;
			sel.item( i ).parentNode.style.visibility = 'hidden';
		}		
	}, // removeBaffle:function
	
	addBaffle:function(){
		if( navigator.userAgent.indexOf( 'MSIE' ) != -1 ){
			var sel = document.getElementsByTagName( 'select' );
			for( var i = 0; i < sel.length; i ++ ) if( typeof sel.item( i ).visibility_ != 'undefined' ) sel.item( i ).style.visibility = sel.item( i ).visibility_;
		}
		var sel = document.getElementsByTagName( 'embed' );
		for( var i = 0; i < sel.length; i ++ ) if( typeof sel.item( i ).parentNode.visibility_ != 'undefined' ) sel.item( i ).parentNode.style.visibility = sel.item( i ).parentNode.visibility_;
		var sel = document.getElementsByTagName( 'object' );
		for( var i = 0; i < sel.length; i ++ ) if( typeof sel.item( i ).parentNode.visibility_ != 'undefined' ) sel.item( i ).parentNode.style.visibility = sel.item( i ).parentNode.visibility_;
	}, // removeBaffle:function
	
	setDefaults:function(){
		this._.box_content.style.width = '';
		this._.box_content.style.height = '';
		this._.box_lite.style.width = '';
		this._.box_lite.style.height = '';		
	}, // setDefaults:function	
	
	close:function(){
		if( this.par && ! this.par.ignoreBaffle ){
			this.addBaffle();
		}
		this.setStyle( false );
		if( this._ && this._.node.parentNode ){
			this.removeNode( this._.node );
			delete this._;
			if( this.onClose ) this.onClose();
			return true;
		} else {
			return false;
		}
	}, // close:function
	
	append:function(){		
		document.body.appendChild( this._.node );
	}, // append:function
	
	open:function( href, par ){
		if( typeof par == 'undefined' ) par = {};
		this.par = par;
		this.onClose = ( typeof par == 'object' && par.onClose ? par.onClose : false );
		var this_ = this;		
		this.init();
		this._.overlay.onclick = function(){};
		this.removeBaffle();
		this.setStyle( true );
		this.removeNode( this._.box_lite  );
		this._.td.appendChild( this._.box );		
		this.clearNode( this._.box_content );
		this_._.box_content.className = 'load';
		if( typeof par == 'undefined' ) var par = {};		
		$.get( href, function( html ){
			if( par.onload_resize !== false ){
				if( par.width && par.height ) this_.resizeTo( par.width, par.height ); else this_.resizeTo( this_.defaults.width, this_.defaults.height );
			}
			this_._.box_content.innerHTML = html;
			
				//alert('1');
			
			
			this_._.box_content.className = 'with_padding';
			evalScripts( {
				node:this_._.box_content
			} );
			if( par.onload ) try{ par.onload.apply( this_ ) } catch(e){ console.error(e); }			
		} );
	}, // open:function
	
	html:function( html, par ){
		if( typeof par == 'undefined' ) par = {};
		this.par = par;
		this.onClose = ( typeof par == 'object' && par.onClose ? par.onClose : false );
		var this_ = this;		
		this.init();
		this._.overlay.onclick = function(){};
		this.removeBaffle();
		this.setStyle( true );
		this.removeNode( this._.box_lite  );
		this._.td.appendChild( this._.box );		
		this.clearNode( this._.box_content );		
		if( typeof par == 'undefined' ) var par = {};
		if( par.width && par.height ) this_.resizeTo( par.width, par.height ); else this_.resizeTo( this_.defaults.width, this_.defaults.height );
		this_._.box_content.innerHTML = html;			
		this_._.box_content.className = 'with_padding';
	},
			
	iframe:function( href, par ){ 
		if( typeof par == 'undefined' ) par = {};
		this.par = par;
		this.onClose = ( typeof par == 'object' && par.onClose ? par.onClose : false );
		var this_ = this;
		this.init();
		this._.overlay.onclick = function(){};
		if( ! par.ignoreBaffle ) this.removeBaffle();
		this.setStyle( true );
		this.removeNode( this._.box_lite  );
		this._.td.appendChild( this._.box );
		this.clearNode( this._.box_content );
		this_._.box_content.className = 'load';
		if( typeof par == 'undefined' ) var par = {};
		var iframe = this._.iframe = document.createElement( 'iframe' );
		iframe.frameBorder = '0';
		var needResize = true;
		iframe.onload = function(){
			if( ! needResize ) return;
			if( par.onload_resize !== false ){
				if( par.width && par.height ) this_.resizeTo( par.width, par.height ); else this_.resizeTo( this_.defaults.width, this_.defaults.height );
			}
			iframe.style.visibility = '';
			this_._.box_content.className = '';
			if( par.onload ) try{ par.onload.apply( this_ ) } catch(e){ console.error(e); }
			needResize = false;
		};
		//if( ! $.browser[ 'msie' ] )
		if( navigator.userAgent.indexOf( 'MSIE' ) == -1 ){
			iframe.style.visibility = 'hidden';
		} else {
			if( par.onload_resize !== false ){
				if( par.width && par.height ) this_.resizeTo( par.width, par.height ); else this_.resizeTo( this_.defaults.width, this_.defaults.height );
			} 
		}
		iframe.src = href;
		this._.box_content.appendChild( iframe );		
	}, // iframe:function
	
	openLite:function( par ){
		var this_ = this;
		if( typeof par == 'undefined' ) var par = {};
		this.par = par;
		this.init();
		this._.overlay.onclick = function(){
			this_.close();
		};
		this.removeBaffle();
		this.setStyle( true );
		this.removeNode( this._.box  );
		this._.td.appendChild( this._.box_lite );
		this._.box_lite.innerHTML = par.text || '...'; 
		if( par.width && par.height ) this_.resizeTo( par.width, par.height );
	}, // openLite:function
	
	resizeTo:function( w, h ){		
		var this_ = this;
		var w = String( w );
		var h = String( h );
		if( String( w ).indexOf( 'px' ) == -1 && String( w ).indexOf( '%' ) == -1 && w != 'auto' ) w = String( Number( w ) + 20 <= document.body.offsetWidth ? Number( w ) + 20 : document.body.offsetWidth - 20 ) + 'px';
		if( String( h ).indexOf( 'px' ) == -1 && String( h ).indexOf( '%' ) == -1 && h != 'auto' ) h = String( Number( h ) + 20 <= document.body.offsetHeight - 70 ? Number( h ) + 20 : document.body.offsetHeight - 70 ) + 'px'
		if( w != 'auto' ) this._.box_lite.style.width = this._.box_content.style.width = w;
		if( h != 'auto' ) this._.box_lite.style.height = this._.box_content.style.height = h;
		//this._.box_content.overflow = 'hidden';
		/*
		$( this._.box_content ).animate( { height:h }, function(){
			//this_._.box_content.overflow = 'auto';
		} ); */
	}, // resizeTo:function
	
	removeNode:function( node ){
		if( node.parentNode ) return node.parentNode.removeChild( node ); else return false;
	}, // clearNode:function
	
	clearNode:function( node ){
		var n;
		while( n = node.firstChild ) this.removeNode( n );
	}, // clearNode:function
	
	toString:function(){
		return 'dr.lv infobox3';
	} // toString:function
};
// --- infobox v3 ---

// Adapter objekts, lai nodroshinaatu savietojamiibu ar veco Infobox versiju.
var InfoBox = {
	// parametri
	defaults: {close:''},
	// inicializaacija
	init:function(){
	},
	// ajax variants
	open:function( href, props ){		
		InfoBox3.open( href, props );
		return false;
	},
	
	html:function( html, props ){		
		InfoBox3.html( html, props );
		return false;
	},
	
	// aizveershana
	close:function(){
		InfoBox3.close();
	},
	// iframe variants
	iframe:function(href, props){		
		InfoBox3.iframe( href, props );
		return false;
	},
	// resize
	resizeTo:function(name, x,y){		
		InfoBox3.resizeTo( x, y );
	}
};

var InfoLite = {
	// loga platums un augstums
	width: 300,
	height: 40,
	defaultWidth: 300,
	defaultHeight: 40,
	wnd: null,
	mode: null,
	text: '...',
	init: function(){
		InfoLite.wnd = $('#infolite');
	},
	open: function(props){
		InfoBox3.openLite( props )
		return false;
	},
	close: function(){
		InfoBox3.close();
	},
	postload: function(){		
	},	
	resizeto: function(w,h){
		InfoBox3.resizeTo( w, h );
	},	
	IEcenter:function(){		
	},
	viewport:function(){
	}  
}


Draugiem.sayExtPostZip = function( title, url, titlePrefix, domain ){
  window.open(
  domain+'/say/ext/add.php?title=' + encodeURIComponent( title ) +
  '&link=' + encodeURIComponent( url ) +
  ( titlePrefix ? '&titlePrefix=' + encodeURIComponent( titlePrefix ) : '' ),
  '',
  'location=1,status=1,scrollbars=0,resizable=0,width=530,height=400'
 );
 return false;
};





// +++ RPC +++
function RPC( url ){
	this.url = url;
	this.XHR = RPC.XHR;
}
RPC.list = [
	function(){ return new XMLHttpRequest(); },
	function(){ return new ActiveXObject ( 'Microsoft.XMLHTTP' ); },
	function(){ return new ActiveXObject ( 'Msxml2.XMLHTTP' ); },
	function(){ return new ActiveXObject ( 'Msxml2.XMLHTTP.4.0' );}
];
for(var i=0; i < RPC.list.length; i ++ ) try{
	RPC.list[i]();
	RPC.XHR = RPC.list[i];
	break;
}catch(e){}

RPC.prototype.toString = function(){
	return 'RPC "' + this.url + '"';
};
RPC.prototype.send = function( method, data, re_fn, o ){
	$.post( this.url, JSON.encode( { method:method, data:data } ), function( re_text ){
		if( re_fn ){
			var re_data = JSON.decode( re_text );
			try{
				if( typeof re_data == 'object' && typeof re_data.ok != 'undefined' ) re_fn( re_data.ok, o ); else console.error( re_text );
			}
			catch( e ){
				console.error( e );
			}
		}
	} );
};
// --- RPC ---

// +++ JSON +++
var JSON = {
	decode:function( s ){
    try{
			return !( /[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( s.replace(/"(\\.|[^"\\])*"/g, '')) ) && eval( '(' + s + ')' );
    }
    catch( e ){
        return false;
    }
	}, // decode:function
	
	encode:function( v ){		
		return this.s[ typeof v ]( v );
	},	// encode:function
	
	s:{
		'boolean': function (x) { return String(x); },
		'null': function (x) { return "null"; },
		number: function (x) { return isFinite(x) ? String(x) : 'null'; },
		string: function (x) {
				if (/["\\\x00-\x1f]/.test(x)) {
						x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
								var c = JSON.m[b];
								if (c) {
										return c;
								}
								c = b.charCodeAt();
								return '\\u00' +
										Math.floor(c / 16).toString(16) +
										(c % 16).toString(16);
						});
				}
				return '"' + x + '"';
		},
		array: function (x) {
				var a = ['['], b, f, i, l = x.length, v;
				for (i = 0; i < l; i += 1) {
						v = x[i];
						f = JSON.s[typeof v];
						if (f) {
								v = f(v);
								if (typeof v == 'string') {
										if (b) {
												a[a.length] = ',';
										}
										a[a.length] = v;
										b = true;
								}
						}
				}
				a[a.length] = ']';
				return a.join('');
		},
		object: function (x) {
				if (x) {
						if (x instanceof Array) {
								return JSON.s.array(x);
						}
						var a = ['{'], b, f, i, v;
						for (i in x) {
								v = x[i];
								f = JSON.s[typeof v];
								if (f) {
										v = f(v);
										if (typeof v == 'string') {
												if (b) {
														a[a.length] = ',';
												}
												a.push( JSON.s.string(i), ':', v );
												b = true;
										}
								}
						}
						a[ a.length ] = '}';
						return a.join('');
				}
				return 'null';
		}
	}, // s
	
	m:{  // A character conversion map
		'\b': '\\b', '\t': '\\t',  '\n': '\\n', '\f': '\\f',
		'\r': '\\r', '"' : '\\"',  '\\': '\\\\'
	} // m
};
// --- JSON ---


// +++ MaksajumuPoga 
Draugiem.MaksajumuPoga = function( prefix, keyword, num, p_value ){
	this.p_value = p_value;
	this.prefix = prefix;
	this.keyword = keyword;
	this.num = num;
	if( ! Draugiem.MaksajumuPoga.rpc ) Draugiem.MaksajumuPoga.rpc = new RPC( '/services/rq/app.php' );
};
Draugiem.MaksajumuPoga.hid = {};

Draugiem.MaksajumuPoga.prototype.pay = function( p_value ){
	var MaksajumuPoga = this;
	this.rpc = Draugiem.MaksajumuPoga.rpc;
	document.getElementById( 'MaksajumuPoga_' + this.prefix + '_button' ).style.display = 'none';
	document.getElementById( 'MaksajumuPoga_' + this.prefix + '_loading' ).style.display = '';
	var node = document.getElementById( 'MaksajumuPoga_' + this.prefix + '_auto' );
	this.rpc.send(
		'MaksajumuPogaPay',
		{
			keyword:this.keyword,
			num:this.num,
			auto:( node ? node.checked : false ),
			p_value:this.p_value
		},
		function( re ){
			if( re.error ){
				document.getElementById( 'MaksajumuPoga_' + MaksajumuPoga.prefix + '_loading' ).style.display = 'none';
			}
			var errorNode = document.getElementById( 'MaksajumuPoga_' + MaksajumuPoga.prefix + '_error' )
			switch( re.error ){
				case 2:
					if( re.payError == 6 ){
						errorNode.innerHTML = xGlobal[ 'MaksajumuPoga day limit' ] || 'Day limit';
					}					
					break;
				case 4:
					return MaksajumuPoga.error4( re );
				case 5:
					return MaksajumuPoga.error5( re );
				case 6:
					return MaksajumuPoga.error6( re );
			}			
			if( re.error ){
				errorNode.style.display = '';
				var spans = errorNode.getElementsByTagName( 'span' );
				if( spans[ 0 ] ){
					spans[ 0 ].innerHTML = '#' + re.error;
				}
				return;
			}
			setTimeout( function(){
				MaksajumuPoga.sms_payment_id = re.sms_payment_id;
				MaksajumuPoga.getStatus();
			}, 5000 );
		}
	);
};

Draugiem.MaksajumuPoga.prototype.getStatus = function(){
	this.rpc.send(
		'MaksajumuPogaOk',
		{
			sms_payment_id:this.sms_payment_id
		},
		Draugiem.MaksajumuPoga.re_MaksajumuPogaok,
		this
	);	
};

Draugiem.MaksajumuPoga.re_MaksajumuPogaok = function( re, par ){
	if( re.error ){
		document.getElementById( 'MaksajumuPoga_' + par.prefix + '_loading' ).style.display = 'none';
		var errorNode = document.getElementById( 'MaksajumuPoga_' + par.prefix + '_error' )
		errorNode.style.display = '';
		if( re.error == 'NOTCHARGED' ){
			errorNode.innerHTML = 'J\u016bsu kont\u0101 nepietieko\u0161s kred\u012bts vai \u0161is pakalpojums nav pieejams \u0161im oper\u0101toram!';
		}
		return;
	}
	if( re.ok ){
		document.getElementById( 'MaksajumuPoga_' + par.prefix + '_loading' ).style.display = 'none';
		document.getElementById( 'MaksajumuPoga_' + par.prefix + '_ok' ).style.display = '';
		if( window[ 'MaksajumuPoga_callback_' + par.prefix ] ) window[ 'MaksajumuPoga_callback_' + par.prefix ]();
	} else {
		setTimeout( function(){
			par.getStatus();
		}, 3000 );
	}
};

Draugiem.MaksajumuPoga.prototype.stop = function(){
	document.getElementById( 'MaksajumuPoga_' + this.prefix + '_stop' ).style.display = 'none';
	Draugiem.MaksajumuPoga.rpc.send(
		'maksajumuPogaStop',
		{
			keyword:this.keyword
		},
		Draugiem.MaksajumuPoga.re_stop,
		this
	);
};

Draugiem.MaksajumuPoga.re_stop = function( re, par ){
	if( window[ 'MaksajumuPoga_callback_' + par.prefix ] ) window[ 'MaksajumuPoga_callback_' + par.prefix ]();
};

Draugiem.MaksajumuPoga.prototype.error4 = function( re ){
	var MaksajumuPoga = this;
	var node = document.getElementById( 'MaksajumuPoga_' + this.prefix + '_errorW' );
	node.className = 'bx warning';
	node.style.display = '';
	clearNode( node );
	mkE( {
		tag:'div',
		els:[
			mkE( {
				tag:'b',
				text:re.smsUser.phone
			} ),
			mkE( {
				tag:'span',
				text:' ' + re.lang[ 'poga_tavs_nr' ]
			} )
		]
	} ).append( node );
	var codeInput, failText;	
	mkE( {
		tag:'div',
		els:[
			mkE( {
				tag:'button',
				text:re.lang[ 'poga_yes' ],
				prop:{
					onclick:function(){
						clearNode( node );
						mkE( {
							tag:'div',
							els:[
								mkE( {
									tag:'div',
									text:re.lang[ 'poga_kad_sanem_kodu' ]
								} ),
								failText = mkE( {
									tag:'div',
									text:re.lang[ 'poga_nepareizs_kods' ],
									prop:{
										style:{
											fontWeight:'bold',
											visibility:'hidden'
										}
									}
								} ),
								mkE( {
									tag:'div',
									els:[
										mkE( {
											tag:'span',
											text:re.lang[ 'poga_kods' ] + ': '
										} ),
										codeInput = mkE( {
											tag:'input',
											prop:{
												maxLength:5,
												style:{
													width:'50px'
												}
											}
										} ),
										mkE( {
											tag:'button',
											text:re.lang[ 'poga_accept' ],
											prop:{
												onclick:function(){
													MaksajumuPoga.rpc.send(
														'maksajumuPogaCheckAcceptCode',
														{
															code:codeInput.value
														},
														function( re, par ){
															codeInput.value = '';
															if( re.ok ){
																node.style.display = 'none';
																document.getElementById( 'MaksajumuPoga_' + MaksajumuPoga.prefix + '_button' ).style.display = '';
																MaksajumuPoga.pay();
															} else {
																failText.style.visibility = '';
																setTimeout( function(){
																	failText.style.visibility = 'hidden';
																}, 5000 );
															}
														}
													);
												} // onclick
											}
										} ) // button
									]
								} )
							]
						} ).append( node );
						MaksajumuPoga.rpc.send(
							'maksajumuPogaAcceptCode',
							{},
							function( re, par ){
							}
						);
					}
				}
			} ),
			mkE( {
				tag:'span',
				text:' '
			} ),
			mkE( {
				tag:'button',
				text:re.lang[ 'poga_no' ],
				prop:{
					onclick:function(){
						MaksajumuPoga.rpc.send(
							'maksajumuPogaDeletePhone',
							{},
							function( re, par ){
								MaksajumuPoga.error5( re );
							}
						);
					}
				}
			} )
		]
	} ).append( node );
};

Draugiem.MaksajumuPoga.prototype.error5 = function( re ){
	var MaksajumuPoga = this;
	var node = document.getElementById( 'MaksajumuPoga_' + this.prefix + '_errorW' );
	clearNode( node );
	node.style.display = '';
	node.className = 'bx';
	mkE( {
		tag:'div',
		style:{
			textAlign:'left'
		},
		prop:{
			innerHTML:re.lang[ 'register_enter_phone' ]
		}
	} ).append( node );
	var input;
	mkE( {
		tag:'div',
		style:{
			textAlign:'left',
			marginTop:'10px'
		},
		els:[
			input = mkE( {
				tag:'input',
				className:'inp',
				prop:{
					size:20,
					value:'+371 '
				}
			} ),
			mkE( {
				tag:'button',
				text:re.lang[ 'register' ],
				prop:{
					onclick:function(){
						Draugiem.MaksajumuPoga.rpc.send(
							'getPhoneAcceptCode',
							{
								phone:input.value
							},
							function( re ){
							}
						);
						clearNode( node );
						mkE( {
							tag:'div',									
							prop:{
								innerHTML:re.lang[ 'confirm_code' ]
							}
						} ).append( node );
						mkE( {
							tag:'div',
							els:[
								input = mkE( {
									tag:'input',
									className:'inp',
									style:{
										width:'50px'
									},
									prop:{
										maxLength:5
									}
								} ),
								mkE( {
									tag:'span',
									text:' '
								} ),
								mkE( {
									tag:'button',
									text:re.lang[ 'register' ],
									prop:{
										onclick:function(){
											Draugiem.MaksajumuPoga.rpc.send(
												'checkPhoneAcceptCode',
												{
													code:input.value
												},
												function( re ){
													if( re.ok ){
														clearNode( node );
														node.style.display = 'none';
														MaksajumuPoga.pay();
														return;
													}
													Draugiem.blink( {
														node:input
													} );
													input.value = '';
												}
											);
										}
									}
								} )
							]
						} ).append( node );						
					} // onclick
				}
			} )
		]
	} ).append( node );
};

Draugiem.MaksajumuPoga.prototype.error6 = function( re ){
	var MaksajumuPoga = this;
	var node = document.getElementById( 'MaksajumuPoga_' + this.prefix + '_errorW' );
	clearNode( node );
	node.style.display = '';
	node.className = 'bx warning';
	node.innerHTML = re.lang[ 'poga_wrong_oper' ];
};
// --- MaksajumuPoga

// PaymentButton - +/- universaalais risinaajums maksaajumu pogaam - toposhaa mobilly maksaajumu poga, draugiem nauda maksaajumu poga, vajadziibas gadiijumaa arii citas.

Draugiem.PaymentButton = function(  prefix, pm, service, amount, cid ){
	this.prefix = prefix;
	this.pm = pm;
	this.service = service;
	this.amount = amount;
	this.cid=cid;
	if( ! Draugiem.PaymentButton.rpc ) Draugiem.PaymentButton.rpc = new RPC( '/services/rq/paymentbutton.php' );
};
Draugiem.PaymentButton.hid = {};
Draugiem.PaymentButton.prototype.pay = function(){
	try{
		var PaymentButton = this;
		this.rpc = Draugiem.PaymentButton.rpc;
		document.getElementById( 'PaymentButton_' + this.prefix + '_button' ).style.display = 'none';
		document.getElementById( 'PaymentButton_' + this.prefix + '_loading' ).style.display = '';
		document.getElementById( 'PaymentButton_' + this.prefix + '_error' ).style.display = 'none';
		document.getElementById( 'PaymentButton_' + this.prefix + '_ok' ).style.display = 'none';
		var node = document.getElementById( 'PaymentButton_' + this.prefix + '_auto' );
		this.rpc.send(
			'PaymentButtonPay',
			{
				service:this.service,
				pm:this.pm,
				auto:( node ? node.checked : false ),
				amount:this.amount,
				cid:this.cid
			},
			function( re ){
				document.getElementById('PaymentButton_' + PaymentButton.prefix + '_loading' ).style.display = 'none';
				if (re.status){
					document.getElementById('PaymentButton_' + PaymentButton.prefix + '_ok' ).style.display = '';
					window.setTimeout(function(){
						if( window[ 'PaymentButton_callback_' + PaymentButton.prefix ] ) window[ 'PaymentButton_callback_' + PaymentButton.prefix ]();
					},1500);
				}else{
					document.getElementById('PaymentButton_' + PaymentButton.prefix + '_error' ).style.display = '';
				}
				
			}
		);
	}catch(e){
		alert(e);
	}
};

Draugiem.PaymentButton.prototype.stop = function(){
	document.getElementById( 'PaymentButton_' + this.prefix + '_stop' ).style.display = 'none';
	Draugiem.PaymentButton.rpc.send(
		'PaymentButtonStop',
		{
			service:this.service
		},
		function (re, par){
			console.info(re);
		}
	);
};


function evalScripts( par ){
	var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
	var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
	var bMoz = (navigator.appName == 'Netscape');
	var node = par.node;
	/* IE wants it uppercase */
	var st = node.getElementsByTagName('SCRIPT');
	var strExec;
	for( var i = 0; i < st.length; i++ ){
		if ( bSaf ){
			strExec = st[ i ].innerHTML;
			st[ i ].innerHTML = "";
		} else if( bOpera ){
			strExec = st[i].text;
			st[ i ].text = "";
		} else if( bMoz ){
			strExec = st[ i ].textContent;
			st[ i ].textContent = "";
		} else {
			strExec = st[ i ].text;
			st[ i ].text = "";
		}
		try {
			var x = document.createElement( "script" );
			x.type = "text/javascript";
			/* In IE we must use .text! */
			if ( bSaf || bOpera || bMoz )
				x.innerHTML = strExec;
			else x.text = strExec;
			document.getElementsByTagName( "head" )[0].appendChild(x);
		} catch(e) {
			console.error( e );
		}
	}
}