/* #####################
##############
######################*/
/* #####################
##############
######################*/

function fetch_object(A){
 if(document.getElementById){
  return document.getElementById(A)
 } else{if(document.all){return document.all[A]}else{if(document.layers){return document.layers[A]}else{return null}}}}

function resize_textarea(C,B) {
 var A=fetch_object(B);
 
 A.style.width=parseInt(A.offsetWidth)+(C<0?-100:100)+"px";
 A.style.height=parseInt(A.offsetHeight)+(C<0?-100:100)+"px";
 
 return false
}

function checkSubmitWording()
{
 var i = 0;
 
 if ( document.getElementById('chk_submit2bookingdeutsch').checked == true )
  i++;
  
 if ( document.getElementById('chk_submit2bookinginternational').checked == true )
  i++;
  
 if ( document.getElementById('chk_submit2matchclub') ) {
    if ( document.getElementById('chk_submit2matchclub').checked == true )
      i++;
 }
  
 if ( document.getElementById('chk_submit2followme') ) {
    if ( document.getElementById('chk_submit2followme').checked == true )
      i++;
 }
  
 if ( document.getElementById('chk_submit2testgroup').checked == true )
  i++;
      
 if ( document.getElementById('chk_submit2kontakteinternational').checked == true )
  i++;
      
 if ( document.getElementById('chk_submit2userevents').checked == true )
  i++;
  
 if ( document.getElementById('chk_submit2kontaktedeutsch').checked == true )
  i++;
  
 if ( document.getElementById('chk_submit2tomnovygroup').checked == true )
  i++;
    
 if ( document.getElementById('chk_receiver').value != "" )
  i++;
  
 if ( i > 0 )
  document.getElementById('chk_save').value = 'speichern und senden';
 else
  document.getElementById('chk_save').value = 'speichern';

 return true;
}


function mrCheckFindSelection (w)
{
 var mrCheckWhitespace = new RegExp('([ \\n\\t\\v\\r\\f]|%0D|%0A|%20)+', 'g');
 var agt               = navigator.userAgent.toLowerCase();
 var txt = document.forms[0].elements[w];

	// IE6 or MOZ
	if ( agt.indexOf('msie') != -1 ) 
 { 
  // Init Vars
  var pattern = escape( w.document.selection.createRange().text );
  
  // Is selection made?
  if ( pattern )	return ( pattern );
  else           return ("");
 }
 else if ( typeof txt.selectionStart != 'undefined' ) // Gecko-Based
 { 
  var selLength = txt.textLength;
		var selStart = txt.selectionStart;
		var selEnd = txt.selectionEnd;  
		if (selEnd==1 || selEnd==2) selEnd=selLength;
  
		var t = (txt.value).substring(selStart, selEnd);
  return (t);
 }
 else
 {
  alert( "The HTML-Editor only works under Firefox 1+ or IE5+ (both PC only)" );
 }
}

function vbcode(theform,vbcode,formfield)
{
	inserttext = prompt("Fügen Sie den zu formatierenden Text ein:"+"\n\n",'');
	//this way out to adress array-vars within form-fields
	with (theform) obj = elements['aFormdata['+formfield+']'];
	obj.value += "<"+vbcode+">"+inserttext+"</"+vbcode+"> ";
}


function namedlink(theform,thetype,formfield)
{
	link_text_prompt = "Geben Sie den Text ein, der für den Link geziegt werden soll (optional)";
	link_url_prompt = "Hier die komplette URL eingeben";
	link_email_prompt = "Bitte die Email Adresse eingeben";

	linktext = prompt(link_text_prompt,"");
	
		if (thetype == "http://www.") {
			prompt_text = link_url_prompt;
			targets = "";
			mail_contents = "";
			}
		else {
			prompt_text = link_email_prompt;
			targets = "";
			thetype = "";
			mail_contents = "mailto:";
			}
			
	linkurl = prompt(prompt_text,thetype);
	with (theform) obj = elements['aFormdata['+formfield+']'];
	obj.value += "<a href='"+mail_contents+linkurl+"'"+targets+">"+linktext+"</A> ";
}

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) {
 var agt = navigator.userAgent.toLowerCase();
	box=b;

	// IE6
	if ( agt.indexOf('msie') != -1 ) 
 {
	 selectd = unescape(mrCheckFindSelection(self));
 }
 else
 {
  selectd = unescape(mrCheckFindSelection(b));
 }

		if (selectd.length > 0) {
		if (selectd.charAt(selectd.length-1)==' ') {selectd=selectd.substring(0,selectd.length-1);}
			if (k=='extern') {l = prompt('Bitte den externen Link angeben!', 'www.');param1='http://';param2='';createLink();}
			if (k=='email') {l = prompt('Bitte die E-Mail Adresse angeben!');param1='mailto:';param2='';createLink();}
			if (k=='bolder') {createBold();}
			if (k=='softer') {createSofter();}
			if (k=='kursiv') {createKursiv();}					
		} 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()
{
	 frm=document.forms[0];
		linked = '<b>'+selectd+'</b>';
		with (frm)
 {
			obj = elements[''+box+''];
			obj.value=replace(obj.value,selectd,linked);
		}
}
function createSofter()
{
	 frm=document.forms[0];
		linked = '<span class="greentxt">'+selectd+'</span>';
		with (frm)
 {
			obj = elements[''+box+''];
			obj.value=replace(obj.value,selectd,linked);
		}
}
function createKursiv() {
	if (document.layers) {frm=document.layers['content'].document.forms[0];} else {frm=document.forms[0];}
		linked = '<i>'+selectd+'</i>';
		with (frm) {
			obj = elements[''+box+''];
			obj.value=replace(obj.value,selectd,linked);
		}
}
// opens new window for internal links
function openIntLinkWin() {
	var left = (screen.width - 320);
	win = window.open('popup_links.php','popup','toolbar=0,status=0,scrollbars=1,width=300,height=500,resizable=1,top=0,left='+left);
	win.focus();
}


function confirmDelete() {
	var chk = window.confirm("Diesen Datensatz wirklich l"+unescape('%F6')+"schen?");
	return(chk);
}

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) {   
  //alert(frm); 
		for ( i=0;i<fields.length;i++ ) {
			field = fields[i];
			obj = elements[''+field+''];
      //alert(obj.value);
      //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='#ff0000';
            }
          } else {
            for (k=0;k<obj.length;k++) {
              obj[k].style.backgroundColor='#ffffff';
            }
          }
        }
      } else if ( obj.type == "select-one" ) {
        if ( obj.value == "00" || obj.value == "0000" ) {ok=false; obj.style.backgroundColor='#ff0000';} else  { obj.style.backgroundColor='#ffffff'; }
		  }      
        else {
        if (!obj.value) {ok=false; obj.style.backgroundColor='#ff0000';} else  { obj.style.backgroundColor='#ffffff'; }
		  }	
    }		
		
		if (!ok)
  {
			alert("Bitte alle rot markierten Pflichtfelder ausf"+unescape('%FC')+"llen");
			return false;
		}
  else
  {
   return true; 
  }
	}
}
//end of function checkReqFields()















function checkReqFieldsChk(fields) {
  fields = explodeArray(fields,",");
	var m,ok,obj,mfocus,frm; ok=true;
	
  frm=document.forms[0];
	
  with (frm) {   
  //alert(frm); 
		for ( i=0;i<fields.length;i++ ) {
			field = fields[i];
			obj = elements[''+field+''];
      //alert(obj.value);
      //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='#fd3f27';
            }
          } else {
            for (k=0;k<obj.length;k++) {
              obj[k].style.backgroundColor='#fd3f27';
            }
          }
        }
      } else if ( obj.type == "select-one" ) {
        if ( obj.value == "00" || obj.value == "0000" ) {ok=false; obj.style.backgroundColor='#fd3f27';} else  { obj.style.backgroundColor='#fd3f27'; }
		  }      
        else {
        if (!obj.value) {ok=false; obj.style.backgroundColor='#fd3f27';} else  { obj.style.backgroundColor='#fd3f27'; }
		  }	
    }		
		
		if (!ok)
    {
			alert("Bitte alle Pflichtfelder (*) ausf"+unescape('%FC')+"llen");
			return false;
		}
   else
   {
    if ( document.getElementById('chk_save').value != 'Wirklich senden?' && document.getElementById('chk_save').value == 'speichern und senden' )
    {
     document.getElementById('chk_save').value='Wirklich senden?';
     document.getElementById('chk_save').style.backgroundColor='#ff0000';
      document.getElementById('chk_save').style.color='#fff';
     return false;
    } 
      else
       return true;
   }
	}
}
//end of function checkReqFields()


























// opens new window for internal links
function generate(etype)
{
	var y = (Math.round((screen.availHeight-500)/2))
	var x = (Math.round((screen.availWidth-300)/2))
	win = window.open('generate.php?etype='+etype+'','popup','toolbar=0,status=0,scrollbars=0,width=300,height=500,resizable=1,top='+y+',left='+x);
	win.focus();
}

// opens new window for SELECT from "Medien-DB"
function selectMediaWin( jsfield_id, realimg )
{
	var y = (Math.round((screen.availHeight-620)/2))
	var x = (Math.round((screen.availWidth-380)/1.3))
	win = window.open('popup_selectmedia.php?jsfield_id='+jsfield_id+'&realimg='+realimg+'','Archiv','toolbar=0,status=1,scrollbars=1,width=380,height=620,resizable=1,top='+y+',left='+x);
	win.focus();
}

// opens new window for DataSearch
function searchMediaWin(type)
{
	var obj,frm;
	if (document.layers) {frm=document.layers['content'].document.forms[0];} else {frm=document.forms[0];}
	
	with (frm) {
		if (type == "titleSearch") {
			obj = elements['aFormdata[titel_1]'];
			searchterm = obj.value;
		} else if (type == "pdfSearch") {
				//pfad zum redakteur abschneiden
				obj = elements['filename_1'];
				searchtermOld = obj.value;
				firstpos=searchtermOld.lastIndexOf('\\')+1;
				lastpos=searchtermOld.length;
				searchterm=searchtermOld.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();
}

function searchMediaWin2()
{
	var y = (Math.round((screen.availHeight-300)/2))
	var x = (Math.round((screen.availWidth-900)/2))
	win = window.open('popup_searchmedia.php?titleSearch=pdfSearch','mediendbsearch','toolbar=0,status=1,menubar=0,scrollbars=1,width=900,height=300,resizable=1,top='+y+',left='+x);
	win.focus();
}
