// ********************************************************
// JavaScript Library
// [lib.js]
//
// created: 24.04.2002 23:50
// changed: 30.12.2002 21:19
// 
// @business media agency
// http://www.atbusiness.de
// lk@atbusiness.de
// ********************************************************	

//
// function to add entries from a one listbox to the other
// formname is the name of the form where the two list boxes are located
// all_values is the name of the list box which stores all possible values for selection
// selected _values is the name of the list box where all entries are stored which have had selected 
// 


function add( formname, all_values, selected_values ) {
  	var feld;
  	check=0;

   for ( j = 0; j < document.forms[ formname ].elements[ all_values ].length; j++ )
   {
   	// alert( all_values );
  		// alert( document.forms[ formname ].elements[ all_values ].length );
   	check=0;            // zum überprüfen der Einträge in der Liste
      if ( document.forms[ formname ].elements[ all_values ].options[j].selected == true ) 
      {
       	caption = document.forms[ formname ].elements[ all_values ].options[j].text;       	
       	value   = document.forms[ formname ].elements[ all_values ].options[j].value;
       	
        	for( i = 0; i < document.forms[ formname ].elements[ selected_values ].length; i++ )
        	{
          	if ( caption == document.forms[ formname ].elements[ selected_values ].options[i].text )     
          	{
            	check = 1;
          	}
        	}
        	if ( check != 1 )
        	{	 
          	neuer_eintrag = new Option( caption, value, false, false );
          	document.forms[ formname ].elements[ selected_values ].options[document.forms[ formname ].elements[ selected_values ].length] = neuer_eintrag;
        	}  
      }
  	}
} 

function addWithText( formname, all_values, selected_values, textFiel  )
{
  	var feld;
  	check=0;

	text2Add = document.forms[ formname ].elements[ textFiel ].value;
   for ( j = 0; j < document.forms[ formname ].elements[ all_values ].length; j++ )
   {
   	// alert( all_values );
  		// alert( document.forms[ formname ].elements[ all_values ].length );
   	check=0;            // zum überprüfen der Einträge in der Liste
      if ( document.forms[ formname ].elements[ all_values ].options[j].selected == true ) 
      {
       	feld = document.forms[ formname ].elements[ all_values ].options[j].text
        	for( i = 0; i < document.forms[ formname ].elements[ selected_values ].length; i++ )
        	{
        		optionvalue = document.forms[ formname ].elements[ selected_values ].options[i].text;
        		optionvalue = optionvalue.substr( 0, optionvalue.indexOf( "[" ) - 1 );
          	if ( feld == optionvalue )     
          	{
            	check = 1;
          	}
        	}
        	if ( check != 1 )
        	{	 
          	neuer_eintrag = new Option( feld + ' [' + text2Add + ']' );
          	document.forms[ formname ].elements[ selected_values ].options[document.forms[ formname ].elements[ selected_values ].length] = neuer_eintrag;
        	}  
      }
  	}
} 
  
  
// 	
// function to remove entries from the selected list box of a form
// formname is the name of the form where the two list boxes are located
// selected _values is the name of the list box where all entries are stored which have had selected and now has to be deleted
//
function del( formname, selected_values )
{ 
  	for ( k = document.forms[ formname ].elements[ selected_values ].length-1; k >= 0; k-- )
  	{
    	if ( document.forms[ formname ].elements[ selected_values ].options[k].selected == true )
    	{
       	document.forms[ formname ].elements[ selected_values ].options[k] = null;
    	}
  	}
} 

function mark_all( formname, selected_values )
{
   for ( k = document.forms[ formname ].elements[ selected_values ].length-1; k >= 0; k-- )
   {
      document.forms[ formname ].elements[ selected_values ].options[k].selected = true;
   }
}

function checkPOTWForm() {

	check = 0;
	
	
	if ( document.potw.housing.options[0].selected	== true ) {
		check = 1;
		field = "housing";
	}
	
	if ( document.potw.camera.options[0].selected == true ) {
		check = 1;
		field = "camera";
	}
	
	if ( document.potw.location_country.options[0].selected == true ) {
		check = 1;
		field = "photo country";
	}

	if ( document.potw.location_area.value 	== "" ) {
		check = 1;
		field = "area / location";
	}
	
	if ( document.potw.site_waters.value 	== "" ) {
		check = 1;
		field = "dive site's ocean / sea";
	}	
	
	if ( document.potw.site_name.value 	== "" ) {
		check = 1;
		field = "dive site's name";
	}
		
	if ( document.potw.comment.value 	== "" ) {
		check = 1;
		field = "photographer's comment";
	}
	     				
	if ( document.potw.photographer_homepage.value == "http://" && document.potw.homepage_flag[1].checked == true ) {
		check = 1;
		field = "photographer's homepage";
	}
	
     if ( document.potw.homepage_flag[0].checked == false && document.potw.homepage_flag[1].checked == false ) {
          check = 1;
		field = "photographer's homepage";
     }
     	
	if ( document.potw.photographer_email.value 	== "" ) {
		check = 1;
		field = "photographer's email";
	}
		
	if ( document.potw.photographer_country.options[0].selected == true ) {
		check = 1;
		field = "photographer's home country";
	}
		
	if ( document.potw.photographer.value 	== "" ) {
		check = 1;
		field = "photographer's name";
	}

	if ( document.potw.image.value == "" ) {
		check = 1;
		field = "image path"	
	}
	
	if ( document.potw.title.value == "" ) {
		check = 1;
		field = "image title"	
	}
	
	if ( check != 1 ) {
		window.scrollTo(0,0);
         MM_showHideLayers('transmitting','','show');
		return true;
	} else {
		alert ( "Please fill out the field: " + field );
		return false;	
	}
}

function checkRequestForm() {
   check = 0;
   if ( document.register.country.options[0].selected == true ) {	   
		check = 1;
		field = "country";
	}
	
	if ( check != 1 ) {
		return true;
	} else {
		alert ( "Please fill out the field: " + field );
		return false;	
	}
}  

function SectionsToogle( instanceName, openSection ) {    
    this._instanceName = instanceName;

    this.getThis = function()
    {
        return this;
    }

    this.toggle = function( sectionId )
    {
        // ====================================================================
        //  Get the currently open section object. 
        // ====================================================================
        openSectionId = this._getCookie( this._instanceName + '_open' );
        if (document.getElementById('_' + this._instanceName + '_' + openSectionId)) {
            document.getElementById('_' + this._instanceName + '_' + openSectionId).style.display = 'none';
            document.getElementById('_' + this._instanceName + '_' + 'tab_' + openSectionId).className = 'tab_foto';
            document.getElementById('_' + this._instanceName + '_' + 'tabLink_' + openSectionId).className = 'tab_foto';
        }

        // ====================================================================
        // Get the newly opened section object. 
        // ====================================================================
        if (document.getElementById('_' + this._instanceName + '_' + sectionId)) {
            document.getElementById('_' + this._instanceName + '_' + sectionId).style.display = 'block';
            document.getElementById('_' + this._instanceName + '_' + 'tab_' + sectionId).className = 'tab_foto_over';
            document.getElementById('_' + this._instanceName + '_' + 'tabLink_' + sectionId).className = 'tab_foto_over';
        }

        // ====================================================================
        // store the newly opened section object name to cookies. 
        // ====================================================================
        this._setCookie( this._instanceName + '_open', sectionId );
    }

    this._getCookie = function(name)
    {
        var dc = document.cookie;
        var prefix = name + '=';
        var begin = dc.indexOf('; ' + prefix);
        if (begin == -1) {
            begin = dc.indexOf(prefix);
            if (begin != 0) {
                return '';
            }
        } else {
            begin += 2;
        }
        var end = document.cookie.indexOf(";", begin);
        if (end == -1) {
            end = dc.length;
        }
        return unescape(dc.substring(begin + prefix.length, end));
    }

    this._setCookie = function(name, value)
    {
        var curCookie = name + '=' + escape(value);
        curCookie = curCookie + ';DOMAIN=www.digideep.com;PATH=/;';
        document.cookie = curCookie;
    }

    this._setCookie( this._instanceName + '_open', openSection );    
}

//
// DREAMWEAVER FUNCTIONS //
//   
function MM_openBrWindow(theURL,winName,features) { //v2.0
   window.open(theURL,winName,features);
}

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.0
   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 && document.getElementById) x=document.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 MM_reloadPage(init) {  //reloads the window if Nav4 resized
   if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
      document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
   else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
