// (C) dizaino studija [arti]
// http://www.arti.lt


// dynapi3 ua detection
function _UserAgent() {
	var b = navigator.appName;
	var v = this.version = navigator.appVersion;
	var ua = navigator.userAgent.toLowerCase();	
	this.v = parseInt(v);
	this.safari = ua.indexOf("safari")>-1;	// always check for safari & opera 
	this.opera = ua.indexOf("opera")>-1;	// before ns or ie
	this.ns = !this.opera && !this.safari && (b=="Netscape");
	this.ie = !this.opera && (b=="Microsoft Internet Explorer");
	this.gecko = ua.indexOf('gecko')>-1; // check for gecko engine
	if (this.ns) {
		this.ns4 = (this.v==4);
		this.ns6 = (this.v>=5);
		this.b = "Netscape";
	}else if (this.ie) {
		this.ie4 = this.ie5 = this.ie55 = this.ie6 = false;
		if (v.indexOf('MSIE 4')>0) {this.ie4 = true; this.v = 4;}
		else if (v.indexOf('MSIE 5')>0) {this.ie5 = true; this.v = 5;}
		else if (v.indexOf('MSIE 5.5')>0) {this.ie55 = true; this.v = 5.5;}
		else if (v.indexOf('MSIE 6')>0) {this.ie6 = true; this.v = 6;}
		this.b = "MSIE";
	}else if (this.opera) {
		this.v=parseInt(ua.substr(ua.indexOf("opera")+6,1)); // set opera version
		this.opera6=(this.v>=6);
		this.opera7=(this.v>=7);
		this.b = "Opera";
	}else if (this.safari) {
		this.ns6 = (this.v>=5);	// ns6 compatible correct?
		this.b = "Safari";
	}
	this.dom = (document.createElement && document.appendChild && document.getElementsByTagName)? true : false;
	this.def = (this.ie||this.dom);
	this.win32 = ua.indexOf("win")>-1;
	this.mac = ua.indexOf("mac")>-1;
	this.other = (!this.win32 && !this.mac);
	this.supported = (this.def||this.ns4||this.ns6||this.opera)? true:false;
}; 


is = new _UserAgent();

// basic browser detection
var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false
var moz = (navigator.userAgent.indexOf("Gecko")  > -1);
var dom = (document.getElementsByName)? true:false
// for DHTML
var ieMac = ( ie4 && (navigator.userAgent.indexOf("Mac")  > -1) );
var isDynamic = ( dom || ((ns4||ie4) && !ieMac) );
var layerRef = (ns4) ? "document" : "document.all";
var styleRef = (ns4) ? "" : ".style";





var dwin;
function debug( msg, end ){
	if( ! dwin ){
		if( end ){
			return;
		}
		dwin = window.open( 'about:blank' , 'debug_window', 'scrollbars=yes,resizable=yes,toolbar=no,status=yes,menubar=no,dependant=yes,alwaysRaised=yes,location=yes'); 
	}
	if( typeof(msg)=='object'){
		var o='';
		for(var i in msg){
			o+= i + '=' + msg[i] + "<br>\n";
		}
		dwin.document.writeln( o + "<br>\n" );
	}else{
		dwin.document.writeln( msg + "<br>" );
	}
	if( end ){
		dwin.document.close();
	}
}




// builder browsing mode detection
mode_is_virtual = ( window.location.pathname.indexOf('/vbui')==0 ) ? 0:1 ;

// what page we are at
if( mode_is_virtual ){
	page_path = window.location.pathname;
	url_prefix = '';
}else{
	rexp = /page=([^&]+)/i;
	if( window.location.search && rexp.test( window.location.search) ){
		a = rexp.exec( window.location.search );
		page_path = a[1];
	}else
		page_path = '/';
	url_prefix = window.location.pathname + '?page=';
}



// Show/Hide functions for non-pointer layer/objects
function show(id) {
	if (dom) document.getElementById(id).style.visibility = "visible"
    else if (ns4) document.layers[id].visibility = "show"
	else if (ie4) document.all[id].style.visibility = "visible"
}

function hide(id) {
	if (dom) document.getElementById(id).style.visibility = "hidden"
	else if (ns4) document.layers[id].visibility = "hide"
	else if (ie4) document.all[id].style.visibility = "hidden"
}



function url( path, parm ){
	if( !path ) path = page_path;
	if( path.charAt(0) != '/' ) path = page_path.slice(0, page_path.lastIndexOf('/') ) + '/' + path;
	url = url_prefix + path;
	if( mode_is_virtual ) x = '?';
	else x = '';
	if( typeof(parm) != 'undefined' ) url+= x + '&' + parm;
	window.location = url;
}





/// image flip-flop

function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

function flip( imgName, imgObj ) {
	if (document.images) {
		document.images[imgName].src = eval(imgObj+".src")
	}
	return true;
}


// lang

function switch_lang( ){
	if( lang_vertimas && (lang_vertimas.length>1) ) {
	   window.location = lang_vertimas;
	}else{
		p = window.location.pathname
		if( p.indexOf( '/en/' ) == 0 ){
			window.location = '/lt' + p.slice( 3 )
		}else if( p.indexOf( '/lt/' ) == 0 ){
			window.location = '/en' + p.slice( 3 )
		}else{
			window.location = '/en' + p
		}
	}
}







/*

// builder


function BuilderObject(){
  this.self     = '/builder/builder.phtml?';
  this.ns4 = (document.layers)? true:false
  this.ie4 = (document.all)? true:false

  this.editWindow = false;

  this.checkEdit        = Builder_checkEdit;
};


function Builder_checkEdit( e, type, table, at, id1, id2, id3, id4 ){
        var ctrl;
        if (this.ns4) { ctrl=(e.modifiers==2) }
        if (this.ie4) { ctrl=e.ctrlKey    }
        if (! ctrl ) return true;

		if( ! this.editWindow || this.editWindow.closed ){
			seed = Math.floor( 10000000 * Math.random() );


			url = '/admin/index.php?go=AdminTables%3B'+table+'&table='+table+'&at='+at+'&start=&close=yes&action=edit&id='+id1+'&seed='+seed;

//			url = 'http://www.lcn.lt/admin/t2.php?table='+table+'&at='+at+'&action=edit&close=yes&id='+id1+'&seed='+seed;
	        this.editWindow = window.open( url , 'edit_win', 'scrollbars=yes,resizable=yes,toolbar=no,status=yes,menubar=no,dependant=yes,alwaysRaised=yes,location=yes');
	        return false;
		}else{
			if( this.editWindow ){
				this.editWindow.focus();
				return false;
			}
		}
}


builder = new BuilderObject();
*/