var lastSelected;
var cab_lastGlossaryGUID;

function cab_gloss_delete(thisGUID)
{
	if(thisGUID==undefined){thisGUID=cab_lastGlossaryGUID;}
	window.open('/app/glossary/delGlossary.asp?guid='+thisGUID,'delGlossary','width=450,height=150,resizable=no,scrollbars=no,status=no');
}

function cab_gloss_edit(thisGUID)
{
	if(thisGUID==undefined){thisGUID=cab_lastGlossaryGUID;}
	window.open('/app/glossary/addGlossary.asp?guid='+thisGUID,'addGlossary','width=500,height=600,resizable=no,scrollbars=no,status=no');
}

function cab_isValidEmail(thisMailAddress)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(thisMailAddress))
	{
	return true
	}
	else
	{
	return false
	}
}


function newGlossary()
{
	window.open('/app/glossary/addGlossary.asp?addText=','addGlossary','width=500,height=600,resizable=no,scrollbars=no,status=no');
}

function checkGlossary()
{
	try
	{
		if(document.selection.createRange().text.length > 0)
			{
			Cab_LeftCorner.setMenuItemState(114,'regular');
			lastSelected = document.selection.createRange().text;
			}
		else
			{
			Cab_LeftCorner.setMenuItemState(114,'disabled');
			lastSelected = '';
			}
	}
	catch(e){}
	//alert(document.selection.createRange().text.length)
}

function resetAdminRights()
{
	window.open('/admin/resetAdmin.asp','resetAdmin','width=450,height=180,resizable=no,scrollbars=no');
}

function openHelp(helpID)
{
	window.open('/admin/documentation/cabacos_de/default.htm?helpid='+helpID,'helpWindow','width=820,height=550,status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=no');
}

function openAbout()
{
	window.open('/admin/about.asp','aboutWindow','width=550,height=380,status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=no');
}

function checkWindow (Redakansicht)
{
var windowName = window.name;

if (Redakansicht == 'false' && windowName.indexOf('RedakWindow') != -1)
{
 //alert("wechseln")
 OpenUserMode(-1)
}
}

function OpenRedakMode(editor,newWindow)
{

if (newWindow == -1)
	{
		var windowName = window.name

		if (windowName.indexOf('RedakWindow') == -1)
		{
			win1 = window.open(global_SessionMe + '?redak=1&editor=' + editor ,'RedakWindow' + global_SessionID,'width='+ (screen.availWidth-200) +',height=' + (screen.availheight - 200) + ',status=yes,resizable=yes');
			win1.moveTo (0,0);
			win1.resizeTo ( screen.availWidth,screen.availheight);

			window.opener=null;
			window.close();
		}
		else
		{
		try{
		document.location.href = global_SessionMe + '?redak=1&editor=' + editor ;
		}catch(e){}
		}
	}
else
	{
		try{
		document.location.href = global_SessionMe + '?redak=1&editor=' + editor ;
		}catch(e){}
	}
}

function OpenUserMode(newWindow)
{
if (newWindow == -1)
	{
	
	win1 = window.open(global_SessionMe + '?redak=0','Userwindow' + global_SessionID,'');
	win1.moveTo (0,0);
	win1.resizeTo ( screen.availWidth,screen.availheight);

	window.opener=null;
	top.frames.close();
	}
else
	{
	
		try
		{
		document.location.href = global_SessionMe + '?redak=0';
		}
		catch(e){}
		
	}
}

function printMe(printType,link)
{
	if (printType == 'app')
	{
		if (link == 'pdf')
		{
		document.getElementById('out_Content_pdf').value = document.getElementById('appContent').innerHTML;
		document.getElementById('out_Title_pdf').value = document.title;

		try{document.getElementById('out_add_Content_pdf').value = document.getElementById('add_appContent').innerHTML;}
		catch(e){}

		try{document.getElementById('out_Site_Content_pdf').value = document.getElementById('add_SiteContent').innerHTML;}
		catch(e){}

		document.getElementById('pdf_submit').submit();
		}
		
		if (link == 'print')
		{
		window.open('','PrinterWindow','width=600,height=700,left=0,top=0,resizable=yes,scrollbars=yes');
		document.getElementById('out_Content_print').value = document.getElementById('appContent').innerHTML;
		document.getElementById('out_Title_print').value = document.title;

		try{document.getElementById('out_Site_Content_print').value = document.getElementById('add_SiteContent').innerHTML;}
		catch(e){}

		try{document.getElementById('out_add_Content_print').value = document.getElementById('add_appContent').innerHTML;}
		catch(e){}

		document.getElementById('print_submit').target = 'PrinterWindow';
		document.getElementById('print_submit').submit();
		}
	}
	else
	{
	window.open(link,'PrinterWindow','width=600,height=700,left=0,top=0,resizable=yes,scrollbars=yes');
	}
}
function findAndReplace(myText, find, replace) {
    var result = myText.split(find).join(replace);
    return result;
}

function setIFrameHeight(thisIFrame)
{ 
   thisIFrame.style.height = thisIFrame.document.body.scrollHeight;
}

function setIFrameWidth(thisIFrame)
{ 
   thisIFrame.style.width = thisIFrame.document.body.scrollWidth;
}

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = false;
// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optWindow='resizable=yes,scrollbars=no,width=700,height=700,left=100,top=100';
	function popImage(imageURL,imageTitle){
		imgWin=window.open('about:blank','popup',optWindow);
		
		with (imgWin.document){
			writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">')
			writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
			writeln('var isIE;');
			writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
			writeln('function reSizeToImage(){');
			
			writeln('width=(document.images[0].width );');
			writeln('height=(document.images[0].height);');
			
			writeln('if (isIE){');
			writeln('window.resizeTo(100,100)')
			writeln('window.resizeTo(width+ 10,height+100-document.documentElement.clientHeight);}');
			writeln('else{');       
			writeln('window.innerWidth=width;');
			writeln('window.innerHeight=height;}}');
			writeln('function doTitle(){document.title="'+imageTitle+'";}');
			writeln('</sc'+'ript>');
			if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
			else writeln('</head><body bgcolor=FFFFFF scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
			writeln('<div id="imgContainer" style="height:auto;"><img name="George" src='+imageURL+' style="display:block"></div></body></html>');
			close();		
		}
}



function encode(input) {
    hexOutput = "";
    for (i=0; i<input.length; i++) {
        hexOutput = hexOutput + Dec2Hex(input.charCodeAt(i));
    }
    return hexOutput;
}

function decode(input) {
    hexOutput = "";
    for (i=0; i<input.length; i=i+2) {
        hexOutput = hexOutput + String.fromCharCode(parseInt(input.slice(i,i+2),16));
    }
    return hexOutput;
}

function Dec2Hex(Decimal) {
    var hexChars = "0123456789ABCDEF";
    var a = Decimal % 16;
    var b = (Decimal - a)/16;
    hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
    return hex;
}


//Funktionen für die Cabacos-Selectboxen Kategorien und Rubriken
var CabSelect_disMe;
function CabSelect_selectCats(myDiv)
{
	if(document.getElementById(myDiv).style.visibility == 'visible')
		{
		CabSelect_hideMeReal(myDiv);
		}
	else
		{
		document.getElementById(myDiv).style.visibility = 'visible';
		document.getElementById(myDiv).style.width = document.getElementById(myDiv.slice(0,myDiv.length-4) + '_Text').offsetWidth + 'px';
		}
}

function CabSelect_hideMe(myDiv)
{
	CabSelect_disMe = window.setTimeout("CabSelect_hideMeReal('"+myDiv+"');",300);
	//document.getElementById('BannerLangsDiv').style.visibility = 'hidden';
}

function CabSelect_transferLangs(transferFrom){
	transferFrom = transferFrom.slice(0,transferFrom.length-4)

	var CabSelect_inputStringRubs = new String;
	var CabSelect_inputStringRubsLong = new String;
	
	if(document.getElementsByName(transferFrom)[0].type.toLowerCase()=="hidden"){
	    //wenn cab_selectbox_selectOnlyOne ausgewaehlt dann ist es ein hiddenfield und keine checkbox
	    CabSelect_inputStringRubs = ',' + document.getElementsByName(transferFrom)[0].value;
	    CabSelect_inputStringRubsLong = ', ' + document.getElementsByName(transferFrom)[0].title;
	}
	else{
	
	    for(var i=0;i<document.getElementsByName(transferFrom).length;i++){
		    if(document.getElementsByName(transferFrom)[i].checked == true){
			    CabSelect_inputStringRubs = CabSelect_inputStringRubs + ',' + document.getElementsByName(transferFrom)[i].value;
			    CabSelect_inputStringRubsLong = CabSelect_inputStringRubsLong + ', ' + document.getElementsByName(transferFrom)[i].title;
            }
        }
    }
            
	try{
		CabSelect_inputStringRubs = CabSelect_inputStringRubs.substring(1);
		CabSelect_inputStringRubsLong = CabSelect_inputStringRubsLong.substring(2);
	}catch(e){}
	document.getElementById(transferFrom + '_Text').value = CabSelect_inputStringRubsLong;
	document.getElementById(transferFrom + '_Value').value = CabSelect_inputStringRubs;
}

function CabSelect_hideMeReal(myDiv)
{
	CabSelect_transferLangs(myDiv);
	
	document.getElementById(myDiv).style.visibility = 'hidden';
}

function getWindowWidth () {
  if (window.innerWidth) {
    return window.innerWidth;
  } else if (document.body && document.body.offsetWidth) {
    return document.body.offsetWidth;
  } else {
    return 0;
  }
}

function getWindowHeight () {
  if (window.innerHeight) {
    return window.innerHeight;
  } else if (document.body && document.body.offsetHeight) {
    return document.body.offsetHeight;
  } else {
    return 0;
  }
}

function cab_selectUsers (initUsers,selectionType,targetField,sql)
{
	window.open("/app/incs/dialogs/userlist/userlist.asp?sql="+encode(sql)+"&ul="+encode(selectionType)+"&target="+encode(targetField)+"&init=" + encode(initUsers) ,"Cab_UserSelect","height=270,width=400,resizable=no,scrollbars=no,menubar=no,location=no,dependent=no");
}
function itd_getFrame(FrameName)
{
	function getSubFrames(Frame)
	{
		for (var i=0;Frame.frames.length;i++)
		{
			if (Frame.frames[i].name.toLowerCase() == FrameName.toLowerCase())
			{
				return Frame.frames[i];
			}
			else if (Frame.frames[i].frames.length > 0)
			{ 
				subFrame = getSubFrames(Frame.frames[i])
				if (subFrame){return subFrame;}
			}
		}
	}
	
	theFrame = getSubFrames(top)
	if (theFrame)
	{
		return theFrame;
		//wenn man Frames per Document.getElementById nen IFrame holt dann kann man bei FF mit 
		//document.getElementById(FrameName).contentDocument
	}
	else
	{
		return undefined;
	}
}

//left corner wieder verschwinden lassen... notwendig wenn custom menus da sind
var lcHide //Variable muss f. LeftCorner Definiert werden
function clearLcMenu()
{
	window.clearTimeout(lcHide)
}
function hideLcMenu()
{
	window.clearTimeout(lcHide)
	lcHide = window.setTimeout('doHideLcMenu()',500);
}
function doHideLcMenu()
{
	$('Cab_leftCornerDiv').style.visibility = "hidden";
	try{
	//wenn keine Submenus wirft es Fehler 
	Cab_LeftCorner.hideSubMenus() //die submenus
	}catch(e){}
	
}
function showLcMenu()
{
	$('Cab_leftCornerDiv').style.visibility = "visible"
}
