
reNUM = /^(\d+)$/;
reEMAIL = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

function itemkit(){
	rvalue = splitkitoptions();
	rvalue = isKitNum();
	return rvalue;
}

function splitkitoptions(){
	xForm = document.sbkitform;
	selecttype = new Array;
	selectcolorway = new Array;
	selectsize = new Array;
	selectoption = new Array;
	sknprice = new Array;
	no_option = "/0//0"
	var yarnreturn = "|"
	var optionskeins=0
	var optionprice=0;
	var optionname="";
	var optionnumber="";
	var optioncount=0;
	var optiontitle="";

	selecttype = xForm.item_type.value.split("/");
	selectcolorway = xForm.item_colorway.value.split("/");
	selectsize = xForm.item_size.value.split("/");
	
	if (xForm.item_option){
	optioncount =xForm.item_option.length;
	optiontitle="Optional Add-Ons";
	for(count=0;count < optioncount;count++){
		if (xForm.item_option[count].checked == true)
				selectoption = xForm.item_option[count].value.split("/");
			else
				selectoption = no_option.split("/");
		optionskeins += Number(selectoption[1]);
		optionprice += Number(selectoption[3]);
		optionname += selectoption[0];
		optionnumber += selectoption[2];
		}
		}
		yarnreturn = getyarnprice(selecttype[3]);
		sknprice = yarnreturn.split("|");
		Price = new Number;
		Price = Number(selecttype[1]) + Number(selectcolorway[1]*sknprice[0]) + Number(selectsize[1]*sknprice[0]) + Number(optionskeins*sknprice[0])+ Number(optionprice);
		xForm.item_name.value = selecttype[0] + selectcolorway[0] + selectsize[0] + optionname;
		xForm.on0.value = optiontitle;
		xForm.os0.value = optionname;
		xForm.amount.value = Price.toFixed(2);
		xForm.item_number.value = selecttype[2] + selectcolorway[2] + selectsize[2] + optionnumber;
		xForm.price.value = "$" + Price.toFixed(2);
				
	return true;
}

function sbItemFormSubmit(vType, xForm){
  if(vType==1){
        selectlist = new Array;
        selectlist = xForm.item_select.value.split("/");
        xForm.item_name.value = selectlist[0];
        xForm.amount.value = selectlist[1];
        xForm.item_number.value = selectlist[2];
 }
 if (reNUM.test(xForm.quantity.value)){return true;}
 alert("Please enter the number of Items you wish to purchase.");
 xForm.quantity.focus();
 xForm.quantity.select();
 return false;
}

function isKitNum(){
  xForm = document.sbkitform;
  if (reNUM.test(xForm.quantity.value)){return true;}
  alert("Please check the Quantity box, and try again.");
  xForm.quantity.focus();
  xForm.quantity.select();
  return false;
}

function isNumYarn(){
  if (document.getElementById){stdBrowser = true;}else{stdBrowser=false;}
  if (stdBrowser){xForm = document.getElementById('yarnform');}else{xForm = document.yarnform;}
  if (reNUM.test(xForm.quantity.value)){return true;}
  alert("Please enter the number of balls you wish to purchase.");
  xForm.quantity.focus();
  xForm.quantity.select();
  return false;
}

function isEMAIL() {
	xForm = document.sbemailform;
	if (reEMAIL.test(eForm.email.value)) {return true}
	alert("Please check the E-Mail address you entered")
	myForm.email.focus()
	myForm.email.select()
	return false
	}
	
function getyarnprice(yarn){
	switch(yarn){
		case "ara":
			return "5.35|reg";
		case "babyull":
			return "5.90|reg";
		case "daletta":
			return "4.70|reg";
		case "falk":
			return "4.90|reg";
		case "freestyle":
			return "4.70|reg";
		case "hauk":
			return "4.95|reg";
		case "heilo":
			return "4.70|reg";
		case "sisik":
			return "5.35|reg";
		case "stork":
			return "4.80|reg";
		case "svale":
			return "5.35|reg";
		case "tiur":
			return "6.10|reg";
		default:
			return "error|error";
		}
	}
		
function SetDTM(){
  var n = new Date();
  var cmd = "|" + n.toUTCString();
  if (document.getElementById){stdBrowser = true;}else{stdBrowser=false;}
  if (stdBrowser){xForm = document.getElementById('newsform');}else{xForm = document.newsform;}
  xForm = document.newsform;
  xForm.cmd.value += cmd;
  return true;
	}		
