var acePopupWindow=null;
var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;

function prepMap(Lat,Lng,moduleType){
	myModuleName = "";
	if(moduleType == 1){
		myModuleName = "accommodation_items";
	}else if(moduleType == 2){
		myModuleName = "accommodation_hotels";
	}

	setOverlayStyle();
	var objWrapper = setWrapperStyles();
	objWrapper.style.display = "block";
	
	var link = "http://" + window.location.host + "/ajax.php?grandparent=site&m="+myModuleName+"&a=180&type=popup&Lat="+Lat+"&Lng="+Lng;
	new Ajax.Updater("wrMap", link, 
	    { evalScripts: true,
		  onLoaded: function () {

	      }
	    }
	);
	
	return true;
}

function insurance(){
    if (document.all['INSURANCE'].checked==true){
       document.getElementById('ensurancediv').style.visibility='visible';
       document.getElementById('noensurancediv').style.visibility='hidden';
    } else {
       document.getElementById('ensurancediv').style.visibility='hidden';
       document.getElementById('noensurancediv').style.visibility='visible';
    }
}
function acePopup(mypage,myname,w,h,pos,infocus)
{
        if(pos=='random')
                {
                        LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
                        TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
                }
        if(pos=='center')
                {
                        LeftPosition=(screen.width)?(screen.width-w)/2:100;
                        TopPosition=(screen.height)?(screen.height-h)/2:100;
                }
        else
                if((pos!='center' && pos!='random') || pos==null){LeftPosition=100;TopPosition=100;}
                        settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,dependent=no';
        acePopupWindow=window.open('',myname,settings);
        if(infocus=='back')
        {
                acePopupWindow.blur();
                acePopupWindow.location=mypage;
                acePopupWindow.blur();
        }
        else
                acePopupWindow.location=mypage;
 return false;
}



function openMess(user)
{
        myname='mess_window'+user;
        LeftPosition=20;
        TopPosition=50;
        w=300;
        h=400;
        settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no';
        PopupWindow=window.open('',myname,settings);
        PopupWindow.location="messenger.php?action=runmess&mode=app&id="+user;
}


function addBookmark()
{
        window.external.addFavorite('http://stuzim.com.il/', 'stuzim.com.il');
        return false;
}

function openInfo(what, id, wi, he)
{
        myname='Preview_'+ what;
        LeftPosition=(screen.width)?(screen.width-wi)/2:100-wi;
        TopPosition=(screen.height)?(screen.height-he)/2:100-he;
        w=wi+100;
        h=he+200;
        settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no';
        PopupWindow=window.open('',myname,settings);
        PopupWindow.location="info.php?action=" + what + "&id=" + id;
}

function cleaner(frm) {
        for(i=0;i<(frm.elements.length-1);i++){
                if( (frm.elements[i].type == "radio") || (frm.elements[i].type == "checkbox") ) frm.elements[i].checked=0;
                if( (frm.elements[i].type == "select") ) frm.elements[i].selected=0;
                if( (frm.elements[i].type == "text") ) frm.elements[i].value="";
        }
}

function setOverlayEvent(objWindow){
	var id = "overlayFullScreenMap";
	var objOverlay = document.getElementById(id);
	objOverlay.onclick = function (){
		if(objWindow)
			objWindow.focus();
	}
	
	 window.opener.onclick = function (){
		if(objWindow)
			objWindow.focus();
	}
}

function disableOverlay(){
	var id = "overlayFullScreenMap";
	var objOverlay = document.getElementById(id);
	objOverlay.style.display = "none";
}

function setWrapperStyles(){
	var objWrapper = document.getElementById("wrMap");
	var curDocWidth = 0, curDocHeight = 0;
	var documentAreaSize = getDocumentAreaSize();
	if(documentAreaSize.length > 1){
		curDocWidth = documentAreaSize[0];
		curDocHeight = documentAreaSize[1];
	}
	
	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		objWrapper.style.width = "930px";
		objWrapper.style.height = "480px";
		objWrapper.style.position = "absolute";
		objWrapper.style.zIndex = "6";
		objWrapper.style.padding = "10px";
		objWrapper.style.left = "300px"
		if(curDocWidth){
			objWrapper.style.left = (curDocWidth - 960)/2 + "px";
		}
		objWrapper.style.top = "200px";
		if(curDocHeight){
			objWrapper.style.top = (curDocHeight - 480)/2 + "px";
		}
		browser = "IE6";
	}else{
		if(ie7){		
			objWrapper.style.position = "fixed";
			objWrapper.style.top = 0;
			objWrapper.style.left = 0;
			objWrapper.style.backgroundColor = "#FFFFFF";
			objWrapper.style.border = "1px solid #D4D4D4";
			objWrapper.style.zIndex = 6;
			objWrapper.style.width = "915px";
			objWrapper.style.height = "460";
			objWrapper.style.padding = "10px";
			objWrapper.style.marginLeft = "300px";
			if(curDocWidth){
				objWrapper.style.marginLeft = (curDocWidth - 915)/2 + "px";
			}
			objWrapper.style.marginTop = "200px";
			if(curDocHeight){
				objWrapper.style.marginTop = (curDocHeight - 460)/2 + "px";
			}
		}else{
			objWrapper.style.width = "875px";
			objWrapper.style.height = "460px";
			objWrapper.style.padding = "10px";
			objWrapper.style.border = "1px solid #D4D4D4";
			objWrapper.style.marginLeft = "300px";
			if(curDocWidth){
				objWrapper.style.marginLeft = (curDocWidth - 875)/2 + "px";
			}
			objWrapper.style.marginTop = "200px";
			if(curDocHeight){
				objWrapper.style.marginTop = (curDocHeight - 460)/2 + "px";
			}
		}
	}
	return objWrapper;
}

function setLoadingStyle(){
	var id = "wrapperLoading";
	var objLoading = document.getElementById(id);
	
	var curDocWidth = 0, curDocHeight = 0;
	var documentAreaSize = getDocumentAreaSize();
	if(documentAreaSize.length > 1){
		curDocWidth = documentAreaSize[0];
		curDocHeight = documentAreaSize[1];
	}
	
	if(ie7){		
		objLoading.style.position = "fixed";
		objLoading.style.top = 0;
		objLoading.style.left = 0;
		objLoading.style.zIndex = 6;
		objLoading.style.padding = "10px";
		
		objLoading.style.marginLeft = "300px";
		if(curDocWidth){
			objLoading.style.marginLeft = (curDocWidth - 50)/2 + "px";
		}

		objLoading.style.marginTop = "200px";
		if(curDocHeight){
			objLoading.style.marginTop = (curDocHeight - 10)/2 + "px";
		}
	}else{	
		if(curDocWidth){
			objLoading.style.left = (curDocWidth - 50)/2 + "px";
		}
		
		if(curDocHeight){
			objLoading.style.top = (curDocHeight - 10)/2 + "px";
		}
	}
	
	objLoading.style.display = "block";
}

function setOverlayStyle(){
	var id = "overlayFullScreenMap";
	var objOverlay = document.getElementById(id);
	
	var curDocWidth = 0, curDocHeight = 0;
	var documentAreaSize = getDocumentAreaSize();
	if(documentAreaSize.length > 1){
		curDocWidth = documentAreaSize[0];
		curDocHeight = documentAreaSize[1];
	}

	var curPageScrollX = 0, curPageScrollY = 0;
	var pageScroll = new Array();
	
	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		objOverlay.style.width = "960px";
		objOverlay.style.height = "480px";
		objOverlay.style.left = "300px";
		if(curDocWidth){
			objOverlay.style.left = (curDocWidth - 960)/2 + "px";
		}
		objOverlay.style.top = "200px";
		if(curDocHeight){
			objOverlay.style.top = (curDocHeight - 480)/2 + "px";
		}

		browser = "IE6";
	}else{
		if(ie7){
			objOverlay.style.filter = 'alpha(opacity=28)';
			objOverlay.style.position = "fixed";
			objOverlay.style.top = 0;
			objOverlay.style.left = 0;

			pageScroll = getPageScroll();
			if(pageScroll.length > 1){
				curPageScrollX = pageScroll[0];
				curPageScrollY = pageScroll[1];
			}

			objOverlay.style.width = "100%";
			objOverlay.style.height = curDocHeight + curPageScrollY + "px";
			objOverlay.style.bottom = curPageScrollY + curDocHeight + "px";

			window.onscroll = function(){
				pageScroll = getPageScroll();
				if(pageScroll.length > 1){
					curPageScrollX = pageScroll[0];
					curPageScrollY = pageScroll[1];
				}
				objOverlay.style.height = curDocHeight + curPageScrollY + "px";
			}
		}else{
			objOverlay.style.width = "100%";
			objOverlay.style.height = "100%";
		}
	}
		
	objOverlay.style.opacity = 0.5;
	objOverlay.style.mozOpacity = 0.5;
	objOverlay.style.khtmlOpacity = 0.5;
	objOverlay.style.display = "block";
}

function getDocumentAreaSize() {
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		return [ myWidth, myHeight ];
	}

	function getPageScroll(){
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;
		}

		arrayPageScroll = new Array(xScroll,yScroll)
		return arrayPageScroll;
	}
	
	function closeFullScreenMap(type){
		var objOverlay = document.getElementById("overlayFullScreenMap");
		objOverlay.style.display = "none";
		
		var objWrapper = document.getElementById("wrMap");
		objWrapper.style.display = "none";
			
		if(type != "popup"){
			map.clearOverlays();
		}
		
		if(objWrapper)
			objWrapper.innerHTML = "";

		return true;
	}