function $(elementId) {
    return document.getElementById(elementId);
}

mbuttons = new Object;
mbuttons.home = new Image; mbuttons.home.src = "/gfx/WGB_ENG_bt_home.jpg";
mbuttons.home1 = new Image; mbuttons.home1.src = "/gfx/WGB_ENG_bt_home1.jpg";
mbuttons.marine = new Image; mbuttons.marine.src = "/gfx/WGB_ENG_bt_marine.jpg";
mbuttons.marine1 = new Image; mbuttons.marine1.src = "/gfx/WGB_ENG_bt_marine1.jpg";
mbuttons.diving = new Image; mbuttons.diving.src = "/gfx/WGB_ENG_bt_diving.jpg";
mbuttons.diving1 = new Image; mbuttons.diving1.src = "/gfx/WGB_ENG_bt_diving1.jpg";
mbuttons.outdoor = new Image; mbuttons.outdoor.src = "/gfx/WGB_ENG_bt_outdoor.jpg";
mbuttons.outdoor1 = new Image; mbuttons.outdoor1.src = "/gfx/WGB_ENG_bt_outdoor1.jpg";
mbuttons.watches = new Image; mbuttons.watches.src = "/gfx/WGB_ENG_bt_watches.jpg";
mbuttons.watches1 = new Image; mbuttons.watches1.src = "/gfx/WGB_ENG_bt_watches1.jpg";
mbuttons.sunglasses = new Image; mbuttons.sunglasses.src = "/gfx/WGB_ENG_bt_sunglasses.jpg";
mbuttons.sunglasses1 = new Image; mbuttons.sunglasses1.src = "/gfx/WGB_ENG_bt_sunglasses1.jpg";
mbuttons.books = new Image; mbuttons.books.src = "/gfx/WGB_ENG_bt_books.jpg";
mbuttons.books1 = new Image; mbuttons.books1.src = "/gfx/WGB_ENG_bt_books1.jpg";
mbuttons.clothing = new Image; mbuttons.clothing.src = "/gfx/WGB_ENG_bt_clothing.jpg";
mbuttons.clothing1 = new Image; mbuttons.clothing1.src = "/gfx/WGB_ENG_bt_clothing1.jpg";
mbuttons.electronics = new Image; mbuttons.electronics.src = "/gfx/WGB_ENG_bt_electronics.jpg";
mbuttons.electronics1 = new Image; mbuttons.electronics1.src = "/gfx/WGB_ENG_bt_electronics1.jpg";
mbuttons.brands = new Image; mbuttons.brands.src = "/gfx/WGB_ENG_brands.jpg";
mbuttons.brands1 = new Image; mbuttons.brands1.src = "/gfx/WGB_ENG_brands1.jpg";

arrows = new Object;
arrows.left1 = new Image; arrows.left1.src = "/gfx/product/WGB_ENG_arrow_left1.jpg";
arrows.left2 = new Image; arrows.left2.src = "/gfx/product/WGB_ENG_arrow_left2.jpg";
arrows.right1 = new Image; arrows.right1.src = "/gfx/product/WGB_ENG_arrow_right1.jpg";
arrows.right2 = new Image; arrows.right2.src = "/gfx/product/WGB_ENG_arrow_right2.jpg";

function Hide(tohide) {
    $(tohide).style.display = "none";       
}

function Show(toshow) {
    $(toshow).style.display = "";        
}

function ToHideShow(tohide) {
    if ($(tohide).style.display == "") {
        $(tohide).style.display = "none";
    }
    else {
    	$(tohide).style.display = "";
    }
}

function HighlightMenuBar(tohighlight) {
	document.images[tohighlight + "btn"].src= mbuttons[tohighlight + "1"].src;
}

function GrayOutMenuBar(tograyout) {
	document.images[tograyout + "btn"].src= mbuttons[tograyout].src;
}

function showPic (whichpic, whichimg, picurl) {
 if ($) {
	$('placeholder').src = picurl + "tn.aspx?w=300&f=" + whichpic;
	$('linkholder').href = picurl + whichpic;
	$('linkholder1').href = picurl + whichpic;
	$('ithumb1').style.border="1px solid #000000";
	$('ithumb2').style.border="1px solid #000000";
	$('ithumb' + whichimg).style.border="2px solid #3F7F00";
	return false;
 } 
 else {
  return true;
 }
}

function MapPopup(url) {
	window.open('http://www.xsgb.com/images/ChartImages/' + url + '.jpg', 'map','0,0,0,0,0,scrollbars=yes,resizable=yes,width=580,height=425,top=5,left=5');
}

function disableDelivery () {
 var dswitch = $("CustomerDetails_deliverdiff");
 if ($("DeliveryHide").style.display=='block') {
 
    $("DeliveryHide").style.display='none';
    $("SubmitHide").style.display='block';
    
    $("CustomerDetails_Delivery_title1").value='';
    $("CustomerDetails_Delivery_forename").value='';
    $("CustomerDetails_Delivery_surname").value='';
    $("CustomerDetails_Delivery_address1").value='';
    $("CustomerDetails_Delivery_address2").value='';
    $("CustomerDetails_Delivery_town").value='';
    $("CustomerDetails_Delivery_county").value='';
    $("CustomerDetails_Delivery_postcode").value='';
    $("CustomerDetails_Delivery_country").value='';
    $("CustomerDetails_Delivery_telephone").value='';  
    $("CustomerDetails_Delivery_night_telephone").value='';

	return false;
 } 
 else {
 
    $("DeliveryHide").style.display='block';
    $("SubmitHide").style.display='none';
    
    if ($("CustomerDetails_Delivery_forename").value == "") {
        $("CustomerDetails_Delivery_title1").value = $("CustomerDetails_title1").value;
        $("CustomerDetails_Delivery_forename").value = $("CustomerDetails_forename").value;
        $("CustomerDetails_Delivery_surname").value = $("CustomerDetails_surname").value;
        $("CustomerDetails_Delivery_address1").value = $("CustomerDetails_address1").value;
        $("CustomerDetails_Delivery_address2").value = $("CustomerDetails_address2").value;
        $("CustomerDetails_Delivery_town").value = $("CustomerDetails_town").value;
        $("CustomerDetails_Delivery_county").value = $("CustomerDetails_county").value;
        $("CustomerDetails_Delivery_postcode").value = $("CustomerDetails_postcode").value;
        $("CustomerDetails_Delivery_country").value = $("CustomerDetails_country").value;
        $("CustomerDetails_Delivery_telephone").value = $("CustomerDetails_telephone").value;
        $("CustomerDetails_Delivery_night_telephone").value = $("CustomerDetails_night_telephone").value;
    }
  return true;
 }
}

function disableDeliveryNew() {
 var dswitch = $("deliverdiff");
 if (dswitch.checked==1) {
    
    $("Delivery_title").value             = $("title").value;
    $("Delivery_forename").value          = $("forename").value;
    $("Delivery_surname").value           = $("surname").value;
    $("Delivery_address1").value          = $("address1").value;
    $("Delivery_address2").value          = $("address2").value;
    $("Delivery_town").value              = $("town").value;
    $("Delivery_county").value            = $("county").value;
    $("Delivery_postcode").value          = $("postcode").value;
    $("Delivery_country").value           = $("country").value;
    $("Delivery_telephone").value         = $("telephone").value;
    $("Delivery_night_telephone").value   = $("night_telephone").value;
        
    $("Delivery_title").disabled          ='';
    $("Delivery_forename").disabled       ='';
    $("Delivery_surname").disabled        ='';
    $("Delivery_address1").disabled       ='';
    $("Delivery_address2").disabled       ='';
    $("Delivery_town").disabled           ='';
    $("Delivery_county").disabled         ='';
    $("Delivery_postcode").disabled       ='';
    $("Delivery_country").disabled        ='';
    $("Delivery_telephone").disabled      ='';  
    $("Delivery_night_telephone").disabled='';
    
    CalcValues('Delivery_country');

	return true;
 } 
 else {
 
    $("Delivery_title").value             = $("title").value;
    $("Delivery_forename").value          = $("forename").value;
    $("Delivery_surname").value           = $("surname").value;
    $("Delivery_address1").value          = $("address1").value;
    $("Delivery_address2").value          = $("address2").value;
    $("Delivery_town").value              = $("town").value;
    $("Delivery_county").value            = $("county").value;
    $("Delivery_postcode").value          = $("postcode").value;
    $("Delivery_country").value           = $("country").value;
    $("Delivery_telephone").value         = $("telephone").value;
    $("Delivery_night_telephone").value   = $("night_telephone").value;
    
    $("Delivery_title").disabled          ='disabled';
    $("Delivery_forename").disabled       ='disabled';
    $("Delivery_surname").disabled        ='disabled';
    $("Delivery_address1").disabled       ='disabled';
    $("Delivery_address2").disabled       ='disabled';
    $("Delivery_town").disabled           ='disabled';
    $("Delivery_county").disabled         ='disabled';
    $("Delivery_postcode").disabled       ='disabled';
    $("Delivery_country").disabled        ='disabled';
    $("Delivery_telephone").disabled      ='disabled';  
    $("Delivery_night_telephone").disabled='disabled';   
    
     CalcValues('country');
        
    return true;
 }
}

var upload_number = 2;
function addInput() {
 	var d = document.createElement("div");
 	var file = document.createElement("input");
 	file.setAttribute("type", "text");
 	file.setAttribute("size", "30");
 	file.setAttribute("maxlength", "255");
 	file.setAttribute("name", "attachment"+upload_number);
 	d.appendChild(file);
 	$("Attachments").appendChild(d);
 	
 	$("AttachmentsCount").value = upload_number;
 	upload_number++;
}

function goToURL(url) { 
    window.location = url; 
}
var g_PopupIFrame;
function IsIE(version) {
    return ((BrowserDetect.browser == "Explorer") && (BrowserDetect.version < version));
}
function IsAnyIE() {
    return (BrowserDetect.browser == "Explorer");
}
function showSubMenu(divId, imgId) {
    if(_currentOpenedComboDiv != null)
    {
        _currentOpenedComboDiv.style.visibility="hidden";
        _currentOpenedComboDiv = null;
     }

  var divElement = $(divId);
  var imgElement = $(imgId);
  var e = imgElement;
  var position = {x:0,y:0};
  var maxRight = 800;
  while (e)
  {
      position.x += e.offsetLeft;
      position.y += e.offsetTop;
      e = e.offsetParent;
  }
  
  if (document.body)
  {
    maxRight = document.body.clientWidth;
  }

  if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft))
  {
      position.x -= document.documentElement.scrollLeft;
      //position.y -= document.documentElement.scrollTop;
  }
  else if (document.body && (document.body.scrollTop || document.body.scrollLeft))
  {
      position.x -= document.body.scrollLeft;
      //position.y -= document.body.scrollTop;
  }
  else if (window.pageXOffset || window.pageYOffset)
  {
      position.x -= window.pageXOffset;
      //position.y -= window.pageYOffset;
  }
    
  if ((position.x + divElement.offsetWidth) > maxRight)
  {
    position.x = position.x - divElement.offsetWidth + imgElement.offsetWidth;
  }
  divElement.style.top =  position.y + imgElement.offsetHeight + 'px';
  divElement.style.left = position.x + 'px';
  divElement.style.display = "";

  if (IsIE(7))
  {
    //Increase default zIndex of div by 1, so that DIV appears before IFrame
    divElement.style.zIndex=divElement.style.zIndex+1;

    var iFrame = document.createElement("IFRAME");
    iFrame.setAttribute("src", "/Blank.htm");

    //Match IFrame position with divPopup
    iFrame.style.position="absolute";
    iFrame.style.left =divElement.offsetLeft + 'px';
    iFrame.style.top =divElement.offsetTop + 'px';
    iFrame.style.width =divElement.offsetWidth + 'px';
    iFrame.style.height =divElement.offsetHeight + 'px';

    document.body.appendChild(iFrame);

    //Store iFrame in global variable, so it can get removed when divPopup is hidden 
    g_PopupIFrame=iFrame;
  }
}

function showBrandMenu(divId, imgId)
{
    if(_currentOpenedComboDiv != null)
    {
        _currentOpenedComboDiv.style.visibility="hidden";
        _currentOpenedComboDiv = null;
     }

  var divElement = $(divId);
  var imgElement = $(imgId);
  var e = imgElement;
  var position = {x:0,y:0};
  var maxRight = 800;
  while (e)
  {
      position.x += e.offsetLeft;
      position.y += e.offsetTop;
      e = e.offsetParent;
  }
  
  if (document.body)
  {
    maxRight = document.body.clientWidth;
  }

  if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft))
  {
      position.x -= document.documentElement.scrollLeft;
      //position.y -= document.documentElement.scrollTop;
  }
  else if (document.body && (document.body.scrollTop || document.body.scrollLeft))
  {
      position.x -= document.body.scrollLeft;
      //position.y -= document.body.scrollTop;
  }
  else if (window.pageXOffset || window.pageYOffset)
  {
      position.x -= window.pageXOffset;
      //position.y -= window.pageYOffset;
  }
    
  divElement.style.top =  "0px";
  divElement.style.left = "0px";
  divElement.style.display = "";
  divElement.style.top =  position.y + imgElement.offsetHeight + 'px';
  divElement.style.left = position.x - divElement.offsetWidth + imgElement.offsetWidth + 'px';
  

  if (IsIE(7))
  {
    //Increase default zIndex of div by 1, so that DIV appears before IFrame
    divElement.style.zIndex=divElement.style.zIndex+1;

    var iFrame = document.createElement("IFRAME");
    iFrame.setAttribute("src", "/Blank.htm");

    //Match IFrame position with divPopup
    iFrame.style.position="absolute";
    iFrame.style.left =divElement.offsetLeft + 'px';
    iFrame.style.top =divElement.offsetTop + 'px';
    iFrame.style.width =divElement.offsetWidth + 'px';
    iFrame.style.height =divElement.offsetHeight + 'px';

    document.body.appendChild(iFrame);

    //Store iFrame in global variable, so it can get removed when divPopup is hidden 
    g_PopupIFrame=iFrame;
  }
}

function hideSubMenu(divId)
{
    $(divId).style.display = "none";
    if (IsIE(7))
    {
        document.body.removeChild(g_PopupIFrame);
        g_PopupIFrame=null;
    }
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();            


function AjaxFormatRequest(method,param)
{
    var _ajax = 'ajax_request=';
    _ajax += '<ajax><head><visirorid>';
    _ajax += Cookies['VisitorID'];
    _ajax += '</visirorid><visirotuid>';
    _ajax += Cookies['VisitorUID'];
    _ajax += '</visirotuid><version>';
    _ajax += Cookies['Version'];
    _ajax += '</version><method>';
    _ajax += method;
    _ajax += '</method></head><request>';
    _ajax += param;
    _ajax += '</request></ajax>';
    return _ajax;
}

function AjaxFormatResponse(XmlString,XmlProcessingFunction,HideProgressFunction)
{
    var xmlDoc;
    if (XmlString)
    {
        XmlString = XmlString.replace(/&/g,"&amp;");
    }
    try //Internet Explorer
    {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async="false";
      xmlDoc.loadXML(XmlString);
    }
    catch(e)
    {
      try //Firefox, Mozilla, Opera, etc.
      {
          parser=new DOMParser();
          xmlDoc=parser.parseFromString(XmlString,"text/xml");
      }
      catch(e)
      {
          alert(e.message);
          if (HideProgressFunction) HideProgressFunction();
          return;
      }
    }
    try
    {
        if (xmlDoc && xmlDoc.documentElement && (xmlDoc.documentElement.tagName == "ajax"))
        {
            // process success element from head
            var headNode = xmlDoc.getElementsByTagName("head")[0];
            if (headNode)
            {
                var successNode = headNode.getElementsByTagName("success")[0];
                if (successNode.firstChild.nodeValue == "1")
                {
                    // process response
                    var responseNode = xmlDoc.getElementsByTagName("response")[0];
                    if (XmlProcessingFunction) XmlProcessingFunction(responseNode, null);
                    if (HideProgressFunction) HideProgressFunction();
                }
                else
                {
                    // display error massages
                    var errorMessage = "";
                    var errorListNode = xmlDoc.getElementsByTagName("errorlist")[0];
                    if (errorListNode)
                    {
                        for (var i=0;i<errorListNode.childNodes.length;i++)
                        {
                            errorMessage += errorListNode.childNodes[i].firstChild.nodeValue;
                            errorMessage += "\r\n";
                        }
                        if (XmlProcessingFunction) 
                        {
                            XmlProcessingFunction(null, errorMessage);
                        }
                        else
                        {                        
                            alert(errorMessage);
                        }
                    }
                    else
                    {
                        if (XmlProcessingFunction) 
                        {
                            XmlProcessingFunction(null, "Error list is not defined.");
                        }
                        else
                        {                        
                            alert ("Error list is not defined.");
                        }                        
                    }
                    if (HideProgressFunction) HideProgressFunction();
                }            
            }
            else
            {
                if (HideProgressFunction) HideProgressFunction();
            }            
        }
        else
        {
            if (HideProgressFunction) HideProgressFunction();        
        }
    }
    catch (e)
    {
        alert(e.message);
        if (HideProgressFunction) HideProgressFunction();
    }
}

function AjaxDisplayError(errorMessage,functiontodisplayerror)
{
    if (errorMessage != null)
    {
        if(functiontodisplayerror)
        {
            functiontodisplayerror(errorMessage);
        }
        else
        {
            alert(errorMessage);
        }
        return true;
    }
    return false;
}

var Cookies = {
	init: function () {
		var allCookies = document.cookie.split('; ');
		for (var i=0;i<allCookies.length;i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create: function (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		this[name] = value;
	},
	erase: function (name) {
		this.create(name,'',-1);
		this[name] = undefined;
	}
};
Cookies.init();

function ajaxRequest(theURL, sendString, callbackFunction, displayProgressFunction, hideProgressFunction)
  {
  	var thisRequestObject;
  	
  	if (displayProgressFunction) displayProgressFunction();
  	
  	thisRequestObject = initiateRequest();
  	thisRequestObject.onreadystatechange = processRequest;
  	
  	function initiateRequest()
  	{
        if (typeof XMLHttpRequest != 'undefined') return new XMLHttpRequest();
        else if (window.ActiveXObject) {
            var avers = ["Microsoft.XMLHTTP", "Msxml2.XMLHTTP"]; // "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP.5.0"
            for (var i = avers.length -1; i >= 0; i--) {
                try {
                    obj = new ActiveXObject(avers[i]);
                    return obj;
                } catch(e) {}
            }
        }  	
        if (hideProgressFunction) hideProgressFunction();
        throw new Error('XMLHttp (AJAX) not supported');
  	}
  	
  	function processRequest()
  	{
  		if (thisRequestObject.readyState == 4)
  		{
  			if (thisRequestObject.status == 200)
  			{
  				if (callbackFunction)
  				{
  				    AjaxFormatResponse(thisRequestObject.responseText,callbackFunction,hideProgressFunction)
  			    }
  			}
  			else
  			{
  				//alert("There was an error: (" + thisRequestObject.status + ") " + thisRequestObject.statusText);
  				if (hideProgressFunction) hideProgressFunction();
  			}
  		}
  	}
  	
  	this.sendGetData = function()
  	{
  		if (theURL)
  		{
  			thisRequestObject.open("GET", theURL, true);
  			thisRequestObject.send(sendString);
  		}
  	}
  	
  	this.sendPostData = function()
  	{
  		if (theURL)
  		{
  			thisRequestObject.open("POST", theURL, true);
  			thisRequestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  			thisRequestObject.send(sendString);
  		}
  	}
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}

function lightup(imageobject, opacity){
    if ((BrowserDetect.browser == "Mozilla") ||(BrowserDetect.browser == "Firefox")
        || (BrowserDetect.browser == "Netscape"))
        imageobject.style.MozOpacity=opacity/100
    else if (BrowserDetect.browser == "Explorer")
        imageobject.filters.alpha.opacity=opacity
    else if ((BrowserDetect.browser == "Safari") || (BrowserDetect.browser == "Chrome") 
        || (BrowserDetect.browser == "Konqueror") || (BrowserDetect.browser == "Opera"))
        imageobject.style.opacity=opacity/100
}