function GetRadio(radioObj) {
	if(!radioObj) return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function GenerateEmbedCode(page) {
	if (!page) page = "http://"+document.location.host+"/widget.php?";
	var movie = document.form1.movie.options[document.form1.movie.selectedIndex].value;
	if (!movie) $movie = 1;
	var widget = page + "movie=" + movie;
	var audio = document.form1.audio.options[document.form1.audio.selectedIndex].value;
	if (audio != 0) widget += "&audio=" + audio;
	var subtitle = document.form1.subtitle.options[document.form1.subtitle.selectedIndex].value;
	if (subtitle != "") widget += "&language=" + subtitle;
	var size = GetRadio(document.form1.size);
	if (size != 0) widget += "&size=" + size;
	var bg = GetRadio(document.form1.bg);
	if (bg != 0) widget += "&bg=" + bg;
	var mute = GetRadio(document.form1.mute);
	if (mute != 0) widget += "&mute=1";
	var auto = GetRadio(document.form1.click);
	if (auto != 0) widget += "&click=" + auto;
	//if (subtitle != "" && subtitle != 25) document.form1.title.selectedIndex = 3;
	
	var title = document.form1.title.options[document.form1.title.selectedIndex].value;
	if (title != 0) widget += "&title=" + title;
	var width = 326;
	var height = 333;
	if (size == 3) {
		width = 646;
		height = 574;
	}
	if (size == 2) {
		width = 456;
		height = 430;
	}
	if (size == 1) {
		width = 206;
		height = 235;
	}

	var code = '<iframe src="'+widget+'" width="'+width+'" height="'+height+'" frameborder="0" scrolling="no"><a href="'+widget+'">Play Movie</a></iframe>';
	document.getElementById("copypaste1").value = code;
	document.getElementById("copypaste2").value = code;
	document.getElementById("preview").style.width = width + 'px';
	document.getElementById("preview").innerHTML = code;
	if (size < 2) {
		document.getElementById("copydiv1").style.display = "";
		document.getElementById("copydiv2").style.display = "none";
	} else {
		document.getElementById("copydiv1").style.display = "none";
		document.getElementById("copydiv2").style.display = "";
	}
	document.form1.title.selectedIndex = -1;
	if (document.all && !window.opera) {
		// Physically remove options in IE because we can't hide them
		while (document.form1.title.options.length > 0) document.form1.title.remove(0);
		var ops = document.form1.titlebackup.options;
		for (var i=0; i < ops.length; i++) {
			if (ops[i].className != "titles"+movie) {
				continue;
			}
			if (subtitle != "" && subtitle != 25 && ops[i].value != 3) {
				continue;
			}
			newOp = document.createElement('option');
			newOp.text = ops[i].text;
			newOp.value = ops[i].value;
			newOp.className = ops[i].className;
			document.form1.title.add(newOp);
			if ((subtitle != "" && subtitle != 25) && newOp.value == 3) {
				newOp.selected = true;
			} else if (newOp.value == title) {
				newOp.selected = true;
			}
		}

	} else {
		var ops = document.form1.title.options;
		for (var i=0; i < ops.length; i++) {
			if (ops[i].className != "titles"+movie) {
				ops[i].style.display = "none";
				continue;
			}
			if (subtitle != "" && subtitle != 25 && ops[i].value != 3) {
				ops[i].style.display = "none";
				continue;
			}

			if ((subtitle != "" && subtitle != 25) && ops[i].value == 3) {
				ops[i].selected = true;
			} else if (ops[i].value == title) {
				ops[i].selected = true;
			}

			ops[i].style.display = "";
		}
	}
	return false;
}

function GenerateEmbedCode2(page) {
	if (!page) page = "http://"+document.location.host+"/widget.php?";
	var movie = document.form1.movie.options[document.form1.movie.selectedIndex].value;
	if (!movie) $movie = 1;
	var widget = page + "movie=" + movie;
	var audio = document.form1.audio.options[document.form1.audio.selectedIndex].value;
	if (audio != 0) widget += "&audio=" + audio;
	var subtitle = document.form1.subtitle.options[document.form1.subtitle.selectedIndex].value;
	if (subtitle != "") widget += "&language=" + subtitle;
	var size = document.form1.size.value;
	if (size != 0) widget += "&size=" + size;
	var bg = GetRadio(document.form1.bg);
	if (bg != 0) widget += "&bg=" + bg;
	var mute = GetRadio(document.form1.mute);
	if (mute != 0) widget += "&mute=1";
	var auto = GetRadio(document.form1.click);
	if (auto != 0) widget += "&click=" + auto;
	//if (subtitle != "" && subtitle != 25) document.form1.title.selectedIndex = 3;
	var titleselect = document.getElementById("title"+movie);
	var title = titleselect.options[titleselect.selectedIndex].value;
	if (title != 0) widget += "&title=" + title;

	var width = 320;
	var height = 240 + 19;
	if (size >= 200) {
		width = size;
		height = Math.round(width * 0.75 + 158.5);
	}

	var code = '<iframe src="'+widget+'" width="'+width+'" height="'+height+'" frameborder="0" scrolling="no"><a href="'+widget+'">Play Movie</a></iframe>';
	document.getElementById("copypaste1").value = code;
	document.getElementById("preview").style.width = width + 'px';
	document.getElementById("preview").innerHTML = code;
	return false;
}

function updatetitle() {
	var movie = document.form1.movie.options[document.form1.movie.selectedIndex].value;
	for (var i = 0; i < movielist.length; i++) {
		var select = document.getElementById("title"+movielist[i]);
		if (movielist[i] == movie) {
			select.style.display = "";
		} else {
			select.style.display = "none";
		}
	}
}
