// BuilderScript global.js v1.0.000520
// (C) dizaino studija [arti], tadas@arti.lt, 2000
// http://www.arti.lt, info@arti.lt, +370 86 49786

// basic browser detection
var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false
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";









// 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"
	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( ){
	p = window.location.pathname
	if( p.indexOf( '/en/' ) == 0 )
		window.location = 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 = '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();
