//Rotem DAHAN 20038 +a little bit of extracted code
// 

var W3CDOM = (document.createElement && document.getElementsByTagName);	
if (!W3CDOM) { alert ('Your Browser doesn\'t support the W3C standarts.If this page doesn\'t display properly, please disable Javascript to access all the page functionnalities'); }
var popcount= 0; //will help to know how many time one has clicked on a popupform

//******START AT WINDOW ONLOAD*************************************************************************************************
function init() {
	
	if(navigator.userAgent.indexOf('MSIE 6.0') != -1){correctPNG();}
    
	///code to reset the search box on load -if it is there
	var searchbox=document.getElementById('searchbox');	
	if (searchbox) { restart ();}
	//
	
var districts=document.getElementById('districts'); 
	if (districts)
	{setDistricts();}
	
var mapclick = document.getElementById('mapclick');
if(mapclick){
mapclick.onclick = popupMap;}

var mygallery= document.getElementById('myGallery');

if (mygallery==""){

var all_links = document.getElementsByTagName("a");
var all_areas = document.getElementsByTagName("area");


if(all_links) {
for (var l = 0; l < all_links.length; l++)
{all_links[l].onclick = pleasewait;}
}

if(all_areas) {
for (var area = 0; area < all_areas.length; area++)
{all_areas[area].onclick = pleasewait;}    }
             }


}




function popupMap () {
	var map = document.getElementById('mapcontainer'); //get all the forms
	var mapheight=map.clientHeight;
	//CALCULATE CLIENT'S WINDOW SIZE ANS SCROLL POSITION 
	var d=document;w=window; 
	var db=!d.documentElement.clientWidth?d.body:d.documentElement;  // ie6 or ie7/win according to doctype
	//window infos
	var scrollW=w.pageXOffset?w.pageXOffset:db.scrollLeft;		// scroll width: unnecessary for now
	var scrollH=w.pageYOffset?w.pageYOffset:db.scrollTop; 		// scroll Height 
	var windowW=w.innerWidth?w.innerWidth:db.clientWidth; 		// window Width 
	var windowH=w.innerHeight?w.innerHeight:db.clientHeight;	// window Height 
  	//now we calculate the X and Y position of our FORM divs
	XPos=(windowW/2)-(550);  // that is: half of the client window's width MINUS half of a form's with
	YPos=scrollH+((windowH-mapheight)/2); // your turn to work!try to understand this positionning ;)..it puts the form in the middle
	
popcount++; //increment the counter for our popupform
// now positionning the FORM  thanks to dd.elements defined in WZ_dragdrop.js 
//var id=dd.elements['mapcontainer']; 
//id.setZ(100);//set Z-index for the form to be on top 
if (popcount < 2) {
	//id.moveTo(XPos,YPos);
	map.style.left=""+XPos+"px"; 
	map.style.top=""+YPos+"px";
	} //move the PopupForm to the center only he first time we click
map.style.visibility = (map.style.visibility == 'visible') ? 'hidden' : 'visible' ;	  

//INITIATE CLICK RELATE CLOSEPOPUPIMG
var closemap = document.getElementById('closemap');
closemap.onclick = popoffMap;
}

function popoffMap() {
	var map = document.getElementById('mapcontainer');
	map.style.visibility= 'hidden';
	this.style.visibility = 'inherit';
	}

function setDistricts() {
	
//CALCULATE CLIENT'S WINDOW SIZE ANS SCROLL POSITION 
	var d=document;w=window; 
	var db=!d.documentElement.clientWidth?d.body:d.documentElement;  // ie6 or ie7/win according to doctype
	//window infos
	var windowH=w.innerHeight?w.innerHeight:db.clientHeight;	// window Height 	
	var districtsheight=windowH-160; 
	
	var districts=document.getElementById('districts');
	if (districts) {
	districts.style.height=""+districtsheight+"px"; 
	districts.style.maxHeight=""+districtsheight+"px";
	districts.style.overflow="auto";
	window.location.href='#choice';}
	
	
	
}




function pleasewait() {
	var waitdiv = document.getElementById('pleasewait');
	var formheight=300;
	//CALCULATE CLIENT'S WINDOW SIZE ANS SCROLL POSITION 
	var d=document;w=window; 
	var db=!d.documentElement.clientWidth?d.body:d.documentElement;  // ie6 or ie7/win according to doctype
	//window infos
	var scrollW=w.pageXOffset?w.pageXOffset:db.scrollLeft;		// scroll width: unnecessary for now
	var scrollH=w.pageYOffset?w.pageYOffset:db.scrollTop; 		// scroll Height 
	var windowW=w.innerWidth?w.innerWidth:db.clientWidth; 		// window Width 
	var windowH=w.innerHeight?w.innerHeight:db.clientHeight;	// window Height 
  	//now we calculate the X and Y position of our FORM divs
	XPos=(windowW/2)-(300/2);  // that is: half of the client window's width MINUS half of a form's with
	YPos=scrollH+((windowH-formheight)/2); // your turn to work!try to understand this positionning ;)..it puts the form in the middle

waitdiv.style.left=XPos;
waitdiv.style.top=YPos;

setTimeout(function() {
	waitdiv.style.visibility='visible';}, 5000); //5 seconds wait

}
	
	
	
	function correctPNG()
// correctly handle PNG transparency in Win IE 5.5 or higher.
// ce script relativement commun sur internet a en l'occurence été récupéré depuis ce site : http://homepage.ntlworld.com/bobosola/
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
   
   //VERY IMPORTANT FONCTION //Extracted from nifty.js THANK YOU!
function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

function ShowHideHelp(number) {  //ex: <div class='explanation' id='explanation-help1'></div>

var help=document.getElementById('explanations'+number);
help.style.visibility= help.style.visibility=='visible' ? 'hidden' : 'visible' ;

var closehelp= help.firstChild; var closename= closehelp.className;
	while ( closename!= 'closehelp') { closehelp=closehelp.firstChild;closename= closehelp.className; }//exemple <div 
	
closehelp.onclick= function() {help.style.visibility= help.style.visibility=='visible' ? 'hidden' : 'visible' ;} ;

	
}
   
   window.onload = init;

/*$(document).ready( function() {
	init();
});*/  

