<!--
// +-------------------------------------------------------+
// | b1gMail 6                                             |
// +-------------------------------------------------------+
// | Copyright (c) 2002-2004 by B1G PHP Scripts            |
// +-------------------------------------------------------+
// | $Author: patrick $
// | $Date: 2006/03/13 18:08:31 $
// | $Revision: 1.16 $
// | $Source: /cvs/b1gmail6/script/lib/common.js,v $
// +-------------------------------------------------------+

//----------------------------------------------------------------------------------
xMousePos = 0; 
yMousePos = 0; 
xMousePosMax = 0; 
yMousePosMax = 0; 
infoElement= null; 
xFromMouse=0;
yFromMouse=0;
yUpFromMouse=37;
standardStyle='position:absolute;left:0px;top:0px;visibility:hidden;text-align:left;z-index:999;filter: shadow(direction=135,color=#FF9900,strength=3);';
vars=new Object();
vars.tags=[ 'a' ]; 
vars.infoAttributeName= 'info'; 
vars.infoElementCentered= true; 
vars.infoElementId=null; 
vars.infoElementStyleClass=null; 
vars.infoElementFontSize= '11px'; 
vars.infoElementTextColor='#000000';
vars.infoElementBGColor= '#FFFFFF';
function setVariables(){
	var settings= window.infoSettings;
	if( settings==null ){
	} else {
	    for( var varName in settings ){
	    	if( settings[varName]!=null )
	    		vars[varName]= settings[varName];	
	    }
	}	
};
setVariables();	
begin();
function begin(){	
	attachInfoElement();
	installTagListeners();
	oldOnmousemove= document.onmousemove;
	if (document.all) {
	    yFromMouse=17;
	    xFromMouse=2;
	    document.onmousemove = captureMousePosition;	
	} else if (document.getElementById) {
	    yFromMouse=21;
	    xFromMouse=2;
	    document.onmousemove = captureMousePosition;		
	}
}
function captureMousePosition(e) {
    if ( document.documentElement&& window.event&& document.documentElement.clientWidth>0 ){
	xMousePos = window.event.x+ document.documentElement.scrollLeft; 
        yMousePos = window.event.y+document.documentElement.scrollTop;
        xMousePosMax = document.documentElement.clientWidth+document.documentElement.scrollLeft;
        yMousePosMax = document.documentElement.clientHeight+document.documentElement.scrollTop-12;        	
   } else if (document.all) {
	xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
	moveElements();	
	if( oldOnmousemove!=null ){		
		oldOnmousemove(e);
	}
}
function out( string ){
	var outDiv=document.getElementById('out')
	if(outDiv!=null) outDiv.firstChild.nodeValue+=string+" ";
}
function moveElements(){
	moveInfoElement();
}
function attachInfoElement( ){
	var str='<div style="'+standardStyle+'" id="';
	if(vars.infoElementId!=null &&vars.infoElementId.length>0){
		str+= vars.infoElementId+'" ';		
	} else {
		vars.infoElementId='infoElement';
		str+= vars.infoElementId+'"';	
		if(vars.infoElementStyleClass!=null && vars.infoElementStyleClass.length>0){
			str+= ' class="'+vars.infoElementStyleClass+'" ';			
		} else {
			str+=' class="'+vars.infoElementId+'" ';
			var sty='<style type="text/css"><!--';
			sty+=('#'+vars.infoElementId+' {');
			sty+=('background-color: '+vars.infoElementBGColor+';');	
			sty+='color:'+vars.infoElementTextColor+';';
			sty+=('border: 1px solid  #666666;filter: shadow(direction=135,color=#666666,strength=3);');
			sty+=('filter: shadow(direction=135,color=#8E8E8E,strength=3);');
			sty+=('font-size: '+vars.infoElementFontSize+';');
			sty+=('font-family: Verdana,Arial, Helvetica, sans-serif;');
			sty+=('margin:4px;');
			sty+='padding:4px;';
			sty+=('}	--></style>');			
			document.writeln( sty );
		}
	}	
	str+=' > </div>'	
	out(str);
	document.writeln( str );	
}
function installTagListeners( delayTime ){
	infoElement=document.getElementById( vars.infoElementId );
	if( infoElement==null ){} else {		
		for( var k=0; k<vars.tags.length; k++){		
			var links=document.getElementsByTagName(  vars.tags[k].toUpperCase() );
			for(var i=0;links!=null&&i<links.length;i++){				
				var node= links[i];
				var infoText=node.getAttribute( vars.infoAttributeName ); 
				if( infoText!=null && infoText.length > 0&& node.infoText_==null ){
						node.infoText_= infoText;
						node.style.cursor='pointer';
						if( node.onmouseover==null ){
							node.onmouseover= showInfo;					
						} else {
							node.oldOnmouseover= node.onmouseover;
							node.newOnmouseover= showInfo;
							node.onmouseover= function(){
								this.newOnmouseover();
								this.oldOnmouseover();
							}
						}
						if( node.onmouseout==null ){
							node.onmouseout= hideInfo;					
						} else {
							node.oldOnmouseout= node.onmouseout;
							node.newOnmouseout= hideInfo;
							node.onmouseout= function(){
								this.newOnmouseout();
								this.oldOnmouseout();
							}
					   }
				}
			}
		}
	}	
	if( delayTime==null)
		delayTime=0;
	if( delayTime < 2 ){
		delayTime+=0.2;
	}	
	setTimeout('installTagListeners('+delayTime+')',delayTime*1000); 
}
function moveInfoElement(){	
	if( infoElement ==null ){
	} else if( infoElement.style.visibility != 'hidden'){		
		var x=xFromMouse+xMousePos;
		if(vars.infoElementCentered==true){
			x-=0.5*infoElement.offsetWidth;			
		}
		if( xMousePosMax>0 && x+ infoElement.offsetWidth> xMousePosMax-20 ){
			x= xMousePosMax-20- infoElement.offsetWidth;			
		}
		if( x<5 ){
			x=5;
		}		
		var y=yFromMouse+yMousePos;
		if( yMousePosMax>0 && y+ infoElement.offsetHeight> yMousePosMax ){
			y-= yFromMouse+yUpFromMouse;
		}		
		infoElement.style.left=x+'px'; 
		infoElement.style.top=y+'px';		
	} 
}
function setInfoText( text ){			
	var subtext='';
	for(var i=0;i<text.length;++i){		
		if(text.substr(i,4)=='<br>' || text.substr(i,6)=='<br />'){			
			infoElement.appendChild(document.createTextNode(subtext));
			infoElement.appendChild(document.createElement('br'));
			subtext='';
			if(text.substr(i,6)=='<br />') {
				i+=5;
			} else {
				i+=3;
			}
		} else {
			subtext=subtext+text.charAt(i)
		}
	}	
	infoElement.appendChild( document.createTextNode(subtext));		
}
function unsetInfoText(){
	while(infoElement.hasChildNodes()){
		infoElement.removeChild(infoElement.lastChild);
	}	
}
function showInfo(){		
	unsetInfoText();
	infoElement.left='0px';
	infoElement.top='0px';
	setInfoText( this.infoText_ );		
	infoElement.style.visibility='visible';
	moveInfoElement();			
}
function hideInfo(){		
	infoElement.style.visibility='hidden';
	unsetInfoText();	
}
//----------------------------------------------------------------------------------


function setdate(form, prefix, d, m, y, h, i, s) {
	var f = document.forms[form].elements;
	
	f[prefix + '_day'].value = d;
	f[prefix + '_month'].value = m;
	f[prefix + '_year'].value = y;
	f[prefix + '_hour'].value = h;
	f[prefix + '_minute'].value = i;
	
	return true;
}

function submdf() {
	document.getElementById('apply').value = '...';
	document.getElementById('ok').value = '...';
	document.getElementById('apply').disabled = true;
	document.getElementById('ok').disabled = true;
	return true;
}

function hoverRow(id) {
	document.getElementById(id + '_1').style.borderLeft = '1px solid #0A246A';
	document.getElementById(id + '_1').style.borderTop = '1px solid #0A246A';
	document.getElementById(id + '_1').style.borderBottom = '1px solid #0A246A';
	document.getElementById(id + '_1').style.background = '#B6BDD2';

	document.getElementById(id + '_2').style.borderRight = '1px solid #0A246A';
	document.getElementById(id + '_2').style.borderTop = '1px solid #0A246A';
	document.getElementById(id + '_2').style.borderBottom = '1px solid #0A246A';
	document.getElementById(id + '_2').style.background = '#B6BDD2';
}

function unhoverRow(id) {
	document.getElementById(id + '_1').style.borderLeft = '1px solid #DBD8D1';
	document.getElementById(id + '_1').style.borderTop = '1px solid #DBD8D1';
	document.getElementById(id + '_1').style.borderBottom = '1px solid #DBD8D1';
	document.getElementById(id + '_1').style.background = '#DBD8D1';

	document.getElementById(id + '_2').style.borderRight = '1px solid #FFFFFF';
	document.getElementById(id + '_2').style.borderTop = '1px solid #FFFFFF';
	document.getElementById(id + '_2').style.borderBottom = '1px solid #FFFFFF';
	document.getElementById(id + '_2').style.background = '#FFFFFF';
}

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_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_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 negateChoice(id) {
	var k=0;
	while(id.elements[k]) {
		if(id.elements[k].name != 'checker') {
			if(id.elements[k].checked == 1) {
				id.elements[k].checked=0;
			} else {
				id.elements[k].checked=1;
			}
		}
		k++;
	}
}

function putsig(text,html,form,field) {
	if (html==1) {
		var oEditor = FCKeditorAPI.GetInstance('text');
		oEditor.InsertHtml(document.forms['cform'].elements[text + 'h'].value);
	} else {
		var erst;
		var nun;
		erst = document.forms['cform'].elements[text + 't'].value;
		nun = erst.replace(new RegExp('<_R_>','g'), '\r');
		nun = nun.replace(new RegExp('<_N_>','g'), '\n');
		  if (document.forms['cform'].elements['text'].createTextRange)
           {
            document.forms['cform'].elements['text'].focus();
            document.selection.createRange().duplicate().text = nun;
           }
          else if ((typeof document.forms['cform'].elements['text'].selectionStart) != 'undefined') // für Mozilla
           {
            var tarea = document.forms['cform'].elements['text'];
            var selEnd = tarea.selectionEnd;
            var txtLen = tarea.value.length;
            var txtbefore = tarea.value.substring(0,selEnd);
            var txtafter =  tarea.value.substring(selEnd, txtLen);
            var oldScrollTop = tarea.scrollTop;
            tarea.value = txtbefore + nun + txtafter;
            tarea.selectionStart = txtbefore.length + nun.length;
            tarea.selectionEnd = txtbefore.length + nun.length;
            tarea.scrollTop = oldScrollTop;
            tarea.focus();
           }
          else
           {
            document.forms['cform'].elements['text'].value += nun;
            document.forms['cform'].elements['text'].focus();
           }
	}
}


function openwindow(url, w, h) {
	var wa = (screen.width-w)/2;
	var l = 0;
	var ha = (screen.height-h)/2 - 60;
	var name = 'popup'+w+h;
	var features = 'scrollbars=yes,toolbar=no,statusbar=no,menubar=yes,resizable=yes,width='+w+',height='+h+',top=' + ha + ',left=' + wa;
	var hwnd = window.open(url,name,features);
}

function attachments(entwurf, sessid) {
	var w = 450;
	var h = 350;
	var url = 'compose.php?bmsession=' + sessid + '&action=attachments&draft=' + entwurf;
	var wa = (screen.width-w)/2;
	var l = 0;
	var ha = (screen.height-h)/2 - 60;
	var name = 'attach' + entwurf;
	var features = 'scrollbars=yes,toolbar=no,statusbar=no,menubar=no,resizable=yes,width='+w+',height='+h+',top=' + ha + ',left=' + wa;
	var hwnd = window.open(url,name,features);
}

function seladdr(sessid) {
	var w = 450;
	var h = 350;
	var url = 'adressen.php?action=box&bmsession=' + sessid;
	var wa = (screen.width-w)/2;
	var l = 0;
	var ha = (screen.height-h)/2 - 60;
	var name = 'seladdr' + sessid;
	var features = 'scrollbars=no,toolbar=no,statusbar=no,menubar=no,resizable=no,width='+w+',height='+h+',top=' + ha + ',left=' + wa;
	var hwnd = window.open(url,name,features);
}

function selsmsaddr(sessid) {
	var w = 450;
	var h = 350;
	var url = 'sms.php?action=addr&bmsession=' + sessid;
	var wa = (screen.width-w)/2;
	var l = 0;
	var ha = (screen.height-h)/2 - 60;
	var name = 'seladdr' + sessid;
	var features = 'scrollbars=yes,toolbar=no,statusbar=no,menubar=no,resizable=no,width='+w+',height='+h+',top=' + ha + ',left=' + wa;
	var hwnd = window.open(url,name,features);
}

function sel_sms_addr(sessid) {
	var w = 450;
	var h = 350;
	var url = 'adressen.php?action=smsbox&bmsession=' + sessid;
	var wa = (screen.width-w)/2;
	var l = 0;
	var ha = (screen.height-h)/2 - 60;
	var name = 'seladdr' + sessid;
	var features = 'scrollbars=no,toolbar=no,statusbar=no,menubar=no,resizable=no,width='+w+',height='+h+',top=' + ha + ',left=' + wa;
	var hwnd = window.open(url,name,features);
}

function clattach() {
	window.opener.document.forms['cform'].elements['action'].value = 'reload';
	window.opener.document.forms['cform'].submit();
	window.close();
}

function switchtext() {
	document.getElementById('action').value = 'reload';
	document.getElementById('modus').value = 'text';
	document.getElementById('reformat').value = 'tohtml';
	document.getElementById('cform').submit();
}

function switchhtml() {
	document.getElementById('action').value = 'reload';
	document.getElementById('modus').value = 'html';
	document.getElementById('reformat').value = 'totext';
	document.getElementById('cform').submit();
}

function spellcheck(sessid) {
	var w = 640;
	var h = 480;
	var url = 'spell.php?bmsession=' + sessid;
	var wa = (screen.width-w)/2;
	var l = 0;
	var ha = (screen.height-h)/2 - 60;
	var name = 'checkspell' + sessid;
	var features = 'scrollbars=no,toolbar=no,statusbar=no,menubar=no,resizable=no,width='+w+',height='+h+',top=' + ha + ',left=' + wa;
	var hwnd = window.open(url,name,features);
}

function toggle(id, tmpl_self) {
	if(document.getElementById(id).style.display=="none") {
		document.getElementById(id).style.display="";
		MM_swapImage('t_' + id,'', tmpl_self+'toggle_minus.gif',1);
	} else {
		document.getElementById(id).style.display="none";
		MM_swapImage('t_' + id,'',tmpl_self+'toggle_plus.gif',1);
	}
}

function switchtype(a, b) {
	if(document.getElementById) {
		document.getElementById(a).style.display = "block";
		document.getElementById(b).style.display = "none";
	}
}

function changecell(a) {
	if(document.getElementById) {
		if(document.getElementById(a).style.display == "none") {
			document.getElementById(a).style.display = "";
		} else {
			document.getElementById(a).style.display = "none";
		}
	}
}

function tab(from,to) {
	if (from.getAttribute && from.value.length == from.getAttribute("maxlength")) {
		to.focus()
	}
}

function exchange(self,opposit) {
	opposit.value = self.value;
}

function start() {
	// nur auf der "neuer Termin"-Seite des Kalenders
	if(document.forms['newDateForm']) {
		if(document.forms['newDateForm'].elements['sms'].checked) {
			changecell('smscell');
		}
		if(document.forms['newDateForm'].elements['type'][1].checked) {
			switchtype('recurring', 'exact');
		} else {
			switchtype('exact', 'recurring');
		}
	}
}

function hilfe(chapter,sid) {
	var offset=245;
	var pane=window.open('hilfe.php?chapter='+chapter+'&bmsession='+sid,'b1gmailhilfe','toolbar=0,status=0,menubar=0,width=1,height=1,left=1,top=3000,resizable=0');

	window.moveTo(0,0);
	window.resizeTo(screen.availWidth-offset,screen.availHeight);

	pane.moveTo(screen.availWidth-offset,0);
	pane.resizeTo(offset,screen.availHeight);
}

function showMailSource(message,sid) {
	openwindow('main.php?action=showsource&id=' + message + '&bmsession=' + sid, 800, 600);
}

function moveMail(message,sid) {
	openwindow('main.php?action=movewindow&id=' + message + '&bmsession=' + sid, 320, 150);
}

function sel_disk_file(id,titel) {
	document.getElementById('id').value = id;
	document.getElementById('dn').value = titel;
}

function save_disk_field() {
	if(document.getElementById('id').value == '0') {
		window.close();
	} else {
		window.opener.document.getElementById('ffield').value = document.getElementById('id').value;
		window.opener.document.getElementById('diskfile').innerHTML = document.getElementById('dn').value;
		window.close();
	}
}

function attachment_to_webdisk(mid,sid) {
	openwindow('webdisk.php?action=attachment_to_webdisk' + mid + '&bmsession=' + sid, 640, 480);
}


function browse_disk(ifeld,tfeld,sid) {
	openwindow('webdisk.php?action=browse_disk&ifeld=' + ifeld + '&tfeld=' + tfeld + '&bmsession=' + sid, 640, 480);
}

function selfile(id,title) {
	document.getElementById('zielort').value = title;
	document.getElementById('dest').value = id;
}

function chkagb(txt) {
	if(document.getElementById('y').checked)
	{
		return true;
	}
	else
	{
		alert(txt);
		return false;
	}
}

function PasswortVergleich(msg1, msg2) {
	if(document.forms["signupform"].elements["reg_pass"].value == "") {
		alert(msg1);
		document.forms["signupform"].elements["reg_pass"].focus();
		return false;
	}
	if(document.forms["signupform"].elements["reg_retype"].value != document.forms["signupform"].elements["reg_pass"].value) {
		alert(msg2);
		document.forms["signupform"].elements["reg_pass"].focus();
		return false;
	}
}

function sendReceipt(id, sid, to) {
	openwindow('main.php?action=receipt&bmsession=' + sid + '&id=' + id + '&to=' + to, 15, 15);
}

function wdRename(aid, mid, sid) {
	openwindow('webdisk.php?action=rename&bmsession=' + sid + '&mid=' + mid + '&aid=' + aid, 320, 150);
}

function wdMove(aid, mid, sid) {
	openwindow('webdisk.php?action=move&bmsession=' + sid + '&mid=' + mid + '&aid=' + aid, 580, 340);
}

function wdShare(aid, mid, sid) {
	openwindow('webdisk.php?action=share&bmsession=' + sid + '&mid=' + mid + '&aid=' + aid, 320, 200);
}

function oStruct(e) {
	var os=document.getElementById("ostruct");

	os.style.visibility="visible";
	os.style.display="";
}

function unoStruct() {
	document.getElementById('ostruct').style.display='none';
	document.getElementById('ostruct').style.visibility='hidden';
}

function smsadd_nopre(nr) {
	window.opener.document.getElementById('an').value = nr;
	window.close();
}

function smsadd_pre(vor, nr) {
	window.opener.document.getElementById('pre').value = vor;
	window.opener.document.getElementById('an').value = nr;
	window.close();
}

var regExp = /<\/?[^>]+>/gi;
function ReplaceTags(xStr) {
	xStr = xStr.replace(regExp,"");
	xStr = xStr.replace("&gt;", ">");
	xStr = xStr.replace("&lt;", "<");
	xStr = xStr.replace("&quot;", "\"");
	xStr = xStr.replace("&amp;", "&");
	return xStr;
}

function trim(str) {
   return str.replace(/^\s*|\s*$/g,"");
}
//-->