    var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
    var collapseprevious="yes" //Collapse previously open content when opening present? (yes/no)
    
    if (document.getElementById){
    document.write('<style type="text/css">')
    document.write('.switchcontent{display:none;}')
    document.write('</style>')
    }

    function getElementbyClass(classname){
    ccollect=new Array()
    var inc=0
    var alltags=document.all? document.all : document.getElementsByTagName("*")
    for (i=0; i<alltags.length; i++){
    if (alltags[i].className==classname)
    ccollect[inc++]=alltags[i]
    }
    }

    function contractcontent(omit){
    //rikki/
    var omitprt=omit.charAt(0);
    var inc=0

      if (omitprt==2)
      {
          
	      while (ccollect[inc]){
	  	      var idprt=ccollect[inc].id.charAt(0);
	          if (ccollect[inc].id!=omit && idprt==2)
	          {

		       ccollect[inc].style.display="none"
	          }
    		
	      inc++
	      }

      }
      else
      {

        while (ccollect[inc]){
          if (ccollect[inc].id!=omit)

          {
            ccollect[inc].style.display="none"
          }
        inc++
        }

      }

    }

    //function expandcontent(cid){
    //if (typeof ccollect!="undefined"){
    //if (collapseprevious=="yes")
    //contractcontent(cid)
    //document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
    //}
    //}


    function expandcontent(cid){

          if (typeof ccollect!="undefined")
          {

            if (collapseprevious=="yes")
            {
              contractcontent(cid)
            }
            
            document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
          }

          else
          {
            
            if (cid!="0")
            {
              
              document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"

           }        
         }
    }




    function revivecontent(){
    contractcontent("omitnothing")
    selectedItem=getselectedItem()
    selectedComponents=selectedItem.split("|")
    for (i=0; i<selectedComponents.length-1; i++)
    
    document.getElementById(selectedComponents[i]).style.display="block"
    }

    function get_cookie(Name) { 
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { 
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }

    function getselectedItem(){
    if (get_cookie(window.location.pathname) != ""){
    selectedItem=get_cookie(window.location.pathname)
    return selectedItem
    }
    else
    return ""
    }

    function saveswitchstate(){
    var inc=0, selectedItem=""
    while (ccollect[inc]){
    if (ccollect[inc].style.display=="block")
    selectedItem+=ccollect[inc].id+"|"
    inc++
    }

    document.cookie=window.location.pathname+"="+selectedItem
    }

    function do_onload(){
    uniqueidn=window.location.pathname+"firsttimeload"
    getElementbyClass("switchcontent")
    if (enablepersist=="on" && typeof ccollect!="undefined"){
    document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
    firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
    if (!firsttimeload)
    revivecontent()
    }
    }


    if (window.addEventListener)
    window.addEventListener("load", do_onload, false)
    else if (window.attachEvent)
    window.attachEvent("onload", do_onload)
    else if (document.getElementById)
    window.onload=do_onload

    if (enablepersist=="on" && document.getElementById)
    window.onunload=saveswitchstate



    function menuover(control,level) {

	    if (level == 1) 
	    {
		    control.style.color='#000000';
    	
	    }
	    else if (level == 2)
	    {
		    control.style.color='#000000';
	    }

	    else if (level == 3)
	    {
		    control.style.color='#000000';
	    }
    }

    function menuout(control,level) {

	    if (level == 1) 
	    {
		    control.style.color='#5C5C5C';
    	
	    }
		    else if (level == 2)
	    {
		    control.style.color='#616161';

	    }
		    else if (level == 3)
	    {
		    control.style.color='#888888';

	    }
    }



	function SwitchCol(imagecol) {
	var pics = imagecol.split("|")[0];
	var sex = imagecol.split("|")[1];
	var image = imagecol.split("|")[2];
	var stxtname = document.getElementById("norm_picture_holder").value;
	//alert(sex);
	//alert(image);
	//alert("http://www.jsgstores.co.uk/pictures/"+ sex + "/med/" + image + "-1.jpg");
	
	document.getElementById(stxtname).value = image
	
	//var BigImg = document.Form1.Image1
	document.mainpic.src = "http://www.jsgstores.co.uk/pictures/"+ sex + "/med/" + image + "-1.jpg"
	
	var contentDiv = document.getElementById("bc2");
	// do something to first div element:
	//var containedDivElements = contentDiv.getElementsByTagName("div");

	// run through all contained elements:
	var allContainedElements = contentDiv.getElementsByTagName("img");
	for (var i = 0; i < allContainedElements.length; i++) {
	var elem = allContainedElements[i];
	//alert(image);
	//alert(elem.src);
	elem.src = "http://www.jsgstores.co.uk/pictures/"+ sex + "/big/" + image + "-1_big.jpg"
	}
	
	  for (i=1;i<=pics;i++) {
	
	    eval("document.smallpic"+i+".src="+ "'http://www.jsgstores.co.uk/pictures/" + sex + "/small/" + image + "-" + i + "s.jpg'");
        //alert(eval("document.smallpic"+i+".src="+ "'http://www.jsgstores.co.uk/pictures/" + sex + "/med/" + image + "-" + i + "s.jpg'"));

		//document.smallpic.src = "http://www.jsgstores.co.uk/pics/"+ sex + "/med/" + image + "-1s.jpg"
     	//DisplayClr = ToColor
	
	  }

	}


function ChangePic(imagename) {

    var sex = imagename.split("|")[0];

    var imagenum = imagename.split("|")[1];

    var stxtname = document.getElementById("norm_picture_holder").value;

    var image = document.getElementById(stxtname).value


    document.mainpic.src = "http://www.jsgstores.co.uk/pictures/"+ sex + "/med/" + image + "-" + imagenum + ".jpg"
    
    var contentDiv = document.getElementById("bc2");
	// do something to first div element:
	//var containedDivElements = contentDiv.getElementsByTagName("div");
	
		// run through all contained elements:
	var allContainedElements = contentDiv.getElementsByTagName("img");
	for (var i = 0; i < allContainedElements.length; i++) {
	var elem = allContainedElements[i];
	//alert(elem.src);
	elem.src = "http://www.jsgstores.co.uk/pictures/"+ sex + "/big/" + image + "-" + imagenum + "_big.jpg"
		// do something with contained elem
	}


}


function roundNumber() {

        var stxtname = document.getElementById("norm_price_holder").value;

	var numberField = document.getElementById(stxtname); // Field where the number appears
	//alert(numberField.value);
	var rnum = numberField.value;
	var rlength = 2; // The number of decimal places to round to
	if (rnum > 8191 && rnum < 10485) {
		rnum = rnum-5000;
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		newnumber = newnumber+5000;
	} else {
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	}
	numberField.value = newnumber;
}





function SizeSelected(ddName) {

var vIndex = ddName.selectedIndex;
var vIndexQty = ddName.options[vIndex].text

var selectedvalue = ddName.value;

var cost = selectedvalue.split("-")[0];

var sizeNE = selectedvalue.split("-")[2];
var size = selectedvalue.split("-")[2].replace("|","");
var maxavail = selectedvalue.split("-")[1];
var idmatch = 0

var textname = selectedvalue.split("-")[3]
var spreviousqty = document.getElementById(textname);


var stxtbasketname = document.getElementById("norm_basket_holder").value;

var currentbholder = document.getElementById(stxtbasketname);
var currentb = currentbholder.value;

var stxtqtyname = document.getElementById("norm_qty_holder").value;
var qty = document.getElementById(stxtqtyname);

var stxtpricename = document.getElementById("norm_price_holder").value;
var tprice = document.getElementById(stxtpricename)

var stxtsizeename = document.getElementById("norm_sizes_holder").value;
var sizeholder = document.getElementById(stxtsizeename)



if(vIndex !== 0) { 


  if (currentb == "") {
  //nothing in basket no need validate

  var sizeholder1 = sizeholder.value;
  var newtest = sizeholder1.replace(sizeNE,"");
  sizeholder.value = newtest + sizeNE;
  
  currentbholder.value = currentbholder.value + sizeNE + vIndexQty + "Z";
  tprice.value = parseFloat(tprice.value) + (parseFloat(cost) * parseInt(vIndexQty));
  qty.value = parseInt(qty.value) + parseInt(vIndexQty);
  spreviousqty.value = vIndexQty
  }

  else {

  //split the string into it's relevant parts ready for looping through
  var splits = currentb.split("Z");

     //use for loop to loop through each array value
     for (var i=0; i<(splits.length -1); i++)
     {
   
       //split each basket array into it's id and its associated number
       var splits_id=(splits[i].split("|")[0]);
       var splits_qty=(splits[i].split("|")[1]);

       //check to see if id euquals the id selected from checkbox
       if (splits_id == size) {
       //mark that we have had a match 
       idmatch = 1


         //check to see if choosen qty added to the existing qty is greater than the max allowed
         var addreq = Math.abs(parseInt(spreviousqty.value) - parseInt(splits_qty))       

         if (parseInt(maxavail) < (parseInt(addreq) + parseInt(vIndexQty))) {
       
            var varitemsallowed = maxavail - (parseInt(splits_qty));
          
          
            alert ("The maximum qty available of this item is " + maxavail + ".\nYour cart currently contains " + splits_qty + ".\nYou may add up to " + varitemsallowed + " more of this item.");
       ddName.selectedIndex = 0;
       ddName.selectedIndex = spreviousqty.value;
       
 
         }
         else {
         //we are ok to add the value to the basket holder asp textbox
         var oldidqty = splits_id + "|" + splits_qty
         
         var testme = Math.abs(parseInt(spreviousqty.value) - parseInt(vIndexQty))
         testme = (parseInt(vIndexQty) - parseInt(testme))
         splits_qty = parseInt(splits_qty) - parseInt(spreviousqty.value)

         
         var newidqty = splits_id + "|" + (parseInt(splits_qty) + parseInt(vIndexQty))
         

         var varnewValue = currentb.replace(oldidqty,newidqty);
         currentbholder.value = varnewValue;
         

         var sizeholder1 = sizeholder.value;
         var newtest = sizeholder1.replace(sizeNE,"");
         sizeholder.value = newtest + sizeNE;
  
         var removeprice1 = parseFloat(cost) * parseInt(spreviousqty.value)
         var removeprice2 = parseFloat(cost) * parseInt(vIndexQty)

         tprice.value = (parseFloat(tprice.value) - parseFloat(removeprice1)) + parseFloat(removeprice2);
         roundNumber()
         
         qty.value = Math.abs((parseInt(qty.value) - parseInt(spreviousqty.value))) + parseInt(vIndexQty);
         spreviousqty.value = vIndexQty

         }
     
       }
   
     }

  if (idmatch == 0) {

    currentbholder.value = currentbholder.value + sizeNE + vIndexQty + "Z";
  
  
    sizeholder.value = sizeholder.value + sizeNE
    var removeprice1 = parseFloat(cost) * parseInt(spreviousqty.value)
    var removeprice2 = parseFloat(cost) * parseInt(vIndexQty)

    tprice.value = (parseFloat(tprice.value) - parseFloat(removeprice1)) + parseFloat(removeprice2);
         
    roundNumber()
  
    qty.value = parseInt(qty.value) + parseInt(vIndexQty);
    spreviousqty.value = vIndexQty

  }

  }

} 
		
else {

  //split the string into it's relevant parts ready for looping through
  var splits = currentb.split("Z");

     //use for loop to loop through each array value
     for (var i=0; i<(splits.length -1); i++)
     {

       //split each basket array into it's id and its associated number
       var splits_id=(splits[i].split("|")[0]);
       var splits_qty=(splits[i].split("|")[1]);

       //check to see if id euquals the id selected from checkbox
       if (splits_id == size) {


            if ((parseInt(splits_qty) - parseInt(spreviousqty.value)) <= 0) {

            var oldidqty = splits_id + "|" + splits_qty + "Z";
            var varnewValue = currentb.replace(oldidqty,"");

            currentbholder.value = varnewValue;
            
            var removeprice1 = parseFloat(cost) * parseInt(spreviousqty.value)
            var removeprice2 = parseFloat(cost) * parseInt(vIndexQty)

            tprice.value = (parseFloat(tprice.value) - parseFloat(removeprice1)) + parseFloat(removeprice2);
            
            roundNumber()
            
            qty.value = parseInt(qty.value) - parseInt(spreviousqty.value);

            spreviousqty.value = vIndexQty

            }
            
            else {

            var oldidqty = splits_id + "|" + splits_qty
       	    var newidqty = splits_id + "|" + (parseInt(splits_qty) - parseInt(spreviousqty.value));
            var varnewValue = currentb.replace(oldidqty,newidqty);

            currentbholder.value = varnewValue;
            
            var removeprice1 = parseFloat(cost) * parseInt(spreviousqty.value)
            var removeprice2 = parseFloat(cost) * parseInt(vIndexQty)

            tprice.value = (parseFloat(tprice.value) - parseFloat(removeprice1)) + parseFloat(removeprice2);
            
            roundNumber()
            qty.value = parseInt(qty.value) - parseInt(document.getElementById(textname).value);

            spreviousqty.value = vIndexQty

            }
        

       }

     
     }



  var tmp = sizeholder.value;
  tmp = tmp.replace(sizeNE,"");
  sizeholder.value = tmp;
  
  
  
}


}



	function check() {
	
var stxtsizesname = document.getElementById("norm_sizes_holder").value;

	    if (document.getElementById(stxtsizesname).value == "") {
            alert("please select from the avialable size and colours ");
            return false;
        }
	}


	function RemoveItem(chkValue) {
	    var selectedvalue = chkValue.value;
	    var cost = selectedvalue.split("-")[0];
	    var item = selectedvalue.split("-")[1];
	    var amount = selectedvalue.split("-")[2];

var stxtbasketname = document.getElementById("norm_basket_holder").value;
        var bholder = document.getElementById(stxtbasketname);

var stxtqtyname = document.getElementById("norm_qty_holder").value;
        var qty = document.getElementById(stxtqtyname);

var stxtpricename = document.getElementById("norm_price_holder").value;
        var tprice = document.getElementById(stxtpricename);

        var idmatch = 0;
//alert(chkValue.name);
//alert(chkValue.name.indexOf('All'));

        if (chkValue.name.indexOf('All')==-1)
        {
            //alert("remove 1 to be disabled");
            var chknum = chkValue.name.replace("chkSelected","")
            //alert(chknum);
            //alert(document.getElementById("chkSelectedAll"+chknum).value);
            var altchkname = document.getElementById("chkSelectedAll"+chknum)

        }
        else
        {
            //alert("remove all to be disabled");
            var chknum = chkValue.name.replace("chkSelectedAll","")
            //alert(chknum);
            //alert(document.getElementById("chkSelected"+chknum).value);
            var altchkname = document.getElementById("chkSelected"+chknum)

        }

        if(chkValue.checked == true) {
altchkname.disabled = true;
            //var varnewValue = currentb.replace(oldidqty,newidqty);
            
            //split the string into it's relevant parts ready for looping through
            var splits = bholder.value.split("Z");
            
            //use for loop to loop through each array value
            for (var i=0; i<(splits.length -1); i++)
            {
                //split each basket array into it's id and its associated number
                var splits_id=(splits[i].split("|")[0]);
                var splits_qty=(splits[i].split("|")[1]);
            
               //check to see if id euquals the id selected from checkbox
               if (splits_id == item) {
                //alert(item);
                //alert(splits_id);
                    if ((parseInt(splits_qty) - 1) <= 0) {
                        //alert("r");

                        var oldidqty = splits_id + "|" + splits_qty + "Z";
                        var varnewValue = bholder.value.replace(oldidqty,"");
                        bholder.value = varnewValue;
                        
                        tprice.value = parseFloat(tprice.value) + (parseFloat(cost) * parseInt(amount));
                        roundNumber()
                        qty.value = parseInt(qty.value) + parseInt(amount);
                        //alert(oldidqty);
                        //alert(varnewValue);
            
                    }
                    
                    else {
                        //alert("t");
                        //alert(amount);

                        
                        if (parseInt(amount) == 1) {
                        //alert("reomve 1");
                        var oldidqty = splits_id + "|" + splits_qty
       	                var newidqty = splits_id + "|" + (parseInt(splits_qty) - 1);
                        var varnewValue = bholder.value.replace(oldidqty,newidqty);

                        }
                        else {
                        //alert("remove all");
                            var oldidqty = splits_id + "|" + splits_qty + "Z";
                            var varnewValue = bholder.value.replace(oldidqty,"");
                        //alert(oldidqty);
                        //alert(varnewValue);
                        }
                        
                        //alert(oldidqty + "'" + newidqty)
                        bholder.value = varnewValue;
                        tprice.value = parseFloat(tprice.value) + (parseFloat(cost) * parseInt(amount));
                        roundNumber()
                        qty.value = parseInt(qty.value) + parseInt(amount);
                        //alert(oldidqty);
                        //alert(varnewValue);
                    }
            
               }
            
            }

        }

        else {
altchkname.disabled = false;
            //var varnewValue = currentb.replace(oldidqty,newidqty);
            
            //split the string into it's relevant parts ready for looping through
            var splits = bholder.value.split("Z");
            
            //use for loop to loop through each array value
            for (var i=0; i<(splits.length -1); i++)
            {

               var splits_id=(splits[i].split("|")[0]);
               var splits_qty=(splits[i].split("|")[1]);
            
               //check to see if id euquals the id selected from checkbox
               if (splits_id == item) {
                    idmatch = 1 
                    var oldidqty = splits_id + "|" + splits_qty
  	                var newidqty = splits_id + "|" + (parseInt(splits_qty) + 1);
                    var varnewValue = bholder.value.replace(oldidqty,newidqty);
                    bholder.value = varnewValue;
                    tprice.value = parseFloat(tprice.value) - parseFloat(cost);
                    roundNumber()
                    qty.value = parseInt(qty.value) - 1;
           
                
               }

                        
             }
             
             if (idmatch == 0) {
             
                if (parseInt(amount) == 1) {
                    //alert("add 1");
  	                var newidqty = item + "|" + 1 + "Z";
                    var varnewValue = bholder.value + newidqty;
                    bholder.value = varnewValue;
                    tprice.value = parseFloat(tprice.value) - parseFloat(cost);
                    roundNumber()
                    qty.value = parseInt(qty.value) - 1;
                    
                }
                
                else {
                    //alert("add all");
  	                var newidqty = item + "|" + amount + "Z";
                    var varnewValue = bholder.value + newidqty;
                    bholder.value = varnewValue;
                    tprice.value = parseFloat(tprice.value) - (parseFloat(cost) * parseInt(amount));
                    roundNumber()
                    qty.value = parseInt(qty.value) - parseInt(amount);
                
                }
             
             }
             
        }
      
	}


function ShowSearch(x) {

        document.getElementById(x).style.display='block';
}


var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
    
    eval(document.getElementById("expand").value);
    
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtml_adv_search'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtml_adv_search_content_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}

//window.onload = initShowHideDivs;

function AdvSearch()
{
 window.location = "products.aspx?"

}
