










var oemcolor = '"#009999"';
var headlinkcolor = '"#FFFFFF"';

var isVAV = false;



var WEBSITE_OPTION = 
  "<option value=\"http://www.iqinvision.com/\">www.IQinVision.com</option>\n";


var isPTZ =  "NO"; 
isPTZ =  (isPTZ == "YES" || isPTZ == "yes" || isPTZ == "Yes") ? true:false;

var prodID = "2a";

var isIQeye2 = prodID.match("1"); 

var isIQeye3 = (prodID == "2a") || (prodID == "2f") || (prodID == "29");
var isIQevent = (prodID == "2f");



var isIQeye7 = (prodID=="3b") || (prodID=="4d");
var isIQeye5 = (prodID=="3c") || (prodID=="3b") || (prodID=="4d");
var isIQeye500 = (prodID=="3c");

var isIQeye6 = (prodID=="2d") || (prodID=="3c") || (prodID=="3b") || (prodID=="4d");

var hasNightModeSupport = !isIQeye2;
var hasHotSpotSupport = isIQeye2; 
var hasPCCardSupport = 0; 
hasPCCardSupport = (hasPCCardSupport > 0) ? true:false;
var hasAudioSupport = "0"; 
hasAudioSupport = (hasAudioSupport>0) ? true:false;
var hasIrisConnector = "0"; 
hasIrisConnector = (hasIrisConnector > 0) ? true:false;
var hasMotionSupport = "8"; 
hasMotionSupport = (! hasMotionSupport.match("Err::Unknown OID"));
var hasColorSupport = "1"; 
hasColorSupport = (hasColorSupport!=0) ? true:false;
var hasPrivacySupport = (isIQeye5 || !isIQeye6) ? true:false;
var hasExposureSupport = (isIQeye5 || !isIQeye6) ? true:false;

var hasRecorderSupport;
if (isVAV) {
     hasRecorderSupport = false;
}
else if (!isIQeye5) {
     hasRecorderSupport = true;
}
else {
     hasRecorderSupport = "TRUE";
     if (hasRecorderSupport=="TRUE" ||
	 hasRecorderSupport=="DEMO") {
	  hasRecorderSupport = true;
     }
     else {
	  hasRecorderSupport = false;
     }
}

var authMode = "Basic"; 
authMode = authMode.toLowerCase();






var serverNameString = "IQEYE0117DF";














var settings = new Object();	 
var viewing = new Object();      
var cameo = new Object();      




function linkAction(link) {
    if (document.images) 
	return "javascript:self.location.replace('" + link + "')";
    else return link;
}

var livevidhref = '<a href="' + linkAction("/") 
                + '"><font color=#FFFFCC><b>LIVE</b></font></a>';

var playbackhref = '<a href="' + linkAction("playback.html") 
                 + '"><font color=#FFFFCC><b>PLAYBACK</b></font></a>';

if (isVAV) {
   livevidhref = '<a href="' + linkAction("/") 
                + '"><font color=#FFFFCC><b>ALARM</b></font></a>';
   playbackhref="";
}

function initSettingsNavBar() {
    var i = 0;
    var navbar = settings;
    var livetext;

    if (isVAV) livetext = "alarm";
    else livetext = "live";

    navbar.columns = 0; 
    navbar.tabwidth = 50;
    navbar.names = new Array();
    navbar.title = "settings"
    navbar.text = new Array();
    navbar.tabtext = new Array(); 
    navbar.values = new Array();
    navbar.tabheight = 13;

    navbar.columns += 4;
    navbar.names[i] = livetext;
    navbar.values[i] = "/";
    navbar.tabtext[i] = livetext;    
    navbar.text[i++] = livetext;

    if (hasRecorderSupport) {
       navbar.columns += 4;
       navbar.names[i] = "playback";
       navbar.tabtext[i] = "playback";    
       navbar.values[i] = "playback.html";
       navbar.text[i++] = "playback";
    }

    navbar.columns += 4;
    navbar.names[i] = "image";
    navbar.values[i] = "imageset.html";
    navbar.tabtext[i] = "image";    
    navbar.text[i++] = "image settings";

    navbar.columns += 4;
    navbar.names[i] = "window";
    if (isVAV) {   
        navbar.values[i] = "exposure.html";
    }
    else {
        navbar.values[i] = "cropset.html";
    }
    navbar.tabtext[i] = "window";    
    navbar.text[i++] = "window settings";

    navbar.columns += 4;
    navbar.names[i] = "server";   
    navbar.values[i] = "serverset.html";
    navbar.tabtext[i] = "network";    
    navbar.text[i++] = "network settings";

    navbar.columns += 4;
    navbar.names[i] = "access";   
    navbar.values[i] = "accessset.html";
    navbar.tabtext[i] = "security";    
    navbar.text[i++] = "security settings";

    if (!isIQevent && !isVAV) {
      navbar.columns += 4;
      navbar.names[i] = "trigger";  
      navbar.values[i] = "triggerset.html";
      navbar.tabtext[i] = "trigger";    
      navbar.text[i++] = "trigger settings";
    }

    if (isIQeye7 || !isIQeye5) {
      navbar.columns += 4;
      navbar.names[i] = "io";
      navbar.values[i] = "ioset.html";
      navbar.tabtext[i] = "i/o";    
      navbar.text[i++] = "i/o settings";
    }

    if (!isVAV && !isIQevent && hasPCCardSupport && isIQeye3) {
        navbar.columns += 4;
        navbar.names[i] = "pccard";    
        navbar.values[i] = "pccardset.html";
        navbar.tabtext[i] = "wi-fi";    
        navbar.text[i++] = "wi-fi settings";
    } 

    if (!isVAV) {
        navbar.columns += 4;
        navbar.names[i] = "recorder";  
        navbar.tabtext[i] = "IQrecorder";    
        if (hasRecorderSupport) {
           navbar.values[i] = "recorderset.html";
        }
        else {
           navbar.values[i] = "nolicense.html";
        }
        navbar.text[i++] = "IQrecorder settings";
    }

    if (!isVAV) {
        navbar.columns += 4;
        navbar.names[i] = "multiview";
        navbar.values[i] = "multiviewset.html";
        navbar.tabtext[i] = "multiview";    
        navbar.text[i++] = "multiview settings";
    }




}


function initViewingNavBar() {
    var i = 0;
    var navbar = viewing;

    var livetext;

    if (isVAV) livetext = "alarm";
    else livetext = "live";

    navbar.columns = 0; 
    navbar.tabwidth = 50;
    navbar.names = new Array();
    navbar.title = "viewing"
    navbar.text = new Array();
    navbar.tabtext = new Array(); 
    navbar.values = new Array();
    navbar.tabheight = 13;

    navbar.columns += 4;
    navbar.names[i] = livetext;
    navbar.values[i] = "/";
    navbar.tabtext[i] = livetext;    
    navbar.text[i++] = livetext;

    if (hasRecorderSupport) {
      navbar.columns += 4;
      navbar.names[i] = "playback";
      navbar.values[i] = "playback.html";
      navbar.tabtext[i] = "playback";    
      navbar.text[i++] = "playback";
    }

    navbar.columns += 4;
    navbar.names[i] = "image";
    navbar.values[i] = "imageset.html";
    navbar.tabtext[i] = "settings";    
    navbar.text[i++] = "settings";




}

function initCameoNavBar() {
    var i = 0;
    var navbar = cameo;

    var livetext;
    if (isVAV) livetext = "alarm";
    else livetext = "live";

    navbar.columns = 0; 
    navbar.tabwidth = 50;
    navbar.names = new Array();
    navbar.title = "cameo"
    navbar.text = new Array();
    navbar.tabtext = new Array(); 
    navbar.values = new Array();
    navbar.tabheight = 13;

    navbar.columns += 4;
    navbar.names[i] = livetext;
    navbar.values[i] = "/";
    navbar.tabtext[i] = livetext;    
    navbar.text[i++] = livetext;

    navbar.columns += 4;
    navbar.names[i] = "cameo";
    navbar.values[i] = "cameo.html";
    navbar.tabtext[i] = "cameo view";    
    navbar.text[i++] = "cameo";

    navbar.columns += 4;
    navbar.names[i] = "cameo config";
    navbar.values[i] = "cameoset.html";
    navbar.tabtext[i] = "cameo config";    
    navbar.text[i++] = "cameo config";




}



function initNavbar(navbar) {
   if (navbar==settings) initSettingsNavBar();
   else if (navbar==viewing) initViewingNavBar();
   else if (navbar==cameo) initCameoNavBar();

}






function writeCroppedImage() {

    

    
    
    
    var ds = 2;
    var maxWidth = "1280"; 
    var maxHeight= "1024";
    
    if (isIQeye6) {
	maxWidth = "1280"; 
	maxHeight= "1024";
    }
    
    
    var ds_necessary = Math.max(Math.ceil(maxWidth/322),
				Math.ceil(maxHeight/322));

    
    var ds_float = Math.max (maxWidth/322, maxHeight/322);

    var dsfactor = Math.max(ds,ds_necessary);

    
    var dsreq = ds_necessary;
    
    
    if (isIQeye6) {
	if (dsreq == 3) dsreq = 4;
    }
    if (isIQeye6 || isIQeye7) {
	
	
	if (dsreq > 4) dsreq = 4;
    }
    if (isIQeye500) {
	
	if (dsreq > 2) dsreq = 2;
    }
    
    var dsstring = "?ds=" + dsreq;
    
    var imWidth =  Math.floor(maxWidth/dsfactor);
    var imHeight = Math.floor(maxHeight/dsfactor);
    
    
    if (isIQeye6 && !isIQeye5) dsstring = "";
    
    
    var orient = "NONE";
    orient = (orient.match("90") || orient.match("270") ||
	      orient.match("BLTR") || orient.match("TLBR")) ? "portrait":"landscape";
    
    if (orient=="portrait") { 
	var tmp;
	tmp = imWidth; imWidth = imHeight; imHeight = tmp;
	tmp = maxWidth; maxWidth = maxHeight; maxHeight = tmp;
    }


    if (UseActiveX()) {

	
	
	
	imWidth = Math.floor(1280/ds_float);
	imHeight = Math.floor(1024/ds_float);
	var imAttr = ' width="' + imWidth + '" height="' + imHeight + '" border=0 ';
	
	
	
	
	off_x = (isIQeye6) ? 0/ds_float:0/ds_float;
	off_y = (isIQeye6) ? 0/ds_float:0/ds_float;
	off_x = Math.floor (off_x);
	off_y = Math.floor (off_y);
	
	var divstr = '<div id="mainfeed" style="padding-left: ' +
	off_x + 'px; padding-top: ' + off_y + 'px">ActiveX Control</div>';

	var url = 'now.jpg?snap=spush0.2' + dsstring;
	if (!isIQeye6) url += '?ov=0';

	
	
	
	

	rv += '<param name="InternalDptz" value="0">';
	rv += '<param name="StreamDptz" value="0">';
	document.write (divstr);
	CreateControl ("mainfeed", imAttr, "", rv, 
		       isIQeye6, isIQeye7 || isIQeye5, url);	
	
	
	
    }
    else {
	var imAttr = ' width="' + imWidth + '" height="' + imHeight + '" border=0 ';
	
	var rv = '<div id="mainfeed">'
	    +'<applet code="WindowSet.class" name="spapplet" ' 
	    + imAttr + '>'
	    + '<param name="url1" value="1pixgray.gif">'
	    + '<param name="offsetx" value="';
	rv       +=  (isIQeye6) ? 0/dsfactor:0/dsfactor;
	rv       +=  '">' + '<param name="offsety" value="';
	rv       += (isIQeye6) ? 0/dsfactor:0/dsfactor;
	rv       += '">' + '<param name="url2" value="';
	rv       += 'now.jpg?snap=spush0.2';
	
	if (!isIQeye6) rv += '?ov=0';
	rv       += dsstring;
	rv       += '">'
	    
	    + '<param name="dsfactor" value="' + dsfactor + '">'
	    + '<param name="numWindows" value="0">';
	if (isIQeye6) {
	    rv += '<param name="hw" value="' + 1280/dsfactor + '">';
	    rv += '<param name="hh" value="' + 1024/dsfactor + '">';
	}
	rv  += '</applet></div>';
	document.write(rv);
    }
}


function spAppletDivs(source, imAttr) {
    var outString = '<div id="mainfeed">'; 
    if (!needsApplet) {
	outString  += "<img src='" + source + "' name='now' " + imAttr + ">\n";
    }
    
    outString += "</div>\n";
    
    if (needsApplet) {
	outString += 
	    '<div id=spushDiv>\n'
	    
	    + '<applet code="ShowServerPush.class" name="spapplet" ' 
	    + imAttr + '>\n'
	    + '<param name="url" value="' + source + '">\n'
	    + '</applet>'
	    
	    
	    + '</div>';
    }
    
    return outString;
}

function theApplet() {
    return document.applets["spapplet"]; 




}

function stopApplet() {
    if (theApplet()) theApplet().stop();
    return false;
}

function helpIconString(loc) {
    return '<font size="-6">'
	 + '<a href="javascript:void(0)" tabindex="-1" '
	 + 'onClick="return helpMe(\'' + loc + '\')" '
         + 'onMouseOver="window.status=\'online help\'; return true;" '
         + 'onMouseOut="window.status=\'\';">?</a></font>';
}

function writeStopAppletButton() {
    if (needsApplet && !isVAV) {
      document.write
	  ('<table width="100\%" border=0 cellpadding=0 cellspacing=0 '
	      + 'vspace=0 hspace=0>'
	      + '<tr><td align="right">\n'
	      + '<input type="button" value="stop loading" '
	      + 'onClick="return stopApplet()">\n'
	      + '</td></tr></table>\n');
    }
}

function writeHelpIcon(loc) {
    document.write (helpIconString(loc));
}

function writeTrickIcon(loc) {
    document.write 
	('<font size="-6">'
	 + '<a href="javascript:void(0)" '
	 + 'onClick="return helpMe(\'' + loc + '\')"'
         + 'onMouseOver="window.status=\'browser help\'; return true;" '
         + 'onMouseOut="window.status=\'\';">'
	 + 'browser management tricks</a></font>');
}

function errorGifTD() {
  return '<td><img name="errorgif" id="errorgif" src="1pixclear.gif" '
      + 'width=300 height=24 border=0></td>';
}

function setupViewingTabs() {
    initNavbar(viewing);
}






function jumpMenu2String() {
    initNavbar(settings);	

    var i, targ, text;

    var onChangeStr = 
	'onChange="self.location=this.options[this.selectedIndex].value"';
        
    var outString = '<td align=right>\n'
        + '<form name="goto"><select class="formselect" name="whereto"' 
        + onChangeStr + '>\n'
	+ '<option value="javascript:void(0)">Quick Jump To ...</option>\n';

    if ((authMode == "error403") &&
        (document.cookie.length==0 
        || document.cookie.indexOf("SrvrCreds") == -1)) { 
  	targ = settings.values[0];
	outString += '<option value="' + targ + '">log in</option>\n';
    } else {
        for (i=0; i < settings.names.length; i++) {
    	    targ = settings.values[i];
  	    text = settings.text[i];
	    outString += '<option value="'+ targ +'">' + text + '</option>\n';
          }
    }
    outString += 
	'<option value="javascript:void(0)">-----------</option>\n'
	+ WEBSITE_OPTION
	+ '</select></form></td>\n';
    return outString;	
}

function writeJumpMenu2Table() {
    document.write("<table width=\"100%\"><tr>"
	+ errorGifTD()
        + jumpMenu2String() 
        + "</tr></table>");	
}



function writeViewHeader() {
    document.write
	("<table border=0 cellpadding=0 cellspacing=0 "
 	 + 'width="100%">\n'

         + '<tr><td colspan=2 bgcolor=' + oemcolor + '>\n'
         + '<image src="1pixclear.gif" height=4 width=1></td></tr>\n'

	 + '<tr><td colspan=2 bgcolor=' + oemcolor + ' width="100%">\n'
	 + '<font color=' + headlinkcolor + 'size="+2">'
	 + '<nobr>&nbsp; live</nobr></font></td></tr>\n'

         + '<tr><td colspan=2 bgcolor=' + oemcolor + '>\n'
         + '<image src="1pixclear.gif" height=4 width=1></td></tr>\n'

	 + '<tr><td colspan=2 height=4></td></tr>\n'

	 + '<tr>' +  errorGifTD() + jumpMenu2String() + '</tr></table>'
	 );
}



function writeTitleBar() {
    document.write
	('<table width=\"100%\" border=0 cellpadding=0 cellspacing=0><tr>\n'
	 + '<td bgcolor=' + oemcolor + '>\n'
	 + '<img src="1pixclear.gif" width=154 height=22 border=0></td>\n'
         + '<td bgcolor=' + oemcolor + ' align=right>' 
         + livevidhref 
         + '<image src="1pixclear.gif" width=10 alt="">'
         + '</td></tr></table>\n');
}

function textTab(name, desc, link, onoff) {
    var outString = (onoff) ? '<li id="current">' : '<li>';
    return outString 
	+ '<a href="' + linkAction(link) + '"'
        + ' onMouseOver=\'window.status="' + desc + '"; return true;\''
	+ ' onMouseOut=\'window.status=""\'>'
	+ name + '</a></li>';
}




function writeSettingsHeader(onItem) {
    writeHeader(settings, onItem);
}




function writeViewingHeader(onItem) {
    writeHeader(viewing, onItem);
}

function writeCameoHeader(onItem) {
    writeHeader(cameo, onItem);
}




function writeInstallHeader(onItem) {
    writeHeader(install, onItem);
}

function writeHeader(navbar, onItem) {
    var i, itemNo=0;

    initNavbar(navbar);
 
    for (i=0; i<navbar.names.length; i++) {
	if (navbar.names[i]==onItem) itemNo=i;
    }

    var out = 
	'<tr><td class="tl"><img src="1pixclear.gif" width=11 height=42></td>'

	if(navbar == viewing || navbar == cameo){
            out += '<td class="topmenu" width=630>'
	}
        else {
            out += '<td class="topmenu" colspan=2 width=';
	    if (0) out += '780>'; 
	    else out += '760>';
	}
    
	out += '<h1><font color="666666"><img src="1pixclear.gif" width=4 height=1>IQeye3 </font>' 
        + 'IQEYE0117DF' + '</h1>'
	+'<img src="1pixclear.gif" width=4 height=1>' + '<ul id="nav">';

    for (i=0; i<navbar.names.length; i++) {
	out += textTab(navbar.tabtext[i], navbar.text[i], navbar.values[i], 
		  (navbar.names[i]==onItem));
    }

    if(navbar==viewing || navbar == cameo){
        out += '</ul></td>'
	    +'<td class="topmenu" width=130><img src="logosm.gif" width=124 height=21></td>'
	    + '<td class="tr"><img src="1pixclear.gif" width=1 height=1></td>'
	    + '</tr>';
    }
    else {
        out += '</ul></td>'
	    + '<td class="tr"><img src="1pixclear.gif" height=1></td>'
	    + '</tr>';
    }
    document.write(out);
}

var logoutHref =
    '<li><a href="javascript:void(0)" onClick="logout(); return false"' 
    + ' onMouseOver=\'window.status="Logout of session"; return true;\''
    + ' onMouseOut=\'window.status=""\'>'
    + 'logout session</a></li>\n';

var rebootHref =
    '<li><a href="javascript:void(0)" onClick="return reboot()"'
    + ' onMouseOver=\'window.status="Reboot camera"; return true;\''
    + ' onMouseOut=\'window.status=""\'>'
    + 'reboot camera</a></li>\n';


function sendCommandAppletString() {
    var outString ="";

    if (needsIframe) {
        outString +=
            '<iframe name="commandIframe" id="commandIframe" '
            + 'frameborder=0 scrolling=no '
	    
	    
	    + 'width=1 height=1 marginwidth=0 marginheight=0 align=top '

	    
	    
	    
	    + 'src=get.oid?2.27></iframe>';
    } else { 
    
    }
    return outString;  
}






function writeFooter() {
    var logoutOK = (authMode == "basic") ? false:true;
    

    var outString = '<tr>'
	+ '<td class="l"><img src="1pixclear.gif" width=1 height=1></td>'
	+ '<td class="buttonbar" align="left"  style="padding-left: 24px">'
	+ '<ul id="button">';

    for (var n=0;n<arguments.length; n++) {
        var arg = arguments[n];
	if (arg == "logout" && logoutOK)   outString += logoutHref;
	else if (arg == "reboot")          outString += rebootHref;
	else if (arg == "myDefaults")      outString += myDefaultsHref;
    }
    outString += '</ul>&nbsp; </td>'
	+ '<td class="logo" align="right">'
	+ '<img src="logo.gif" height="24" width="156">'
	+ sendCommandAppletString() + '</td>'
        + '<td class="r"><img src="1pixclear.gif" height=1 width=11></td>'
	+ '</tr>';
    document.write(outString);
}



function writeBareFooter() {
    var outString = 
	'<table width="100%"><tr>'
	+ '<td align="right">'
	+ '<font face="Arial, Helvetica, sans-serif"><b>' 
	+ 'IQEYE0117DF' + '</b><br></font></td></tr>\n'
	+ '<tr><td align=center height=2 bgcolor=' + oemcolor + '>'
	+ '<img src="1pixclear.gif" height=3 border=0></td></tr></table>\n';
    document.write(outString);
}

