var wait4download = 0
function LoadImage(filename,image)
{
     document.images[image].src = './medias/thumbsmall/'+filename;
}


function imageswap(imgDocID,imgObjName)
{
     document.images[imgDocID].src = eval(imgObjName + ".src");
}

function gimageswap(imgDocID, imgObjectName, imgObjectType, imgObjectNumber)
{
     document.images[imgDocID].src = eval(imgObjectName + imgObjectType + "[" + imgObjectNumber+ "].src");
}

function EmailCheck (emailStr)
{

     var emailPat=/^(.+)@(.+)$/
     var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
     var validChars="\[^\\s" + specialChars + "\]"
     var quotedUser="(\"[^\"]*\")"
     var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
     var atom=validChars + '+'
     var word="(" + atom + "|" + quotedUser + ")"
     var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
     var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
     var matchArray=emailStr.match(emailPat)
     if (matchArray==null)
     	return 0
     var user=matchArray[1]
     var domain=matchArray[2]

     if (user.match(userPat)==null)
         return 0


     var IPArray=domain.match(ipDomainPat)
     if (IPArray!=null)
     {
          for (var i=1;i<=4;i++)
               if (IPArray[i]>255)
     		   return 0
          return 1
     }

     var domainArray=domain.match(domainPat)
     if (domainArray==null)
          return 0

     var atomPat=new RegExp(atom,"g")
     var domArr=domain.match(atomPat)
     var len=domArr.length
     if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4)
        return 0

     if (len<2)
        return 0

     return 1;
}

function PreloadThumbnails() 
{
     
     for (iForPreload = 0; iForPreload < ThumbnailList.length; iForPreload++) 
     {
          PreLoadingThumbs[iForPreload] = new Image()
          PreLoadingThumbs[iForPreload].src = ThumbnailList[iForPreload]
     }

     for (iForPreload = 0; iForPreload < PreLoadingThumbs.length; iForPreload++) 
     {
          PreLoadedThumbs[iForPreload] = false
     }
     CheckLoad()
}


function CheckLoad() 
{
     if (ImageCounter == PreLoadingThumbs.length) 
     {
          return
     }
     
     for (iForPreload = 0; iForPreload <= PreLoadingThumbs.length; iForPreload++) 
     {
          if (PreLoadedThumbs[iForPreload] == false && PreLoadingThumbs[iForPreload].complete) 
          {
               PreLoadedThumbs[iForPreload] = true
               ImageCounter++
               document.getElementById('preloadprogress').style.width      =  (150 / PreLoadingThumbs.length * ImageCounter) +'px' ;
               
               if (ImageCounter == PreLoadingThumbs.length)
               {
                    document.getElementById('preloadarea').style.width      =  '0px' ;
                    parent.window.document.getElementById('hidescrollbar').style.width     =  '0px' ;
               }
          }
     }
     timerID = setTimeout('CheckLoad()',10)
}

function CheckUserInputChar(Type,Value)
{

     if (!Type)
          Type = "posinteger";    

     Type = Type.toLowerCase()

     if (document.all)
          InputCharCode = window.event.keyCode;
     else
          InputCharCode = FF_LastEvent.which;

     if (!InputCharCode || InputCharCode==8)
          return (true);

     if (Type == 'noenter')
     {

          if (InputCharCode != 13)
               return(true);
          else
               return(false);
     }

     if (Type == 'password')
     {
          if ((InputCharCode >= 65 && InputCharCode <= 90) || (InputCharCode >= 97 && InputCharCode <= 122) || (InputCharCode >= 48 && InputCharCode <= 57))
               return(true);
          else
               alert("Es sind nur die Zeichen A-Z und 0-9 erlaubt");
     }

     if (Type=='loginname')
     {
          if (Value.length==0)
          {
               if ((InputCharCode >= 65 && InputCharCode <= 90) || (InputCharCode >= 97 && InputCharCode <= 122) || InputCharCode == 196 || InputCharCode == 214 || InputCharCode == 220 || InputCharCode == 228 || InputCharCode == 246 || InputCharCode == 252)
                    return(true);
               else
                    alert('Der Loginname muss mit einem Buchstaben beginnen');
          }
          else
          {
               if ((InputCharCode >= 65 && InputCharCode <= 90) || (InputCharCode >= 97 && InputCharCode <= 122) || (InputCharCode >= 48 && InputCharCode <= 57) || InputCharCode == 43  || InputCharCode == 45 || InputCharCode == 46 || InputCharCode == 190 || InputCharCode == 58 || InputCharCode == 95 || InputCharCode == 196 || InputCharCode == 214 || InputCharCode == 220 || InputCharCode == 228 || InputCharCode == 246 || InputCharCode == 252)
                    return(true);
          }    
     }

     if (Type=='emailaddress')
     {
          if (Value.length==0)
          {
               if ((InputCharCode>=65 && InputCharCode<=90) || (InputCharCode>=97 && InputCharCode<=122) || InputCharCode == 45 || InputCharCode == 43 || InputCharCode==46 || InputCharCode == 190 || InputCharCode==95 || (InputCharCode>=48 && InputCharCode<=57))
                    return(true);
               else
                    alert('Die eMailadresse kann nicht mit diesem Zeichen beginnen');
          }
          else
          {
               if (InputCharCode == 64)
               {
                    if (Value.indexOf('@') != -1)
                         alert('Die eMailadresse darf nur ein @ enthalten');
                    else
                         return (true);
               }
               
               if ((InputCharCode>=65 && InputCharCode<=90) || (InputCharCode>=97 && InputCharCode<=122) || InputCharCode == 45 || InputCharCode == 43 || InputCharCode==46 || InputCharCode == 190 || InputCharCode==95 || (InputCharCode>=48 && InputCharCode<=57))
                    return(true);
          }            
     }

     if (Type=='emailalias')
     {
          if (InputCharCode == 42 && Value.length==0)
               return (true);
          if (Value.length > 0 && Value.indexOf('*') != -1)
               return(false);
               
          if ((InputCharCode>=65 && InputCharCode<=90) || (InputCharCode>=97 && InputCharCode<=122) || InputCharCode == 45 || InputCharCode == 43 || InputCharCode==46 || InputCharCode == 190 || InputCharCode==95 || (InputCharCode>=48 && InputCharCode<=57))
               return(true);
     }


     if (Type=='reversedns')
     {
          if (Value.length==0)
          {
               if ((InputCharCode >= 65 && InputCharCode <= 90) || (InputCharCode >= 97 && InputCharCode <= 122) || (InputCharCode >= 48 && InputCharCode <= 57))
                    return(true);
          }
          else
          {
               if ((InputCharCode >= 65 && InputCharCode <= 90) || (InputCharCode >= 97 && InputCharCode <= 122) || (InputCharCode >= 48 && InputCharCode <= 57) || InputCharCode == 45 || InputCharCode == 46 || InputCharCode == 190 || InputCharCode == 95)
                    return(true);
          }    
     }


     if (Type=='domainname')
     {
          var validChars = new Array(45,46,48,49,50,51,52,53,54,55,56,57,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,190,122,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,248,249,250,251,252,253,254,255,257,259,261,263,265,267,269,271,273,275,277,279,281,283,285,287,289,291,293,295,297,299,301,303,305,309,311,312,314,316,318,322,324,326,328,331,333,335,337,339,341,343,345,347,349,351,353,355,357,359,361,363,365,367,369,371,373,375,378,380,382);
          if (in_array(InputCharCode,validChars))
               return(true);
          else
               alert('Zeichen in Domainnamen nicht erlaubt');
     }

     if (Type=='hostnamemapping')
     {
          var validChars = new Array(45,47,48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,95,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122);
          if (in_array(InputCharCode,validChars))
               return(true);
          else
               alert('Zeichen in Verzeichnisnamen nicht erlaubt');
     }

     if (Type=='url')
     {
          var validChars = new Array(45,46,47,48,49,50,51,52,53,54,55,56,57,58,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,190,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,248,249,250,251,252,253,254,255,257,259,261,263,265,267,269,271,273,275,277,279,281,283,285,287,289,291,293,295,297,299,301,303,305,309,311,312,314,316,318,322,324,326,328,331,333,335,337,339,341,343,345,347,349,351,353,355,357,359,361,363,365,367,369,371,373,375,378,380,382);
          if (in_array(InputCharCode,validChars))
               return(true);
          else
               alert('Zeichen in URL nicht erlaubt');
     }

     if (Type=='realname')
     {
          if (Value.length==0)
          {
               if ((InputCharCode >= 65 && InputCharCode <= 90) || (InputCharCode >= 97 && InputCharCode <= 122) || InputCharCode == 196 || InputCharCode == 214 || InputCharCode == 220 || InputCharCode == 228 || InputCharCode == 246 || InputCharCode == 252)
                    return(true);
               else
                    alert('Der Name muss mit einem Buchstaben beginnen');                    
          }
          else
          {
               if (InputCharCode == 32 || (InputCharCode >= 65 && InputCharCode <= 90) || (InputCharCode >= 97 && InputCharCode <= 122) || (InputCharCode >= 48 && InputCharCode <= 57) || InputCharCode == 43  || InputCharCode == 45 || InputCharCode == 46 || InputCharCode == 190 || InputCharCode == 58 || InputCharCode == 95 || InputCharCode == 196 || InputCharCode == 214 || InputCharCode == 220 || InputCharCode == 228 || InputCharCode == 246 || InputCharCode == 252)
                    return(true);
          }    
     }

     if (Type=='posinteger' || Type == "integer")
     {
          if (InputCharCode >= 48 && InputCharCode <= 57)
               return(true);
     }

     if (Type == 'decimal' || Type == "posdecimal")
     {
          if (InputCharCode == 44)
          {
               if (document.all && !window.opera)
               {
                    InputCharCode = 46
                    window.event.keyCode = 46
               }
               else
               {
                    alert("',' not allowed! use '.'")
                    return(false)
               }
          }
          if (!Value)
          {
               if ((InputCharCode >= 48 && InputCharCode <= 57) || InputCharCode == 46 || InputCharCode == 190)
                    return(true);
          }
          else
          {
               if ((InputCharCode >= 48 && InputCharCode <= 57) || ((InputCharCode == 46 || InputCharCode == 190)  && substr_count(Value,String.fromCharCode(46))<1))
                    return (true)
          }          
     }
     if (Type == 'phonenumber')
     {
          if (InputCharCode >= 48 && InputCharCode <= 57)
               return (true)
          else
          {
               if (document.all && !window.opera)
               {
                    if (InputCharCode >=97 && InputCharCode <=122)
                         InputCharCode = InputCharCode - 32;
     
                    if (InputCharCode>82)
                         InputCharCode = InputCharCode -1;
                    if (InputCharCode==89)
                         InputCharCode = InputCharCode -1;
                    if (InputCharCode>=65 && InputCharCode<=90)
                    {
                         window.event.keyCode = Math.floor((InputCharCode - 65) / 3) + 50;
                         return (true);
                    }
               }
          }
     }

     return (false);
}

function FF_SaveEvent(evt)
{
     FF_LastEvent = evt;
}

if (!document.all)
{
     var FF_LastEvent = "";
     document.onkeydown = FF_SaveEvent;
}

function substr_count(String,SearchChar)
{
     counter = 0;
     for (iFor1 = 0; iFor1 < String.length; iFor1++)
     {
          if (String.charAt(iFor1) == SearchChar)
               counter++;
     }
     return (counter)               
}

function in_array(value,a_array)
{
     for (var i=0; i<a_array.length; i++) 
     {
          if (a_array[i] == value) 
          {
               return(1)
          }
     }
     return(0)
}

function DeCryptSendto(s) 
{
     var n=0;
     var r="";
     s = "ocknvq<"+s;
     for(var i=0; i < s.length; i++) 
     {
     	n=s.charCodeAt(i);
     	if (n>=8364) {n = 128;}
     	r += String.fromCharCode(n-(2));
     }
     location.href=r;
}

   function InsertText(field,aTag, eTag) 
   {
        var input = field;
        input.focus();

        /* f?r Internet Explorer */
        if(typeof document.selection != 'undefined') 
        {
             /* Einf?gen des Formatierungscodes */
             var range = document.selection.createRange();
             var insText = range.text;
             range.text = aTag + insText + eTag;
             /* Anpassen der Cursorposition */
             range = document.selection.createRange();
             if (insText.length == 0) 
             {
                  range.move('character', -eTag.length);
             } 
             else 
             {
                  range.moveStart('character', aTag.length + insText.length + eTag.length);      
             }
             range.select();
        }
        else if(typeof input.selectionStart != 'undefined')
        {
             /* Einf?gen des Formatierungscodes */
             var start = input.selectionStart;
             var end = input.selectionEnd;
             var insText = input.value.substring(start, end);
             input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
             /* Anpassen der Cursorposition */
             var pos;
             if (insText.length == 0) 
             {
                  pos = start + aTag.length;
             } else 
             {
                  pos = start + aTag.length + insText.length + eTag.length;
             }
             input.selectionStart = pos;
             input.selectionEnd = pos;
        }
        /* f?r die ?brigen Browser */
        else
        {
             /* Abfrage der Einf?geposition */
             var pos;
             var re = new RegExp('^[0-9]{0,3}$');
             while(!re.test(pos)) 
             {
                  pos = prompt('Einf?gen an Position (0..' + input.value.length + '):', '0');
             }
             if(pos > input.value.length) 
             {
                  pos = input.value.length;
             }
             /* Einf?gen des Formatierungscodes */
             var insText = prompt('Bitte geben Sie den zu formatierenden Text ein:');
             input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
        }
   }


String.prototype.LTrim = new Function("return this.replace(/^\\s+/,'')")
String.prototype.RTrim = new Function("return this.replace(/\\s+$/,'')")
String.prototype.Trim  = new Function("return this.replace(/^\\s+|\\s+$/g,'')")

function str_replace(nach, ersetzte, source) 
{
     anzahl = nach.length;
     dummy = ""
     while (source.indexOf(nach)>=0) 
     {
          aktuell = source.indexOf(nach);
          dummy += source.substr(0, aktuell)
          if (aktuell >= 0) 
               dummy += ersetzte
          source = source.substr((aktuell+anzahl), source.length);
     }
     if (source.length >0) 
          dummy += source
     
     return dummy
}

function str_repeat(char2repeat, repeatcount) 
{
	var repString = "";
	for (iFor1 = 0; iFor1 < (repeatcount-0); iFor1++)
	{
		repString += char2repeat;
	}
     
	return (repString);
}


var http_request = false;

function serverRequest(url,actionFunction) 
{
      
	http_request = false;
     if (window.XMLHttpRequest) 
     { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) 
          {
               http_request.overrideMimeType('text/xml');
          }
     } 
     else if (window.ActiveXObject) 
     { // IE
          try 
          {
               http_request = new ActiveXObject("Msxml2.XMLHTTP");
          } 
          catch (e) 
          {
               try 
               {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
               } 
               catch (e) 
               {}
          }
     }
      
     if (!http_request) 
     {
          alert('Kann keine XMLHTTP-Instanz erzeugen');
          return false;
     }
     http_request.onreadystatechange = eval(actionFunction);
     http_request.open('GET', url, true);
     http_request.send(null);
      
}


function aj_checkDownloadStatus()
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
			var xmldoc = http_request.responseXML;
			fStatus = xmldoc.getElementsByTagName('status').item(0).firstChild.data;
			if (fStatus == '1')
			{
				document.getElementById('hidesite').style.display	 =  'none' ;
				document.getElementById('waitingtext').style.display	 =  'block' ;
				document.getElementById('waitingtextpreview').style.display	 =  'none' ;
				top.frames['gallerystage'].document.getElementById('imagegallery').style.display	 =  'block' ;
				window.clearInterval(wait4download);
			}
		}
	}
	
}

function aj_cacheImages() 
{
     if (http_request.readyState == 4) 
     {
		if (http_request.status == 200) 
		{
			var xmldoc = http_request.responseXML;

			for (iFor1 = 0; iFor1 < xmldoc.getElementsByTagName('menue_name').length; iFor1++)
			{
				var menue_name 	 = xmldoc.getElementsByTagName('menue_name').item(iFor1);
				var menue_artist 	 = xmldoc.getElementsByTagName('menue_artist').item(iFor1);
				var menue_name_alt 	 = xmldoc.getElementsByTagName('menue_name_alt').item(iFor1);
				var menue_artist_alt = xmldoc.getElementsByTagName('menue_artist_alt').item(iFor1);
				var menue_id		 = xmldoc.getElementsByTagName('menue_id').item(iFor1);
				
				imageCache[menue_name.firstChild.data] 			= new Image();
				imageCache[menue_name.firstChild.data].src 		= menue_name.firstChild.data.Trim();
				picgalleryname[iFor1]						= menue_name.firstChild.data.Trim();
				imageCache[menue_artist.firstChild.data] 		= new Image();
				imageCache[menue_artist.firstChild.data].src 	= menue_artist.firstChild.data.Trim();
				picgalleryartist[iFor1]						= menue_artist.firstChild.data.Trim();
				imageCache[menue_name_alt.firstChild.data] 		= new Image();
				imageCache[menue_name_alt.firstChild.data].src	= menue_name_alt.firstChild.data.Trim();
				pic2galleryname[iFor1]						= menue_name_alt.firstChild.data.Trim();
				imageCache[menue_artist_alt.firstChild.data] 	= new Image();
				imageCache[menue_artist_alt.firstChild.data].src 	= menue_artist_alt.firstChild.data.Trim();
				pic2galleryartist[iFor1]						= menue_artist_alt.firstChild.data.Trim();
				fieldname = 'galleryname['+iFor1+']';
				fieldartist = 'galleryartist['+iFor1+']';
				document.images[fieldname].src = imageCache[menue_name.firstChild.data].src;
				document.images[fieldartist].src = imageCache[menue_artist.firstChild.data].src;
				fieldid = 'galleryid['+iFor1+']';
				document.gallerymenue.elements[fieldid].value = menue_id.firstChild.data.Trim();
			}
		}
		else 
		{
			alert('Noch einmal, bitte.\nOnce again, please.\nOtra vez, por favor. ');
		}
	}
}

function aj_Diashow() 
{
     if (http_request.readyState == 4) 
     {
          if (http_request.status == 200) 
          {
               var xmldoc = http_request.responseXML;
               iAktNr = xmldoc.getElementsByTagName('imagenr').item(0).firstChild.data;
            
               imageAktNr = str_repeat('0',iCounterLength)+iAktNr;
               imageAktNr = imageAktNr.substr(imageAktNr.length-iCounterLength,iCounterLength);
               document.images['imagecount'].src = './_gettext.php?type=png&text='+(imageAktNr)+ sJStext +'&textsize=9';

			if (xmldoc.getElementsByTagName('morelink').item(0).firstChild.data-0 > 0)
			{
				document.getElementById('morelink').innerHTML= '';
				document.getElementById('morelink').innerHTML = '<a href=./catalog.php?bid='+iProjectID+'&pmid='+iAktNr+'&oid='+xmldoc.getElementsByTagName('morelink').item(0).firstChild.data+' onMouseOver="imageswap(\'projectlink\',\'pic2projectlink\')" onMouseOut="imageswap(\'projectlink\',\'picprojectlink\')"><img name=projectlink src=./siteimages/transp.gif border=0 align=left></a>';
				imageswap('projectlink','picprojectlink');
			}
			else
			{
				document.getElementById('morelink').innerHTML= '';
			}

               PreLoading = "";
               PreLoading = new Image();
               PreLoading.src = './_getmedia.php?pid='+iProjectID+'&ptype=2&mid='+xmldoc.getElementsByTagName('imageid').item(0).firstChild.data+'&mtype=2';


               if (infostatus  || infostatusOver)
                    document.images['infotext'].src = xmldoc.getElementsByTagName('portfolioiptc').item(0).firstChild.data;
               pic1infotext.src = xmldoc.getElementsByTagName('portfolioiptc').item(0).firstChild.data;

               aj_PortfolioDiashowWaitForLoad()
          }
          else 
          {
        	  alert('Noch einmal, bitte.\nOnce again, please.\nOtra vez, por favor. ');
               fAllowNext=1;
          }
     }
}
var AppearOrDisappear = 0;
function aj_PortfolioDiashowWaitForLoad()
{
     if (PreLoading.complete)
     {

          if (!AppearOrDisappear)
          {
          	layerFront = 'disappear_div';
          	layerBack = 'appear_div';
          	document.images['nextportfolioimage'].src = './siteimages/transp.gif';
          	document.images['nextportfolioimage'].src = PreLoading.src;
          }
          else
          {
          	layerFront = 'appear_div';
          	layerBack = 'disappear_div';
          	document.images['portfolioimage'].src = './siteimages/transp.gif';
          	document.images['portfolioimage'].src = PreLoading.src;
          }
          
          //document.images['portfolioimage'].src = './siteimages/transp.gif';
          //document.images['portfolioimage'].src = PreLoading.src;
          
          Effect.Fade(layerFront,{delay:0.0,duration:0.3 });
          Effect.Appear(layerBack,{delay:0.0,duration:0.3 });
          window.setTimeout("fAllowNext=1;", 400);

    
    		AppearOrDisappear = (AppearOrDisappear-1) * (-1);
                   
          if (fSlideshowStatus)
               window.setTimeout("MoveNext()", iSlideShowTimer);     
     }
     else
          window.setTimeout("aj_PortfolioDiashowWaitForLoad()", 10);     
}

function aj_StartPageImage()
{
     if (http_request.readyState == 4) 
     {
          if (http_request.status == 200) 
          {
			//alert('ok');
			location.reload()
          }
          else 
          {
        	  alert('Noch einmal, bitte.\nOnce again, please.\nOtra vez, por favor. ');
               fAllowNext=1;
          }
     }

}


function aj_Noop() 
{}     
     function alertInhalt() 
     {
     
          if (http_request.readyState == 4) 
          {
               if (http_request.status == 200) 
               {
               	alert(http_request.responseText);
/*
                    var xmldoc = http_request.responseXML;
                    alert(xmldoc.getElementsByTagName('menue_name').length);
                    var root_node = xmldoc.getElementsByTagName('menue_name').item(1);
                    alert(root_node.firstChild.data);
*/
               } 
               else 
               {
            	   alert('Noch einmal, bitte.\nOnce again, please.\nOtra vez, por favor. ');
               }
          }
     
     }     
