﻿function reqPollFac(h){
	var s = this;
	s.html = h;
	s.required = s.html.getAttribute('required')||'false';
	s.flaConId = s.html.getAttribute('flacon')||null;
	s.flaCon = s.flaConId!==null?document.getElementById(s.flaConId):null;
	s.flaW = s.html.getAttribute('flaw')||600;
	s.flaH = s.html.getAttribute('flah')||400;
	s.flaS = s.html.getAttribute('flas')||'';
	s.fix_x = s.html.getAttribute('xfix')||null;
	s.fix_y = s.html.getAttribute('yfix')||null;
	s.flaHTML = s.flaS!=''?'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+s.flaW+'" height="'+s.flaH+'"><param name="movie" value="'+s.flaS+'" /><param name="quality" value="high" /><embed src="'+s.flaS+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+s.flaW+'" height="'+s.flaH+'"></embed></object>':null;
	if(s.html.currentStyle&&navigator.userAgent.indexOf("MSIE 7")==-1){//ie6
		var frame = document.createElement('iframe');
		frame.src = "javascript:''"
        frame.frameBorder = "0";
        frame.scrolling = "no";
        frame.className = "iframeShim";
        frame.style.zIndex = s.html.currentStyle.zIndex - 1;
		frame.style.width = parseFloat(s.html.offsetWidth) + 'px';
		frame.style.height = parseFloat(s.html.offsetHeight) + 'px';
		frame.style.visibility = 'hidden';
		frame.style.position = 'absolute';
		frame.style.top = getCurrentStyle(s.html,'top');
		frame.style.left = getCurrentStyle(s.html,'left');
		document.body.appendChild(frame);
		s.html.shim = frame;
	}
	if(s.required=='true') setTimeout(function(){s.popupDiv()},10);//s.popupDiv();
}

reqPollFac.prototype = {
	popupDiv : function(){
		var s = this;
		if(!window['windowMask']) window['windowMask'] = reqPollFac.createWinMask();
		if(s.flaCon&&s.flaHTML) s.flaCon.innerHTML = s.flaHTML;
		window['windowMask'].show();
		var coord = s.calXY();
		s.html.style.top = coord.y + ((s.fix_y!==null&&!isNaN(s.fix_y))?parseInt(s.fix_y):0) + 'px';
		s.html.style.left = coord.x + ((s.fix_x!==null&&!isNaN(s.fix_x))?parseInt(s.fix_x):0) + 'px';
		s.html.style.visibility = 'visible';
		if(s.html.shim){
			s.html.shim.style.width = parseFloat(s.html.offsetWidth) + 'px';
			s.html.shim.style.height = parseFloat(s.html.offsetHeight) + 'px';
			s.html.shim.style.top = coord.y + ((s.fix_y!==null&&!isNaN(s.fix_y))?parseInt(s.fix_y):0) + 'px';
			s.html.shim.style.left = coord.x + ((s.fix_x!==null&&!isNaN(s.fix_x))?parseInt(s.fix_x):0) + 'px';
			s.html.shim.style.visibility = 'visible';
		}
	},
	calXY : function(){
		var s = this;
		var pointer = {x:0,y:0};
		var scrollTop = document.documentElement.scrollTop||document.body.scrollTop,scrollLeft = document.documentElement.scrollLeft||document.body.scrollLeft;
		var winWH = getWindowWH();
		pointer.x = (winWH.w - parseFloat(s.html.offsetWidth))/2 + scrollLeft;
		pointer.y = (winWH.h - parseFloat(s.html.offsetHeight))/2 + scrollTop;
		return pointer;
	}
}

reqPollFac.createWinMask = function(){
	if(!window['windowMask'] || window['windowMask'].nodeType!=1 || window['windowMask'].tagName!='div'){
		var div = document.createElement('div');
		div.className = 'windowMask';
		if(typeof(div.style.filter)!='undefined') div.style.filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
		else div.style.MozOpacity=0.7;
		document.body.appendChild(div);
		div.setWH = function(){
			var s = this;
			var winWH = getWindowWH();
			var docWH = getDocumentWH();
			s.style.width = docWH.w + 'px';//Math.max(winWH.w,docWH.w) + 'px';
			s.style.height = Math.max(winWH.h,docWH.h) + 'px';
		}
		div.show = function(){
			var s = this;
			s.setWH();
			s.style.visibility = 'visible';
			var sel = document.getElementsByTagName('select');
			if(s.currentStyle&&navigator.userAgent.indexOf("MSIE 7")==-1){//ie6
				window['winMaskSel'] = new Array();
				for(var i=0;sel[i];i++) if(!sel[i].getAttribute('divsel')){
					sel[i].disabled = true;
					window['winMaskSel'].push(sel[i]);
				}
			}
		}
		div.hide = function(){
			var s = this;
			s.style.visibility = 'hidden';
			var sel = document.getElementsByTagName('select');
			if(window['winMaskSel']) for(var i in window['winMaskSel']) window['winMaskSel'][i].disabled = false;
		}
		return div;
	}
	return window['windowMask'];
}

function closePopupPoll(id){
	var o = window['sapModuleIns']&&window['sapModuleIns'][id];
	if(o&&o.html&&o.html.nodeType==1&&o.popupDiv){
		o.html.style.visibility = 'hidden';
		if(o.flaCon&&o.flaHTML) o.flaCon.innerHTML = '';
		if(o.html.shim) o.html.shim.style.visibility = 'hidden';
		if(window['windowMask']) window['windowMask'].hide();
	}
}

function fixWinMask(){
	if(window['windowMask']&&window['windowMask'].nodeType==1&&window['windowMask'].style.visibility!='hidden') window['windowMask'].setWH();
}

myAttachEvent(window,'resize',fixWinMask);
function dashify(str){return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();}
function getCurrentStyle(element,styleProp){var retVal;if(element.currentStyle){retVal = element.currentStyle[styleProp];}else if(document.defaultView && document.defaultView.getComputedStyle){retVal = document.defaultView.getComputedStyle(element,null).getPropertyValue(dashify(styleProp));}else{retVal = null;}return retVal;}
