
var month=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	
function timer(){
		document.getElementById('timeHolder').innerText=calcTime();
}

function calcTime(){
	var now=new Date();
//	var seconds=now.getSeconds()<10?'0'+now.getSeconds():now.getSeconds();
	var minutes=now.getMinutes()<10?'0'+now.getMinutes():now.getMinutes();
	var timeStr=now.getHours()>11?((now.getHours()==12?12:now.getHours()-12))+':'+minutes+' PM':(now.getHours()==0?12:now.getHours())+':'+minutes+' AM';
	var dayStr=month[now.getMonth()]+' '+now.getDate()+', '+now.getFullYear();
	return timeStr;
}

var xrip=1, t=0, inc=0, scrnr, bin=true, noShow='none', show='block';
var scrollEff=1, incr=new Array();

function animate(){

	for (m=1;m<=j;m++){
	
		if (move[m] && (x[m]=parseInt(fob[m].left))<0) {
			fade[m]=false;
			fob[m].left=(x[m]*1/2)+'px';
			foa[m].display='block';
		}
		
		if (fade[m] && (x[m]=parseInt(fob[m].left))>-180) {
			move[m]=false;
			incr[m]=incr[m]+1;
			fob[m].left=(-Math.pow(2,incr[m]))+'px';
			if (parseInt(fob[m].left)<-170) foa[m].display='none';
		} else {
			incr[m]=1;
		}


	}	
}


	function resizeDnB() {
		//if (document.images.gtsi){
		//	document.images.gtsi.style.width='120px';
		//	document.images.gtsi.style.height='42px';
		//}
	}


/*--------------------------CALENDAR SCRIPT ---------------------------------*/

var thisMonth, thisYear, origDate

function makeCal(dir,calNum){
		if (!calNum) calNum='';
		var today=new Date()

		switch(dir){
			case 2:
				thisMonth=thisMonth<11?thisMonth+1:0;
				thisYear=thisMonth==0?thisYear+1:thisYear
				today=new Date(thisYear,thisMonth,1);
				break;
			case 1:
				thisMonth=thisMonth>0?thisMonth-1:11;
				thisYear=thisMonth==11?thisYear-1:thisYear;
				today=new Date(thisYear,thisMonth,1);
				break;
			default:
				thisMonth=today.getMonth();
				thisYear=today.getYear();
				origDate=today;
		}
			
		var dateArray=new Array(), monthsLength=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		if (Math.floor(today.getFullYear()/4)==today.getFullYear()/4) monthsLength[1]=29;
		for (i=0;i<42;i++) dateArray[i]='';
		var dayNum=today.getDate(), weekDay=today.getDay(), firstDay;
		while (dayNum>7){
			dayNum-=7;
		}
		firstDay=weekDay-dayNum+1;
		firstDay+=(7*(firstDay<0));
		for (i=0;i<42;i++) {
			var calDate=i-firstDay+1
			if(i<firstDay) {
				dateArray[i]='class="calendarDate">&nbsp;';
			} else {
				dateArray[i]='class="calendarDate" onClick="putDate('+calDate+',\''+calNum+'\')">'+calDate;
			  if (calDate>monthsLength[today.getMonth()]) dateArray[i]='class="calendarDate">&nbsp;';
			  if (calDate==origDate.getDate()&&origDate.getMonth()==today.getMonth()&&origDate.getYear()==today.getYear()) dateArray[i]=' class="calendarHead" style="cursor:default" onClick="putDate('+calDate+',\''+calNum+'\')">' + calDate;
			}
		}
		
		tbl='<table id="cal" width="140" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#CCCCCC"><tr><td>'
		+'<table width="140" border="0" cellspacing="1" cellpadding="0" align="center">'
		+'  <tr align="center">'
		+'	  <td valign="top" align="center" class="calendarHead" bgcolor="#406095"><a href="javascript: makeCal(1,\''+calNum+'\')"><img src="images/cal-minus.gif" /></a></td>'
		+'    <td colspan="5" valign="top" align="center" class="calendarHead" bgcolor="#406095">'+month[today.getMonth()]+', '+today.getFullYear()+'</td>'
		+'    <td valign="top" align="center" class="calendarHead" bgcolor="#406095"><a href="javascript: makeCal(2,\''+calNum+'\')"><img src="images/cal-plus.gif" /></a></td>'  
		+'  </tr>'
		+'  <tr align="center"> '
		+'    <td height="15" class="calendarDay" width="20" align="center" bgcolor="#406095">S</td>'
		+'    <td class="calendarDay" width="20" align="center" bgcolor="#406095">M</td>'
		+'    <td class="calendarDay" width="20" align="center" bgcolor="#406095">T</td>'
		+'    <td class="calendarDay" width="20" align="center" bgcolor="#406095">W</td>'
		+'    <td class="calendarDay" width="20" align="center" bgcolor="#406095">T</td>'
		+'    <td class="calendarDay" width="20" align="center" bgcolor="#406095">F</td>'
		+'    <td class="calendarDay" width="20 align="center" bgcolor="#406095">S</td>'
		+'  </tr>'
		for (i=0;i<6;i++){
		var hiTest=dateArray[i*7].substring(dateArray[i*7].indexOf(">")+1);
		if (hiTest!='&nbsp;' || i==0){
			tbl+='  <tr> '
			+'    <td align="center" height="15"'+ dateArray[i*7+0]+'</td>'
			+'    <td align="center" height="15"'+ dateArray[i*7+1]+'</td>'
			+'    <td align="center" height="15"'+ dateArray[i*7+2]+'</td>'
			+'    <td align="center" height="15"'+ dateArray[i*7+3]+'</td>'
			+'    <td align="center" height="15"'+ dateArray[i*7+4]+'</td>'
			+'    <td align="center" height="15"'+ dateArray[i*7+5]+'</td>'
			+'    <td align="center" height="15"'+ dateArray[i*7+6]+'</td>'
			+'  </tr>'
		}
		}
		tbl+='</table></td></tr></table>'

		document.getElementById('calDiv'+calNum).innerHTML=tbl;

}

function putDate(dy,calNum){
	document.getElementById('date'+calNum).value=thisYear + '-' + ((thisMonth+1)>9?thisMonth+1:'0'+(thisMonth+1)) + '-' + (dy>9?dy:'0'+dy) ;
	if (document.getElementById('00N30000000n1eU'))document.getElementById('00N30000000n1eU').value=(thisMonth+1)+'/'+dy+'/'+thisYear;
	document.getElementById('calHolder'+calNum).style.display='none';
	if (document.lmapplication){
		if (calNum==1){
			document.getElementById('foreclosure_hearing_date').value=document.getElementById('date'+calNum).value;
			doAjax(document.getElementById('foreclosure_hearing_date'));
		}
		if (calNum==2){
			document.getElementById('saleDate').value=document.getElementById('date'+calNum).value;
			doAjax(document.getElementById('saleDate'));
		}
	}
}
/*----------------------------END CALENDAR SCRIPT--------------------------*/

function validation(obj){
	if (obj.first_name.value==''){
		alert('You must provide your first name.')
		obj.first_name.focus();
		return false;
	} else {
		obj.first_name.value=obj.first_name.value.toUpperCase().substr(0,1)+obj.first_name.value.toLowerCase().substr(1);
	}
	
	if (obj.last_name.value==''){
		alert('You must provide your last name.')
		obj.last_name.focus();
		return false;
	} else {
		obj.last_name.value=obj.last_name.value.toUpperCase().substr(0,1)+obj.last_name.value.toLowerCase().substr(1);
	}
	
	if (obj.email.value==''){
		alert('You must provide your email address.')
		obj.email.focus();
		return false;
	}	
	
	if (obj.email.value!='' && obj.email.value.replace(/[A-Z]|[a-z]|[0-9]|\_|\-|\=/g,'').indexOf('@.')==-1){
		alert('Your email address appears to be invalid.');
		obj.email.focus();
		return false;
	}
	if (obj.state.value==''){
		alert('You must specify a state.');
		obj.state.focus();
		return false;
	}
	if (document.getElementById('00N30000000gwQg').value==''){
		alert('You must choose a "Best Time to Call".');
		document.getElementById('00N30000000gwQg').focus();
		return false;
	}
	if (document.getElementById('00N30000000gwQe').value=='' && document.getElementById('00N30000000gwQf').value==''){
		alert('You must provide either a valid daytime or evening phone number so that we may contact you. Phone numbers should be entered in the form of XXX-XXX-XXXX.')
		document.getElementById('00N30000000gwQe').focus();
		return false;
	}
}

function valPhone(obj){
	if (obj.value=='') return;
	if (obj.value.replace(/[^0-9]/g,'').length<10){
		alert('The value you entered for ' +obj.id+ ' is of an incorrect format. The phone number should be entered in the form of XXX-XXX-XXXX.');
		obj.select();
		return false;
	} else {
		var phStr=obj.value.replace(/[^0-9]/g,'');
		phStr=phStr.substr(0,3) + '-' + phStr.substr(3,3) + '-' + phStr.substr(6,4) + (phStr.length>10?' x' + phStr.substr(10):'');
		obj.value=phStr;
	}
}

function capitalize(str){
	var strArray=str.split(' ');
}

function highlightWord(node,word) {
  // Iterate into this nodes childNodes
  if (node.hasChildNodes) {
    var hi_cn;
    for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
      highlightWord(node.childNodes[hi_cn],word);
    }
  }

  // And do this node itself
  if (node.nodeType == 3) { // text node
    tempNodeVal = node.nodeValue.toLowerCase();
    tempWordVal = word.toLowerCase();
    if (tempNodeVal.indexOf(tempWordVal) != -1) {
      pn = node.parentNode;
      if (pn.className != "searchword") {
        // word has not already been highlighted!
        nv = node.nodeValue;
        ni = tempNodeVal.indexOf(tempWordVal);
        // Create a load of replacement nodes
        before = document.createTextNode(nv.substr(0,ni));
        docWordVal = nv.substr(ni,word.length);
        after = document.createTextNode(nv.substr(ni+word.length));
        hiwordtext = document.createTextNode(docWordVal);
        hiword = document.createElement("span");
        hiword.className = "searchword";
        hiword.appendChild(hiwordtext);
        pn.insertBefore(before,node);
        pn.insertBefore(hiword,node);
        pn.insertBefore(after,node);
        pn.removeChild(node);
      }
    }
  }
}

/*------------------------------- ROUNDED CORNERS AND DROPSHADOW ROUTINE-------------*/

	function makeCorners(node){
	
		  if (node.hasChildNodes) {
				var iteration;
				for (iteration=0;iteration<node.childNodes.length;iteration++) {
					makeCorners(node.childNodes[iteration]);
				}
		  }
		  
		  // format for ATTRIBUTE: corners="round,[radius (0 if none)],[shadowOffset (0 if none)],[color (opt)]"
		  
		  if (node.getAttribute&&(sty=node.getAttribute('corners'))){
		   
			var arrSty=sty.split(',');
			sty=arrSty[0];
			cornerRadius=parseInt(arrSty[1]);
			shadowOffset=parseInt(arrSty[2]);
			
			var n=node;
			
			if (arrSty[3]) {
				borderColor=arrSty[3];
			} else {
				borderColor=n.style.backgroundColor;
			}
						
			if (parseInt(n.offsetWidth)!=0){  
			
				elWidth=n.offsetWidth;
				elHeight=n.offsetHeight;
				
			} else {  //ROUTINE TO DETERMINE SIZE OF display:none ELEMENTS
			
				var elTemp=document.createElement('div');
				elTemp.style.position='absolute';
				elTemp.style.visibility='hidden';
				document.body.insertBefore(elTemp,document.body.firstChild);
				nodeTemp=n.cloneNode(true);
				elTemp.appendChild(nodeTemp);
				elWidth=nodeTemp.offsetWidth;
				elHeight=nodeTemp.offsetHeight;
				elTemp.parentNode.removeChild(elTemp);
			
			}
			
			if (sty=='round'){
			
				var newDiv=document.createElement('div');
				newDiv.style.width=elWidth+(!document.all?0:0)+'px';
				newDiv.style.styleFloat=n.style.styleFloat;
				newDiv.style.cssFloat=n.style.cssFloat;
				newDiv.style.marginLeft=n.style.marginLeft;
				newDiv.style.marginRight=n.style.marginRight;
				newDiv.style.marginTop=n.style.marginTop;
				newDiv.style.marginBottom=n.style.marginBottom;
				newDiv.style.position=n.style.position==''?'relative':n.style.position;
				newDiv.style.top=n.style.top;
				newDiv.style.left=n.style.left;
				
				for (i=cornerRadius;i>=0;i--){
					var newLine=document.createElement('div');
					newLine.style.height='1px';
					newLine.style.overflow='hidden';
					newLine.style.position='relative';
					newLine.style.zIndex='10';
					var mrgn=cornerRadius-Math.cos(Math.asin(i/cornerRadius))*cornerRadius;
					newLine.style.margin='0px ' + mrgn + 'px';
					newLine.style.backgroundColor=borderColor;
					newDiv.appendChild(newLine);	
				}
				
				var orig=n.cloneNode(true);
				orig.style.position='relative';
				orig.style.top='0px';
				orig.style.left='0px';
				orig.style.width='100%'
				orig.style.marginLeft='0px';
				orig.style.marginRight='0px';
				orig.style.marginTop='0px';
				orig.style.marginBottom='0px';
				orig.style.cssFloat='';
				orig.style.styleFloat='';
				newDiv.appendChild(orig);
				
				for (i=1;i<=cornerRadius;i++){
					var newLine=document.createElement('div');
					newLine.style.height='1px';
					newLine.style.overflow='hidden';
					newLine.style.position='relative';
					var mrgn=cornerRadius-Math.cos(Math.asin(i/cornerRadius))*cornerRadius;
					newLine.style.margin='0px ' + mrgn + 'px';
					newLine.style.backgroundColor=borderColor;
					newDiv.appendChild(newLine);	
				}

				n.parentNode.replaceChild(newDiv,n);
				
				if (shadowOffset!=0){
				
					if (document.all && !window.opera){
						var shad=newDiv.cloneNode(true);
						shad.style.position='absolute';
						shad.style.marginLeft='0px';
						shad.style.marginRight='0px';
						shad.style.marginTop='0px';
						shad.style.marginBottom='0px';
						shad.style.top=-shadowOffset/2+'px';
						shad.style.left=-shadowOffset/2+'px';
						shad.style.filter='progid:DXImageTransform.Microsoft.Blur(PixelRadius="'+shadowOffset+'", MakeShadow="true", ShadowOpacity="0.50")';
						newDiv.insertBefore(shad,newDiv.firstChild);
					} else {
						var shad=newDiv.cloneNode(true);
						shad.style.marginLeft='0px';
						shad.style.marginRight='0px';
						shad.style.marginTop='0px';
						shad.style.marginBottom='0px';
						var allDivs=shad.getElementsByTagName('div');
						for (i=0;i<allDivs.length;i++){
							allDivs[i].style.backgroundColor='black';
						}
						shad.style.position='absolute';
						shadowOffset+=5;
						for (x=1;x<=shadowOffset;x++){
							var shad2=shad.cloneNode(true);
							shad2.style.top=x+'px';
							shad2.style.left=x+'px';
							shad2.style.opacity=1/(3*x);
							newDiv.insertBefore(shad2,newDiv.firstChild);
						}
					}
				}
				
			}

		  }
		  
	}

function displayPR(objNum){
	var objStat=document.getElementById('pr'+objNum).style.display;
	var switchStat=document.getElementById('PRswitch'+objNum).innerHTML;
	document.getElementById('pr'+objNum).style.display=objStat=='block'?'none':'block';
	document.getElementById('PRswitch'+objNum).innerHTML=switchStat=='[ CLOSE ]'?'[ VIEW ]':'[ CLOSE ]';
}

/*------------------------------ZOOM OVERLAY SCRIPT -------------------------*/

var pdfAdder=0;

function getZoom(url,action){
	pdfAdder=url.indexOf('.pdf')==-1?0:30;
	var size=openOverlay();
	var ifr=document.createElement('iframe');
	ifr.frameBorder='0';
	ifr.style.width=size[0]+'px';
	ifr.style.height=size[1]+'px';
	//if (url.indexOf('http://')==-1&&url.indexOf('_returnDetails.cfm?id=')==-1) url='http://'+url;
	ifr.src=url;
	ifr.id='newFrame';
	ifr.name='newFrame';
	document.getElementById('rolodex').insertBefore(ifr,document.getElementById('rolodex').firstChild);
	var closer=document.createElement('div');
	
	var button=document.createElement('input');
	button.type='button';
	button.value='Close';
	button.id='histCloser';
	button.onclick=function(){showLess()};

	var button2=document.createElement('input');
	button2.type='button';
	button2.value='Print';
	button2.id='histPrinter';
	button2.style.float='left';
	button2.style.display='none';
	button2.onclick=function(){printHist()};

	var button3=document.createElement('input');
	button3.type='button';
	button3.value='Create PDF';
	button3.id='makePDF';
	button3.style.float='left';
	button3.style.display='none';
	button3.onclick=function(){createPDF()};

	var button4=document.createElement('input');
	button4.type='button';
	button4.value='Calendar';
	button4.id='showCalendar';
	button4.style.float='left';
	button4.style.display='none';
	button4.onclick=function(){
		window.top.frames[0].location.href='calendar.cfm';
		//window.top.document.getElementById('showCalendar').style.display='none';
	};

	if (url.indexOf('.pdf')==-1){
		closer.style.position='relative';
	} else {
		closer.style.position='relative';
	}
	
	closer.style.top='0px';
	closer.id='closerHolder';
	//closer.style.width='100%';
	closer.style.left='0px';
	closer.style.backgroundColor='#CCCCCC';
	closer.style.border='1px solid #000000';
	closer.style.padding='2px';
	closer.style.textAlign='right';
	
	closer.appendChild(button4);
	closer.appendChild(button3);
	closer.appendChild(button2);
	closer.appendChild(button);
	
	if (action=='makePDF'||action=='makeCalendar') button3.style.display='inline';
	if (action=='makeCalendar') button4.style.display='inline';

	document.getElementById('rolodex').insertBefore(closer,document.getElementById('rolodex').firstChild);
}

			function openOverlay(){
					if (window.pageYOffset) prevScroll=window.pageYOffset;
			
					document.documentElement.style.overflow='hidden';
					window.scrollBy(0,1);
					if (document.documentElement.scrollTop==0){
						document.body.style.overflow='hidden';
					}
			
					var w=document.body.clientWidth;
					var h=document.body.clientHeight;
			
					var card=document.createElement('div');
					card.id='rolodex';
					with (card.style){
						overflow='auto';
						backgroundColor='white';
						border='20px #1A4E76 solid';
						position= 'absolute';
						zIndex=201;
						top=(window.pageYOffset ? (window.pageYOffset) : (document.documentElement.scrollTop!=0?document.documentElement.scrollTop:document.body.scrollTop))+70+'px';
						left=(w/2-(w-260)/2)+'px';
						//top='70px';
						//width = (w-190) + 'px';
						//height=(h-200) + 'px';
						width = (w-300) + (isLTIE7*40) + 'px';
						height=(h-200) + pdfAdder + (isLTIE7*40) + 'px';
					}
					var size=new Array()
					size[0]=w-300;
					size[1]=h-230;
					
					document.body.insertBefore(card,document.body.firstChild);
			
					var screener=document.createElement('div');
					screener.id='screen2';
					with (screener.style){
						position='absolute';
						top=(window.pageYOffset ? (window.pageYOffset) : (document.documentElement.scrollTop!=0?document.documentElement.scrollTop:document.body.scrollTop))+'px'
						left='0px';
						width=w+30+'px';
						height=h+10+'px';;
						backgroundColor='black';
						filter='alpha(opacity=50)';
						opacity='0.50';
						display='block';
						zIndex=200;
					}
					document.body.insertBefore(screener,document.getElementById('rolodex'));
					document.getElementById('rolodex').style.overflow='hidden';
					setTimeout('setResize()',1000);
					return size;
			}
			
			function setResize(){
					window.onresize=function(){showLess()};	
			}
			
			function showLess(action){
					window.onresize=null;
					//document.getElementById('screen2').style.display='none';
					document.body.removeChild(document.getElementById('rolodex'));
					if (document.getElementById('screen2')) document.body.removeChild(document.getElementById('screen2'))
					
					document.documentElement.style.overflow='auto';
					window.scrollBy(0,1);
					if (document.documentElement.scrollTop==0){
						document.body.style.overflow='auto';
					}
					
					if (typeof prevScroll!='undefined' && prevScroll!=0) window.scrollTo(0,prevScroll);
					if (action=='reloadHist'){
							srvrConnect.open('post','_returnHistory.cfm',0);
							srvrConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
							srvrConnect.send();
							document.getElementById('historyHolder').innerHTML=srvrConnect.responseText;
					}
			}

function printHist(){
	window.top.frames[0].focus();
	window.top.frames[0].print();
}
function createPDF(){
	window.top.frames[0].document.workOrder.submit();
}
function showButtons(){
	window.top.document.getElementById('showCalendar').style.display='inline';
}


window.onload=function() {resizeDnB(); setup();};

