var iw_wait;
var ib_unload;
var ii_width, ii_height, ii_timer, ii_timout;
var is_user, is_request, is_wparms, is_fr, is_auto, is_no;
var tmpl_auto, tmpl_no, tmpl_sty, tmpl_load;
var t = top.MapFrame;

is_user    = "";                       // Unused - for compatability with ktovomat
is_request = "";                       // Used for address url

// Timeout for kiosk
ii_timer   =   0;
ii_timeout = 300;

ii_height  = screen.availHeight - 10;  // ii_height  = screen.availHeight - 80;
ii_width   = screen.availWidth  - 10;

iw_wait    = window;
ib_unload  = true;
is_nl      = String.fromCharCode(13);

is_wparms  = "scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no,location=no,top=150,y=150,left=250,x=250,width=300,height=300";
is_fr      = ' MARGINWIDTH=0 MARGINHEIGHT=0 FRAMEBORDER=no '
is_auto    = is_fr + ' SCROLLING=Auto ';
is_no      = is_fr + ' SCROLLING=no ';

tmpl_auto  = ' SRC=fr_htm/fr_empty.htm NORESIZE ' + is_auto;
tmpl_auton = ' SRC=fr_htm/fr_empty.htm NORESIZE ' + is_fr + ' SCROLLING=no ';
tmpl_no    = ' SRC=fr_htm/fr_empty.htm NORESIZE ' + is_no;
tmpl_load  = ' SRC=fr_asp/fr_load.asp  NORESIZE ' + is_no;
tmpl_sty   = ' STYLE="border-left: solid 1pt #000000; border-right: solid 1pt #000000; border-bottom: solid 1pt #000000;"';


if (gs_iriaMode == 'kiosk') {window.setTimeout("f_timeout()", 10000)}   // 10000 (millisecs) = 10 secs
function f_timeout()
{
 ii_timer += 10;
 window.setTimeout("f_timeout()", 10000);
}

// Usage: Called by aimsNavigation.js: mouseStuff()
// Note:  Only calls reloadApp() if in kiosk mode
function f_timein()
{
 var ls_msg;

 if (ii_timer > ii_timeout - 1)
 {
  ls_msg = msgList[270].replace('###timeout###', parseInt(ii_timeout/60) + ' דקות ');
  if (confirm(ls_msg)) {reloadApp();return false;}
  else                 {ii_timer = 0}
 }
 else {ii_timer = 0}
}

function f_refresh(ab_nounload)
{
 var  ls_href, ls_parms;
 var  li;

 ls_parms  = '';
 ib_unload = false;

 if (ab_nounload) {f_nounload()}

 ls_href = '';
 ls_href = document.location.href;
 li      = ls_href.indexOf('?');
 if (li > 10) {ls_href = ls_href.substring(0, li)}

 window.open(ls_href,'_self')

 // EQUIVALENTS:
 // document.location.reload(true);
 // document.history.go(0);
 // document.location.href = ls_href;
 // window.location.href = ls_href;
 // parent.location.href = ls_href;
}

function f_unload()
{
 var ls_href;

 if (iw_wait)
 {
  ls_href = iw_wait.document.location.href;
  if (ls_href.indexOf('wait') > -1) {iw_wait.close()}
 }

 if (ib_unload)
 {
  // ls_href = 'fr_asp/fr_unload.asp';
  // window.location.href = ls_href;
 }
}

function f_nounload()
{
 // ls_href = 'fr_asp/fr_nounload.asp';
 // top.BottomFrame.document.location.href = ls_href;
}

var theTitle    = "מערכת המפות של עיריית תל אביב יפו - iView GIS";
var cmdString   = document.location.search;
var webParams   = cmdString;
var reloadTimer = 0;

// TITLE
if (theTitle.indexOf("###TITLE##") != -1) {theTitle = titleList[0]}
document.writeln("<TITLE>" + theTitle + "</TITLE>");

function doIt()
{
 MapFrame.useJava=false;
 MapFrame.checkParams();
}

function replacePlus(inText)
{
 var re = /\+/g;

 inText = inText.replace(re," ");
 return inText;
}

function reloadApp()
{
 f_refresh(true)

 // window.clearTimeout(reloadTimer);
 // reloadTimer = window.setTimeout("document.location = 'viewer.htm' + cmdString",1000);
}


//////////////////////////
// Layer ID conversions //
//////////////////////////
function jf_viewer_iriaID2layer(ai_iriaID, as_type)
{
 // Purpose:    To convert to different layer numbers using ai_iriaID
 // Parameters: ai_iriaID
 //             as_type       ; type requested: layer, layerno, layerid, irialayer (reverse case)
 //                           ; or other layer properties (else ...)
 // Returns:    layer requested

 var li_layerno, li_layer;
 var li, li_upb;

 as_type = as_type.toLowerCase();
 li_layer = 0;
 li_upb   = top.MapFrame.iriaLayers.length;
 for (li=0;li<li_upb;li++)
 {
  if (as_type == 'irialayer')
  {
   // Reverse Case Lookup for iriaLayer
   if (top.MapFrame.iriaLayers[li].no == ai_iriaID)
   {
    li_layer = top.MapFrame.iriaLayers[li].id;
    li = li_upb;
   }
  }
  else
  {
   if (top.MapFrame.iriaLayers[li].id == ai_iriaID)
   {
    li_layerno = top.MapFrame.iriaLayers[li].no;
    if      (as_type == 'layer')   {li_layer = li;}
    else if (as_type == 'layerno') {li_layer = li_layerno;}
    else if (as_type == 'layerid') {li_layer = top.MapFrame.LayerID[li_layerno];}
    else
    {
     ls_eval = "top.MapFrame.iriaLayers[li]." + as_type;
     li_layer = eval(ls_eval);
    }
    li = li_upb;
   }
  }
 }
 return li_layer;
}

function jf_viewer_processdata(as_data)
{
 // Purpose: To process data received from fr_getdata.asp
 // Usage:   When retrieving data using the ActiveX object
 // Note:    1 - The <IFRAME ID=specials > is used by fr_getdata.asp
 //          2 - fr_getdata.asp uses this function as a callback
 //          3 - the first parameter in lr_request[] determines which
 //              type of map function to implement
 // History: 20080307 - CREATED
 //
 var lr, lr1, lr_data, lr_request, lr_response;
 var ls_point, ls_where, ls_spatialquery, theString;
 var li, lj;
 var lb_debug = false; // lb_debug = true;

if (lb_debug) {alert("js_viewer.js - li:199 - jf_viewer_processdata: " + as_data);}

 ls_point    = '<POINT x="###X_COORD###" y="###Y_COORD###" />';
 lr_data     = as_data.split('<RESPONSE>');
 lr_request  = lr_data[0].split('&');
 lr_response = lr_data[1].split('<BR>');

 lr = lr_request[0].split('=');
if (lb_debug) {alert("js_viewer.js - li: 207 - jf_viewer_processdata: lr[1]: " + lr[1]);}
 switch (lr[1])
 {
  case 'gushhelka':
   for (li=0;li<lr_response.length;li++)
   {
    lr1 = lr_response[li].split('=');
    // Set new Israel Coordinates
    if (lr1[0] == 'X_COORD') 
    {
     if (lr1[1] < 160000) {lr1[1] = parseFloat(lr1[1]) + parseFloat(50000);}
     ls_point = ls_point.replace('###' + lr1[0] + '###', lr1[1]);
    }
    else if (lr1[0] == 'Y_COORD') 
    {
     if (lr1[1] < 600000) {lr1[1] = parseFloat(lr1[1]) + parseFloat(500000);}
     ls_point = ls_point.replace('###' + lr1[0] + '###', lr1[1]);
    }
   }
   theString = top.MapFrame.jf_aimsXML_XYfromSQL();
   theString = theString.replace('###multipoint###', ls_point);
   top.MapFrame.sendToServer(top.MapFrame.imsQueryURL,theString,1101);
   break;

  case 'houses':
   // Inserts the houses in correct order
   // alert(lr_response.join(','));
   break;

  case 'house':
   gr_iriaURL.house = '';
   for (li=0;li<lr_response.length;li++)
   {
    if      (lr_response[li].indexOf('ADDRESS_ID') > -1) {ls_where               = lr_response[li];}
    else if (lr_response[li].indexOf('STREET_NAM') > -1) {gr_iriaURL.street_nam  = lr_response[li].split('=')[1];}
    else if (lr_response[li].indexOf('HOUSE') > -1)      {gr_iriaURL.house      += lr_response[li].split('=')[1];}
    else if (lr_response[li].indexOf('ENTRANCE') > -1)   {gr_iriaURL.house      += lr_response[li].split('=')[1];}
   }
if (lb_debug) {alert("js_viewer.js - li:245 - jf_viewer_processdata()\n" + ls_where + "\n" + gr_iriaURL.street_nam + "\n" + gr_iriaURL.house);}

   try
   {
    ls_where += '';
    if (ls_where == 'undefined' || ls_where == '')
    {
     alert('כתובת לא תקנית');
     top.right.ib_pinup = false;
     top.right.jf_right_pinup('hidden');
    }
    else
    {
     top.right.jf_right_query_execute(ls_where, '', 'house');
     top.right.ib_pinup = true;
     top.right.jf_right_pinup('visible')
    }
   }
   catch(e)
   {
    alert('כתובת לא תקנית');
    top.right.ib_pinup = false;
    top.right.jf_right_pinup('hidden');
   }
   break;

  default:
   break;
 }
}

/////////////////////////////
function f_pikuach(as_parms)
{
 var ls_href, ls_wparms;
 var lw;

 ls_href   = "fr_asp/fr_pikuachf.asp?" + as_parms;
 ls_wparms = "titlebar=no,toolbar=no,status=no,location=no,menubar=no,resizable=yes,scrollbars=yes,width=300,height=300,menubar=0,top=5,y=5,left=5,x=5";
 if(lw) {close()}
 lw = window.open(ls_href, "pikuach", ls_wparms);
 lw.focus();
}

//// News Popup
//function f_show_wait(as_path)
//{
// iw_wait = window.open(as_path + "w_htm/w_wait.htm?iriaMode=" + top.gs_iriaMode + "&","hadashot",is_wparms);
// // iw_wait.focus();
//}
//if (top.gr_iriaURL.url.indexOf('?') == -1 && top.gs_iriaMode == 'internet') {f_show_wait("")}
//
//function f_close_wait() {iw_wait = window}


