//eg modeltype = 3, motion=true,deblocking=false
function WriteVitamin(id,ip,httpport,width,height,user,pw,modeltype,motion,deblocking,mediatype,controltype,protocol,ptz)
{
    if ((navigator.appName == "Microsoft Internet Explorer")&&(navigator.platform != "MacPPC")) 
    {
        strObject = '<OBJECT ID="' + id + '" WIDTH="'+width+'" HEIGHT="'+height+'" name="'+ id +'" CLASSID="CLSID:70EDCF63-CA7E-4812-8528-DA1EA2FD53B6" CODEBASE="/VitaminCtrl.cab#version=2,1,0,28">'
        document.write(strObject);
        if (ptz == "1")
        {
            document.write('<PARAM NAME="ClickEventHandler" VALUE="1">');
            document.write('<PARAM NAME="WheelEventHandler" VALUE="true">');        
        }
        else
        {
            document.write('<PARAM NAME="ClickEventHandler" VALUE="0">');
            document.write('<PARAM NAME="WheelEventHandler" VALUE="false">');
        }
        document.write('<PARAM NAME="ReadSettingByParam" VALUE="true">');
        document.write('<PARAM NAME="Stretch" VALUE="true">');
        document.write('<PARAM NAME="Language" VALUE="EN">');
        document.write('<PARAM NAME="UserName" VALUE="'+user+'">');
        document.write('<PARAM NAME="Password" VALUE="'+pw+'">');
        document.write('<PARAM NAME="RemoteIPAddr" VALUE="'+ip+'">');
        document.write('<PARAM NAME="HttpPort" VALUE="'+httpport+'">');
        document.write('<PARAM NAME="AutoReconnect" VALUE="true">');
        document.write('<PARAM NAME="IgnoreBorder" VALUE="true">');
        document.write('<PARAM NAME="IgnoreCaption" VALUE="true">');
        if (mediatype == "0")
        {
            document.write('<PARAM NAME="MediaType" VALUE="1">');
        }
        else
        {
            document.write('<PARAM NAME="MediaType" VALUE="3">');
        }
        document.write('<PARAM NAME="DisplayErrorMsg" VALUE="false">');
        document.write('<PARAM NAME="ReconnectionWait" VALUE="1000">');
        document.write('<PARAM NAME="ConnectionTimeout" VALUE="12000">');
        document.write('<PARAM NAME="ReadWriteTimeout" VALUE="12000">');
        document.write('<PARAM NAME="PreEventTime" VALUE="0">');
        if ((controltype=="0")||(controltype=="false")||(controltype=="False"))
        {
            document.write('<PARAM NAME="ControlType" VALUE="0">');
        }
        else
        {
            document.write('<PARAM NAME="ControlType" VALUE="1">');        
        }
        if (modeltype == "auto")
        {           
           document.write('<PARAM NAME="AutoServerModelType" VALUE="true">');
        }
        else
        {
            document.write('<PARAM NAME="ServerModelType" VALUE="'+modeltype+'">');
        }
        if ((motion=="0")||(motion=="false")||(motion=="False"))
        {
           document.write('<PARAM NAME="DisplayMotionFrame" VALUE="false">');
        }
        else
        {
            document.write('<PARAM NAME="DisplayMotionFrame" VALUE="true">');
        }     
           
        if ((deblocking=="0")||(deblocking=="false")||(deblocking=="False"))
        {
           document.write('<PARAM NAME="Deblocking" VALUE="false">');
        }
        else
        {
            document.write('<PARAM NAME="Deblocking" VALUE="true">');
        }  
        if (protocol=="3")
        {        
            document.write('<PARAM NAME="ConnectionProtocol" VALUE="3">');
        }
        document.write('<PARAM NAME="ForceNonYYV" VALUE="true">');        
        document.write('You appear to be running Internet Explorer for Windows with no ActiveX Support. Talk to your network administrator to enable ActiveX Support.</OBJECT>'); 
    }
}

function NoConfirm()
{
    win = top;
    win.opener = top;
    win.close();
}


function WriteVideoArmed(id,url,width,height,pw, motion, audio, ptz, codeurl)
{
    if ((navigator.appName == "Microsoft Internet Explorer")&&(navigator.platform != "MacPPC")) 
    {
        document.write('<OBJECT ID="' + id + '" WIDTH="'+width+'" HEIGHT="'+height+'" name="'+ id +'" CLASSID="CLSID:e62d1a95-8299-4b94-85d0-731dc125a60d" CODEBASE="'+codeurl+'">');
        if (ptz == "1")
        {    
        }
        else
        {
        }
        document.write('<PARAM NAME="Source" VALUE="'+url+'">');        
        document.write('<PARAM NAME="AutoPlay" VALUE="1">');
        document.write('<PARAM NAME="DisplayRate" VALUE="0">');
        document.write('<PARAM NAME="OpenRefRegionMD" VALUE="1">');
        document.write('<PARAM NAME="Width" VALUE="'+width+'">');
        document.write('<PARAM NAME="Height" VALUE="'+height+'">');        
//        if (audio == "auto")
//        {
//        }
//        else
//        {
//        }
//        if (motion=="")
//        {        
//        }    
        document.write('You appear to be running Internet Explorer for Windows with no ActiveX Support. Talk to your network administrator to enable ActiveX Support.</OBJECT>');        
        window.setTimeout("VAStart("+ id + ", '" + url + "')", 200);  
    }   
}

function VAStart(inobj, inurl) 
{
    inobj.Source = inurl;
    inobj.Play();
}

function WriteVideoVitamin(id,width,height,display,motion,mediatype,controltype)
{
    if ((navigator.appName == "Microsoft Internet Explorer")&&(navigator.platform != "MacPPC")) 
    {
        document.write('<OBJECT ID="' + id + '" WIDTH="'+width+'" HEIGHT="'+height+'" name="'+ id +'" CLASSID="CLSID:70EDCF63-CA7E-4812-8528-DA1EA2FD53B6" CODEBASE="/VitaminCtrl.cab#version=2,1,0,28">');
        document.write('<PARAM NAME="ClickEventHandler" VALUE="1">');
        document.write('<PARAM NAME="WheelEventHandler" VALUE="true">');
        document.write('<PARAM NAME="ReadSettingByParam" VALUE="true">');
        document.write('<PARAM NAME="Stretch" VALUE="'+display+'">');
        document.write('<PARAM NAME="Display" VALUE="'+display+'">');
        document.write('<PARAM NAME="Language" VALUE="EN">');
        document.write('<PARAM NAME="IgnoreBorder" VALUE="true">');                
        document.write('<PARAM NAME="AutoReconnect" VALUE="false">');
        document.write('<PARAM NAME="RemoteIPAddr" VALUE="From Proxy">');
        document.write('<PARAM NAME="IgnoreCaption" VALUE="true">');
        document.write('<PARAM NAME="MediaType" VALUE="'+mediatype+'">');
        document.write('<PARAM NAME="DisplayErrorMsg" VALUE="false">');
        document.write('<PARAM NAME="PreEventTime" VALUE="0">');
        document.write('<PARAM NAME="ControlType" VALUE="'+controltype+'">');
        document.write('<PARAM NAME="AutoServerModelType" VALUE="true">');
        document.write('<PARAM NAME="DisplayMotionFrame" VALUE="'+motion+'">');
        document.write('<PARAM NAME="Deblocking" VALUE="true">');
        document.write('<PARAM NAME="ForceNonYYV" VALUE="true">');
	    document.write('<PARAM NAME="AutoAVISettings" VALUE="true">');		
	    document.write('<PARAM NAME="AVIVideoSizeByStream" VALUE="true">');	
	    document.write('<PARAM NAME="AVIManualNaming" VALUE="true">');		        
        document.write('You appear to be running Internet Explorer for Windows with no ActiveX Support. Talk to your network administrator to enable ActiveX Support.</OBJECT>'); 
    }
}

function WriteQuickTime(id,url,width,height)
{
    document.write('<OBJECT id="'+id+'" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'+width+'" height="'+height+'" codebase="http://www.apple.com/qtactivex/qtplugin.cab">'); 
    document.write('<param name="qtsrc" value="rtsp://'+url+'">'); 
    document.write('<param name="autoplay" value="true">'); 
    document.write('<param name="QTSRCDONTUSEBROWSER" value="true">'); 
    document.write('<param name="controller" value="false">'); 
    document.write('<param name="loop" value="false">'); 
    document.write('<param name="scale" value="ToFit">'); 
    document.write('<param name="bgcolor" value="#000000">'); 
    document.write('<EMBED type="video/quicktime" id="'+id+'" src="empty.mov" qtsrc="rtsp://'+url+'" width="'+width+'" height="'+height+'" autoplay="true" ');
    document.write('controller="false" scale="ToFit" loop="false" QTSRCDONTUSEBROWSER="true" bgcolor="#000000" pluginspage="http://www.apple.com/quicktime/download/">'); 
    document.write('</EMBED> '); 
    document.write('</OBJECT> '); 
}

function WriteQuickTimeFile(id,url,width,height)
{
    document.write('<OBJECT id="'+id+'" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'+width+'" height="'+height+'" codebase="http://www.apple.com/qtactivex/qtplugin.cab"> ');
    document.write('<param name="src" value="'+url+'"> ');
    document.write('<param name="autoplay" value="true"> ');
    document.write('<param name="loop" value="false"> ');
    document.write('<param name="scale" value="ToFit">');     
    document.write('<param name="bgcolor" value="#000000"> ');
    document.write('<EMBED type="video/quicktime" id="'+id+'" src="'+url+'" width="'+width+'" height="'+height+'"autoplay="true"  ');
    document.write(' loop="false" scale="ToFit" bgcolor="#000000" pluginspage="http://www.apple.com/quicktime/download/">');
    document.write('</EMBED> ');
    document.write('</OBJECT> ');
}

function WriteAirlink(id,width,height)
{
    document.write('<OBJECT id=' + id + ' name=' + id + ' height=' + height + ' width=' + width + ' ');
    document.write('classid=CLSID:CCA0B877-CB5E-4adc-AD30-457C379512DD CODEBASE="/xplugLiteAL.cab#version=2,2,0,0">');
    document.write('</OBJECT>'); 
}

function SetUpAirlink(airobj,id,ipaddr,portnum,width,height) 
{
    airobj.RemoteHost = ipaddr;
    airobj.RemoteWeb = portnum;
    airobj.RemotePort = portnum;
    airobj.Timeout = 5;
    airobj.AuthType = 1;
    airobj.PreviewFrameRate = 1;
    airobj.PreviewWidth = width;
    airobj.PreviewHeight = height;
    airobj.DeviceSerialNo = "";
    window.setInterval("AirLinkRate("+ id + ")", 1000);     
}

function AirLinkRate(airobj) 
{
    airobj.Play()
}

popupWins = new Array();
function windowOpener(url, name, args) 
{
  if ( typeof( popupWins[name] ) != "object" )
  {
   popupWins[name] = window.open(url,name,args);
 } 
 else 
 {
  if (!popupWins[name].closed)
  {
	popupWins[name].location.href = url;
  } 
  else 
  {
	popupWins[name] = window.open(url, name,args); }
 }
  
popupWins[name].focus();
}

function imagewindow(htmlfile,image,height,width) 
{
windowOpener(htmlfile,image,'height=' + height + ', width=' + width + ', top=25,left=25,location=no, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=yes'); } 
function rollover(imgID) { var thisimg = document.getElementById(imgID); thisimg.src = thisimg.src.replace(/(\.[a-z0-9]+)$/i,'sel$1'); } 
function rollout(imgID) { var thisimg = document.getElementById(imgID); thisimg.src = thisimg.src.replace(/sel(\.[a-z0-9]+)$/i,'$1'); } 
function getHTTPObject() {
if (typeof XMLHttpRequest != 'undefined') {
    return new XMLHttpRequest(); } 
try {
    return new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
   try {
       return new ActiveXObject("Microsoft.XMLHTTP");
   } catch (e) {}
  }
 return false;
}

function authenticate(url,user,pass) 
{
    var http = getHTTPObject();
    http.open("get", url, false, user, pass);
    http.send();
    if (http.status != 200) 
    {
        alert("Authentication Failed.");
        return false;
    }
}
function presetptz(preset,camera) 
{
    retframe.location.href = "ptz.vpx?camera=" + camera + "&recall=" + preset; 
}

function recording(command) 
{
    alert(command +" User Recording"); 
} 

function PlaySound(soundfile)
{
    document.write('<embed src="audio/' + soundfile +'" autostart=true loop=false height=0 width=0 visible=false></embed>');
}

function SonyActiveXAuto(id,ipaddr,portnum,width, codec, codeurl)
{
    document.write('<object id="' + id + '" classid="CLSID:6E49B4EF-9FE5-44DF-8D04-445AA94F83DB" CODEBASE="'+codeurl+'">');
    if( codec == "mpeg4")
    {
        document.write('<param name="ParamCodec" value="PRM_CODEC_MPEG">');
    }
    document.write('<PARAM name="ParamCamAddress" value="' + ipaddr + '">');
    document.write('<PARAM name="ParamCamPort" value="' + portnum + '">');
    document.write('<PARAM name="ParamViewMode" value="00000000">');
//PRM_VIEWSIZE_VGA VGA (640x480)
//PRM_VIEWSIZE_QVGA QVGA (320x240)
//PRM_VIEWSIZE_QQVGA QQVGA (160x120)
//PRM_VIEWSIZE_AUTO
    if (width>639)
    {
        document.write('<PARAM name="ParamViewSize" value="PRM_VIEWSIZE_VGA">');
    }
    else if (width>319)
    {
        document.write('<PARAM name="ParamViewSize" value="PRM_VIEWSIZE_QVGA">');
    }
    else
    {
        document.write('<PARAM name="ParamViewSize" value="PRM_VIEWSIZE_QQVGA">');
    }
    document.write('</object>');
}

function AxisActiveXAuto(id,ipaddr,portnum,user,pass,width,height, codec, ptz, audio, extra, codeurl)
{    
    document.write('<object id="' + id + '" width="' + width + '" height="' + height + '" border="0" classid="CLSID:745395C8-D0E1-4227-8586-624CA9A10A8D" CODEBASE="'+codeurl+'">');
    document.write('<PARAM name="AutoStart" value="1">');
    if (ptz == "1")
    { 
        document.write('<PARAM name="UIMode" value="ptz-relative">');         
    }
    else
    {
        document.write('<PARAM name="UIMode" value="none">');         
    }
    if (audio == "0")
    {    
        document.write('<PARAM name="Mute" value="1">');    
    }   
    if (extra == "1")
    {
        document.write('<PARAM name="ShowToolbar" value="1">');    
    }   
    document.write('<PARAM name="StretchToFit" value="1">'); 
    document.write('<param name="MediaType" value="auto-sense">');
    document.write('<param name="NetworkTimeout" value="5000">');
    document.write('<param name="MediaUsername" value="' + user + '">');
    document.write('<param name="MediaPassword" value="' + pass + '">');    
    if (codec == "mpeg4")
    {
        document.write('<param name="MediaURL" value="rtsp://' + ipaddr + ':' + portnum + '/mpeg4/media.amp">');
    }
    else
    {
        document.write('<param name="MediaURL" value="http://' + ipaddr + ':' + portnum + '/axis-cgi/mjpg/video.cgi">');
    }    
    document.write('</object>');
}

function InstallFilter(ID, CLSID_filter, ver_filter, cab, installText1, text, installText2, installText3, installText4)
{
    document.write('<object ID="'+ ID + '" height="0" width="0" CLASSID="CLSID:' + CLSID_filter + '" CODEBASE="/activex/' + cab + '#Version=' + ver_filter + '">');
    document.write('</OBJECT>');
}

function InstallDecoder(ID, CLSID_AMC, cab, ver_AMC, authorized, notAuthorizedText, authorizedText, installDecoderText1, installDecoderText2)
{
    document.write('<OBJECT ID="'+ ID + '" height="0" width="0" CLASSID="CLSID:' + CLSID_AMC + '" CODEBASE="' + cab + '#version=' + ver_AMC + '"');
    document.write('</OBJECT>');
}

function drawMpeg4Dec(id, height, width, codebase)
{
    document.write('<OBJECT ID="' + id + '" height="' + height + '" width="' + width + '" border="0" CLASSID="CLSID:c32fe9f1-a857-48b0-b7bf-065b5792f28d" CODEBASE="' + codebase + '"></OBJECT>');
}

function drawAacDec(id, height, width, codebase)
{
    document.write('<OBJECT ID="' + id + '" height="' + height + '" width="' + width + '" border="0" CLASSID="CLSID:ba7a56eb-d1b9-443b-96e9-086532a378f1" CODEBASE="' + codebase + '"></OBJECT>');
}