var crappyBrowser = navigator.appName.indexOf("Microsoft")>=0;if (crappyBrowser)    document.execCommand("BackgroundImageCache",false,true);var init=null;var onScrolled=null;var onResized=null;var ims=null;var tempTime;var ajaxReqTime;var nlVisible=false;var pageLogin=null,    pageLogout=null;var imageCache = new Array(9);var imageURLs = new Array("basket1.png","basket2.png","basket3.png",                            "help1.png","help2.png","help3.png",                            "contact1.png","contact2.png","contact3.png"                          );for (var i=0; i<imageCache.length; ++i){    imageCache[i] = new Image();    imageCache[i].src="images/"+imageURLs[i];}var loginVisible=false,    contactVisible=false,    countryShow=false,    countryHide=false;function setCurrency(c){    var url = location.href;    if (url.indexOf("?")>=0){          if (url.indexOf("currency=")>=0)             url=url.substring(0,url.indexOf("currency="));        else            url += "&";    }else        url += "?";    url += "currency="+escape(c);    location.href=url;}function setCombo(id, val){//debugLog("set ="+id+" to "+val);    try{        var e = xGetElementById(id).options;        for(var i=0; i<e.length; ++i){            if (id="rightSphere")                debug("check ["+e[i].value+"]");            if (e[i].value==val)                e[i].selected=true;        }    }catch(oops){        debugLog("x="+oops);    }}function setText(id, val){    try{        xGetElementById(id).value=val;    }catch(oops){}}function debugLog(s){    xGetElementById("debugStuff").innerHTML += (s+"<br />");}function showCountries(){    xSlideTo("countryL",-210,0,200);    xSlideToR("countryR",-210,0,200);    xShow("chooseCurrency");}function hideCountries(){    xShow("countryL");    xShow("countryR");    xSlideTo("countryL",-82,0,200);    xSlideToR("countryR",-82,0,200);    xHide("chooseCurrency");}function hiRow(evt){    var e = new xEvent(evt);    var t = e.target;    if (t.tagName == "A")        t = t.parentNode;    t.childNodes[0].style.color="#0000F0";    t.style.backgroundColor="WHITE";}function normRow(evt){    var e = new xEvent(evt);    var t = e.target;    if (t.tagName == "A")        t = t.parentNode;    t.childNodes[0].style.color="WHITE";    t.style.backgroundColor="";}function pageInit(){        if (readCookie("emailAddress") != null)        document.getElementById("loginEmail").value=readCookie("emailAddress");    pageResized();    if (init)        init();    window.setInterval("checkForMessages();",15000);//    if (readCookie("newsLetter")==null && location.href.indexOf("specsonthenet.com")>=0)//        toggleNewsLetter();}function isChildOf(child,parent){    var kid=xGetElementById(child);    var kids = xGetElementById(parent).childNodes;    for(var i=0; i<kids.length; ++i)        if (kids[i]==kid)            return true;    return false;}function pageScrolled(){/*    if (xGetElementById("feedbackPanel").style.visibility=="visible"){        feedback();    }*/        if (onScrolled)        onScrolled();}function pageResized(){    var cHeight = xHeight("mainContent");    var lHeight = xHeight("leftContent");    var rHeight = xHeight("rightContent");    var maxHeight = Math.max(cHeight, lHeight, rHeight); if (xGetElementById("subBarPara"))    xGetElementById("subBarPara").innerHTML = "lh="+lHeight+", mh="+cHeight+", rh="+rHeight+", ch="+bodyHeight;    xHeight("mainColumn", maxHeight);    xHeight("leftColumn", maxHeight);    xHeight("rightColumn", maxHeight);        var bodyHeight = xHeight("container");    xHeight("leftBorder",bodyHeight);    xHeight("rightBorder",bodyHeight);        xLeft("countryMask", xPageX("countryMenu"));  // (xPageX("countryMenu")+237)-242-60);    xShow("footer");    if (xWidth("header")<1000){        var fl = xGetElementById("freeLenses");        if (isChildOf("freeLenses","header")){            xGetElementById("header").removeChild(fl);            xGetElementById("leftContent").insertBefore(fl, xGetElementById("sideP1"));            xMoveTo("freeLenses",20,350);            xResizeTo("animatedPanel",360,157);            xGetElementById("animatedPanel").src="images/panel1e.png";//         xMarginRight("eliminateGuesswork",380);        }    }else{        var fl = xGetElementById("freeLenses");        if (isChildOf("freeLenses","leftContent")){            xGetElementById("leftContent").removeChild(fl);            xGetElementById("header").appendChild(fl);            xMoveTo("freeLenses",210,-20);            xResizeTo("animatedPanel",424,170);            xGetElementById("animatedPanel").src="images/panel2_424.png";//         xMarginRight("eliminateGuesswork",444);        }    }    if (onResized)        onResized();}function feedback(){    document.getElementById("feedbackButtonDiv").innerHTML="<input type=\"button\" onclick=\"leaveFeedback();\" value=\"Send Feedback\" />";    if (!crappyBrowser){        showGreyPanel();        showCentered("feedbackPanel", true);    }else{        showCentered("feedbackPanel");    }}function showGreyPanel(){    xResizeTo("greyPanel", xClientWidth(), xClientHeight());    if (crappyBrowser)        xMove("greyPanel", xScrollLeft(), xScrollTop());    xShow("greyPanel");}function hideGreyPanel(){    xHide("greyPanel");}function changeOpacity(opacity){    var object = document.getElementById("fadeImage").style;    object.opacity = (opacity / 100);    object.MozOpacity = (opacity / 100);    object.KhtmlOpacity = (opacity / 100);    object.filter = "alpha(opacity=" + opacity + ")";//	object.visibility="visible";	if (opacity==100){		document.getElementById("stepImage").src=document.getElementById("fadeImage").src;//		document.getElementById("fadeImage").style.visibility="hidden";	}else if (opacity==102){		object.opacity = 0;        object.MozOpacity = 0;        object.KhtmlOpacity = 0;        object.filter = "alpha(opacity=0)";        return;	}    opacityTimer = setTimeout("changeOpacity("+(opacity+2)+")",opacityTimerMS);}function createCookie(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=/";}function eraseCookie(name){    createCookie(name,"",-1);}function readCookie(name) {	var nameEQ = name + "=";	var ca = document.cookie.split(';');	for(var i=0;i < ca.length;i++) {		var c = ca[i];		while (c.charAt(0)==' ') c = c.substring(1,c.length);		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);	}	return null;}function login(){    if (document.getElementById("rememberMe").checked)        createCookie("emailAddress",document.getElementById("loginEmail"),365);    xGetElementById("loginButtonP").style.display="none";    xGetElementById("loginProcessingP").style.display="block";    makeRequest("http://www.specsonthenet.co.uk/servlet/ProcessCustomer",                "loginEmail="+escape(document.getElementById("loginEmail").value)                +"&loginPassword="+escape(document.getElementById("loginPassword").value)                , loginResult);}function toggleNewsLetter(){	if (!nlVisible){		opacity("newsLetter", 0, 100, 300);                xGetElementById("nlProcessingP").style.display="none";        xGetElementById("nlSuccess").style.display="none";        xGetElementById("nlButtonP").style.display="block";        nlVisible=true;        if (readCookie("newsLetter") == null)            createCookie("newsLetter","off",1);        if (document.getElementById("nlEmail"))                        document.getElementById("nlEmail").focus();	}else{		opacity("newsLetter", 100, 0, 300);		nlVisible=false;	}}function signupNewsLetter(){        xGetElementById("nlButtonP").style.display="none";    xGetElementById("nlProcessingP").style.display="block";    makeRequest("http://www.specsonthenet.co.uk/servlet/ProcessCustomer",                "newsSignup="+escape(document.getElementById("nlEmail").value),                 signupResult);}function signupResult(httpRequest){    if (httpRequest.readyState == 4){//alert(httpRequest.responseText);            if (httpRequest.status == 200){            var r = httpRequest.responseXML;                   if(document.all){                r=new ActiveXObject("Microsoft.XMLDOM");                r.async="false";                r.loadXML(httpRequest.responseText);            }                  if (xmlGetElem("oops",r)!=null){                xGetElementById("nlTitle").style.color="RED";                xGetElementById("nlTitle").innerHTML = "Invalid eMail address";                xGetElementById("nlProcessingP").style.display="none";                xGetElementById("nlButtonP").style.display="block";            }else{                               xGetElementById("nlProcessingP").style.display="none";                xGetElementById("nlSuccess").style.display="block";                                   setTimeout('opacity("newsLetter", 100, 0, 300)', 1500);                nlVisible=false;                  eraseCookie("newsLetter");                 createCookie("newsLetter",xmlGetElem("email"),1);                          }        }else{            xGetElementById("nlProcessingP").style.display="none";            xGetElementById("nlButtonP").style.display="block";            alert("Sign-up Error: Server connection problem");        }    }    }function loginResult(httpRequest){    if (httpRequest.readyState == 4){            if (httpRequest.status == 200){            var r = httpRequest.responseXML;            if(document.all){                r=new ActiveXObject("Microsoft.XMLDOM");                r.async="false";                r.loadXML(httpRequest.responseText);            }             cid=r.getElementsByTagName('login').item(0).firstChild.data;            if (cid=="FAILED"){                xGetElementById("loginTitle").style.color="RED";                xGetElementById("loginTitle").innerHTML = "Invalid Login";                xGetElementById("loginProcessingP").style.display="none";                xGetElementById("loginButtonP").style.display="block";                cid=-1;            }else{                xGetElementById("menuLogin").href = "javascript:logout();";                xGetElementById("loginProcessingP").style.display="none";                xGetElementById("loginSuccess").style.display="block";                cid = xmlGetElem("id",r);                vid = xmlGetElem("vid",r);                xGetElementById("menuLogin").innerHTML="<span>Logout<br />(" +xmlGetElem("name",r) +")</span>";                xGetElementById("ids").innerHTML = "cid:" +cid +", vid:" +vid +", oid="+oid;                setTimeout('opacity("login", 100, 0, 300)', 1500);                loginVisible=false;                if (pageLogin!=null)                    pageLogin();            }        }else{            xGetElementById("loginProcessingP").style.display="none";            xGetElementById("loginButtonP").style.display="block";            alert("Login Error: Server connection problem");        }    }    }function toggleLogin(){	if (!loginVisible){		opacity("login", 0, 100, 300);		if (readCookie("emailAddress") == null)	       document.getElementById("loginEmail").focus();	    else	       document.getElementById("loginPassword").focus();        xGetElementById("loginProcessingP").style.display="none";        xGetElementById("loginSuccess").style.display="none";        xGetElementById("loginButtonP").style.display="block";        loginVisible=true;	}else{		opacity("login", 100, 0, 300);		loginVisible=false;	}}function logout(){    makeRequest("http://www.specsonthenet.co.uk/servlet/ProcessCustomer",                "logout", logoutResult);}function logoutResult(httpRequest){    if (httpRequest.readyState == 4){        if (httpRequest.status == 200){            xGetElementById("menuLogin").innerHTML="<span>Login</span>";            xGetElementById("menuLogin").href = "javascript:toggleLogin();";            xGetElementById("ids").innerHTML = "cid:-1, vid:0, oid=0";            if (pageLogout!=null)                pageLogout();        }    }}function toggleContact(){	if (contactVisible = !contactVisible){        xShow("messageButtonDiv");        xHide("loadingDiv");        xHide("thanksDiv");		opacity("contact", 0, 100, 300);	}else{		opacity("contact", 100, 0, 300);	}}function opacity(id, opacStart, opacEnd, millisec){        if (crappyBrowser){        changeOpac(id, opacEnd);    }else{    //speed for each frame        var speed = Math.round(millisec / 100),            timer = 0,            i=0;    //determine the direction for the blending, if start and end are the same nothing happens        if(opacStart > opacEnd) {            for(i = opacStart; i >= opacEnd; i--){                setTimeout("changeOpac('" +id +"'," +i +")",(timer * speed));                timer++;            }        }else if(opacStart < opacEnd){            for(i = opacStart; i <= opacEnd; i++){                setTimeout("changeOpac('" +id +"'," +i +")",(timer * speed));                timer++;            }        }    }    }function changeOpac(id, opacity) {    var object = document.getElementById(id).style;    object.visibility = (opacity>0 ? "visible" : "hidden");    object.opacity = (opacity / 100);    object.MozOpacity = (opacity / 100);    object.KhtmlOpacity = (opacity / 100);    object.filter = "alpha(opacity=" + opacity + ")";}/******************************** AJAX stuff **********************************/function sendMessage(){    xHide("messageButtonDiv");    xShow("loadingDiv");    tempTime = new Date();        makeRequest("http://www.specsonthenet.co.uk/servlet/SendMessage",                "contactEmail="+escape(xGetElementById("contactEmail").value)                +"&message="+escape(xGetElementById("messageBox").value)                +"&pageURL="+escape(pageURL), alertMessage);    xGetElementById("contactEmail").disabled=true;    xGetElementById("messageBox").disabled=true;    createCookie("openMessage","true",24*7);        }function leaveFeedback(){    document.getElementById("feedbackButtonDiv").innerHTML="<img src=\"images/loading.gif\" alt=\"Loading...\" />";    makeRequest("http://www.specsonthenet.co.uk/servlet/LeaveFeedback",                "feedbackEmail="+escape(document.getElementById("feedbackEmail").value)                +"&feedback="+escape(document.getElementById("feedback").value)                +"&pageURL="+escape(pageURL), alertContents);}function checkForMessages(){    if (readCookie("openMessage") == "true"){//alert("check messages");            makeRequest("http://www.specsonthenet.co.uk/servlet/CheckMessages", null, checkMessageResponse);    }}function checkMessageResponse(httpRequest){    if (httpRequest.readyState==4){        var mess = httpRequest.responseText;//alert(mess);                if (mess.indexOf("<openMessage>")>=0){                        xGetElementById("contactIntro").style.display="none";                                    var body = mess.substring(mess.indexOf("<message>")+9, mess.indexOf("</message>"));                        var author = mess.substring(mess.indexOf("<author>")+8, mess.indexOf("</author>"));            addChat(body, author);                        if (!contactVisible)                toggleContact();        }    }}function addChat(body, author){    var newChat = document.createElement("div");    newChat.className = "historyMessageHi";        var messageBody = document.createElement("p");    messageBody.className = "messageBody";    var ts = document.createElement("span");    var now = new Date();    ts.className = "messageTime";    ts.appendChild( document.createTextNode(now.getHours() +":" +(now.getMinutes()<10 ? "0"+now.getMinutes() : now.getMinutes())+" " ) );    messageBody.appendChild(ts);    messageBody.appendChild(document.createTextNode(body));      newChat.appendChild(messageBody);                  if (author!=""){        var messageAuthor = document.createElement("p");        messageAuthor.className = "messageAuthor";        messageAuthor.appendChild(document.createTextNode(author));         newChat.appendChild(messageAuthor);       }              for (var i=0; i<xGetElementById("messageHistory").childNodes.length; ++i){        if (xGetElementById("messageHistory").childNodes[i].tagName=="DIV")            xGetElementById("messageHistory").childNodes[i].className="historyMessage";    }        var eldest = xGetElementById("messageHistory").firstChild;    if (eldest)        xGetElementById("messageHistory").insertBefore(newChat, eldest);    else        xGetElementById("messageHistory").appendChild(newChat);}function getForm(fobj){    var str = "";    var ft = "";    var fv = "";    var fn = "";    var els = "";    for(var i = 0;i < fobj.elements.length;i++){        els = fobj.elements[i];        ft = els.title;        fv = els.value;        fn = els.name;        switch(els.type) {            case "text":            case "hidden":            case "password":            case "textarea":            // is it a required field?            if(encodeURI(ft) == "required" && encodeURI(fv).length < 1) {                alert('\''+fn+'\' is a required field, please complete.');                els.focus();                return false;            }            str += fn + "=" + encodeURI(fv) + "&";            break;            case "checkbox":            case "radio":            if(els.checked) str += fn + "=" + encodeURI(fv) + "&";            break;            case "select-one":            str += fn + "=" +            els.options[els.selectedIndex].value + "&";            break;        }    }    str = str.substr(0,(str.length - 1));    return str;}function alertMessage(httpRequest){    var s;    if (httpRequest.readyState == 4){                    if (httpRequest.status == 200){  //alert(httpRequest.responseText);                              s="Thank you for the message.";                    }else            s="Sorry, there was a problem with the request.";        var now = new Date();        if ( (now.valueOf() - tempTime.valueOf())<1000)            window.setTimeout("updateMessageWindow('"+s+"')", 1600);        else            updateMessageWindow(s);    }}function updateMessageWindow(s){    xHide("loadingDiv");    xShow("thanksDiv");    if (s.indexOf("Thank you")>=0){        addChat(xGetElementById("messageBox").value, "");        xGetElementById("messageBox").value="";    }    xGetElementById("contactEmail").disabled=false;    xGetElementById("messageBox").disabled=false;    xGetElementById("thanksDiv").innerHTML=s;    setTimeout("toggleContact();",1600);}function makeRequest(url, formData, fn){    var httpRequest;    var method="GET";    if (formData==null)        formData="";    if (formData!="")        method="POST";    ajaxReqTime = new Date().getTime();    if (window.XMLHttpRequest){               // Firefox, Safari and other Proper Browsers        httpRequest = new XMLHttpRequest();        if (httpRequest.overrideMimeType)            httpRequest.overrideMimeType('text/xml');    }    else if (window.ActiveXObject){           // infernal excrement and other shite        try{            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");        }catch(x){            try{                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");            }catch(x){}        }    }    if (!httpRequest) {        alert("Sorry, the feedback system uses AJAX which your browser doesn't support.");        return false;    }    httpRequest.onreadystatechange = function(){ fn(httpRequest); };    httpRequest.open(method, url, true);    if (method=="POST"){        httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");        httpRequest.setRequestHeader("Content-length", formData.length);        httpRequest.setRequestHeader("Connection", "close");    }    httpRequest.send(formData);    return true;}function alertContents(httpRequest){    if (httpRequest.readyState == 4){        if (httpRequest.status == 200)            document.getElementById("feedbackButtonDiv").innerHTML="Thank you for the feedback.";        else            document.getElementById("feedbackButtonDiv").innerHTML="Sorry, there was a problem with the request.";        setTimeout("closeFeedback();",1600);    }}function closeFeedback(){    document.getElementById("feedbackPanel").style.visibility="hidden";    hideGreyPanel();}function getCookieVal(offset){	  var endstr = document.cookie.indexOf (";", offset);	  if (endstr == -1)		endstr = document.cookie.length;	  return unescape(document.cookie.substring(offset, endstr));}function getCookie(name){	  var arg = name + "=";	  var alen = arg.length;	  var clen = document.cookie.length;	  var i = 0;	  while (i < clen) {		var j = i + alen;		if (document.cookie.substring(i, j) == arg)		  return getCookieVal (j);		i = document.cookie.indexOf(" ", i) + 1;		if (i == 0) break;	  }	  return null;}function checkFeedbackPos(){    if (xGetElementById("greyPanel").style.visible=="visible")        showCentered("greyPanel");    if (xGetElementById("feedbackPanel").style.visible=="visible")        showCentered("feedbackPanel");}// Tooltip library - copyright Mark James// uses a standard div element as the tooltip, default alignment below to left// optional comma separted paramater://   "right" - align to the right//   "quote" - for use with speech bubble, align topvar currentTip=null;var nextTip=null;var showTimer=null;var hideTimer=null;var triggerEvent;var tipParam;var nextParam;function startTipTimer(id, e, p){debug("check show timer");    if (id==nextTip && showTimer!=null)        return;    if (currentTip==id && hideTimer!=null){        clearTimeout(hideTimer);        hideTimer=null;        return;    }    if (showTimer!=null && nextTip!=id)        clearTimeout(showTimer);    nextTip=id;    nextParam = p;    triggerEvent = new xEvent(e);    showTimer = setTimeout("initTip()",500);    document.onmousemove = mouseMoved;    if (document.captureEvents) document.captureEvents(Event.MOVE);debug("start show timer");}function initTip(){debug("show tip "+nextTip+" @ "+(triggerEvent.pageX - xWidth(nextTip)-3)+","+(triggerEvent.pageY+3));    xGetElementById(nextTip).style.display="block";    if (currentTip){        xHide(currentTip);        if (hideTimer){            clearTimeout(hideTimer);            hideTimer=null;        }        currentTip=null;    }    xMoveTo(nextTip,-1000,0);    xShow(nextTip);    tipParam=nextParam;    var tx = triggerEvent.pageX - xWidth(nextTip)-3;    var ty = triggerEvent.pageY+3;    if (tipParam){        if (tipParam.indexOf("quote")>=0){            tx += 40;            ty -= xHeight(nextTip)+6;        }        if (tipParam.indexOf("right")>=0){            tx = triggerEvent.pageX + 5;        }    }    xMoveTo(nextTip, tx, ty);    currentTip = nextTip;    nextTip=null;    clearTimeout(showTimer);    showTimer = null;}function showTip(id){    if (currentTip != null && currentTip != id){        xHide(currentTip);    }    xGetElementById(id).style.display="block";    var tx = triggerEvent.pageX - xWidth(id)-3;    var ty = triggerEvent.pageY+3;    xMoveTo(id,-1000,0);    xShow(id);    if (tipParam){        if (tipParam.indexOf("quote")>=0){            tx += 40;            ty -= xHeight(id)+6;        }        if (tipParam.indexOf("right")>=0){            tx = triggerEvent.pageX + 5;        }    }    xMoveTo(id, tx, ty);    currentTip = id;    xGetElementById(id).onmouseover=cancelHideTimer;    xGetElementById(id).onmouseout=startHideTimer;}function cancelHideTimer(id){window.status="cancel hide timer";    clearTimeout(hideTimer);    hideTimer=null;}function startHideTimer(){    if (showTimer){        clearTimeout(showTimer);        showTimer = null;        nextTip=null;    }    if (currentTip==null)        return;    if (hideTimer!=null)        return;    hideTimer = setTimeout("hideTip()",150);}function hideTip(){    xHide(currentTip);    clearTimeout(hideTimer);    hideTimer=null;/*    if (showTimer){        clearTimeout(showTimer);        showTimer=null;        nextTip=null;    }*/    currentTip=null;}function mouseMoved(e){    if (currentTip==null && nextTip==null)        return;    triggerEvent = new xEvent(e);    if (currentTip==null)        return;//    window.status = "M @ "+triggerEvent.pageX+", "+triggerEvent.pageY;    showTip(currentTip);}function clearCheck(){    if (xGetElementById("quickSearchText").value=="search")        xGetElementById("quickSearchText").value="";}function searchCheck(){    if (xGetElementById("quickSearchText").value=="")        xGetElementById("quickSearchText").value="search";}function qSearch(){    var q = xGetElementById("quickSearchText").value;    if (q=="" || q=="search")        return;    location.href="glasses.jsp?search="+escape(q);}function getElementPosition(elemID){    var offsetTrail = document.getElementById(elemID);    var offsetLeft = 0;    var offsetTop = 0;    while (offsetTrail){        offsetLeft += offsetTrail.offsetLeft;        offsetTop += offsetTrail.offsetTop;        offsetTrail = offsetTrail.offsetParent;    }    if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){        offsetLeft += document.body.leftMargin;        offsetTop += document.body.topMargin;    }//    return {left:offsetLeft,top:offsetTop};    return offsetLeft; }xAddEventListener(window, "resize", pageScrolled, false);xAddEventListener(window, "scroll", pageResized, false);xAddEventListener(window, "onload", pageInit, false);