﻿// GreyMatter base functions

 function roundNumber(number, d_places) {
	        var rnum = number;
	        var rlength = d_places; 
	        if (rnum > 8191 && rnum < 10485) {
		        rnum = rnum-5000;
		        var result = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		        result = result+5000;
	        } else {
		        var result = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	        }
	        return result;
        }
        
        function getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) {
                    return pair[1];
                }
            } 
            return null;
        }
        
        function getCookie(c_name)
        {
        if (document.cookie.length>0)
            {
            c_start=document.cookie.indexOf(c_name + '=')
            if (c_start!=-1)
                { 
                c_start=c_start + c_name.length+1 
                c_end=document.cookie.indexOf(';',c_start)
                if (c_end==-1) c_end=document.cookie.length
                    return unescape(document.cookie.substring(c_start,c_end))
                } 
             }
        return null
        }
            
        function addEvent(elm, evType, fn, useCapture) {
            // gecko browsers & compliant with dom2
            if (elm.addEventListener) {
                elm.addEventListener(evType, fn, useCapture);
                return true;t
                }
            // ie 5+
            else if (elm.attachEvent) {
                var r = elm.attachEvent ('on' + evType, fn);
                return r;
                }
            // for compatibility; untested
            else {
                elm['on' + evType] = fn;
                }
            }
            
        function getexpirydate( nodays){
            var UTCstring;
            Today = new Date();
            nomilli=Date.parse(Today);
            Today.setTime(nomilli+nodays*24*60*60*1000);
            UTCstring = Today.toUTCString();
            return UTCstring;
            }
            
      
        function ShowPic(strPath) {
            var wImage=window.open();
            wImage.document.open();
            wImage.document.write("<html><head><script language='JavaScript'>");
            wImage.document.write("var isNav4, isIE4;");
            wImage.document.write("if (parseInt(navigator.appVersion.charAt(0)) >= 4) {");
            wImage.document.write("isNav4 = (navigator.appName == 'Netscape') ? 1 : 0;");
            wImage.document.write("isIE4 = (navigator.appName.indexOf('Microsoft') != -1) ? 1 : 0;");
            wImage.document.write("}");                       
            wImage.document.write("function FitWindow() {");
            wImage.document.write("if (isNav4) {");
            wImage.document.write("window.innerWidth = document.images[0].width;");
            wImage.document.write("window.innerHeight = document.images[0].height;");
            wImage.document.write("}");
            wImage.document.write("if (isIE4) {");
            wImage.document.write("window.resizeTo(500, 500);");
            wImage.document.write("width = 500 - (document.body.clientWidth -  document.images[0].width);");
            wImage.document.write("height = 500 - (document.body.clientHeight -  document.images[0].height);");
            wImage.document.write("window.resizeTo(width, height);}}");
            wImage.document.write("</script></head><body onLoad='javascript:FitWindow();'>"); 
            wImage.document.write("<div style='position:absolute; left:0px; top:0px'>");
            wImage.document.write("<img src='"+strPath+"'>");
            wImage.document.write("</div>"); 
            wImage.document.write("</body></html>"); 
            wImage.document.close();
            }
