var lang=0;
var mbsize=60;
var currpage=-1;
var menu=new Array();
var FF=0; var Chrome=0;
/*********************************************************************************************************
 **********               LoadData() - AJAX GET data loader                                     **********
 *********************************************************************************************************/
function LoadData(Filehref)
{
var textfile='';
  try {textfile=new ActiveXObject('Msxml2.XMLHTTP');}
  catch (e)
  {
    try {textfile=new ActiveXObject('Microsoft.XMLHTTP');}
    catch (e)
    {
      try {textfile=new XMLHttpRequest();}
      catch (e)
      {return "<p>error</p>";}
    }
  }
textfile.open('GET', Filehref, false);
textfile.send(null);
return textfile.responseText;
}

/*********************************************************************************************************
 **********     getFront(where,what) getEnd(where,what) - substring parsing functions           **********
 *********************************************************************************************************/
function getFront(mainStr, searchStr)
{
  foundOffset = mainStr.indexOf(searchStr);
  if (foundOffset == -1) {
  foundOffset=mainStr.indexOf('"');
    if (foundOffset == 0) {
    mainStr=mainStr.substring(1,mainStr.length);}
  foundOffset=mainStr.indexOf("'");
    if (foundOffset == 0) {
    mainStr=mainStr.substring(1,mainStr.length);}
    return mainStr;
}
  work=mainStr.substring(0,foundOffset);
  foundOffset=work.indexOf('"');
    if (foundOffset == 0) {
    work=work.substring(1,work.length);}
  foundOffset=work.indexOf("'");
    if (foundOffset == 0) {
    work=work.substring(1,work.length);}
return work;
}
function getEnd(mainStr,searchStr)
{
  foundOffset = mainStr.indexOf(searchStr);
   if (foundOffset == -1) {
     return "";
   }
  return mainStr.substring(foundOffset+searchStr.length, mainStr.length);
}
/*********************************************************************************************************
 **********     getFront(where,what) getEnd(where,what) - substring parsing functions           **********
 *********************************************************************************************************/


function loadPage(pageno) {
	   	var B=(function x(){})[-5]=='x'?'FF':(function x(){})[-6]=='x'?'FF':/a/[-1]=='a'?'FF':'\v'=='v'?'IE':/a/.__proto__=='//'?'Saf':/s/.test(/a/.toString)?'Ch':/^function \(/.test([].sort)?'Op':'Unknown';
	   	 if (B=="FF") FF=1;
	     if (B=="Ch") Chrome=1;

   if (pageno==undefined) {

     var menuline=LoadData("php/menu.php?r="+Math.random());
     for (var i=0;i<6;i++) {
		 menu[i]=new Array();
		 for (var j=0;j<6;j++) {
		var items=getFront(menuline,",");
		menuline=getEnd(menuline,",");
		menu[i][j]=items;
		 }
	 }

   }
	if (menu[lang]){
   		for (var i=0;i<6;i++) {
	   	document.getElementById("b"+i).innerHTML=menu[lang][i];
   		}
	}
	if (pageno!=undefined) currpage=pageno;
	else currpage=-1;
   contentLoad();
   redrawPage() ;
}
function redrawPage() {
//  alert ("Redraw");
   wx=document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
   wy=document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
  if (wy<600) {
	   document.getElementById("css").href = "../css/enbs.css";
	   mbsize=30;
  }
  else {
	  document.getElementById("css").href = "../css/enb.css";
	  mbsize=60;
  }
  for (var i=0;i<5;i++) {
	 obj=document.getElementById("p"+i);
	 swapB(obj,i,0);
  }
   var obj=document.getElementById("datafield");
   var objc=document.getElementById("content");
   objc.style.background="none";
   if (mbsize==30)  {obj.style.width=wx-220;
      objc.style.width=wx-252; }
   else { obj.style.width=wx-260;
   objc.style.width=wx-294;
	}
   obj.style.height=wy-182;
   objc.style.height=wy-214;

}



function swapB(obj,ind,status) {
//	 alert (obj.id);
   var shift=mbsize*2*ind;
   if (status==1)  {shift=shift+mbsize;}
   if (mbsize==60)
   obj.style.background='url(images/mb.png) no-repeat 0px -'+shift+'px';
   else
   obj.style.background='url(images/mb30.png) no-repeat 0px -'+shift+'px';
}


function openLSelector(){
	document.getElementById("langselector").style.display="block";

}
function selectLang (id) {

	lang=id;
	document.getElementById("lang").style.background="url(images/flag.gif) no-repeat 0px -"+(18*id)+"px";
	document.getElementById("langselector").style.display="none";
	loadPage(currpage);
}

function contentLoad() {
	var text=LoadData("php/pagesel.php?lang="+lang+"&page="+currpage+"&r="+Math.random());
	document.getElementById("content").innerHTML=text;

}
/*********************************************************************************************************
 **********                                                                                     **********
 **********     showGmap  -                               **********
 **********                                                                                     **********
 *********************************************************************************************************/

function showGmap() {
	  var baseIcon = new GIcon(G_DEFAULT_ICON);
      if (GBrowserIsCompatible()) {
      document.getElementById("content").innerHTML=
      "<div style='height:10%;width:100%;'>20050 Winter Ln,Saratoga,CA 95070</div><div style='width:100%;height:90%;' id=content2></div>";
      
      
      
 panelId="content2";
        var map = new GMap2(document.getElementById(panelId));
         var baseIcon = new GIcon(G_DEFAULT_ICON);
         baseIcon.image = "images/gicon.png";
         baseIcon.iconSize = new GSize(50, 28);
         baseIcon.imageMap=[0,0,0,28,50,28,28,0];
//		baseIcon.shadow = "images/template/gshadow.png";
		         baseIcon.shadowSize = new GSize(50, 28);
var center=new GLatLng( 37.278714,-122.02510); //mi_lat, mi_lng);
        map.setCenter(center, 14);
        var marker = new GMarker(center, { icon:baseIcon });

 GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml("20050 Winter line,<br>Saratoga,<br>CA95070");} );
 map.addOverlay(marker);
         var mapTypeControl = new GMapTypeControl();
         var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
         var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
 //       map.addControl(mapTypeControl, topRight);
         map.addControl(new GSmallMapControl());
      }
}

