var BUGS=true;
var debug=new Array();
var bugs_iterate=0;
function deba(el) {
	bugs_iterate++;

	var out = "";	
	out = "\n============================================================\n";
	if (deba.caller == null) {
		out += "This function was called from the top!\n"
					+"------------------------------------------------------------\n";
	} else {
		var callerName=deba.caller.toString().substring(0,deba.caller.toString().indexOf('{'));
		out += "This function's caller was: " + callerName +"\n"
					+"------------------------------------------------------------\n";
	}
	
	out += "The debug element or content is:\n" + el + "\n";
	
	if(typeof el=="object"){
		out += "------------------------------------------------------------\n";
		for(prop in el) {
			out += prop+' = '+el[prop]+"\n";
		}
	}
	
	debug[bugs_iterate]=out;
	if(bugs_iterate>100){
		debug.shift();
	}
	
	if(BUGS){
		win = window.open('', 'Debug','width=400,height=300,left=50,top=50,status,menubar,scrollbars,resizable');
		win.document.open();
		win.document.write('<pre>' + debug.join('\n') + '</pre>');
		win.document.close()
		win.focus();
	}
}




function sizePage(){
/*
    initDHTMLAPI();
    var browserHeight = getInsideWindowHeight();
    var content = getRawObject('content');
    if(content && getObjectHeight(content) < browserHeight - 130){
	    content.style.height = browserHeight - 130 + 'px';
	}
*/
	return true;
}
function addObject(){
	switchMode('toolAdd');
	$('#addObjectForm').fadeIn();
}

function cancelAddObject(){
	switchMode('toolPan');
	document.forms.addPointForm.x_point.value = '';
	document.forms.addPointForm.y_point.value = '';
	$('#addObjectForm').fadeOut();
}

function toggleBlock(id){
	$block=$('#' + id);
	if($block.css('display')=='none'){
		$block.slideDown();
	}
	else{
		$block.slideUp();
	}
}

function queryClose(id,e){

	try{
		$('#'+id).fadeOut();
		objXmlOverlay.removePoint(id);
	}
	catch(err){
	}

	try{
		//alert(id);
		myKaNavigator.clear(id);
	}
	catch(err){
	}

    e = (e)?e:((event)?event:null);
	e.preventDefault();
	e.stopPropagation();
	e.preventBubble();
	e.preventCapture();
	e.cancelBubble = true;

	return false;
}

function updateLeftObjects(){
	var coords = '';
	var mid='';
	if (arguments.length > 0 && arguments[0] != ''){
    	coords = arguments[0];
    }
	if (arguments.length > 1 && arguments[1] != ''){
    	mid = arguments[1];
    }
	$('#objectsLeft').load('/requests.php?act=objectsLeft&coords=' + coords + '&mid=' + mid);
}

/**
 * switchMode
 * ...
 */
function switchMode(id){
    if(id=='toolQuery'){
        myKaQuery.activate();
        //getRawObject('toolQuery').style.backgroundImage = 'url(images/tool_query_2.png)';
        //getRawObject('toolPan').style.backgroundImage = 'url(images/tool_pan_1.png)';
    }else if(id=='toolPan'){
        myKaNavigator.activate();
        //getRawObject('toolQuery').style.backgroundImage = 'url(images/tool_query_1.png)';
        //getRawObject('toolPan').style.backgroundImage = 'url(images/tool_pan_2.png)';
    }else if(id=='toolAdd'){
        myAddQuery.activate();
        //getRawObject('toolQuery').style.backgroundImage = 'url(images/tool_query_1.png)';
        //getRawObject('toolPan').style.backgroundImage = 'url(images/tool_pan_1.png)';
    }else{
        myKaNavigator.activate();
    }
}

function addQueryHandler(eventID,coords){
	//alert(coords[0] + ' x ' + coords[1]);
	document.forms.addPointForm.x_point.value = '';
	document.forms.addPointForm.y_point.value = '';
	document.forms.addPointForm.x_point.value = coords[0];
	document.forms.addPointForm.y_point.value = coords[1];

	if(document.forms.addPointForm.x_point1){
		document.forms.addPointForm.x_point1.value = '';
		document.forms.addPointForm.y_point1.value = '';
		document.forms.addPointForm.x_point2.value = '';
		document.forms.addPointForm.y_point2.value = '';
	}

	return true;
}

