 function selectValue(formObjectName,givenValue)
{
	formObject = document.forms[0].item(formObjectName);
	optionsLength = formObject.length;

	for(kk=0;kk<optionsLength;kk++)
	{
		if(formObject.options[kk].value==givenValue)
		{
			formObject.selectedIndex=kk;
			break;
		}
	}
}
function selectChecked(formObjectName,givenValue)
{
	formObject = document.forms[0].item(formObjectName);
	if (givenValue=="Y")
	{
		formObject.checked = true;
	}
}

function selectByValue(formObject,givenValue)
{
	optionsLength = formObject.length;

	for(kk=0;kk<optionsLength;kk++)
	{
		if(formObject.options[kk].value==givenValue)
		{
			formObject.selectedIndex=kk;
			break;
		}
	}
}

function selectByText(formObject,givenText)
{
	optionsLength = formObject.length;
	for(kk=0;kk<optionsLength;kk++)
	{
		if(formObject.options[kk].text==givenText)
		{
			formObject.selectedIndex=kk;
			break;
		}
	}
}

function setComponent(whichComponent,givenValue,whichForm,valueOrText)
{
	if(arguments[2]==null) whichForm=0;

	formObject = document.forms[whichForm].elements[whichComponent];

	objectType = formObject.type;

	objectIsArray="no";
	if(objectType==null)
	{
		objectType=formObject[0].type;
		objectIsArray="yes";
	}

	if(objectType=="select-one")
	{
		if(arguments[3]==null)    alert("SELECT TYPE:\nYou have not defined whether\n  - " + givenValue+" is Value? \n      or \n  - " + givenValue+" is Text?\n\nPlease specify the fourth parameter.");
		if(arguments[3]=="value") selectByValue(formObject,givenValue);
		if(arguments[3]=="text")  selectByText(formObject,givenValue);
		if(arguments[3]=="index") formObject.selectedIndex = givenValue
	}

	if(objectType=="text" || objectType=="hidden" || objectType=="textarea")
	{
		formObject.value=givenValue;
	}

	if( (objectType=="checkbox" || objectType=="radio")  && objectIsArray=="no")
	{
		formObject.checked=arguments[3];
	}

	if( (objectType=="checkbox" || objectType=="radio")  && objectIsArray=="yes")
	{
		optionsLength=formObject.length
		for(kk=0;kk<optionsLength;kk++)
		{
			if(formObject[kk].value==givenValue)
			{
				formObject[kk].checked=arguments[3];
			}
		}
	}

}


//now this function can also return the selected Index, valid parameters : text,value,index
function getComponent(whichComponent,whichForm,valueOrText)
{
	returnValue="";
	if(arguments[1]==null) whichForm=0;

	formObject = document.forms[whichForm].elements[whichComponent];

	objectType = formObject.type;

	objectIsArray="no";
	if(objectType==null)
	{
		objectType=formObject[0].type;
		objectIsArray="yes";
	}

	if(objectType=="select-one")
	{
		if(arguments[2]==null)    alert("SELECT TYPE:\nYou have not defined whether\n  - " + givenValue+" is Value? \n      or \n  - " + givenValue+" is Text?");
		if(arguments[2]=="value") returnValue=formObject.options[formObject.selectedIndex].value;	//formObject.selectedIndex.value;
		if(arguments[2]=="text")  returnValue=formObject.options[formObject.selectedIndex].text;
		if(arguments[2]=="index") returnValue=formObject.selectedIndex;
	}

	if(objectType=="text" || objectType=="hidden" || objectType=="textarea")
	{
		returnValue=formObject.value;
	}


	if( (objectType=="checkbox" || objectType=="radio")  && objectIsArray=="no")
	{
		if(formObject.checked==true) returnValue=formObject.value;
		else returnVallue="";
	}

	if( (objectType=="checkbox" || objectType=="radio")  && objectIsArray=="yes")
	{
		selectedArray=new Array();
		counter=-1;

		optionsLength=formObject.length
		for(kk=0;kk<optionsLength;kk++)
		{
			if(formObject[kk].checked==true)
			{
				selectedArray[++counter]=formObject[kk].value;
			}
		}
		returnValue=selectedArray;
	}

	//alert(returnValue);
	return returnValue;
}

function clearSelect(whichComponent,whichForm,startingIndex,endingIndex)
{
	if(arguments[1]==null) whichForm=0;
	formObject = document.forms[whichForm].elements[whichComponent];
	optionsLength = formObject.length
	if(startingIndex==null)
	{
		for(kk=optionsLength;kk>0;kk--)
			formObject.options[kk-1]=null;
	}
	else
	{
		//if ending position not specified, delete from given starting point to end
		if(endingIndex==null) endingIndex = optionsLength;
		for(kk=endingIndex+1;kk>startingIndex;kk--)
			formObject.options[kk-1]=null;
	}
}

function fillSelect(whichComponent,givenIndex,givenValue,givenText,whichForm)
{
	if(arguments[4]==null) whichForm=0;
	formObject = document.forms[whichForm].elements[whichComponent];

	optionsLength = formObject.length;
	if(givenIndex=="") givenIndex=optionsLength;

	var newOption = new Option(givenText,givenValue);
	formObject.options[givenIndex] = newOption;
}

/*
if you have only one form in one HTML, then instead of passing FORM NAME
every time, pass null everever it is being used in the middle of the parameters list

setComponent("mySelect","3","myForm","value");
setComponent("education","Masters","myForm",true)
setComponent("education","Masters","myForm",false)

setComponent("myText","Chhabra")
setComponent("education","Masters","myForm",true);
setComponent("country","India","myForm",true)
setComponent("country","USA","myForm",true)
setComponent("smoker","yes","myForm",true)
setComponent("smoker","no","myForm",true)
setComponent("required","yes","myForm",true)
setComponent("education","Masters","myForm",false);
setComponent("country","India","myForm",false)
setComponent("smoker","yes","myForm",false)
setComponent("required","yes","myForm",false)


a=getComponent("mySelect","myForm","value");
a=getComponent("myText")
getComponent("country");
alert("Everything set");


clearSelect("mySelect")
fillSelect("mySelect","3","1","FourIndex Here","myForm");
fillSelect("mySelect","","1","Last index Here","myForm");
*/

