var active_program = '';
var OPTS_SERVICE_TYPE = [":",
	"Undefined:Undefined",
	"Digital Television:Digital Television",
	"Digital Radio Sound:Digital Radio Sound",
	"Teletext:Teletext",
	"NVOD Reference:NVOD Reference",
	"NVOD Time-shifted:NVOD Time-shifted",
	"Mosaic:Mosaic",
	"PAL:PAL",
	"SECAM:SECAM",
	"D/D2-MAC:D/D2-MAC",
	"FM Radio:FM Radio",
	"NTSC:NTSC",
	"Data Broadcast:Data Broadcast",
	"Reserved CIU:Reserved CIU",
	"RCS Map:RCS Map",
	"RCS Map:RCS FLS",
	"DVB MHP:DVB MHP"
];
var selServiceType = [];
var selVoipType = [];
var OPTS_VOIPTYPE = [":", "Disabled:disabled", "SPTS UDP:spts udp", "SPTS RTP:spts rtp"];
var selVoipAndAsi = [];
var selScramble = [];
var OPTS_VOIPANDASI = [":", "Yes:Yes", "No:No"];
var selLang1 = [];
var selLang2 = [];
var OPTS_LANG_CODE = [
':',
'Not Detected:Not Detected',
'Abkhazian:abk',
'Achinese:ace',
'Acoli:ach',
'Adangme:ada',
'Adygei; Adyghe:ady',
'Adyghe; Adygei:ady',
'Afar:aar',
'Afrihili:afh',
'Afrikaans:afr',
'Afro-Asiatic (Other):afa',
'Akan:aka',
'Akkadian:akk',
'Albanian:alb',
'Aleut:ale',
'Algonquian languages:alg',
'Altaic (Other):tut',
'Amharic:amh',
'Apache languages:apa',
'Arabic:ara',
'Aragonese:arg',
'Aramaic:arc',
'Arapaho:arp',
'Araucanian:arn',
'Arawak:arw',
'Armenian:arm',
'Artificial (Other):art',
'Assamese:asm',
'Asturian; Bable:ast',
'Athapascan languages:ath',
'Australian languages:aus',
'Austronesian (Other):map',
'Avaric:ava',
'Avestan:ave',
'Awadhi:awa',
'Aymara:aym',
'Azerbaijani:aze',
'Bable; Asturian:ast',
'Balinese:ban',
'Baltic (Other):bat',
'Baluchi:bal',
'Bambara:bam',
'Bamileke languages:bai',
'Banda:bad',
'Bantu (Other):bnt',
'Basa:bas',
'Bashkir:bak',
'Basque:baq',
'Batak (Indonesia):btk',
'Beja:bej',
'Belarusian:bel',
'Bemba:bem',
'Bengali:ben',
'Berber (Other):ber',
'Bhojpuri:bho',
'Bihari:bih',
'Bikol:bik',
'Bilin; Blin:byn',
'Bini:bin',
'Bislama:bis',
'Blin; Bilin:byn',
'Bokml, Norwegian; Norwegian Bokml:nob',
'Bosnian:bos',
'Braj:bra',
'Breton:bre',
'Buginese:bug',
'Bulgarian:bul',
'Buriat:bua',
'Burmese:bur',
'Caddo:cad',
'Carib:car',
'Castilian; Spanish:spa',
'Catalan; Valencian:cat',
'Caucasian (Other):cau',
'Cebuano:ceb',
'Celtic (Other):cel',
'Central American Indian (Other):cai',
'Chagatai:chg',
'Chamic languages:cmc',
'Chamorro:cha',
'Chechen:che',
'Cherokee:chr',
'Chewa; Chichewa; Nyanja:nya',
'Cheyenne:chy',
'Chibcha:chb',
'Chichewa; Chewa; Nyanja:nya',
'Chinese:chi',
'Chinook jargon:chn',
'Chipewyan:chp',
'Choctaw:cho',
'Chuang; Zhuang:zha',
'Church Slavic; Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic:chu',
' Church Slavonic; Church Slavic; Old Slavonic; Old Bulgarian; Old Church Slavonic:chu',
'Chuukese:chk',
'Chuvash:chv',
'Classical Newari; Old Newari:nwc',
'Coptic:cop',
'Cornish:cor',
'Corsican:cos',
'Cree:cre',
'Creek:mus',
'Creoles and pidgins (Other):crp',
'Creoles and pidgins, English-based (Other):cpe',
'Creoles and pidgins, French-based (Other):cpf',
'Creoles and pidgins, Portuguese-based (Other):cpp',
'Crimean Tatar; Crimean Turkish:crh',
'Crimean Turkish; Crimean Tatar:crh',
'Croatian:scr',
'Cushitic (Other):cus',
'Czech:cze',
'Dakota:dak',
'Danish:dan',
'Dargwa:dar',
'Dayak:day',
'Delaware:del',
'Dinka:din',
'Divehi:div',
'Dogri:doi',
'Dogrib:dgr',
'Dravidian (Other):dra',
'Duala:dua',
'Dutch; Flemish:dut',
'Dutch, Middle (ca. 1050-1350):dum',
'Dyula:dyu',
'Dzongkha:dzo',
'Efik:efi',
'Egyptian (Ancient):egy',
'Ekajuk:eka',
'Elamite:elx',
'English:eng',
'English, Middle (1100-1500):enm',
'English, Old (ca.450-1100):ang',
'Erzya:myv',
'Esperanto:epo',
'Estonian:est',
'Ewe:ewe',
'Ewondo:ewo',
'Fang:fan',
'Fanti:fat',
'Faroese:fao',
'Fijian:fij',
'Finnish:fin',
'Finno-Ugrian (Other):fiu',
'Flemish; Dutch:dut',
'Fon:fon',
'French:fre',
'French, Middle (ca.1400-1600):frm',
'French, Old (842-ca.1400):fro',
'Frisian:fry',
'Friulian:fur',
'Fulah:ful',
'Ga:gaa',
'Gaelic; Scottish Gaelic:gla',
'Gallegan:glg',
'Ganda:lug',
'Gayo:gay',
'Gbaya:gba',
'Geez:gez',
'Georgian:geo',
'German:ger',
'German, Low; Saxon, Low; Low German; Low Saxon:nds',
'German, Middle High (ca.1050-1500):gmh',
'German, Old High (ca.750-1050):goh',
'Germanic (Other):gem',
'Gikuyu; Kikuyu:kik',
'Gilbertese:gil',
'Gondi:gon',
'Gorontalo:gor',
'Gothic:got',
'Grebo:grb',
'Greek, Ancient (to 1453):grc',
'Greek, Modern (1453-):gre',
'Greenlandic; Kalaallisut:kal',
'Guarani:grn',
'Gujarati:guj',
'Gwich&#xFFFD;in:gwi',
'Haida:hai',
'Haitian; Haitian Creole:hat',
'Haitian Creole; Haitian:hat',
'Hausa:hau',
'Hawaiian:haw',
'Hebrew:heb',
'Herero:her',
'Hiligaynon:hil',
'Himachali:him',
'Hindi:hin',
'Hiri Motu:hmo',
'Hittite:hit',
'Hmong:hmn',
'Hungarian:hun',
'Hupa:hup',
'Iban:iba',
'Icelandic:ice',
'Ido:ido',
'Igbo:ibo',
'Ijo:ijo',
'Iloko:ilo',
'Inari Sami:smn',
'Indic (Other):inc',
'Indo-European (Other):ine',
'Indonesian:ind',
'Ingush:inh',
'Interlingua (International Auxiliary Language Association):ina',
'Interlingue:ile',
'Inuktitut:iku',
'Inupiaq:ipk',
'Iranian (Other):ira',
'Irish:gle',
'Irish, Middle (900-1200):mga',
'Irish, Old (to 900):sga',
'Iroquoian languages:iro',
'Italian:ita',
'Japanese:jpn',
'Javanese:jav',
'Judeo-Arabic:jrb',
'Judeo-Persian:jpr',
'Kabardian:kbd',
'Kabyle:kab',
'Kachin:kac',
'Kalaallisut; Greenlandic:kal',
'Kalmyk:xal',
'Kamba:kam',
'Kannada:kan',
'Kanuri:kau',
'Karachay-Balkar:krc',
'Kara-Kalpak:kaa',
'Karen:kar',
'Kashmiri:kas',
'Kashubian:csb',
'Kawi:kaw',
'Kazakh:kaz',
'Khasi:kha',
'Khmer:khm',
'Khoisan (Other):khi',
'Khotanese:kho',
'Kikuyu; Gikuyu:kik',
'Kimbundu:kmb',
'Kinyarwanda:kin',
'Kirghiz:kir',
'Klingon; tlhlngan-Hol:tlh',
'Komi:kom',
'Kongo:kon',
'Konkani:kok',
'Korean:kor',
'Kosraean:kos',
'Kpelle:kpe',
'Kru:kro',
'Kuanyama; Kwanyama:kua',
'Kumyk:kum',
'Kurdish:kur',
'Kurukh:kru',
'Kutenai:kut',
'Kwanyama, Kuanyama:kua',
'Ladino:lad',
'Lahnda:lah',
'Lamba:lam',
'Lao:lao',
'Latin:lat',
'Latvian:lav',
'Letzeburgesch; Luxembourgish:ltz',
'Lezghian:lez',
'Limburgan; Limburger; Limburgish:lim',
'Limburger; Limburgan; Limburgish; :lim',
'Limburgish; Limburger; Limburgan:lim',
'Lingala:lin',
'Lithuanian:lit',
'Lojban:jbo',
'Low German; Low Saxon; German, Low; Saxon, Low:nds',
'Low Saxon; Low German; Saxon, Low; German, Low:nds',
'Lower Sorbian:dsb',
'Lozi:loz',
'Luba-Katanga:lub',
'Luba-Lulua:lua',
'Luiseno:lui',
'Lule Sami:smj',
'Lunda:lun',
'Luo (Kenya and Tanzania):luo',
'Lushai:lus',
'Luxembourgish; Letzeburgesch:ltz',
'Macedonian:mac',
'Madurese:mad',
'Magahi:mag',
'Maithili:mai',
'Makasar:mak',
'Malagasy:mlg',
'Malay:may',
'Malayalam:mal',
'Maltese:mlt',
'Manchu:mnc',
'Mandar:mdr',
'Mandingo:man',
'Manipuri:mni',
'Manobo languages:mno',
'Manx:glv',
'Maori:mao',
'Marathi:mar',
'Mari:chm',
'Marshallese:mah',
'Marwari:mwr',
'Masai:mas',
'Mayan languages:myn',
'Mende:men',
'Micmac:mic',
'Minangkabau:min',
'Miscellaneous languages:mis',
'Mohawk:moh',
'Moksha:mdf',
'Moldavian:mol',
'Mon-Khmer (Other):mkh',
'Mongo:lol',
'Mongolian:mon',
'Mossi:mos',
'Multiple languages:mul',
'Munda languages:mun',
'Nahuatl:nah',
'Nauru:nau',
'Navaho, Navajo:nav',
'Navajo; Navaho:nav',
'Ndebele, North:nde',
'Ndebele, South:nbl',
'Ndonga:ndo',
'Neapolitan:nap',
'Nepali:nep',
'Newari:new',
'Nias:nia',
'Niger-Kordofanian (Other):nic',
'Nilo-Saharan (Other):ssa',
'Niuean:niu',
'Nogai:nog',
'Norse, Old:non',
'North American Indian (Other):nai',
'Northern Sami:sme',
'North Ndebele:nde',
'Norwegian:nor',
'Norwegian Bokm&#xFFFD;l; Bokm&#xFFFD;l, Norwegian:nob',
'Norwegian Nynorsk; Nynorsk, Norwegian:nno',
'Nubian languages:nub',
'Nyamwezi:nym',
'Nyanja; Chichewa; Chewa:nya',
'Nyankole:nyn',
'Nynorsk, Norwegian; Norwegian Nynorsk:nno',
'Nyoro:nyo',
'Nzima:nzi',
'Occitan (post 1500); Provenal:oci',
'Ojibwa:oji',
'Old Bulgarian; Old Slavonic; Church Slavonic; Church Slavic; Old Church Slavonic:chu',
'Old Church Slavonic; Old Slavonic; Church Slavonic; Old Bulgarian; Church Slavic :chu',
'Old Newari; Classical Newari:nwc',
' Old Slavonic; Church Slavonic; Old Bulgarian; Church Slavic; Old Church Slavonic :chu',
'Oriya: ori',
'Oromo:orm',
'Osage:osa',
'Ossetian; Ossetic:oss',
'Ossetic; Ossetian:oss',
'Otomian languages:oto',
'Pahlavi:pal',
'Palauan:pau',
'Pali:pli',
'Pampanga:pam',
'Pangasinan:pag',
'Panjabi; Punjabi:pan',
'Papiamento:pap',
'Papuan (Other):paa',
'Persian:per',
'Persian, Old (ca.600-400 B.C.):peo',
'Philippine (Other):phi',
'Phoenician:phn',
'Pohnpeian:pon',
'Polish:pol',
'Portuguese:por',
'Prakrit languages:pra',
'Provenal; Occitan (post 1500) :oci',
'Provenal, Old (to 1500):pro',
'Punjabi; Panjabi:pan',
'Pushto:pus',
'Quechua:que',
'Raeto-Romance:roh',
'Rajasthani:raj',
'Rapanui:rap',
'Rarotongan:rar',
'Reserved for local use:qaa-qtz',
'Romance (Other):roa',
'Romanian:rum',
'Romany:rom',
'Rundi:run',
'Russian:rus',
'Salishan languages:sal',
'Samaritan Aramaic:sam',
'Sami languages (Other):smi',
'Samoan:smo',
'Sandawe:sad',
'Sango:sag',
'Sanskrit:san',
'Santali:sat',
'Sardinian:srd',
'Sasak:sas',
'Saxon, Low; German, Low; Low Saxon; Low German :nds',
'Scots:sco',
'Scottish Gaelic; Gaelic:gla',
'Selkup:sel',
'Semitic (Other):sem',
'Serbian:scc',
'Serer:srr',
'Shan:shn',
'Shona:sna',
'Sichuan Yi:iii',
'Sidamo:sid',
'Sign languages:sgn',
'Siksika:bla',
'Sindhi:snd',
'Sinhalese:sin',
'Sino-Tibetan (Other):sit',
'Siouan languages:sio',
'Skolt Sami:sms',
'Slave (Athapascan):den',
'Slavic (Other):sla',
'Slovak:slo',
'Slovenian:slv',
'Sogdian:sog',
'Somali:som',
'Songhai:son',
'Soninke:snk',
'Sorbian languages:wen',
'Sotho, Northern:nso',
'Sotho, Southern:sot',
'South American Indian (Other):sai',
'Southern Sami:sma',
'South Ndebele:nbl',
'Spanish; Castilian:spa',
'Sukuma:suk',
'Sumerian:sux',
'Sundanese:sun',
'Susu:sus',
'Swahili:swa',
'Swati:ssw',
'Swedish:swe',
'Syriac:syr',
'Tagalog:tgl',
'Tahitian:tah',
'Tai (Other):tai',
'Tajik:tgk',
'Tamashek:tmh',
'Tamil:tam',
'Tatar:tat',
'Telugu:tel',
'Tereno:ter',
'Tetum:tet',
'Thai:tha',
'Tibetan:tib',
'Tigre:tig',
'Tigrinya:tir',
'Timne:tem',
'Tiv:tiv',
'tlhlngan-Hol; Klingon:tlh',
'Tlingit:tli',
'Tok Pisin:tpi',
'Tokelau:tkl',
'Tonga (Nyasa):tog',
'Tonga (Tonga Islands):ton',
'Tsimshian:tsi',
'Tsonga:tso',
'Tswana:tsn',
'Tumbuka:tum',
'Tupi languages:tup',
'Turkish:tur',
'Turkish, Ottoman (1500-1928):ota',
'Turkmen:tuk',
'Tuvalu:tvl',
'Tuvinian:tyv',
'Twi:twi',
'Udmurt:udm',
'Ugaritic:uga',
'Uighur:uig',
'Ukrainian:ukr',
'Umbundu:umb',
'Undetermined:und',
'Upper Sorbian:hsb',
'Urdu:urd',
'Uzbek:uzb',
'Vai:vai',
'Valencian; Catalan:cat',
'Venda:ven',
'Vietnamese:vie',
'Volapk:vol',
'Votic:vot',
'Wakashan languages:wak',
'Walamo:wal',
'Walloon:wln',
'Waray:war',
'Washo:was',
'Welsh:wel',
'Wolof:wol',
'Xhosa:xho',
'Yakut:sah',
'Yao:yao',
'Yapese:yap',
'Yiddish:yid',
'Yoruba:yor',
'Yupik languages:ypk',
'Zande:znd',
'Zapotec:zap',
'Zenaga:zen',
'Zhuang; Chuang:zha',
'Zulu:zul',
'Zuni:zun'
];

function init() {
	var what = document.getElementById("applyForm");
	if (!what.elements["voipandasi"]) {
		selVoipAndAsi = document.createElement('select');
		selVoipAndAsi.name = 'voipandasi';
		selVoipAndAsi.id = 'voipandasi';
	} else {
		selVoipAndAsi = what.elements["voipandasi"];
	}
	if (!what.elements["scramble"]) {
		selScramble = document.createElement('select');
		selScramble.name = 'scramble';
		selScramble.id = 'scramble';
	} else {
		selScramble = what.elements["scramble"];
	}
	var anOpt, aOPTION, aOPTION1, aOPTION2;
	for (var i=0; i < OPTS_VOIPANDASI.length; i++) {
		aOPTION1 = document.createElement('option');
		aOPTION2 = document.createElement('option');
		try {
			anOpt = [];
			anOpt = OPTS_VOIPANDASI[i].split(':');
			if (anOpt.length >= 2) {
				aOPTION1.value = anOpt[1];
				aOPTION2.value = anOpt[1];
				aOPTION1.text = anOpt[0];
				aOPTION2.text = anOpt[0];
			}
		} catch(e) {
			alert(e.message + OPTS_VOIPTYPE[i]);
			aOPTION1.value = OPTS_VOIPANDASI[i];
			aOPTION2.value = OPTS_VOIPANDASI[i];
			aOPTION1.text = OPTS_VOIPANDASI[i];
			aOPTION2.text = OPTS_VOIPANDASI[i];
		}
		try {
			selVoipAndAsi.add(aOPTION1);
			selScramble.add(aOPTION2);
		} catch (er) {
			selVoipAndAsi.add(aOPTION1, null);
			selScramble.add(aOPTION2, null);
		}
	}
	if (!what.elements["voiptype"]) {
		selVoipType = document.createElement('select');
		selVoipType.name = 'voiptype';
		selVoipType.id = 'voiptype';
	} else {
		selVoipType = what.elements["voiptype"];
	}
	for (i=0; i < OPTS_VOIPTYPE.length; i++) {
		aOPTION = document.createElement('option');
		try {
			anOpt = [];
			anOpt = OPTS_VOIPTYPE[i].split(':');
			if (anOpt.length >= 2) {
				aOPTION.value = anOpt[1];
				aOPTION.text = anOpt[0];
			}
		} catch(err) {
			alert(OPTS_VOIPTYPE[i]);
			aOPTION.value = OPTS_VOIPTYPE[i];
			aOPTION.text = OPTS_VOIPTYPE[i];
		}
		try {
			selVoipType.add(aOPTION);
		} catch (erro) {
			selVoipType.add(aOPTION, null);
		}
	}
	if (!what.elements["lang1"]) {
		selLang1 = document.createElement('select');
		selLang1.name = 'lang1';
		selLang1.id = 'lang1';
	} else {
		selLang1 = what.elements["lang1"];
	}
	if (!what.elements["lang2"]) {
		selLang2 = document.createElement('select');
		selLang2.name = 'lang2';
		selLang2.id = 'lang2';
	} else {
		selLang2 = what.elements["lang2"];
	}
	for (i=0; i < OPTS_LANG_CODE.length; i++) {
		aOPTION1 = document.createElement('option');
		aOPTION2 = document.createElement('option');
		try {
			anOpt = [];
			anOpt = OPTS_LANG_CODE[i].split(':');
			if (anOpt.length >= 2) {
				aOPTION1.value = anOpt[1];
				aOPTION2.value = anOpt[1];
				aOPTION1.text = anOpt[0];
				aOPTION2.text = anOpt[0];
			}
		} catch(error) {
			alert(OPTS_LANG_CODE[i]);
			aOPTION1.value = OPTS_LANG_CODE[i];
			aOPTION2.value = OPTS_LANG_CODE[i];
			aOPTION1.text = OPTS_LANG_CODE[i];
			aOPTION2.text = OPTS_LANG_CODE[i];
		}
		try {
			selLang1.add(aOPTION1);
			selLang2.add(aOPTION2);
		} catch(error1) {
			selLang1.add(aOPTION1, null);
			selLang2.add(aOPTION2, null);
		}
	}
	if (!what.elements["service_type_out"]) {
		selServiceType = document.createElement('select');
		selServiceType.name = 'service_type_out';
		selServiceType.id = 'service_type_out';
	} else {
		selServiceType = what.elements["service_type_out"];
	}
	for (i=0; i < OPTS_SERVICE_TYPE.length; i++) {
		aOPTION = document.createElement('option');
		try {
			anOpt = [];
			anOpt = OPTS_SERVICE_TYPE[i].split(':');
			if (anOpt.length >= 2) {
				aOPTION.value = anOpt[1];
				aOPTION.text = anOpt[0];
			}
		} catch(error2) {
			alert(OPTS_SERVICE_TYPE[i]);
			aOPTION.value = OPTS_SERVICE_TYPE[i];
			aOPTION.text = OPTS_SERVICE_TYPE[i];
		}
		try {
			selServiceType.add(aOPTION);
		} catch (error3) {
			selServiceType.add(aOPTION, null);
		}
	}
} 

function addInputRow(table, label, id, value) {
	var aINPUT = document.createElement('input');
	aINPUT.type = 'text';
	aINPUT.name = id;
	aINPUT.id = id;
	var aTR = table.insertRow(table.rows.length);
	//aTR = table.insertRow(0);
	aTR.className = 'activerow';
	var aTD1 = aTR.insertCell(0);
	aTD1.className = 'cell';
	aTD1.appendChild(document.createTextNode(label));
	var aTD2 = aTR.insertCell(1);
	aTD2.className = 'cell';
	aTD2.appendChild(aINPUT);
	aINPUT.value = value;
}

function addSelectRow(table, label, sel, value) {
	var aTR = table.insertRow(table.rows.length);
	aTR.className = 'activerow';
	var aTD1 = aTR.insertCell(0);
	aTD1.className = 'cell';
	aTD1.appendChild(document.createTextNode(label));
	var aTD2 = aTR.insertCell(1);
	aTD2.className = 'cell';
	var cp;
	try {
		cp = sel.cloneNode(true);
	} catch(e) {
		cp = sel;
	}
	aTD2.appendChild(cp);
	cp.value = value;
}

function pidFlagClick() {
	var el = window.event.srcElement;
	var inputs = document.getElementsByName(el.name);
	document.getElementById(el.name.slice(0, el.name.length - 5)).disabled = (el.value != 'User');
	if (inputs.length >= 3) {
		inputs[0].checked = (inputs[0].value == el.value);
		inputs[1].checked = (inputs[1].value == el.value);
		inputs[2].checked = (inputs[2].value == el.value);
	}
}

function addPidFlags(id, flags) {
	var inputs = document.getElementsByName(id + "_flag");
	var el = document.getElementById(id);
	if (inputs.length >= 3) {
		inputs[0].checked = (flags.indexOf('A') != -1);
		inputs[0].disabled = false;
		inputs[1].checked = (flags.indexOf('D') != -1);
		inputs[1].disabled = false;
		inputs[2].checked = (flags.indexOf('U') != -1);
		inputs[2].disabled = false;
	} else {
		var aINPUT = document.createElement('input');
		aINPUT.type = 'radio';
		aINPUT.name = id + "_flag";
		aINPUT.id = id + "_flag";
		aINPUT.value = "Auto";
		aINPUT.className = "pidflags";
		aINPUT.onclick = pidFlagClick;
		el.parentNode.appendChild(aINPUT);
		aINPUT.checked = (flags.indexOf('A') != -1);
		el.parentNode.appendChild(document.createTextNode('Auto'));
		//aINPUT.appendChild(document.createTextNode('Auto'));

		aINPUT = document.createElement('input');
		aINPUT.type = 'radio';
		aINPUT.name = id + "_flag";
		aINPUT.id = id + "_flag";
		aINPUT.value = "Drop";
		aINPUT.className = "pidflags";
		aINPUT.onclick = pidFlagClick;
		el.parentNode.appendChild(aINPUT);
		aINPUT.checked = (flags.indexOf('D') != -1);
		el.parentNode.appendChild(document.createTextNode('Drop'));
		//aINPUT.appendChild(document.createTextNode('Drop'));

		aINPUT = document.createElement('input');
		aINPUT.type = 'radio';
		aINPUT.name = id + "_flag";
		aINPUT.id = id + "_flag";
		aINPUT.value = "User";
		aINPUT.className = "pidflags";
		aINPUT.onclick = pidFlagClick;
		el.parentNode.appendChild(aINPUT);
		aINPUT.checked = (flags.indexOf('U') != -1);
		el.parentNode.appendChild(document.createTextNode('User'));
		//aINPUT.appendChild(document.createTextNode('User'));
	}
	el.disabled = (flags.indexOf('U') == -1);
}

function updateFormLink(ds, voip) {/* ds is a dataset */
	var 
	LEN_NAME = -1,
	LEN_NAMEIN = -1,
	LEN_DESC = -1,
	LEN_STYPE = -1,
	LEN_SID = 1,
	LEN_PMT = -1,
	LEN_PCR = -1,
	LEN_TELE = -1,
	LEN_DSMCC = -1,
	LEN_VID = -1,
	LEN_AUD = 2,
	LEN_SCRAM = -1,
	LEN_ACCESS = -1,
	LEN_PORT = -1,
	LEN_PROG = -1,
	LEN_VOIPTYPE = -1,
	LEN_VOIPANDASI = -1,
	LEN_VOIPDEST = -1,
	LEN_VOIPPORT = 1;

	var active_program = ds;
	var what = document.getElementById("applyForm");
	var table = document.getElementById('mapfields');
	for (var i=0; i < table.rows.length-1; i++) {
		table.rows[i].className = "nosyncrow";
	}
	for (i=0; i < what.elements.length; i++) {
		if ((what.elements(i).tagName == "INPUT" || what.elements(i).tagName == "input") && what.elements(i).type == "text") {
			what.elements(i).value = "";
			what.elements(i).disabled = true;
		} else if ((what.elements(i).tagName == "INPUT" || what.elements(i).tagName == "input") && what.elements(i).type == "radio") {
			what.elements(i).checked = false;
			what.elements(i).disabled = true;
		} else if ((what.elements(i).tagName == "SELECT" || what.elements(i).tagName == "select")) {
			what.elements(i).disabled = true;
		}
	}
	var data;
	for (var prop in ds) {
		if (prop == "name") {
			if (what.elements["name_out"]) {
				what.elements["name_out"].value = ds.name;
				what.elements["name_out"].disabled = false;
				what.elements["name_out"].parentNode.parentNode.className = "activerow";
			} else {
				addInputRow(table, 'Name', 'name_out', ds.name);
			}
		} else if (prop == "desc") {
			if (what.elements["description_out"]) {
				what.elements["description_out"].value = ds.desc;
				what.elements["description_out"].disabled = false;
				what.elements["description_out"].parentNode.parentNode.className = "activerow";
			} else {
				addInputRow(table, 'Description', 'description_out', ds.desc);
			}
		} else if (prop == "stype") {
			if (what.elements["service_type_out"]) {
				what.elements["service_type_out"].value = ds.stype;
				what.elements["service_type_out"].disabled = false;
				what.elements["service_type_out"].parentNode.parentNode.className = "activerow";
			} else {
				addSelectRow(table, 'Service Type', selServiceType, ds.stype);
			}
		} else if (prop == "sid") {
			if (what.elements["program_number_out"]) {
				what.elements["program_number_out"].value = ds.sid;
				what.elements["program_number_out"].disabled = false;
				what.elements["program_number_out"].parentNode.parentNode.className = "activerow";
			} else {
				addInputRow(table, 'Service ID', 'program_number_out', ds.sid);
			}
		} else if (prop == "pmt") {
			data = ds.pmt.split(':');
			if (data.length >= LEN_PMT && (data[0].length > 0 || data[1].length > 0)) {
				if (what.elements["pmt_pid"]) {
					what.elements["pmt_pid"].value = data[0];
					if (data[0].length > 0) {
						what.elements["pmt_pid"].disabled = false;
						what.elements["pmt_pid"].parentNode.parentNode.className = "activerow";
					}
				} else {
					addInputRow(table, 'PMT PID', 'pmt_pid', data[0]);
				}
				addPidFlags("pmt_pid", data[1]);
			}
		} else if (prop == "pcr") {
			data = ds.pcr.split(':');
			if (data.length >= LEN_PCR && (data[0].length > 0 || data[1].length > 0)) {
				if (what.elements["pcr_pid"]) {
					what.elements["pcr_pid"].value = data[0];
					if (data[0].length > 0) {
						what.elements["pcr_pid"].disabled = false;
						what.elements["pcr_pid"].parentNode.parentNode.className = "activerow";
					}
				} else {
					addInputRow(table, 'PCR PID', 'pcr_pid', data[0]);
				}
				addPidFlags("pcr_pid", data[1]);
			}
		} else if (prop == "tele") {
			data = ds.tele.split(':');
			if (data.length >= LEN_TELE && (data[0].length > 0 || data[1].length > 0)) {
				if (what.elements["teletext_pid"]) {
					what.elements["teletext_pid"].value = data[0];
					if (data[0].length > 0) {
						what.elements["teletext_pid"].disabled = false;
						what.elements["teletext_pid"].parentNode.parentNode.className = "activerow";
					}
				} else {
					addInputRow(table, 'Teletext PID', 'teletext_pid', data[0]);
				}
				addPidFlags("teletext_pid", data[1]);
			}
		} else if (prop == "vid") {
			data = ds.vid.split(':');
			if (data.length >= LEN_VID && (data[0].length > 0 || data[1].length > 0)) {
				if (what.elements["video_pid"]) {
					what.elements["video_pid"].value = data[0];
					if (data[0].length > 0) {
						what.elements["video_pid"].disabled = false;
						what.elements["video_pid"].parentNode.parentNode.className = "activerow";
					}
				} else {
					addInputRow(table, 'Video PID', 'video_pid', data[0]);
				}
				addPidFlags("video_pid", data[1]);
			}
		} else if (prop == "aud1") {
			data = ds.aud1.split(':');
			if (data.length >= LEN_AUD && (data[0].length > 0 || data[1].length > 0)) {
				if (what.elements["prim_aud_pid"]) {
					what.elements["prim_aud_pid"].value = data[0];
					if (data[0].length > 0) {
						what.elements["prim_aud_pid"].disabled = false;
						what.elements["prim_aud_pid"].parentNode.parentNode.className = "activerow";
					}
				} else {
					addInputRow(table, 'Primary Audio PID', 'prim_aud_pid', data[0]);
				}
				addPidFlags("prim_aud_pid", data[1]);
				if (what.elements["lang1"]) {
					if (data.length >= 3 && data[2].length > 0) {
						what.elements["lang1"].value = data[2];
						if (data[2].length > 0) {
							what.elements["lang1"].disabled = false;
							what.elements["lang1"].parentNode.parentNode.className = "activerow";
						}
					} else {
						what.elements["lang1"].value = "";
					}
				} else {
					if (data.length >= 3 && data[2].length > 0) {
						addSelectRow(table, 'Language', selLang1, data[2]);
					} else {
						addSelectRow(table, 'Language', selLang1, '');
						//addInputRow(table, 'Language', 'lang1', '');
					}
				}
			}
		} else if (prop == "aud2") {
			data = ds.aud2.split(':');
			if (data.length >= LEN_AUD && (data[0].length > 0 || data[1].length > 0)) {
				if (what.elements["sec_aud_pid"]) {
					what.elements["sec_aud_pid"].value = data[0];
					if (data[0].length > 0) {
						what.elements["sec_aud_pid"].disabled = false;
						what.elements["sec_aud_pid"].parentNode.parentNode.className = "activerow";
					}
				} else {
					addInputRow(table, 'Secondary Audio PID', 'sec_aud_pid', data[0]);
				}
				addPidFlags("sec_aud_pid", data[1]);
				if (what.elements["lang2"]) {
					if (data.length >= 3 && data[2].length > 0) {
						what.elements["lang2"].value = data[2];
						if (data[2].length > 0) {
							what.elements["lang2"].disabled = false;
							what.elements["lang2"].parentNode.parentNode.className = "activerow";
						}
					} else {
						what.elements["lang2"].value = "";
					}
				} else {
					if (data[2] !== null && data[2].length > 0) {
						addSelectRow(table, 'Language', selLang2, data[2]);
						//addInputRow(table, 'Language', 'lang2', data[3]);
						//what.elements["lang2"].value = data[2];
					} else {
						addSelectRow(table, 'Language', selLang2, '');
						//addInputRow(table, 'Language', 'lang2', '');
					}
				}
			} else {
				if (what.elements["lang2"]) {
					what.elements["lang2"].value = "";
				}
			}
		} else if (prop == "dsmcc") {
			data = ds.dsmcc.split(':');
			if (data.length >= LEN_DSMCC && (data[0].length > 0 || data[1].length > 0)) {
				if (what.elements["dsmcc_pid"]) {
					what.elements["dsmcc_pid"].value = data[0];
					if (data[0].length > 0) {
						what.elements["dsmcc_pid"].disabled = false;
						what.elements["dsmcc_pid"].parentNode.parentNode.className = "activerow";
					}
				} else {
					addInputRow(table, 'DSMCC PID', 'dsmcc_pid', data[0]);
				}
				addPidFlags("dsmcc_pid", data[1]);
			}
		} else if (prop == "scram") {
			if (what.elements["scramble"]) {
				what.elements["scramble"].value = ds.scram;
				what.elements["scramble"].disabled = false;
				what.elements["scramble"].parentNode.parentNode.className = "activerow";
			} else {
				addSelectRow(table, 'Scramble', selScramble, ds.scram);
			}
		} else if (prop == "access") {
			if (what.elements["access_criteria"]) {
				what.elements["access_criteria"].value = ds.access;
				what.elements["access_criteria"].dsiabled = false;
				what.elements["access_criteria"].parentNode.parentNode.className = "activerow";
			} else {
				addInputRow(table, 'Access Criteria', 'access_criteria', ds.access);
				//what.elements["voiptype"].value = data[1];
			}
		} else if (prop == "port") {
			what.elements["port"].value = ds.port;
		} else if (prop == "prog") {
			what.elements["program_number_in"].value = ds.prog;
		} else if (prop == "namein") {
			what.elements["name_in"].value = ds.namein;
		} else if (prop == "voiptype") {
			if (what.elements["voiptype"]) {
				what.elements["voiptype"].value = ds.voiptype;
				what.elements["voiptype"].disabled = false;
				what.elements["voiptype"].parentNode.parentNode.className = "activerow";
			} else {
				addSelectRow(table, 'VOIP Type', selVoipType, ds.voiptype);
			}
			what.elements["voiptype"].onchange = voiptypeChange;
			if (voip) {
				what.elements["voiptype"].value = voip;
			}
			voip = voip || (what.elements["voiptype"].value != 'disabled');
		} else if (prop == "voipandasi") {
			if (what.elements["voipandasi"]) {
				what.elements["voipandasi"].value = ds.voipandasi;
				what.elements["voipandasi"].disabled = false;
				what.elements["voipandasi"].parentNode.parentNode.className = "activerow";
			} else {
				addSelectRow(table, 'VOIP and ASI', selVoipAndAsi, ds.voipandasi);
			}
		} else if (prop == "voipdest") {
			if (what.elements["voipdest"]) {
				what.elements["voipdest"].value = ds.voipdest;
				what.elements["voipdest"].disabled = false;
				what.elements["voipdest"].parentNode.parentNode.className = "activerow";
			} else {
				addInputRow(table, 'VOIP IPA', 'voipdest', ds.voipdest);
			}
		} else if (prop == "voipport") {
			if (what.elements["voipport"]) {
				what.elements["voipport"].value = ds.voipport;
				what.elements["voipport"].disabled = false;
				what.elements["voipport"].parentNode.parentNode.className = "activerow";
			} else {
				addInputRow(table, 'VOIP Port', 'voipport', ds.voipport);
			}
		}
	}
}

function voiptypeChange() {
	var el = window.event.srcElement;
	if (el.value != 'disabled') {
		updateFormLink(active_program, el.value);
	}
}

function delInputRow(table, id) {
	var aINPUT = document.getElementById(id);
	if (aINPUT) {
		var aTR = aINPUT.parentNode.parentNode;
		table.deleteRow(aTR.rowIndex);
	}
}

function parseFields(aStr) {
	var a = aStr.split(",");
	for(var i = 0; i < a.length; i++) {
		var b = a[i].split(":");
		var values = '';
		for (var j = 0; j < b.length; j++) {
			if (j === 0) {
				var aName = b[j];
			} else {
				values += "Value(" + (j-1).toString() +") = "+ b[j] + '\n';
			}
		}
	}
}

function debug(obj) {
	var s = '';
	for (var prop in obj) {
		if (true) {
			s += prop + ':' + obj[prop] + '\n';
		}
	}
	alert(s);
}