//var IE = document.all?true:false;


var nc  =	!!(document.captureEvents && !document.documentElement);
var ie  =	!!self.innerHeight;
var ie4  =	!!(!document.documentElement && document.all);
var dom  =	!!document.documentElement;
var nc6  =	!!(dom && (!document.all));

//
  // getPageSize()
  // Returns array with page width, height and window width, height
  // Core code from - quirksmode.org
  // Edit for Firefox by pHaez
  //
  function getPageSize(){
	var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	

		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}


		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight, xScroll, yScroll) 
		return arrayPageSize;
  }


//Tooltips:
function get_scroll_pos() {
   if (document.body.scrollTop != undefined && navigator.appName.indexOf("Explorer") != -1 ) {
      var res = (document.compatMode != "CSS1Compat") ? document.body : document.documentElement;
      return {x : res.scrollLeft, y : res.scrollTop};
   }
   else {
      return {x : window.pageXOffset, y : window.pageYOffset};
   }

}

function set_mouseposition_help_default(event) {
	var scr = get_scroll_pos();
	var cordX = event.clientX + scr.x;
	var cordY = event.clientY + scr.y;
	
	document.getElementById('help_default').style.display ='block';
	
	document.getElementById("help_default").style.position = "absolute";
	document.getElementById("help_default").style.left = ( cordX + 16 ) + "px";

	document.getElementById("help_default").style.top = ( cordY + 16 ) + "px";	
	
	return true;
}
function hide_help_default () {
	document.getElementById('help_default').style.display ='none';
}
function set_help_default_text (texttoset) {
	document.getElementById('help_default_text').innerHTML = texttoset;
}

//Frageboxen:
function create_question_box(question_title, question_to_ask, ok_function, event) {
	var arrayPageSize = getPageSize();


    var qr_height = 100;
    var qr_width = 400;


    //Position des Elements bestimmen, welches zum aufruf geklickt wurde
    //alert(arrayPageSize[4]);
    var x_coord = arrayPageSize[2] / 2 - qr_width / 2;
    var y_coord = arrayPageSize[3] / 2 - qr_height / 2;
    var yOffset = 0;

    if (self.pageYOffset)
    {
  	  yOffset = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    {
    	yOffset = document.documentElement.scrollTop;
    }
    else if (document.body)
    {
    	yOffset = document.body.scrollTop;
    }
    y_coord = y_coord + yOffset;

	
	document.getElementById('question_box').style.left = Math.round(x_coord)+"px";
	document.getElementById('question_box').style.top = Math.round(y_coord)+"px";
	
	
	document.getElementById('question_box_header').firstChild.nodeValue = question_title;
	document.getElementById('question_box_text').innerHTML = question_to_ask;
	document.getElementById('question_box_ok_button').onclick =  new Function(""+ok_function+"");
	
	
	_show_overlay();
	
	document.getElementById('question_box').style.display = "block";
	
}
function close_question_box() {
	document.getElementById('question_box').style.display = "none";
	
	_close_overlay();
}
//nachrichtboxen:
function create_message_box(message_title, message) {
	var arrayPageSize = getPageSize();

    var qr_height = 100;
    var qr_width = 400;

    //Position des Elements bestimmen, welches zum aufruf geklickt wurde
    //alert(arrayPageSize[4]);
    var x_coord = arrayPageSize[2] / 2 - qr_width / 2;
    var y_coord = arrayPageSize[3] / 2 - qr_height / 2;
    var yOffset = 0;

    if (self.pageYOffset)
    {
  	  yOffset = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    {
    	yOffset = document.documentElement.scrollTop;
    }
    else if (document.body)
    {
    	yOffset = document.body.scrollTop;
    }
    y_coord = y_coord + yOffset;
	
	document.getElementById('message_box').style.left = Math.round(x_coord)+"px";
	document.getElementById('message_box').style.top = Math.round(y_coord)+"px";
	
	document.getElementById('message_box_header').firstChild.nodeValue = message_title;
	document.getElementById('message_box_text').innerHTML = message;
	
	
	_show_overlay();
	
	document.getElementById('message_box').style.display = "block";
}
function close_message_box() {
	document.getElementById('message_box').style.display = "none";
	_close_overlay();
}
//misc:
function open_picture_popup(image_url, title_text) {
	picture_popup = window.open(image_url, title_text, "width=500,height=500,left=100,top=100");
	picture_popup.focus();
}
function toggle_std_button (togglemode, idofelement) {
	if (togglemode == "down") {
		document.getElementById("std_button_"+idofelement+"_bg_l").className = "std_button_l_pressed";
		document.getElementById("std_button_"+idofelement+"_bg_m").className = "std_button_m_pressed";
		document.getElementById("std_button_"+idofelement+"_bg_r").className = "std_button_r_pressed";
	} else if (togglemode == "up") {
		document.getElementById("std_button_"+idofelement+"_bg_l").className = "std_button_l";
		document.getElementById("std_button_"+idofelement+"_bg_m").className = "std_button_m";
		document.getElementById("std_button_"+idofelement+"_bg_r").className = "std_button_r";
	}
}
function open_style_edit(texttoedit) {
	
	_show_overlay();
	
	var arrayPageSize = getPageSize();


    var qr_height = 480;
    var qr_width = 620;


    //Position des Elements bestimmen, welches zum aufruf geklickt wurde
    //alert(arrayPageSize[4]);
    var x_coord = arrayPageSize[2] / 2 - qr_width / 2;
    var y_coord = arrayPageSize[3] / 2 - qr_height / 2;
    var yOffset = 0;

    if (self.pageYOffset)
    {
  	  yOffset = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    {
    	yOffset = document.documentElement.scrollTop;
    }
    else if (document.body)
    {
    	yOffset = document.body.scrollTop;
    }
    y_coord = y_coord + yOffset;


	    //stripslashes:
	    /*for (var i = 0; i <= graphic_name.sc4_count('\\'); i++) {
	      graphic_name = graphic_name.replace('\\', '');
	    }
	    for (var i = 0; i <= graphic_artist.sc4_count('\\'); i++) {
	      graphic_artist = graphic_artist.replace('\\', '');
	    }*/

	
	
	document.getElementById('fstyle_edit_box').style.left = Math.round(x_coord)+"px";
	document.getElementById('fstyle_edit_box').style.top = Math.round(y_coord)+"px";
	
	document.getElementById('fstyle_edit_box_text').value = document.getElementById(texttoedit).value;
	document.getElementById('fstyle_edit_field_id').value = texttoedit;
	
	//_show_overlay();
	
	document.getElementById('fstyle_edit_box').style.display = "";
}
function close_style_edit(texttoedit) {
	if (texttoedit != '') {
		document.getElementById(texttoedit).value = document.getElementById('fstyle_edit_box_text').value;
	}
	document.getElementById('fstyle_edit_box').style.display = "none";
	_close_overlay();
}

function _close_overlay () {
	document.getElementById('f_overlay').style.display = "none";
}
function _show_overlay () {
	var arrayPageSize = getPageSize();

	  //Overlay auf ganze seitengroesse skalieren
	  //document.getElementById("overlay").style.height = arrayPageSize[1];
	  if (self.innerHeight) { // Alle ausser IE
	    document.getElementById("f_overlay").style.width = '100%';
	  } else {
		    document.getElementById("f_overlay").style.width = Math.round(arrayPageSize[0])+'px';
		  }
		  document.getElementById("f_overlay").style.height = Math.round(arrayPageSize[1])+'px';
	  document.getElementById("f_overlay").style.display = 'block';
}
