function validateemail( address )
{
    window.status = address.value;
    var reg = /^[a-zA-Z0-9#&\\+\\.\\_\\-]+@[a-zA-Z0-9\\.\\_\\-]+\.[a-zA-Z0-9\\.\\_\\-]+$/;
    if ( reg.test( address.value ) )
        return true;
    else
    {
        alert( "\"" + address.value + "\" does not appear to be a valid email address." );
        address.focus();
        address.select();
        return false;
    }
}

function OpenCertDetails() {
    thewindow = window.open('https://www.thawte.com/cgi/server/certdetails.exe?code=UKHARD3-3', 'anew', config='height=400,width=525,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes');
}

function hideSelects(){
	var oSelects=document.getElementsByTagName("select");
	for(var i=0;i<oSelects.length;i++)
		oSelects[i].className+=" hide";
}
function showSelects(){
	var oSelects=document.getElementsByTagName("select");
	for(var i=0;i<oSelects.length;i++)
		oSelects[i].className=oSelects[i].className.replace(" hide","");
}


Gallery = function(config) {

    this.config = config;
    this.index = 0;

    this.setMediaType(this.config.initial);
    this.setShowingAlt(false);
    
    this.setupImages();
}

Gallery.prototype.setupImages = function() {
    //load images
    if (this.hasImages()) {
        for (var i=0; i<this.config.images.length; i++) {
            //there may not be any thumbs
            if (this.config.images[i].thumb != null) {
                var image = new Image();
                image.src = this.config.images[i].thumb;    
                this.config.images[i].thumbImage = image;
            }
            //pre load full images
            if (this.config.images[i].full != null) {
                var image = new Image();
                image.src = this.config.images[i].full;                
                this.config.images[i].fullImage = image;                
            }
        }    
    }
}

Gallery.prototype.image = function(idx) {
    if (!this.isShowingImage()) {
        this.swapMedia();
    }
    this._showImage(idx, Gallery.FX_FADE);
}

Gallery.prototype.hasImages = function() {
    return this.config.images != null && this.config.images.length > 0;
}

Gallery.prototype.isShowingImage = function() {
    return (this.mediaType == Gallery.TYPE_IMAGE);
}

Gallery.prototype.setMediaType = function(type) {
    this.mediaType = type;
}

Gallery.prototype._showImage = function(idx, fx) {
    if (idx == this.index) {
        return;
    }
        
    if (!this.hasImages()) {
        return;
    }
    
    var oldIndex = this.index;
         
    if (idx >= this.config.images.length) {
        idx = 0;
    } else if (idx < 0) {
        idx = this.config.images.length - 1;
    }
    
    this.changeThumbImageState(Gallery.TYPE_IMAGE, this.index, idx);     

    this.getActiveImage().src = this.config.images[idx].fullImage.src;
    
    this.index = idx;    
}

Gallery.prototype.getActiveImage = function() {
    if (this.isShowingAlt()) {
        return this.getAltFullImage();
    } else {
        return this.getFullImage();
    }
}

Gallery.prototype.isShowingAlt = function() {
    return this.showingAlt;
}

Gallery.prototype.setShowingAlt = function(val) {
    return this.showingAlt = val;
}

Gallery.prototype.changeThumbImageState = function(type, prevIndex, nextIndex) {
    var prevImg = this.getThumbAnchor(type, prevIndex);
    var nextImg = this.getThumbAnchor(type, nextIndex);  

    if (prevImg != null) {  
        prevImg.className = this.config.image.thumb.cssClass;
    }
    if (nextImg) {
        nextImg.className = this.config.image.thumb.cssActiveClass;
    }
}

Gallery.prototype.getFullImage = function() {
    return document.getElementById(this.config.image.full.elementId);
}

Gallery.prototype.getViewer = function() {
    return document.getElementById(this.config.viewer.elementId);
}

Gallery.prototype.getThumbAnchorId = function(type, index) {
    var id = null;
    if (type == Gallery.TYPE_IMAGE) {
        id = this.config.image.thumb.elementId + index;
    } else {
        id = this.config.movie.thumb.elementId + index;
    }
    return id;
}

Gallery.prototype.getThumbAnchor = function(type, index) {
    return document.getElementById(this.getThumbAnchorId(type, index));
}

function addBasket(catno)
{
    this.catno = catno;
    var ajaxRequest;  // The variable that makes Ajax possible!

    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            var ajaxDisplay = document.getElementById('ajaxDiv');
            ajaxDisplay.innerHTML = ajaxRequest.responseText;
        }
    }

    queryString = "?catno=" + this.catno

    ajaxRequest.open("GET", "/basket/ajax.php" + queryString, true);
    ajaxRequest.send(null); 
}