function popupWindow(global_object){
	this.place = document.getElementById('placePopupWindow');
	this.win = document.getElementById('windowWindowBlock');
	this.global_object = global_object;
	this.save_result = false;
}

popupWindow.prototype.createWindow = function(obj) {
	
	this.save_result = this.getPlaceResult(obj);
	
	screenHeight = this.getDocumentHeight();
	
	this.place.style.height = screenHeight+'px';
	
	this.place.style.display = 'block';
	this.win.style.display = 'block';
	
	this.setPositionWindow();

	return false;
}

popupWindow.prototype.closeWindow = function() {

	this.place.style.display = 'none';
	this.win.style.display = 'none';

	//oбнуляем значения в форме
	forms = this.win.getElementsByTagName('form');
	for(i in forms){
		if(forms){
			for(j in forms[i].childNodes){
				if(forms[i].childNodes[j].nodeName == 'SELECT'){
					forms[i].childNodes[j].selectedIndex = 0;
				}

				//частный случай - обнуляем див в котором второй select
				if(forms[i].childNodes[j].nodeName == 'DIV' && forms[i].childNodes[j].id == 'loadSpecialityBlock'){
					forms[i].childNodes[j].innerHTML = '';
				}	
			}
		}
	}

	return false;
}


//проходим все select и сохраняем id селекнутых и сохраняем в нужном поле:)
popupWindow.prototype.saveSpeciality = function(form, default_value) {
	
	var title = '';
	var sel = new Array(2);
	for(t=0; t<2; t++)
		sel[t] = new Array(0, '');
	
	if(default_value == false){
		var tags = form.getElementsByTagName('select');
		if(tags.length < 2){
			alert('Bitte wählen Sie eine Branche aus!');
			return false;
		}
		

		for(t=0; t<tags.length; t++)
		{
			sel[t] = tags[t].options[tags[t].selectedIndex].value.split(':');
		}
	}
	else{
		this.save_result = this.getPlaceResult(form);
	}

	var separate = '';
	if(this.save_result){
		this.save_result.innerHTML = '';
		for(s=0; s<sel.length; s++){
			this.save_result.innerHTML += separate + sel[s][1];
			if(default_value == false)
				separate = ' / ';
		}
		
		//сохраняем ID подгруппы в input
		var inputs = this.save_result.parentNode.getElementsByTagName('input');

		for(i=0; i<inputs.length; i++)
		{
			if(inputs[i].type == 'hidden')
				inputs[i].setAttribute('value', sel[1][0]);
		}
	}
	this.closeWindow();

	return false;
}

//найти тот див куда мы будем запихивать результат возвращенный окном
popupWindow.prototype.getPlaceResult = function(obj) {
	var parent = obj.parentNode;

	for(r in parent.childNodes){

		if(parent.childNodes[r].nodeName == 'DIV')
		{
			return parent.childNodes[r];
		}
	}
	
	return false;
}


popupWindow.prototype.setPositionWindow = function () {

	var top = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	var height = this.getClientHeight();
	this.win.style.top = (top+height/2-150)+'px';
}

//Размер видимой части документа по вертикали 
popupWindow.prototype.getClientHeight = function() {
  var h = 0;
  if (typeof(window.innerWidth) == 'number' ) {
    //Non-IE
    h = window.innerHeight;
  }
  else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
    h = document.documentElement.clientHeight;
  }
  else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
    //IE 4 compatible
     h = document.body.clientHeight;
  }
  return h;
}

//Размер документа по вертикали   
popupWindow.prototype.getDocumentHeight = function()
{   
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}   

