//SERVER="";


var result_ini="<table width=100% class=itm border=1>";
var result_end="</table>";
var lang="";

function login_ok() {
	
	document.body.style.overflow="hidden";
	
	DE("head").style.display="none";
	
	DE("main1").style.display="";
	
}

function login() {

	prm="&ar0002="+prm2+"&v0="+DE("username").value+"&v1="+DE("password").value;
	send("bVKVhMIY88UDdeFUYrBwpVEy0ZaBdntzxOYPC2T6",prm);
}
function switch_radio() 
{
  find_dealer('place')	
}

function find_dealer(s1) {

s3="<div style='position: absolute; top: 0; right: 0'>"
s3+="<img class=close src='http://www.allpa.nl/allpi/gif/close.gif' onclick='close_popup()' style='cursor:pointer; float:right;'></div>"
s3+="<div style='width:47%;background:white;display:inline-block;border:solid black 1px;float:right;margin-right:12px;'>";
s3+="<div id=map01 style='height:480px;'> map </div>"
s3+="</div><div id=details style='overflow:auto; width:47%;height:480px;background:white;"
s3+="display:inline-block;border:solid black 1px;float:left;margin-left:12px;'>"
s3+="<div id='result'></div></div>"
	
DE("popup").innerHTML=s3;

if (s1=='place') {
  allpa_popup_dealer(1);
  s0=DE("DealerProximity").value;
  s1=DE("countries").value;
  s3=GetSelectedItem();
  DE("v100").value=s0+" "+s1;
  geocode_parameters="&v105="+s3;
  geocode_find_near('yuyl4vsrOMd0lIZFf5FywA478IIe1QCyA4Rwua0D');
	}
else {
  s2=DE("DealerName").value;
  s0=DE("mySearch").value;
  s1=DE("countries").value;
  s3=GetSelectedItem();
  DE("v100").value=s1;
  send2("bXjtqSILvcxMMZM3JfQwMEsctYzuh17lIl3eCJvD"+"&v100="+s2+" "+s1+" "+s3);
 }
google_lang=lang.substr(0,2).toLowerCase();

}

function geocoder_show_2(s0) {
  s2=DE("DealerProximity").value;
  if (s2<"0") {s2="kerkenbos, Nijmegen";}
  s1=DE("countries").value;
  DE("v100").value=s2+" "+s1;
  geocode_find_near(s0);

  s1=DE("add1").innerHTML;
}                          

function GetSelectedItem() {

  chosen = ""
  len = document.form1.R1.length;
  for (i = 0; i <len; i++) {
    if (document.form1.R1[i].checked) {
      chosen = document.form1.R1[i].value
    }
  }
return chosen;
}

function display_addresses(s0) {
//alert("display: "+s0);
}

function search(s0,s1,s2) {

	DE("popup").style.display="none";
	DE("darkener").style.display="none";
   if (DE("categories")!= null)  {
   	DE("categories").style.display="none";
   	DE("products").style.display="";
   }
   page(s0);

   lang=s2;
	var prm="";
	var tmp=new Date();
   prm=SERVER+"?ar0000=*RuiOnA4OGTJIPeSREJLnchfkyX6cV_SmvvolqQY&"+aranda_engine+"&ar0001=sDKWwP6xahbWWZLLf2aSGgZUpDXDvRVBcwfOkHsg&v100="+DE(s0).value+"&v102="+s2+"&v103="+s1;
   prm+="&ar0004="+escape(Math.random())+"-"+escape(tmp.valueOf());
	s4=DE("a00_frame");
	s4.src=prm;
  window.status="Search "+DE(s0).value+" ...";
}

function search_category(s0, s5) {
  // send a category search request to the server
  lang=s5;
  DE("categories").style.display="none";
  DE("products").style.display="";
  // where to show the output
  s1="col2"
  window.status="Search category "+s0+" ...";
  send1("kymoOrofamwmNcmfUXdrJOEcC3VSMH6gJlacX6Cm&v100="+s0+"&v102="+lang+"&v103="+s1);
}

function detail(s0,s1) {

  // send a "view product" request to the server

  var prm="";
  var tmp=new Date();
  prm=SERVER+"/a/eng.exe?ar0000=*RuiOnA4OGTJIPeSREJLnchfkyX6cV_SmvvolqQY&";
  prm+=aranda_engine+"&ar0001="+s0+s1+"&v102="+lang;
  prm+="&ar0004="+escape(Math.random())+"-"+escape(tmp.valueOf());

  nchilds=s0;

  s4=DE("a00_frame");
  s4.src=prm;
  window.status="Retrieving product details ...";
}

function help() {
 detail('xnRQiVickT6rS1YhngdeXYQshmoUTgjtoODZxcVA','&v100=aranda_id&v101=968a1417-fe20-4cbf-b839-8c39d58e0a2c');
}

function help_dealer_search() {
 detail('xnRQiVickT6rS1YhngdeXYQshmoUTgjtoODZxcVA','&v100=aranda_id&v101=d5502f7b-eda8-490d-b4dd-a92a0b45a328');
}



var product_code ="";
var product_title ="";
var product_html ="";
var product_links ="";
var product_page ="";
var product_child_navigation ="";
var product_page_numer ="";
var product_print_content="";
var product_footer =""; 
var product_logo ="http://www.allpa.nl/allpi/jpg/allpa_marine_equipment_logo.jpg";
var product_logo_empty ="http://www.allpa.nl/allpi/jpg/allpa_marine_equipment_logo_empty.jpg";
  

function details_ok() {

  // call back function, called by the returning "view product"

  s2=a00_frame.document.getElementById("aranda_search").innerHTML;
  s1=s2.split("`");

  // the returning page contains 3 elements, title / html / links

  product_code=s1[0];
  product_title=s1[1];
  product_html=s1[2];
  product_links=s1[3];
  product_child_navigation=s1[5];
  product_page_number=s1[4];

  // remove links from html content
  remove_links();
  // remove bullets from links (Alberto)
  remove_bullets();
  
  // Set the path where the documents are downloadable
  f1 = new RegExp("DOCUMENT_PATH","g");
  product_links=product_links.replace(f1,DOCUMENT_PATH);
    // display results in a popup window.

  display_popup() ;
}

function display_popup() {

  var highlight_hint = "";
			switch (lang)
		{
			case 'NLD': highlight_hint = "(de)markeer zoektermen"; break;
			case 'DEU': highlight_hint = "(de)markier Stichworte"; break;
			case 'ENG': highlight_hint = "(un)highlight search phrases";break;
		}

  s3="";

  s3+="<img src='http://www.allpa.nl/allpi/gif/printer.gif' class=p title=' * print * 'onclick='print_me()' style='float:right;'>";

  s3+="<div align='center' style='padding:0px 18px 0px 18px;font-size:1.5em;font-bold=true;color:Navy'>"
  s3+=product_title+"</div>";

  s3+="<table width=100% ><tr><td align='left'>"+product_html+"</td></tr>";
		switch (lang)
		{
			case 'NLD': s3+="<tr><td>allpa catalogus 2010: pagina "+product_page_number+ "</td></tr></table>"; break;
			case 'DEU': s3+="<tr><td>allpa Katalog 2010: Seite "+product_page_number+ "</td></tr></table>"; break;
			case 'ENG': s3+="<tr><td>allpa catalog 2010: page "+product_page_number+ "</td></tr></table>"; break;
		}

  // this is the title & the html content
  product_page=s3;
  
  s3="<img src='http://www.allpa.nl/allpi/png/loep.png' title=' * "+highlight_hint+" * ' onclick='switch_highlight()' style='cursor:pointer; float:right;'>" +s3;
  s3="<img class=close src='http://www.allpa.nl/allpi/gif/close.gif' onclick='close_popup()' style='cursor:pointer; float:right;'>"  +s3;

  s3+="<hr><table width=100%><tr><td align='left'>"+product_links+"</td></tr></table>";

  product_footer="<table width=100% cellspacing=0 cellpadding=0 style='color:#000080;'>"; 
  product_footer+="<tr><td><b>allpa<sup>®</sup></b></td>";
  product_footer+="<td>Kerkenbos 10-15</td>";
  product_footer+="<td>6546 BB Nijmegen</td>";
  product_footer+="<td>T+31-(0)24-377 77 73</td>";
  product_footer+="<td>F+31-(0)24-377 77 70</td>";
  product_footer+="<td>www.allpa.nl</td>";
  product_footer+="<td align=right>info@allpa.nl</td></tr>";
  product_footer+="<tr><td colspan='7'><P align='right'><img src='http://www.allpa.nl/allpi/gif/powered_by.gif'><img src='http://www.allpa.nl/allpi/gif/domani_logo.gif'><img src='http://www.allpa.nl/allpi/gif/aranda_logo.gif'><img src='http://www.allpa.nl/allpi/gif/allpi_logo.gif'>" 
  product_footer+="</td></tr></table>"
  s3+=product_footer;

  s3=highlight(s3);

  s3=products_prevnext()+s3;

  if(product_child_navigation.length>10) {
    f1 = new RegExp("IMG_SRC1_","g");
    product_child_navigation=product_child_navigation.replace(f1,IMG_SRC1_);
    f1 = new RegExp("<!-- child -->","gi");
    s3=s3.replace(f1,product_child_navigation);
  }

	
  
  DE("darkener").style.display="";
  DE("popup").innerHTML=s3;
  DE("popup").style.display="";

  if (nchilds>0) {
    roundAll(nchilds,"rw",".srch3");
  }

  h1=DE("popup").clientHeight;
  DE("darkener").style.height=(h1*1+40)+"px";
  w1=DE("popup").clientWidth;
  DE("darkener").style.width=(w1*1+80)+"px";
  window.status="OK";
}
// toggle highlights...
var highlighted = 0;
function highlight(s3) {
  //
  // to highlight the searched text...
  // substitute "mySearch" with ID of <input> where text is being typed
  s2=s3;
  if(document.getElementById("mySearch") != null) {
  s0=DE("mySearch").value;
  s1=s0.split(" ");
 
  for (i=0;i<s1.length;i++) {
    if (s1[i]>" ") {
      s4=s1[i];
      f1 = new RegExp(s4+"(?![^<]*>)","gi");       
      s2=s2.replace(f1,"<span class=nohighlight>"+s4+"</span>");
    }
  }

  highlighted = 0;

 }
  return s2;
}

function switch_highlight() {
  s3=DE("popup").innerHTML;
  DE("popup").innerHTML="";

  if (highlighted == 1) {
    f1 = new RegExp("class=highlight","gi");
    s3=s3.replace(f1,"class=nohighlight");
    highlighted = 0;
  }
  else {
    f1 = new RegExp("class=nohighlight","gi");
    s3=s3.replace(f1,"class=highlight");
    highlighted = 1;
  }

  DE("popup").innerHTML=s3;
}

var nchilds=0;

function details_childs(s0) {
  nchilds=s0;
  expand_models(a00_frame.document.getElementById("result"));
}

function close_popup() {

  // close the popup

  DE("popup").style.display="none";
  DE("darkener").style.display="none";
}

function print_me() {
 x1=window.open("/allpa/aranda_print.htm","allpa_print");
}

function remove_bullets() {
  s2 = product_links
  i1=s2.indexOf('<LI>',0);
  while (i1>0) {
    s2=s2.replace('<LI>','<BR>');
    i1=s2.indexOf('<LI>',0);
  }
  product_links=s2;
}

function remove_links() {

  s2=product_html;

  var itmcode="";
  var itmmsg="";
  i2=0;
  i1=s2.toUpperCase().indexOf('<A HREF="[ALLPA_WEB_LINK]',0);

  while (i1>0) {

    // Search for closing braket ]
    i2=s2.indexOf(']',i1+2)+1;

    // Search for quote "
    i3=s2.indexOf('"',i1+20);

    // Retrieve Article code
    itmcode=s2.substr(i2,i3-i2)

    // End of <a href tag
    i2=s2.indexOf('>',i3)+1;

    // closing </a> tag
    i3=s2.toUpperCase().indexOf('</A>',i2);

    // message, usually <strong>...
    itmmsg=s2.substr(i2,i3-i2)
 
    // Insert Item Code
    s5="onmouseover="+quote("inf('"+itmcode+"','&v102="+lang+"',event)");
    s5+=" onmouseout="+quote("inf_remove()");
    s5+=" onmousemove="+quote("inf_move(event)");
    
    // SEARCH PREVIOUS WORD (E.G. ART OR ITEM CODE)
    labelX=i1;
    while (labelX>0) {
     if(s2.substr(labelX,1)==">") {
      itmlabel=s2.substr(labelX+1,i1-labelX-2);
      break ;
      }
      else {
      labelX-- ;
      }
    }
    labelX=(labelX>0) ?labelX+1:i1;

    s4="<img src="+quote(IMG_SRC1_+"gif/inf.gif")+" class=p align=middle "+s5+">&nbsp;"+itmlabel+" &nbsp;"+itmmsg;

    s2=s2.substr(0,labelX)+s4+s2.substr(i3+4);

    // Looks for other Links to replace
    // Changed i3 to 0, not knowing exactly the length of the removed string 
    // and sometimes starting to far ahead missing links 
    //i1=s2.toUpperCase().indexOf('<A HREF="[ALLPA_WEB_LINK]',i3);
    i1=s2.toUpperCase().indexOf('<A HREF="[ALLPA_WEB_LINK]',0);
  }

  // for some strange reasons there sometimes is added 'http:///' before the link...
  var itmcode="";
  var itmmsg="";
  i2=0;
  i1=s2.toUpperCase().indexOf('<A HREF="HTTP:///[ALLPA_WEB_LINK]',0);
  while (i1>0) {

    // Search for closing braket ]
    i2=s2.indexOf(']',i1+2)+1;

    // Search for quote "
    i3=s2.indexOf('"',i1+20);

    // Retrieve Article code
    itmcode=s2.substr(i2,i3-i2)

    // End of <a href tag
    i2=s2.indexOf('>',i3)+1;

    // closing </a> tag
    i3=s2.toUpperCase().indexOf('</A>',i2);

    // message, usually <strong>...
    itmmsg=s2.substr(i2,i3-i2)
 
    // Insert Item Code
    s4=itmmsg;
    s2=s2.substr(0,i1)+s4+s2.substr(i3+4);
    
    // now allpi sometimes adds _target=blank...
    s2=s2.replace('target=_blank','');

    // Looks for other Links to replace
    // Changed i3 to 0, not knowing exactly the length of the removed string and sometimes starting to far ahead
    // and sometimes starting to far ahead missing links 
    //i1=s2.toUpperCase().indexOf('<A HREF="HTTP:///[ALLPA_WEB_LINK]',i3);
    i1=s2.toUpperCase().indexOf('<A HREF="HTTP:///[ALLPA_WEB_LINK]',0);
  }
  product_html=s2;
}

function search_result(s0) {

	s2=a00_frame.document.getElementById("aranda_search").innerHTML

	if (s2=='') {

		switch (lang)
		{
			case 'NLD': alert('Geen informatie gevonden'); break;
			case 'DEU': alert('Keine Information gefunden'); break;
			case 'ENG': alert('No information found'); break;
		}
		return;
	}
	
	s1=s2.split("`");

	nrows=8;
	
	i1=1;
	i3=s1.length;
	var nrow=0;
	var npages=0;
	s3="";
	s4="";
	s5="";
	
	while (i1<i3) {
		
		i=s1[i1];
	
		if ((nrow % nrows)==0) {
		
			if(nrow==0) {
				s3+="<div style='display:none;' class=pag id=pag"+npages+">"+result_ini;
			}
			else	{
				npages++;
				s3+=result_end+"</div><div style='display:none;' class=pag id=pag"+npages+"> "+result_ini;
			}
		}
		nrow++;	
	
		s2=Nflds[i];
		s4=models[i];
	
		i1++;

		for (j=0;j<s2;j++) {
			f1 = new RegExp("@VIB_"+j+"@","g");
			s4=s4.replace(f1,s1[i1+j*1]);
		}

		s3=s3+s4;
		i1=i1+s2*1;
	}
	
	f1 = new RegExp("IMG_SRC1_","g");
	s3=s3.replace(f1,IMG_SRC1_);
   f1= new RegExp("DOCUMENT_PATH","g");
   s3=s3.replace(f1,DOCUMENT_PATH);
	
	s3=s3+result_end;
	if(npages>0) 
	{
		s3+="</div>";
	}
	
	s4="<div>";
	s5="<div>";
	for (i=0;i<=npages;i++) {
		s4+="<button id=button_top_"+i+"  class='p' style='color:#FFFFFF;border:none;background-color:transparent;' onclick='pag("+i+","+npages+")'>"+(i+1)+"</button>"+"&nbsp;";
		s5+="<button id=button_bottom_"+i+"  class='p' style='color:#AEBBD5;border:none;background-color:transparent;' onclick='pag("+i+","+npages+")'>"+(i+1)+"</button>"+"&nbsp;";
	}
	
	s5+="<img style='float:right' src='http://www.allpa.nl/allpi/gif/allpi_logo_xsmall.gif'><img style='float:right' src='http://www.allpa.nl/allpi/gif/aranda_logo_xsmall.gif'><img style='float:right' src='http://www.allpa.nl/allpi/gif/domani_logo_xsmall.gif'><img style='float:right' src='http://www.allpa.nl/allpi/gif/powered_by.gif'>" 
	s4+="</div>";
	s5+="</div>";
	
	s3=s4+s3+s5;
	s5="<div style='margin-top:0;height:2;width:610;'></div> ";
	s3=s5+s3;
	
	DE(s0).innerHTML=s3;
	
	pag(0,npages);
	
	create_product_list();
	
	window.status="OK";
   
}

function pag(s0,s1) {
	
	for (i=0;i<=s1;i++) {
		
		s2=DE("pag"+i);
		
		if (i==s0) {
			s2.style.display="";
		}
		else {
			s2.style.display="none";
		}
		s2=DE("button_top_"+i);
		
		if (i==s0) {
			s2.style.color="red";
		}
		else {
			s2.style.color="#FFFFFF";
		}
			s2=DE("button_bottom_"+i);
		if (i==s0) {
			s2.style.color="red";
		}
		else {
			s2.style.color="#AEBBD5";
    }
  }
}

var products=new Array();
function create_product_list() {
  // product list
  s2=a00_frame.document.getElementById("aranda_prd_list").innerHTML
  s1=s2.split("`");

  products=new Array();

  i1=1;
  i3=s1.length;

  for (i=1;i<i3;i=i+3) {
    products[i1]=new product(s1[i],s1[i+1],s1[i+2]);
    i1++;
  }
  last_scroll_list="";
}

function product( id, key, desc)
{
  this.length = 3; // Numero di proprietà dell'oggetto, esclusa la proprietà this.
  this.id = id;
  this.key=key;
  this.desc=desc;
}

var product_curr=0;
var product_prev=0;
var product_next=0;
function product_indexof() {
  product_curr=0;
  product_prev=0;
  product_next=0;
  i3=products.length;

  i1=1;
  while (i1<i3) {
    if (products[i1].key==product_code) {
      product_curr=i1;
      i1=i3;
    }
    i1++;
  }

  product_prev=(product_curr>1) ? product_curr-1:0;
  product_next=(product_curr<(i3-1)) ? product_curr+1:0;
}

var last_scroll_list="";
function products_prevnext(s3) {
  product_indexof();

  s2="";

  if(product_curr==0) {
    s2=last_scroll_list;
  }
  else {
    if (product_prev>0) {
      s3=product_scroll(product_prev)
      s2+="<img src='"+IMG_SRC1_+"gif/allpa-previous.gif' style='float:left;' "+s3+">";
    }
    else {
		s2+="<img src='"+IMG_SRC1_+"gif/allpa-empty.gif' style='float:left;'>";	     
     }

    if (product_curr>0) {
    }
    if (product_next>0) {
      s3=product_scroll(product_next)
      s2+="<img src='"+IMG_SRC1_+"gif/allpa-next.gif' class=p style='float:left;' "+s3+">";
    }
     else {
		s2+="<img src='"+IMG_SRC1_+"gif/allpa-empty.gif' style='float:left;'>";	     
     }

    last_scroll_list =s2;
  }
  return s2;
}

function product_scroll(s0) {
  s4="";
  s4="class='p' title=' * "+products[s0].desc+" *' onclick="+quote("detail('xnRQiVickT6rS1YhngdeXYQshmoUTgjtoODZxcVA','&v100="+products[s0].id+"&v101="+products[s0].key+"')");
  return s4;
}

function load_model_1(s2) {
	
	s1=document.getElementById("f_m0").innerHTML;
	lang=s2;
	load_model_common();
	DE("mySearch").style.display=""	
}
function show_large_category_image(div, cat, img, div_small)	
{
	DE(cat).src=img;
	DE(div).style.display="";
}

function hide_small_category_image(div)	
{
	DE(div).style.display="none";			
}

function geocoder_show_2(s0) {

  markers_num=s0;
  markers = new Array();

  for (i=1;i<=s0;i++) {

    markers.push( {
      code: "",
      coord:0,
      name:"",
      color:"80a0ff"
    }
    );

    markers[i-1].code=String.fromCharCode(48+i);
    markers[i-1].coord=new GLatLng(s2,s3);
    markers[i-1].name=DE("msg"+i).innerHTML;

  }

  bounds = new GLatLngBounds;
  markers_num=s0;
  allpa_popup_dealer(s0);
if (s0>0)
  {
  display_address(1);
  }
}

function allpa_popup_dealer(s0) {  
if (s0>0)
{
  DE("darkener").style.display="";
  DE("popup").style.display="";
  h1=DE("popup").clientHeight;
  DE("darkener").style.height=(h1*1+40)+"px";
  w1=DE("popup").clientWidth;
  DE("darkener").style.width=(w1*1+80)+"px";
  
}
else
{
		DE("popup").style.display="none";
		DE("darkener").style.display="none";
		switch (lang)
		{
			case 'NLD': alert('Geen dealers gevonden.'); break;
			case 'DEU': alert('Keine Händler gefunden.'); break;
			case 'ENG': alert('No dealer found.');break;
		}
}
}
