function setupradio(fieldName,newTrigger)
{
	$('#fld_length'+fieldName).val('NA');
	$('#fld_length'+fieldName).attr('disabled',true);
	$('#options_linetype'+fieldName).attr('disabled',true);
	$('#options_linetype'+fieldName).val('NA');
	$('#fld_linetype'+fieldName).attr('disabled',true);
	$('#options_fieldtype'+fieldName).removeAttr('disabled');
	if (newTrigger=='Y')
	{
		$('#options_fieldtype'+fieldName).val('');
	}
}
function setupcheck(fieldName,newTrigger)
{

	$('#fld_length'+fieldName).val('NA');
	$('#fld_length'+fieldName).attr('disabled',true);
	$('#options_fieldtype'+fieldName).value='NA';
	$('#options_fieldtype'+fieldName).attr('disabled',true);
	$('#options_linetype'+fieldName).attr('disabled',true);
	$('#options_linetype'+fieldName).val('NA');
	$('#fld_linetype'+fieldName).attr('disabled',true);
}

function setuptext(fieldName,newTrigger)
{
	$('#fld_length'+fieldName).removeAttr('disabled');
	$('#options_linetype'+fieldName).removeAttr('disabled');
	$('#fld_linetype'+fieldName).removeAttr('disabled');
	$('#options_fieldtype'+fieldName).val('NA');
	$('#options_fieldtype'+fieldName).attr('disabled',true);

	if (newTrigger=='Y')
	{
		$('#fld_length'+fieldName).val('');
		$('#options_linetype'+fieldName).val('');
	}
}
function getOrigValue(fieldNumber)
{
	var origType = $('#origtype_'+fieldNumber).val();
	var origIndex;

	if (origType=='text')
	{ origIndex=0; }
	else if (origType=='radio')
	{ origIndex=1; }
	else if (origType=='check')
	{ origIndex=2; }

	return origIndex;
}

function checkrequired() {
	//alert('here');
	pass = true;
	$(".required").filter(
		function (index) {
				$(this).css('background-color','#ffffff');

		}
	);
	$(".ritem").filter(
		function (index) {
				$(this).css('background-color','#ffffff');

		}
	);

	$(".required").filter(
		function (index) {
			if (pass) {

				if ($(this).val() == '') {
					$(this).css('background-color','#ffcc00');
					alert('Required information is missing in '+$(this).attr('title'));
					$(this).focus();
					pass = false;
				}
			}
		}
	);

	$(".radio").filter(
		function (index) {
			if (pass) {
				isselected = $("input[name='"+$(this).attr('radioname')+"']:checked").val();
				if (isselected === undefined) {
					alert($(this).attr('title')+" must have an option selected");
					$('#rnum_'+$(this).attr('rnum')).css('background-color','#ffcc00');
					pass = false;
				}
			}
		}
	);

	$(".check").filter(
		function (index) {

			if (pass) {
				isselected = $('#'+$(this).attr('checkname')).is(':checked');

				if (!isselected) {
					alert($(this).attr('title')+" must have an option selected");
					$('#rnum_'+$(this).attr('rnum')).css('background-color','#ffcc00');
					pass=false;
				}
			}
		}
	);
	return pass;
}

function presetValues(fieldName)
{
	var fieldType = $("#fld_type"+fieldName+" option:selected").val();
	if (fieldType=='radio')
	{
		if ($('#fieldStatus_'+fieldName).val() != 'new')
		{
			if (confirm("Are you sure you wish to continue?  This will overwrite your exiting settings for this field."))
				setupradio(fieldName,'Y');
			else
			{
				origIndex=getOrigValue(fieldName);
				document.getElementById('fld_type'+fieldName).selectedIndex = origIndex;
			}
		}else{
			setupradio(fieldName,'Y');
		}
	}

	if (fieldType=='check')
	{
		if ($('#fieldStatus'+fieldName).val() != 'new')
		{
			if (confirm("Are you sure you wish to continue?  This will overwrite your exiting settings for this field."))
				 setupcheck(fieldName,'Y');
			else
			{
				origIndex=getOrigValue(fieldName);
				document.getElementById('fld_type'+fieldName).selectedIndex = origIndex;
			}
		}else{
			setupcheck(fieldName,'Y');
		}
	}

	if (fieldType=='text')
	{
		if ($('#fieldStatus'+fieldName).val() != 'new')

		{
			if (confirm("Are you sure you wish to continue?  This will overwrite your exiting settings for this field."))
				setuptext(fieldName,'Y');
			else
			{
				origIndex=getOrigValue(fieldName);
				document.getElementById('fld_type'+fieldName).selectedIndex = origIndex;

			}
		}else{
			setuptext(fieldName,'Y');
		}
	}

}

function presetLines(fieldName) {
	var fieldType = $("#fld_linetype"+fieldName+" option:selected").val();
	if (fieldType=='single') {
		$('#options_linetype'+fieldName).attr('disabled',true);
		$('#options_linetype'+fieldName).val('NA');
	} else {
		$('#options_linetype'+fieldName).removeAttr('disabled');
		$('#options_linetype'+fieldName).val('');
	}
}
function checkempties(){
	for(a=10; a<51; a++)
	{
		if ($('fld_length'+a))
			$('#fld_length'+a).removeAttr('disabled');

		if ($('#options_linetype'+a))
			$('#options_linetype'+a).removeAttr('disabled');

		if ($('#fld_linetype'+a))
			$('fld_linetype'+a).removeAttr('disabled');

		if ($('#options_fieldtype'+a))
			$('#options_fieldtype'+a).removeAttr('disabled');

		if ($('#fld_name'+a).val() == '')
			$('#fld_name'+a).val(' ');

		if ($('#fld_type'+a).val() == '')
			$('#fld_type'+a).val(' ');

		if ($('#options_fieldtype'+a).val() =='')
			$('#options_fieldtype'+a).val(' ');

		if ($('#fld_length'+a).val() == '')
			$('#fld_length'+a).val(' ');

		if ($('#fld_req'+a).val() == '')
			$('#fld_req'+a).val(' ');

		if ($('#fld_linetype'+a).val() == '')
			$('#fld_linetype'+a).val(' ');

		if ($('#options_linetype'+a).val() == '')
			$('#options_linetype'+a).val(' ');

	}
	return true;
}

function inputTest(s){
	var tempstring = new String();
	tempstring = $('#formconfirm').val();
	while(tempstring.match("&")=="&"){
		tempstring=tempstring.replace('&',"and");
	}
	$('#formconfirm').val(tempstring);
}

