function AWConfirm(onDeleteFunction, param) {
	confirmWin.showAW();
	confirmWin.setParam(param);
	confirmWin.setOnDeleteFunction(onDeleteFunction);
}

function getCenterTop() {
	return 200 + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
}

function getCenterLeft() {
	width = screen.width - 600;
	return width / 2;
}

function getField(form, name) {
	if (typeof form[name] == 'undefined') return '';
	return form[name].value;
}
	
function prepareParameter(paramName, paramValue) {
	return paramName+ "=" + escape(encodeURI(paramValue));		
}
	
function getFieldAsFormParameter(form, name) {
	field = getField(form, name);
	return prepareParameter(name, field);
}

//http://www.quirksmode.org/js/dragdrop.html

function addEvent (el, evname, func) {
	if (el.attachEvent) { // IE
		el.attachEvent("on" + evname, func);
	} else if (el.addEventListener) { // Gecko / W3C
		el.addEventListener(evname, func, true);
	} else {
		el["on" + evname] = func;
	}
}

function removeEvent (el, evname, func) {
	if (el.detachEvent) { // IE
		el.detachEvent("on" + evname, func);
	} else if (el.removeEventListener) { // Gecko / W3C
		el.removeEventListener(evname, func, true);
	} else {
		el["on" + evname] = null;
	}
}

var draggedAW = null;	//current absWin object - the one which is showed

function startDragMouse (e) {
	startDrag(draggedAW);
	var evt = e || window.event;
	draggedAW.initialMouseX = evt.clientX;
	draggedAW.initialMouseY = evt.clientY;
	addEvent(document,'mousemove',dragMouse);
	addEvent(document,'mouseup',releaseElement);
	return false;
}

function startDrag(obj) {
	if (draggedAW.draggedObject)
		releaseElement();
		
	for(var i=0; i < draggedAW.draggedElementsCount; i++){
		draggedAW.draggedElements[i]['startX'] = parseInt(draggedAW.draggedElements[i]['name'].style.left);
		draggedAW.draggedElements[i]['startY'] = parseInt(draggedAW.draggedElements[i]['name'].style.top);
	}
	
	draggedAW.draggedObject = obj;
	//obj.className += ' dragged';ADD DRAG STYLE
}

function dragMouse(e) {
	var evt = e || window.event;
	var dX = evt.clientX - draggedAW.initialMouseX;
	var dY = evt.clientY - draggedAW.initialMouseY;
	setPosition(dX,dY);
	return false;
}

function setPosition(dx,dy) {
	//absWin.draggedObject.style.left = absWin.startX + dx + 'px';
	//absWin.draggedObject.style.top = absWin.startY + dy + 'px';
	for(var i=0; i < draggedAW.draggedElementsCount; i++){
		draggedAW.draggedElements[i]['name'].style.left = draggedAW.draggedElements[i]['startX']+ dx + 'px';
		draggedAW.draggedElements[i]['name'].style.top = draggedAW.draggedElements[i]['startY'] + dy + 'px';
	}
}

function releaseElement() {
	removeEvent(document,'mousemove',dragMouse);
	removeEvent(document,'mouseup',releaseElement);
	//absWin.draggedObject.className = absWin.draggedObject.className.replace(/dragged/,'');REMOVE DRAG STYLE
	draggedAW.draggedObject = null;
}

function getRealScreenHeight(){
	document.getElementById('htmlId').className = 'fullHeight';
	var realHeight = document.getElementById('bodyId').offsetHeight;
	document.getElementById('htmlId').className = '';
	return realHeight;
}

absWin = function(showActionFog, dragger, dragElements, AWFogId, AWShId, AWId, AWFrameId, AWShTRId, AWLoadingId, AWErrorId, AWContentId) {
	this.initialMouseX = null;
	this.initialMouseY = null;
	this.draggedObject = null;
	
	this.param = null;
	this.onCustomFunction = null;
	
	this.buttonName = null;
	this.showActionFog = showActionFog;
	
	this.elemAWFogId = document.getElementById(AWFogId);
	this.elemAWShId = document.getElementById(AWShId);
	this.elemAWId = document.getElementById(AWId);
	this.elemAWFrameId = document.getElementById(AWFrameId);
	this.elemAWShTRId = document.getElementById(AWShTRId);
	this.elemAWLoadingId = document.getElementById(AWLoadingId);
	this.elemAWErrorId = document.getElementById(AWErrorId);
	this.elemAWContentId = document.getElementById(AWContentId);
	this.elemAWContentFogId = document.getElementById(AWContentId + '_fog');
	
	this.draggedElements = new Array();
	this.draggedElementsCount = dragElements.length;
	
	for(var i=0; i < this.draggedElementsCount; i++){
		this.draggedElements[i] = new Array();
		this.draggedElements[i]['name'] = document.getElementById(dragElements[i]);
	}
		
	if (typeof dragger == 'string')
		element = document.getElementById(dragger);
	element.onmousedown = startDragMouse;
	
	
	function showAW(){
		draggedAW = this;
	
		var top = getCenterTop();
		var left = getCenterLeft();	
	
		this.setAbsPosition(left, top);
	
		var screenHeight = getRealScreenHeight();
				
		if(screenHeight > document.getElementById('bodyId').offsetHeight){
			setHeight(this.elemAWFogId, screenHeight);
		}
		else{
			heightCopy(document.getElementById('bodyId'), this.elemAWFogId , 0);
		}
	
		this.elemAWFogId.style.display = 'block';
		this.elemAWId.style.display = 'block';
		this.elemAWShId.style.display = 'block';
		
		showIFrameFix(this.elemAWFogId);
				
		heightCopy(this.elemAWFrameId, this.elemAWShTRId , -5);	
	}
	
	function hideAW(){
		this.hideLoading();
		this.hideError();
		
		hideIFrameFix(this.elemAWFogId);
		
		this.elemAWShId.style.display = 'none';
		this.elemAWId.style.display = 'none';
		this.elemAWFogId.style.display = 'none';
		
		draggedAW = null;
	}
	
	function setAbsPosition(x,y) {
		this.draggedElements[0]['name'].style.left = x + 'px';
		this.draggedElements[0]['name'].style.top = y + 'px';

		this.draggedElements[1]['name'].style.left = x + 5 + 'px';
		this.draggedElements[1]['name'].style.top = y + 5 + 'px';
	}
	
	function showLoading(){
		this.hideError();
		this.elemAWLoadingId.style.display = 'block';
		if (this.showActionFog) {
			heightCopy(this.elemAWContentId, this.elemAWContentFogId , -5);
			this.elemAWContentFogId.style.display = 'block';
		}
	}
	
	function hideLoading(){
		this.elemAWLoadingId.style.display = 'none';
		if (this.showActionFog) {
			this.elemAWContentFogId.style.height = '0px';
			this.elemAWContentFogId.style.display = 'none';
		}
	}
	
	function showError(){
		this.hideLoading();
		this.elemAWErrorId.style.display = 'block';
	}
	
	function hideError(){
		this.elemAWErrorId.style.display = 'none';
	}
	
	function setContent(text) {
		this.elemAWContentId.innerHTML = text;
		heightCopy(this.elemAWFrameId, this.elemAWShTRId , -5);
	}
	
	function setOnDeleteFunction(func) {
		this.onCustomFunction = func;
	}
	
	function onDeleteFunction() {
		if (this.getParam() != '')
			this.onCustomFunction(this.getParam());
		else
			this.onCustomFunction();
	}
	
	function setParam(param) {
		this.param = param;
	}
	
	function getParam() {
		return this.param;
	}
	
	//declare methods
	this.showAW = showAW;
	this.hideAW = hideAW;
	this.setAbsPosition = setAbsPosition;
	
	this.setContent = setContent;
	
	this.showLoading = showLoading;
	this.hideLoading = hideLoading;
	
	this.showError = showError;
	this.hideError = hideError;
	
	this.setOnDeleteFunction = setOnDeleteFunction;
	this.onDeleteFunction = onDeleteFunction;
	
	this.setParam = setParam;
	this.getParam = getParam;
	
}


