//																 //
// START: Required for the IMAGE PRELOAD and SWAPPING OF IMAGES  //
//																 //
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
//																 //
// END: Required for the IMAGE PRELOAD and SWAPPING OF IMAGES    //
//																 //


// START : Code for the BUTTON's MOUSEOVER & MOUSEOUT effects
var i=0;		// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
var ie=(document.all)?1:0;
var ns=(document.layers)?1:0;
function initStyleElements()
{
	var a = document.frm;
	if (ie)
	{
		//a.text.style.backgroundColor="#666666";
		a.submit.style.backgroundColor="#005BC1";
		a.submit.style.cursor="hand";
		//a.clear.style.backgroundColor="#C0C0A8";
		//a.clear.style.cursor="hand";
	}
	else return;
}
function LightOn(what)
{
	if (ie) what.style.backgroundColor = '#004EA6';
	else return;
}
function LightOff(what)
{
	if (ie) what.style.backgroundColor = '#005BC1';
	else return;
}
	// END : Code for the BUTTON's MOUSEOVER & MOUSEOUT effects


	// START: TEXTBOXES/CONTROLS VALIDATION - CHANGE COLOR FOR CONTROLS
	function validateOnBlur(e)
	{
		e.className='blur'; 
		if(e.value=='' || e.value==0)
			e.className='required';
	}

	function validateOnFocus(e)
	{
		e.className='focus';
	}
	// END  : TEXTBOXES/CONTROLS VALIDATION - CHANGE COLOR FOR CONTROLS



	/** START ::: LAUNCH POP-UP WINDOWS ELEGANTLY **/
	var newwin;
	function popupwindow(winurl,winname,winfeatures)
	{
		//This launches a new window and then focuses it if window.focus() is supported.
		newwin = window.open(winurl,winname,winfeatures);
		if(javascript_version > 1.0)
		{
			//delay a bit here because IE4 encounters errors when trying to focus a recently opened window
	 		setTimeout('newwin.focus();', 250);
		}
	}

	function printPage()
	{
		window.print();
	}
	
	function openNewWin()
	{	
		
		//var newWin= window.open("print.php","print.php", "height=900,width=580,no,no,scrollbars,resizable,no,no,status=0");
		var newWin =window.open('','windowname2','width=580,height=900,directories=no,location=no,menubar=no,resizable=no,scrollbars=1,status=no,toolbar=no');
		newWin.document.write("<html><body style=\"margin:0px;padding:0px;\">");
		newWin.document.write("<div style=\"text-align:right;padding:3px;padding-right:15px;\"><INPUT TYPE=\"image\" NAME=\"Close\" VALUE=\" \"  src=\"https://www.rentalprotectionagency.com/images/close.gif\" onClick=\" window.close()\";></div>"); 
		newWin.document.write("<div style=\"padding-left:15px;text-align:center;\">");
		newWin.document.write(document.getElementById('printPage').innerHTML);
		newWin.document.write("</div>");
			newWin.document.write("</body></html>");
//		newWin.document.write(" " + "<br>");
		newWin.document.close;
		newWin.window.print();
		
	}
	
	function openNewMail()
	{
		
		var email_text = "";
		email_text  += '<br /><br /><table width="100%" border="0" height="40" cellspacing="0" cellpadding="0" bgcolor="#f7f7f7">'
		email_text +=	'<tr>';	
		email_text +=	'  	<td colspan="3"></td>';
		email_text +=	'</tr>';
		email_text +=	'<tr>';
		email_text +=	'	<td><strong>Please Enter Email</strong></td>';
		email_text +=	'		<td>';
		email_text +=	'			<input type="text" name="emailName"  id="emailName"  style="width:250px;" />';
		email_text +=	'	 	</td>';
		email_text +=	'		<td>';
		email_text +=	'			<input value="Send" class="ajaxButton" type="submit" />';
		email_text +=	'		</td>';
		email_text +=	' </tr>';
		email_text += '</table>';

		
		var newWin = window.open("print.php", "SendEmail", "height=300,width=500,no,no,scrollbars,resizable,no,no,status=0,top=100,left=350");

		newWin.document.write("<div style=\"text-align:right;padding:3px;padding-right:15px;\"><INPUT TYPE=\"image\" NAME=\"Close\" VALUE=\" \"  src=\"https://www.rentalprotectionagency.com/images/close.gif\" onClick=\" window.close()\";></div>"); 
		//newWin.document.write(document.getElementById('printPage').innerHTML);
		newWin.document.write(" " + "<br>");
		newWin.document.write("<form action='bg_emailsent.php' method='post'>");
		
		newWin.document.write(email_text);
		
		newWin.document.write("<div style='display:none;'><textarea name='txtEmail'>"+document.getElementById('printPage').innerHTML+"</textarea></div></form>");
		newWin.document.write("</form>");
		//newWin.document.close;
		//newWin.window.print();
		
	}



function xmlhttpPost(strURL)
 {
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) 
		{
        	self.xmlHttpReq = new XMLHttpRequest();
    	}
    else if (window.ActiveXObject) 
		{
			self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function()
	 {
		
		if (self.xmlHttpReq.readyState == 1) 
		{
            updatepage('<div style="height:10px;" ></div><table border="0" cellpadding="0" cellspacing="0" width="98%"><tr><td valign="bottom"><img src="http://www.rentalprotectionagency.com/images/box_top_left.gif" width="10" height="10" /></td><td class="box_top_bg" style="padding-bottom: 4px;" align="left" valign="bottom" width="100%">&nbsp;</td><td valign="bottom"><img src="http://www.rentalprotectionagency.com/images/box_top_right.gif"  width="10" height="10" /></td></tr><tr><td class="box_left_bg">&nbsp;</td><td class="justify" align="left" bgcolor="#f7f7f7" align="center" style="padding:5px;color:#FF0000;">Waiting ....</td><td class="box_right_bg">&nbsp;</td></tr><tr><td valign="top"><img src="http://www.rentalprotectionagency.com/images/box_bottom_left.gif"  width="10" height="10" /></td><td class="box_bottom_bg" valign="top">&nbsp;</td><td valign="top"><img src="http://www.rentalprotectionagency.com/images/box_bottom_right.gif"  width="10" height="10" /></td></tr></table>');
        }
        if (self.xmlHttpReq.readyState == 4) 
		{
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring());
	document.getElementById('toggleDivId').style.display='none';
	document.getElementById('result').style.display='block';
	InitializeTimer();
 }

function getquerystring() 
	{

		var word = document.getElementById('printPage').innerHTML;
		var emailName = document.getElementById('emailName').value;
		qstr = 'w=' + escape(word) +'&e=' + escape(emailName);  // NOTE: no '?' before querystring
		return qstr;
	}

function updatepage(str)
	{
		document.getElementById("result").innerHTML = str;
	}

function toggle()
	{
		if(document.getElementById('toggleDivId').style.display == 'none') 
		{
			document.getElementById('toggleDivId').style.display='block';
			document.getElementById('result').style.display='none';
			//InitializeTimer();
		}
		 else 
		 {
			document.getElementById('toggleDivId').style.display='none';
		}
	}

		
			var secs;											
			var timerID = null;									
			var timerRunning = false;							
			var delay = 5000;									
			function InitializeTimer()
				{
					secs = 5;											// Set the length of the timer, in seconds
					StopTheClock();
					StartTheTimer();
				}
			function StopTheClock()
				{
					if(timerRunning)
						clearTimeout(timerID);
					timerRunning = false;
				}
			
			function StartTheTimer()
				{
					if (secs==0)
					{
						StopTheClock();
						document.getElementById('result').style.display = 'none';
					}
					else
					{
						secs = secs - 1;
						timerRunning = true;
						timerID = self.setTimeout("StartTheTimer()", delay);
					}
				}
/** END ::: LAUNCH POP-UP WINDOWS ELEGANTLY **/