var selSKUs = ""
var selQTYs = ""
var JustSkus = ""
var CurSortHead = "colHead4"
// overly simplistic test for IE
isIE = (document.all ? true : false);
// both IE5 and NS6 are DOM-compliant (well, sort of...)
isDOM = (document.getElementById ? true : false);

function UncheckAll(){
count = document.frmList.chkSku.length;
if (count==undefined) {
	document.frmList.chkSku.checked = 0;
}
else
{
    for (i=0; i < count; i++) 
	{
    	{document.frmList.chkSku[i].checked = 0; }
	}
}
}
function CheckAll(){
count = document.frmList.chkSku.length;
if (count==undefined) {
	document.frmList.chkSku.checked = 1;
}
else 
{
    for (i=0; i < count; i++) 
	{
    	{document.frmList.chkSku[i].checked = 1; }
	}
}
}
function CheckAllForClass(SkuToCheck){
count = document.frmList.chkSku.length;
if (count==undefined) {
	document.frmList.chkSku.checked = 1;
}
else 
{
    for (i=0; i < count; i++) 
	{  if (SkuToCheck == getItem(0,document.frmList.chkSku[i].value,"|"))
    		{
    		
    		document.frmList.chkSku[i].checked = 1;
    		}
	}
}
}
function GetJustSkus(){

 	RemovePages_Skus_From_SkuList();
	AddPages_Skus_To_SkuList();
	if (selSKUs.length < 6)
	{
	 alert("Please check a product.");
	 return false;
	}
    else
	{
	TheSkus = selSKUs.split(";");
	count = TheSkus.length;
	JustSkus="";
	
	for (i=0; i < count; i++) {
       if (i==0) {
			JustSkus = getItem(1,TheSkus[i],"|");
		}
		else
		{
			JustSkus += "," + getItem(1,TheSkus[i],"|");
		}

	}
	//alert(JustSkus);
	return true;
	}
}
function AddToQuickList(cypherID){
    if (GetJustSkus())
    {
    openAddToQuickList(JustSkus,cypherID);}
 }

 function AddPages_Skus_To_SkuList(){
	count = document.frmList.chkSku.length;
	var CountofCheckedSkus;
	CountofCheckedSkus=0;
    skuinfo = document.frmList.ThePage.value + "|";
    current_skuinfo = "";
    if (count==undefined) {
	   count=1;
		if (document.frmList.chkSku.checked) {
		    current_skuinfo = getItem(1,document.frmList.chkSku.value,"|");
		    skuinfo+=current_skuinfo;
			CountofCheckedSkus++;
		}	   
	}
    else{	
    for (i=0; i < count; i++) {
		if (document.frmList.chkSku[i].checked) {
		    current_skuinfo = getItem(1,document.frmList.chkSku[i].value,"|");
			if (CountofCheckedSkus==0)
				{skuinfo+=current_skuinfo;}
			else
			    {skuinfo+= "," + current_skuinfo}	
			CountofCheckedSkus++;
		}
	}
	}
	if (CountofCheckedSkus>0) {
		selSKUs = addUniqueItem(skuinfo, selSKUs, ";");
		document.frmList.hdnselsku.value = selSKUs;
		//alert(selSKUs);
	}
}	
 function AddPages_Qtys_To_QtyList(){
	count = document.frmList.txtQty.length;
	var CountofQtys;
	CountofQtys=0;
    qtyinfo = document.frmList.ThePage.value + "|";
    current_qtyinfo = "";
        //alert(selQTYs);
    if (count==undefined){
    		var qty = document.frmList.txtQty.value;
			qty = getNumeric(qty);
			if (!(qty=="" || qty==0 || qty>99999)&& document.frmList.chkSku.checked)
			{  
				current_qtyinfo =getItem(1,document.frmList.chkSku.value,"|") + "#" + document.frmList.txtQty.value;
				if (CountofQtys==0)
					{qtyinfo+=current_qtyinfo;}
				else
				    {qtyinfo+= "," + current_qtyinfo}	
				CountofQtys++;
			}
    }
    else
    {
		for (i=0; i < count; i++) {
			var qty = document.frmList.txtQty[i].value;
			qty = getNumeric(qty);
			if (!(qty=="" || qty==0 || qty>99999)&& document.frmList.chkSku[i].checked)
			{  
				current_qtyinfo =getItem(1,document.frmList.chkSku[i].value,"|") + "#" + document.frmList.txtQty[i].value;
				if (CountofQtys==0)
					{qtyinfo+=current_qtyinfo;}
				else
				    {qtyinfo+= "," + current_qtyinfo}	
				CountofQtys++;
			}
		}
	}
		if (CountofQtys>0) {
			selQTYs = addUniqueItem(qtyinfo, selQTYs, ";");
			document.frmList.hdnselqty.value = selQTYs;
			//alert(selQTYs);
		}
 }
function ClearAllPages(){
    selSKUs="";
    document.frmList.hdnselsku.value = selSKUs;
    UncheckAll();
    GOTO_URL(document.frmList.ThePage.value,'');
 }
 function SelectAllPages(){
	CheckAll()
    selSKUs="all";
    document.frmList.hdnselsku.value = selSKUs;
    GOTO_URL(document.frmList.ThePage.value,'');
 }
  function SelectAllForClass(){
	CheckAll()
    selSKUs="all";
    document.frmList.hdnselsku.value = selSKUs;
    GOTO_URL(document.frmList.ThePage.value,'');
 }
 function RemovePages_Skus_From_SkuList(){
    AllSkus = selSKUs.split(";");
    selSKUs = "";
    for (i=0; i < AllSkus.length; i++){
     Page_Skus = AllSkus[i].split("|");
     if (Page_Skus[0] != document.frmList.ThePage.value) {
		 selSKUs = addUniqueItem(AllSkus[i],selSKUs,";");
	 }
    }
   	document.frmList.hdnselsku.value = selSKUs;
 }
  function RemovePages_Qtys_From_QtyList(){
    AllQtys = selQTYs.split(";");
    selQTYs = "";
    for (i=0; i < AllQtys.length; i++){
     Page_Qtys = AllQtys[i].split("|");
     if (Page_Qtys[0] != document.frmList.ThePage.value) {
		 selQTYs = addUniqueItem(AllQtys[i],selQTYs,";");
	 }
    }

   	document.frmList.hdnselqty.value = selQTYs;
 }
  function SwitchSort(colHead){
  
 //alert(colHead);
 
 Head1 = document.getElementById('colHead1')
 Head2 = document.getElementById('colHead2')
 Head3 = document.getElementById('colHead3')
 Head4 = document.getElementById('colHead4')
 
 nodirection = '<IMG width="9" height="10" border="0"  SRC="/catalog/images/arrow-notactive_10-9.gif">'

 if (document.frmList.TheSortDirection.value=='0')
 {
 directionArrow = '<IMG width="9" height="10" border="0"  SRC="/catalog/images/arrow_active-up_10-9.gif">'
 }
 else
 {
 directionArrow = '<IMG width="9" height="10" border="0"  SRC="/catalog/images/arrow_active_10-9.gif">'

 
 }
 switch(colHead) {
  case '1':
    Head4.innerHTML = 'Category' + nodirection;
    Head1.innerHTML = 'Product Description'+ directionArrow;
    Head2.innerHTML = 'Price' + nodirection;
	Head3.innerHTML = 'Stock' + nodirection;
    break;
  case '2':
    Head4.innerHTML = 'Category' + nodirection;
    Head1.innerHTML = 'Product Description' + nodirection;
    Head2.innerHTML = 'Price'+ directionArrow;
	Head3.innerHTML = 'Stock' + nodirection;
    break;
  case '3':    
	Head4.innerHTML = 'Category' + nodirection;
    Head1.innerHTML = 'Product Description' + nodirection;
    Head2.innerHTML = 'Price' + nodirection;
	Head3.innerHTML = 'Stock'+ directionArrow;
    break;
   case '4':
    Head4.innerHTML = 'Category' + directionArrow  
    Head1.innerHTML = 'Product Description' + nodirection;
    Head2.innerHTML = 'Price' + nodirection;
	Head3.innerHTML = 'Stock' + nodirection;
    break;
  default:
    Head4.innerHTML = 'Category' + directionArrow
    Head1.innerHTML = 'Product Description' + nodirection;
    Head2.innerHTML = 'Price' + nodirection;
	Head3.innerHTML = 'Stock'+ nodirection;
    break;
    //if myVar does not satisfy any case, this is executed
	  //break; is unnecessary here as there are no cases following this
}
 
 }
 function SaveChecksANDQtys(){
  	if (selSKUs!="all") { 
 		RemovePages_Skus_From_SkuList();
		AddPages_Skus_To_SkuList();
	}
	RemovePages_Qtys_From_QtyList();
	AddPages_Qtys_To_QtyList();
 }
 
 
 function GOTO_URL(ThePage,TheSort){
    SaveChecksANDQtys();
 	if (selSKUs!="all") { 
 		RemovePages_Skus_From_SkuList();
		AddPages_Skus_To_SkuList();
	}
	RemovePages_Qtys_From_QtyList();
	AddPages_Qtys_To_QtyList();
	document.frmList.ThePage.value = ThePage;
	if (document.frmList.TheSort.value != TheSort){
		   document.frmList.TheSortDirection.value = 0;
		}	
	if ( TheSort!='') {
		if (document.frmList.TheSortDirection.value==0){
		   document.frmList.TheSortDirection.value = 1;
		}
		else
		{
		   document.frmList.TheSortDirection.value = 0;
		}
	}
    else
    {
       TheSort =  document.frmList.TheSort.value ;   
       document.frmList.TheSortDirection.value = 0;
    }
	if ((TheSort > 0) && (TheSort < 4)) 
	{
	document.frmList.TheSort.value = TheSort;
	}
	else
	{
	document.frmList.TheSort.value = 0;
	}
	document.frmList.submit();
 }
 function compareSelectedS(par,cat) {
	
	if (GetJustSkus()){
        JustSkusCount = JustSkus.split(",").length;
        if (JustSkusCount > 1) {
			parent.location = "/catalog/product_compare.asp?sku=" + JustSkus + "&par=" + par + "&cat=" + cat;
        }
        else
        {
      	 alert("Please check at least 2 products to perform compare.");
		}
	}
	return;
}
 function Add_Skus_To_Cart(ThePFX){
  	RemovePages_Skus_From_SkuList();
	AddPages_Skus_To_SkuList();
	RemovePages_Qtys_From_QtyList();
	AddPages_Qtys_To_QtyList();
	TheSkus = selQTYs.split(";");
	count = TheSkus.length;
	PageSkus="";
	addSkus = "";
	//alert(count);
	if (selQTYs != ''){
		for (TT=0; TT < count; TT++) {
			// alert(TT)
			PageSkus = getItem(1,TheSkus[TT],"|");
			// alert(PageSkus);
			//SplitSkus = PageSkus.split(",");
			//scount = SplitSkus.length;
			
		}
		document.frmList.hdnPageAction.value = "InsertList"
		document.frmList.hdnSkuList.value = PageSkus
		document.frmList.hdnPfx.value = ThePFX
		document.frmList.action = 'Processcart.asp';
		document.frmList.submit();
	}
   	else
   	{
   	alert("Please fill quantity for at least 1 product.");
   	}
}

// fixPosition() attaches the element named eltname
// to an image named eltname
//
function showdiscount(divname, pos) {
if (document.getElementById(divname).style.visibility == 'visible') {
    document.getElementById(divname).style.visibility = 'hidden';
    }
else
{

		Thepos = document.getElementById(pos);
		coordsx = Thepos.offsetLeft + Thepos.offsetParent.offsetLeft;
  	    coordsy = Thepos.offsetTop + Thepos.offsetParent.offsetTop;
  	    coordsy += Thepos.height;

        if (isIE) {
		}
		else
		{
    	  coordsy += Thepos.height;
		}
		
		
		
		document.getElementById(divname).style.left = (coordsx) + 'px';
		document.getElementById(divname).style.top = (coordsy) + 'px';
		document.getElementById(divname).style.visibility = 'visible';
		document.getElementById(divname).style.zindex=1;

}
}

function ShowTrace(TheTrace) {
//alert(TheTrace);
newwindow=window.open();
newdocument=newwindow.document;
newdocument.write(TheTrace);
//newdocument.close();
return;
 }
