function DoSearch( )
{
  q = document.getElementById( 'searchQ' ).value;

  if( q.length >= 3 || $('searchPriceMin').value != 0 || $('searchPriceMax').value != 0 )
    return true;
    //window.location='http://www.gifts4bizz.nl/zoeken/?q=' + q;
  else
  {
    document.getElementById( 'searchQ' ).style.borderColor = '#FC7770';
    return false;
  }
}

function Login( )
{
  u = document.getElementById( 'username' );
  p = document.getElementById( 'password' );

  if( u.value.length > 3 && p.value.length > 3 )
    return true;
  else
  {
    if( u.value.length <= 3 )
      u.style.borderColor = '#FC7770';
    else
      u.style.borderColor = '#e5e5e5';

    if( p.value.length <= 3 )
      p.style.borderColor = '#FC7770';
    else
      u.style.borderColor = '#e5e5e5';

    return false;
  }
}

// #############################################################
function isNumber( a ) {
    return typeof a == 'number' && isFinite( a );
}

function TickerClick( id, sum )
{
  i = document.getElementById( id );

  if( !isNumber( Number( i.value ) ) ) {
    i.value = 1;
    return false;
  }

  if( sum != 'min' ) {
    // plus
    i.value++;
  }
  else if ( Number( i.value ) > 1 )
  {
    // min
    i.value--;
  }

  return false;
}

// #############################################################
function ChangeModel( url )
{
  if( ( s = document.getElementById( 'modelSize' ) ) )
    sValue = s.value;
  else
    sValue = '';

  if( ( c = document.getElementById( 'modelColor' ) ) )
    cValue = c.value;
  else
    cValue = '';

  url = modelArray['_' + sValue  + cValue ];

  if( url == undefined ) {
    document.getElementById( 'modelMess' ).innerHTML = 'niet leverbaar';
    return false;
  }
  else
    document.getElementById( 'modelMess' ).innerHTML = '';

  //alert( '_' + ( Number( sValue ) ) + ( Number( cValue )  ) );
  //alert( url );
  window.location = url;
}

// IMAGE ZOOMER ################################################
var zoomObj = null
var blk   = null;
var imgW  = null;
var imgH  = null;
var zoomS = 12;

function showImage ( id )
{
  if( id == 'false' )
    return false;

  obj = $(id);//document.getElementById( id )
  zoomObj = obj;

  if( obj.getStyle('display') == 'none' )//style.display == 'none' )
  {
    obj.setStyle('display', 'block');//style.display = 'block';
    imgW = obj.getElement( 'img' ).getSize().size.x;
    imgH = obj.getElement( 'img' ).getSize().size.y;
//    img = obj.getElement( 'img' ).getSize().size;
    blk = obj.getElement( 'div' );

//    imgW = img.x;//img.offsetWidth;
//    imgH = img.y;//offsetHeight;

    ZoomImage( );//blk, imgW, imgH );

    // hide selectboxes for ie
    if( selects = $( 'contentMiddle' ).getElements( 'select' ) )
      for(var i = 0; i < selects.length; i++ ) { selects[ i ].style.display = 'none'; }

    //blk.style.width   = ( img.offsetWidth + 12 + 'px' );
    //blk.style.height  = ( img.offsetHeight + 45 + 'px' );
  }
  else
  {
    obj.setStyle('display', 'none');//style.display = 'none';

    // hide selectboxes for ie
    if( selects = $( 'contentMiddle' ).getElements( 'select' ) )
      for(var i = 0; i < selects.length; i++ ) { selects[ i ].style.display = 'block'; }

    blk = obj.getElement( 'div' );
    blk.style.width   = '100px';
    blk.style.height  = '100px';
    zoomObj           = null
    blk               = null;
    imgW              = null;
    imgH              = null;
  }

  return false;
}

function ZoomImage( )
{
  if( zoomObj == null )
    return;

  z = false;

  w = document.body.clientWidth;
  h = document.body.clientHeight;

  zoomObj.style.left  = Math.round( ( w / 2 ) - ( blk.offsetWidth / 2 ) ) + 'px';
  zoomObj.style.top   = Math.round( ( h / 2 ) - ( blk.offsetHeight / 2 ) ) + 'px';

  // width
  if( blk.offsetWidth - 12 < imgW ) {
    blk.style.width = blk.offsetWidth + zoomS + 'px';
    z = true;
  }

  // height
  if( blk.offsetHeight - 58 < imgH ) {
    blk.style.height = blk.offsetHeight + zoomS + 'px';
    z = true;
  }

  // continue
  if( z === true )
    setTimeout( ZoomImage, 25 );
}

// #############################################################
function changefootText ( t )
{
  document.getElementById ( 'footerImageInfo' ).innerHTML = t;
}

// AUTOCOMPLETER --------------------------------
window.addEvent( 'domready', function(){

  if( $chk( $('searchQ') ) )//true || $( 'myCheck' ).innerHTML == 1 && 
  {
  var searchInput = $('searchQ');

  var autoCompleteIndicator = new Element('div', {'class': 'autocompleter-loading', 'styles': {'display': 'none'}}).setHTML('&nbsp;').injectInside( searchInput.getParent() );

  var completer = new Autocompleter.Ajax.Json.g4b(
    searchInput,
    'http://www.relatie-geschenken.nl?a=11&action=ajax&e=autocomplete',
    {
      maxChoices:25,
      postVar: 'q',
      ajaxOptions: {
        method: 'get'
      },
      onRequest: function(el) {
        autoCompleteIndicator.setStyle('display', '');
      },
      onComplete: function(el) {
        autoCompleteIndicator.setStyle('display', 'none');
        /*items = $$( '.autocompleter-choices li' ).length;
        if( items > 20 )
        {
          completer.choices.setStyle( 'height', 300 );
          //completer.scroll();
        }
        else
        {
          completer.choices.setStyle( 'height', 'auto' );
        }*/
      }
    } );

  }
} );

function getRadio(name) {
	return $$('input[name='+name+']').filter(function(item) { return item.checked })[0].get('value');	
}

function submitShopCart( )
{
	var r = true;
	var showUpload = false;
	elms = $$( '.printButton' );

	elms.forEach( function( el ) {
		if( el.id.test('ja_') && el.checked )
		{
			$( 'printType_' + el.id.substr( 3 ) ).style [ 'backgroundColor' ] = '';
			$( 'imprintFile_' + el.id.substr( 3 ) ).style [ 'backgroundColor' ] = '';

			if ( $( 'printType_' + el.id.substr( 3 ) ).value == 1 )
				r = r;
			else if ( $( 'printType_' + el.id.substr( 3 ) ).value > 1 && $( 'imprintFile_' + el.id.substr( 3 ) ).value.length > 0 )
				showUpload = true;
			else
			{
				/*if ( $( 'printType_' + el.id.substr( 3 ) ).value == 0 )
					$( 'printType_' + el.id.substr( 3 ) ).style [ 'backgroundColor' ] = 'red';
					r = r; 
				else if ( $( 'printType_' + el.id.substr( 3 ) ).value > 1 && $( 'imprintFile_' + el.id.substr( 3 ) ).value.length == 0) {
					$( 'imprintFile_' + el.id.substr( 3 ) ).style [ 'backgroundColor' ] = 'red';
					r = r;
				}*/

				//r = false;

				r = r;
			}
		}
	} );

	if( r === true && showUpload )
	{
		block = $( 'formBlock' );

		$('contentMiddle2').getElements( 'select' ).setStyle('display','none');

		c = $('contentMiddle2').getCoordinates();
		block.setStyles( {
		  'height': c.height,
		  'width': c.width,
		  'top': c.top,
		  'left': c.left
		} );

		block.setStyle( 'display', 'block' );
	}

	return r;
}

function showPrintDetails( artID )
{
	elm = document.getElementById ( 'printDetails_' + artID );

	if (elm.style.display == 'none' )
	{
		if ( navigator.userAgent.indexOf ( 'MSIE' ) == -1 )
			elm.style.display = 'table-row-group';
		else
			elm.style.display = 'block';
	}
}

function hidePrintDetails( artID )
{
	elm = document.getElementById ( 'printDetails_' + artID );

	if (elm.style.display != 'none' )
	{
		elm.style.display = 'none';
	}
}

function showChooseImg( artID, value )
{
	if (value != 0 && value != 1)
	{
		if ( navigator.userAgent.indexOf ( 'MSIE' ) == -1 )
			document.getElementById ( 'printRow_' + artID ).style.display = 'table-row';
		else
			document.getElementById ( 'printRow_' + artID ).style.display = 'block';
	}
	else 
		document.getElementById ( 'printRow_' + artID ).style.display = 'none';
}
