function setRes(obj,x,y) {
	var items = obj.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("input");
	items[0].value = x + "";
	items[1].value = y + "";
}

function Switch(divId)
{
  var styleSheet = GetObjectStyle(divId);
  if (styleSheet)
  {
    HideAll();
    SetVisible(divId, "block");
  }
  else
  {
    alert("Sorry, this site requires browsers that support DHTML");
  }
}

function GetObject(n, d)
{
	return document.getElementById(n);

  var p,i,x;

  if(!d) d=document;

  if((p=n.indexOf("?"))>0&&parent.frames.length)
  {
	  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }

  if(!(x=d[n])&&d.all) x=d.all[n];

  for (i=0;!x&&i<d.forms.length;i++)
  	x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
  	x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById)
  	x=d.getElementById(n);

  return x;
}

function SetVisible(objId, newValue)
{
  var styleObj = GetObject(objId);
  if (styleObj)
  {
    styleObj.style.display = newValue;
    return true;
  }
  return false;
}

function HideAll()
{
  SetVisible("unknown", "none");
  SetVisible("cwmedia", "none");
  SetVisible("cflash", "none");
  SetVisible("cflashFLV", "none");
  SetVisible("cqtime", "none");
  SetVisible("creal", "none");
}

function GenerateHtml(mediatype, support, link, link_type, image_link, image_path, text_link, url, width, height, autoplay, controller, quality, popup, popup_width, popup_height)
{
  if(autoplay!=null)
  	autoplay = autoplay.getElementsByTagName('input')[0].checked;
  if(controller!=null)
  	controller = controller.getElementsByTagName('input')[0].checked;

  //Initialize height & width
  if(!height) height = 0;
  if(!width) width = 0;

  //Initialize text
  var text = '';

  //Make external link?
  if (link)
  {
	  // FLV?
	  if (mediatype==5) {
	  	//Type of external link (text/image)
	  	// TRUE = image / FALSE = text
	  	// window.open('http://www.pageresource.com/jscript/jex5.htm','mywindow','width=400,height=200')
	  	/*
	  	if (link_type)
			  text = text + '&lt;img src="' + text_link + '" alt="" style="cursor:pointer;" onclick="window.open(\'http://freevideocoding.com/flvplayer.swf?file=' + url + '\',\'mywindow\',\'width=320,height=240\')" /&gt;';
	  	else
	  		  text = text + '&lt;span style="color:blue;text-decoration:underline;cursor:pointer;" onclick="window.open(\'http://freevideocoding.com/flvplayer.swf?file=' + url + '\',\'mywindow\',\'width=320,height=240\')"&gt;' + text_link + '&lt;/span&gt;';
	    */
	  	if (link_type)
			  text = text + '&lt;a href="'+url+'" onclick="window.open(\'http://freevideocoding.com/flvplayer.swf?file=' + url + '\',\'mywindow\',\'width=320,height=240\');return false;" &gt;&lt;img src="' + text_link + '" alt=""&gt;&lt;/a&gt;';
	  	else
	  		  text = text + '&lt;a href="'+url+'" onclick="window.open(\'http://freevideocoding.com/flvplayer.swf?file=' + url + '\',\'mywindow\',\'width=320,height=240\');return false;" &gt;' + text_link + '&lt;/a&gt;';
	  }
	  // SWF?
	  else if (mediatype==2) {
	  	//Type of external link (text/image)
	  	// TRUE = image / FALSE = text
	  	/*
	  	if (link_type)
			  text = text + '&lt;img src="' + text_link + '" alt="" style="cursor:pointer;" onclick="window.open(\'' + url + '\',\'mywindow\',\'width=320,height=240\')" /&gt;';
	  	else
	  		  text = text + '&lt;span style="color:blue;text-decoration:underline;cursor:pointer;" onclick="window.open(\'' + url + '\',\'mywindow\',\'width=320,height=240\')"&gt;' + text_link + '&lt;/span&gt;';
	    */
	  	if (link_type)
			  text = text + '&lt;a href="'+url+'" onclick="window.open(\'' + url + '\',\'mywindow\',\'width=320,height=240\');return false;" &gt;&lt;img src="' + text_link + '" alt=""&gt;&lt;/a&gt;';
	  	else
	  		  text = text + '&lt;a href="'+url+'" onclick="window.open(\'' + url + '\',\'mywindow\',\'width=320,height=240\');return false;" &gt;' + text_link + '&lt;/a&gt;';
  	  }
	  else {
	  	//Type of external link (text/image)
	  	// TRUE = image / FALSE = text
	  	// window.open('http://www.pageresource.com/jscript/jex5.htm','mywindow','width=400,height=200')
	  	if(mediatype==3)
	  		var blank = ' target=_blank';
	  	else
	  		var blank = '';

	  	if (link_type)
			  text = text + '&lt;a href="' + url + '"'+blank+'&gt;&lt;img src="' + text_link + '" alt="" /&gt;&lt;/a&gt;';
	  	else
	  		  text = text + '&lt;a href="' + url + '"'+blank+'&gt;' + text_link + '&lt;/a&gt;';
  	  }
  }
  else if (popup)
  {
	  var c = 0;
	if(controller)
	{
		switch(mediatype)
		{
			case 1:
				c = 43;
				break;
			case 3:
				c = 16;
				break;
			case 4:
				c = 27;
				break;
			default:
				c = 0;
		}
	}

		var jcode = 'var win=window.open(\'\',\'mywindow\',\'height=' + (c+parseInt(popup_height)) + ', width=' + popup_width + '\');win.document.write(\'&lt;html&gt;&lt;head&gt;&lt;title&gt;Video Window&lt;/title&gt;&lt;style&gt;html,body {margin:0;padding:0;}&lt;/style&gt;&lt;/head&gt;&lt;body&gt;'+AddObjectElement(mediatype, url, popup_width, popup_height, autoplay, controller, quality).replace(/"/g,"\\'")+'&lt;/body&gt;&lt;/html&gt;\');return false;';
		jcode = jcode.replace(/&lt;/g,"\\x3C");
		jcode = jcode.replace(/&gt;/g,"\\x3E");
	  if (link_type)
	  {
		  text = '&lt;a href="' + url + '" onclick="'+jcode+'"&gt;&lt;img src="' + text_link + '" alt=""&gt;&lt;/a&gt;';
	  }
	  else
	  {
		  text = '&lt;a href="' + url + '" onclick="'+jcode+'"&gt;' + text_link + '&lt;/a&gt;';
	  }
/*
	  if(mediatype==5)
	  {
	  	if (link_type)
	  		text = text + '&lt;img src="' + text_link + '" alt="" style="cursor:pointer;" onclick="window.open(\'http://freevideocoding.com/flvplayer.swf?file=' + url + '\',\'mywindow\',\'width=' + popup_width + ',height=' + popup_height + '\')" /&gt;';
	  	else
	  		text = '&lt;a href="http://freevideocoding.com/flvplayer.swf?file=' + url + '" onclick="window.open(\'http://freevideocoding.com/flvplayer.swf?file=' + url + '\',\'mywindow\',\'height=' + popup_height + ', width=' + popup_width + '\');return false;"&gt;' + text_link + '&lt;/a&gt;';
	  }
	  else
	  {
	  	if (link_type)
	  		text = text + '&lt;img src="' + text_link + '" alt="" style="cursor:pointer;" onclick="window.open(\'' + url + '\',\'mywindow\',\'width=' + popup_width + ',height=' + popup_height + '\')" /&gt;';
	  	else
	  		text = '&lt;a href="' + url + '" onclick="window.open(\'' + url + '\',\'mywindow\',\'height=' + popup_height + ', width=' + popup_width + '\');return false;"&gt;' + text_link + '&lt;/a&gt;';
  	  }
*/
  }
  else if (mediatype == 0)
  {
	text = text + AddEmbedElement(url, width, height, autoplay);
	if ( image_link )
		text = swapPicVid(text, image_path, height, width);
  }
  else if (mediatype == 6)
  {
	text = text + AddObjectElement(mediatype, url, width, height, autoplay, controller, quality);
  }
  else
  {
    text = text + AddObjectElement(mediatype, url, width, height, autoplay, controller, quality);
    if ( image_link ) {
		if ( !(mediatype==3 && document.getElementById('qt_posterYes').checked) )
		{
			var xheight = parseInt(height);
			if(controller)
			{
				switch(mediatype)
				{
					case 1:
						xheight += 43;
						break;
					case 3:
						xheight += 16;
						break;
					default:
				}
			}
			text = swapPicVid(text, image_path, xheight, width);
		}
	}
  }

  //Add support link
  if(support) {
	  if(image_link)
	  	text = text + '&lt;a href="http://www.freevideocoding.com"&gt;FreeVideoCoding.com&lt;/a&gt;';
	  else
	  	text = text + '&lt;br&gt;&lt;a href="http://www.freevideocoding.com"&gt;FreeVideoCoding.com&lt;/a&gt;';
	}

  ///////
  //Code added by Jeff Johnson: contact@togaenwebdesign.com
  //Write output to page
  ////
  //Get output text element
  x = document.getElementById('output_text');

  //Clear output text element
  x.innerHTML = '';

  //Write to output text
  x.innerHTML = '<p class="title"><span class="title_text">Highlight, copy (cntrl+c), then paste (cntrl+v) code.</span></p><p>&lt;!-- START FreeVideoCoding.com --&gt;<br />' + text + '<br />&lt;!-- END FreeVideoCoding.com --&gt;</p>';

  //Make DIV visible
  //HideAll();
  document.getElementById('output_text').style.display = 'block';
  ////

  return true;
}

function AddEmbedElement(url, width, height, autoplay)
{
  return '&lt;embed src="' + url + '" width="' + width + '" height="' + height + '" autoplay="' + autoplay + '" scale="tofit"&gt;&lt;/embed&gt;';
}

function AddObjectElement(mediatype, url, width, height, autoplay, controller, quality)
{
  var clsid = "";
  var codebase = "";
  var tmp = "";

  switch (mediatype)
  {
    case 1: // Windows Media Player
      clsid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95";
      codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112";
      break;
    case 5:
    case 2: // Macromedia Flash
      clsid="CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000";
      codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0";
      break;
    case 3: // Apple QuickTime
      clsid="CLSID:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
      codebase="http://www.apple.com/qtactivex/qtplugin.cab";
      break;
    case 4: // Real Player
      clsid="CLSID:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA";
      codebase="";
      break;
    case 6: // Embed audio
      break;
  }

  var autoplayFlag = autoplay;
  var controllerFlag = controller;

  var qualityStr = "";
  if (quality!=null)
  	quality = quality.getElementsByTagName('input');
  if (quality != null)
  {
    if (quality[0].checked)
      qualityStr = "high";
    else if (quality[1].checked)
      qualityStr = "medium";
    else
      qualityStr = "low";
  }

  if (mediatype == 1)
  {
	//If controls present, add 43px to height to account for them
	// http://support.microsoft.com/default.aspx?scid=kb;en-us;285154
	if(controllerFlag) height = parseInt(height) + 43;

	//Mini mode?
	var miniMode = "";

	if ( document.getElementById('wm_minimode').getElementsByTagName('input')[0].checked ) {
		miniMode = 'uiMode="mini"';
	}

	(autoplayFlag) ? autoplayFlag = '1': autoplayFlag = '0';
	(controllerFlag) ? controllerFlag = '1' : controllerFlag = '0';
    tmp = tmp + '&lt;embed src="' + url + '" width="' + width + '" height="' + height +
    '" autostart="' + autoplayFlag + '" ' + miniMode + ' showcontrols="' + controllerFlag + '" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/windowsmedia/download/"&gt; &lt;/embed&gt;';
  }
  else if (mediatype == 2)
  {

	// http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_12701
    tmp = tmp + '&lt;embed src="' + url + '" width="' + width + '" height="' + height +
    '" quality="' + qualityStr + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"&gt;&lt;/embed&gt;';
  }
  else if (mediatype == 5)
  {

	// http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_12701
	(autoplayFlag) ? autoplayFlag = '&amp;autoStart=true' : autoplayFlag = '&amp;autoStart=false';
    tmp = tmp + '&lt;embed src="http://freevideocoding.com/flvplayer.swf?file=' + url + autoplayFlag + '" width="' + width + '" height="' + height +
    '" quality="' + qualityStr + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"&gt;&lt;/embed&gt;';
  }
  else if (mediatype == 3)
  {

      //If controls present, add '16' to height to account for them
      // http://www.apple.com/quicktime/tutorials/embed.html
      if(controllerFlag) height = parseInt(height) + 16;

      // Poster frame?
      if ( document.getElementById('qt_posterYes').checked ) {
      	tmp = tmp + '&lt;embed src="' + document.getElementById('posterPath').value + '" href="' + url + '" width="' + width + '" height="' + height +
      	'" autoplay="' + autoplayFlag + '" target="myself" controller="' + controllerFlag + '" type="video/quicktime" scale="tofit" cache="true" pluginspage="http://www.apple.com/quicktime/download/"&gt; &lt;/embed&gt;';
	  }
	  else {
      	tmp = tmp + '&lt;embed src="' + url + '" width="' + width + '" height="' + height +
      	'" autoplay="' + autoplayFlag + '" controller="' + controllerFlag + '" type="video/quicktime" scale="tofit" pluginspage="http://www.apple.com/quicktime/download/"&gt; &lt;/embed&gt;';
  	  }

  }
  else if (mediatype == 4)
  {

	  // Get unique control name
	  var d = new Date();
	  var controlName = "c" + Date.UTC(d.getFullYear(),d.getMonth(),d.getDay(),d.getHours(),d.getMinutes(),d.getSeconds(),d.getMilliseconds());

      //Fix weird Real display
      //var controller = "";
      // http://service.real.com/help/library/guides/realone/ProductionGuide/HTML/realpgd.htm?page=htmfiles/embed.htm%23basics
      tmp = tmp + '&lt;embed type="audio/x-pn-realaudio-plugin" src="' + url + '" width="' + width + '" height="' + height +
      '" autostart="' + autoplayFlag + '" controls="imagewindow" nojava="true" console="' + controlName + '" pluginspage="http://www.real.com/"&gt;&lt;/embed&gt;';
	  if(controllerFlag)
	  	tmp = tmp + '&lt;br&gt;&lt;embed type="audio/x-pn-realaudio-plugin" src="' + url + '" width="' + width + '" height="26" autostart="' + autoplayFlag + '" nojava="true" controls="ControlPanel" console="' + controlName + '"&gt; &lt;/embed&gt;';
  }
  else if (mediatype == 6)
  {
	  	// Embed Audio
	  	tmp = '&lt;embed src="' + url + '" width="0" height="0" autostart="true"&gt;&lt;/embed&gt;';
  }
  return tmp;
}

/** Function to add swap routine
 *******************************/
function swapPicVid(tmp, text_link, height, width) {
  var code;

	tmp = tmp.replace(/&lt;/g,"\\x3C");
	tmp = tmp.replace(/&gt;/g,"\\x3E");

  code = "&lt;div&gt;";
  code += "&lt;img src=\"" + text_link + "\" height=\"" + height + "\" width=\"" + width + "\" alt=\"\" style=\"cursor:pointer;\" onclick=\"" + "this.parentNode.innerHTML = '" + tmp.replace(/"/g,"\\'") + "';" + "\"&gt;";
  code += "&lt;/div&gt;";

  return code;
}
