// JavaScript Document

// browsererkennung
 isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
 IE = ((document.all)&&(navigator.appVersion.indexOf("MSIE")!=-1)) ? true : false;
 IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
 IE7 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)) ? true : false;
 IEmac = ((document.all)&&(isMac)) ? true : false;
 NS4 = (document.layers) ? true : false;
 Opera = navigator.userAgent.indexOf("Opera") >= 0;
 
function reload_treemenu(titel)
{
	// alert("YO");
	if (titel==null || titel=="") titel="dokumente";
	titel_iframe = titel + "_iframe";
	frame_exists = check_frame_exists("ms_frame_left", titel_iframe);
	
	if(frame_exists) 
		eval("top.ms_frame_left."+titel_iframe+".location.reload();");
}

function reload_treemenu_timeout(reload_menu) {
	// alert(reload_menu);
	window.setTimeout('reload_treemenu("'+reload_menu+'")',400);
}

function open_treemenu(titel, link)
{
	// alert("XO");
	if (titel==null || titel=="") titel="dokumente";
	window.setTimeout("open_treemenu_left('"+titel+"')",1000);
	window.setTimeout("load_mainframe('"+link+"')",2000);
}

function open_treemenu_left(titel) {
	// alert("HO");
	titel_iframe = titel + "_iframe";
	frame_exists = check_frame_exists("ms_frame_left", titel_iframe);
	
	// alert(frame_exists);
	if(frame_exists) {
		eval("top.ms_frame_left.showSlide('"+titel+"');");
		eval("top.ms_frame_left.setContentHeight('"+titel_iframe+"');");
		reload_treemenu_timeout(titel);
	}
}

function check_frame_exists(outer_frame, inner_frame) {
	objekt = eval("top." + outer_frame + "." + inner_frame);
	// alert(objekt);
	if(typeof objekt == "undefined") 
		return false;
	else 	
		return true;
}

function load_mainframe(link) 
{
	parent.frames[2].location.href = link;
}

function Logout()
{
	remove_cookie('openTrees', '', '');
	top.location.href = "index.php?logout=1";
}

function ActionLink(linkname, txt, do_switch, reload_menu) 
{
	if(do_switch == "") do_switch = 0;
	// alert("ACTIONLINKED");
	if (do_switch) {
		yes = confirm(txt);
		if (yes) {
			showLoadingBar();
			//alert(linkname);
			if(reload_menu != "") {
				window.setTimeout('reload_treemenu("'+reload_menu+'")',200);
		    }
          this.location.href = linkname;   //alert(this.location.href); return;
			return true;
		} else {
	  		// return false;
		}
	} else {
		showLoadingBar();
		this.location.href = linkname;
		if(reload_menu != "") {
	    	window.setTimeout('reload_treemenu("'+reload_menu+'")',200);
	    }
		return true;
	}
}

function Delete(Id, Projektname) {
  yes = confirm('func_tr("Wollen Sie dieses Dokument wirklich loeschen?")');
  if (yes == true) {
    return true;
  } else {
    return false;
  }
}

function Delete_File(url, file, confirm_it, confirm_txt) {
	// alert("DELETEFILE");
	if(confirm_it == 1) {
		yes = confirm(confirm_txt);
		if(yes == true) {
			this.location.href = url + "&file_to_delete=" + file;	
			return true;
		} else {
			return false;
		}
	} else {
		this.location.href = url + "&file_to_delete=" + file;	
		return true;
	}
}

function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

var theWindow='';
function openWindow(myURL ,winTitel ,width , height, printoption) 
{  
		//alert(theWindow.closed + " und " + theWindow.location);
	if (!theWindow.closed && theWindow.location && theWindow.name == winTitel) {
		//alert('drinne');
		theWindow.location.href = myURL;
		//theWindow.innerWidth = width;
		//theWindow.innerHeight = height;
	}else{
		theWindow=window.open(myURL,winTitel,'width='+width+',height='+height+',toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes');
  	}
  	if (window.focus && theWindow) theWindow.focus();
}

var pr_dialog=false;
function printThis(myWindow) {
	if(!pr_dialog){	
		loc=myWindow.document.location;
		if(loc!="about:blank"){
			myWindow.print();
		//alert(loc);
		pr_dialog=true;
		}
	}
}

function openWindowScroll(myURL ,winTitel ,width , height) {
  myWindow=window.open(myURL,winTitel,'width='+width+',height='+height+',toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes');
  myWindow.focus();
}

function PicChange(form, link, prepath, imagepath, wpath_image, link_origin, tr_txt, tr_txt2) {
	
	var parts=link.split("/");
	parts[parts.length-1]="150x150_"+parts[parts.length-1].substr(0,parts[parts.length-1].length-3)+"jpg"
	
	var apx = link.substr(link.length-3, link.length);
	apx = apx.toLowerCase();
	if(apx.substr(apx.length-1, apx.length) == "0") {
		apx = "";
	}
	if(apx!="eps" && apx!="ndd" && apx!="")
		link="/"+parts[parts.length-1];
	//alert(link+prepath)
	switch(apx) {
  		case "eps":
  		form.pic.src = imagepath + "/defaults/eps.gif";
  		break;
	  	case "ndd":
  		form.pic.src = imagepath + "/defaults/indd.gif";
  		break;
	 /* 	case "tif":
  		form.pic.src = imagepath + "/defaults/tif.gif";
  		break;*/
	  	case "":
  		form.pic.src = imagepath + "/defaults/spacer.gif";
  		break;  		
  		default:
		form.pic.src = prepath+link; 
		break;
  	}

	// extra link fuer download
	var pic_dl_extra = wpath_image + link_origin;
	var div_element = document.getElementById('pic_download_extra');
	// alert(pic_dl_extra + '\n' + div_element);
	if(link_origin == "") {
		div_element.innerHTML = tr_txt2;
	} else {
		div_element.innerHTML = '<a href="' + pic_dl_extra + '">' + tr_txt + '</a>';  	
	}
	
	// extra link visibility
	if(link == "") {
		div_element.style.display = 'none';
	} else {
		div_element.style.display = '';
	}
}

function PicChangeShop(form, linkpath, link, imagepath, wpath_image, thumb_token, tr_txt, tr_txt2) 
{
	var apx = link.substr(link.length-3, link.length);
	apx = apx.toLowerCase();
	if(apx.substr(apx.length-1, apx.length) == "0") {
		apx = "";
	}
	
	/*
	alert(
		"linkpath: " + linkpath + "\n" + 
		"link: " + link + "\n" + 
		"imagepath: " + imagepath + "\n" + 
		"wpath_image: " + wpath_image + "\n" + 
		"thumb_token: " + thumb_token + "\n" + 
		"tr_txt: " + tr_txt + "\n" + 
		"tr_txt2: " + tr_txt2 + "\n" + 
		"apx: " + apx + "\n"
	);
	*/
	
	switch(apx) {
  		case "eps":
  		picture = imagepath + "/defaults/eps.gif";
  		break;
	  	case "ndd":
  		picture = imagepath + "/defaults/indd.gif";
  		break;
	  	case "":
  		picture = imagepath + "/defaults/spacer.gif";
  		break;  		
  		default:
		picture = imagepath+"/" + thumb_token + link;
		break;
  	}

	form.pic.src = picture;

	// extra link fuer download
	var pic_dl_extra = wpath_image + link;
	var div_element = document.getElementById('pic_download_extra');
	// alert(pic_dl_extra + '\n' + div_element);
	if(link == "") {
		div_element.innerHTML = tr_txt2;
	} else {
		div_element.innerHTML = '<a href="' + pic_dl_extra + '">' + tr_txt + '</a>';  	
	}
	
	// extra link visibility
	if(link == "") {
		div_element.style.display = 'none';
	} else {
		div_element.style.display = '';
	}
}

function showLayer(left,top,width,height) {
   if (IE) width=width+5;
   if (IE) height=height+5;
   
	wmtt = frames["preview_iframe"].document.getElementById("overDiv");
	if(!wmtt)
		return false;
   wmtt.style.left = left+"px";
   wmtt.style.top = top+"px";
   wmtt.style.width = width+"px";
   wmtt.style.height = height+"px";
   wmtt.style.display = "block"
   //alert(frames["preview_iframe"].scrollLeft)
   frames["preview_iframe"].scrollTo(left,top);
   return true;
} 

function showLayer_5(left,top,width,height) {
	
   if (!showLayer(left,top,width,height))
      window.setTimeout('showLayer('+left+','+top+','+width+','+height+');',2000);
   
} 

function hideLayer(){
	wmtt = frames["preview_iframe"].document.getElementById("overDiv");
	if(!wmtt)
		return;
	wmtt.style.display = "none"
}

function PreviewSwitch(url, url_pop, width, height, preview_state_txt) {
  if(document.p_p_sb.preview_popup.checked == true) {
//  	alert(url_pop);
	openWindow("about:blank", "preview_win", width, height);
	openWindow(url_pop, 'preview_win', width, height, "print");
	
  } else {
//  	alert(url);
    top.tiki.preview_iframe.location.href = url;
  }

  // preview_state aendern
  SetPreviewState("none");
}

function SetPreviewState(visible) { // Previewtext ein/ausblenden : visible => "" oder "none"
	if(eval(opener)) {
		opener.top.tiki.document.getElementById("preview_state_js").style.display = visible;
	} else {
		top.tiki.document.getElementById("preview_state_js").style.display = visible;	
	}
}

function PreviewPop(url, width, height) {
	openWindow("about:blank", "preview_win", width, height);
	openWindow(url, "preview_win", width, height);
}

function SetPreview() {
  for(i=0;i<document.forms.length;i++){
  	for(j=0;j<document.forms[i].elements.length;j++){
  	   if(document.forms[i].elements[j].name=="preview_check"){
  	     my_preview=document.forms[i].elements[j];
  	     break;
  	   }
  	}
  }
  if(document.p_p_sb.preview_popup.checked == true) {
	
	my_preview.value = 1;
  } else {
  	my_preview.value = 0;
  }
}


function changeLang(newLanguage)  {
   top.ms_header.location.href = top.ms_header.location.href+( (top.ms_header.location.href.indexOf("?")>-1)? "&" : "?" )+"langID="+newLanguage+"&langChanged=1";
	top.ms_frame_left.location.href = top.ms_frame_left.location.href+( (top.ms_frame_left.location.href.indexOf("?")>-1)? "&" : "?" )+"langID="+newLanguage+"&langChanged=1";
	top.tiki.location.href = top.tiki.location.href+( (top.tiki.location.href.indexOf("?")>-1)? "&" : "?" )+"langID="+newLanguage+"&langChanged=1";
}


function openInfos( element, pic, picpath, zusatz_label, zusatz_info, zusatz_info_wenig) {
	// alert(zusatz_info + "\n" + zusatz_info_wenig);
	if (picpath.substr(picpath.length-1,1)!="/") picpath+="/";
	if (element.style.display=='' || element.style.display=='block' || element.style.display=='inline' ) {
	      element.style.display='none';
	      // document.images[pic].src=picpath+'info_down.gif';
	      pic.src = picpath+'info_down.gif';
	      pic.alt = zusatz_info;
	      zusatz_label.innerHTML = zusatz_info;
	} else {
	      element.style.display='block';
	      // alert(pic);
	      // document.images[pic].src=picpath+'info_up.gif';
	      pic.src = picpath+'info_up.gif';
	      pic.alt = zusatz_info_wenig;
	      zusatz_label.innerHTML = zusatz_info_wenig;
	}
}

function change_img(img){
	//alert('huhu '+img.src)
   if(document.images[img].src.indexOf("info_down.gif")!=-1)
		document.images[img].src="http://192.168.1.14/rasper_work/info_up.gif";
   else
	   document.images[img].src="http://192.168.1.14/rasper_work/info_down.gif"
}

function change_vis(div_id){
	var change_div=document.getElementById(div_id);
	if(change_div.style.display=="none" || change_div.style.display==""){
		change_div.style.display="block";
	}else{
		change_div.style.display="none";
	}
   return change_div.style.display;
}

function openOldValInfos(div_id, element_id) {
	var change_div=document.getElementById(div_id);
	var element_div=document.getElementById(element_id);
	
   //alert(div_id);
   //alert(element_id);
   
   if(element_id!="") {
	   if (element_div.style.display=='' || element_div.style.display=='block') {
			element_div.style.display='none';
		} else {
			element_div.style.display='';
		}
   }
   
	if(change_div.style.display=="block" || change_div.style.display==""){
		change_div.style.display="none";
	} else {
		change_div.style.display="";
	}
   return change_div.style.display;
   return element_div.style.display;
}

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 surfto(form) {
          var myindex=form.select1.selectedIndex
          if (form.select1.options[myindex].value != "0") {
           location=form.select1.options[myindex].value;}
  }


BrowserDetect();
function BrowserDetect() {
	// Browsercheck 
	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	NS4 = (document.layers) ? true : false;
	IEmac = ((document.all)&&(isMac)) ? true : false;
	IE4plus = (document.all) ? true : false;
	IE = ((document.all)&&(navigator.appVersion.indexOf("MSIE")!=-1)) ? true : false;
	IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
	IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
	ver4 = (NS4 || IE4plus) ? true : false;
	NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
	IE5plus = IE5 || IE6;
	IEMajor = 0;
	if (IE4plus) {
		var start = navigator.appVersion.indexOf("MSIE");
		var end = navigator.appVersion.indexOf(".",start);
		IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
		IE5plus = (IEMajor>=5) ? true : false;
	}
}

var tmpTextEl="";
var tmpImgId="";
var tmpImgSrc="";

function markTreeNode(textEl,imgId,imgPath,img){
//	alert(imgId)
	if(tmpImgId!="" && tmpImgSrc!="")
		document.getElementById(tmpImgId).src=tmpImgSrc;
	if(typeof(tmpTextEl)=="object")
		tmpTextEl.className='treeMenuText';
	tmpImgId=imgId;
	tmpImgSrc=document.getElementById(imgId).src;
	
	textEl.className='treeMenuSelected';
	document.getElementById(imgId).src=imgPath+"/"+img;
	tmpTextEl=textEl;
}

function SetChanged(form, wert) {
	// alert(wert + " = 1");
	form.changed.value = 1;
	wert.value = 1;
}

function SortItList(link, sort) {
   sort_txt = sort.options[sort.options.selectedIndex].value;
   // alert("Link: " + link + "\nSort: " + sort_txt);
   window.location.href = link + "&sort=" + sort_txt;
}

function showLoadingBar() {
	if(top.tiki == undefined) {
		return true;
	}
	var rightframe = top.tiki;
	var body = rightframe.document.getElementsByTagName("body")[0];
	if(rightframe.document.getElementById("overlay") == undefined && body != undefined){
		var overdiv = rightframe.document.createElement("div");
		overdiv.setAttribute('id','overlay');
		/* Nach zwei verschiedenen Methoden, versuchen die Hoehe zu bestimmen */
		var hg_v1 = document.documentElement.clientHeight;
		if (document.body.clientHeight>hg_v1) hg_v1=document.body.clientHeight;
		var hg_v2=screen.availHeight-100;
		/* Dann das vermeintlich bessere Ergebnis waehlen */
		var hg=(hg_v1>hg_v2)? hg_v1 : hg_v2;
		var hg2 = Math.round(hg/2)-80;
		var imgHtml = '<div id="overlayBG" style="height:'+hg+'px;"></div><div id="overlay_inner" style="padding-top:'+hg2+'px;"><img src="skins/default/images/document/loading.gif"></div>';
		body.appendChild(overdiv);
		rightframe.document.getElementById('overlay').innerHTML = imgHtml;		
	}
	hideSelectBoxes();
}

function remove_cookie(name, path, domain) { 
	var cookie; 
   cookie = name + '='; 
   if (typeof path != "undefined") cookie += '; path=' + path; 
   if (typeof domain != "undefined") cookie += '; domain=' + domain; 
   cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT'; 
   document.cookie = cookie; 
}

function showSelectBoxes(){
	if(top.tiki == undefined) {
		return true;
	}
	var selects = top.tiki.document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	if(top.tiki == undefined) {
		return true;
	}
	var selects = top.tiki.document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

function checkAll(form, type, is_checked) {
   var o = form.elements;//getElementsByTagName('checkbox');
   if (o){
      for (i=0; i<o.length; i++){
         if (o[i].type == 'checkbox' && o[i].name.indexOf(type) != -1)
         {
            o[i].checked = is_checked;
         }
      }
   }
}

function checkAllUsergroups(form, is_checked) {
   filter = form.rfilter.options[form.rfilter.options.selectedIndex].value;
   filter_name = 'checkbox_' + filter;
   // alert(filter+"\n"+filter_name);

   var o = form.elements;//getElementsByTagName('checkbox');
   if (o){
      for (i=0; i<o.length; i++) {
         if (o[i].type == 'checkbox')
         {
         	if(filter != 0) {
         		
         		cb_id = o[i].id;
					if(cb_id.indexOf(filter_name)>-1) {
						// alert("dabei: " + cb_id);
						o[i].checked = is_checked;
					} else {		
						// nichts 
					}
         	} else {
	            o[i].checked = is_checked;
         	}					
         }
      }
   }
}

function switchTrUsergroups(rfilter) {
   trs=document.getElementsByTagName('tr');
   for(i=0;i<trs.length;i++) {
      //alert(trs[i].id);
      if(trs[i].id.indexOf('rfilter_')>-1)
         trs[i].style.display=(trs[i].id.indexOf('rfilter_'+rfilter)!=-1 || rfilter==0) ? '' : 'none'
   }
}

