// Browser Detect Lite  v2.1.1
// http://www.dithered.com/javascript/browser_detect/index.html
// modified by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)
//var urlBase='http://pre-release.bookcrossing-spain.com';
var urlBase='http://www.bookcrossing-spain.com';
var browser = new BrowserDetectLite();


var replacementImage = new Image(4,4);
replacementImage.src = urlBase + '/images/clearpixel.gif';

var myHash=null;

var myButton = new Image(39,18);
myButton.src = urlBase +"/images/BuyBook-teal-39x18.gif";

var myButtonHilite = new Image(39,18);
myButtonHilite.src = urlBase +"/images/BuyBook-gold-39x18.gif";

var myButtonDown = new Image(39,18);
myButtonDown.src = urlBase +"/images/BuyBook-down-39x18.gif";
if (browser.isGecko){
  document.write('<link rel="StyleSheet" href="/css/css_ns4.css?date=2002-04-23b" type="text/css">');
}else{
  document.write('<link rel="StyleSheet" href="/css/css_ie.css?date=2003-04-23b" type="text/css">');
}
document.write('<link rel="StyleSheet" href="/css/css_ghaz.css" type="text/css">');
MM_preloadImages('../images/rombito.gif');
//---------------------//
function BrowserDetectLite() {
	var ua = navigator.userAgent.toLowerCase(); 

	// browser name
	this.isGecko     = (ua.indexOf('gecko') != -1);
	this.isMozilla   = (this.isGecko && ua.indexOf("gecko/") + 14 == ua.length);
	this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
	this.isIE        = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
	this.isOpera     = (ua.indexOf("opera") != -1); 
	this.isKonqueror = (ua.indexOf("konqueror") != -1); 
	this.isIcab      = (ua.indexOf("icab") != -1); 
	this.isAol       = (ua.indexOf("aol") != -1); 
	this.isWebtv     = (ua.indexOf("webtv") != -1); 
	
	// spoofing and compatible browsers
	this.isIECompatible = ( (ua.indexOf("msie") != -1) && !this.isIE);
	this.isNSCompatible = ( (ua.indexOf("mozilla") != -1) && !this.isNS && !this.isMozilla);
	
	// browser version
	this.versionMinor = parseFloat(navigator.appVersion); 
	
	// correct version number
	if (this.isNS && this.isGecko) {
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
	}
	else if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	else if (this.isOpera) {
		if (ua.indexOf('opera/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
		}
	}
	else if (this.isKonqueror) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
	}
	else if (this.isIcab) {
		if (ua.indexOf('icab/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
		}
	}
	else if (this.isWebtv) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('webtv/') + 6 ) );
	}
	
	this.versionMajor = parseInt(this.versionMinor); 
	this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
	
	// dom support
   this.isDOM1 = (document.getElementById);
	this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

	// platform
	this.isWin   = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1) );
	this.isMac   = (ua.indexOf('mac') != -1);
	this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('linux') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
	
	// specific browser shortcuts
	this.isNS4x = (this.isNS && this.versionMajor == 4);
	this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
	this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
	this.isNS4up = (this.isNS && this.versionMinor >= 4);
	this.isNS6x = (this.isNS && this.versionMajor == 6);
	this.isNS6up = (this.isNS && this.versionMajor >= 6);
	
	this.isIE4x = (this.isIE && this.versionMajor == 4);
	this.isIE4up = (this.isIE && this.versionMajor >= 4);
	this.isIE5x = (this.isIE && this.versionMajor == 5);
	this.isIE55 = (this.isIE && this.versionMinor == 5.5);
	this.isIE5up = (this.isIE && this.versionMajor >= 5);
	this.isIE6x = (this.isIE && this.versionMajor == 6);
	this.isIE6up = (this.isIE && this.versionMajor >= 6);
	
	this.isIE4xMac = (this.isIE4x && this.isMac);
}

function imageLoadError(myImage){
  myImage.src=replacementImage.src
  //myImage.src=myImage.src;
	return true;
}


function checkAllImages(){
	
	if(myHash!=null) self.location.hash=myHash;
	if(navigator.userAgent.indexOf("MSIE")>=0){
		for(i=0;i<document.images.length;i++){
			if(document.images[i].src.indexOf("amazon.com")>=0 &&
			   parseInt(document.images[i].height)<=30)
				document.images[i].src=replacementImage.src
		} 
	}
}

function checkImage(theImage){
  if(parseInt(theImage.width)<10 || theImage.width=="" || !theImage.width) theImage.src=replacementImage.src;
}

function preventSelection(){
	if (navigator.userAgent.indexOf('Win') >= 0 && 
		  navigator.userAgent.indexOf('MSIE') >= 0)
		document.selection.empty();
	return;
}

function checkEmail(myField)
{
    var newstr = "";
    var at = false;
    var dot = false;

    // DO SOME PRELIMINARY CHECKS ON THE DA

    // IF EMAIL ADDRESS HAS A '@' CHARACTER
    if (myField.value.indexOf("@") != -1) {
      at = true;

    // IF EMAIL ADDRESS HAS A '.' CHARACTER
    } else if (myField.value.indexOf(".") != -1) {
      dot = true;
    }
    // PARSE REMAINDER OF STRING
    for (var i = 0; i < myField.value.length; i++) {
        ch = myField.value.substring(i, i + 1);
        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
                || (ch == "@") || (ch == ".") || (ch == "_")
                || (ch == "-") || (ch >= "0" && ch <= "9")) {
                newstr += ch;
                if (ch == "@") {
                    at=true;
                }
                if (ch == ".") {
                    dot=true;
                }
        }
    }
    if (((at == true) && (dot == true))||myField.value=='') {
				myField.value=newstr;
        //return true;
    }else{
      // DISPLAY ERROR MESSAGE
			// skip the alert if they're not submitting the form yet. No need to annoy.
			alert('La dirección de email introducida no parece válida. Por favor, introducela de nuevo.');
			myField.focus();
			myField.select();
			return false;
    }
}

function myOver(myImage){
	myImage.src=myButtonHilite.src;
	return true;
}
	
function myOut(myImage){
	myImage.src=myButton.src;
	return true;
}

function myDown(myImage){
	myImage.src=myButtonDown.src;
	return true;
}


function noenter(){
	return !(window.event && window.event.keyCode == 13); 
}
function checkBCIDform(myForm,textoboton){
	if(myForm.bookprefix.value==""){
		alert("Tienes que introducir ambas partes del BCID.");
		myForm.sysSubmitButton.value=textoboton;	
    myForm.bookprefix.focus();
    return false;
	}
  if(myForm.bookid.value==""){
		alert("Tienes que introducir ambas partes del BCID.");
		myForm.sysSubmitButton.value=textoboton;	
    myForm.bookid.focus();
    return false;
	}

	//retrasoOcultarEstaVentana(3000);
	prepareWin(myForm);
	retrasoCambiarNombreBoton(myForm.sysSubmitButton,textoboton);
  return true;
}

function cambiarNombreBoton(nombreForm, nombreObjeto, valor){
  eval('this.window.document.' + nombreForm +'.'+ nombreObjeto + '.value="'+ valor +'";');
  }
function retrasoCambiarNombreBoton(objeto, valor){
  setTimeout('cambiarNombreBoton("' + objeto.form.name +'","'+ objeto.name +'","' + valor +'")', 5000);
}
function abrirVentana(direccion){
 ventana= window.open(direccion, 'popupFrame', 'toolbar=yes,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=550,top=0,left=0')
 ventana.focus()
}
function abrirVentanaChat(direccion){
 ventana= window.open(direccion, 'popupFrameChat', 'toolbar=yes,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=552,height=625,top=0,left=0')
 ventana.focus()
}

function prepareWin(myForm) {
 abrirVentana('about:blank');
  myForm.submit()
}

function checkLoginForm(myForm,textoboton){
  if(myForm.email.value==""){
		alert("Tienes que introducir el email.");
		myForm.submitlogin.value=textoboton;	
    myForm.email.focus();
    return false;
	}

	//retrasoOcultarEstaVentana(3000);
	prepareWin(myForm);
	retrasoCambiarNombreBoton(myForm.submitlogin,textoboton);
  return true;
}
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 writeHeaderColumnBox(parcolumna){
	var columna=1;
	if (parcolumna=='2') columna=2;
dwrite('<table width="100%" border=0 cellpadding=0 cellspacing=0 bgcolor=white>');
dwrite('<tr > ');
dwrite('<td background="../images/bordes/color0/caja' + columna +'arriba.jpg"><img src="../images/clearpixel.gif" align=middle width=14 height=14 border=0 alt=""></td>');
dwrite('</tr>');
dwrite('<tr> ');
dwrite('<td  background="../images/bordes/color0/fondolargo.jpg" class=boxleft> ');
dwrite('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
dwrite('<tr> ');
dwrite('<td width="14"><img src="../images/clearpixel.gif" align=middle width=14 height=14 border=0 alt=""></td>');
dwrite('<td>');
}

function writeFooterColumnBox(parcolumna){
	var columna=1;
	if (parcolumna=='2') columna=2;
dwrite('</td>');
dwrite('<td width="14"><img src="../images/clearpixel.gif" align=middle width=14 height=14 border=0 alt=""></td>');
dwrite('</tr>');
dwrite('</table></td>');
dwrite('</tr>');
dwrite('<tr> ');
dwrite('<td background="../images/bordes/color0/caja' + columna +'abajo.jpg"><img src="../images/clearpixel.gif" align=middle width=14 height=14 border=0 alt=""></td>');
dwrite('</tr>');
dwrite('</table>');
}


function dwrite(texto){
	document.write(texto);
}

