// JavaScript Document

var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if(msie>0) iMsieVersion = parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
else iMsieVersion = 0;
iThumbnails_Delta = 0;

function popup(url_address,window_width,window_height,framename,additional) {
  sx = (screen.availWidth - window_width) / 2;
  sy = (screen.availHeight - window_height) / 2;
  params = "width="+window_width+",height="+window_height+",Left="+sx+",Top="+sy+",screenX="+sx+",screenY="+sy;
  if(additional>"") params += "," + additional;
  nw = window.open(url_address, framename, params);
  if(nw) nw.focus();
  return false;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function checkDateMy(frm) {
	var yearmonth = frm.yearmonth;
	var day = frm.day;
	var dyearmonth = frm.dyearmonth;
	var dday = frm.dday;
	var start = yearmonth.value+'-'+day.value;
	var end = dyearmonth.value+'-'+dday.value;
	if(start>=end) {
		var DayIndex = day.selectedIndex;
		var YearIndex = yearmonth.selectedIndex;
		if ((DayIndex+1)>30){
			if (YearIndex==dyearmonth.options.length-1){
				var newDayIndex = DayIndex;
				var newYearIndex = YearIndex;
			}else{
				var newDayIndex = 0;
				var newYearIndex = YearIndex+1;
			}
		}else{
			var newDayIndex = DayIndex+1;
			var newYearIndex = YearIndex;
		}
		dday.selectedIndex = newDayIndex;
		dyearmonth.selectedIndex = newYearIndex;
	}
}

function GoViaPost(sLink, sParams) {
	var oForm = document.createElement("FORM");
	if(oForm) {
		oForm.setAttribute("method", "POST");
		oForm.setAttribute("action", sLink);
		if(sParams) {
			a = sParams.split(/\&/);
			if(a && a.length) {
				for(i=0; i<=a.length-1; i++) {
					b = a[i].split(/\=/);
					oInput = document.createElement("INPUT");
					oInput.setAttribute("type", "HIDDEN");
					oInput.setAttribute("name", b[0]);
					oInput.setAttribute("value", b[1]);
					oForm.appendChild(oInput);
				}
			}
		}
		document.body.appendChild(oForm);
		oForm.submit();
	}
	return false;
}

function command(sText) { return false; }
function go(sText) { return false; }
function openpopup(sText) { return go(sText); }

function ShowInStatusbar(sText) {
	window.status = sText;
}

function ValidateOnlyIntegers(oInput) {
	if(!oInput) return "";
	if(!oInput.value) return "";
	var str = oInput.value;
	var new_str = "";
	for(var i=0; i<=str.length-1; i++) {
		ch = str.substr(i,1);
		if(ch>="0" && ch<="9") new_str += ch;
	}
	return new_str;
}

function PrepareLoadDataPage() {
	var oIframe = document.createElement("IFRAME");
	if(!oIframe) {
		for(var i=1; i<1000; i++) {
			document.body.focus();
			oIframe = document.createElement("IFRAME");
			if(oIframe) break;
		}
	}
	if(oIframe) {
		oIframe.style.width = "0px";
		oIframe.style.height = "0px";
		oIframe.style.display = "none";
		oIframe.style.visibility = "hidden";
		oIframe.style.border = "0px";
		oIframe.style.margin = "0px";
		oIframe = document.body.appendChild(oIframe);
		//oIframe.src = "/inc/prepareloaddatapage.php";
	}
	
	//var oIframe = document.getElementById('prepareloaddatapage');
	if(oIframe) {
		oIframe.setAttribute("src", "/inc/prepareloaddatapage.php");
		for(i=1; i<=100; i++) {
			if(oIframe.contentWindow.document && oIframe.contentWindow.document.body && oIframe.contentWindow.document.body.innerHTML=="LOADED") {
				return true;
			}
			document.body.focus();
		}
	}
	return true;
}

function CloseAnyOcmsInfoPanel() {
	var a = document.getElementsByTagName("DIV");
	if(a && a.length) for(var i=0; i<=a.length-1; i++) {
		if(a[i] && a[i].id && a[i].id.search(/^ocmsinfopanel/)!=-1) {
			a[i].style.display = "none";
		}
	}
	return false;
}

function GegIsoDate(iPlusDays, oDate) {
	if(!oDate) oDate = new Date();
	if(iPlusDays) oDate.setTime( oDate.getTime() + 24*60*60*1000 );
	var iDay = oDate.getDate();
	var sDay = (iDay<10 ? "0" : "") + iDay;
	var iMonth = oDate.getMonth() + 1;
	var sMonth = (iMonth<10 ? "0" : "") + iMonth;
	return oDate.getFullYear() + "-" + sMonth + "-" + sDay;
}

function GetDhtmlPosition(oNode) {
	var iLeft = 0;
	var iTop = 0;
	var oParentNode = oNode;
	while(oParentNode) {
		iLeft += oParentNode.offsetLeft;
		iTop += oParentNode.offsetTop;
		oParentNode = oParentNode.offsetParent;
	}
	return new Array(iLeft, iTop);
}


function ScrollElementToTheTop(oElement) {
	do {
		self.scrollBy(0,iThumbnails_Delta);
	} while(ScrollElementToTheTop_MustScrollThis(oElement));
}

function ScrollElementToTheTop_MustScrollThis(oElement) {
	var Y = document.body.offsetHeight;
	var iScrollY = 0;
	if(document.all) {
    iScrollY += document.body.scrollTop;
    if(iMsieVersion<=6) {
    	for(var i=0; i<=document.childNodes.length-1; i++) {
    		if(document.childNodes[i].tagName=="HTML") {
    			iScrollY += document.childNodes[i].scrollTop;
    			break;
    		}
    	}
    }
    else {
	    if(document.body.parentNode && typeof document.body.parentNode.scrollTop != "undefined") {
	      iScrollY += document.body.parentNode.scrollTop;
	    }
	  }
	}
	else iScrollY = self.scrollY;
	var iTop = oElement.offsetTop;
	var oParent = oElement.offsetParent;
	while(oParent) {
		iTop += oParent.offsetTop;
		oParent = oParent.offsetParent;
	}
	if(iTop<iScrollY && iScrollY>0) return -1;
	else if(iTop>iScrollY && iTop+oElement.offsetHeight-iScrollY>Y) return 1;
	else return 0;
}

function DoPublicLogin(iFormIndex) {
	var oForm = document.getElementById("ocmspubliclogoutform_" + iFormIndex);
	if(oForm) oForm.submit();
	return false;
}