﻿function loadGM() { 
    if (GBrowserIsCompatible())
    {
        var my_GMap1 = new GMap2(document.getElementById("map"));
        gobalMAP = my_GMap1;
        var point = new GLatLng(40.263727, -3.835795);
        var centerpoint = new GLatLng(40.2655, -3.835795);
        var marker = new GMarker(point);
        my_GMap1.setCenter(centerpoint, 16, G_NORMAL_MAP);
        my_GMap1.panTo(centerpoint);
        my_GMap1.addOverlay(marker);
        var WINDOW_HTML = "<table cellpadding='0' cellspacing='0' border='0' style='font-family: Arial; font-size: 11px; color: #4F5473;'>" +
                          "<tr><td><strong>CASTFLOW VALVES, S.L.</strong></td></tr>" +
                          "<tr><td><img src='Images/FabricaGM.jpg' style='width: 165px; height: 120px;' /></td></tr>" +
                          "</table>";
        var WINDOW_HTML = "<div style='text-align:left; font-family:Arial; font-size: 10pt;font-weight: bold;padding-left: 3px; color:#4F5473'>\n" +
                          "  <img src='Images/FabricaGM.jpg' align='left' style='text-align:left; width: 165px; height: 120px; margin-right:20' />CASTFLOW VALVES, S.L.</div><div style='text-align:left; font-family:Arial; font-size: 8pt;font-weight: normal;padding-left: 3px; color:#4F5473'>Calle Dalia nº 17. Polígono Industrial El Lomo<br />28970 - Humanes de Madrid (Madrid)<br /><br />\n" +
                          "  <strong style='margin-right:9px; text-align:left'>Teléfono:</strong>(+34) 916 043 045<br /><strong style='margin-right:40'>Fax:</strong>(+34) 916 043 046<br /><br />\n" +
                          "  <strong style='margin-right:23px;'>E-Mail:</strong> <a class='classLink' href='mailto:castflow@castflow.com'>castflow@castflow.com</a>\n" +
                          "</div>\n";
                          
        GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(WINDOW_HTML);});
        marker.openInfoWindowHtml(WINDOW_HTML);
        my_GMap1.enableDoubleClickZoom();
        my_GMap1.enableContinuousZoom();
        my_GMap1.addControl(new GLargeMapControl());
        my_GMap1.addControl(new GScaleControl());
        my_GMap1.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(3, 3)));
    }
}

function handle(delta) {
    if (delta < 0)
{
        gobalMAP.zoomOut();
    }
    else
    {
        gobalMAP.zoomIn();
    }
}

function wheel(event){
    var delta = 0;
    if (!event) event = window.event;
    if (event.wheelDelta) {
	    delta = event.wheelDelta/120; 
	    if (window.opera) delta = -delta;
    } else if (event.detail) {
	    delta = -event.detail/3;
    }
    if (delta)
	    handle(delta);
        if (event.preventDefault)
                event.preventDefault();
        event.returnValue = false;
}

function unselectableObjects()
{
    for (i=0; i < document.all.length; i++) 
    {
        obj = document.all[i];
        if (obj.tagName != "INPUT") obj.setAttribute("unselectable", "on");
//        if ((obj.tagName != "A") && (obj.tagName != "AREA") && (obj.tagName != "IMG") && (obj.tagName != "TD") && (obj.className != "handPoint") && (obj.style.cursor != "pointer"))
//            obj.style.cursor = "default";
    }
}

function hidestatus()
{
    window.status="CASTFLOW VALVES, S.L.";
    window.setTimeout("hidestatus()", 1);
}

function onContextMenu(e) 
{
    return false;
}

function mouseDown(e) 
{
    return false;
}

/* MENU CONTEXTUAL */

var about="...";
var rmenu = new Array(
//"Atras","history.back();",
//"Adelante","history.forward();",
//"Actualizar","history.go(0);",
//"hr",
"Acerca de...","alert('CASTFLOW VALVES, S.L.');"
); 

var tid;
function isvis()
{
    var els=getCM();
    if(els) tid=els.style ? els.style.visibility : els.visibility;
} 

function getCM()
{
    var d=document, el=null;
    if(d.all){el=d.all.contextMenu}
    else if(d.getElementById){el=d.getElementById("contextMenu")}
    else if(d.layers){el=d.layers["contextMenu"]}
    return el;
} 

function hideMenu() 
{
    var el=getCM(); if(!el) return;
    if(el.style) el.style.visibility="hidden";
    else el.visibility="hide";

    popupTop = (document.getElementById("ModalPopupExtender_foregroundElement")) ? document.getElementById("ModalPopupExtender_foregroundElement").offsetTop : 0;
    if (popupTop > 0)
    {
        newTop = parseInt(Math.round((window.screen.availHeight / 2) - (document.getElementById("ModalPopupExtender_foregroundElement").clientHeight / 2) - 72 + WebForm_GetScrollY()));
        document.getElementById("ModalPopupExtender_foregroundElement").style.top = newTop + "px";
    }
} 

function showMenu (evt) 
{
    if(!evt) evt = window.event || {};
    var d=document;
    var e = {x:evt.x || evt.pageX || 0, y:evt.y || evt.pageY || 0};
    var CM = getCM(); 

    if(CM)
    {
        var clientDim = (d.body && typeof d.body.clientWidth!="undefined") ? {w:d.body.clientWidth, h:d.body.clientHeight} : {w:window.innerWidth, h:window.innerHeight};
        var CMDim = {w:CM.offsetWidth||0, h:CM.offsetHeight || 0};
        var shift = {x:(clientDim.w-e.x<CMDim.w) ? CMDim.w : 0, y:(clientDim.h-e.y<CMDim.h) ? CMDim.h : 0};
        var scroll = (d.body && typeof d.body.scrollLeft!="undefined") ? {x:d.body.scrollLeft, y:d.body.scrollTop} : {x:window.pageXOffset, y:window.pageYOffset}; 

        if(CM.style)
        {
            CM.style.left = ((scroll.x+e.x-shift.x)||0) + "px";
            CM.style.top = ((scroll.y+e.y-shift.y)||0) + "px";
            CM.style.visibility = "visible";
            return false;
        } 
        else 
        {
            if(evt.which == 3) 
            {
                CM.left = e.x;
                CM.top = e.y;
                CM.visibility = "show";
                return false;
            } 
            else 
            {
                hideMenu();
            }
        }
    } 
    return true;
} 

if(typeof window.onscroll != "undefined")
window.onscroll=hideMenu; 

//ie, gecko
document.onmousedown = isvis;
document.onmouseup = hideMenu;
document.oncontextmenu = showMenu; 

if(document.captureEvents && !window.opera && document.layers) 
{
    //nn4, exclude opera and gecko
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown = function(evt) 
        {
            isvis(evt);
            return showMenu(evt);
        }
} 
else 
{
    if(window.opera) 
    {
        //Opera
        document.onmouseup=null;
        document.onmousedown = function(evt)
            {
                if(evt && evt.ctrlKey)
                {
                    isvis(evt);
                    return showMenu(evt);
                }
                else 
                {
                    hideMenu(evt);
                }
            }
    } 
}

function writemenu()
{
    var txt = "<div id=\"contextMenu\">"+
              "<table border=\"0\" cellpadding=\"0\" "+
              "cellspacing=\"0\">";
    for(var i=0;i<rmenu.length; i+=2)
    {
        if(rmenu[i]=="hr") 
        {
            txt+="<tr><td><hr width='95%'><\/td><\/tr>";
            i--;
        } 
        else 
        {
            txt+="<tr>"+
                 "<td>"+
                 "<a href=\"#\" "+
                 "onclick=\"" + rmenu[i+1] + ";return false\" "+
                 "class=\"menoff\" "+
                 "onmouseover=\""+
                 "this.className='menon';"+
                 "return true\" "+
                 "onmouseout=\""+
                 "this.className='menoff';"+
                 "return true\">"+
                 rmenu[i]+
                 "<\/a>"+
                 "<\/td>"+
                 "<\/tr>";
        }
    } 
    document.write(txt+"<\/table><\/div>");
}

/* POPUP */

var __nonMSDOMBrowser = (window.navigator.appName.toLowerCase().indexOf('explorer') == -1);
        
function WebForm_GetScrollX() {
    if (__nonMSDOMBrowser) {
        return window.pageXOffset;
    }
    else {
        if (document.documentElement && document.documentElement.scrollLeft) {
            return document.documentElement.scrollLeft;
        }
        else if (document.body) {
            return document.body.scrollLeft;
        }
    }
    return 0;
}

function WebForm_GetScrollY() {
    if (__nonMSDOMBrowser) {
        return window.pageYOffset;
    }
    else {
        if (document.documentElement && document.documentElement.scrollTop) {
            return document.documentElement.scrollTop;
        }
        else if (document.body) {
            return document.body.scrollTop;
        }
    }
    return 0;
}


function setImagePopup(image, url, w, h, tittle) {

    w = w + 20;
    h = h + 25;
    popupLeft = parseInt(Math.round((window.screen.availWidth / 2) - (w / 2) - 15));
    popupTop = parseInt(Math.round((window.screen.availHeight / 2) - (h / 2) - 100 + WebForm_GetScrollY()));

    document.getElementById("popupContent").src = url;
    document.getElementById("popupContent").style.height = h + "px";
    document.getElementById("popupContent").style.width = w + "px";

    document.getElementById("DIV1").style.width = w + "px";
    document.getElementById("tituloPopup").style.width = w + "px";
    document.getElementById("ModalPopupExtender_foregroundElement").style.position = 'absolute';
    document.getElementById("ModalPopupExtender_foregroundElement").style.left = popupLeft + "px";
    document.getElementById("ModalPopupExtender_foregroundElement").style.top = popupTop + "px";
    document.getElementById("ModalPopupExtender_foregroundElement").style.display = 'block';
    document.getElementById("ModalPopupExtender_backgroundElement").style.display = 'block';
    document.getElementById("ModalPopupExtender_backgroundElement").style.height = document.body.scrollHeight + 'px';
    document.getElementById("tituloPopupText").innerText = tittle;
}

function closeImagePopup(pageToLoad)
{
    document.getElementById("popupContent").src = pageToLoad;
    document.getElementById("ModalPopupExtender_foregroundElement").style.position = 'fixed';
    document.getElementById("ModalPopupExtender_foregroundElement").style.display = 'none';
    document.getElementById("ModalPopupExtender_backgroundElement").style.display = 'none';
    document.getElementById("ModalPopupExtender_backgroundElement").style.height = '0px';
}

/* MENU */

var csssubmenuoffset=5 
if(__nonMSDOMBrowser) csssubmenuoffset=0
var csssubmenuoffsetleft=3 

var mainMenuTabs={
	last_accessed_tab:null,

	revealsubmenu:function(curtabref)
	{
	    if (this.last_accessed_tab!=null)
		    this.last_accessed_tab.className=""
	    curtabref.className="current"
	    this.last_accessed_tab=curtabref
	},

	clearSelTab:function(curtabref)
	{
	    if (this.last_accessed_tab!=null)
		    this.last_accessed_tab.className=""
	},

	init:function(menuId, cssmenuid, selectedIndex)
	{
	    var tabItems=document.getElementById(menuId).getElementsByTagName("a")
		for (var i=0; i<tabItems.length; i++)
		{
			if (i==selectedIndex)
			{   
			    //if this tab item should be selected by default
				tabItems[i].className="current"
				this.revealsubmenu(tabItems[i])
	        }
	        if (tabItems[i].getAttribute("rel") == "MENU")
	        {
		        tabItems[i].onmouseover=function()
		            {
		                mainMenuTabs.revealsubmenu(this)
		            }
		        tabItems[i].onmouseout=function()
		            {
		                mainMenuTabs.clearSelTab(this)
		            }
		    }
		} //END FOR LOOP
        var ultags=document.getElementById(cssmenuid).getElementsByTagName("ul")
        for (var t=0; t<ultags.length; t++)
        {
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+csssubmenuoffset+"px"
			ultags[t].style.left=csssubmenuoffsetleft+"px"
    	    ultags[t].parentNode.onmouseover=function()
    	        {
    	            this.getElementsByTagName("ul")[0].style.visibility="visible"
    	            mainMenuTabs.revealsubmenu(this.childNodes[0])
    	        }
    	    ultags[t].parentNode.onmouseout=function()
    	        {
					this.getElementsByTagName("ul")[0].style.visibility="hidden"
    	            mainMenuTabs.clearSelTab(this.childNodes[0])
    	        }
        }
	}
}
