function CLEARBOX(BOX){for(i=BOX.length;i>=0;i--){BOX.options[i]=null;}}
function listfind(list,value,delimiters) {
if(!delimiters){var delimiters=','}
list = list.toUpperCase();
value = value.toUpperCase();
_TempListSplitArray = list.split(delimiters)
FoundIdx = 0;
for(i=0;i<_TempListSplitArray.length;i++)
{
if(_TempListSplitArray[i]==value)
	{
	FoundIdx= i+1;
	break
	}
}
return FoundIdx
}

function  replace(string, substring1, substring2 , scope )
{
if(!scope){scope='1'}
if(scope!='ALL'){scope='1'}
re = '/'+substring1
if(scope=='1'){re += '/'}
else{re +='/g'}
new_string = string.replace(eval(re),substring2)
return new_string
}

function FillBox(BOX,TEXT,VALUE,POS){
if(!POS)POS=0;
newoption = new Option(TEXT,VALUE, false, false);
BOX.options[POS] = newoption;}
function listtoarray(list,delimiters) {
if(!delimiters){var delimiters=','}
_TempListSplitArray = list.split(delimiters)
return _TempListSplitArray
}

function AddOption(){
errors="";
if(FRM.OptionName.value == "")errors=errors+ "Please enter the name for this Level (ie. Red,large etc.)\n";
if(errors==""){
OptName=OptName=replace(replace(FRM.OptionName.value, ";", "" , "ALL"), "~", "" , "ALL");
	val = OptName + ";" + 0;
	txt = OptName;
	FillBox(FRM.CreatedOptions,txt,val,FRM.CreatedOptions.length);
	FRM.OptionName.value="";
}
else alert(errors);
}

function RemoveOption(){
	if(FRM.CreatedOptions.selectedIndex >= 0){
	selval = FRM.CreatedOptions.options[FRM.CreatedOptions.selectedIndex].value;
		FRM.CreatedOptions.options[FRM.CreatedOptions.selectedIndex] = null;
	temp = selval.split(";");
	id = eval(temp[1]);
	if(id > 0){FRM.options_remove.value=FRM.options_remove.value + "," + id;}
	}
}

function FormSubmit(){
errors="";
if(FRM.OptionGroup.value == "")errors=errors+ "Please enter the name for these groups of Levels\n";
if(FRM.CreatedOptions.length == 0)errors=errors+ "Please enter Levels in for this Level group\n";

if(errors==""){
Optiontemp="";
		for(X=0;X<=FRM.CreatedOptions.length-1;X++){
			Optiontemp = Optiontemp + FRM.CreatedOptions.options[X].value + "~";
		}

	FRM.options_add.value=Optiontemp;
	FRM.submit(FRM);
}
else alert(errors);
}

function RemoveFromBox(BOX){if(BOX.selectedIndex >= 0){BOX.options[BOX.selectedIndex] = null;}}

function ExistsinBox(BOX,VAL){
found = false;
for(X=0;X<=BOX.length-1;X++){if(BOX.options[X].value==VAL)found=true;}
return found;
}

function ExistsinSelection(BOX,VAL){
found = false;
for(X=0;X<=BOX.length-1;X++){
	temp = BOX.options[X].value.split(",");
	option_id = temp[0];
	if(option_id==VAL)found=true;
}
return found;
}

function SortBox(box)  {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++)  {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++)  {
for(var y=(x+1); y<temp_opts.length; y++)  {
if(temp_opts[x].text > temp_opts[y].text)  {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
temp = temp_opts[x].value;
temp_opts[x].value = temp_opts[y].value;
temp_opts[y].value = temp;
      }
   }
}
for(var i=0; i<box.options.length; i++)  {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
   }
}

	function SameAsClick(){
		FRM = document.forms["orderform"];
		isChecked = FRM.elements["SameAs"].checked;
		if(isChecked){
			FRM.shippingname.value = FRM.first_name.value + " " + FRM.last_Name.value;
			FRM.shippingaddress.value = FRM.address.value;
			FRM.shippingcity.value = FRM.city.value;
			FRM.shippingstate.value = FRM.state.value;
			FRM.shippingzip.value = FRM.zip.value;						
			FRM.shippingcountry.value = FRM.country.value;
			FRM.cardType.focus();
		}
		else{
			FRM.shippingname.value =  "";
			FRM.shippingaddress.value =  "";
			FRM.shippingcity.value =  "";
			FRM.shippingstate.value =  "Illinois";
			FRM.shippingzip.value = "";
			FRM.shippingcountry.value = "US";
			FRM.shippingname.focus();
		}	
	}
	
function OpenChart(Chart_ID){
	window.open('/ViewChart.asp?Chart_ID='+Chart_ID,'VIEWCHART_' + Chart_ID,'scrollbars,width=600,height=550');
}
