function get_host()
{
    if( document.URL == null ) return '' ;
    str = document.URL.substring(7);
    if( str == null ) return '' ;
    i = str.indexOf( '/' ) ;
    if( i == -1 ) return '' ;
    host = str.substring( 0, i ) ;
    i = host.indexOf( '.' ) ;
    if( i == -1 ) return '' ;
    srv = host.substring( 0, i ) ;
    return srv  ;
}

function bopf()
{
    if( document.form1 != null )
    {
	document.form1.q.focus() ;
    }
}

function write_header()
{
    srv = get_host() ;

    if( srv == "megapixel" )
    {
	document.write( "<table width=100%><tr bgcolor=#000000><td><a href=http://www.megapixel.net/ target=_blank><img src=/IM/megapixel_cobrand_logo_162x40.gif border=0></a></td></tr><tr><td><img src=/x.gif></td></tr></table>" ) ;
	return ;
    }

    if( srv == "espacephoto" )
    {
	document.write( '<a href=/><img src=/IM/espacephoto_boursoprix.gif border=0></a>' ) ;
	return ;
    }

    if( srv == "yamafoto" )
    {
	document.write( '<a href=/><img src=/IM/yamaphoto.gif border=0></a>' ) ;
	return ;
    }


    if( srv == "nouvelobs" )
    {
	document.write( '<a href=/><img src=/IM/nouvelobslogo130.gif border=0></a>' ) ;
	return ;
    }

    if( srv == "fhm" )
    {
	document.write( '<img src=/IM/partner/logo_fhm.gif border=0>' ) ;
	return ;
    }

    if( srv == "autojournal" )
    {
	document.write( '<img src=/IM/partner/logo_autojournal.gif border=0>' ) ;
	return ;
    }

    if( srv == "addxonline" )
    {
	document.write( '<img src=/IM/partner/logo_addxonline.gif border=0>' ) ;
	return ;
    }

    if( srv == "francegolf" )
    {
	document.write( '<img src=/IM/partner/logo_francegolf.jpg border=0>' ) ;
	return ;
    }

    if( srv == "www" )
    {
	document.write( "<a href=/><img src=/IM/logo_bpx4.jpg border=0></a>" ) ;
	return ;
    }

    if( srv == "noheader" || srv == "partner"   )
    {
	return ;
    }

    document.write( "<a href=/><img src=/IM/logo_bpx4.jpg border=0></a>" ) ;
}
function write_pwdby()
{
}
function isEmailAddr2(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function isEmailAddr(checkThisEmail)
{
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}


// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

if (mySpaceAt != -1) 
 {myEMailIsValid = false}


return myEMailIsValid
}

function bgo( f )
{
    if( f.selectedIndex != -1 )
    {
	n = f.selectedIndex ;
	document.location.href= f.options[ n ].value ;
    }
}

function ow( url )
{
    window.open( url, "rd" , "location=yes,toolbar=yes,menubar=yes,status=no,scrollbars=yes,width=640,height=480,resizable=yes" ) ;
}

function ow2( name, url )
{
    window.open( url, name , "location=no,toolbar=no,menubar=no,status=no,scrollbars=yes,width=800,height=480,resizable=yes" ) ;
}

function crd( f, m, c, n, p, b, country )
{
    srv = get_host() ;
    if( srv == "megapixel" )
    {
	f = 'mpxl' ;
    }
    else
    {
	if( srv == "espacephoto" )
	{
	    f = 'espph' ;
	}
	else
	{
    	    if( srv == "yamaphoto" )
    	    {
    		f = 'yamaphoto' ;
    	    }
	    else
	    {
		f = 'bprx' ;
	    }
	}
    }
    //url = 'http://' + country + '.rd.boursoprix.com/out.php?f=' + f + '&r_m=' + m + '&r_c=' + c + '&r_n=' + n + '&r_p=' + p + '&r_b=' + b + '&country=' + country ;
    url = 'http://rd.boursoprix.com/out.php?f=' + f + '&r_m=' + m + '&r_c=' + c + '&r_n=' + n + '&r_p=' + p + '&r_b=' + b + '&country=' + country ;
    w = window.open( url, c + '_' + m , "location=yes,toolbar=yes,menubar=yes,status=no,scrollbars=yes,width=800,height=600,resizable=yes" ) ;
    if (w != null) {
    	w.focus() ;
    }

}


function rd( f, m, c, n, p, b )
{
    srv = get_host() ;
    if( srv == "megapixel" )
    {
	f = 'mpxl' ;
    }
    else
    {
	if( srv == "espacephoto" )
	{
	    f = 'espph' ;
	}
	else
	{
    	    if( srv == "yamaphoto" )
    	    {
    		f = 'yamaphoto' ;
    	    }
	    else
	    {
		f = 'bprx' ;
	    }
	}
    }
    url = 'http://rd.boursoprix.com/out.php?f=' + f + '&r_m=' + m + '&r_c=' + c + '&r_n=' + n + '&r_p=' + p + '&r_b=' + b ;
    w = window.open( url, c + '_' + m , "location=yes,toolbar=yes,menubar=yes,status=no,scrollbars=yes,width=800,height=600,resizable=yes" ) ;
    if (w != null) {
    	w.focus() ;
    }

}

function rd2( m, c, b, to )
{
    url = 'http://rd.boursoprix.com/out2.php?r_b=' + b + '&r_m=' + m + '&r_c=' + c + '&to=' + escape(to) ;
    w = window.open( url, c + '_' + m , "location=yes,toolbar=yes,menubar=yes,status=no,scrollbars=yes,width=800,height=600,resizable=yes" ) ;
    if (w != null) {
    	w.focus() ;
    }
}


function newsletter_open( email )
{
    if( isEmailAddr( email ) == false )
    {
	alert("Veuillez entrer une adresse email de la forme (exemple): votrenom@votredomain.com");
	return false ;
    }

    window.open( "/php/newsletter.php?action=add&email=" + email, "newsletter", "menubar=no,status=no,scrollbars=no,width=300,height=200" ) ;
    return false ;

}

function mysort( type )
{
    url = document.location.href ;
    i = url.indexOf( '_pricesort.html' ) ;

    if( i > -1 )
    {
        url = url.substr( 0, i ) ;
    }
    else
    {
        j = url.indexOf( '_alphasort.html' ) ;

        if( j > -1 )
        {
            url = url.substr( 0, j ) ;
        }
        else
        {
            i = url.indexOf( '.html' ) ;
            url = url.substr( 0, i ) ;
        }
    }

    if( type == 0 ) // sort is alpha
    {
        document.location.href = url + "_alphasort.html" ;
    }

    if( type == 1 ) // sort is alpha
    {
        document.location.href = url + "_pricesort.html" ;
    }

    if( type == 2 ) // sort is pop
    {
        document.location.href = url + ".html" ;
    }
}



