// functions for sharepointlists
var LastPageRow = "";
function getContentOfSharepointList(ListGenId, ViewId, StartItem, Rendering, ItemsPerPage, bRerender, bTryAuthentication)
{
    if (ListGenId.tagName) {
        ListGenId = GetListGenIdFromDiv(ListGenId);
        if (ListGenId == "")
            return;
    }
    if (!bTryAuthentication)
        bTryAuthentication = false;
        
	var sClientHost = document.location.protocol + "//" + document.location.hostname;
	if (document.location.port != "")
		sClientHost += ":"+ document.location.port; 
        
    var ListId = ListGenId.substring(0, ListGenId.lastIndexOf("_genid"));
	var aPages = eval("aPages_" + ViewId.replace("\{","").replace("\}","").replace(/-/g, ""));
	var ContentUrl = L_Menu_BaseUrl + "/_layouts/Querplex/Siemens/WCMS3/service/ioservice.aspx?command=getcontentofsharepointlist&listid=" + encodeURIComponent(ListId) + "&viewid=" + encodeURIComponent(ViewId) + "&startitem=" + encodeURIComponent(StartItem) + "&rendering=" + encodeURIComponent(Rendering) + "&itemsperpage=" + ItemsPerPage + "&page=" + aPages.length + "&TryAuthentication=" + bTryAuthentication + "&ClientHost=" + encodeURIComponent(sClientHost);
	if (aPages)
	{
		FillPagesArray(aPages, ContentUrl);
	}
	FillInContent(ListGenId, ListId, ContentUrl, bRerender);
}
function getPreviousPage(ListGenId, ViewId, Page)
{
    if (ListGenId.tagName) {
        ListGenId = GetListGenIdFromDiv(ListGenId);
        if (ListGenId == "")
            return;
    }
    var ListId = ListGenId.substring(0, ListGenId.lastIndexOf("_genid"));
	var aPages = eval("aPages_" + ViewId.replace("\{","").replace("\}","").replace(/-/g, ""));
	aPages.pop();
	FillInContent(ListGenId, ListId, aPages[aPages.length-1], true);
//	if(aPages[Page])
//	{
//		FillInContent(ListId, aPages[Page], true);
//	}
}
function GetListGenIdFromDiv(oThis)
{
    var sListGenId = "";
    var oParentNode = oThis;
    while (true)
    {
        if (oParentNode.id.substring(0, 4) == "spl_") {
            sListGenId = oParentNode.id.substring(4);
            break;
        }
        oParentNode = oParentNode.parentNode;
        if (oParentNode == null)
            break;
    }
    return sListGenId;
}

function FillInContent(ListGenId, ListId, ContentUrl, bRerender)
{
    document.getElementById("spl_" + ListGenId).innerHTML = "<img src='/_layouts/Querplex/Siemens/WCMS3/images/loadingcircle.gif'></img>";
    jQuery.get(ContentUrl, function(data) {
    if ((data.xml && data.xml.indexOf("<error>") > -1)) {
            document.getElementById("spl_" + ListGenId).innerHTML = "<p>Error: " + data.selectSingleNode("//error").text + "</p>";
        }
        else if (!data.xml && data.indexOf("<error>") > -1)
            alert(data);
        else if (data.xml)
            document.getElementById("spl_" + ListGenId).innerHTML = "<p title='" + data.xml + "'>No Data</p>";
        else
            document.getElementById("spl_" + ListGenId).innerHTML = data;
    });
}
function FillPagesArray(aPages, Url)
{
	if(aPages.length == 0)
	{
		aPages.push(Url);
		return; 
	}
	var bFillIn = true;
	for(var i=0; i<aPages.length; i++)
	{
		if(aPages[i] == Url)
		{
			bFillIn = false;
			break;
		}
	}
	if(bFillIn == true)
	{
		aPages.push(Url);
	}
}
//#####################################################
//open a print window
function PrintThisPage(sUrl, nWidth)
{
	var sOpenUrl = sUrl;
	if (sOpenUrl.indexOf("?") > -1)
		sOpenUrl += "&";
	else
		sOpenUrl += "?";
	sOpenUrl += "printpage=true";
	openWindow(sOpenUrl, nWidth, -1, "scrollBars=1,resizable=1");
}

function getPos(id)
{
	return getPosByObject(document.getElementById(id));
}
function getPosByElement(obj)
{
	var pos = {left:0, top:0};

	if(typeof obj.offsetLeft != 'undefined')
	{
		while (obj) {
			pos.left += obj.offsetLeft;
			pos.top += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else {
		pos.left = obj.left;
		pos.top = obj.top;
	}

	return pos;
}

function maxPosition()
{
	var iMaxPos = -Number.MAX_VALUE;

	for(var i = 0; i < maxPosition.arguments.length; i++) {
		if(maxPosition.arguments[i] > iMaxPos) {
			iMaxPos = maxPosition.arguments[i];
		}
	}
	return iMaxPos;
}

function setObjectHeight(id, height)
{
	var obj = document.getElementById(id);
	obj.style.height = height + "px";
}

function getObjectHeight(id)
{
	var obj = document.getElementById(id);
	var iObjectHeight = 0;
	iObjectHeight = obj.offsetHeight;
	return parseInt(iObjectHeight);
}

function getWindowInnerSize(win)
{
	if(!win) win = window;
		var objWin = new Object();
		if(typeof win.innerWidth != 'undefined') {
			objWin.width = win.innerWidth;
			objWin.height = win.innerHeight;
		} else {
			var obj = getBody(win);
			objWin.width = parseInt(obj.clientWidth);
			objWin.height = parseInt(obj.clientHeight);
		}
		return objWin;
}

function getBody(w)
{
	return (w.document.compatMode && w.document.compatMode == "CSS1Compat") ? w.document.documentElement : w.document.body || null;
}

function positionFooter()
{
	var iSecNavPos = getPos("sec-nav-footer-placeholder").top;
	var iContentPos = getPos("content-footer-placeholder").top;
	var iContextPos = getPos("context-footer-placeholder").top;

	var iWindowInnerHeight = getWindowInnerSize().height;
	var iWindowMinPos = iWindowInnerHeight - getObjectHeight("footer-padding");

	var iMaxValue = maxPosition(iSecNavPos, iContentPos, iContextPos, iWindowMinPos);

	var iContentFooterPHHeight = 0;

	if (iMaxValue > iContentPos) {
		iContentFooterPHHeight = iMaxValue - iContentPos;
	}

	setObjectHeight("content-footer-placeholder", iContentFooterPHHeight);
}


/*

//START: Fix IE 6 Text Selection Bug
if (window.createPopup && document.compatMode && document.compatMode=="CSS1Compat")
{
	document.onreadystatechange = onresize = function fixIE6AbsPos()
	{
		if (!document.body) return;
		onresize = null;
		document.body.style.height = 0;
		setTimeout(function() { document.body.style.height = document.documentElement.scrollHeight+'px'; }, 1);
		setTimeout(function() { onresize = fixIE6AbsPos; }, 100);
	}
}
//END: Fix IE 6 Text Selection Bug


*/


function init()
{
	sStatus = "loaded";
}
//window.onresize = init;


/* check the width of the image an resize it to nMaxWidth */
function imageloadcomplete(nMaxWidth)
{
	if (event.srcElement.readyState != "complete")
		return;
	if (!nMaxWidth)
		return;
	
	var oThis = event.srcElement;
	oThis.style.width = "";
	var nWidth = oThis.width;
	if (nWidth == 0)
	{
		var oImage = new Image();
		oImage.src = oThis.src;
		nWidth = oImage.width;
	}
	if (nWidth > nMaxWidth)
		oThis.style.width = nMaxWidth + "px";
}

function gotoLinkWithSubmit() {
	document.forms[0].action = "";
	document.forms[0].submit();
	return;
}
function gotoLink(oThis, sThisValue) {
    var sValue = "";
    if (sThisValue != null)
    {
        sValue = sThisValue
    }
    else
    {
        if (oThis.options && oThis.options[0])
            sValue = oThis.options[0].value;
        if (oThis.options && oThis.options[oThis.selectedIndex])
	        sValue = oThis.options[oThis.selectedIndex].value;
	    if (sValue.substring(0, "dpglossarycategory".length) == "dpglossarycategory")
	    {
		    document.getElementById("dpglossarycategory").value = sValue.substring("dpglossarycategory".length+1);
		    document.forms[0].action = "";
		    document.forms[0].submit();
		    return;
	    }
	}
	if (sValue == "")
	    return "";
	    
	var sGotoURL = '';
	if (oThis.tagName.toUpperCase() == 'SELECT');
		sGotoURL = sValue;
	if (sGotoURL != '') {
		if (sGotoURL.substring(sGotoURL.length-7) == ",_blank")
		{
			sGotoURL = sGotoURL.substring(0, sGotoURL.length-7);
			window.open(sGotoURL);
		}else{
			location.href = sGotoURL;
		}
	}
}

function openWindow(OpenUrl, Width, Height, Param)
{
	var nWidth = Width;
	if (!Width || Width == -1)
		nWidth = screen.availWidth - 10;
	var nLeft = (screen.availWidth - nWidth) / 2;
	var nHeight = Height;
	if (!Height || Height == -1)
		nHeight = screen.availHeight - 30;
	var nTop = (screen.availHeight - nHeight) / 2;
	if (nTop > 9)
	    nTop = nTop -10;
    
    var sParam = ",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0";
    if (Param) {
        if (Param.substring(1,1) != ",")
            sParam = "," + Param;
        else
            sParam = Param;
    }
    if (sParam.indexOf("scrollBars") == -1)
        sParam += ",scrollBars=0";
    if (sParam.indexOf("resizable") == -1)
        sParam += ",resizable=0";
        
    newPage = window.open(OpenUrl, '', "width=" + nWidth + ",height=" + nHeight + ",left=" + nLeft +",top=" + nTop + sParam);
    newPage.focus();
}


//toggle between open and close of a portlet box
function toggle_boxOpenClose(oElement)
{
	var bOpen = false;
	if (oElement.className == "boxopen") {
		oElement.className = "boxclose";
	}else{
		oElement.className = "boxopen";
		bOpen = true;
	}
	oElement = oElement.parentNode;
	var oContentDiv = oElement.getElementsByTagName("DIV");
	var oContentDivLength = oContentDiv.length;

	for (var xi=0;xi<oContentDivLength;xi++) {
		if (oContentDiv[xi].className == "portlet-content") {
			if (bOpen)
				oContentDiv[xi].style.display = "block";
			else
				oContentDiv[xi].style.display = "none";
			break;
		}
	}
	
}

//toggle_RelatedBoxOpenClose
function toggle_RelatedBoxOpenClose(oThis, sBlockElementName)
{
	var oBlockElm = document.getElementById(sBlockElementName);
	if (oThis.className == "hingedboxopen") {
		oBlockElm.style.display = "none";
		oThis.className = "hingedboxclose";
	}else{
		oBlockElm.style.display = "";
		oThis.className = "hingedboxopen";
	}
}
//open a portlet linkbox
var oOpenLinkBox = null;
function do_LinkBoxOpen(sId)
{
	if (oOpenLinkBox != null) {
		var sOldId = oOpenLinkBox.id.substring(3);
		document.getElementById("lbc" + sOldId).style.display = "none";
		if (document.getElementById("pbp" + sOldId))
		    document.getElementById("pbp" + sOldId).className = "category";
		oOpenLinkBox.className = "linkboxopen";
		if (sOldId == sId) {
			oOpenLinkBox = null;
			return;
		}
		oOpenLinkBox = null;
	}

	document.getElementById("lbc" + sId).style.display = "block";

	if (document.getElementById("pbp" + sId))
	    document.getElementById("pbp" + sId).className = "linkboxopencolor category";
	oOpenLinkBox = document.getElementById("pbd" + sId);
	oOpenLinkBox.className = "linkboxclose";
}
//open a portlet NewschannelCategory
var oSelectAggCategoryDIV = null;
function do_SelectCategory(oThis)
{
    if (oSelectAggCategoryDIV)
        oSelectAggCategoryDIV.style.display = "none";

	var sId = oThis.options[oThis.selectedIndex].value;

	oSelectAggCategoryDIV = document.getElementById(sId);
	oSelectAggCategoryDIV.style.display = "block";
}

//toggle SharePoint View Group
function toggleGroup(oThis)
{
    var sTgId = jQuery(oThis).attr("togglegroup");
    if (!jQuery(oThis).hasClass("open"))
    {
        jQuery(oThis).addClass("open");
        jQuery("*[toggleid='toggle_" + sTgId + "']").show();
    }
    else
    {
        jQuery(oThis).removeClass("open");
        jQuery("*[toggleid='toggle_" + sTgId + "']").hide();
    }   
}

//selectSharedContent
function selectSharedContent(oThis)
{
	event.cancelBubble = true;
	event.returnValue = false;
	if (!oThis)
		return false;

	window.returnValue = oThis.guid;
	self.close();
}


//Zoom
function OpenZoomPopup(url, description, opentype)
{
    var sOpenParam = 'resizable=no,menubar=no,status=no,scrollbars=no,toolbar=no';
    if (opentype == "Video")
        sOpenParam += ',width=480,height=376';
    else
        sOpenParam += ',width=900,height=700';
    window.open(L_Menu_BaseUrl + "/_layouts/Querplex/Siemens/WCMS3/service/ioservice.aspx?command=showzoompopup&uid=" + url + "&description=" + encodeURI(description) + "&opentype=" + opentype, '', sOpenParam);
	return false;
}
//Zoom


//Flash
/*
function showFlash(classname, flashID, flashSrc, flashWidth, flashHeight, flashParameter1, flashParameter2, flashParameter3, flashParameter4, flashParameter5) {
    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if (!hasReqestedVersion || flashSrc == "") {
		setTimeout("visiblePicture('" + flashID + "')", 50);
		return;
	}

	var sTmp = "";
	sTmp += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	sTmp += '	codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"';
	sTmp += '	class="' + classname + '"';
	sTmp += '	WIDTH="' + flashWidth + '"';
	sTmp += '	HEIGHT="' + flashHeight + '"';
	sTmp += '	id="flashid' + flashID + '"';
	sTmp += '	ALIGN="">';
	sTmp += '	<param name="movie" value="' + flashSrc + '" />';
	sTmp += '	<param name="wmode" value="opaque"/>';                        
	sTmp += '	<param name="play" value="false">';
	sTmp += '	<param name="loop" value="false">';
	sTmp += '	<param name="quality" value="high">'
	sTmp += '	<param name="menu" value="false">';  					
	if (flashParameter1)
		sTmp += '	<param name="FlashVars" value="' + flashParameter1.replace('"', '\\"') + '">';
	if (flashParameter2)
		sTmp += '	<param name="FlashVars" value="' + flashParameter2.replace('"', '\\"') + '">';
	if (flashParameter3)
		sTmp += '	<param name="FlashVars" value="' + flashParameter3.replace('"', '\\"') + '">';
	if (flashParameter4)
		sTmp += '	<param name="FlashVars" value="' + flashParameter4.replace('"', '\\"') + '">';
	if (flashParameter5)
		sTmp += '	<param name="FlashVars" value="' + flashParameter5.replace('"', '\\"') + '">';
	
	sTmp += '	<EMBED src="' + flashSrc + '"';
	sTmp += '		class="' + classname + '"';
	sTmp += '		quality="high" play="true" loop="true" menu="false" wmode="opaque"';
	sTmp += '		swLiveConnect="true"';
	sTmp += '		WIDTH="' + flashWidth + '"';
	sTmp += '		HEIGHT="' + flashHeight + '"';
	sTmp += '		NAME="' + flashID + '"';
	sTmp += '		TYPE="application/x-shockwave-flash" ';
	sTmp += '		PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"';
	if (flashParameter1)
		sTmp += '	FlashVars="' + flashParameter1.replace('"', '\\"') + '"';
	if (flashParameter2)
		sTmp += '	FlashVars="' + flashParameter2.replace('"', '\\"') + '"';
	if (flashParameter3)
		sTmp += '	FlashVars="' + flashParameter3.replace('"', '\\"') + '"';
	if (flashParameter4)
		sTmp += '	FlashVars="' + flashParameter4.replace('"', '\\"') + '"';
	if (flashParameter5)
		sTmp += '	FlashVars="' + flashParameter5.replace('"', '\\"') + '"';
	sTmp += '		>';
	sTmp += '	</EMBED> ';
	sTmp += '</object>';
	
	document.write(sTmp);
}
function visiblePicture(flashID)
{
	var oPicElm = document.getElementById("imgid" + flashID);
	if (!oPicElm)
		return;
	oPicElm.style.display = "inline";
}
//
*/


// Globals
// Major version of Flash required
var requiredMajorVersion = 7;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// the version of javascript supported
var jsVersion = 1.0;

