/**
 * This function is used to populate the select drop-down box with
 * options. The format of the options array should be:
 * 
 * It should be observed that the correct number of parameters should be
 * passed in always.
 *
 * In case of the value of 'selectedValue' is not exsits on the dropdown list,
 * the first item on the dropdown list shall be selected.
 *
 * var optionsArray=[['value0','label0'],['value1','label1'],['value2','label2']];
 */
function populateOptions(selectId,optionsArray,selectedValue){
	var select=document.getElementById(selectId);
	var selected=false;
	select.selectedIndex= -1;
	select.options.length=0;
	for (var i=0;i<optionsArray.length;++i){
		select.options[i]=new Option(optionsArray[i][1],optionsArray[i][0]);
		if(selected==false && optionsArray[i][0]==selectedValue){
			selected=true;
			select.selectedIndex=i;
		}
	}
    if (selected==false){
        select.selectedIndex=0;
    }
}
function populateNumericOptions(selectId,lower,upper,selectedValue){
	var select=document.getElementById(selectId);
	var selected=false;
	select.selectedIndex= -1;
	select.options.length=0;
	for (var i=lower;i<=upper;++i){
		select.options[i-lower]=new Option(i.toString(),i.toString());
		if(selected==false && i.toString()==selectedValue){
			selected=true;
			select.selectedIndex=i-lower;
		}
	}
    if (selected==false){
        select.selectedIndex=0;
    }
}

function populateOptionsMulti(selectId,optionsArray,selectedValue,multiplier){
	var selectedIndex=0;
	var select=document.getElementById(selectId);
	var selected=false;
	select.selectedIndex= -1;
	select.options.length=0;
	var j =0;
	for (var i=multiplier-1;i<optionsArray.length;i=i+multiplier){
		select.options[j]=new Option(optionsArray[i][1],optionsArray[i][0]);
		if(selected==false&&optionsArray[i][0]==selectedValue){
			selected=true;
			selectedIndex=j;
		}
		++j;
	}
	select.selectedIndex=selectedIndex;
}
/**
 * This function is used to populate the select drop-down box with
 * options. A "class" attribute can be added as well.
 *
 * The format of the options array should be:
 *
 * var optionsArray=[['value0','label0','class0'],['value1','label1','class1'],['value2','label2','class2']];
 *
 * If the class is empty it will not add a class attribute to that option.
 * 
 * It should be observed that the correct number of parameters should be
 * passed in always.
 *
 * In case of the value of 'selectedValue' is not exsits on the dropdown list,
 * the first item on the dropdown list shall be selected.
 */
function populateOptionsWithStyle(selectId,optionsArray,selectedValue){
	var select=document.getElementById(selectId);
	var selected=false;
	select.selectedIndex= -1;
	select.options.length=0;
	for (var i=0;i<optionsArray.length;++i){
		select.options[i]=new Option(optionsArray[i][1],optionsArray[i][0]);
		if(optionsArray[i][2]!=null && optionsArray[i][2]!="") {
			select.options[i].className=optionsArray[i][2];
		}
		if(selected==false && optionsArray[i][0]==selectedValue){
			selected=true;
			select.selectedIndex=i;
		}
	}
    if (selected==false){
        select.selectedIndex=0;
    }
}