// JavaScript Document
$(document).ready(function(){ 
	loc=window.location.href.split("#")[0];
	//hrefSections = window.location.href.split("/"); 
	//var fileName = hrefSections[hrefSections.length - 2]; 
	//alert(fileName);
	$("#box1").click(function() {window.location='/get-a-personal-self-storage-quote.asp';});
	$("#box2").click(function() {window.location='/size-estimator.asp';});
	$("#box3").click(function() {window.location='/special-offers.asp';});
	$("#box4").click(function() {window.location='/self-storage-packing-materials.asp';});
	$("#sb1").click(function() {window.location='/online-store.asp';});
	$("#sb2").click(function() {window.location='/self-storage-packing-materials-instore.asp';});
	$("#st1").click(function() {window.location='/TheStudentCase.asp';});
	$("#st2").click(function() {window.location='/storage-features-and-benefits.asp';});
	if ($("#accordion").length > 0 ) {
		$("#accordion").accordion({active: false, autoHeight: false, collapsible: true});
		if(loc.match("1")){$("#accordion").accordion('activate' , 0);}
		if(loc.match("2")){$("#accordion").accordion('activate' , 1);}
		if(loc.match("3")){$("#accordion").accordion('activate' , 2);}
		if(loc.match("4")){$("#accordion").accordion('activate' , 3);}
	
	$("#accordion a.head").click(function() {
		destination = $("#acchead").offset().top-20;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
	});
	}
	$("ul#navbar").superfish(); 
	$("a").each(function() {
		if(this.href == window.location.href.split("#")[0]) {
			if ($(this).parent().parent().parent().parent().get(0).id=="navbar") {
				$(this).parent().parent().parent().addClass("selected");
			} else {
				$(this).parent().addClass("selected");
			}
		}
	});
	$(".questions a").click(function() {
		showid=$(this).attr("rel");
		$('.questions a').css("color","#000");
		$(this).css("color","#006F51");
		$("#answers > *").hide();
		$("#a" + showid).fadeIn(300);
	});
	if ($("#answers").length > 0 ) {
		$("#answers > *").hide();
		$("#a1").fadeIn(300);
		$("a[rel='1']").css("color","#006F51");
	}
	if ($(".examples").length > 0 ) {
		illcurrent="1";
		$('.examples a').css("color","#006F51");
		$(".examples a[rel='1']").css("color","#0079C1");
		$("#illustrations > *").hide();
		$("#ill"+illcurrent).show("slide", {}, 1000);
		$(".examples a").click(function() {
			destination = $("#illustrations").offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );

			$('.examples a').css("color","#006F51");
			$(this).css("color","#0079C1");
			illid=$(this).attr("rel");
			if (illid!=illcurrent){
			$("#ill"+illcurrent).hide("slide", { direction: "right" }, 1000, function() {
				illcurrent=illid;
				$("#ill"+illcurrent).show("slide", { direction: "left" }, 1000);
			});
			}
		});

	}
}); 

function valpc(tf){
	if(!checkPostCode(tf.postcode.value)) {
		alert('Please enter a valid postcode');
		return false;
	}
	tf.postcode.value=checkPostCode(tf.postcode.value)
	return true;
	
}
function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  
  // Overseas Territories
  pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  //alert(postCode);
  if (valid) {return postCode;} else return false;
}

function outyear() {
	var time=new Date();
	var year=time.getYear();
	if (year < 2000) {	year = year + 1900; }
	document.write(year);
}