
//===========================================================================

// MENU CONTROL FOR CATALOG BROWSE PRODUCTS

//===========================================================================
function showSubGroup(id){

	if (window.document.getElementById(id)){

		var group = window.document.getElementById(id);
		var groupimg = window.document.getElementById('img-'+id);
		
		if (group.style.display==''){
			group.style.display='none';
			groupimg.src = 'images/closed.gif';
		}else{
			group.style.display='';
			groupimg.src = 'images/open.gif';
		}
		
	}

}

//===========================================================================

// DISPLAYS RESUTL PAGE NUMBERS 

//===========================================================================
function calcResultPages(intCurrentPage, intStylesPerPage, intTotalStyles, url){

	// DEFAULT STYLES PER PAGE TO 10
	if (intStylesPerPage==''){intStylesPerPage = 10;}

	// CALC NUMBER OF PAGES
	var pageCount = intTotalStyles / intStylesPerPage;
	
	// LOOP PAGES
	for (var i=1;i<=pageCount+1;i++){
	
		if (i==intCurrentPage){
			document.write ("<B class='resultPage'>" + i + "</B>" + " ");
		}
		else{
			document.write ("<A href='" + url + "&currentPage=" + i + "' class='resultLink'>" + i + "</A>" + " ");
		}
	}

}

//===========================================================================

// CONTROLS ADD TO BASKET

//===========================================================================
function addBasket(frm, productCount){

	var noSelection = true;
	
	//CHECK FORM EXISTS
	if (frm){
	
		// MORE THAN ONE PRODUCT
		//if (productCount>1){
		//	var products = frm.Product.length;
		//	//LOOP THROUGH PRODUCTS
		//	for (var i=0;i<products;i++){
		//		if (frm.Product[i].checked){
		//			noSelection = false;
		//		}
		//	}
		//}
		// ONLY ONE PRODUCT
		//else{
		//	if (frm.Product.checked){
		//		noSelection = false;
		//	}
		//}
		
		
		var products = frm.Product.length;
		if(products == undefined){
			// 1 item
			if (frm.Product.checked){
				noSelection = false;
			}			
		}else{
			//LOOP THROUGH PRODUCTS
			for (var i=0;i<products;i++){
				if (frm.Product[i].checked){
					noSelection = false;
				}
			}
		}
		
		if (noSelection){
			alert('Please select a least one product.')
		}
		else{
			frm.submit();
		}
		
	}
}


//===========================================================================

// CONTROLS ADD TO BASKET
// Used in catalog2.asp where products use textboxes for qty

//===========================================================================

function checkString(strToCheck) {
	var bad = 0;
	for (i = 0; i < strToCheck.length; i++) {
	    ch = strToCheck.substring(i, i + 1);
	    if (ch != "0" && ch != "1" && ch != "2" && ch != "3" && ch != "4" && ch != "5" && ch != "6" && ch != "7" && ch != "8" && ch != "9") { 
			bad = 1; 
		} 
	}
	if (bad==1){ 
		return false;
	}else{ 
		return true;
	}
}


function addQtyBasket(frm, productCount){

	var noSelection = true;
	
	//CHECK FORM EXISTS
	if (frm){		
		for(var i=0; i<frm.length; i++)
		{
			//alert("CHECKING FIELD : " + frm.elements[i].name + "\n" + " VALUE : " + frm.elements[i].value + " \n" + " LENGTH : " + frm.elements[i].value.length + " \n" + " TYPE : " +  frm.elements[i].type);
			if (frm.elements[i].type == "text" )
			{		
				if(frm.elements[i].value == "0"){
					// 0 qty OR non numeric text
				}else if(checkString(frm.elements[i].value)){
					noSelection = false;
				}
			}
		}
		
		if (noSelection){
			alert('Please Select at least one product using the quantity boxes provided')
		}
		else{
			frm.submit();
		}		
		
	}
	return false;
}
