
var CateogyID;
var SubCategoryID;
var SubCategoryDivName;
var FCatName;

function FormClearSelect(p) {
	for(var i=0; i<p.options.length; i++){
		p.options[i] = null;
	}
	p.options.length = 0;
}

function FormMakeSelected(d, id) {
	for(var i=0; i<d.options.length; i++){
		d.options[i].selected = false;
		if(d.options[i].value==id) {
			d.options[i].selected = true;
		}
	}
}

function FormCategoryInsert(id, name) {
	CateogyID.options[CateogyID.options.length] = new Option(name,id);
}

function FormSubCategoryInsert(id, name) {
	SubCategoryID.options[SubCategoryID.options.length] = new Option(name,id);
}

function FormSubCategoryFill(id) {
	for(x=0; x<categorybse.length; x++){
		if((categorybse[x][2]==1)&&(categorybse[x][3]==id)) {
			FormSubCategoryInsert(categorybse[x][0],categorybse[x][1]);
		}
	}
}

function GetCategoryBySubCategoryID(SubID) {
	for(x=0; x<categorybse.length; x++){
		if((categorybse[x][2]==1)&&(categorybse[x][0]==SubID)) {
			return categorybse[x][3];
		}
	}
	return 0;
}

function InitCategorySelectBox(CatID, SubCatID, SubCatDivName, SubCatDefault, FirstName, CatDefault) {

	CateogyID = CatID;
	SubCategoryID = SubCatID;
	SubCategoryDivName = SubCatDivName;
	FCatName = FirstName;

	// Clear Selects
	FormClearSelect(CateogyID);
	FormClearSelect(SubCategoryID);

	// Fill Category List
	FormCategoryInsert("0",FCatName);
	for(x=0; x<categorybse.length; x++){
		if(categorybse[x][2]==0) {
			FormCategoryInsert(categorybse[x][0],categorybse[x][1]);
		}
	}

	// Set category select by default
	if(CatDefault!=0) {
		FormMakeSelected(CateogyID, CatDefault);
	} else {
		if(SubCatDefault!=0) {
			FormMakeSelected(CateogyID, GetCategoryBySubCategoryID(SubCatDefault));
		}
	}

	// Fill Sub Category List
	OnFormCategorySelect();

	// Set sub category select by default
	FormMakeSelected(SubCategoryID, SubCatDefault);
}

function OnFormCategorySelect() {
	FormClearSelect(SubCategoryID);
	FormSubCategoryInsert("",FCatName);
	if(CateogyID.value!='0') {
		FormSubCategoryFill(CateogyID.value);
	}
}

function OpenAddReminder(id) {
	var load = window.open('/events/calendar.html?id='+id,'','scrollbars=no,menubar=no,height=30,width=450,resizable=yes,toolbar=no,location=no,status=no');
}
