function fix_flash() {
    // loop through every embed tag on the site
    var embeds = document.getElementsByTagName('embed');
    for (i = 0; i < embeds.length; i++) {
        embed = embeds[i];
        var new_embed;
        // everything but Firefox & Konqueror
        if (embed.outerHTML) {
            var html = embed.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/wmode\s*=\s*('|")[a-zA-Z]+('|")/i))
                new_embed = html.replace(/wmode\s*=\s*('|")window('|")/i, "wmode='transparent'");
            // add a new wmode parameter
            else
                new_embed = html.replace(/<embed\s/i, "<embed wmode='transparent' ");
            // replace the old embed object with the fixed version
            embed.insertAdjacentHTML('beforeBegin', new_embed);
            embed.parentNode.removeChild(embed);
        } else {
            // cloneNode is buggy in some versions of Safari & Opera, but works fine in FF
            new_embed = embed.cloneNode(true);
            if (!new_embed.getAttribute('wmode') || new_embed.getAttribute('wmode').toLowerCase() == 'window')
                new_embed.setAttribute('wmode', 'transparent');
            embed.parentNode.replaceChild(new_embed, embed);
        }
    }
    // loop through every object tag on the site
    var objects = document.getElementsByTagName('object');
    for (i = 0; i < objects.length; i++) {
        object = objects[i];
        var new_object;
        // object is an IE specific tag so we can use outerHTML here
        if (object.outerHTML) {
            var html = object.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")[a-zA-Z]+('|")\s*\/?\>/i))
                new_object = html.replace(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")window('|")\s*\/?\>/i, "<param name='wmode' value='transparent' />");
            // add a new wmode parameter
            else
                new_object = html.replace(/<\/object\>/i, "<param name='wmode' value='transparent' />\n</object>");
            // loop through each of the param tags
            var children = object.childNodes;
            for (j = 0; j < children.length; j++) {
                try {
                    if (children[j] != null) {
                        var theName = children[j].getAttribute('name');
                        if (theName != null && theName.match(/flashvars/i)) {
                            new_object = new_object.replace(/<param\s+name\s*=\s*('|")flashvars('|")\s+value\s*=\s*('|")[^'"]*('|")\s*\/?\>/i, "<param name='flashvars' value='" + children[j].getAttribute('value') + "' />");
                        }
                    }
                }
                catch (err) {
                }
            }
            // replace the old embed object with the fixed versiony
            object.insertAdjacentHTML('beforeBegin', new_object);
            object.parentNode.removeChild(object);
        }
    }
}

function flasherOffF(eL) {
    eL.parentNode.parentNode.style.display='none';
    document.cookie='flasherOff=1; path=/'; // session expiry
}

maxOpacity=100; 
minOpacity=5;
o=maxOpacity; 
odi=35; // dec
oii=35; // inc
function decOpacity() {
    o-=Math.round(o*(odi/100)); // document.getElementById('debug').innerHTML+=o+'<br />';
    document.getElementById(loopId).style.opacity=(o<=1?0:o)/100;
    document.getElementById(loopId).style.filter='alpha(opacity='+(o<=1?0:o)+')';
    if (o<=minOpacity) {clearInterval(odInt);oiInt=setInterval('incOpacity()',50);}
}
function incOpacity() {
    o+=Math.round(o*(oii/100))+1; // document.getElementById('debug').innerHTML+=o+'<br />';
    document.getElementById(loopId).style.opacity=(o>maxOpacity?maxOpacity:o)/100;
    document.getElementById(loopId).style.filter='alpha(opacity='+(o>maxOpacity?maxOpacity:o)+')';
    if (o>maxOpacity) {clearInterval(oiInt);o=maxOpacity;setTimeout(function(){odInt=setInterval('decOpacity()',50);},2500);}
}

// the soft part of the curve is the invisible part.
// need to swap things around and have the visible part the soft part.

function dropF(thisLabel,doStuff) { // doStuff true if fired onclick or false if fired by existing cookie (just a pre-selector)
    // 'hover' off 'select' on click so it acts like select
    thisLabel.parentNode.style.height='21px'; // auto is reset on hover
    thisDrop=thisLabel.parentNode.parentNode;
    thisDropName=thisDrop.id.replace(/Drop/,'');
    dispText=thisLabel.innerText?thisLabel.innerText:thisLabel.textContent;
    document.getElementById(thisDropName+'0').parentNode.innerHTML='<input type="radio" id="'+thisDropName+'0" name="'+thisDropName+'" checked="checked" value="'+thisLabel.firstChild.value+'">'+dispText; // change the value of the first option for the form
    if (doStuff) { // fired by click and may need to reset cookie
        doFrameF('sizeFrame.php?Size='+thisLabel.firstChild.value+'&cook=1'); // no related frame grabbing, just cookie change and reload
    }
}

function stockCheckF(thisLabel,id) {
    // 'hover' off 'select' on click so it acts like select
    thisLabel.parentNode.style.height='21px'; // auto is reset on hover
    thisDrop=thisLabel.parentNode.parentNode;
    thisDropName=thisDrop.id.replace(/Drop/,'');
    // selected color or text?
    if (thisDropName.indexOf('olor')>0) { // it's a color or base color (case insensitive) so change bg color
        document.getElementById(thisDropName+'0').parentNode.style.backgroundColor=thisLabel.style.backgroundColor; // change the bg for display
        document.getElementById(thisDropName+'0').parentNode.innerHTML='<input type="radio" id="'+thisDropName+'0" name="'+thisDropName+'" checked="checked" value="'+thisLabel.firstChild.value+'">'+thisDropName.replace(/e_c/,'e c'); // change the value of the first option for the form and neatly write the drop name
    } else { // it's a size or quantity so change text
        dispText=thisLabel.innerText?thisLabel.innerText:thisLabel.textContent;
        document.getElementById(thisDropName+'0').parentNode.innerHTML='<input type="radio" id="'+thisDropName+'0" name="'+thisDropName+'" checked="checked" value="'+thisLabel.firstChild.value+'">'+dispText; // change the value of the first option for the form
    } /* else if (thisLabel.parentNode.parentNode.id.indexOf('Size')>-1) { // it's a size so change text
        document.getElementById(thisDropName+'0').parentNode.innerHTML='<input type="radio" id="Size0" name="Size" value="'+thisLabel.firstChild.value+'">'+thisLabel.firstChild.value; // change the value of the first option for the form
    } */
    if (thisDropName!='Quantity') { // quantity is the end result, not stock pull criteria
        // now go through each required 'select' for stock pull
        if (document.getElementById('Base_color0')) {
            if (document.getElementById('Base_color0').value!='') {
                a=true;
            } else {
                a=false;
            }
        } else {
            a=true;
        }
        if (document.getElementById('Color0')) {
            if (document.getElementById('Color0').value!='') {
                b=true;
            } else {
                b=false;
            }
        } else {
            b=true;
        }
        if (document.getElementById('Size0')) {
            if (document.getElementById('Size0').value!='') {
                c=true;
            } else {
                c=false;
            }
        } else {
            c=true;
        }
        // check stock
        if (a && b && c) { // enough choices made, calculate
            currentStockF(id);
            // document.getElementById('Quantity').style.display='inline';
        } else { // reset select
            document.getElementById('QuantityDrop').firstChild.innerHTML='';
            document.getElementById('QuantityDrop').firstChild.style.display='none';
        }
    } // end if not quantity
    if (thisDropName=='Color') {
        colorImgF(thisLabel.firstChild.value);
    } else if (thisDropName=='Base_color') {
        baseColorImgF(thisLabel.firstChild.value);
    } else if (thisDropName=='Size') {
        // sizeChangeF(thisLabel.firstChild.value); // xxx no automatic shop by size
    }
}

proto='https:'==document.location.protocol?'https:':'http:'; // used here and do frame

function currentStockF(id) {
    http=getHTTPObject();
    url=proto+'//www.femaleforlife.com.au/currentStock.php?id='+id;
    if (document.getElementById('Size0')) {url+='&size='+document.getElementById('Size0').value;}
    if (document.getElementById('Color0')) {url+='&color='+document.getElementById('Color0').value;}
    if (document.getElementById('Base_color0')) {url+='&baseColor='+document.getElementById('Base_color0').value;}
    url=url+"&sid="+Math.random(); // prevent caching
    http.open('GET',url,true);
    http.onreadystatechange=function() { // attaches anon function to onreadystatechange event
        if (http.readyState==4) {
            theResponse=parseInt(http.responseText);
            if (http.responseText=='') {
                alert('Your browser couldn\'t determine if this item is in stock, but you can proceed to Add To Bag.');
                currentStock=1; // just let them order 1 given can't determine actual stock
            } else { // got a numerical response
                if (theResponse>0) {
                    // alert('url: '+url+'\n\ntrue: '+theResponse);
                    currentStock=theResponse;
                    document.getElementById('messageS').innerHTML='';
                } else {
                    // alert('url: '+url+'\n\nfalse: '+theResponse);
                    currentStock=0; // put out of stock notice/form link in here
                    document.getElementById('messageS').innerHTML=('Sorry, this style is temporarily out of stock.<br /><span>Try another style, or <a href="/Contact-Female-For-Life.htm&msg=Please+let+me+know+when+'+prodName+'+'+curBodyShape+'+'+curBaseColor+'+'+curColor+'+'+document.getElementById('Size0').value.replace(/ /g,'+')+'+returns+to+stock.#form" title="Click here to request notification when this style returns to stock">request an email when it returns</a>.</span>').replace(/\+N\/A/g,'');
                }
            }
            updateQuaDropF(id);
        }
    }
    http.send(null); // should this be here so quickly? xxx
}
function getHTTPObject() {
    if (typeof XMLHttpRequest!='undefined') {
        return new XMLHttpRequest();
    }
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
    }
    alert('No HTTP Request available on this browser');return false;
}

function updateQuaDropF(id) { // separate function so we can wait for correct onreadystatechange to fire before fixing the quantity
    maxQua=5; // the most anyone can add to bag in one go if there is sufficient stock
    dump='<label class="first"><input type="radio" id="Quantity0" name="Quantity" value="" checked="checked">0</label>';
    x=0;while (x<currentStock && x<maxQua) {x++;
        dump+='<label onclick="stockCheckF(this,'+id+');"><input type="radio" id="Quantity'+x+'" name="Quantity" value="'+x+'">'+x+'</label>';
    }
    document.getElementById('QuantityDrop').firstChild.innerHTML=dump;
    document.getElementById('QuantityDrop').firstChild.style.display='block';
}

function frontBackImgF(which) {
    if (document.getElementById('FrontS')) {document.getElementById('FrontS').className='';}
    if (document.getElementById('BackS')) {document.getElementById('BackS').className='';}
    if (document.getElementById('AngleS')) {document.getElementById('AngleS').className='';}
    document.getElementById(which+'S').className='thisS';
    curFrontBack=which;
    lrgImgUpdateF();
    // thumbImgUpdateF();
}

function bodyShapeImgF(which,thisDiv) {
    // if (window.location.href.indexOf('Exercise-Accessories')>0) {alert('Exercise accessories fit all body shapes!');return false;}
    curBodyShape=which;
    lrgImgUpdateF();doFrameF('bodyShapeCook.php?bodyShape='+curBodyShape);
    bodyShapeDivs=document.getElementById('imgBoxD').getElementsByTagName('div');
    x=0;while(x<bodyShapeDivs.length) { // blank all class names
        bodyShapeDivs[x].className='';
        x++;
    }
    thisDiv.className='thisIcon';
}

function colorImgF(which) {
    curColor=which;
    lrgImgUpdateF();
    // thumbImgUpdateF();
}

function baseColorImgF(which) {
    curBaseColor=which; 
    lrgImgUpdateF();
    // thumbImgUpdateF();
}

function sizeChangeF(which) {
    if (document.getElementById('shopBySize')) {
        curSize=which;
        doFrameF('sizeFrame.php?Size='+curSize);
        document.getElementById('shopBySize').innerHTML='see all sizes';
    } else {
        setTimeout(function () {sizeChangeF(which);},100);
    }
}

function shopBySizeF() {
    if (document.getElementById('shopBySize').innerHTML=='shop by size/shape') {
        /* if (document.getElementById('Size0').value=='') {
            buyformErr('Please select your size.');
        } else {
            curSize=document.getElementById('Size0').value;
            doFrameF('sizeFrame.php?Size='+curSize);
            document.getElementById('shopBySize').innerHTML='see all sizes';
        } // old related frame version */
        window.location.href='/search/+';
    } else {
        curSize='';
        document.getElementById('shopBySize').innerHTML='shop by size/shape';
        doFrameF('sizeFrame.php?Size=0');
    }
}

bodyShapes=['Hourglass','Apple','Pear','Ruler'];

nnbc=0;
function lrgImgUpdateF() {
    if (typeof imgs == 'undefined') {
        setTimeout(function () {lrgImgUpdateF();},100);
    } else {
        // alert('running...');
        needNewBC=true;
        x=0;while (x<imgs.length) {
            if (imgs[x].imgBodyShape==curBodyShape && imgs[x].imgBaseColor==curBaseColor && imgs[x].imgColor==curColor && imgs[x].imgFrontBack==curFrontBack) { // found match
                needNewBC=false;break;
            }
            x++;
        }
        if (needNewBC) {
            nnbc++;
            if (document.getElementById('Base_color'+nnbc)) {
                curBaseColor=document.getElementById('Base_color'+nnbc).value;lrgImgUpdateF();
            }
        }
        document.getElementById('lrgImg').src='/large/'+curBodyShape+'-'+curBaseColor+'-'+curColor+'-'+curFrontBack+'-'+prodId+'-'+x+'.jpg';
        document.getElementById('lrgImg').title=curBodyShape+' '+curBaseColor+' '+curColor+' '+curFrontBack;
        // update related products if it was a color or base color change, not if it was an angle or body shape change (how to tell?)
        if (typeof prodId=='number') {
            doFrameF('relatedFrame.php?color='+curColor+'&baseColor='+curBaseColor+'&id='+prodId);
        }

        /*/ unused (change bodyshape on thumbsnails behind shape icons)
        if (typeof doBodyShapes != 'undefined') {
            // cycle through images, if it's the shape you want, append img line
            append='';x=0;while (x<imgs.length) {
                if (imgs[x].imgBodyShape==curBodyShape) { // found match
                    append+='<img src="/thumbs/'+prodId+'-'+x+'.jpg" alt="" /><img src="/large/'+prodId+'-'+x+'.jpg" alt="" />\n';
                }
                x++;
            }
            document.getElementById('preload').innerHTML+=append;
        } // */

    } // was tripping onload due to base_color calling, or frag color
}

function thumbImgUpdateF() {
    if (typeof imgs != 'undefined') {
        bSx=0;while (bSx<bodyShapes.length) {
            x=0;while (x<imgs.length) {
                if (imgs[x].imgBodyShape==bodyShapes[bSx] && imgs[x].imgBaseColor==curBaseColor && imgs[x].imgColor==curColor && imgs[x].imgFrontBack==curFrontBack) { // found match
                    break;
                }
                x++;
            }
            document.getElementById(bodyShapes[bSx]+'Thumb').src='/thumbs/'+prodId+'-'+x+'.jpg';
            document.getElementById(bodyShapes[bSx]+'Thumb').title=curBodyShape+', '+curBaseColor+', '+curColor+', '+curFrontBack;
            bSx++;
        }
    } // was on tripping when loading js.js but shouldn't check for vars in function (?)
}

function doFrameF(fileName) {
    url=proto+'//www.femaleforlife.com.au/'+fileName;
    url=url+"&sid="+Math.random(); // prevent caching
    if (document.getElementById('doFrame')) { // just use it, with random appendage
        document.getElementById('doFrame').src=url;
    } else {
        append='<iframe id="doFrame" src="'+url+'"></iframe>\n';
        document.getElementById('preload').innerHTML+=append;
    }
}




// product page

function buyformValF(bf) { // this needs some work xxx
    if (bf.Size0) {
        if (bf.Size0.value=='') {
            buyformErr('You need to select your size first.');
            return false;
        }
    }
    if (bf.Color0) {
        if (bf.Color0.value=='') {
            buyformErr('You need to select a color first.');
            return false;
        }
    }
    if (bf.Base_color0) {
        if (bf.Base_color0.value=='') {
            buyformErr('You need to select a base color first.');
            return false;
        }
    }
    if (bf.Quantity0.value==0) {
        if (document.getElementById('Quantity1')) { // only if there's stock avail
            buyformErr('You need to select a quantity first.');
        }
        return false;
    }
    return true;
}

function buyformErr(msg) {
    document.getElementById('messageS').innerHTML=msg;
    if (msg.indexOf('</a>')<0) { // don't clear message with links
        setTimeout(function () {document.getElementById('messageS').innerHTML='';},5000);
    }
}

function searchIF(thisInput) {
    thisInput.value='';
    thisInput.style.color='rgb(0,0,0)';
    thisInput.style.fontStyle='normal';
}

// cart / checkout

function intCountryF(countryName) {
    // get group
    cx=0;while (cx<countryList.length) {
        if (countryName==countryList[cx][0]) { // countryList[0][0]=countryName; countryList[0][1]=countryGroup;
            countryGroup=countryList[cx][1];break;
        }
        cx++;
    }
    // get group freight brackets
    gx=0;while (gx<groupList.length) {
        if (groupList[gx][0]==countryGroup) { // groupList[0][0]=countryGroup; groupList[0][1]=array(array(-1,20),array(119,25),array(249,20),array(499,0));
            freightBrackets=groupList[gx][1];break;
        }
        gx++;
    }
    // get freight
    if (document.ccform.cartTotal.value<.01) { // so we get a freight calc when the voucher is driving negative
        freightBase=.01; // shipping at first rate
    } else {
        freightBase=document.ccform.cartRRPTotal.value;
    }
    fx=0;while (fx<freightBrackets.length) {
        if (freightBase>freightBrackets[fx][0]) {
            freight=freightBrackets[fx][1];
        }
        fx++;
    }
    // add freight
    document.ccform.Freight.value=freight.toFixed(2);
    document.getElementById('freightbox').innerHTML=document.ccform.Freight.value;
    document.ccform.Total.value=(parseFloat(document.ccform.cartTotal.value)+parseFloat(freight)).toFixed(2);
    if (parseFloat(document.ccform.Total.value)>0) {
        document.getElementById('totalbox').innerHTML=document.ccform.Total.value;
    } else {
        document.getElementById('totalbox').innerHTML='0.00';
    }
}

function showHidePassF(thisL) {
    if (document.getElementById('Pass').type!='text'){
        changeInputTypeF(document.getElementById('Pass'),'text');
        thisL.innerHTML='hide password';
        thisL.title='Click to hide your password.';
    } else {
        changeInputTypeF(document.getElementById('Pass'),'password');
        thisL.innerHTML='show password';
        thisL.title='Click to show your password for editing.';
    }
}

// because IE can't change the type of an element, only read it
function changeInputTypeF(oldObject,newType) {
  var newObject = document.createElement('input');
  newObject.type = newType;
  if(oldObject.size) newObject.size = oldObject.size;
  if(oldObject.value) newObject.value = oldObject.value;
  if(oldObject.name) newObject.name = oldObject.name;
  if(oldObject.id) newObject.id = oldObject.id;
  if(oldObject.className) newObject.className = oldObject.className;
  oldObject.parentNode.replaceChild(newObject,oldObject);
  return newObject;
}

function emptyF() {
    if (!confirm('Do you want to remove all items from your cart?')) {
        return false;
    } else {
        document.form.empty.value='empty';document.form.submit(); // this could be a submit with the value of the id, but IE needs underscore parsing on other side
    }
}

function remF(rem) {
    document.form.rem.value=rem; // this could be a submit with the value of the id, but IE needs underscore parsing on other side
    document.form.submit();
}

function checkoutF() {
}

function jumpF(box) {
    box.value=box.value.replace(/\D/g,'');
    if (box.value.length==4) {
        if (box.id=='CardNumber1') {next=2;} else if (box.id=='CardNumber2') {next=3;} else {next=4;}
        document.getElementById('CardNumber'+next).focus();
    }
}

function stopF(box) {
    box.value=box.value.replace(/\D/g,'');
    if (box.value.length==5) {box.value=box.value.substr(0,4);}
}

function cvvF() {
    if (document.getElementById('cvv').style.display=='none') {document.getElementById('cvv').style.display='inline';} else if (true) {document.getElementById('cvv').style.display='none';}
}

function payF(thisform,box) {
    // val address form
    df=thisform;
    if (df.LoggedName.value.length<2) {alert('Please enter your name.');df.LoggedName.focus();return false;} else {df.LoggedName.value=df.LoggedName.value.toLowerCase().replace(/\b(\w)/g,
function (w, p1) {return p1.toUpperCase();});} //capitalise
    if (df.Surname.value.length<2) {alert('Please enter your surname.');df.Surname.focus();return false;} else {df.Surname.value=df.Surname.value.toLowerCase().replace(/\b(\w)/g,
function (w, p1) {return p1.toUpperCase();});} //capitalise
    if (df.Email.value.length<6 || df.Email.value.lastIndexOf('@')<2 || (df.Email.value.length-df.Email.value.lastIndexOf('@'))<6 || (df.Email.value.length-df.Email.value.lastIndexOf('.'))<3 || df.Email.value.lastIndexOf('.')==-1) {alert('Please enter your email address correctly.');df.Email.focus();return false;}
    if (df.Pass.value.length<1) {alert('Please enter a password for use when you return to Female For Life.');df.Pass.focus();return false;}
    if (df.Delivery_address.value.length<7) {alert('Please enter your Delivery address.');df.Delivery_address.focus();return false;} else {df.Delivery_address.value=df.Delivery_address.value.replace(/\b(\w)/g,
        function (w, p1) {return p1.toUpperCase();});} //capitalise
    if (df.Delivery_suburb.value.length<3) {alert('Please enter your Delivery address suburb.');df.Delivery_suburb.focus();return false;} else {df.Delivery_suburb.value=df.Delivery_suburb.value.toUpperCase();}
    if (df.Delivery_city.value.length<3) {alert('Please enter your Delivery address city.');df.Delivery_city.focus();return false;} else {df.Delivery_city.value=df.Delivery_city.value.toUpperCase();}
    //df.Delivery_postcode.value=df.Delivery_postcode.value.replace(/\D/g,''); // England has alphanumeric postcodes
    if (df.Delivery_postcode.value.length<4) {alert('Please enter 4-digit or more Delivery address postcode.');df.Delivery_postcode.focus();return false;}
    if (df.Delivery_state.value=='') {alert('Please select your Delivery address state.');df.Delivery_state.focus();return false;}
    //if (df.Delivery_country.value=='') {alert('Please select your Delivery address country.');df.Delivery_country.focus();return false;}
    //df.Delivery_phone.value=df.Delivery_phone.value.replace(/\D/g,'');
    /* if (
        df.Delivery_phone.value.length<9
/*		(df.night_phone_b.value.length!=9 && df.night_phone_b.value.length!=10 && df.state.value=='Other') ||
		(df.night_phone_b.value.length!=10 && df.night_phone_b.value!='Other') ||
		(df.night_phone_b.value.substr(0,1)!='0' && df.night_phone_b.value.substr(0,1)!='1')
* /
    ) { // break
        alert('Please enter your Delivery phone number correctly (including area code).\n\nMobile phone is acceptable.');df.Delivery_phone.focus(); return false;
    } */

    if (df.Referred_by) { // only new purchasers
        if (df.Referred_by.value=='') {alert('Please tell us how you heard about us.');df.Referred_by.focus();return false;}
    }
    if (parseFloat(df.Total.value)>0) { // don't val for cc if not paying
        // pre val cc here
        df.CardCVV.value=df.CardCVV.value.replace(/\D/g,'');
        if (df.CardCVV.value.length<3) {alert('Please enter your full CVV number.');df.CardCVV.focus();return false;}
        if (df.CardHolderName.value.length<3) {alert('Please enter the full name on the card.');df.CardHolderName.focus();return false;}
        // number and expiry are pre-val'd
        cardNumber=''+df.CardNumber1.value+df.CardNumber2.value+df.CardNumber3.value+df.CardNumber4.value;
        if (cardNumber.length<13) {alert('Please enter your full credit card number.');df.CardNumber1.focus();return false;}
    }
    if (document.getElementById('freightbox').innerHTML.indexOf('select country')>0) {
        df.Delivery_country.selectedIndex=0;alert('Please select your delivery address country.');df.Delivery_country.focus();return false;
    }
    box.style.opacity=.3;box.style.filter='alpha(opacity=30)';document.getElementById('paynowL').innerHTML='Please wait...';
    return true;
}

/* end cart/checkout functions */



function forgotF() { // duplicated differently on bscFrame.php
	if (document.loginform.LogEmail.value=='') {
		alert('Enter your email address in the box above and then click the \'Forgot password?\' link again.');
	} else {
		alert('We will now attempt to send your password to '+document.loginform.LogEmail.value+'.\nIf you have entered your registered email address correctly, your password will be sent there. Please check your email.');
		window.location.href='/user&forgot='+document.loginform.LogEmail.value;
	}
}


function bscF(thisE) { // return the click false so we only get one slide advance
    document.getElementById(thisE.id.replace(/label/,'')).checked=true;
    tsbsbpF();
    $('#bscFormSlides').cycle('next');
    return false;
}

function tsbsbpF() { // check if form 1 has been filled and show only appropriate result comment. reset frame (to save answers to db) if logged.
    ts=getCheckedValue(document.forms['bscForm'].elements['Top_size']);
    bs=getCheckedValue(document.forms['bscForm'].elements['Bottom_size']);
    bp=getCheckedValue(document.forms['bscForm'].elements['Body_shape']);
    if (ts!='' && bs!='' && bp!='') { // convert to ffl sizing
        nbs=bs;nts=ts;ts=fflSizeF(ts);bs=fflSizeF(bs);
        $('div.preload').css('display','none');
        if (window.bscFrame.document.getElementById('bscReg')) { // not logged
            document.getElementById('bscFrame').document.bscReg.bscSave.value=ts+'--'+bp+'--'+nbs+'--'+nts;
        } else { // logged
            document.getElementById('bscFrame').src='/bscFrame.php?bscSave='+ts+'--'+bp+'--'+nbs+'--'+nts;
        }
        document.getElementById(ts+bs+bp).style.display="block";
        document.getElementById('bscSBS').href='/search/+--'+ts+'--'+bp;
    }
}

function fflSizeF(convertThis) { // convert size numbers to FFL sizes
    switch (convertThis) {
        case '6':convertThis='Petite';break;
        case '8':convertThis='Petite';break;
        case '10':convertThis='Sexy';break;
        case '12':convertThis='Sexy';break;
        case '14':convertThis='Curvy';break;
        case '16':convertThis='Curvy';break;
        case '18':convertThis='Voluptuous';break;
        case '20':convertThis='Voluptuous';break;
    }
    return convertThis;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function StripTags(strMod){ // javascript version of php plus more // StripTags(str [, IsAllowed [, SpecifiedTags]]]) // Added IsAllowed parameter. If true, then any specfied tags are allowed (just like in PHP). If false, then only specified tags are removed.
    if(arguments.length<3) strMod=strMod.replace(/<\/?(?!\!)[^>]*>/gi, '');
    else{
        var IsAllowed=arguments[1];
        var Specified=eval("["+arguments[2]+"]");
        if(IsAllowed){
            var strRegExp='</?(?!(' + Specified.join('|') + '))\b[^>]*>';
            strMod=strMod.replace(new RegExp(strRegExp, 'gi'), '');
        }else{
            var strRegExp='</?(' + Specified.join('|') + ')\b[^>]*>';
            strMod=strMod.replace(new RegExp(strRegExp, 'gi'), '');
        }
    }
    return strMod;
}


/* fancy zoom - NOTE: added 20px wide blank.gif images to two cells below to get the shadow to work, it was disappearing on this site */

jQuery.fn.fancyZoom = function(options){

  var options   = options || {};
  var directory = options && options.directory ? options.directory : '/zoomImages';
  var zooming   = false;

  if ($('#zoom').length == 0) {
    var ext = $.browser.msie ? 'gif' : 'png';
    var html = '<div id="zoom" style="display:none;"> \
                  <table id="zoom_table" style="border-collapse:collapse; width:100%; height:100%;"> \
                    <tbody> \
                      <tr> \
                        <td class="tl" style="background:url(' + directory + '/tl.' + ext + ') 0 0 no-repeat; width:20px; height:20px; overflow:hidden;" /> \
                        <td class="tm" style="background:url(' + directory + '/tm.' + ext + ') 0 0 repeat-x; height:20px; overflow:hidden;" /> \
                        <td class="tr" style="background:url(' + directory + '/tr.' + ext + ') 100% 0 no-repeat; width:20px; height:20px; overflow:hidden;" /> \
                      </tr> \
                      <tr> \
                        <td class="ml" style="background:url(' + directory + '/ml.' + ext + ') 0 0 repeat-y; width:20px; overflow:hidden;"><img src="/blank.gif" width="20" /></td> \
                        <td class="mm" style="background:#fff; vertical-align:top; padding:10px;"> \
                          <div id="zoom_content"> \
                          </div> \
                        </td> \
                        <td class="mr" style="background:url(' + directory + '/mr.' + ext + ') 100% 0 repeat-y;  width:20px; overflow:hidden;"><img src="/blank.gif" width="20" /></td> \
                      </tr> \
                      <tr> \
                        <td class="bl" style="background:url(' + directory + '/bl.' + ext + ') 0 100% no-repeat; width:20px; height:20px; overflow:hidden;" /> \
                        <td class="bm" style="background:url(' + directory + '/bm.' + ext + ') 0 100% repeat-x; height:20px; overflow:hidden;" /> \
                        <td class="br" style="background:url(' + directory + '/br.' + ext + ') 100% 100% no-repeat; width:20px; height:20px; overflow:hidden;" /> \
                      </tr> \
                    </tbody> \
                  </table> \
                  <a href="#" title="Close" id="zoom_close" style="position:absolute; top:0; left:0;"> \
                    <img src="' + directory + '/closebox.' + ext + '" alt="Close" style="border:none; margin:0; padding:0;" /> \
                  </a> \
                </div>';

    $('body').append(html);

    $('html').click(function(e){if($(e.target).parents('#zoom:visible').length == 0) hide();});
    $(document).keyup(function(event){
        if (event.keyCode == 27 && $('#zoom:visible').length > 0) hide();
    });

    $('#zoom_close').click(hide);
  }

  var zoom          = $('#zoom');
  var zoom_table    = $('#zoom_table');
  var zoom_close    = $('#zoom_close');
  var zoom_content  = $('#zoom_content');
  var middle_row    = $('td.ml,td.mm,td.mr');

  this.each(function(i) {
    $($(this).attr('href')).hide();
    $(this).click(show);
  });

  return this;

  function show(e) {
    if (zooming) return false;
		zooming         = true;
		var content_div = $($(this).attr('href'));
  	var zoom_width  = options.width;
		var zoom_height = options.height;

		var width       = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
  	var height      = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
  	var x           = window.pageXOffset || (window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
  	var y           = window.pageYOffset || (window.document.documentElement.scrollTop || window.document.body.scrollTop);
  	var window_size = {'width':width, 'height':height, 'x':x, 'y':y}

		var width              = (zoom_width || content_div.width()) + 60;
		var height             = (zoom_height || content_div.height()) + 60;
		var d                  = window_size;

		// ensure that newTop is at least 0 so it doesn't hide close button
		var newTop             = Math.max((d.height/2) - (height/2) + y, 0);
		var newLeft            = (d.width/2) - (width/2);
		var curTop             = e.pageY;
		var curLeft            = e.pageX;

		zoom_close.attr('curTop', curTop);
		zoom_close.attr('curLeft', curLeft);
		zoom_close.attr('scaleImg', options.scaleImg ? 'true' : 'false');

    $('#zoom').hide().css({
			position	: 'absolute',
			top				: curTop + 'px',
			left			: curLeft + 'px',
			width     : '1px',
			height    : '1px'
		});

    fixBackgroundsForIE();
    zoom_close.hide();

    if (options.closeOnClick) {
      $('#zoom').click(hide);
    }

		if (options.scaleImg) {
  		zoom_content.html(content_div.html());
  		$('#zoom_content img').css('width', '100%');
		} else {
		  zoom_content.html('');
		}

    $('#zoom').animate({
      top     : newTop + 'px',
      left    : newLeft + 'px',
      opacity : "show",
      width   : width,
      height  : height
    }, 500, null, function() {
      if (options.scaleImg != true) {
    		zoom_content.html(content_div.html());
  		}
			unfixBackgroundsForIE();
			zoom_close.show();
			zooming = false;
    })
    return false;
  }

  function hide() {
    if (zooming) return false;
		zooming         = true;
	  $('#zoom').unbind('click');
		fixBackgroundsForIE();
		if (zoom_close.attr('scaleImg') != 'true') {
  		zoom_content.html('');
		}
		zoom_close.hide();
		$('#zoom').animate({
      top     : zoom_close.attr('curTop') + 'px',
      left    : zoom_close.attr('curLeft') + 'px',
      opacity : "hide",
      width   : '1px',
      height  : '1px'
    }, 500, null, function() {
      if (zoom_close.attr('scaleImg') == 'true') {
    		zoom_content.html('');
  		}
      unfixBackgroundsForIE();
			zooming = false;
    });
    return false;
  }

  function switchBackgroundImagesTo(to) {
    $('#zoom_table td').each(function(i) {
      var bg = $(this).css('background-image').replace(/\.(png|gif|none)\"\)$/, '.' + to + '")');
      $(this).css('background-image', bg);
    });
    var close_img = zoom_close.children('img');
    var new_img = close_img.attr('src').replace(/\.(png|gif|none)$/, '.' + to);
    close_img.attr('src', new_img);
  }

  function fixBackgroundsForIE() {
    if ($.browser.msie && parseFloat($.browser.version) >= 7) {
      switchBackgroundImagesTo('gif');
    }
	}

  function unfixBackgroundsForIE() {
    if ($.browser.msie && $.browser.version >= 7) {
      switchBackgroundImagesTo('png');
    }
	}
}


