var disablePage = '';

// append site title to page title
document.title = document.title.indexOf('Perform X Plus')==-1?document.title+' | Perform X Plus':document.title;
// Format Shopping Cart Summary
	/*if(jQuery("#catCartSummary a.cartSummaryLink").length>0){
		var viewCartURL = jQuery("#catCartSummary a.cartSummaryLink").attr("href");
		jQuery("#catCartSummary a.cartSummaryLink").remove();
		jQuery("#catCartSummary .cartSummaryItem").wrapInner("<a href='"+viewCartURL+"' title='View Cart'></a>");
	}*/	
	

// clear the default values of a text field on click
function ClearInput(value, id){ // This calls our function ClearInput, and the two variables we will need for it to function the original value and the id.
	var input = document.getElementById(id); // Gets the input field based on its id.
	if(value == input.value){ // If the default value is equal to the current value.
		input.value = ''; // Empty It.
		input.style.color="#333";
	}else{ // Else the value is not equal to the current input field value.
		input.value = input.value; // Leave it the same.
		input.style.color="#333";
	} // End Else.
} // Close Function.
function RestoreInput(value, id){
	var input = document.getElementById(id);
	if(input.value==''){
		input.value = value;
		input.style.color="#999";
	}
}

/*Function for checking if the user is logged in and subscribed to a secure zone*/		   
function checkSubscription(thisZone){	var json, dateSpace, dateString, dateElem, newDateStr, thisDate, thisYear,thisMonth, thisDay, todaysDate, todaysYear, todaysMonth, todaysDay;var zoneValid = false;if(isLoggedIn=='1' && subscriptionList.indexOf('{')!=-1){json = jsonParse(subscriptionList);$.each(json.SecureZoneSubscriptionList.Subscriptions, function(i, secureZone) {if(secureZone.ZoneId==thisZone){dateSpace = secureZone.ExpiryDate.indexOf(' ');dateString = secureZone.ExpiryDate.substring(0,dateSpace);dateElem = dateString.split('/');newDateStr = (dateElem[0].length==1?'0'+dateElem[0]:(dateElem[0].length<1?'00':dateElem[0])) +'/'+ (dateElem[1].length==1?'0'+dateElem[1]:(dateElem[1].length<1?'00':dateElem[1])) +'/'+ dateElem[2];thisDate = new Date(newDateStr);thisYear = parseInt(thisDate.getFullYear());thisMonth = parseInt(thisDate.getMonth()) + 1;thisDay = parseInt(thisDate.getDate());todaysDate = new Date();todaysYear = parseInt(todaysDate.getFullYear());todaysMonth = parseInt(todaysDate.getMonth()) + 1;todaysDay = parseInt(todaysDate.getDate());if(thisYear>todaysYear){zoneValid=true;return false;}else if(thisYear==todaysYear){if(thisMonth>todaysMonth){zoneValid=true;return false;}else if(thisMonth==todaysMonth){if(thisDay>=todaysDay){zoneValid = true;return false;}}}}});}if(zoneValid){return true;}else{return false;}}


// preload rollover images
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_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_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];}
}
// Popup Window Fuction
function popupWin(url,name,width,height){
	window.open(url,name,"menubar=no,innerWidth="+width+",width="+width+",height="+height+",innerHeight="+height+",toolbar=no,scrollbars=no,status=no,resizable=no,screenX=200,screenY=100,directories=no");
}


/* Gets the current year for copyright info */
function writeCurrentYear(){
  var date = new Date();
  document.write(date.getFullYear());
}

// currency formatting
function tryNumberFormat(obj)
{
	obj.value = new NumberFormat(obj.value).toFormatted();
}

//used to remove a token substring from a string
function remove(s, t) {
/*
**    s  string to be processed
**    t  token to be removed
**  returns new */
i = s.indexOf(t);
r = "";
if (i == -1) return s;
r += s.substring(0,i) + remove(s.substring(i + t.length), t);
return r;
}  


jQuery(document).ready(function(){

	jQuery("#mainNav a").each(function(){
		if(jQuery(this).parent().hasClass('selected')){
			jQuery(this).css({'background-position':'0px -52px','cursor':'default'});
			
			jQuery(this).mouseover(function(){
				jQuery(this).css({'background-position':'0px -52px','cursor':'default'});
			});
			jQuery(this).mouseout(function(){
				jQuery(this).css({'background-position':'0px -52px','cursor':'default'});
			});
		}else{
			jQuery(this).mouseover(function(){
				jQuery(this).css('background-position','0px -26px');
			});
			jQuery(this).mouseout(function(){
				jQuery(this).css('background-position','0px 0px');
			});
		}
	});
	
	jQuery('#mainLogo').click(function(){
		window.location = "/";								   
	});
});


jQuery(document).ready(function(){ 

	// Find all LeftFloatImage items and remove the span around them.
	jQuery('p span.LeftFloatCaption').removeClass('LeftFloatCaption').parent().addClass('LeftFloatCaption');
	jQuery('p img.LeftFloatImage').removeClass('LeftFloatImage').parent().addClass('LeftFloatImage');
	// style LeftFloatImage image captions
	jQuery('.LeftFloatImage').each(function(){
		// if image is wider than 200px, adjust to 200
		if(jQuery(this).width()>200){
			jQuery(this).each(function() {
				var maxWidth = 200; // Max width for the image
				var maxHeight = 500;    // Max height for the image
				var ratio = 0;  // Used for aspect ratio
				var width = jQuery(this).width();    // Current image width
				var height = jQuery(this).height();  // Current image height
		 
				// Check if the current width is larger than the max
				if(width > maxWidth){
					ratio = maxWidth / width;   // get ratio for scaling image
					jQuery(this).css("width", maxWidth); // Set new width
					jQuery(this).css("height", height * ratio);  // Scale height based on ratio
					height = height * ratio;    // Reset height to match scaled image
					width = width * ratio;    // Reset width to match scaled image
				}
				// Check if current height is larger than max
				if(height > maxHeight){
					ratio = maxHeight / height; // get ratio for scaling image
					jQuery(this).css("height", maxHeight);   // Set new height
					jQuery(this).css("width", width * ratio);    // Scale width based on ratio
					width = width * ratio;    // Reset width to match scaled image
				}
			});			
		}
		// Remove any P tags surrounding the image
		//jQuery(this).unwrap();
		/*if(this.parentNode.tagName=="P"){
			var thisImg = jQuery(this).parent().html();
			jQuery(this).parent().replaceWith(thisImg);
		}*/
		// detect if it has a caption P and wrap the img+caption(s) with a div
		if(jQuery(this).next().hasClass('LeftFloatCaption')){
			//alert(jQuery(this).next('p.LeftFloatImage').length);
			jQuery(this).adjAfter('.LeftFloatCaption').wrapAll('<div class="LeftFloatDiv"/>');
		}else{// if no caption, just wrap the img with a div
			jQuery(this).wrapAll('<div class="LeftFloatDiv"/>');	
			//alert(jQuery(this).next('p.LeftFloatImage').length);
		}
	});
});
	
/**
 * jQuery Adjacent plugin
 *
 * Selects all elements consecutively adjacent to the current element which match the given filter.
 *
 * Usage: eg: Find all the elements with class "foo" next to the #active element:
 * jQuery('#active').adjacent('.foo');
 *
 *                                   SELECTED?
 * <p class="foo"></p>                  no
 * <p></p>                              no
 * <p class="foo"></p>                  yes
 * <p class="foo"></p>                  yes
 * <p class="foo" id="active"></p>      yes
 * <p class="foo"></p>                  yes
 * <p></p>                              no
 * <p class="foo"></p>                  no
 * <p class="foo"></p>                  no
 *
 *
 * Note that this will select the current item even if it doesn't match the filter itself.
 */

jQuery.fn.adjAfter = function(filter) {
    var $all = this;

    /*for (var $curr = this.prev(filter); $curr.length > 0; $curr = $curr.prev(filter)) {
        $all = $all.add($curr);
    }*/
    for (var $curr = this.next(filter); $curr.length > 0; $curr = $curr.next(filter)) {
        $all = $all.add($curr);
    }
    return $all;
};	

jQuery.fn.adjBefore = function(filter) {
    var $all = this;

    for (var $curr = this.prev(filter); $curr.length > 0; $curr = $curr.prev(filter)) {
        $all = $all.add($curr);
    }
    /*for (var $curr = this.next(filter); $curr.length > 0; $curr = $curr.next(filter)) {
        $all = $all.add($curr);
    }*/
    return $all;
};	

jQuery.fn.adjacent = function(filter) {
    var $all = this;

    for (var $curr = this.prev(filter); $curr.length > 0; $curr = $curr.prev(filter)) {
        $all = $all.add($curr);
    }
    for (var $curr = this.next(filter); $curr.length > 0; $curr = $curr.next(filter)) {
        $all = $all.add($curr);
    }
    return $all;
};	
