var phcHtml;
var strHtml;


var _sAttributDelimiter = "<attrib>";
var _sItemDelimiter = "<item>";

function changePostingProperties(strFolderPath,strGuid) { // obsolete
	window.open(strFolderPath + "/EditPostingProperties.aspx?PostingGuid=" + strGuid,"PostingProps","width=600,height=500,scrollbars=yes,status=no,toolbar=no,resizable=no,menubar=no,location=no");
}

function LayoutProperties(strFolderPath,strGuid) {
	window.open(strFolderPath + "/LayoutProperties.aspx?PostingGuid=" + strGuid,"PostingProps","width=945,height=820,scrollbars=yes,status=no,toolbar=no,resizable=yes,menubar=no,location=no");
}

function MetaTagEditor(strFolderPath,strGuid) {
	window.open(strFolderPath + "/MetaTagEditor.aspx?PostingGuid=" + strGuid,"MetaTagEditor","width=945,height=820,scrollbars=yes,status=no,top=100,toolbar=no,resizable=yes,menubar=no,location=no");
}

function websiteAdmin(strFolderPath,strGuid) {
	window.open(strFolderPath + "/WebsiteAdmin.aspx?ChannelGuid=" + strGuid,"PostingProps","width=800,height=665,scrollbars=yes,status=yes,toolbar=no,resizable=no,menubar=no,location=no");
}

function showPublicUrl(strPublicUrl) {
	prompt("Public URL of current posting.", strPublicUrl);
}


/* functions for r.a.d.editor (prevent from strange headlines such as <h2><h3><p>text</p></h3></h2>): */
var selValue = null;
var doNotCheck = false;

function CleanFormat(editor, commandName, oTool) {  
	if ("FormatBlock" == commandName) { 
		if (doNotCheck) return;   
		if ("body" != oTool.GetSelectedValue())	{ 
			selValue = oTool.GetSelectedValue();
			var newTool = { GetSelectedValue: function(){return "body";} };    
			editor.Fire (commandName, newTool);    
		}   
	}
}

function CleanFormat2(editor, commandName, oTool) {  
	if ("FormatBlock" == commandName) {   
		if ("body" != oTool.GetSelectedValue())	{ 
		if (doNotCheck) {
			doNotCheck = false;
			return;
		}   
		var newTool = { GetSelectedValue: function(){return selValue;} };   
		doNotCheck = true;     
		editor.Fire (commandName, newTool);    
		}   
	}
}
/* r.a.d. functions end /*/


function normalizeClipBoard()
{
	var clipboard = window.clipboardData.getData('Text');
	
	if (clipboard != null)
	{		
		/*var reg = new RegExp("<(.|\n)+?>","gi");
		var newClipboard = clipboard.replace(reg, "");
		
		document.test.textfeld.value = newClipboard; */
		
	  document.test.textfeld.value = clipboard;
		newText = document.test.textfeld.createTextRange();
		newText.execCommand("RemoveFormat");
		newText.execCommand("Copy");
	}
}

function insertCodeFragment(strPlaceholderId , ddlStyleList)
{
	phcHtml = document.getElementById("NCPHRICH_" + strPlaceholderId);

	/*switch(ddlStyleList.value){
		case "PicLeftTextRight":
			insertPicLeftTextRight(phcHtml);
		break;
		
		case "TextLeftPicRight":
			insertTextLeftPicRight(phcHtml);
		break;
	}*/
	if (ddlStyleList.value != "")
		phcHtml.insertHTML(ddlStyleList.value);
	
	ddlStyleList.selectedIndex = 0;
	window.focus();
} 



/*
------------------------------------------------
Scripts für den ResourceBrowser
------------------------------------------------
*/



//
//  ID = Picture ID
//	BasePath = Base path to the MSCMS Base
//	strTxtId = ClientID from the hidden textbox
//	strPicId = ClientID from the target picture control
//
function openImageSelect(ID, BaseGlobalPath, strTxtId, strPicID )
{ 
	// neues Media Objekt
	obMedia = new MediaObject('','','');
	// hole neues Media Objekt
	obMedia = window.showModalDialog(BaseGlobalPath + "Resources/ResourceBrowser.aspx","","status:false;dialogWidth:780px;dialogHeight:670px");
	// verarbeite Rückgabewerte
	if(obMedia != null)
	{ 
		// zeige Bild in Übersicht
		document.getElementById(strPicID).src = obMedia.PicUrl;
		var sPicGUID = obMedia.PicGuid;
		var sPicUrl = obMedia.PicUrl;
		// aktualisiere Daten
		updateHiddenField(strTxtId,strPicID,sPicGUID,sPicUrl,null);
	}
	// destroy objekt
	obMedia = null;
}

function openImageSelectForHover(BaseGlobalPath, strTxtId, strPicID )
{ 
	obMedia = new MediaObject('','','');
	obMedia = window.showModalDialog(BaseGlobalPath + "Resources/ResourceBrowser.aspx","","status:false;dialogWidth:780px;dialogHeight:670px");
	
	if(obMedia != null)
	{ 
		document.getElementById(strTxtId).value = obMedia.PicUrl;
		document.getElementById(strPicID).src = obMedia.PicUrl;
	}
}
//
// Rückgabeobjekt vom Resource selector
// ImageGUID
// PictureURL
// PictureCountID
//
function MediaObject(strPicGuid, strPicUrl, strPicID)
{ 
	this.PicGuid = strPicGuid;
	this.PicUrl = strPicUrl;
	this.PicID	= strPicID;
}


//
// Wenn ein Item ausgewählt wurde, dann füllt die Textbox mit
// dem Namen der Datei und fülle auch die versteckten Felder
//
//
function setMediaItemValue(strName, strURL, strPicGuid, strPicID)
{ 
	// setzte textbox mit dem selektierten Item
	var objtxt = document.getElementById('txtSelectedPicture');
		objtxt.innerText = strName;
		objtxt.style.backgroundColor = "#EEEEEE";
		objtxt.style.color = "#000000";
	
	// fülle die verstecken Felder
	document.getElementById('txtPicGuid').value = strPicGuid;
	document.getElementById('txtURL').value = strURL;
	document.getElementById('txtPicID').value = strPicID;
	
}
	
//
// Show Resource Images in IFrame
//
//			
function loadMediaItems(strGUID, strPicID)
{ 
	document.getElementById('divStepTwo').style.visibility = "visible";
	document.getElementById('divStepTwo').style.display = "block";
	document.getElementById('divStepTwoHeader').style.visibility = "visible";
	document.getElementById('divStepTwoHeader').style.display = "block";
	oIframe = document.getElementById('ifrItems');
	oIframe.setAttribute("src","ResourceItems.aspx?ResGUID=" + strGUID + "&type=image&id=" + strPicID);
}

//
// Show Resource Files in IFrame
//
//			
function loadMediaItemsAllFiles(strGUID, strPicID)
{ 
	document.getElementById('divStepTwo').style.visibility = "visible";
	document.getElementById('divStepTwo').style.display = "block";
	document.getElementById('divStepTwoHeader').style.visibility = "visible";
	document.getElementById('divStepTwoHeader').style.display = "block";
	oIframe = document.getElementById('ifrItems');
	oIframe.setAttribute("src","ResourceItems.aspx?type=all&ResGUID=" + strGUID + "&type=image&id=" + strPicID);
}

//
// Show Resource Files filtered by extensions in IFrame
//
//			
function loadMediaItemsByExtensions(strGUID, strPicID, strAllowedExtensions)
{ 
	document.getElementById('divStepTwo').style.visibility = "visible";
	document.getElementById('divStepTwo').style.display = "block";
	document.getElementById('divStepTwoHeader').style.visibility = "visible";
	document.getElementById('divStepTwoHeader').style.display = "block";
	oIframe = document.getElementById('ifrItems');
	oIframe.setAttribute("src","ResourceItems.aspx?extensions=" + strAllowedExtensions + "&ResGUID=" + strGUID + "&type=image&id=" + strPicID);
}



//
// cancel ModalDialog return null value
// and close window
//
function cancelOperation()
{ 
	returnValue = null;
	window.close();
}

//
// Fülle Objekt für die Rückgabe
// und schliesse den ModalDialog
//
function insertImage()
{
	strPicURL = document.getElementById('txtURL').value;
	strPicGuid = document.getElementById('txtPicGuid').value;
	strPicID = document.getElementById('txtPicID').value;
	var obMedia = new MediaObject(strPicGuid, strPicURL, strPicID);
	returnValue = obMedia;
	window.close();
}



//
// lösche das Bild
//
//
function deleteImage( strPicID, strNoPicURL, strTxtId )
{
	// zeige nopic in Übersicht
	var objPic = document.getElementById(strPicID);
	objPic.src = strNoPicURL;
	objPic.width = 30;
	// update daten
	updateHiddenField(strTxtId,strPicID,'','',null);
}

//
// Aktualisiert das versteckte Feld mit den Daten
//
//
function updateHiddenField(strTextBoxID,strPicID,PicGUID,PicURL,DestinationURL)
{

	// alte Werte vom Textfeld
	var strPicValuesOld = document.getElementById(strTextBoxID).value;
	// schreibe in einen Array
	var arrOldPictures = strPicValuesOld.split("$");
	// Varialbe für die neuen Werte
	var strPicValuesNew = ""; 
	
	
	// 
	for (i=0;i<=arrOldPictures.length-1; i++)
	{
		var arrItem = arrOldPictures[i].split("|");
		if (arrItem[0] == strPicID)
		{
			// Image ID
			if (strPicID != null)
				arrItem[0] = strPicID;
			// Image GUID
			if (PicGUID != null)
				arrItem[1] = PicGUID;
			// Image URL
			if (PicURL != null)
				arrItem[2] = PicURL;
			// Destination URL
			if (DestinationURL != null)
				arrItem[3] = DestinationURL;

			// schreibe aktuelles item	
			arrOldPictures[i] = arrItem[0]+"|"+arrItem[1]+"|"+arrItem[2]+"|"+arrItem[3]
		}
		strPicValuesNew += arrOldPictures[i] + "$";
	}
	
	// schneide letztes "$" ab
	strPicValuesNew = strPicValuesNew.substring(0,strPicValuesNew.length-1);
	
	// schreibe neue Values in verstecktes textfeld
	document.getElementById(strTextBoxID).value = strPicValuesNew;	
	
}




//
// Füge Destination URL für das Bild ein
//
//
function openURLSelect(SiteRootPath, strTxtId, strTextBoxID, strPicID)
{
	var DestinationURL = '';

	// TextBox mit der URL
	var objTextBox = document.getElementById(strTextBoxID);
	
	if (objTextBox != null)
	{
		DestinationURL = browseInternalLinksWithoutHiddenBox(SiteRootPath, objTextBox.value);
	}
	
	//obMedia = window.showModalDialog(BaseGlobalPath + "Resources/ResourceBrowser.aspx","","status:false;dialogWidth:780px;dialogHeight:670px");
	// wenn Objekt nicht leer
	if(DestinationURL != null)
	{

		objTextBox.value = DestinationURL;
		updateHiddenField(strTxtId, strPicID,null,null,objTextBox.value);		
	}
}

function openResourceSelect(SiteRootPath, strTxtId, strTextBoxID, strPicID)
{
	var DestinationURL = '';

	// TextBox mit der URL
	var objTextBox = document.getElementById(strTextBoxID);
	
	if (objTextBox != null)
	{
		DestinationURL = browseResources(SiteRootPath, objTextBox.value);
	}
	
	//obMedia = window.showModalDialog(BaseGlobalPath + "Resources/ResourceBrowser.aspx","","status:false;dialogWidth:780px;dialogHeight:670px");
	// wenn Objekt nicht leer
	if(DestinationURL != null)
	{

		objTextBox.value = DestinationURL;
		updateHiddenField(strTxtId, strPicID,null,null,objTextBox.value);		
	}
}

//
// Löscht den Inhalt der URL Textbox
//
//
function deleteURL(strTxtId, strTextBoxID,strPicID )
{
	// textbox object
	var objTextbox = document.getElementById(strTextBoxID);
	// leere inhalt
	objTextbox.value = '';
	// update der daten
	updateHiddenField(strTxtId,strPicID,null,null,'');
}
//
// aktualisiert die Daten im hidden-field mit den geänderten 
// Destination Angaben
//
function updateURL(strTxtId,strPicID,strTextBoxID)
{
	// textbox object
	var objTextbox = document.getElementById(strTextBoxID);
	// aktualisiere daten
	updateHiddenField(strTxtId,strPicID,null,null,objTextbox.value)
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function browseInternalLinksWithoutHiddenBox(strSiteRootPath, strPresentItem)
{
	var result = window.showModalDialog(strSiteRootPath + "CMS/WebAuthor/Dialogs/InternalLinks/InternalLinks.aspx" + "?NRMODE=Unpublished&wbc_caller=IEModal", strPresentItem, IDS_IEWIN_INTLINKS_FEATURES);
	if (result != "Cancel") 	{
		
		return result;
	}
	else
	 return null;
}

function browseResources(strSiteRootPath, strPresentItem)
{
	// neues Media Objekt
	obMedia = new MediaObject('','','');
	// hole neues Media Objekt
	obMedia = window.showModalDialog(strSiteRootPath + "Base/Authoring/Resources/ResourceBrowser.aspx?onlyimages=false","","status:false;dialogWidth:780px;dialogHeight:670px");
	// verarbeite Rückgabewerte
	if(obMedia != null)
	{ 
		var sPicGUID = obMedia.PicGuid;
		var sPicUrl = obMedia.PicUrl;
		
		obMedia = null;
		return sPicUrl;
	}
	else
	{
		obMedia = null;
		return null;
	}
}



//
// I have to write soemthing because of Heiko
// The following function will do amazing things
// 
function browseInternalLinks(strSiteRootPath, strTextBoxId) {

	var txtUrl = document.getElementById(strTextBoxId);
	var linkUrlString = txtUrl.value;
	
	var result = window.showModalDialog(strSiteRootPath + "CMS/WebAuthor/Dialogs/InternalLinks/InternalLinks.aspx" + "?NRMODE=Unpublished&wbc_caller=IEModal", linkUrlString, IDS_IEWIN_INTLINKS_FEATURES);
	if (result != "Cancel") 	{
		
		txtUrl.value = result;
	}
}


/*
------------------------------------------------
Scripts für das PictureModule
------------------------------------------------
*/




//
// administrate the images for the picture module placeholder
//
//
function administrateImages(HiddenTextID, HiddenImageDataID, BaseGlobalPath)
{

	var _sResFolderGUIDAndPictureCount = "";
	var _sImageData = "";
	
	var objHidText = document.getElementById(HiddenTextID);
	var objHidImage = document.getElementById(HiddenImageDataID);
	
	
	if (objHidText != null && objHidImage != null)
	{
		_sResFolderGUIDAndPictureCount = objHidText.value;
		
		if (objHidImage.value != "")
			_sImageData = objHidImage.value;
		
		_sImageData = window.showModalDialog(BaseGlobalPath + "PictureModule/AdministratePictures.aspx?guid=" + _sResFolderGUIDAndPictureCount,_sImageData,"status:false;dialogWidth:820px;dialogHeight:650px");
		
		//objHidText.value = BaseGlobalPath + "PictureModule/AdministratePictures.aspx?guid=" + _sResFolderGUIDAndPictureCount,"","status:false;dialogWidth:820px;dialogHeight:650px";
		
		// schreibe image daten in hidden textbox
		if (_sImageData != "" && _sImageData != null)
			objHidImage.value = _sImageData;
			
		return true;
	}
	else
		return false;

}

//
// remove the resource folder and remove image date also...
//
//
function removeResourceFolder(TxtResNameID, TxtID)
{
	// schreibe resfolder name
	var objText = document.getElementById(TxtResNameID);
	objText.value = "";
		
	document.getElementById("trstep2_1").style.visibility = "hidden";
	document.getElementById("trstep2_2").style.visibility = "hidden";
		
	//clear image data
	document.getElementById("txtImageData").value = "";
	
	//clear resource folder data
	document.getElementById(TxtID).value = "";
	
}

//
// Choose resourcefolder for the PictureModule
//
//
function selectResourceFolderForPicModule(TxtResNameID, TxtID, BaseGlobalPath, ReplaceTag, ReplaceImage, ButtonID )
{ 
	// neues Media Objekt
	obMedia = new MediaObject('','','');
	// hole neues Media Objekt
	obMedia = window.showModalDialog(BaseGlobalPath + "Resources/ResourceBrowser.aspx?files=0","","status:false;dialogWidth:780px;dialogHeight:670px");
	// verarbeite Rückgabewerte
	if(obMedia != null)
	{ 
		// GUID
		var sPicGUID = obMedia.PicGuid;
		var sPicID = obMedia.PicID;
		var sImagesCount = obMedia.PicUrl;
		// schreibe in hidden field
		var objTextfield = document.getElementById(TxtID);
		objTextfield.value = sPicGUID+"$"+sImagesCount;
		// schreibe resfolder name
		var objText = document.getElementById(TxtResNameID);
		objText.value = sPicID;
		// change button image
		var objButton = document.getElementById(ButtonID);	
		objButton.src = ReplaceImage;
		objButton.alt = ReplaceTag;	
		
		var objImageButton = document.getElementById("btnadminitrateImages");
		
		//picture count
		if (sImagesCount > "0")
		{
			objImageButton.style.visibility = "visible";
			document.getElementById("txtResFolderImages").value = sImagesCount + " images";
		}
		else
		{
			objImageButton.style.visibility = "hidden";
			document.getElementById("txtResFolderImages").value = "no images";
		}
			
			
		document.getElementById("trstep2_1").style.visibility = "visible";
		document.getElementById("trstep2_2").style.visibility = "visible";
		
		//clear image data
		document.getElementById("txtImageData").value = "";
		
		
	}
	// destroy objekt
	obMedia = null;
}



//
// write the selected resource folder to the result textfield
//
//
function selectResFolder(ResFolderName, ResFolderGUID, ResFolderImagesCount )
{
	setMediaItemValue(ResFolderGUID, ResFolderImagesCount, ResFolderName, ResFolderGUID);
}


//
// read image GUID/descriptions/sort and write back 
//
//
function saveImages()
{

	var objTxt = document.getElementById("txtHidImageCount");
	var iPictureCount = objTxt.value;
	var sImageData = "";
	var sTemp = "";
	var objTblItems = document.getElementById("tblItems");
	
	if (objTblItems != null)
	{
		for (i=1;i<=iPictureCount;i++)
		{
	
		// hole image und die guid aus dem Attrib GUID
		var objImg = document.getElementById("img" +  + i);
		var _sGuid = objImg.guid;
		var _sText;
	
		// hole IFRAME
		var objIFrame = document.getElementById("mytext" + _sGuid);
		// Fülle Div-TAG mit dem gespeicherten Inhalt
		var objDiv = objIFrame.contentWindow.document.getElementById("divText");
			_sText = objDiv.innerHTML;
		// Sort ID
		var objSort = document.getElementById("hidSort" + _sGuid);
	
		sTemp = _sGuid + _sAttributDelimiter + _sText + _sAttributDelimiter + objSort.value + _sItemDelimiter;
		sImageData += sTemp;
		
		}
	}
	// return value and close window
	returnValue = sImageData;
	window.close();
}


//
// Moves the selected button's table row up or down.
//
//
function moveRow(bUpDown , objImg, sHidSortID) {

	// lese darüberliegende TR des Image
	var pTableRow = findNearestParentOfType(objImg, "TR");
	// Textbox mit der SortID
	var objHidSort = document.getElementById(sHidSortID);
	
	if (pTableRow != null) {
		
		// Hole komplette Tabelle
		var pTable = findNearestParentOfType(pTableRow, "TABLE");
		// Index der gewählten TR		
		var nRowIndex = pTableRow.rowIndex;
		// Anzahl aller TR in der Tabelle
		var nRowLength = pTable.rows.length;
		// wenn nicht erstes oder letztes Element
		if ((bUpDown && nRowIndex > 0) || (!bUpDown && nRowIndex < nRowLength-1)) {	
			if (pTable != null) {
				if (bUpDown) 
				{
					// decrease SortID
					objHidSort.value = nRowIndex;
					// vertausche Zeilen
					pTable.rows[nRowIndex].swapNode(pTable.rows[nRowIndex - 1]);
					// ändere SortID des getauschten Elements
					ChangePreviousSortIndex(pTable.rows[nRowIndex],nRowIndex+1);
					
				} else 
				{
					// increase SortID
					objHidSort.value = nRowIndex +2;
					// vertausche Zeilen
					pTable.rows[nRowIndex].swapNode(pTable.rows[nRowIndex + 1]);
					// ändere SortID des getauschten Elements
					ChangePreviousSortIndex(pTable.rows[nRowIndex],nRowIndex+1);
				}
			}
		}
	}	
}

//
// Setzte die SortID des ausgetauschten Item
//
//
function ChangePreviousSortIndex(PrevTR,SortID){
	var objInputs = PrevTR.all.tags("Input");
	if (objInputs!=null)
		objInputs[0].value = SortID;
}


//
// Suche übergeordnetes Element
//
//
function findNearestParentOfType(element, strType) {
	while ( (element != null) &&
			(element.tagName != strType) )
	{
		element = element.parentElement;
	}
	
	// if we found a table row, return it.
	if ( (element != null) && 
		(element.tagName == strType) )
	{
		return element;
	} else {
		return null;
	}
}



//
// lese vorhandene Daten und fülle Felder
//
//
function InitializePage()
{

	// lese Argumente welche dem ModalDialog 
	// übergeben wurden
	var objArgs = window.dialogArguments;
	var arrContainerItems;
	
	if (objArgs != null)
	{
		// hole item daten
		arrContainerItems = objArgs.split(_sItemDelimiter);
	
		var arrItem;
		var Count;
		
		// loop durch alle Items
		for (m=0;m<arrContainerItems.length-1;m++)
		{
			// picture attribute
			var _sDesc;
			var _sGuid;
			var _sSortID;
			
			// lese attribute aus
			arrItem = arrContainerItems[m].split(_sAttributDelimiter);
			
			// wenn eine Beschreibung vorhanden ist,
			// dann das zugehörige Textfeld füllen
			if (arrItem[1] != null && arrItem[1] != _sItemDelimiter)
			{
				// hole attribute
				_sDesc = arrItem[1];
				_sGuid = arrItem[0];
				_sSortID = arrItem[2];
					
				// setzte counter
				Count = m + 1;
				
				// hole IFRAME
				var objIFrame = document.getElementById("mytext" + _sGuid);
				// Fülle Div-TAG mit dem gespeicherten Inhalt
				var objDiv = objIFrame.contentWindow.document.getElementById("divText");
					objDiv.innerHTML = _sDesc;
				// schreibe sortID in hidden textfield
				var objHidSort = document.getElementById("hidSort" + _sGuid);
				objHidSort.value = _sSortID;	
			}
		}
		// item sorting
		FirstTimeSorting();
	}
}

//
// Sortiere die Items beim erstmaligen Aufruf
//
//
function FirstTimeSorting()
{
	sortTable("tblItems", 4, false);
}


  // global variables
  var col = 0;
  var parent = null;
  var items = new Array();

  function get(i)
  {
    var node = items[i].getElementsByTagName("TD")[col]; 
    var retval = node.childNodes[3].value; 
    if(parseInt(retval) == retval) return parseInt(retval);
    return retval;
  }

  function compare(val1, val2, desc)
  { 
    return (desc) ? val1 > val2 : val1 < val2;
  }

  function exchange(i, j)
  {
    parent.insertBefore(items[i], items[j]);
  }

  function sortTable(tableid, n, desc)
  {
    parent = document.getElementById(tableid);
    col = n;

    if(parent.nodeName != "TBODY")
      parent = parent.getElementsByTagName("TBODY")[0];
    if(parent.nodeName != "TBODY")
      return false;

    items = parent.getElementsByTagName("TR");
    var N = items.length;

    // insertion sort
    for(var j=1; j < N; j++) {
		if (items[j].spacer == "0")
			for(var i=j; i > 0 && compare(get(i), get(i-1), desc); i--) {
				exchange(i, i-1);
			}
    }
  }





//
// convert a string to base64 string
//
//

var base64s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";



function encode(decStr){
decStr=escape(decStr);		//line add for chinese char
  var bits, dual, i = 0, encOut = '';
  while(decStr.length >= i + 3){
    bits =
    (decStr.charCodeAt(i++) & 0xff) <<16 |
    (decStr.charCodeAt(i++) & 0xff) <<8  |
     decStr.charCodeAt(i++) & 0xff;
    encOut +=
     base64s.charAt((bits & 0x00fc0000) >>18) +
     base64s.charAt((bits & 0x0003f000) >>12) +
     base64s.charAt((bits & 0x00000fc0) >> 6) +
     base64s.charAt((bits & 0x0000003f));
    }
  if(decStr.length -i > 0 && decStr.length -i < 3){
    dual = Boolean(decStr.length -i -1);
    bits =
     ((decStr.charCodeAt(i++) & 0xff) <<16) |
     (dual ? (decStr.charCodeAt(i) & 0xff) <<8 : 0);
    encOut +=
      base64s.charAt((bits & 0x00fc0000) >>18) +
      base64s.charAt((bits & 0x0003f000) >>12) +
      (dual ? base64s.charAt((bits & 0x00000fc0) >>6) : '=') +
      '=';
    }
  return encOut
  }




function decode(encStr) {
  var bits, decOut = '', i = 0;
  for(; i<encStr.length; i += 4){
    bits =
     (base64s.indexOf(encStr.charAt(i))    & 0xff) <<18 |
     (base64s.indexOf(encStr.charAt(i +1)) & 0xff) <<12 | 
     (base64s.indexOf(encStr.charAt(i +2)) & 0xff) << 6 |
      base64s.indexOf(encStr.charAt(i +3)) & 0xff;
    decOut += String.fromCharCode(
     (bits & 0xff0000) >>16, (bits & 0xff00) >>8, bits & 0xff);
    }
  if(encStr.charCodeAt(i -2) == 61)
    undecOut=decOut.substring(0, decOut.length -2);
  else if(encStr.charCodeAt(i -1) == 61)
    undecOut=decOut.substring(0, decOut.length -1);
  else undecOut=decOut;
  
  return unescape(undecOut);		//line add for chinese 
char
  }


function setDisabledState(strControlIdArray, bDisabled)
{
	var arrControls = strControlIdArray.split("|");
	
	for(iCtl = 0; iCtl < arrControls.length; iCtl ++)
	{
		document.getElementById(arrControls[iCtl]).disabled = bDisabled;
	}
}

function setVisibility(strControlID)
{
	var ctlToSet = document.getElementById(strControlID); 
	
	var bShow = false;

	if(ctlToSet.style.display == "none") bShow = true;
	
	if(bShow)
	{
		ctlToSet.style.display = "block";
		ctlToSet.style.visibility = "visible";
	}
	else
	{
		ctlToSet.style.display = "none";
		ctlToSet.style.visibility = "hidden";
	}

}

/* Function for extended Attachment Placeholder (Flash) */
// WBC_launchAttachmentGallery(strPostingQueryString, strPhName, strPhType, bAllowUpload, bAttachIcon, bAllowVideo)
function selectSingleAttachment(strSiteRootPath, strAllowedExtensions, strPostingQueryString, strPhName, strPhType, bAllowUpload, bAttachIcon, bAllowVideo)
{
	var strDispText = "";
	// neues Media Objekt
	obMedia = new MediaObject('','','');
	// hole neues Media Objekt
	obMedia = window.showModalDialog(strSiteRootPath + "/Globals/Authoring/Resources/ResourceBrowser.aspx?onlyimages=false&extensions=" + strAllowedExtensions,"","status:false;dialogWidth:780px;dialogHeight:670px");
	// verarbeite Rückgabewerte
	if(obMedia != null)
	{ 
		var strURL = obMedia.PicUrl;
		
		WBC_setSingleAttachment(strPhName, strURL, strDispText);
	}
	
	// destroy objekt
	obMedia = null;
}

// ###########################################################################################
// Common function to select resources
// - strSiteRootPath : Path of the site root (e.g. "/degussa") (w/o slash at the end)
// - strAllowedExtensions: File extensions seperated by | (e.g. "doc|ppt|xls")
// - strTextBoxId: Client side ID of the input control to write the URL to (e.g. "txtImageUrl")
// ############################################################################################
function selectResourceUrl(strSiteRootPath, strAllowedExtensions, strTextBoxId)
{
	obMedia = new MediaObject('','','');
	obMedia = window.showModalDialog(strSiteRootPath + "/Globals/Authoring/Resources/ResourceBrowser.aspx?onlyimages=false&extensions=" + strAllowedExtensions,"","status:false;dialogWidth:780px;dialogHeight:670px");
	if(obMedia != null)
	{ 
		document.getElementById(strTextBoxId).value = obMedia.PicUrl;
	}
	obMedia = null;
}

// #######################################################################################################################
// Common function to select images
// - strSiteRootPath : Path of the site root (e.g. "/degussa") (w/o slash at the end)
// - strTextBoxId: Client side ID of the input control to write the URL to (e.g. "txtImageUrl")
// - strPreviewImageId: Client side ID of preview image (e.g. "imgPreview") > Empty string = Preview image will not be set
// #######################################################################################################################
function SelectResourceImageUrl(strSiteRootPath, strTextBoxId, strPreviewImageId)
{
	obMedia = new MediaObject('','','');
	obMedia = window.showModalDialog(strSiteRootPath + "/Globals/Authoring/Resources/ResourceBrowser.aspx?onlyimages=true","","status:false;dialogWidth:780px;dialogHeight:670px");
	if(obMedia != null)
	{ 
		document.getElementById(strTextBoxId).value = obMedia.PicUrl;
		
		if(strPreviewImageId.length > 0)
		{
			document.getElementById(strPreviewImageId).src = obMedia.PicUrl;
		}
	}
	obMedia = null;
}

// ###########################################################################################
// Common function to select internal link
// - strSiteRootPath : Path of the site root (e.g. "/degussa") (w/o slash at the end)
// - strTextBoxId: Client side ID of the input control to write the URL to (e.g. "txtImageUrl")
// ############################################################################################
function selectInternalLink(strSiteRootPath, strTextBoxId)
{
	var strInternalLink = "";

	// TextBox mit der URL
	var txtValue = document.getElementById(strTextBoxId);
	
	if (txtValue != null)
	{
		strInternalLink = browseInternalLinksWithoutHiddenBox(strSiteRootPath + "/", txtValue.value);
	}

	if(strInternalLink != null)
	{
		txtValue.value = strInternalLink;	
	}
}





