var ns6 = (document.getElementById && !document.all) ? true : false;
//var maxPicWidth = 160;
//var maxPicHeight = 80;
var maxPicWidth = 300;
var maxPicHeight = 150;
var clickWidth, clickHeight;

function picClick(picurl, picwidth, picheight, listing_id, finh, finw) {
	var finalWidth, finalHeight;
	//finalWidth = picwidth + 20;
	//finalHeight = picheight + 64;
	//finalWidth = picwidth + 120;
	//alert('picwidth= ' + picwidth + '  finw=' + finw);
	if (finw==0 && finh==0)
	{
		finalWidth = picwidth + 64;
		finalHeight = picheight + 120;
	}
	else
	{
		finalWidth = finw * 1.15 ;
		finalHeight = finh * 1.10;
	}
	//alert(finalWidth);
	//	window.open(imgPath+'auto/lease/search/picshow.aspx?listing_id='+listing_id+'&picurl='+picurl, '_blank', 'width='+finalWidth+', height='+finalHeight+',titlebar=no');
	//window.open(imgPath+'auto/lease/search/picshow.aspx?listing_id='+listing_id+'&w='+ picwidth+'&h='+picheight+'&picurl='+picurl, '_blank', 'width='+finalWidth+', height='+finalHeight+',resizable=yes,titlebar=yes,scrollbars=yes,top=0,left=0');
	picurl = picurl.replace(/&/gi, 'andand');
	window.open(imgPath+'auto/lease/search/picshow.aspx?listing_id='+listing_id+'&w='+ finalWidth+'&h='+finalHeight+'&picurl='+picurl, '_blank', 'width='+finalWidth+', height='+finalHeight+',resizable=yes,titlebar=yes,scrollbars=yes,top=0,left=0');
	
}


function picClick3(picurl, picwidth, picheight, listing_id, finh, finw) {
	var finalWidth, finalHeight;
	//finalWidth = picwidth + 20;
	//finalHeight = picheight + 64;
	//finalWidth = picwidth + 120;
	if (finw==0 && finh==0)
	{
		finalWidth = picwidth + 64;
		finalHeight = picheight + 120;
	}
	else
	{
		finalWidth = finw * 1.15 ;
		finalHeight = finh * 1.10;
	}
	//	window.open(imgPath+'auto/lease/search/picshow.aspx?listing_id='+listing_id+'&picurl='+picurl, '_blank', 'width='+finalWidth+', height='+finalHeight+',titlebar=no');
	window.open(imgPath+'auto/lease/search/picshow.aspx?listing_id='+listing_id+'&w='+ picwidth+'&h='+picheight+'&picurl='+picurl, '_blank', 'width='+finalWidth+', height='+finalHeight+',resizable=yes,titlebar=no,scrollbars=yes,top=0,left=0');
}

function picClick2(picurl, picwidth, picheight, listing_id, finh, finw) {
	var finalWidth, finalHeight;
	//finalWidth = picwidth + 20;
	//finalHeight = picheight + 64;
	//finalWidth = picwidth + 120;
	if (finw==0 && finh==0)
	{
		finalWidth = picwidth + 64;
		finalHeight = picheight + 120;
	}
	else
	{
		finalWidth = finw * 1.15 ;
		finalHeight = finh * 1.10;
	}
	//	window.open(imgPath+'auto/lease/search/picshow.aspx?listing_id='+listing_id+'&picurl='+picurl, '_blank', 'width='+finalWidth+', height='+finalHeight+',titlebar=no');
	window.open(imgPath+'auto/lease/search/picshow.aspx?listing_id='+listing_id+'&req=yes&w='+ picwidth+'&h='+picheight+'&picurl='+picurl, '_blank', 'width='+finalWidth+', height='+finalHeight+',titlebar=yes,scrollbars=yes,top=0,left=0');
}


if(document.URL.indexOf('lt_test') > 0) {
	var imgPath = '/lt_test/'
} else {
	var imgPath = '/'
}

function pageUp () {
	window.scrollTo(0, 0);
}

function pageMiddle () {
	if (window.scrollTo) window.scrollTo(0, document.body.clientHeight / 2);
}

function pageDown () {
	if (window.scrollBy) window.scrollTo(0, document.body.clientHeight);
}

function setPic(target, source, picWidth, picHeight, listing_id) {
	clickWidth = picWidth + 20;
	clickHeight = picHeight + 20;
	if(target != source) {
		
		target.src = source.src.replace(/100x75/gi, '300x225');
		target.width = 300;
		target.height = 225;
		var tmplink = eval(target.id.replace(/imgMain/gi, 'lnkPicMain'));
		if(typeof tmplink != 'undefined') {
			//tmplink.href = "javascript: picClick('" + target.src + "'," + picWidth + ", " + picHeight + ", " + listing_id + ");"
			tmplink.href = "javascript: picClick('" + target.src + "',650, 640, " + listing_id + ", 0 , 0);"
		}
	} else {
		//window.open(replaceMe(source.src, 't_'));
	}
}

function setPic3(target, source, picWidth, picHeight, listing_id) {
	clickWidth = picWidth + 20;
	clickHeight = picHeight + 20;
	if(target != source) {
		var newWidth, newHeight;
		newWidth = picWidth;
		newHeight = picHeight;
		if(newWidth > maxPicWidth) {
			newHeight = (maxPicWidth / picWidth) * picHeight;
			newWidth = maxPicWidth;
		}
		if(newHeight > maxPicHeight) {
			newWidth = (maxPicHeight / picHeight) * picWidth;
			newHeight = maxPicHeight;
		}
		target.src = source.src.replace(/t_imgshow/gi, 'imgshow');
		target.width = newWidth;
		target.height = newHeight;
		var tmplink = eval(target.id.replace(/imgMain/gi, 'lnkPicMain'));
		if(typeof tmplink != 'undefined') {
			tmplink.href = "javascript: picClick('" + target.src + "'," + picWidth + ", " + picHeight + ", " + listing_id + ");"
		}
	} else {
		//window.open(replaceMe(source.src, 't_'));
	}
}

function setPic2(target, source, picWidth, picHeight, listing_id) {
	clickWidth = picWidth + 20;
	clickHeight = picHeight + 20;
	if(target != source) {
		var newWidth, newHeight;
		newWidth = picWidth;
		newHeight = picHeight;
		//if(newWidth > maxPicWidth) {
		//	newHeight = (maxPicWidth / picWidth) * picHeight;
		//	newWidth = maxPicWidth;
		//}
		//if(newHeight > maxPicHeight) {
		//	newWidth = (maxPicHeight / picHeight) * picWidth;
		//	newHeight = maxPicHeight;
		//}
		target.src = source.src.replace(/t_imgshow/gi, 'imgshow');
		target.width = newWidth;
		target.height = newHeight;
	//	var tmplink = eval(target.id.replace(/imgMain/gi, 'lnkPicMain'));
		//if(typeof tmplink != 'undefined') {
		//	tmplink.href = "javascript: picClick('" + target.src + "'," + picWidth + ", " + picHeight + ", " + listing_id + ");"
		//}
	} else {
		//window.open(replaceMe(source.src, 't_'));
	}
}

function setPic4(target, source, picWidth, picHeight, listing_id) {
	clickWidth = picWidth + 20;
	clickHeight = picHeight + 20;
	if(target != source) {
		var newWidth, newHeight;
		newWidth = picWidth;
		newHeight = picHeight;
		//if(newWidth > maxPicWidth) {
		//	newHeight = (maxPicWidth / picWidth) * picHeight;
		//	newWidth = maxPicWidth;
		//}
		//if(newHeight > maxPicHeight) {
		//	newWidth = (maxPicHeight / picHeight) * picWidth;
		//	newHeight = maxPicHeight;
		//}
		target.src = source.src.replace(/t_imgshow/gi, 'imgshow');
		target.src = target.src.replace(/210x242/gi, '640x480');
		target.width = newWidth;
		target.height = newHeight;
	//	var tmplink = eval(target.id.replace(/imgMain/gi, 'lnkPicMain'));
		//if(typeof tmplink != 'undefined') {
		//	tmplink.href = "javascript: picClick('" + target.src + "'," + picWidth + ", " + picHeight + ", " + listing_id + ");"
		//}
	} else {
		//window.open(replaceMe(source.src, 't_'));
	}
}


function setRegion(reg)
{
	document.Form1.region_id.value = reg;
}


//********SCROLL*************************************
function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=lib_bwcheck()

var speed = 30

var loop, timer

function makeObj(obj,nest){
    nest=(!nest) ? "":'document.'+nest+'.'
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight	
	this.scrollWidth=bw.ns4?this.css.document.width:this.el.offsetWidth
	this.clipWidth=bw.ns4?this.css.clip.width:this.el.offsetWidth	
	this.up=goUp;this.down=goDown;
	this.leftScroll=goLeft;this.rightScroll=goRight;
	this.moveIt=moveIt; this.x=0; this.y=0;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this
}

var px = bw.ns4||window.opera?"":"px";

function moveIt(x,y){
	this.x = x
	this.y = y
	this.css.left = this.x+px
	this.css.top = this.y+px
}

function goRight(move){
	if (this.x>-this.scrollWidth+oCont.clipWidth){
		this.moveIt(this.x-move,0)
		if (loop) setTimeout(this.obj+".rightScroll("+move+")",speed)
	}
}

function goLeft(move){
	if (this.x<0){
		this.moveIt(this.x-move,0)
		if (loop) setTimeout(this.obj+".leftScroll("+move+")",speed)
	}
}

function goDown(move){
	if (this.y>-this.scrollHeight+oCont.clipHeight){
		this.moveIt(0,this.y-move)
			if (loop) setTimeout(this.obj+".down("+move+")",speed)
	}
}
function goUp(move){
	if (this.y<0){
		this.moveIt(0,this.y-move)
		if (loop) setTimeout(this.obj+".up("+move+")",speed)
	}
}

function scroll(speed){
if (ns6) {
	if (speed>0) speed+=4
	else speed-=4;
}
	if (scrolltextLoaded){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

function scrollResults(speed){
if (ns6) {
	if (speed>0) speed+=8
	else speed-=8;
}
	if (scrolltextResLoaded){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

function scrollComparison(speed){
if (ns6) {
	if (speed>0) speed+=8
	else speed-=8;
}
	if (scrolltextCompLoaded){
		loop = true;
		if (speed>0) oScroll.rightScroll(speed)
		else oScroll.leftScroll(speed)
	}
}

function scrollEdit(speed){
if (ns6) {
	if (speed>0) speed+=5
	else speed-=5;
}
	if (scrolltextEdit){
		loop = true;
		if (speed>0) oScroll.rightScroll(speed)
		else oScroll.leftScroll(speed)
	}
}

function scrollUpload(speed){
if (ns6) {
	if (speed>0) speed+=5
	else speed-=5;
}
	if (scrolltextUpload){
		loop = true;
		if (speed>0) oScroll.rightScroll(speed)
		else oScroll.leftScroll(speed)
	}
}
function scrollFaqMenu(speed){
if (ns6) {
	if (speed>0) speed+=8
	else speed-=8;
}
	if (scrolltextFaqMenu){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}
function scrollFaq(speed){
if (ns6) {
	if (speed>0) speed+=8
	else speed-=8;
}
	if (scrolltextFaq){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}
function scrollSummary(speed){
if (ns6) {
	if (speed>0) speed+=8
	else speed-=8;
}
	if (scrolltextSummary){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}
function scrollFavorites(speed){
if (ns6) {
	if (speed>0) speed+=8
	else speed-=8;
}
	if (scrolltextFavorites){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

function noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}

var scrolltextFaqMenu = false
var scrolltextLoaded = false
var scrolltextResLoaded = false
var scrolltextCompLoaded = false
var scrolltextEdit = false
var scrolltextFaqMenu = false
var scrolltextFaq = false

function scrolltextInit(){
	oCont = new makeObj('ScrollTable')
	oScroll = new makeObj('ScrollText','ScrollTable')
	oScroll.moveIt(0,0)
	oCont.css.visibility = "visible"
	scrolltextLoaded = true
}
function scrolltextInitR(){
	oCont = new makeObj('ScrollResults')
	oScroll = new makeObj('ScrollResText','ScrollResults')
	oScroll.moveIt(0,0)
	oCont.css.visibility = "visible"
	scrolltextResLoaded = true
}

function scrolltextInitC(){
	oCont = new makeObj('ComparisonTable')
	oScroll = new makeObj('ComparisonText','ComparisonTable')
	oScroll.moveIt(0,0)
	//oCont.css.visibility = "visible"
	scrolltextCompLoaded = true	
}
function scrolltextdesInitR(){
	scrolltextResLoaded = false
}
function scrolltextdesInit(){
	scrolltextLoaded = false
}
function scrolltextdesInitC(){
	scrolltextCompLoaded = false
}
function scrolltextdesSummary(){
	scrolltextSummary = false
}
function scrolltextInitSummary(){
	oCont = new makeObj('SummaryScroll')
	oScroll = new makeObj('SummaryText','SummaryScroll')
	oScroll.moveIt(0,0)
	//oCont.css.visibility = "visible"
	scrolltextSummary = true	
}
function scrolltextdesFavor(){
	scrolltextFavor = false
}
function scrolltextdesEdit(){
	scrolltextEdit = false
}
function scrolltextdesUpload(){
	scrolltextUpload = false
}
function scrolltextdesFaqMenu(){
	scrolltextFaqMenu = false
}
function scrolltextdesFaq(){
	scrolltextFaq = false
}
function scrolltextInitFavor(){
	oCont = new makeObj('FavoritesScroll')
	oScroll = new makeObj('FavoritesText','FavoritesScroll')
	oScroll.moveIt(0,0)
	//oCont.css.visibility = "visible"
	scrolltextFavorites = true	
}

function scrolltextInitEdit(){
	oCont = new makeObj('ScrollEdit')
	oScroll = new makeObj('ScrollEditText','ScrollEdit')
	oScroll.moveIt(0,0)
	//oCont.css.visibility = "visible"
	scrolltextEdit = true	
}
function scrolltextInitUpload(){
	oCont = new makeObj('UploadScroll')
	oScroll = new makeObj('UploadText','UploadScroll')
	oScroll.moveIt(0,0)
	//oCont.css.visibility = "visible"
	scrolltextUpload = true	
}
function scrolltextInitF(){
	oCont = new makeObj('FaqMenuScroll')
	oScroll = new makeObj('FaqMenuText','FaqMenuScroll')
	oScroll.moveIt(0,0)
	//oCont.css.visibility = "visible"
	scrolltextFaqMenu = true	
}
function scrolltextInitFaq(){
	oCont = new makeObj('FaqScroll')
	oScroll = new makeObj('FaqText','FaqScroll')
	oScroll.moveIt(0,0)
	//oCont.css.visibility = "visible"
	scrolltextFaq = true
}


//if (bw.bw) onload = scrolltextInit

//********END SCROLL*************************************

//********LAYER*************************************

var ie4 = (document.all) ? true : false;
// LAYER SWITCHING CODE

// SHOW LAYER
function showLayer(layerName){
//if (ie4) {document.all[layerName].style.visibility = "visible";}
//if (ns6) {document.getElementById([layerName]).style.visibility = 'visible';}
//	var layerObj = document.all(layerName);
	if(ie4) {
		var layerObj = document.all(layerName);
	}
	if(ns6)
	{
		var layerObj = document.getElementById([layerName]);
	}
	if(typeof(layerObj.length) != 'number') {
		if (ie4) {layerObj.style.visibility = "visible";}
		if (ns6) {layerObj.style.visibility = 'visible';}
	} else {
		for(var i=0; i < layerObj.length; i++) {
			if (ie4) {layerObj[i].style.visibility = "visible";}
			if (ns6) {layerObj[i].style.visibility = 'visible';}
		}
	}
}


// HIDE LAYER
function hideLayer(layerName) {
	if(ie4) {
		var layerObj = document.all(layerName);
	}
	if(ns6)
	{
		var layerObj = document.getElementById([layerName]);
	}
	if(typeof(layerObj.length) != 'number') {
		layerObj.style.visibility = "hidden";
		//if (ie4) {document.all[layerName].style.visibility = "hidden";}
		//if (ns6) {document.getElementById([layerName]).style.visibility = 'hidden';}
	} else {
		for(var i=0; i < layerObj.length; i++) {
			//alert(typeof layerObj[i].style.visibility);
			//if (ie4) {layerObj[i].style.visibility = "hidden";}
			//if (ns6) {layerObj[i].style.visibility = 'hidden';}
			layerObj[i].style.visibility = "hidden";
		}
	}
}
//********END LAYER*************************************

//*******TAB LAYER**************************************

	if(document.images) {
		ftover = new Array(4);
		ftout = new Array(4);
		for(var n=1;n<=4;n++) {
			ftover[n]=new Image;
			ftout[n]=new Image;
			ftover[n].src=imgPath+"auto/images/button0"+n+"_offb.gif";
			ftout[n].src=imgPath+"auto/images/button0"+n+"_off.gif";
		}
	}
	function tabOn(i) {
		if(document.images) document.images["ft"+i].src=ftover[i].src;
	}
	function tabOff(i) {
		if(document.images) document.images["ft"+i].src=ftout[i].src;
	}
   function searchOn() {
	if(document.images) document.images["over"].src=imgPath+"auto/images/search_borderb.gif";
   }
   function searchOff() {
	if(document.images) document.images["over"].src=imgPath+"auto/images/search_border.gif";
   }
   function searchaddOn() {
	if(document.images) document.images["advanced_img"].src=imgPath+"auto/images/search_advanced_borderb.gif";
   }
   function searchaddOff() {
	if(document.images) document.images["advanced_img"].src=imgPath+"auto/images/search_advanced_border.gif";
   }
//*******END TAB LAYER*************************************

//*******MOUSE OVER****************************************
  function mOvr(src,clrOver,type) {
	if (type == "selected") {
		src.className='selectedcell_over';
	} else {
		if (type == "selectedM") {
			src.className='selectcell_over';
		} else {
			if (type == "favorites") {
				src.className='favoritecell_over';
			} else {
				src.className='cell_over';
			}
		}
	}
  }
  function mOut(src,clrIn,type) {
	if (type == "selected") {
		src.className='selectedcell_out';
	} else {
		if (type == "selectedM") {
			src.className='selectcell_out';
		} else {
			if (type == "favorites") {
				src.className='favoritecell_out';
			} else {
				src.className='cell_out';
			}
		}
	}
  }
  function mClk(src) {
      if(event.srcElement.tagName=='TD'){
	  src.children.tags('A')[0].click();
    }
  }

//*******END MOUSE OVER************************************


function ValidExpression(exp) {
	var checkRegexGroup = function(group, input, f) {
		for (var i=0; i < group.length; i++) {
			if (new RegExp(group[i]).test(input)) {
				f();
				return false;
			}
		}
		return true;
	}

	var arMails = [];
	arMails.push("([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})");
	arMails.push("([a-zA-Z0-9_\\.\\-])+\\@([a-zA-Z0-9\\-\\.])");
	
	var arTel = [];
	arTel.push("\\(?\\d{3}\\)?[-\\s.]?\\d{3}[-\\s.]?\\d{4}");
	arTel.push("[0-9]{3,}[ -/]*[0-9]{4,}");
	arTel.push("[0-9]{3,}[ -/]+[0-9]{3,}[ -/]+");
	arTel.push("[0-9][ -/]*[0-9][ -/]*[0-9][ -/]*[0-9][ -/]*[0-9][ -/]*[0-9][ -/]*[0-9][ -/]*[0-9][ -/]*[0-9][ -/]*[0-9]");
	arTel.push("[0-9]{3,}.[0-9]{3,}.[0-9]{4,}");

	return checkRegexGroup(arMails, exp, function() {alert('Sorry, you should not send email addresses.');}) && 
			checkRegexGroup(arTel, exp, function() {alert('Sorry, you should not send phone numbers.');});						
		
}

						
			function ValidExpressionMile(exp)
			{
						
				var arMile = new Array(3);
				//4444-4444</FONT>
				//"^(\d{1,4})?$";
				arMile[0] = "^(\d{1,24})(,\d{1,2} | \.\d{1,2} )?$";
				arMile[1] = "^(\d{1,3})((\.\d{3}){1,4})?(,\d{1,2})?$";
				arMile[2] = "^(\d{1,3})((,\d{3}){1,4})?(\.\d{1,2})?$";				
							
		
				//Valid Mile
				var validMile=false
				var i=0
			
				while ((i < arMile.length) && (!validMile))
				{
					var strRegExp = new RegExp(arMile[i]);
					validMile = strRegExp.test(exp)
					i = i+1;
				}//end while
			
				if (!validMile)
				{
					
						return true
				}
				else
				{
						alert('Invalid Format, Ex: 18000/18.000/18,000.50');
						return false
				}
					
			}
			
				
			function fnTrapKD(btn, evt){
				var d = document;
				if (d.all){
					evt.returnValue=false;
					evt.cancel = true;
					eval(btn + "." + evt + "()");
				} 
				if (d.getElementById){
					evt.returnValue = false;
					evt.cancel = true;
					eval("d.getElementById('" + btn + "')." + evt + "()");
				} 
			}