// JScript File

$(function(){

var sTop = $(document).scrollTop(); 
var wHeight = document.documentElement.clientHeight;
var FeedBackHeight = $("#fdbk_tab").height();
var posi = wHeight + sTop - FeedBackHeight;
$("#fdbk_tab").css("top",posi);

$("#NewIn").hover(function(){
$("#NewInMenu").show();
},function(){
$("#NewInMenu").hide();
});

$("#NewInMenu").hover(function(){
$("#NewInMenu").show();
},function(){
$("#NewInMenu").hide();
});

$("#Valentine").hover(function(){
$("#ValentineMenu").show();
},function(){
$("#ValentineMenu").hide();
});

$("#ValentineMenu").hover(function(){

$("#ValentineMenu").show();
},function(){

$("#ValentineMenu").hide();
});

$("#BathRoom").hover(function(){
$("#BathRoomMenu").show();
},function(){
$("#BathRoomMenu").hide();
});

$("#BathRoomMenu").hover(function(){
$("#BathRoomMenu").show();
},function(){
$("#BathRoomMenu").hide();
});

$("#BedRoom").hover(function(){
$("#BedRoomMenu").show();
},function(){
$("#BedRoomMenu").hide();
});

$("#BedRoomMenu").hover(function(){
$("#BedRoomMenu").show();
},function(){
$("#BedRoomMenu").hide();
});

$("#LicensedBrands").hover(function(){
$("#LicensedBrandsMenu").show();
},function(){
$("#LicensedBrandsMenu").hide();
});

$("#LicensedBrandsMenu").hover(function(){
$("#LicensedBrandsMenu").show();
},function(){
$("#LicensedBrandsMenu").hide();
});

$("#Gifts").hover(function(){
$("#GiftsMenu").show();
},function(){
$("#GiftsMenu").hide();
});

$("#GiftsMenu").hover(function(){
$("#GiftsMenu").show();
},function(){
$("#GiftsMenu").hide();
});

$("#Offers").hover(function(){
$("#OffersMenu").show();
},function(){
$("#OffersMenu").hide();
});

$("#OffersMenu").hover(function(){
$("#OffersMenu").show();
},function(){
$("#OffersMenu").hide();
});

var ShowFilter = false;
$("#category_left_filter_title_Michael").click(function(){
$("#category_left_filter_bg_Michael").css("background","url(./Skins/skin_1/images/menu_bg.png)");
$("#category_left_filter_content_Michael").show();
if(!ShowFilter)
{
ShowFilter = !ShowFilter;

var totalheight = $(".category_content_bg_center_Michael").height() + $(".template_innveroutdiv_Michael").height() + 35;
$("#category_left_filter_bg_Michael").animate({
                                      height: totalheight
},300);
}
else
{
ShowFilter = !ShowFilter;
 $("#category_left_filter_bg_Michael").animate({
                                      height: "25px"
},300,function(){$("#category_left_filter_bg_Michael").css("background","none");});

}
});


$("#product_movie_moreimages").click(function(){
$("#product_small_icons_Michael").toggle(400);
});

$("#product_movie_play").click(function(){

$("#productmovie").show();
$("#movieinneritem").show();
$("#productmovie").animate({
               width: "425px",
               height: "424px",
               left: "334px",
               top: "-327px"
               },300);
$("#movieinneritem embed").animate({
               width: "410px",
               height: "410px"
               },300);
               
$("#movieinneritem object").animate({
               width: "410px",
               height: "410px"
               },300);
if($.browser.msie){movie.Play();}
});

$("#product_movie_stop").click(function(){
if($.browser.msie){movie.Rewind()};
$("#productmovie").animate({
               width: "1",
               height: "1",
               left: "0",
               top: "0"
               },300,function(){$("#productmovie").hide();});
$("#movieinneritem embed").animate({
               width: "0px",
               height: "0px"
               },300,function(){$("#movieinneritem").hide();});
               
$("#movieinneritem object").animate({
               width: "0px",
               height: "0px"
               },300,function(){$("#movieinneritem").hide();});
               

});


/*
$("#product_movie2_moreimages").click(function() {
	// $("#palletcontent").hide(200);
    $("#palletcontent").animate({width: 'toggle'}, 200, function () {
	    // $("#product_small_icons_Michael").slideToggle(200);
		$("#product_small_icons_Michael").animate({width: 'toggle'});
	});
});
*/

$("#product_movie2_play").click(function(){

$("#productmovie").show();
$("#movieinneritem").show();
$("#productmovie").animate({
               width: "425px",
               height: "424px",
               left: "534px",
               top: "-327px"
               },300);
$("#movieinneritem embed").animate({
               width: "410px",
               height: "410px"
               },300);
               
$("#movieinneritem object").animate({
               width: "410px",
               height: "410px"
               },300);
if($.browser.msie){movie.Play();}
});

$("#product_movie2_stop").click(function(){
if($.browser.msie){movie.Rewind()};
$("#productmovie").animate({
               width: "1",
               height: "1",
               left: "0",
               top: "0"
               },300,function(){$("#productmovie").hide();});
$("#movieinneritem embed").animate({
               width: "0px",
               height: "0px"
               },300,function(){$("#movieinneritem").hide();});
               
$("#movieinneritem object").animate({
               width: "0px",
               height: "0px"
               },300,function(){$("#movieinneritem").hide();});
               

});


/*$("#palletpart").click(function() {
	console.log($("#product_small_icons_Michael").attr('width'));
	
	// $("#product_small_icons_Michael").hide(200);
	$("#product_small_icons_Michael").animate({width: 'toggle'}, 400, function () {
		//$("#palletcontent").slideToggle(200);
		$("#palletcontent").animate({width: 'toggle'});
	});	
});*/

//Ajax Find Product


var preparewidth = $(".MagicZoom img").width();
if(preparewidth > 500)
{
$(".product_play2_bg_Michael").css("width",preparewidth);
}
else
{
$(".product_play2_bg_Michael").css("width","500");
}


$("#AddtoBasket").click(function(){
var i = 0;
$("select[id^=selectQuantity_]").each(function(){
 if(this.options[0].value != "-")
 {
   var ID = this.id.replace("selectQuantity_","");
   var FL = $("#ProductIDVariantID_"+ID).val();
   $(this).attr("name","Qty"+FL+document.getElementById("selectColor_"+ID).selectedIndex+"_0");
   i++;
 }
});

if(i == 0)
{
  alert('No Product Selected.');
  return false;
}
else
{
  document.forms["TableOrderForm"].submit();
}
});


$("#AddItemtoBasket").click(function(){
var i = 0;
$("select[id^=selectQuantity_]").each(function(){
 if(this.value != "-")
 {
   var ID = this.id.replace("selectQuantity_","");
   if(document.getElementById("selectColor_"+ID).value != "-")
   {
     var FL = $("#ProductIDVariantID_"+ID).val();
     $(this).attr("name","qty"+FL+(document.getElementById("selectColor_"+ID).selectedIndex-1)+"_0");
     i++;
   }
 }
});

if(i == 0)
{
  alert('No Product Selected.');
  return false;
}
else
{
  document.forms["TableOrderForm"].submit();
}
});



//bedline product
$("#AddBedLinetoBasket").click(function(){

var i = 0;
$("select[id^=selectQuantity_]").each(function(){
 if(this.value != "-")
 {
   var ID = this.id.replace("selectQuantity_","");
   var VariantID = document.getElementById("VariantList_"+ID).value;
   if(document.getElementById("selectColor_"+ID).value != "-")
   {
     var FL = '_'+CollectProductID+'_'+VariantID+'_';
     $(this).attr("name","qty"+FL+(document.getElementById("selectColor_"+ID).selectedIndex-1)+"_0");
     i++;
   }
 }
});

if(i == 0)
{
  alert('No Product Selected.');
  return false;
}
else
{
  document.forms["TableOrderForm"].submit();
}
});




$("input[id^=txtCatID_]").each(function(){

$(this).focus(function(){
$(this).keydown(function(e){
 if(e.keyCode == 13)
	{
	var n = this.id.replace("txtCatID_","");
	$("#FindCatID_"+n).click();
	return false;
	}
});
});

})




//Mini Shopping Cart
$("#shoppingcart_icon_Michael").click(function(){
$("#MiniShoppingCart").toggle(300);
});

//Mini Shopping Cart workaround!
$("#shoppingcart_icon_Adrian").click(function(){
$("#MiniShoppingCart").toggle(300);
});

$("#CloseMinicart").click(function(){
$("#MiniShoppingCart").hide(300);
});


//var updown = false;
//$("#Product_Size_Price_Link_Michael").click(function(){
//alert('asdfasdf');
//updown = !updown;
//if(updown)
//{
// $("#Product_Size_Price_Link_Michael").removeClass("Product_Size_Price_Link_1_Michael");
// $("#Product_Size_Price_Link_Michael").addClass("Product_Size_Price_Link_2_Michael");
//}
//else
//{
//$("#Product_Size_Price_Link_Michael").removeClass("Product_Size_Price_Link_2_Michael");
//$("#Product_Size_Price_Link_Michael").addClass("Product_Size_Price_Link_1_Michael");
//}
//$("#Price_Table_Content").toggle(200);

//});


var colorpricetablewidth = $("#Price_Table_Content").width();
if(colorpricetablewidth > 578)
{
 $("#Price_Table_Content").css("left",578 - colorpricetablewidth);
}

});

function showandhidepricetable()
{
	$("#ChartTable").css("width",$(document).width());
	$("#ChartTable").css("height",$(document).height());
	$("#ChartTable").show();
	
	var scrollTop = $(document).scrollTop(); 
	var scrollLeft = $(document).scrollLeft();
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#sizecolortableoutdiv").height();
	var popupWidth = $("#sizecolortableoutdiv").width();
		
	// browser sniffing for fixed bug
	// var topPos = $.browser.opera || $.browser.mozilla? (windowHeight/2)-popupHeight + scrollTop : (windowHeight/2)-(popupHeight/2) + scrollTop;
	var topPos = (windowHeight/2)-(popupHeight/2) + scrollTop;
	
	$("#sizecolortableoutdiv").css({
		"position": "absolute",
		"top": topPos,
		"left": (windowWidth/2)-(popupWidth/2) + scrollLeft
	});
	
	var p1;
	
	if($('.Product_Color_Size_Table_Michael').width() < 1024) {
		p1 = windowWidth/2 + $('.Product_Color_Size_Table_Michael').width()/2 + scrollLeft - 41;
	} else {
		p1 = windowWidth/2 + 512 + scrollLeft - 41;
	}
	
	$('#XXX').css({
		"position":"absolute",
		"z-index":"999999999",
		"top": topPos + popupHeight,
		"left":p1
	});
	
	$("body").css("overflow","hidden"); 

}

function ClosePopTable()
{
  $("#ChartTable").hide();
  $("body").css("overflow","auto");
}

function CloseReviewPopTable()
{
  $("#ReviewTable").hide();
  $("body").css("overflow","auto");
}

function HidePopDiv()
{
 $("#CompleteTable").hide();
 $("body").css("overflow","auto");
}

function showandhideBedLinepricetable(ID)
{
  $("#"+ID).css("width",$(document).width());
  $("#"+ID).css("height",$(document).height());
  $("#"+ID).show();
}

function CloseBedLinePopTable(ID)
{
  $("#"+ID).hide();
}

function showandhidereviewtable()
{
	$("#ReviewTable").css("width",$(document).width());
	$("#ReviewTable").css("height",$(document).height());
	$("#ReviewTable").show();
	
	$("body").css("overflow","hidden");
	
	repositionReviewTable();	
}

function repositionReviewTable()
{
	var scrollTop = $(document).scrollTop(); 
	var scrollLeft = $(document).scrollLeft();
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(".Review_table_Border_Michael").height();
	var popupWidth = $(".Review_table_Border_Michael").width();
	
	$(".Review_table_Border_Michael").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2 + scrollTop,
		"left": windowWidth/2-popupWidth/2 + scrollLeft
	});
}

function showandhidecompletetable()
{
	$("#CompleteTable").css("width",$(document).width());
	$("#CompleteTable").css("height",$(document).height());
	$("#CompleteTable").show();
	
	$("body").css("overflow","hidden");
	
	repositionCompleteTable();	
}

function repositionCompleteTable()
{
	var scrollTop = $(document).scrollTop(); 
	var scrollLeft = $(document).scrollLeft();
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(".Complete_table_Border_Michael").height();
	var popupWidth = $(".Complete_table_Border_Michael").width();
	
	$(".Complete_table_Border_Michael").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2 + scrollTop,
		"left": windowWidth/2-popupWidth/2 + scrollLeft
	});
}




//Page Height
function pageHeight(){
if($.browser.msie){
return document.compatMode == "CSS1Compat"? document.documentElement.clientHeight :
document.body.clientHeight;
}else{
return self.innerHeight;
}
}

function pageWidth(){
if($.browser.msie){
return document.compatMode == "CSS1Compat"? document.documentElement.clientWidth :
document.body.clientWidth;
}else{
return self.innerWidth;
}
}


var LineNumber = 6;
function addnewline(currency)
{
LineNumber = LineNumber + 1;
var AppendContent = "<tr class=\"quickorder_content_Michael\"><td><div class=\"quick_clear_Michael\" id=\"quick_clear_"+LineNumber+"\" onclick=\"ResetDetailLine(this,'"+LineNumber+"')\"></div></td><td><div id=\"txtVariantName_"+LineNumber+"\"></div><input id=\"txtCatID_"+LineNumber+"\" class=\"quick_textbox_Michael\" type=\"text\">&nbsp;<input id=\"FindCatID_"+LineNumber+"\" onclick=\"startAjax(this)\" class=\"quick_findbt_Michael\" type=\"button\"></td><td><select id=\"selectColor_"+LineNumber+"\" class=\"quick_color_Michael\"><option>No Product Selected</option></select></td><td><select id=\"selectQuantity_"+LineNumber+"\" onchange=\"ChangeLineTotal('"+LineNumber+"')\" class=\"quick_quantity_Michael\"><option value=\"-\">-</option></select></td><td><div>"+currency+"<span id=\"Price_"+LineNumber+"\"></span></div></td><td><div>"+currency+"<span id=\"Total_"+LineNumber+"\"></span></div></td></tr>";
$("#AjaxFindProduct").append(AppendContent);
}




//Ajax Find Product


function startAjax(obj)
{
  var btID = obj.id;
  var ID = btID.replace("FindCatID_","");
  showproductdetail(ID);
}

function showproductdetail(boxID)
{
  var content = $("#txtCatID_"+boxID).val();
  if(content.length == 0)
  {
   alert("Please enter Catalogue ID.");
   return false;
  }
  else
  {
   var number = Math.random();
   number = number * 1000000000;
   number = Math.ceil(number);
  
	$.ajax({
	type:"GET",
	url:"AjaxProductDetail.aspx?CatID="+content,
	data:"&number="+number,
	dataType:"html",
	success:function(myContent)
	{
	    if(myContent.length == 0)
	    {
	      alert('No Products Found');
	      return false;
	    }
	    var ProductID = $(myContent).find("#AjaxProductID").html();
	    var VariantID = $(myContent).find("#AjaxVariantID").html();
	    var Quantities = $(myContent).find("#AjaxQuantity").html();
	    var Price = Number($(myContent).find("#AjaxPrice").html());
	    var VariantName = $(myContent).find("#AjaxVariantName").html();
	    var Colors = $(myContent).find("#AjaxColor").html();
	   
	    $("#ProductIDVariantID_"+boxID).val("_"+ProductID+"_"+VariantID+"_");
	    $("#txtVariantName_"+boxID).html(VariantName);
		resetColorOption("selectColor_"+boxID,Colors);
		resetQuantityOption("selectQuantity_"+boxID,Quantities);
		$("#Price_"+boxID).html(Price.toFixed(2));
		$("#Total_"+boxID).html(Price.toFixed(2));
	}
	});
  }
}


function resetColorOption(ID,Colors)
{
 var Box = document.getElementById(ID);

 for(var j = 1;j != Box.options.length;)
 {
   Box.options[Box.options.length - 1] = null;
 }
 var colorArray = new Array();
 colorArray = Colors.split(",");
 for(var i = 0; i < colorArray.length ; i ++)
 {
   var oOption = new Option(colorArray[i],colorArray[i]);
   Box.options[i] = oOption;
 }
}


function resetQuantityOption(ID,Quantities)
{
 var Box = document.getElementById(ID);

 for(var j = 1;j != Box.options.length;)
 {
   Box.options[Box.options.length - 1] = null;
 }
 if(Quantities.length == 0)
 {
  var oOption = new Option("1","1");
  Box.options[0] = oOption;
 }
 else
 {
  var quantityArray = new Array();
  quantityArray = Quantities.split(",");
  for(var i = 0; i < quantityArray.length ; i ++)
  {
    var oOption = new Option(quantityArray[i],quantityArray[i]);
    Box.options[i] = oOption;
  }
 }
}


function ResetDetailLine(obj,num)
{
  $("#txtVariantName_"+num).html("");
  $("#txtCatID_"+num).val("");
  $("#Price_"+num).html("");
  $("#Total_"+num).html("");

  var Box = document.getElementById("selectColor_"+num);

  for(var j = 1;j != Box.options.length;)
  {
    Box.options[Box.options.length - 1] = null;
  }
  
  var oOption = new Option("No Product Selected","");
  Box.options[0] = oOption;
  
  var Box2 = document.getElementById("selectQuantity_"+num);
  for(var i = 1;i != Box2.options.length;)
  {
    Box2.options[Box2.options.length - 1] = null;
  }
  var oOption2 = new Option("-","-");
  Box2.options[0] = oOption2;
  
  
}


function ChangeLineTotal(num)
{
  var singleprice = $("#Price_"+num).html().substring(0,$("#Price_"+num).html().length);
  var Qunatity = Number($("#selectQuantity_"+num).val());
  $("#Total_"+num).html((Qunatity * singleprice).toFixed(2));
}



function showproductinfo(productid)
{
$("#cate_"+productid).show();
}

function hideproductinfo(productid)
{
$("#cate_"+productid).hide();
}

function changecategoryproductimage(imageid,productimageid)
{ 
   var iid = eval(imageid);
   $("#"+productimageid).attr("src",iid);

}

function changeproductpageproductimage(imageid)
{
   var iid = eval(imageid);
   $("#ProductPicOutATag").attr("href",iid);
   $("#ProductPicOutATag img").attr("src",iid);
}

function changeproductpageproductimagefromown(mediumimagepath,largeimagepath)
{   
   $("#ProductPicOutATag").attr("href",largeimagepath);
   $("#ProductPicOutATag img").attr("src",mediumimagepath);
}



function MoreImageMove(direction)
{

  if(direction == 'left')
  {
   var divwidth = $("#imagegroupdiv").width();
   var groupwidth = $("#imageitemdiv").width();
   var divoffset = $("#imagegroupdiv").offset();
   var groupoffset = $("#imageitemdiv").offset();
   var divoffsetleft = divoffset.left;
   var groupoffsetleft = groupoffset.left;
   var l = String($("#imageitemdiv")[0].style.left).replace('px','');
   var ll = Number(l);

   if( (groupwidth + groupoffsetleft) - 50 < (divoffsetleft + divwidth))
   {
    $("#imageitemdiv").animate({
			left: ll - ((groupwidth + groupoffsetleft) - (divoffsetleft + divwidth))
		},500);
   }
   else
   {
   
    $("#imageitemdiv").animate({
			left: ll - 50
		},500);
   }
  }
  
  if(direction == 'right')
  {
   var divwidth = $("#imagegroupdiv").width();
   var groupwidth = $("#imageitemdiv").width();
   var divoffset = $("#imagegroupdiv").offset();
   var groupoffset = $("#imageitemdiv").offset();
   var divoffsetleft = divoffset.left;
   var groupoffsetleft = groupoffset.left;
   var l = String($("#imageitemdiv")[0].style.left).replace('px','');
   var ll = Number(l);

   if( groupoffsetleft + 45 > divoffsetleft)
   {
    $("#imageitemdiv").animate({
			left: (ll + (divoffsetleft - groupoffsetleft))
		},500);
   }
   else
   {
    $("#imageitemdiv").animate({
			left: (ll + 47)
		},500);
   }
  }
}

function ShowPalletName(content)
{
 $("#PalletColorName").html(content);
}

function ChangePriceLabel(quantity,character)
{
  if(Number(quantity) == -1)
  {
    quantity = 1;
  }
  var total = Number(quantity) * Number($("#rememberprice").val());
  var singleprice = Number($("#rememberprice").val());
  $("#currentprice").html(quantity + " x " + character + singleprice.toFixed(2) + " = " + character + total.toFixed(2));
}



//Product Ajax

function ajaxFunction()
 {
 var xmlHttp;
 
 try
    {
   // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
 catch (e)
    {

  // Internet Explorer
   try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
   catch (e)
      {

      try
         {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
         }
      catch (e)
         {
         alert("Not support Ajax.");
         return false;
         }
      }
    }
	return xmlHttp;
}

function GetAddtoCart(ProductID,VariantID,currencycode)
{
   xmlhttp = new ajaxFunction();
   xmlhttp.onreadystatechange=function()
   {
   	if(xmlhttp.readyState==4)
	{
		if(xmlhttp.status==200)
		{
		  if(xmlhttp.responseText.indexOf("!!!Error!!!") > -1)
		  {
		    alert('Load Error! Please refresh this page!');
		    return false;
		  }
		  else
		  {
		    $("#AddtoCartField").html(xmlhttp.responseText);
		    $("#rememberprice").val(eval('PriceRemember_'+VariantID));
		    $("#currentprice").html(currencycode + eval('PriceRemember_'+VariantID).toFixed(2));
		  }
		}
	}
   }
   var number = Math.random(); 
   number = number * 1000000000;
   number = Math.ceil(number);
   
   url="GetAddtoCart.aspx?ProductID="+ProductID+"&VariantID="+VariantID+"&number="+number;
   xmlhttp.open('GET',url,true);
   xmlhttp.send(null);
}


function ValidateEmailAddress(EA)
{
	//var reg = /^([_a-z0-9-]+)([.'_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,6})$/i;
	var reg = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
	
	if (!reg.test(EA)) {
		alert('Please enter your email address!');
		return false;
	}
	return true;
}

//bedline product
function refreshquantity(VariantListID,m)
{
  var VariantID = document.getElementById(VariantListID).value;
  /*
  var QuantityList = eval("QuantityList_"+VariantID);
  var QuantityArray = new Array();
  QuantityArray = QuantityList.split(',');
  var QuantityObj = document.getElementById("selectQuantity_"+m);
  
  for(var j = 1;j != QuantityObj.options.length;)
  {
    QuantityObj.options[QuantityObj.options.length - 1] = null;
  }
  
  for(var i = 0;i < QuantityArray.length; i++)
  {
    var oOption = new Option(QuantityArray[i],QuantityArray[i]);
    QuantityObj.options[i+1] = oOption;
  }
  */
  
  $("#PriceCol_"+m).html(eval("CollectSpec_"+VariantID) + eval("CollectPrice_"+VariantID));
  
  var msrppricestr = eval("CollectMSRP_"+VariantID);
  if(msrppricestr != '0')
  {
  $("#MSRPCol_"+m).html(eval("CollectSpec_"+VariantID) + msrppricestr);
  }
  else
  {
   $("#MSRPCol_"+m).html('');
  }
  
  
	var colours = eval("CollectColors_" + VariantID);
	var colourArray = colours.split(',');
    
    var ColourObj = document.getElementById("selectColor_"+m);
	for(var j = 1;j != ColourObj.options.length;)
	{
		ColourObj.options[ColourObj.options.length - 1] = null;
	}
	
	for(var i = 0;i < colourArray.length; i++)
	{
		var oOption = new Option(colourArray[i],colourArray[i]);
		ColourObj.options[i+1] = oOption;
	}
}

function Poprefreshquantity(VariantListID,m)
{
  var VariantID = document.getElementById(VariantListID).value;
  var QuantityList = eval("PopQuantityList_"+VariantID);
  var QuantityArray = new Array();
  QuantityArray = QuantityList.split(',');
  var QuantityObj = document.getElementById("PopselectQuantity_"+m);
  
  for(var j = 1;j != QuantityObj.options.length;)
  {
    QuantityObj.options[QuantityObj.options.length - 1] = null;
  }
  
  for(var i = 0;i < QuantityArray.length; i++)
  {
    var oOption = new Option(QuantityArray[i],QuantityArray[i]);
    QuantityObj.options[i+1] = oOption;
  }
  
  $("#PopPriceCol_"+m).html(eval("PopCollectSpec_"+VariantID) + eval("PopCollectPrice_"+VariantID));
  
  var msrppricestr = eval("PopCollectMSRP_"+VariantID);
  if(msrppricestr != '0')
  {
  $("#PopMSRPCol_"+m).html(eval("PopCollectSpec_"+VariantID) + msrppricestr);
  }
  else
  {
   $("#PopMSRPCol_"+m).html('');
  }
  
}


//Pop
function BLAddBedLinetoBasketClick(PID,FormID)
{

 var ss = document.forms[FormID].getElementsByTagName("select");
 var j = 0;
 for(var i = 0;i<ss.length;i++)
 {
  if(ss[i].id.indexOf("BLselectQuantity_") > -1)
  {
   if(ss[i].value != "-")
   {
    var ID = ss[i].id.replace("BLselectQuantity_","");
    var VariantID = document.forms[FormID].elements["BLVariantList_"+ID].value;
    if(document.forms[FormID].elements["BLselectColor_"+ID].value != "-")
    {
      var FL = '_'+PID+'_'+VariantID+'_';
      $("#"+ss[i].id).attr("name","qty"+FL+(document.forms[FormID].elements["BLselectColor_"+ID].selectedIndex-1)+"_0");
      j++;
    }
   }
  }
 }


if(j == 0)
{
  alert('No Product Selected.');
  return false;
}
else
{
  document.forms[FormID].submit();
}

}

function BLrefreshquantity(VariantListID,m)
{
  var VariantID = document.getElementById(VariantListID).value;
  var QuantityList = eval("BLQuantityList_"+VariantID);
  var QuantityArray = new Array();
  QuantityArray = QuantityList.split(',');
  var QuantityObj = document.getElementById("BLselectQuantity_"+m);
  
  for(var j = 1;j != QuantityObj.options.length;)
  {
    QuantityObj.options[QuantityObj.options.length - 1] = null;
  }
  
  for(var i = 0;i < QuantityArray.length; i++)
  {
    var oOption = new Option(QuantityArray[i],QuantityArray[i]);
    QuantityObj.options[i+1] = oOption;
  }
  
  $("#BLPriceCol_"+m).html(eval("BLCollectSpec_"+VariantID) + eval("BLCollectPrice_"+VariantID));
  
  msrppricestr = eval("BLCollectMSRP_"+VariantID);
  if(msrppricestr != '0')
  {
   $("#BLMSRPCol_"+m).html(eval("BLCollectSpec_"+VariantID) + msrppricestr);
  }
  else
  {
   $("#BLMSRPCol_"+m).html('');
  }
  
}

function NormalAddBedLinetoBasketClick(PID,FormID)
{
	var ss = document.forms[FormID].getElementsByTagName("select");
	var j = 0;
	for(var i = 0;i<ss.length;i++) {
		if(ss[i].id.indexOf("NormalselectQuantity_") > -1) {
			if(ss[i].value != "-") {
				var ID = ss[i].id.replace("NormalselectQuantity_","");
				var VariantID = ID;
				if(document.forms[FormID].elements["NormalselectColor_"+ID].value != "-") {
					var FL = '_'+PID+'_'+VariantID+'_';
					$("#"+ss[i].id).attr("name","qty"+FL+(document.forms[FormID].elements["NormalselectColor_"+ID].selectedIndex-1)+"_0");
					j++;
				}
			}
		}
	}
		
	if(j == 0) {
		alert('No Product Selected.');
		return false;
	} else {
		document.forms[FormID].submit();
	}
}




function PopAddBedLinetoBasketClick(PID,FormID)
{

 var ss = document.forms[FormID].getElementsByTagName("select");
 var j = 0;
 for(var i = 0;i<ss.length;i++)
 {
  if(ss[i].id.indexOf("PopselectQuantity_") > -1)
  {
   if(ss[i].value != "-")
   {
    var ID = ss[i].id.replace("PopselectQuantity_","");
    var VariantID = document.forms[FormID].elements["PopVariantList_"+ID].value;
    if(document.forms[FormID].elements["PopselectColor_"+ID].value != "-")
    {
      var FL = '_'+PID+'_'+VariantID+'_';
      $("#"+ss[i].id).attr("name","qty"+FL+(document.forms[FormID].elements["PopselectColor_"+ID].selectedIndex-1)+"_0");
      j++;
    }
   }
  }
 }


if(j == 0)
{
  alert('No Product Selected.');
  return false;
}
else
{
  document.forms[FormID].submit();
}

}

function ReloadField1(num)
{
	$("div[id^=RangeField_]").each(function() {
		$(this).hide();
	});
	
	$("div[id^=PopField_]").each(function() {
		$(this).hide();
	});
	
	$("#RangeField_"+num).show();
}

function ReloadField2(num)
{
	$("div[id^=RangeField_]").each(function() {
		$(this).hide();
	});
	
	$("div[id^=PopField_]").each(function() {
		$(this).hide();
	});
	
	$("#PopField_"+num).show();
	
	repositionCompleteTable();
}

function needhelp()
{
 $("#needhelp_bg_Michael").css("width",$(document).width());
 $("#needhelp_bg_Michael").css("height",$(document).height());
 $("#needhelp_bg_Michael").show();
}

function CloseNeedHelp()
{
 $("#needhelp_bg_Michael").hide();
}


//Category Fitler



function ToggleCollection(Collection)
{

var CateTD = document.getElementById('CategoryTable').getElementsByTagName('td');
 for(var j = 0;j<CateTD.length;j++)
 {
   if($(CateTD[j]).attr("name") != null)
   {
     if($(CateTD[j]).attr("name") == "ProductTD")
     {
      PName = $(CateTD[j]).attr("id");
      PID = PName.replace("ProductTD_","");
      
      if(Collection != "##MISAKKO##")
      {
      TotalCollection = "," + eval("Product_Collection_"+PID) + ",";
      if(TotalCollection.indexOf(","+Collection+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      if(CurrentFilterSize.length != 0)
      {
      TotalFilterSize = "," + eval("Product_FilterSize_"+PID) + ",";
      if(TotalFilterSize.indexOf(","+CurrentFilterSize+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      if(CurrentGroup.length != 0)
      {
      TotalGroups = "," + eval("Product_ColorGroup_"+PID) + ",";
      if(TotalGroups.indexOf(","+CurrentGroup+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      if(CurrentMaxPrice != -1.0 && CurrentMinPrice != -1.0)
      {
      MiPrice = eval("Product_MinPrice_"+PID);
      MaPrice = eval("Product_MaxPrice_"+PID);
      if(MiPrice > CurrentMaxPrice || MaPrice < CurrentMinPrice)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      
      
     }
   }
  }
  
  
}

function ToggleFilterSize(FilterSize)
{
 var CateTD = document.getElementById('CategoryTable').getElementsByTagName('td');
 for(var j = 0;j<CateTD.length;j++)
 {
   if($(CateTD[j]).attr("name") != null)
   {
     if($(CateTD[j]).attr("name") == "ProductTD")
     {
      PName = $(CateTD[j]).attr("id");
      PID = PName.replace("ProductTD_","");
      if(FilterSize != "##MISAKKO##")
      {
      TotalFilterSize = "," + eval("Product_FilterSize_"+PID) + ",";
      if(TotalFilterSize.indexOf(","+FilterSize+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      if(CurrentGroup.length != 0)
      {
      TotalGroups = "," + eval("Product_ColorGroup_"+PID) + ",";
      if(TotalGroups.indexOf(","+CurrentGroup+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      if(CurrentCollection.length != 0)
      {
      TotalCollection = "," + eval("Product_Collection_"+PID) + ",";
      if(TotalCollection.indexOf(","+CurrentCollection+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      if(CurrentMaxPrice != -1.0 && CurrentMinPrice != -1.0)
      {
      MiPrice = eval("Product_MinPrice_"+PID);
      MaPrice = eval("Product_MaxPrice_"+PID);
      if(MiPrice > CurrentMaxPrice || MaPrice < CurrentMinPrice)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
     }
   }
  }
  
  
}

function ToggleColors(Group)
{

var CateTD = document.getElementById('CategoryTable').getElementsByTagName('td');
 for(var j = 0;j<CateTD.length;j++)
 {
   if($(CateTD[j]).attr("name") != null)
   {
     if($(CateTD[j]).attr("name") == "ProductTD")
     {
      PName = $(CateTD[j]).attr("id");
      PID = PName.replace("ProductTD_","");
      if(Group != "##MISAKKO##")
      {
      TotalGroups = "," + eval("Product_ColorGroup_"+PID) + ",";
      if(TotalGroups.indexOf(","+Group+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      if(CurrentCollection.length != 0)
      {
      TotalCollection = "," + eval("Product_Collection_"+PID) + ",";
      if(TotalCollection.indexOf(","+CurrentCollection+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      
      if(CurrentFilterSize.length != 0)
      {
      TotalFilterSize = "," + eval("Product_FilterSize_"+PID) + ",";
      if(TotalFilterSize.indexOf(","+CurrentFilterSize+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      if(CurrentMaxPrice != -1.0 && CurrentMinPrice != -1.0)
      {
      MiPrice = eval("Product_MinPrice_"+PID);
      MaPrice = eval("Product_MaxPrice_"+PID);
      if(MiPrice > CurrentMaxPrice || MaPrice < CurrentMinPrice)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
     }
   }
  }
  
  
}


function TogglePrice(MinPrice,MaxPrice,Range)
{
var CateTD = document.getElementById('CategoryTable').getElementsByTagName('td');
 for(var j = 0;j<CateTD.length;j++)
 {
   if($(CateTD[j]).attr("name") != null)
   {
     if($(CateTD[j]).attr("name") == "ProductTD")
     {
      PName = $(CateTD[j]).attr("id");
      PID = PName.replace("ProductTD_","");
      
      MiPrice = eval("Product_MinPrice_"+PID);
      MaPrice = eval("Product_MaxPrice_"+PID);

      if(MiPrice > MaxPrice || MaPrice < MinPrice)
      {
       
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      
      if(CurrentGroup.length != 0)
      {
      TotalGroups = "," + eval("Product_ColorGroup_"+PID) + ",";
      if(TotalGroups.indexOf(","+CurrentGroup+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      if(CurrentCollection.length != 0)
      {
      TotalCollection = "," + eval("Product_Collection_"+PID) + ",";
      if(TotalCollection.indexOf(","+CurrentCollection+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      
      if(CurrentFilterSize.length != 0)
      {
      TotalFilterSize = "," + eval("Product_FilterSize_"+PID) + ",";
      if(TotalFilterSize.indexOf(","+CurrentFilterSize+",") == -1)
      {
       for(var i = 0;i < VisibleProductID.length;i++)
       {
         if(VisibleProductID[i][0] == PID)
         {
           VisibleProductID[i][1] = "0";
         }
       }
      }
      }
      
      
     }
   }
  }
}

function equalarray()
{
 for(var i = 0;i < VisibleProductID.length; i++)
 {
  VisibleProductID[i][0] = VisibleProductID_BK[i][0];
  VisibleProductID[i][1] = VisibleProductID_BK[i][1];
 }
}

function ToggleCollectionDiv(Collection)
{
 CurrentCollection = Collection;
 equalarray();
 ToggleCollection(Collection);
 decidewhichproducttoshow('Collection');
 resetslidebar();
 //seven add 
 resetleftright();
}

function ToggleFilterSizeDiv(FilterSize)
{
 CurrentFilterSize = FilterSize;
 equalarray();
 ToggleFilterSize(FilterSize);
 decidewhichproducttoshow('Size');
 resetslidebar();
 //seven add 
 resetleftright();
}

function ToggleColorsDiv(Group)
{
 CurrentGroup = Group;
 equalarray();
 ToggleColors(Group);
 decidewhichproducttoshow('Group');
 resetslidebar();
 //seven add 
 resetleftright();
}

function TogglePriceDiv(MinPrice,MaxPrice,Range)
{
CurrentPriceRange = Range;
CurrentMaxPrice = MaxPrice;
CurrentMinPrice = MinPrice;
equalarray();
TogglePrice(MinPrice,MaxPrice,Range);
decidewhichproducttoshow('Price');
resetslidebar();
//seven add 
 resetleftright();
}

function  decidewhichproducttoshow(type)
{
 for(var i= 0;i< VisibleProductID.length;i++)
 {
  if(VisibleProductID[i][1] == "1")
  {
   $("#ProductTD_" + VisibleProductID[i][0]).show();
  }
  else
  {
   $("#ProductTD_" + VisibleProductID[i][0]).hide();
  }
 }
 
 var SpanArray = document.getElementById('category_left_filter_content_Michael').getElementsByTagName('span');
 for(var j = 0;j<SpanArray.length;j++)
 {
  if($(SpanArray[j]).text() == CurrentCollection)
  {
   $(SpanArray[j]).show();;
   $(SpanArray[j]).next().show()
  }
  else if($(SpanArray[j]).text() == CurrentGroup)
  {
   $(SpanArray[j]).show();
   $(SpanArray[j]).next().show()
  }
  else if($(SpanArray[j]).text() == CurrentFilterSize)
  {
   $(SpanArray[j]).show();
   $(SpanArray[j]).next().show()
  }
  else if($(SpanArray[j]).text() == CurrentPriceRange)
  {
   $(SpanArray[j]).show();
   $(SpanArray[j]).next().show()
  }
  else
  {
    $(SpanArray[j]).hide();
    $(SpanArray[j]).next().hide()
  }
 }
 
  if(type == 'Collection')
  {
   if(CurrentGroup == '##MISAKKO##' || CurrentGroup.length == 0)
   {
    $("#GroupSpan span").each(function(){
     $(this).show();
    });
   }
   
   if(CurrentFilterSize == '##MISAKKO##' || CurrentFilterSize.length == 0)
   {
    $("#FilterSizeSpan span").each(function(){
     $(this).show();
    });
   }
   
   if(CurrentPriceRange == '##MISAKKO##' || CurrentPriceRange.length == 0)
   {
    $("#PriceSpan span").each(function(){
     $(this).show();
    });
   }
   HideUnuseGroupSpan();
   HideUnuseFilterSizeSpan();
   HideUnusePriceSpan();
  }
  
  if(type == 'Group')
  {
   if(CurrentCollection == '##MISAKKO##' || CurrentCollection.length == 0)
   {
    $("#CollectionSpan span").each(function(){
     $(this).show();
    });
   }
   
   if(CurrentFilterSize == '##MISAKKO##' || CurrentFilterSize.length == 0)
   {
    $("#FilterSizeSpan span").each(function(){
     $(this).show();
    });
   }
   
   if(CurrentPriceRange == '##MISAKKO##' || CurrentPriceRange.length == 0)
   {
    $("#PriceSpan span").each(function(){
     $(this).show();
    });
   }
   
   HideUnuseCollectionSpan();
   HideUnuseFilterSizeSpan();
   HideUnusePriceSpan();
  }
  
  if(type == 'Size')
  {
   if(CurrentCollection == '##MISAKKO##' || CurrentCollection.length == 0)
   {
    $("#CollectionSpan span").each(function(){
     $(this).show();
    });
   }
   
   if(CurrentGroup == '##MISAKKO##' || CurrentGroup.length == 0)
   {
    $("#GroupSpan span").each(function(){
     $(this).show();
    });
   }
   
   if(CurrentPriceRange == '##MISAKKO##' || CurrentPriceRange.length == 0)
   {
    $("#PriceSpan span").each(function(){
     $(this).show();
    });
   }
   HideUnuseGroupSpan();
   HideUnuseCollectionSpan();
   HideUnusePriceSpan();
  }
  
  if(type == 'Price')
  {
   if(CurrentGroup == '##MISAKKO##' || CurrentGroup.length == 0)
   {
    $("#GroupSpan span").each(function(){
     $(this).show();
    });
   }
   
   if(CurrentFilterSize == '##MISAKKO##' || CurrentFilterSize.length == 0)
   {
    $("#FilterSizeSpan span").each(function(){
     $(this).show();
    });
   }
   
   if(CurrentCollection == '##MISAKKO##' || CurrentCollection.length == 0)
   {
    $("#CollectionSpan span").each(function(){
     $(this).show();
    });
   }
   HideUnuseGroupSpan();
   HideUnuseFilterSizeSpan();
   HideUnuseCollectionSpan();
  }
 
}


function HideUnuseGroupSpan()
{
 $("#GroupSpan span").each(function(){

 var GroupContent = $(this).text();
 var iif = false;
 var CateTD = document.getElementById('CategoryTable').getElementsByTagName('td');
 for(var j = 0;j<CateTD.length;j++)
 {
   if($(CateTD[j]).attr("name") != null)
   {
     if($(CateTD[j]).attr("name") == "ProductTD")
     {
  
      PName = $(CateTD[j]).attr("id");
      PID = PName.replace("ProductTD_","");
      
      TotalGroups = "," + eval("Product_ColorGroup_"+PID) + ",";
      if(GroupContent.length > 0 && TotalGroups.indexOf(","+GroupContent+",") > -1 && $(CateTD[j]).css("display") != "none")
      {
       iif = true;
      }
     }
    }
  }
  
  if(!iif){$(this).hide()}
  
 });
 IfHideColorTitle();
}


function HideUnuseCollectionSpan()
{
 $("#CollectionSpan span").each(function(){

 var GroupContent = $(this).text();
 var iif = false;
 var CateTD = document.getElementById('CategoryTable').getElementsByTagName('td');
 for(var j = 0;j<CateTD.length;j++)
 {
   if($(CateTD[j]).attr("name") != null)
   {
     if($(CateTD[j]).attr("name") == "ProductTD")
     {
  
      PName = $(CateTD[j]).attr("id");
      PID = PName.replace("ProductTD_","");
      
      TotalGroups = "," + eval("Product_Collection_"+PID) + ",";
      if(GroupContent.length > 0 && TotalGroups.indexOf(","+GroupContent+",") > -1 && $(CateTD[j]).css("display") != "none")
      {
       iif = true;
      }
     }
    }
  }
  
  if(!iif){$(this).hide()}
  
 });
 IfHideCollectionTitle();
}

function HideUnuseFilterSizeSpan()
{
 $("#FilterSizeSpan span").each(function(){

 var GroupContent = $(this).text();
 var iif = false;
 var CateTD = document.getElementById('CategoryTable').getElementsByTagName('td');
 for(var j = 0;j<CateTD.length;j++)
 {
   if($(CateTD[j]).attr("name") != null)
   {
     if($(CateTD[j]).attr("name") == "ProductTD")
     {
  
      PName = $(CateTD[j]).attr("id");
      PID = PName.replace("ProductTD_","");
      
      TotalGroups = "," + eval("Product_FilterSize_"+PID) + ",";
      
      if(GroupContent.length > 0 && TotalGroups.indexOf(","+GroupContent+",") > -1 && $(CateTD[j]).css("display") != "none")
      {
       iif = true;
      }
     }
    }
  }
  
  if(!iif){$(this).hide()}
  
 });
 
 IfHideFilterSizeTitle();
}

function HideUnusePriceSpan()
{
 $("#PriceSpan span").each(function(){

 var MinPrice = Number($(this).attr("name"));
 var MaxPrice = Number($(this).attr("title"));
 var iif = false;
 var CateTD = document.getElementById('CategoryTable').getElementsByTagName('td');
 for(var j = 0;j<CateTD.length;j++)
 {
   if($(CateTD[j]).attr("name") != null)
   {
     if($(CateTD[j]).attr("name") == "ProductTD")
     {
  
      PName = $(CateTD[j]).attr("id");
      PID = PName.replace("ProductTD_","");
      
       MiPrice = eval("Product_MinPrice_"+PID);
       MaPrice = eval("Product_MaxPrice_"+PID);
       
      if(((MiPrice >= MinPrice && MiPrice <= MaxPrice) || (MaPrice >= MinPrice && MaPrice <= MaxPrice))  && $(CateTD[j]).css("display") != "none")
      {
      
       iif = true;
      }
      
     }
    }
  }
  
  if(!iif){$(this).hide()}
  
 });
 IfHidePriceTitle();
}


function ShowProductByFilter(FilterID)
{
if(FilterID == "ALL")
{
   $("#CategoryTable td").each(function(){
   if($(this).attr("name") != null)
   {
     if($(this).attr("name") == "ProductTD")
     {
      $(this).show();
     }
   }
  });
  CurrentCollection = '';
  CurrentGroup = '';
  CurrentFilterSize = '';
  CurrentPriceRange = '';
  CurrentMinPrice = -1.0;
  CurrentMaxPrice = -1.0;
  


 //seven comment
// var SpanArray = document.getElementById('category_left_filter_content_Michael').getElementsByTagName('span');
// for(var j = 0;j<SpanArray.length;j++)
// {
//   $(SpanArray[j]).show();
//   $(SpanArray[j]).next().hide();
// }
 
 //seven add here
 location.reload();

 }
 
 
 
 if(FilterID == "PRICE")
{
CurrentPriceRange = '';
CurrentMaxPrice = -1.0;
CurrentMinPrice = -1.0;
equalarray();
TogglePrice(-10.0,99999.0,'');
decidewhichproducttoshow('Price');

var SpanArray = document.getElementById('PriceSpan').getElementsByTagName('span');
 for(var j = 0;j<SpanArray.length;j++)
 {
   $(SpanArray[j]).show();
   $(SpanArray[j]).next().hide();
 }
   HideUnusePriceSpan();
   HideUnuseGroupSpan();
   HideUnuseFilterSizeSpan();
   HideUnuseCollectionSpan();
}
  
 if(FilterID == "GROUP")
 {
  CurrentGroup = '';
  equalarray();
  ToggleColors("##MISAKKO##");
  decidewhichproducttoshow('Group');
  var SpanArray = document.getElementById('GroupSpan').getElementsByTagName('span');
 for(var j = 0;j<SpanArray.length;j++)
 {
   $(SpanArray[j]).show();
   $(SpanArray[j]).next().hide();
 }
   HideUnuseGroupSpan();
   HideUnusePriceSpan();
   HideUnuseFilterSizeSpan();
   HideUnuseCollectionSpan();
 }
 
 if(FilterID == "FILTERSIZE")
 {
 CurrentFilterSize = '';
 equalarray();
 ToggleFilterSize("##MISAKKO##");
 decidewhichproducttoshow('Size');
 var SpanArray = document.getElementById('FilterSizeSpan').getElementsByTagName('span');
 for(var j = 0;j<SpanArray.length;j++)
 {
   $(SpanArray[j]).show();
   $(SpanArray[j]).next().hide();
 }
   HideUnuseFilterSizeSpan();
   HideUnusePriceSpan();
   HideUnuseGroupSpan();
   HideUnuseCollectionSpan();
 }
 
 if(FilterID == "COLLECTION")
 {
  CurrentCollection = '';
  equalarray();
  ToggleCollection("##MISAKKO##");
  decidewhichproducttoshow('Collection');
  var SpanArray = document.getElementById('CollectionSpan').getElementsByTagName('span');

 for(var j = 0;j<SpanArray.length;j++)
 {
   $(SpanArray[j]).show();
   $(SpanArray[j]).next().hide();
 }
   HideUnuseCollectionSpan();
   HideUnusePriceSpan();
   HideUnuseGroupSpan();
   HideUnuseFilterSizeSpan();
  
 }
 resetslidebar();
 //seven add 
 //resetleftright();
}

function IfHideFilterSizeTitle()
{
 var hide = true;
 $("#FilterSizeSpan span").each(function(){
  if($(this).css("display") != "none"){hide = false;}
 });
 
 if(hide){$("#FilterSize_Title").hide()}else{$("#FilterSize_Title").show()}
}

function IfHideCollectionTitle()
{
 var hide = true;
 $("#CollectionSpan span").each(function(){
  if($(this).css("display") != "none"){hide = false;}
 });
 
 if(hide){$("#Collection_Title").hide()}else{$("#Collection_Title").show()}
}

function IfHideColorTitle()
{
 var hide = true;
 $("#GroupSpan span").each(function(){
  if($(this).css("display") != "none"){hide = false;}
 });
 if(hide){$("#Color_Title").hide()}else{$("#Color_Title").show()}
}

function IfHidePriceTitle()
{
 var hide = true;
 $("#PriceSpan span").each(function(){
  if($(this).css("display") != "none"){hide = false;}
 });
 
 if(hide){$("#Price_Title").hide()}else{$("#Price_Title").show()}
}


function resetslidebar()
{
 var tablewidth = $('#CategoryTable').width();
 var divwidth = $('div.cat-sliderGallery').width();
 
 if(tablewidth <= divwidth)
 {
  $('#catsld').html('');
 }
 else
 {
 $('#catsld').html('<div class="cat-slider cat-ui-slider"  style="margin-top:15px;"><a href="javascript:void(0)" style="border: medium none ; outline-color: -moz-use-text-color; outline-style: none; outline-width: medium;"><div style="left: 0px;" class="cat-handle"></div></a></div>');
 $('#delayscript').html('');
 var t = document.createElement('script'); 
 t.src='jscripts/category_slider_delay.js';
 t.type='text/javascript';
 document.getElementById('delayscript').appendChild(t);
 
 }
}

//seven add reset left right slider

function resetleftright()
{
var $cur =1;
 var $showbox = $(".cat-imageUL");
 var $showbox1 = $(".cat-imageUL1");
 var $pagenums=$(".pagenumforjs");
 var $leftrightbtn=$(".leftrightbutton");
 $showbox.attr("style","left:0");
 $showbox1.attr("style","left:0");
 $pagenums.fadeOut("300");
 $leftrightbtn.fadeOut("200");
 
}

function checkOutOfStock(id, m) {
	var VariantID = document.getElementById('VariantList_'+m).value;
	var stock = eval('StockLevel_'+VariantID);
	var current = document.getElementById('selectQuantity_'+m).value;
	if(parseInt(stock) < parseInt(current)) {
		$('#PriceCol_'+m).html($('#PriceCol_'+m).html().trim(' ').split(' ')[0].trim(' ') + ' <p class="stockwarning">out of stock</p>');
	} else {
		$('#PriceCol_'+m).html($('#PriceCol_'+m).html().trim(' ').split(' ')[0].trim(' '));
	}
};

$(document).ready(function () {
	var tabControls = $('div.tabControl');
	if (tabControls.length > 1) {
		// set first tab as selected
		$(tabControls[0]).addClass('selected');
	
		// hide all controls other than the first one
		for (var i = 1; i < tabControls.length; i++) { 
			var tabPanelId = $(tabControls[i]).attr('rel');
			if ($('#' + tabPanelId).length > 0) {
				$('#' + tabPanelId).attr("style", "display: none");
			}			 
		}
		
		for (var i = 0; i < tabControls.length; i++) {
			$(tabControls[i]).bind('click', {currentIndex: i}, function (e) {
				var currentIndex = e.data.currentIndex;
							
				var currentSelectedTab = $('div.tabControl.selected');
				var newTab = $(e.target);				
				
				if (!newTab.hasClass('selected')) {
					// show current panel
					tabControls.removeClass('selected');
					newTab.addClass('selected'); 
					
					var hideId = currentSelectedTab.attr('rel');
					var showId = newTab.attr('rel');
										
					$('#' + hideId).animate({width: 'toggle'}, 400, function () {
						$('#' + showId).animate({width: 'toggle'});
					});
				}
			});
		}			
	}
});


