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);

function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}


function MM_findObj(n, d) { 
  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_validateForm() { 
if (form.btnContinueOrder == true)
{
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  }
}

function getEl(id) {
	// Helper to reduce typing
	return document.getElementById(id);
}

function checkPromotionCode(src, arg) {
	var i = getEl("txtPromotionCode").value.length;
	if (i != 0) {
		arg.IsValid = (i >= 10 && i <=15);
	} else {
		arg.IsValid = true;
	}
}

function checkHouseNumberOrName(src, arg){
	arg.IsValid = (getEl("txtHouseNumber").value.length != 0 || getEl("txtHouseName").value.length != 0);
}

function checkClubcardNumber(src, arg){
	arg.IsValid = (getEl("txtClubcardNumber").value.length >= 16 || getEl("txtClubcardNumber").value.length == 0);
}

function checkCreditCard(src, arg){
	arg.IsValid = (getEl("txtCardNumber").value.length == 16 || getEl("txtCardNumber").value.length == 18 || getEl("txtCardNumber").value.length == 19);
}

function checkSortCode(src, arg) {
	var sSortCode = getEl("txtSortCode1").value + getEl("txtSortCode2").value + getEl("txtSortCode3").value;
	arg.IsValid = (sSortCode.length == 6);
}

function checkSecurityCode(src, arg) {
	var sSortCode = getEl("Checkout:CardPaymentDetailsTemplate_SecurityCode").value;
	arg.IsValid = (sSortCode.length > 2);
}

function checkEmails(src, arg) {
	if (getEl("txtEmail").value.length != 0 && getEl("txtEmailConfirm").value.length != 0) {
		arg.IsValid = getEl("txtEmail").value == getEl("txtEmailConfirm").value;
	} else {
		arg.IsValid = true;
	}
}

function popup(url, windowName, width, height, top, left) {
	remote = window.open(url, windowName, "resizable=yes,toolbar=0,location=0,directories=0,status=no,menubar=0,scrollbars=1,copyhistory=0,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",screeny=" + top + ",screenx=" + left);
	return false;
}

function checkTandC(src, arg)
{
	arg.IsValid = getEl("chkTerms").checked;
}

function checkEnter(evt) {
	var evt = (evt) ? evt : ((event) ? event : null);
	var src = evt ? (evt.target ? evt.target : evt.srcElement) : event.srcElement;

	if (evt) {
		var kc = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
		if (kc == 13) {
			switch (src.id.toLowerCase()) {			
				case "quicksearch_quicksearchaccessoriesid_txttextsearch" :
					getEl("QuickSearch_quicksearchAccessoriesID_btnTextSearch").click();	
					break;	
				case "quicksearch_quicksearchreconid_txttextsearch" :
				    getEl('QuickSearch_quicksearchReconID_btnTextSearch').click();
				    break;
				case "quicksearch_quicksearchathomeid_txttextsearch" :
				    getEl('QuickSearch_quicksearchAtHomeID_btnTextSearch').click();
				    break;			    
			}
		}		
	}
	if(window.event.keyCode == 13)
	{
		return false;
	}	
	return true;
}

function cleartextbox(textbox){
    textbox.value='';       
}

$(document).ready(function() {

    function mycarousel_initCallback(carousel) {
        carousel.clip.hover(function() {
            carousel.stopAuto();
        }, function() {
            carousel.startAuto();
        });
    };

    jQuery('#mycarousel').jcarousel({
        auto: 5,
        scroll: 1,
        wrap: 'last',
        initCallback: mycarousel_initCallback,
        buttonNextHTML: '<div class="carouselNext"><img src="images/1024/buttons/offer_carousel_rightbtn.gif" width="27" height="164" alt="next"/></div>',
        buttonPrevHTML: '<div class="carouselPrev"><img src="images/1024/buttons/offer_carousel_leftbtn.gif" width="27" height="164" alt="previous"/></div>'
    });


    //------------------------------------------------- new flash element added. ----//
    //------------------------------------------------- find the root url 

    var base_url = location.href;   // get url and set to base_url
    //alert (base_url);
    var split_url = base_url.split("/");    // split url on "/"
    //alert (split_url[2]);
    var orange_url = "www.orangeaccessories.co.uk";     // sets orange_url to be live url for comparison to split_url[2]

    var domain_ref1 = split_url[2].indexOf("10");       //checks to see if domain is 10. address
    var domain_ref2 = split_url[2].indexOf("212");      //checks to see if domain is 212. address
    //alert ("domain_ref1 " + domain_ref1 + ", and domain_ref2 :" + domain_ref2);

    if (split_url[2] === orange_url) {  //rebuild url and set it to the var root_url
        var root_url = split_url[0] + "//" + split_url[2] + "/";

    } else if (!(domain_ref1 == -1) || !(domain_ref2 == -1)) {
        //alert ("domain_ref1 " + domain_ref1 + ", and domain_ref2 :" + domain_ref2);
        var root_url = split_url[0] + "//" + split_url[2] + "/";
    }
    else {
        var root_url = split_url[0] + "//" + split_url[2] + "/" + split_url[3] + "/";

    }

    //------------------------------------------------- setup vars for the replacement

    var flashPeel = root_url + 'media/FlashPeel_v12.swf?link_URL=iphone4g_accessories.html';
    var flashBanner = root_url + 'media/top_banner.swf?V4';

    //------------------------------------------------- replacement scripts

    $('#flashPeel').flash(
    flashPeel, {
        attr: { width: 184, height: 94, wmode: 'transparent' }
    });

    $('#top_banner').flash(
    flashBanner, {
        attr: { width: 490, height: 80 }
    });




    $('.shop-menu ul ul .selected').parent().find('ul').show();
    // accessories navigation
    //$('.shop-menu>ul>li:nth-child(1)>ul').accordion({ autoHeight:false, active: '.selected' });
    // business navigation
    //$('.shop-menu>ul>li:nth-child(4)>ul').accordion({ autoHeight:false, active: '.selected' });


    $("a#donate").bind("click", function() {
        $("#donate_form").submit();
        return false;
    });

    $("a.imagePop").fancybox({
        'overlayShow': false,
        'centerOnScroll': false,
        'hideOnContentClick': true,
        'autoScale': true,
        'hideOnOverlayClick': true,
        'overlayOpacity': 0.1,
        'frameWidth': 600,
        'frameHeight': 600,
        'zoomSpeedIn': 200,
        'zoomSpeedOut': 500,
        'titlePosition': 'inside',
        'transitionIn': 'none',
        'transitionOut': 'none',
        'easingIn': 'easeOutBack',
        'easingOut': 'easeInBack',
        'onStart': function() {
            if (typeof (onFancyBoxStart) == 'function') {
                return onFancyBoxStart();
            }
        }
      });

      $('a.iframe').fancybox({
          'overlayShow': true,
          "centerOnScroll": false,
          'overlayOpacity': 0.5,
          'frameWidth': 600,
          'frameHeight': 560,
          'zoomSpeedIn': 600,
          'zoomSpeedOut': 500,
          'easingIn': 'easeOutBack',
          'easingOut': 'easeInBack'
      });

      // appending text and link to VAT CHANGE.
      // var vatBannerCode = "<div class='vatChanges'><img src='" + root_url + "/images/vat-banner-1.png' /></div>";
      // var vatBannerText = "<div class='basketWarning'><p>You may have noticed that you are paying more in VAT on the items in your basket, the good news is that the price that you pay hasn't increased on <strong>Orangeaccessories.co.uk</strong></p></div>";

      //APPEND IMAGE
      // $(vatBannerCode).insertAfter('div.shop-menu');
      // $(vatBannerCode).prependTo('div.contentSidebar');

      //BASKET CHANGES
      // $('div.basket-view-footer').prepend(vatBannerText);
      // $('div.basketWarning').css("padding", "10px 20px 10px 20px").css("font-size", "1.1em").css("font-weight", "100").css("background-color", "#ff6600").css("color", "#ffffff");
      // $('div.basketWarning strong').css({ 'color': '#ffffff', 'font-weight': '900' });

      // $('div.vatChanges').css({ 'padding': '0px 0px 0px 0px', 'color': '#ffcc00' });

      // $('div.vatChanges img').css({ 'padding': '0px 0px 20px 0px', 'color': '#ffcc00' });


  });


