if (window != top) {
  isGoogle=document.location.href.indexOf('google.com');
  if (isGoogle == '-1') {
    //document.location.href = 'http://www.buymobilephones.net/gotobmp.html';
  }
}
function writeIfFound(img, rephtml, span) {
    var sess = new Date();
    var nocache = sess.getTime();
    var imguri = img+"?time="+nocache;
    var imgPreload = new Image();
    imgPreload.onload = function() {
        $('#'+span).html(rephtml);
    };
    imgPreload.src = imguri;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
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 MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
if (checkIt('konqueror')) {
  browser = "Konqueror";
  OS = "Linux";
} else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible')) {
  browser = "Netscape Navigator"
  version = detect.charAt(8);
} else browser = "An unknown browser";
if (!version) version = detect.charAt(place + thestring.length);
if (!OS) {
  if (checkIt('linux')) OS = "Linux";
  else if (checkIt('x11')) OS = "Unix";
  else if (checkIt('mac')) OS = "Mac"
  else if (checkIt('win')) OS = "Windows"
  else OS = "an unknown operating system";
}
function checkIt(string) {
  place = detect.indexOf(string) + 1;
  thestring = string;
  return place;
}

function showfg(ids) {
  window.open ('/info_freegifts.php?ids=' + ids, 'freegifts', 'width=450,height=420,status=yes,scrollbars=yes,resizable=yes');
  return false;
}
function sshowfg(ids) {
  window.open ('/info_freegifts.php?ids=' + ids, 'freegifts', 'width=450,height=420,status=yes,scrollbars=yes,resizable=yes');
  return false;OS
}
function showsecnum() {
  window.open ('/security_number.ihtml', 'securitynumber', 'width=380,height=320,status=no,scrollbars=yes,resizable=yes');
}
function doPop(pge) {
  myWin = window.open('store/popup/popup.ihtml?pge=' + pge,'jtpop','scrollbars=yes,resizable,width=618,height=465');
}
function TROvr(obj) { obj.className = 'rowOver'; }
function TROut(obj) { obj.className = 'rowUp'; }
function extrasCheck(ftype,ecount,optional,thefield,exceptids,enames) {
  //alert(ftype+'\n'+ecount+'\n'+optional+'\n'+thefield);
  switch (ftype) {
    case 1: // Checkboxes
      if (ecount == 1  && !optional) thefield.checked=true;
      break;
    case 2: // Radio Buttons
      if (ecount == 1  && !optional) thefield.checked=true;
      break;
    case 3: // Select
      break;
  }
  cExceptions(thefield, exceptids, enames);
}
function cExceptions(tparent, exceptids, enames) {
  for (i=0; exceptids.length - 1 >= i; i++) {
    if ((exceptids[i] != 0) && (eval('document.forms.fdaddthis.network' + exceptids[i])) != null) {
      thiscb = eval('document.forms.fdaddthis.network' + exceptids[i]);
      if (thiscb.checked == true) {
        tparent.checked = false;
        alert('This extra can not be selected at the same time as\n - \''+enames[i]+'\'');
        return false;
      }
    }
  }
  return true;
}
function showInfo(r,pge,pid) {
  switch (pge) {
    case 't' :
      var fn='/info_tariff.php';
      break;
    case 'p' :
      var fn='/info_phone.php';
      break;
    case 'a' :
      var fn='/info_accessory.php';
      break;
    case 'd' :
      var fn='/info_delivery.php';
      break;
    case 'da' :
      var fn='/info_delivery_address.php';
      break;
    case 'i' :
      var fn='/info_insurance.php';
      break;
    case 'tc' :
      var fn='/info_terms.php';
      break;
    case 'if' :
      var fn='/info_insurance_faq.php';
      break;
    case 'id' :
      var fn='/info_new_gift_claims.php';
      break;
    case 'tm' :
      var fn='/info_tmob_business_advantages.php';
      break;
    case 'obb' :
      var fn='/orange_homebb_home.html';
      break;
    default :
      var fn=pge;
      break;
  }
  if (r) { fn='store/'+fn; }
  if ((pid.length !=0) && (pid != 0)) { var ps='?id='+pid; } else { var ps=''; }
  if (fn) { window.open (fn+ps, 'bmp_information', 'width=620,height=550,status=yes,scrollbars=yes,resizable=yes'); } //450x420
  return false;
}

// TEMP FUNCTIONS
function sshowPhoneDets(ids) {
  window.open ('/layout_phone_details_popup.html', 'phonedetails', 'width=450,height=420,status=yes,scrollbars=yes,resizable=yes');
  return false;

}
function showinsurancefaq() {
  window.open ('/insurance_faq.php', 'InsuranceFAQ', 'width=380,height=320,status=yes,scrollbars=yes,resizable=yes');
  return false;
}
function tog(t,ttype,classSwpObj,tClassOne,tClassTwo,htmlSwpObj,htmlOne,htmlTwo) {
  togDiv = document.getElementById(t);
  if (ttype == 'tr') {
    if (togDiv.style['display'] == 'none') {
      try { togDiv.style['display'] = 'table-row'; }
      catch(err) { togDiv.style['display'] = 'block'; }
    }
    else if ((togDiv.style['display'] == 'table-row') || (togDiv.style['display'] == 'block')) { togDiv.style['display'] = 'none'; }
  } else {
    if (togDiv.style['display'] == 'none') { togDiv.style['display'] = 'block'; }
    else if (togDiv.style['display'] == 'block') { togDiv.style['display'] = 'none'; }
  }
  if (classSwpObj && (classSwpObj != '') && ((tClassOne != '') && (tClassTwo != ''))) {
    var swapObj = document.getElementById(classSwpObj);
    if (swapObj.className == tClassOne) { swapObj.className = tClassTwo; }
    else if (swapObj.className == tClassTwo) { swapObj.className = tClassOne; }
  }

  if (htmlSwpObj && (htmlSwpObj != '') && ((htmlOne != '') && (htmlTwo != ''))) {
    var swapObj = document.getElementById(htmlSwpObj);
    if (swapObj.innerHTML == htmlOne) { swapObj.innerHTML = htmlTwo; }
    else if (swapObj.innerHTML == htmlTwo) { swapObj.innerHTML = htmlOne; }
  }
}
function quickFind(obj) {
	url = obj.options[obj.selectedIndex].value;
	if (url.length) {
		if (document.location.href.indexOf('store/') < 1) url = 'store/' + url;
		document.location.href=url;
	}
}
function isNumberKey(evt){
  var charCode = (evt.which) ? evt.which : evt.keyCode
  if ((charCode!= 8 && charCode!= 9) && charCode < 33 || (charCode > 40 && charCode < 48 && evt.keyCode!= 46) || charCode > 57) {
  	return false;
  } else {
	 return true;
	}
}


function intToText(num){
    switch(num){
        case 0:
            return 'zero';
            break;
        case 1:
            return 'one';
            break;
        case 2:
            return 'two';
            break;
        case 3:
            return 'three';
            break;
        case 4:
            return 'four';
            break;
        default:
            return num;
    }
}
//jQuery Tools modal
function loadModal(elemID, callBack){
    overlayApi = $(elemID).overlay({
        expose: '#5B5B5B',
        effect: 'apple',
        opacity: 0.1,
        closeSpeed: 400,
        top: 120,
        left: 'center',
        closeOnClick: true,
        closeOnEsc: true,
        oneInstance: false,
        api: true,
        onClose: function(){
            //IE6 quirk - re-enable select elements
            $('select').css({visibility: 'visible'});
            if(typeof callBack == "function"){
                callBack();
            }
        }
    });
    //IE6 quirk - hide select elements as otherwise they overlap the overlay
    if ($.browser.msie && $.browser.version <= 6 ) $('select').css({visibility: 'hidden'});
    overlayApi.load();
}

//Q Tips tool tips
function initQTips(target){
    $(target).qtip({
        style: {
            width: 300,
            padding: 10,
            font: 'normal 12px arial, helvetica, sans-serif',
            color:'#666460',
            background: '#FFEE8D',
            border: {
                width: 1,
                radius: 3,
                color: '#edcf45'
            },
            tip: {
                corner: 'topLeft'
            }
        },
        show: {
            effect: {
                length: 430,
                type: 'fade'
            }
        },
        position: {
            corner: {
                target: 'bottomMiddle'
            }
        }
    })
}

//Q Tips Modal
var QTipModal = {
    init: function(selector){

        this.buildOverlay();

        //define custom styles
        $.fn.qtip.styles.norm = {
           width: 540,
           padding: 0,
           background: '#FFF',
           border: {width: 9, radius: 9, color: '#E2E2E2'},
           classes: {tooltip: 'modal-qtip'}

        }
        $.fn.qtip.styles.dark = {
            background: '#FEFBE4',
            border: { color: '#F3EA98'},
            name: 'norm'
        }

        //set up modal options
        this.s = '#'+selector;
        $(this.s).qtip({
            content: {
                text: $(this.s).html()
            },
            position: {
                target: $(document.body), // Position it via the document body...
                corner: 'center' // ...at the center of the viewport
            },
            show: {
                when: false,
                solo: false
            },
            hide: {
                when: 'unfocus'
            },
            style: 'norm',
            api: {
                beforeShow: function(){
                    // Fade in the modal "blanket" using the defined show speed
                    $('#qtip-blanket').fadeIn(this.options.show.effect.length);
                    //IE6 quirk - hide select elements as otherwise they overlap the overlay
                    if ($.browser.msie && $.browser.version <= 6 ) $('select').css({visibility: 'hidden'});
                },
                onShow: function(){
                    $('.QTipClose').click(function(){
                        $(QTipModal.s).qtip('hide');
                    })
                },
                beforeHide: function(){
                    // Fade out the modal "blanket" using the defined hide speed
                    $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
                    //IE6 quirk
                    $('select').css({visibility: 'visible'});
                }
            }
        })
    },
    buildOverlay: function(){
        //create overlay
        $('<div id="qtip-blanket">')
        .css({
            position: 'absolute',
            top: 0,
            left: 0,
            width: '100%',
            opacity: 0.6,
            backgroundColor: '#000',
            zIndex: 5000
        })
        .appendTo(document.body)
        .hide();
    },
    load: function(a, b, c, d){
        var api = $(this.s).qtip('api');
        
        if(a){
            api.updateContent($('#'+a).html());
        }
        if(typeof b == 'function'){
            api.onShow = function(){
                $('.QTipClose').click(function(){
                    $(QTipModal.s).qtip('hide');
                });
                b();
            }
        }
        if(typeof c == 'function'){
            api.onHide = function(){
                c();
            }
        }
        if(typeof d == 'string'){
            api.updateStyle(d);
            api.onHide = function(){
                if(typeof c == 'function'){c()}
                api.updateStyle('norm');
            }
        }
        $('#qtip-blanket').css({height: $(document).height()});   // Span the full document height, put here as page height may have changed...
        api.show();
    }
}