// Escaping js problems, activate only after launch
//function oe() {return true;}
//window.onerror = oe;


// flash-include-workaround ie7 active-x-sperre
function flashInclude( swf, height, width ) {
// JS-Initialising and Activating
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'" id="tvl" align="middle"><param name="allowScriptAccess" value="sameDomain"><param name="movie" value="movies/'+swf+'"><param name="quality" value="high"><param name="bgcolor" value="#ffffff"><embed src="movies/'+swf+'" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="tvl" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></object>');
}

function flashIncludeOpaque( swf, height, width ) {
// JS-Initialising and Activating
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="movies/'+swf+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><embed src="movies/'+swf+'" quality="high" wmode="transparent" bgcolor="#ffffff" width="'+width+'" height="'+height+'" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
}

function trailer( flv, height, width ) {
	var y =   ( Math.round ( (screen.availHeight-height)/2  ) )
	var x =   ( Math.round ( (screen.availWidth-width)/2 ) )
	win   =   window.open  ('trailer.php4?flv='+flv+'&height='+height+'&width='+width,'Trailer','toolbar=0,status=0,scrollbars=0,width='+width+',height='+height+',resizable=0,top='+y+',left='+x);
	win.focus ();
}

// print it
function printContent() {
 window.print();
}

// window opener
function winOpen(site,width,height,resz,scrlb) {
	var y = (Math.round((screen.availHeight-height)/2))
	var x = (Math.round((screen.availWidth-width)/2))
	showWin = open(site,"x","width="+width+",height="+height+",top="+y+",left="+x+",scrollbars="+scrlb+",status=0,resizable="+resz+",location=0,menubar=0,toolbar=0,fullscreen=0");
  showWin.focus();
}


function editor_display () {
  if (document.getSelection)
  {
   var str = document.getSelection();
  }
  else if (document.selection && document.selection.createRange)
  {
   var range = document.selection.createRange();
   var str = range.text;
  }
}

function editor_findSelection (w) {
	var pattern;
	var TextRange;

	pattern = escape(w.document.selection.createRange().text);
  if (pattern) return (pattern);
  return("");
}

function showHidePreDiv (num,what) {
  eval('document.all.'+num+'.style.visibility = what');
}

function explodeArray(item,delimiter) {
  tempArray=new Array(1);

  var Count=0;
  var tempString=new String(item);

  while (tempString.indexOf(delimiter)>0) {
    tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
    tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1); 
    Count=Count+1
  }

  tempArray[Count]=tempString;

  return tempArray;
}


function checkReqFields( fields ) {
 fields = explodeArray(fields,",");

 var m,ok,obj,mfocus,frm;
 ok=true;

 frm=document.forms[0];

  with (frm) {
		for ( i=0;i<fields.length;i++ )
    {
			field = fields[i];

			obj = elements[''+field+''];

      //wenn radio box dann dyn. durchklappern
      if ( obj.type != "text"  && obj.type != "password" && obj.type != "file" && obj.type != "textarea" && obj.type != "select-one" && obj.type != "checkbox" )

      {
        if ( obj[0].type == "radio" )
        {
          var check = 0;

          for (k=0;k<obj.length;k++)
          {
            if ( obj[k].checked == true ) { check++; }
          }

          if ( check == 0 )
          {
            ok=false;

            for (k=0;k<obj.length;k++)
            {
              obj[k].style.backgroundColor='#73AA1B';
            }
          } else {
            for (k=0;k<obj.length;k++) {
              obj[k].style.backgroundColor='#0866b0';
            }
          }
        }
      }
      else if ( obj.type == "select-one" )
      {
        //alert(obj.value);
        if ( obj.value == "" ) {ok=false; obj.style.backgroundColor='#73AA1B';} else  { obj.style.backgroundColor='#0866b0'; }
		    }  

      else if ( obj.type == "checkbox" )
      {
        if ( obj.checked == false ) {ok=false; obj.style.backgroundColor='#73AA1B'; } else  { obj.style.backgroundColor='#0866b0'; }
		    }     
      else
      {
        if (!obj.value) {ok=false; obj.style.backgroundColor='#73AA1B';} else  { obj.style.backgroundColor='#0866b0'; }
		  }	
    }		

		if ( !ok )
    {
			document.all.heidi.src = '../pix/heidi_alert.gif';

			return false;
		}
    else return true;
	}
} //end of function checkReqFields()


function checkReqFields2( fields )
{
 fields = explodeArray(fields,",");

 var m,ok,obj,mfocus,frm; ok=true;

 frm=document.forms[1];

  with (frm) {    
		for ( i=0;i<fields.length;i++ )
   {
			field = fields[i];

			obj = elements[''+field+''];

      //wenn radio box dann dyn. durchklappern
      if ( obj.type != "text"  && obj.type != "password" && obj.type != "file" && obj.type != "textarea" && obj.type != "select-one" )
      {

        if ( obj[0].type == "radio" )
        {
          var check = 0;

          for (k=0;k<obj.length;k++)
          {
            if ( obj[k].checked == true ) { check++; }
          }

          if ( check == 0 )
          {
            ok=false;

            for (k=0;k<obj.length;k++)
            {
              obj[k].style.backgroundColor='#73AA1B';
            }
          } else {
            for (k=0;k<obj.length;k++) {
              obj[k].style.backgroundColor='#0D7ACF';
            }
          }
        }
      }
      else if ( obj.type == "select-one" )
      {
        //alert(obj.value);
        if ( obj.value == "" ) {ok=false; obj.style.backgroundColor='#73AA1B';} else  { obj.style.backgroundColor='#0D7ACF'; }
		  }      
     else
     {
      if (!obj.value) {ok=false; obj.style.backgroundColor='#73AA1B';} else  { obj.style.backgroundColor='#0D7ACF'; }
		   }	
    }		
		if ( !ok )
    {
			document.getElementById('stan').src = 'pix/stan_alert.gif';
			return false;
		}
    else return true;
	}
} //end of function checkReqFields()


function checkReqFields3( fields )
{
 fields = explodeArray(fields,",");
 var m,ok,obj,mfocus,frm; ok=true;

 frm=document.forms[1];

  with (frm) {    
		for ( i=0;i<fields.length;i++ )
    {
			field = fields[i];
			obj = elements[''+field+''];

      //wenn radio box dann dyn. durchklappern
      if ( obj.type != "text"  && obj.type != "password" && obj.type != "file" && obj.type != "textarea" && obj.type != "select-one" )
      {
        if ( obj[0].type == "radio" )
        {
          var check = 0;

          for (k=0;k<obj.length;k++)
          {
            if ( obj[k].checked == true ) { check++; }
          }
          if ( check == 0 )
          {
            ok=false;

            for (k=0;k<obj.length;k++)
            {
              obj[k].style.backgroundColor='#73AA1B';
            }
          } else {
            for (k=0;k<obj.length;k++) {
              obj[k].style.backgroundColor='#0D7ACF';
            }
          }
        }
      }
      else if ( obj.type == "select-one" )
      {
        //alert(obj.value);
        if ( obj.value == "" ) {ok=false; obj.style.backgroundColor='#73AA1B';} else  { obj.style.backgroundColor='#0D7ACF'; }
		  }
      else
      {
        if (!obj.value) {ok=false; obj.style.backgroundColor='#73AA1B';} else  { obj.style.backgroundColor='#0D7ACF'; }
		  }	
    }		

		if ( !ok )
    { 
			document.getElementById('pat').src = 'pix/pat-2_alert.gif';			
      return false;			
		}
    else
    {
     return true;
    }
	}
} //end of function checkReqFields()
var InternalLink,selectd,box,frm,obj;

function replace(STR, SRCH, SUBST)
{
    Split = STR.split(SRCH); Out = Split[0];

		for (c =1; c< Split.length; c++) 
		{
			Out += SUBST + Split[c];
		}

    return Out;
}

function linkman(k,b)
{
	box=b;

	selectd = unescape(editor_findSelection(self));
		if (selectd.length > 0)
		{
			if (selectd.charAt(selectd.length-1)==' ') {selectd=selectd.substring(0,selectd.length-1);}
			if (k=='extern') {l = prompt('WWW-Adresse eintragen:', '');param1='';param2='" target="_blank';createLink();}
			if (k=='email') {l = prompt('E-Mail Adresse eintragen:','');param1='mailto:';param2='';createLink();}
			if (k=='bolder') {createBold();}	
      if (k=='ital') {createItalic();}	
      if (k=='azur') {createAzur();}				
		} else { alert('Bitte erst ein Wort markieren!') };
}

function createLink()
{
	if (document.layers) {frm=document.layers['content'].document.forms[0];} else {frm=document.forms[0];}

	if ((l)&&l!=''&&l!='undefined'&&l!='www.')
	{
		//if (l.indexOf('javascript'!=-1)) {param2='';}
		linked = '<a href="'+param1+l+param2+'">'+selectd+'</a>';

		with (frm)
		{
			obj = elements[''+box+''];
			obj.value=replace(obj.value,selectd,linked);
		}
	}
}

function createBold()
{
	if (document.layers) {frm=document.layers['content'].document.forms[0];} else {frm=document.forms[0];}

		linked = '<b>'+selectd+'</b>';

		with (frm)
		{
			obj = elements[''+box+''];
			obj.value=replace(obj.value,selectd,linked);
		}
}

function BlurLinks()
{
	//global blur on all hrefs
	if (!document.layers) {
	lnks=document.getElementsByTagName('a');

	for(i=0;i<lnks.length;i++) {
	lnks[i].onfocus=new Function("if(this.blur)this.blur()");
	}

	//global blur on all checkboxes
	lnks=document.getElementsByTagName('input');
	for(i=0;i<lnks.length;i++)
 {
	  if (lnks[i].type == "checkbox" || lnks[i].type == "radio" || lnks[i].type == "submit" || lnks[i].type == "button") lnks[i].onfocus=new Function("if(this.blur)this.blur()");
 }
  }
}

// Opens "Mediapool"-Window
function selectMediaWin( old_id, old_img )
{
	var y =   ( Math.round ( (screen.availHeight-480)/2  ) )
	var x =   ( Math.round ( (screen.availWidth-480)/1.4 ) )
	win   =   window.open  ('select.php?old_id='+old_id+'&old_img='+old_img+'','Mediapool','toolbar=0,status=1,scrollbars=1,width=510,height=550,resizable=1,top='+y+',left='+x);
	win.focus ();
}

// Opens "PDF"-Window
function selectPdfWin( old_id )
{
	var y =   ( Math.round ( (screen.availHeight-480)/2  ) )
	var x =   ( Math.round ( (screen.availWidth-480)/1.3 ) )
	win   =   window.open  ('selectpdf.php?old_id='+old_id,'PDFpool','toolbar=0,status=1,scrollbars=1,width=600,height=450,resizable=1,top='+y+',left='+x);
	win.focus ();
}

// Opens "PDF"-Window
function selectMovieWin( old_id )
{
	var y =   ( Math.round ( (screen.availHeight-480)/2  ) )
	var x =   ( Math.round ( (screen.availWidth-480)/1.3 ) )
	win   =   window.open  ('selectmv.php?old_id='+old_id,'Moviepool','toolbar=0,status=1,scrollbars=1,width=600,height=450,resizable=1,top='+y+',left='+x);
	win.focus ();
}

// Opens new window for data-search, used in the CMS only yet
function searchMediaWin( type )
{
	var obj;
	with ( document.forms[0] )
	{
		// Init Vars
		obj        = elements['aFormdata[titel_1]'];
		searchterm = obj.value;

		if  ( type == "pdf"     )
		{
		  // Cut pat to author, This part is for PDF
			obj        = elements['filename_1'];
			searchOld  = obj.value;
			firstpos   = searchOld.lastIndexOf('\\')+1;
			lastpos    = searchOld.length;
			searchterm = searchOld.substring( firstpos, lastpos );
		}
	}

	var y        = ( Math.round( ( screen.availHeight-300 )/2 ) )
	var x        = ( Math.round( ( screen.availWidth-900 )/2 ) )
	win      = window.open('popup_searchmedia.php?searchterm='+searchterm+'&titleSearch='+type+'','mediendbsearch','toolbar=0,status=1,menubar=0,scrollbars=1,width=900,height=300,resizable=1,top='+y+',left='+x);
	win.focus();
}