// browser detection
function browserStats() {
  var ua = " " + navigator.userAgent.toLowerCase();
  this.nn = ua.indexOf( "mozilla" ) > 0;
  this.safari = ua.indexOf( "safari" ) > 0;
  ua.indexOf( "compatible" ) > 0 ? this.nn = false : "";
  this.ie = ua.indexOf( "msie" ) > 0;
  this.version = parseInt( navigator.appVersion );
  this.mac = ua.indexOf( "mac" ) > 0;
  this.ie ? ua.indexOf( "msie 5" ) > 0 ? this.version = 5 : "" : "";
  this.ie ? ua.indexOf( "msie 6" ) > 0 ? this.version = 6 : "" : "";
  return this;
}

var b = new browserStats();

//File path
var cssPath = "/user/css/", cssFile;

//Netscape
b.nn && b.version >= 5 ? cssFile = "netscape_font_adjust.css":"";

//IE
b.ie ? cssFile = "ie_font_adjust.css" : b.mac && b.ie && b.version >= 5 ? cssFile = "mac_ie_font_adjust.css":"";

//Safari
b.mac && b.safari ? cssFile = "safari_font_adjust.css":"";

cssFile ? document.write( '<link rel="stylesheet" href="' + cssPath + cssFile + '" type="text/css" />' ) : "";

//Global Netscape browser resize fix
if(b.nn && b.version < 5) {widthCheck = window.innerWidth;heightCheck = window.innerHeight;window.onresize = resizeFix;}
function resizeFix(){widthCheck != window.innerWidth || heightCheck != window.innerHeight ? window.location.reload(true) : "";}

function getParameter(aP){
	var qS = new String(location.search.substring(1,location.search.length));
	var p = qS.split("&");
	var val = "";
	if(aP){
		for(i=0;i<p.length;i++){
			if(p[i].split( "=" )[0] == aP){
				val = p[i].split( "=" )[1];
			}
		}
		// note that the brand-side getParameter DOES NOT do what the next line does;
		// it does not unescape the url-encoding. caveat coder.
		return unescape(val);
	}
}

function openNewWindow(URLtoOpen, windowName, windowFeatures) {
    newWindow = window.open( URLtoOpen, windowName, windowFeatures );
}

//Universal function for no cache
function nocacheRandom(){var axel = Math.random() + "";var ord = axel * 1000000000000000000;return ord;}

//Universal Window Function Type "yes" or "no" for scrollBar
function flexWin(aU,aS,aW,aH,aN,aO,aX,aY,aC){
   var wN = aN ? aN : "myWin" + nocacheRandom();
   var oV = aO == "all" ? 1 : 0;
   var oS = "history="+oV+",toolbar="+oV+",location="+oV+",directories="+oV+",status="+oV+",menubar="+oV+",resizable="+oV;
   var wO = aO != "all" ? aO : oS;
   var wW = aW ? aW : 800;wO += ",width=" + wW;
   var wH = aH ? aH : 600;wO += ",height=" + wH;
   var sB = ",scrollbars=yes";wO+=sB;
   var wX = aX ? aX :(screen.availWidth-wW)/2;wO+=",left="+wX+",screenX="+wX;
   var wY = aY ? aY :((screen.availHeight-wH)/2)-40;wO+=",top="+wY+",screenY="+wY;
   window.open(aU,wN,wO);
   aC ? window.close():"";
}

// this fixes the IE interrupted download issue
function getDownload(argFile){
	if(b.ie){
		window.open(argFile,"fileWin","height=2,width=2")
	} else {
		document.location = argFile;
	}
}

function replaceDomain ( oldText, newText, inText ) {
    var replacementString = oldText;
    var pos = inText.indexOf(replacementString);
    var len = replacementString.length;
    if (pos > -1) {
        return ( inText.substring(0, pos) + newText + inText.substring(pos+len) );
    } else {
        return inText;
    }
}

// get proper domain for global navigation images and links
function getDomain( argLink ) {
    var curUrl = document.location.href;
    var newUrl = "";
    if( curUrl.indexOf( "iw-mount" ) >= 0 ) {
        // preserve virtualization
        newUrl = "";
    } else if( curUrl.indexOf( "://test" ) >= 0 ) {
        newUrl = "http://test.discoverdodge.com";
    } else if( curUrl.indexOf( "://uat" ) >= 0 ) {
        newUrl = "http://uat.discoverdodge.com";
    } else {
        newUrl = "http://www.discoverdodge.com";
    }
    if( argLink ) {
        if( argLink.indexOf( "javascript:" ) >= 0 ) {
            return argLink;
        } else {
            return newUrl + argLink;
        }
    } else {
        return newUrl;
    }
}

// returns offscreen height of page's content
function offscreenH() {
    var docH = document.documentElement.scrollHeight;
    var winH = document.documentElement.clientHeight;
    return docH - winH;
}

//DHTML FUNCTIONS
var d=document; var _a=(d.all)?1:0; var l=(!d.getElementById && b.nn)?1:0;
function getE(e,f){if(l){f=(f)?f:self;V=f.document.layers;if(V[e])return V[e];for(W=0;W<V.length;)t=getE(e,V[W++]);return t;}if(_a)return d.all[e];return d.getElementById(e);}
function showE(e){e=getE(e);if(l)e.visibility='show';else e.style.visibility='visible';}
function hideE(e){e=getE(e);if(l)e.visibility='hide';else e.style.visibility='hidden';}
function getX(e){e=getE(e);if(l)return e.left;else return e.style.left;}
function setX(e,x){e=getE(e);if(l)e.left=x;else e.style.left=x;}
function getY(e){e=getE(e);if(l)return e.top;else return e.style.top;}
function setY(e,y){e=getE(e);if(l)e.top=y;else e.style.top=y;}
function setZ(e,z){e=getE(e);if(l)e.zIndex=z;else e.style.zIndex=z;}
function setW(e,w){e=getE(e);if(l)e.clip.width=w;else e.style.width=w;}
function getW(e){e=getE(e);if(l)return e.document.width;if(_a)return e.scrollWidth;return e.offsetWidth;}
function setH(e,h){e=getE(e);if(l)e.clip.height=h;else e.style.height=h;}
function getH(e){e=getE(e);if(l)return e.document.height;if(_a)return e.scrollHeight;return e.offsetHeight;}
function setC(e,t,r,b,x){e=getE(e);if(l){X=e.clip;X.top=t;X.right=r;X.bottom=b;X.left=x;}else e.style.clip='rect('+t+' '+r+' '+b+' '+x+')';}
function writeH(e,h){e=getE(e);if(l){Y=e.document;Y.write(h);Y.close();}else e.innerHTML=h;}
function getMouseX(e){if(_a)return event.clientX;return e.pageX;}
function getMouseY(e){if(_a)return event.clientY;return e.pageY;}
function getScrollX(){if(_a)return d.body.scrollLeft;return window.pageXOffset;}
function getScrollY(){if(_a)return d.body.scrollTop;return window.pageYOffset;}

