/* Agility Mortgage Corporation JavaScript */

var isStnd = document.getElementById ? true : false; // Standards compliant
var pre_w3c = false;
var ie5 = false;
var isMac = false; 
var isSafari = false;
var isIE = document.all ? true : false; // IE 4/5

var newWindow = null;

// X Variables
var xVersion='3.14.1';
var xOp7=false;
var xOp5or6=false;
var xIE4Up=false;
var xNN4=false;
var xUA=navigator.userAgent.toLowerCase();
if(window.opera){
  xOp7=(xUA.indexOf('opera 7')!=-1 || xUA.indexOf('opera/7')!=-1);
  if (!xOp7) xOp5or6=(xUA.indexOf('opera 5')!=-1 || xUA.indexOf('opera/5')!=-1 || xUA.indexOf('opera 6')!=-1 || xUA.indexOf('opera/6')!=-1);
}
else if(document.layers) {xNN4=true;}
else {xIE4Up=document.all && xUA.indexOf('msie')!=-1 && parseInt(navigator.appVersion)>=4;}

var DHTML = (document.getElementById || document.all || xNN4); // Any of the above

w3c();

function w3c()  { 
	if(navigator.appVersion.indexOf( "Macintosh" ) != -1){
		isMac = true;
	}
	if(navigator.appVersion.indexOf( "Safari" ) != -1){
		isSafari = true;
	}
	if (navigator.appName.indexOf("Netscape") != -1) {
		var version = navigator.appVersion
		var subVersion = version.substring(0,3)
		var subVersion_p = parseFloat(subVersion)
		if (subVersion_p < 5)  {
			pre_w3c = true;
			isNS = true;
    	}  
  	}   
	if (navigator.appName.indexOf("Explorer") != -1) {
		var version = navigator.appVersion
		var subVersion = version.substring(22,25)
		var subVersion_p = parseFloat(subVersion)
		if (subVersion_p < 5)  {
			pre_w3c = true;
			isNS = false;
		}
		if ((subVersion_p == 5) || (subVersion_p == 5.5))  {
			ie5 = true;
		}
	}
}  

function rc(){
	if(realtorID) {
		document.location.href = rcURL;
	} else {
		toggleVisib("mod-realtors");
	}
}

/* Note: MacIE5.2.3 takes relative links from the location of this script file,
note the location of the calling file */
function zoom(page,orientation) {
	//alert("Loc: " + document.location.href + "\n" + "Page: " + page);
	if(isIE && isMac) page = getBackPaths(page);
		//alert(page);
	if (newWindow != null){
		if(navigator.appName.indexOf("Netscape")>=0){
			if(newWindow.name){
		 		newWindow.close();
			}
		}else{
			newWindow.close();
		}
	}
	if(orientation == "landscape"){
		height = 215; // 560
		width = 550; // 730
	} else if(orientation == "portrait"){
		height = 710;
		width = 550;
	} else if(orientation == "pass"){
		height = 360;
		width = 500;
	}
	newWindow = window.open(page, "newWin", "width=" + width + ",height=" + height + ",screenX=0,screenY=0,top=0,left=0,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes");
	//newWindow.location.href = page;
	if (newWindow.opener == null) newWindow.opener = window;

}

function writeFlash(name,file,width,height,wmode){
	var url = document.location.href;
	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+width+"\" height=\""+height+"\"><param name=\"flashvars\" value=\"name="+name+"&ptitle="+title+"&sitelang="+sitelang+"&siteloc="+siteloc+"\&url="+url+"\" /><param name=\"movie\" value=\""+file+"\" /><param name=\"quality\" value=\"high\" /><param name=\"menu\" value=\"false\" /><param name=\"wmode\" value=\""+wmode+"\" /><embed src=\""+file+"\" wmode=\""+wmode+"\" quality=\"high\" menu=\"false\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\" flashvars=\"name="+name+"&ptitle="+title+"&sitelang="+sitelang+"&siteloc="+siteloc+"\&url="+url+"\"></embed></object>");
	
}

// Image preload
function preldimgs() {
  var d=document; 
  if(d.images){ 
  	if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preldimgs.arguments; 
	for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){ 
			d.p[j]=new Image; d.p[j++].src=a[i];
		}
	}
}

function adjustLayout(){
	var adjForTopMargins = 3;
	var header = xHeight("header");
	var left = xHeight("leftcolcon");
	var right = xHeight("rightcolcon");
	var main = Math.max(525, xHeight("main"));
	var maxheight = Math.max(main, Math.max(right, left));
	
	xHeight("leftcolcon", maxheight-header); 
	xHeight("rightcolcon", maxheight-header);
	xHeight("main", maxheight+adjForTopMargins);

	//alert("adjusting layout");
}

// Functions from the x DHTML library
// X v3.14.1, Cross-Browser DHTML Library from Cross-Browser.com
// Copyright (c) 2002,2003 Michael Foster (mike@cross-browser.com)
// This library is distributed under the terms of the LGPL (gnu.org)

function xHeight(e,uH) {
  if(!(e=xGetElementById(e))) return 0;
  if (xNum(uH)) { // v3.13.1
    if (uH<0) uH = 0;
    else uH=Math.round(uH);
  }
  else uH=0;
  var css=xDef(e.style);
  if(css && xDef(e.offsetHeight) && xStr(e.style.height)) {
    if(uH) xSetCH(e, uH);
    uH=e.offsetHeight;
  }
  else if(css && xDef(e.style.pixelHeight)) {
    if(uH) e.style.pixelHeight=uH;
    uH=e.style.pixelHeight;
  }
  else if(xDef(e.clip) && xDef(e.clip.bottom)) {
    if(uH) e.clip.bottom=uH;
    uH=e.clip.bottom;
  }
  return uH;
}

function visib(objName, flag) { // triggers layer visibility 
	var x = xGetElementById(objName); 
	if(x != null) x.style.visibility = (flag) ? 'visible' : 'hidden'; 
}

function toggleVisib(objName, flag) { // triggers layer visibility 
	var x = xGetElementById(objName); 
	if(x != null) {
		if(x.style.visibility == 'visible'){
			x.style.visibility = 'hidden';
		} else {
			x.style.visibility = 'visible';
		}
	} else {
		alert("Div " + objName + " could not be found.");	
	}
}

function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else if(document.layers) e=xLayer(e);
  else e=null;
  return e;
}

function xLayer(id,root) { // only for nn4
  var i,layer,found=null;
  if (!root) root=window;
  for(i=0; i<root.document.layers.length; i++) {
    layer=root.document.layers[i];
    if(layer.id==id) return layer;
    if(layer.document.layers.length) found=xLayer(id,layer);
    if(found) return found;
  }
  return null;
}

function xNum(n) {
  return typeof(n)=='number';
}

function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xStr(s) {
  return typeof(s)=='string';
}

function xSetCH(ele,uH){
  var pt=0,pb=0,bt=0,bb=0;
  if(xDef(document.defaultView) && xDef(document.defaultView.getComputedStyle)){
    pt=xGetCS(ele,'padding-top');
    pb=xGetCS(ele,'padding-bottom');
    bt=xGetCS(ele,'border-top-width');
    bb=xGetCS(ele,'border-bottom-width');
  }
  else if(xDef(ele.currentStyle,document.compatMode)){
    if(document.compatMode=='CSS1Compat'){
      pt=parseInt(ele.currentStyle.paddingTop);
      pb=parseInt(ele.currentStyle.paddingBottom);
      bt=parseInt(ele.currentStyle.borderTopWidth);
      bb=parseInt(ele.currentStyle.borderBottomWidth);
    }
  }
  else if(xDef(ele.offsetHeight,ele.style.height)){ // ?
    ele.style.height=uH+'px';
    pt=ele.offsetHeight-uH;
  }
  if(isNaN(pt)) pt=0; if(isNaN(pb)) pb=0; if(isNaN(bt)) bt=0; if(isNaN(bb)) bb=0;
  var cssH=uH-(pt+pb+bt+bb);
  if(isNaN(cssH)||cssH<0) return;
  else ele.style.height=cssH+'px';
}

function xGetCS(ele,sP){return parseInt(document.defaultView.getComputedStyle(ele,'').getPropertyValue(sP));}

// Event:
function xAddEventListener(e,eventType,eventListener,useCapture) {
  if(!(e=xGetElementById(e))) return;
  eventType=eventType.toLowerCase();
  if((!xIE4Up && !xOp7) && e==window) {
    if(eventType=='resize') { window.xPCW=xClientWidth(); window.xPCH=xClientHeight(); window.xREL=eventListener; xResizeEvent(); return; }
    if(eventType=='scroll') { window.xPSL=xScrollLeft(); window.xPST=xScrollTop(); window.xSEL=eventListener; xScrollEvent(); return; }
  }
  var eh='e.on'+eventType+'=eventListener';
  if(e.addEventListener) e.addEventListener(eventType,eventListener,useCapture);
  else if(e.attachEvent) e.attachEvent('on'+eventType,eventListener);
  else if(e.captureEvents) {
    if(useCapture||(eventType.indexOf('mousemove')!=-1)) { e.captureEvents(eval('Event.'+eventType.toUpperCase())); }
    eval(eh);
  }
  else eval(eh);
}

// Window:
function xClientWidth() {
  var w=0;
  if(xOp5or6) w=window.innerWidth;
  else if(!window.opera && document.documentElement && document.documentElement.clientWidth) // v3.12
    w=document.documentElement.clientWidth;
  else if(document.body && document.body.clientWidth)
    w=document.body.clientWidth;
  else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
    w=window.innerWidth;
    if(document.height>window.innerHeight) w-=16;
  }
  return w;
}
function xClientHeight() {
  var h=0;
  if(xOp5or6) h=window.innerHeight;
  else if(!window.opera && document.documentElement && document.documentElement.clientHeight) // v3.12
    h=document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    h=document.body.clientHeight;
  else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
    h=window.innerHeight;
    if(document.width>window.innerWidth) h-=16;
  }
  return h;
}

function xResizeEvent() { // window resize event simulation
  if (window.xREL) setTimeout('xResizeEvent()', 250);
  var cw = xClientWidth(), ch = xClientHeight();
  if (window.xPCW != cw || window.xPCH != ch) { window.xPCW = cw; window.xPCH = ch; if (window.xREL) window.xREL(); }
}
function xScrollEvent() { // window scroll event simulation
  if (window.xSEL) setTimeout('xScrollEvent()', 250);
  var sl = xScrollLeft(), st = xScrollTop();
  if (window.xPSL != sl || window.xPST != st) { window.xPSL = sl; window.xPST = st; if (window.xSEL) window.xSEL(); }
}

function xScrollLeft(e) {
  var offset=0;
  if (!(e=xGetElementById(e))) {
    if(xDef(window.pageXOffset)) offset=window.pageXOffset;
    else if(document.documentElement && document.documentElement.scrollLeft) offset=document.documentElement.scrollLeft;
    else if(document.body && xDef(document.body.scrollLeft)) offset=document.body.scrollLeft;
  }
  else { if (xNum(e.scrollLeft)) offset = e.scrollLeft; }
  return offset;
}
function xScrollTop(e) {
  var offset=0;
  if (!(e=xGetElementById(e))) {
    if(xDef(window.pageYOffset)) offset=window.pageYOffset;
    else if(document.documentElement && document.documentElement.scrollTop) offset=document.documentElement.scrollTop;
    else if(document.body && xDef(document.body.scrollTop)) offset=document.body.scrollTop;
  }
  else { if (xNum(e.scrollTop)) offset = e.scrollTop; }
  return offset;
}

function validateEmail(){
			if ( ( document.emailForm.text.value == "" ) || ( document.emailForm.email.value.search("@") == -1 ) || ( document.emailForm.email.value.search("[.*]" ) == -1 ) ) {
				alert( "Please make sure the form is complete and valid." );
			} else if ( ( document.emailForm.email.value.search(";") != -1 ) || ( document.emailForm.email.value.search(",") != -1 ) || ( document.emailForm.email.value.search(" ") != -1 ) ) {
				alert( "You cannot enter more than one email address." );			
			} else {
				document.emailForm.action = "http://temp.agilitymortgage.com/public/component/option,com_contact/Itemid,54/lang,en/"
				document.emailForm.submit();
			}
}