// JavaScript Document
window.onload = showImage;	
// <--------------------------------SLIDE BAR SLIDING CODE START-------------------------------->
       $(function() {
            var offset = $("#sidebarImagebox").offset();
            var topPadding = 20;
            $(window).scroll(function() {
                if ($(window).scrollTop() > offset.top) 
				{
                    $("#sidebarImagebox").stop().animate({marginTop: $(window).scrollTop() - offset.top + topPadding });
                } 
				else 
				{
                    $("#sidebarImagebox").stop().animate({ marginTop: 0});
                };
            });
        });
//<--------------------------------SLIDE BAR SLIDING CODE END-------------------------------->

Date.prototype.getWeek = function() {
  var onejan = new Date(this.getFullYear(),0,1);
  return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
}
var imgList = [
'http://www.sportslined.com/images/header_pic1.jpg', 'http://www.sportslined.com/images/header_pic2.jpg', 'http://www.sportslined.com/images/header_pic3.jpg', 'http://www.sportslined.com/images/header_pic4.jpg', 'http://www.sportslined.com/images/header_pic5.jpg', 'http://www.sportslined.com/images/header_pic6.jpg', 'http://www.sportslined.com/images/header_pic7.jpg', 'http://www.sportslined.com/images/header_pic8.jpg', 'http://www.sportslined.com/images/header_pic9.jpg', 'http://www.sportslined.com/images/header_pic10.jpg', 'http://www.sportslined.com/images/header_pic11.jpg', 'http://www.sportslined.com/images/header_pic12.jpg', 'http://www.sportslined.com/images/header_pic13.jpg', 'http://www.sportslined.com/images/header_pic14.jpg', 'http://www.sportslined.com/images/header_pic15.jpg', 'http://www.sportslined.com/images/header_pic16.jpg', 'http://www.sportslined.com/images/header_pic17.jpg', 'http://www.sportslined.com/images/header_pic18.jpg', 'http://www.sportslined.com/images/header_pic19.jpg', 'http://www.sportslined.com/images/header_pic20.jpg', 'http://www.sportslined.com/images/header_pic21.jpg', 'http://www.sportslined.com/images/header_pic22.jpg', 'http://www.sportslined.com/images/header_pic23.jpg', 'http://www.sportslined.com/images/header_pic24.jpg', 'http://www.sportslined.com/images/header_pic25.jpg', 'http://www.sportslined.com/images/header_pic26.jpg', 'http://www.sportslined.com/images/header_pic27.jpg', 'http://www.sportslined.com/images/header_pic28.jpg', 'http://www.sportslined.com/images/header_pic29.jpg', 'http://www.sportslined.com/images/header_pic30.jpg', 'http://www.sportslined.com/images/header_pic31.jpg', 'http://www.sportslined.com/images/header_pic32.jpg', 'http://www.sportslined.com/images/header_pic33.jpg', 'http://www.sportslined.com/images/header_pic34.jpg', 'http://www.sportslined.com/images/header_pic35.jpg', 'http://www.sportslined.com/images/header_pic36.jpg', 'http://www.sportslined.com/images/header_pic37.jpg', 'http://www.sportslined.com/images/header_pic38.jpg', 'http://www.sportslined.com/images/header_pic39.jpg', 'http://www.sportslined.com/images/header_pic40.jpg', 'http://www.sportslined.com/images/header_pic41.jpg', 'http://www.sportslined.com/images/header_pic42.jpg', 'http://www.sportslined.com/images/header_pic43.jpg', 'http://www.sportslined.com/images/header_pic44.jpg', 'http://www.sportslined.com/images/header_pic45.jpg', 'http://www.sportslined.com/images/header_pic46.jpg', 'http://www.sportslined.com/images/header_pic47.jpg', 'http://www.sportslined.com/images/header_pic48.jpg', 'http://www.sportslined.com/images/header_pic49.jpg', 'http://www.sportslined.com/images/header_pic50.jpg', 'http://www.sportslined.com/images/header_pic51.jpg', 'http://www.sportslined.com/images/header_pic52.jpg', 'http://www.sportslined.com/images/header_pic53.jpg', 'http://www.sportslined.com/images/header_pic54.jpg'	  // Note: No comma after last entry
];
// HEADER WEEKLY IMAGE CHANGE SCRIPT
function showImage() {
  var today = new Date();
  var weekno = today.getWeek();
  document.getElementById('WeeklyImage').src = imgList[weekno];
  document.getElementById('WeeklyImage').alt = imgList[weekno];
//  alert(weekno+'\t'+imgList[weekno]);
}

// TEST JAVASCRIPT 
function abc()
{
alert("Javascript file linked");
}

// FACEBOOK 
$(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

// FOOTER COPYRIGHT DATE 
function footerdate()
{
var d=new Date();
document.write(d.getFullYear());	
}

// <--------------------------------CALCULATION END-------------------------------->

// START FORM VALIDATION 
function validateForm()
{
var x=document.forms["MainOrderForm"]["store"].value
var y=document.forms["MainOrderForm"]["orderby"].value
if (x=="" || y=="")
  {
  alert("Fields must be filled in");
  if (x!="")
  	{ document.getElementById("textfield2").focus(); }
  else
  	{ document.getElementById("textfield").focus(); }
  return false;
  }
}
//<-------------------------------- END FORM VALIDATION -------------------------------->
// START FORM VALIDATION 2
function validateForm2()
{
//alert("test");
var a=document.forms["MainOrderForm"]["storeName"].value;
var b=document.forms["MainOrderForm"]["store"].value;
var c=document.forms["MainOrderForm"]["storePhone"].value;
var d=document.forms["MainOrderForm"]["storeAddress"].value;
var e=document.forms["MainOrderForm"]["zip"].value;
var f=document.forms["MainOrderForm"]["orderby"].value;
var msg = "All Fields are required. Please fill all";
if (!a||!b||!c||!d||!e||!f)
  {
  alert(msg);
	if(!a){ document.getElementById("storeNamefield").focus(); }
	else if(!b){ document.getElementById("storefield").focus(); }
	else if(!c){ document.getElementById("storePhonefield").focus(); }
	else if(!d){ document.getElementById("storeAddressfield").focus(); }
	else if(!e){ document.getElementById("zipfield").focus(); }
	else { document.getElementById("orderbyfield").focus(); }
//	else {}
	return false;
  }
}
//<-------------------------------- END FORM VALIDATION -------------------------------->


// START CALCULATION  
	var bIsFirebugReady = (!!window.console && !!window.console.log);
 
	$(document).ready(
		function (){
			// update the plug-in version
			$("#idPluginVersion").text($.Calculation.version);
 
			// bind the recalc function to the quantity fields
			$("input[name^=qty_item_]").bind("keyup", recalc);
			// run the calculation function now
			recalc();
 
			// automatically update the "#totalSum" field every time
			// the values are changes via the keyup event
			$("input[name^=sum]").sum("keyup", "#totalSum");
			
			// automatically update the "#totalAvg" field every time
			// the values are changes via the keyup event
			$("input[name^=avg]").avg({
				bind:"keyup"
				, selector: "#totalAvg"
				// if an invalid character is found, change the background color
				, onParseError: function(){
					this.css("backgroundColor", "#cc0000")
				}
				// if the error has been cleared, reset the bgcolor
				, onParseClear: function (){
					this.css("backgroundColor", "");
				}
			});
 
			// automatically update the "#minNumber" field every time
			// the values are changes via the keyup event
			$("input[name^=min]").min("keyup", "#numberMin");
 
			// automatically update the "#minNumber" field every time
			// the values are changes via the keyup event
			$("input[name^=max]").max("keyup", {
				selector: "#numberMax"
				, oncalc: function (value, options){
					// you can use this to format the value
					$(options.selector).val(value);
				}
			});
 
			// this calculates the sum for some text nodes
			$("#idTotalTextSum").click(
				function (){
					// get the sum of the elements
					var sum = $(".textSum").sum();
 
					// update the total
					$("#totalTextSum").text("$" + sum.toString());
				}
			);
 
			// this calculates the average for some text nodes
			$("#idTotalTextAvg").click(
				function (){
					// get the average of the elements
					var avg = $(".textAvg").avg();
 
					// update the total
					$("#totalTextAvg").text(avg.toString());
				}
			);
		}
	);
	
	function recalc(){
		$("[id^=total_item]").calc(
			// the equation to use for the calculation
			"qty * price",
			// define the variables used in the equation, these can be a jQuery object
			{
				qty: $("input[name^=qty_item_]"),
				price: $("[id^=price_item_]")
			},
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "$" + s.toFixed(2);
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#gtotal").val("$" + sum.toFixed(2));

$("#grandTotal").text(
					// round the results to 2 digits
					"$" + sum.toFixed(2)
				);
			}
		);
	}
// <--------------------------------CALCULATION END-------------------------------->
function newImageCall(imgCall)
{
//	alert('test');
	switch(imgCall)
{	case(imgCall==1):
	document.getElementById('slideImageSz').images.src='http://www.sportslined.com/images/productImages/cubs/24ctCups.jpg';
	break;
	default:
	{}
//	img_2=new Image;
//	img_2.src='http://www.sportslined.com/images/productImages/cubs/3pcTumbler.jpg';
}
}
function testJS()
{
alert('test');
}
