/*
 * @file
 * @author  Original:      German Escallon
 * @author  Contributors:  N/A
 * @date    Created:       2008/12/29
 * @date    Last Edit:     $Date: 2009/10/02 20:15:05 $ by $Author: germane $
 * Description: This file handles the OSD section on the dashboard tab
 *****************************************************************************/
function DisplayOSD(){_ostImageSize.OFF=["ANY","ANY"];UpdateCurrentSubTab("osd");var b='<br/><br/><form id="osdForm"><a onclick="return ValidateOSDForm(document.getElementById(&quot;osdForm&quot;));" >   <img src="/images/apply.gif" /></a>&nbsp;&nbsp;&nbsp;<a onclick="return DisplayOSD();">   <img src="/images/cancel.gif" /></a><br/><br/><table width="100%" ><tr><td><table class="general">  <tr><td align="left" colspan="2"><b>Single OSD: <img id="singleosdHint" onclick="ShowHelp(&quot;hlp_single_osd&quot;, this);" src="/images/hints.gif"/></b> </td><td align="right" colspan="2"><img src="/images/clearosd.gif" onClick="SubmitClearOSD();"> </td></tr><tr><td colspan="4" style="width:auto;"><hr width="100%"></td></tr>  <tr>     <td>Graphic File: <img id="gfOSDHint" onclick="ShowHelp(&quot;hlp_gf_osd&quot;, this);" src="/images/hints.gif"/></td>     <td>        <select id="graphicFileSelect"></select>     </td><td></td>  </tr>  <tr>     <td>Scaling: <img id="scalingOSDHint" onclick="ShowHelp(&quot;hlp_scaling_osd&quot;, this);" src="/images/hints.gif"/></td>     <td><select id="scalingSelect">'+GetSelectOptions("osd_scaling")+'     </select></td>     <td>Position: <img id="positionOSDHint" onclick="ShowHelp(&quot;hlp_position_osd&quot;, this);" src="/images/hints.gif"/></td>     <td>        <select id="positionSelect">'+GetSelectOptions("osd_position")+'        </select>     </td></tr>    <tr> <td colspan="4"><br /><b>Note:</b> You must specify the correct values every time you make a change as the Scaling and Position drop down boxes do not currently reflect actual configuration.</td>  </tr></table><br/><br/><a onclick="return ValidateOSDForm(document.getElementById(&quot;osdForm&quot;));" >   <img src="/images/apply.gif" /></a>&nbsp;&nbsp;&nbsp;<a onclick="return DisplayOSD();">   <img src="/images/cancel.gif" /></a><br/><br/></form>';$("main_div").innerHTML=b;var a="/myles?req="+Math.random()+"&q=DCMD+OSD";var c=function(e){if(ParseOSD(e)){GetGraphicFiles()}else{if(_debug){console.log("ERROR parsing OSD")}}};var d={success:c,failure:function(e){if(_debug){console.log("OSD AJAX Error")}}};_yuiConnect.asyncRequest("GET",a,d,null)}function ValidateOSDForm(a){SetInfoMessage("Submitting display settings",_DEFAULT_INFO_MSG_TIMEOUT,_YELLOW);SubmitOSDForm(a)}function SubmitOSDForm(b){var a=function(k){var h,g,e;h=$("graphicFileSelect").value;g=$("scalingSelect").value;e=$("positionSelect").value;var i="/myles?req="+Math.random();if(h.toUpperCase()!="NONE"){i+="&q=DCMD+OSD+0+L+"+h}var f="&q=DCMD+OSD+D+";switch(e){case"C":f+="C+C+";break;case"TR":f+="R+T+";break;case"TL":f+="L+T+";break;case"BR":f+="R+B+";break;case"BL":f+="L+B+";break;default:f+="*+*+";break}f+=_DEFAULT_VIDEO_SCALING_VAL+"+"+g+"%+F";i+=f;var j=function(m){SetInfoMessage("Your new settings have been set",_DEFAULT_INFO_MSG_TIMEOUT,_GREEN);SaveSettings();setTimeout(DisplayOSD,600)};var l={success:j,failure:function(m){if(_debug){console.log("AJAX ERROR!\nDisplay settings could not be set")}}};_yuiConnect.asyncRequest("GET",i,l,null)};var d={success:a,failure:function(e){if(_debug){console.log("AJAX error when submitting OST setting")}}};var c="/myles?req="+Math.random()+"&q=DCMD+OST+OFF";_yuiConnect.asyncRequest("GET",c,d,null)}function GetGraphicFiles(){var d;for(d=$("graphicFileSelect").length-1;d>=0;d--){$("graphicFileSelect").remove(d)}var a={id:_REQID.GETOSDGRAPHICS,width:_ostImageSize.OFF[0],height:_ostImageSize.OFF[1],req:Math.random()};var e=function(i){try{var j=YAHOO.lang.JSON.parse(i.responseText);var f=j.Graphics;var g=new Option("Select Graphic File","none");if(f.length===0){g.innerHTML="No Graphic files"}$("graphicFileSelect").appendChild(g);for(d=0;d<f.length;d++){g=new Option(f[d].filename,f[d].path+"/"+f[d].filename);$("graphicFileSelect").appendChild(g)}if(setting["dcmd_osd_region"+setting.dcmd_osd_imageRegion+"_graphisloaded"]){for(d=0;d<$("graphicFileSelect").length;d++){if(($("graphicFileSelect").options[d]).value==setting["dcmd_osd_region"+setting.dcmd_osd_imageRegion+"_graph"]){$("graphicFileSelect").selectedIndex=d;break}}}else{}}catch(h){if(_debug){console.log("Graphics could not be parsed in JSON format")}}};var c={success:e,failure:function(f){if(_debug){console.log("List of graphics could not be retrieved")}}};var b=_yuiStringify(a);if(_debug){console.log("retrieving playlists. postdata: \n"+b)}_yuiConnect.asyncRequest("POST",_REQHANDLER,c,b)}function SubmitClearOSD(a){var b="/myles?req="+Math.random()+"&q=DCMD+OSD+0+OFF";var c=function(e){setTimeout(DisplayOSD,_DISPLAYRELOADTIMEOUT);SaveSettings();SetInfoMessage("Your new settings have been set",_DEFAULT_INFO_MSG_TIMEOUT,_GREEN)};var d={success:c,failure:function(e){document.body.style.cursor="default";if(_debug){console.log("OSD could not be cleared."+e.response)}}};_yuiConnect.asyncRequest("GET",b,d,null);return false}CreateMetaTagElement("osd");