
function SetColorAndSizes(color_id)
{
	var found = false;
	var i = 0;
	while((i < cl.length) && !found)
	{
		if(cl[i].color_id == color_id)
		{
			found = true;
		}
		else
			i++;
		
	}
	
	MM_setTextOfLayer('availableSizes','',cl[i].sizes);
	
	    //show image
    if(document.images)
    {
		document.images.colorThumb.src = "/images/productColorThumbs/" +  cl[i].thumb;   
    }
}

function ColorSelect(table_id,color)
{
	newcolor = color.split('|');
	
	if (document.all)
	{
		var thestyle= eval ('document.all.'+table_id+'.style');
		thestyle.backgroundColor=newcolor[0];
	}
}

function QntyCheck(qnty,formfield)
{

		//need to check to be sure that sizes have been chosen
		var total	= 0;
		var i		= 0;
		var name	= "";
		var value	= 0;
		var error	=	null;
		
		for(i=0;i<form.length;i++)
		{ 
			name	= form.elements[i].name;
			value	= numberCharFilter(form.elements[i].value);
			if(value == 0 && name != 'action' && name != 'minQnty' && name != 'ProductSetup_id')
			{
				form.elements[i].value = 0;
			}
				//alert( form.elements[i].name);
				
			if(name != 'action' && name != 'minQnty' && name != 'ProductSetup_id')
			{
				total = parseInt(total) + parseInt(value); 
				//alert(name + " : " + value);
			}
		}
		
	
		
		if(parseInt(formfield) < qnty)
		{
			error = error + "Your Quantity is less than the Minimum Quantity for this product please adjust your quantities\n\rMinimum Quantity: " + qnty;	
		}
		
		if(parseInt(total) <= 0)
		{
			error = error + "Please select add a quantity to at leaset one of the size choices!";
		} 
		
		
		if(error != null)
		{
			alert(error);
		 return false;
		}else{
		//alert('good');
		 return true;	
		}

}

function addToQnty(thisid,form,thisQnty)
{
	
	var total	= 0;
	var i		= 0;
	var name	= "";
	var value	= 0;
	 
	 for(i=0;i<form.length;i++)
	 { 
		name	= form.elements[i].name;
		value	= numberCharFilter(form.elements[i].value);
		if(value == 0 && name != 'action' && name != 'minQnty' && name != 'ProductSetup_id' && name != 'Product_id' && name != 'MinimumQnty')
		{
			form.elements[i].value = 0;
		}
			//alert( form.elements[i].name);
			
		if(name != 'action' && name != 'minQnty' && name != 'ProductSetup_id' && name != 'Product_id' && name != 'MinimumQnty')
		{
			total = parseInt(total) + parseInt(value); 
			//alert(name + " : " + value);
		}
	}


	form.minQnty.value = total;
}


function numberCharFilter(string)	
// Purpose		:	Utility funtion used by _setPhone(string)
//					Removes all non numerical characters
// Precondition	:	none
// Postcondition:	returns a string conisting of numeric characters
{
	var digits = ""; // should hold only digits
	var allow = "0123456789";
	var j=0;
	
	for(i=0; i < string.length; i++)
	{
		var match = false;
		
		while(j < allow.length && match == false)
		{
			if(string.charAt(i) == allow.charAt(j))
			{
				digits += string.charAt(i);	
				match = true;
			}
			j++;
		}
		j=0;
			
	}
	if(digits.length)
	{  
		return digits;
	}else{
		return 0;
	}
}

function showDivDyn(divID) { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
	document.getElementById(divID).style.visibility = 'visible'; 
	} else { 
		if (document.layers) { // Netscape 4 
			document.logo.visibility = 'visible'; 
		} else { // IE 4		
			document.all.logo.style.visibility = 'visible'; 
		} 
	} 
}

function hideDivDyn(divID) { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
	document.getElementById(divID).style.visibility = 'hidden'; 
	} else { 
		if (document.layers) { // Netscape 4 
		document.logo.visibility = 'hidden'; 
		} 
		else { // IE 4 
		document.all.logo.style.visibility = 'hidden'; 
		} 
	} 
} 

function SubmitForm(){
	document.forms[1].ColorSubmit.value = "Submit";
	document.forms[1].submit();
}
function SubmitColorForm(strForm){
	strForm.ColorSubmit.value = "Submit";
	strForm.submit();
}
