function maincat(mcid,mcname,mpcid){
this.mcid = mcid;
this.mcname = mcname;
this.mpcid = mpcid;
}

function getMainCats(ctrl,selcatid){
	    var frm = ctrl.form;
        var s_select = frm.example;
        //delete values from s_select (subcats)
        s_select.length=0;
        //populate states select
        for (i=0;i<myarray1.length;i++){
				if (myarray1[i].mpcid == ctrl.value || myarray1[i].mpcid == '0'){
						//call function to add the options
						AddOption(s_select,myarray1[i].mcname,myarray1[i].mcid,selcatid);
				}
        }
}

function subcat(cid,cname,pcid){
this.cid = cid;
this.cname = cname;
this.pcid = pcid;
}

function getSubCats(ctrl,selcatid){
        var frm = ctrl.form;
        var s_select = frm.stage2;
        //delete values from s_select (subcats)
        s_select.length=0;
        //populate states select
        for (i=0;i<myarray2.length;i++){
				if (myarray2[i].pcid == ctrl.value || myarray2[i].pcid == '0'){
				//call function to add the options
						AddOption(s_select,myarray2[i].cname,myarray2[i].cid,selcatid);
				}
        }
}
function product(pid,pname,prodcid){
this.pid = pid;
this.pname = pname;
this.prodcid = prodcid;
}

function getProducts(ctrl,cf,selcatid){
var frm = ctrl.form;
var s_select2 = frm.stage3;
        //delete values from s_select (subcats)
        s_select2.length=0;
		cboItems=0;
        //populate states select
        for (i=0;i<myarray3.length;i++){
				if (myarray3[i].prodcid == ctrl.value || myarray3[i].prodcid == '0'){
						//call function to add the options
						AddOption(s_select2,myarray3[i].pname,myarray3[i].pid,selcatid);
						if (myarray3[i].prodcid != '0'){
							cboItems = cboItems + 1;
						}
				}
        }
		//alert(cboItems);
		if (cboItems == 0 && cf == '') {
			i="/products/?pcid="+document.isc.stage2.options[document.isc.stage2.selectedIndex].value;
			window.location=i;
		}

}



//FUNCTIONS FOR SELECT BOXES ************************************
function RemoveOption(ctrl,txt,val){
//remove given option
for (i=0;i<ctrl.length;i++){
if (ctrl.options[i].text == txt && ctrl.options[i].value == val){
ctrl.options[i] = null

}}}


function AddOption(ctrl,txt,val,selcatid){
//OLD CODE START	
var opt = new Option;
opt.text = txt;
opt.value = val;
if (opt.value == selcatid){
opt.selected = true;
}
// First try the DOM2 method ...
try {
ctrl.add(opt,null);
}
// ... And if that doesn't work use the IE-only method
catch (e) {
ctrl.add(opt);
}



//ctrl.add(opt);
//alert('text='+opt.text);
//alert('val='+opt.value);
//returns index of option added
return eval(ctrl.length)-1;
//OLD CODE END
}

