function $(id) {
	return document.getElementById(id);
}

/* pobranie formularza */
function gF(FormID){
	return  document.forms[FormID];
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

/* ---- obiekt wojewodztw --------- */

function Province(iId,sName){
	this.iId = iId;
	this.sName = sName;
}

function FormMap(oVars) {

	this.aProvinces = oVars.aProvinces;

	this.sMapName = oVars.sMapName;
	this.sMapBackground = oVars.sMapBackground;
	this.oImageEmpty = newImage(oVars.sImageEmpty);
	this.aImages = new Array();

	this.sProvinceField = oVars.sProvinceField;
	this.sProvinceFieldTxt = oVars.sProvinceFieldTxt;

	this.oForm = gF(oVars.sFormName);
	this.oMapLayer = $(oVars.sMapLayerName);


	this.iProvinceID = oVars.iProvinceID;
	
	for(var i=1;i<=16;i++){
		this.aImages[i] = newImage('images/gfx_woj_'+i+'.gif');
	}

	this.showProvince = function(ProvinceID){
    $(this.sMapName).src = this.aImages[ProvinceID].src;
	}

	this.hideProvince = function(){
		$(this.sMapName).src = this.oImageEmpty.src;
	}

	this.changeProvince = function(iProvinceID){
		this.iProvinceID = iProvinceID;
		this.iCityID = 0;
		this.iDepartmentID = 0;
		this._setProvince(iProvinceID)
	}


	
	this.changeMapBG = function(){
		var sTmpBgSrc = (this.iProvinceID) ? this.aImages[this.iProvinceID].src : this.oImageEmpty.src;
		$(this.sMapBackground).style.backgroundImage = 'url('+sTmpBgSrc+')';
		$(this.sMapBackground).style.backgroundRepeat = 'no-repeat';
	}





	this._setProvince = function(iProvinceID){
        	SetCookie(this.sProvinceField,iProvinceID);

		this.iProvinceID = parseInt(iProvinceID);
		var iQOptions = this.oForm.elements[this.sProvinceField].options.length;
		for(i=0;i<iQOptions;i++){
			if (this.oForm.elements[this.sProvinceField].options[i].value==this.iProvinceID){
				this.oForm.elements[this.sProvinceField].options[i].selected = true;
			}
		}
		this.changeMapBG();
		
	}

	
	
	/* -- załadowanie wojewodztw  -- */
	this._loadProvinces = function(){
		this.oForm.elements[this.sProvinceField].options.length=0;
		this.oForm.elements[this.sProvinceField].options[0] = new Option('Wybierz ........','');
		var iQProvinces = this.aProvinces.length;
		for(i=0;i<iQProvinces;i++){
			this.oForm.elements[this.sProvinceField].options[i+1] = new Option(this.aProvinces[i].sName,this.aProvinces[i].iId);
		}
		this._setProvince(this.iProvinceID);
	}
	


	
	this._loadProvinces();
	this.oMapLayer.style.visibility = 'visible';
}







