
WEBAUDIT=function() {
    
  this.WACID=null;
  this.WACIDName="WACID";
  
  
  this.getCookie=function(name)  {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++)
    {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
  }
  
  this.setCookie=function(name,value,topDomain) {
    var date = new Date(2020,12,31,23,59,59);
    var expires = "; expires="+date.toGMTString();
    document.cookie = name+"="+value+expires+"; path=/; domain=" + topDomain;  
  }
  
  this.generateID=function(splitter) {
    var sp=(splitter) ? splitter : 'A';
    var now=new Date();
    return Date.parse(now.toGMTString()) + sp + Math.floor(Math.random()*1000000000);
  }
  
  this.getTopDomain=function(fullDomain) {
    var darabok=fullDomain.split('.');
    return darabok[(darabok.length-2)] + '.' + darabok[(darabok.length-1)];
  }
  
  this.getDomain=function(url) {
    var urlDarabok=url.split('/');
    return urlDarabok[2];
  }
  
  this.WACID=this.getCookie(this.WACIDName);
}

var same =  Math.floor(Math.random()*1000000);
var wa=new WEBAUDIT();
var felbontas = "";
var wa_url = "@u=";
var wa_referrer = "@r=";

if(wa.WACID==null)
{
  wa.WACID=wa.generateID('A');
  wa.setCookie(wa.WACIDName,wa.WACID,wa.getTopDomain(wa.getDomain(document.URL)));
}

same = same + "@c=" + wa.WACID;
if(screen) felbontas='@s='+screen.width+'x'+screen.height;
if(document.referrer) wa_referrer=wa_referrer+document.referrer;
if(document.URL) wa_url=wa_url+document.URL;
same = same + felbontas + wa_url + wa_referrer;
//-->


// -------------------------------------------------------------
function getElement( id, indoc ) {

  if ( undefined == indoc ) 
    indoc = document;

  obj = null;

  if ( indoc.getElementById ) {
    obj = indoc.getElementById( id );
  }
  else
    if ( indoc.all ) 
      obj = indoc[ id ];

  return obj;

}

// -------------------------------------------------------------
function hidebyid( id ) {

  if ( obj = getElement( id ) ) {

    obj.style.visibility = 'hidden';
    obj.style.display    = 'none';

  }

}

// -------------------------------------------------------------
function showbyid( id ) {

  if ( obj = getElement( id ) ) {

    obj.style.visibility = 'visible';
    obj.style.display    = 'block';

  }

}

// -------------------------------------------------------------
function replyform( id ) {

  if ( obj = getElement( 'commentform' + id ) ) {

    form = document.forms.input;
    html = form.innerHTML;
    html = html.replace( 'value="0"', 'value="' + id + '"' );
    html = html.replace( "hidebyid('commentform')", "hidebyid('commentform" + id + "')" );
    html = html.replace( "showbyid('commentlink')", "showbyid('commentlink" + id + "')" );

    obj.innerHTML = html;

  }

}

// -------------------------------------------------------------
function check_commentform( id, message ) {

  if ( id )
    form = document.forms[ 'input_' + id ];
  else
    form = document.forms.input;

  if ( form.message.value.length == 0 ) {
    alert( message );
    return false;
  }
  else
    return true;

}


// ----------------------------------------------------------------------------
function checkcheckboxes( message ) {

  form = document.getElementsByTagName('INPUT');
  found = 0;

  for ( i = 0; i < form.length; i++ ) {
    if ( form[ i ].name.substr( 0, 5 ) == 'media' ) {
        found = found || form[ i ].checked;
    }
  }

  if ( !found ) {
    alert( message );
    return false;
  }

  return true;

}

// ----------------------------------------------------------------------------
var star_imgs = new Array();
var star_count = 5;

function load_stars( star_path ) {

  star_names = new Array('star', 'star_half', 'star_light');

  for( i = 0; i < 3; i++ ) {
    star_imgs[i] = new Image();
    star_imgs[i].src = star_path + star_names[i] + '.gif';
  }

}

function init_stars( star_val ) {

  getElement('ratingtitle').innerHTML = '<b>' + rat_title + '</b>';

  l = Math.floor(star_val);
  h = Math.ceil(star_val);

  for( i = 1 ; i <= star_count; i++ ) {

    if ( i <= l )
      s = 0;
    else
      s = 2;

    document.images['star_' + i].src = star_imgs[ s ].src;
                                                    
  }

  if ( star_val != l ) {
    document.images['star_' + l].src = star_imgs[1].src;
  }

}

function over_stars(val, title) {

  for( i = 1; i <= star_count; i++ ) {
    s = (i <= val ? 0 : 2);
    document.images['star_' + i].src = star_imgs[ s ].src;
  }

  document.getElementById('ratingtitle').innerHTML = '<b>' + title + '</b>';

}

function send_stars( val ) {

  document.forms['stars_form'].rating.value = val;
  ajax_do( document.forms['stars_form'].ajaxurl.value + "&rating=" + val );

}

// -------------------------------------------------------------
function image_previous() {

  if ( imagecount > 1 ) {

    thumbnailborder( 0 );
    imagecount--; 
    thumbnailborder( 1 );
    updatecounter();
    mediumsize.document.location.href = galleryimagesmedium[ imagecount ];

  }

}

// -------------------------------------------------------------
function thumbnailborder( border ) {

  if ( border )
    window.top.thumbnails.document.images[ 't'+galleryimages[ imagecount ] ].style.border = '2px solid black';
  else
    window.top.thumbnails.document.images[ 't'+galleryimages[ imagecount ] ].style.border = '2px solid white';

}

// -------------------------------------------------------------
function image_next() {

  if ( imagecount < allimages ) {
    
    thumbnailborder( 0 );
    imagecount++;
    thumbnailborder( 1 );
    updatecounter();
    
    mediumsize.document.location.href = galleryimagesmedium[ imagecount ];

    if ( obj = getElement( 'slideshow' ) ) {
      slideshow( obj.value );
    }

  } 
  else {
    
    if ( obj = getElement( 'slideshow' ) ) {

      if ( obj.value > 0 ) {
        obj.value = 0;
        thumbnailborder( 0 );
        imagecount = 1;
        thumbnailborder( 1 );
        updatecounter();
        mediumsize.document.location.href = galleryimagesmedium[ imagecount ];
      }

      slideshow( 0 );

    }

  }

} 

// -------------------------------------------------------------
function updatecounter() {

  if ( obj = getElement( 'counter' ) ) {
    obj.innerHTML = imagecount + '/' + allimages;
  }

}

// -------------------------------------------------------------
function slideshow( timeout ) {

  if ( obj = getElement( 'slideshow' ) )
    obj.value = timeout;

  if ( timeout > 0 ) {

    if (
         ( play = getElement( 'slideshowstart' ) ) &&
         ( stop = getElement( 'slideshowstop' ) )
       ) {
      play.style.visibility = 'hidden';
      play.style.display    = 'none';
      stop.style.visibility = 'visible';
      stop.style.display    = 'block';
    }
    timerID = setTimeout( 'image_next()', timeout * 1000 );

  }
  else {

    if (
         ( play = getElement( 'slideshowstart' ) ) &&
         ( stop = getElement( 'slideshowstop' ) )
       ) {
      play.style.visibility = 'visible'; 
      play.style.display    = 'block';   
      stop.style.visibility = 'hidden';  
      stop.style.display    = 'none';    
    }

    if ( timerID ) {
      clearTimeout( timerID );
      timerID = 0;
    }

    if ( forward.length ) 
      location.href = forward;

  }

}

// -------------------------------------------------------------
function resizewindowtoimage( id ) {
var x,y;

  if ( 
       ( undefined != document.images[id] ) &&
       document.images[id].complete
     ) {
    
    if (self.innerHeight) // all except Explorer
    {
    	x = self.innerWidth;
    	y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    	// Explorer 6 Strict Mode
    {
    	x = document.documentElement.clientWidth;
    	y = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
    	x = document.body.clientWidth;
    	y = document.body.clientHeight;
    }
    
    img      = document.images[ id ];
    newxsize = img.width  + 30;
    newysize = img.height + 50;
    
    overflow = 'hidden';
    switch( true ) {
      case ( newxsize > screen.width  ): 
        newxsize = screen.width;
        overflow = 'auto';
      break;
      case ( newysize > screen.height ):
        newysize = screen.height;
        overflow = 'auto';
      break;
    }
    
    try { document.getElementById('body')[0].style.overflow = overflow; } catch(e) {}
    
    if ( 1 || ( x < img.width ) || ( y < img.height ) ) {
      
      try {
        
        // ie throws security errors sometimes, since xpsp2
        
        window.resizeTo( newxsize, newysize );
        topPos   = Math.round( ( screen.height - newysize ) / 2 );
        leftPos  = Math.round( ( screen.width  - newxsize ) / 2 );
        
        window.moveTo( leftPos, topPos );
        return;
        
      }
      catch ( e ) {}
      
    }
    
  }
  
  window.setTimeout( "resizewindowtoimage('" + id + "')", 100 );
  
}

// -------------------------------------------------------------
function openwindow( url, x, y ) {

  topPos  = ( screen.height - y ) / 2;
  leftPos = ( screen.width - x ) / 2;

  window.open( url,'',
    'toolbars=no,menubar=no,scrollbars=yes,resizable=yes,' +
    'top=' + topPos + ','+
    'left=' + leftPos + ','+
    'width=' + x + ','+
    'height=' + y
  ); 

}

// -------------------------------------------------------------
function fillscreen() {

  window.moveTo( 0, 0 );
  window.resizeTo( screen.availWidth, screen.availHeight );

}

// -------------------------------------------------------------
function updatemediainfo( type, start, count, outof, all, items ) {

  if ( obj = parent.document.getElementById( type + 'info' ) ) {
    obj.innerHTML = start + ' - ' + ( start + count - 1 ) + ' ' + outof + ' ' + all + ' ' + items;
  }

  if ( obj = parent.document.getElementById( type + 'all' ) ) {
    obj.innerHTML = '(' + all + ')';
  }

}

// -------------------------------------------------------------
function updatecaption( string ) {

  if ( obj = parent.document.getElementById( 'caption' ) ) {
    obj.innerHTML = string;
  }

}

// -------------------------------------------------------------
function changeuploadcontrol() {

  if ( ( hideit = getElement( 'uploadcontrol' ) ) &&
       ( showit = getElement( 'uploadstatusbar' ) )
     ) {
    hideit.style.visibility = 'hidden';
    hideit.style.display    = 'none';
    showit.style.visibility = 'visible';
    showit.style.display    = 'inline';
  }

}

// -------------------------------------------------------------
function ajax_do( url ) {

  if ( document.createElement ) {

    // Create new JS element
    var jsel  = document.createElement( 'SCRIPT' );
    jsel.type = 'text/javascript';
    jsel.src  = url;

    // Append JS element (therefore executing the 'AJAX' call)
    document.body.appendChild( jsel );

  }

}
