﻿function setup() {
    gmh.init();
    /*if (gmh.hasElement('u_ip') && gmh.Ip != '0.0.0.0') {
        gmh.getRawObject('u_ip').innerHTML = '<img class="mright" src="img/gmh_bullet.gif" alt="your ip">We think your IP Adress is ' + gmh.Ip;
    } else {
        gmh.getRawObject('u_ip').innerHTML = '<img class="mright" src="img/gmh_bullet.gif" alt="your ip">We could not get your IP Address';
    }*/
    if (gmh.hasElement('u_latlng')) {
        gmh.getRawObject('u_latlng').innerHTML = '<img class="mright" src="img/gmh_bullet.gif" alt="your ip">We think your Latitude/Longitude is ' + gmh.lat + '&deg;/' + gmh.lng + '&deg;<br/>';
        gmh.getRawObject('u_latlng').innerHTML += '<img class="mright" src="img/gmh_bullet.gif" alt="your ip">This locates you at ' + gmh.address + '<br/>';
        gmh.getRawObject('u_latlng').innerHTML += '<img class="mright" src="img/gmh_bullet.gif" alt="your ip">If this is correct click <span class="link">[YES]</span> else click <span class="link">[NO]</span><br/>';
    } else {
        gmh.getRawObject('u_lnglng').innerHTML = '<img class="mright" src="img/gmh_bullet.gif" alt="your ip">We could not get Latitude &amp; Longitude';
    }
    
}
var gmh = {
    
    init: function() {
    
        //CSS COMPATIBILITY
        this.isCSS = (document.body && document.body.style) ? true : false;
        this.isW3C = (this.isCSS && document.getElementById) ? true : false;
        this.isIE4 = ((this.isCSS && document.all) ? true : false);
        this.isNN4 = ((document.layers) ? true : false);
        this.isIECSSCompat = ((document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false);
        
        //BROWSER VERSION              
        var ua = navigator.userAgent.toLowerCase(); 
        this.ua = ua;
        this.isGecko       = (ua.indexOf('gecko') != -1) ? true : false;
        this.isMozilla     = (this.isGecko && ua.indexOf("gecko/") + 14 == ua.length) ? true : false;
        this.isFireFox     = (this.isGecko && ua.indexOf('firefox') != -1) ? true : false;
        this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) )? true : false;
        this.isIE          = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
        this.isOpera       = (ua.indexOf("opera") != -1)? true : false; 
        this.isKonqueror   = (ua.indexOf("konqueror") != -1)? true : false; 
        this.isIcab        = (ua.indexOf("icab") != -1)? true : false; 
        this.isAol         = (ua.indexOf("aol") != -1) ? true : false; 
        this.isWebtv       = (ua.indexOf("webtv") != -1)? true : false; 
        this.isOmniweb     = (ua.indexOf("omniweb") != -1)? true : false;
        this.isDreamcast   = (ua.indexOf("dreamcast") != -1)? true : false;
        this.isBlackberry  = (ua.indexOf("blackberry") != -1)? true : false;  
        this.jEnabled      = navigator.javaEnabled();
        

        //OS VERSION
        this.OS = this.getOS();
                        
        //WINDOW SETTINGS
        this.wh = this.getInsideWindowHeight();
        this.ww = this.getInsideWindowWidth();

        //SESSION SETTINGS
        var ip = this.getIp();
        this.Ip=(ip== '0.0.0.0')? this.sip() : ip;
        this.lat=46.456;
        this.lng=74.234;
        this.address='200 7th Avenue, NYC, NY, USA';   
    },

    locateMe : function() {
        if (navigator.cookieEnabled==true) {
            if (this.readCookie('isplash') != null) {
                this.eraseCookie('isplash');
                this.createCookie('isplash','true',1);
            } else {
                this.createCookie('isplash','true',1);
            }
        }
        window.location.href ="services.asp";
        
    },
    
    createCookie : function (name,value,days) {
	    if (days) {
		    var date = new Date();
		    date.setTime(date.getTime()+(days*24*60*60*1000));
		    var expires = "; expires="+date.toGMTString();
	    }
	    else var expires = "";
	    document.cookie = name+"="+value+expires+"; path=/";
    },

    readCookie : function(name) {
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0;i < ca.length;i++) {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	    }
	    return null;
    },

    eraseCookie: function(name) {
	    this.createCookie(name,"",-1);
    },

    getInsideWindowWidth : function () {
        if (window.innerWidth) {return window.innerWidth;}
        else if (this.isIE) {return document.body.parentElement.clientWidth;}
        else if (document.body && document.body.clientWidth) {return document.body.clientWidth;}
        return 0;
    },

    getInsideWindowHeight : function () {
        if (window.innerHeight) {return window.innerHeight;}
        else if (this.isIE) {return document.body.parentElement.clientHeight;}
        else if (document.body && document.body.clientHeight) {return document.body.clientHeight;}
        return 0;
    },

    getRawObject : function (elemRef) {
        var elem;
        if (typeof elemRef == "string") {
            if (this.isW3C) {elem = document.getElementById(elemRef);}
            else if (this.isIE4) {elem = document.all(elemRef);} 
            else if (this.isNN4) {elem = this.seekLayer(document, elemRef);}
        } else {elem = elemRef;}
        return elem;
    },
    
    //Check if element exists on page if so return true else return false
    hasElement : function (elemRef) {
         var hasref = false;
         if (typeof elemRef == "string") {
            if (this.isW3C) {hasref =(document.getElementById(elemRef)) ? true : false;}
            else if (this.isIE4) {hasref = document.all(elemRef) ? true : false ;} 
            else if (this.isNN4) {hasref = seekLayer(document, elemRef) ? true : false ;}
        }  
        return hasref;
    
    },

   setContent : function(content,elem,bdisplay,smode) {

        if (this.isW3C){
            bdisplay == true ? this.toggleDisplay(elem,smode) : this.toggleDisplay(elem,smode);
            bdisplay == true ? document.getElementById(elem).innerHTML = content : document.getElementById(elem).innerHTML='';
        } else if (this.isIE4) {
            bdisplay == true ? this.show(elem) : this.hide(elem);
            document.all(elem).innerHTML = content;
        } else if (this.isNN4) {
        
        }
    },

    setContentPlus : function(content,elem,bdisplay,smode) {

        if (this.browserClass.isW3C) {
            document.getElementById(elem).innerHTML += content;
            document.getElementById(elem).scrollTop = document.getElementById(elem).scrollHeight;
        } else if (this.isIE4) {
            bdisplay == true ? this.show(elem) : this.hide(elem);
            document.all(elem).innerHTML += content;
        } else if (this.isNN4) {
        }
    },

    toggleDisplay : function (obj,smode) {
        var elem = this.getStyleObject(obj);
        if (elem) {elem.display = smode;}
    },

    getStyleObject : function (elemRef) {
        var elem = this.getRawObject(elemRef);
        if (elem && this.isCSS) {return elem.style;}
    },            
    getIp : function () {
        if (this.isNS) {return'<!--#echo var="REMOTE_ADDR"-->';}
        else if(this.isIE){return '0.0.0.0';}
        else if (this.jEnabled && (this.isMozilla || this.isGecko || this.isOpera)) {return this.getJiP();}
        else {return '0.0.0.0';}   
    },
    
    getIeIP : function() {
       var sip='0.0.0.0';
       if (this.OS == "WIN") {
           try {
                var wsh = new ActiveXObject("WScript.Shell");             
                if (wsh != null || typeof(wsh) != 'undefined') {
                    var bHaveIP = false;
                    for (var i=0;i<10;i++) {
                        if (bHaveIP == false) {
                            var cNICSearch='HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\' + i + '\\ServiceName';
                            try {
                                var cNicServiceName = '';
                                cNicServiceName=wsh.RegRead(cNICSearch);
                                alert('regread=' + cNicServiceName);
                                if (cNicServiceName != '') {
                                    var cIPAddressKey='HKLM\\SYSTEM\\CurrentControlSet\\Services\\TCPIP\\Parameters\\Interfaces\\' + cNicServiceName+'\\DhcpIPAddress';
                                    try {
                                        var cNicIP = '';
                                        cNicIP = wsh.RegRead(cIPAddressKey);
                                        if (cNicIP != '') {
                                            sip=cNicIP;
                                            bHaveIP = true;   
                                        }
                                    } catch(e) {alert('error enuming NICs' + e)}
                                }
                            } catch (e) {alert('error reading register ' + e)}  
                        }
                    }
                }
            } catch(e) {alert('error creating activeXObject ' + e)}
        } else {
            
        
        }
        return sip;     
    },
    
    getJiP : function() {
        var jip='';
        if (this.jEnabled) {
            var addr=java.net.NetworkInterface.getNetworkInterfaces();
            while (addr.hasMoreElements()) {
                var h = addr.nextElement();
                var addrlist = h.getInetAddresses();
                while (addrlist.hasMoreElements()) {
                    var ne = addrlist.nextElement();
                    if (ne.getHostAddress() != '127.0.0.1') {jip= ne.getHostAddress();};
                }
            }
            if (jip.length == 0){return '0.0.0.0';}else{return jip;}      
        } 
        else 
        { 
        return '0.0.0.0';
        }     
    },
    
    getOS : function() {
        var ua = navigator.userAgent.toLowerCase();
        if(ua.indexOf("win") != -1){if(ua.indexOf("nt 6")!=-1){return "VIS";}else{return "WIN";}}
        else if(ua.indexOf("mac") != -1){return "MAC";}
        else if(ua.indexOf("linux") != -1){return "LIN";}
        else if(ua.indexOf("x11") != -1){return "UNX";}
        else{return "N/A";}
    },
    
    requestXMLHTTP : function()
    {  
	    var xmlHttp;
	    try{xmlHttp=new XMLHttpRequest();}
	    catch (e){       
		    try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
		    catch (e){      
			    try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
			    catch (e){return false;}
		    }
	    }
	    return xmlHttp;
    },
    
    sip : function(){
        return '192.168.2.4';
    }
};