/* **************************************************************************************
	written by Robert Overman
	11/08/2001
	This function checks the number of characters typed into a <textarea>. When MaxNum is
	reached, no additional characters can be entered.
		
	syntax: onKeyDown="MaxAllowedStop(this,1);"
	************************************************************************************* */
function MaxAllowedStop(ctrl, MaxNum)
{
	//alert('Running MaxAllowed()');
	//alert('ctrl.type=' + ctrl.type);
	var Str = '';
	event.cancelbubble = true;
	switch(ctrl.type)
	{
		case 'textarea':
			Str = ctrl.innerText;
			break;
		default:
			Str = ctrl.value;
	}
	//Check length on input and make sure <TAB> was not the key pressed
	if(Str.length >= MaxNum && ((event.keyCode > 32 && event.keyCode < 222) || event.keyCode == 0))
	{
		switch(ctrl.type)
		{
			case 'textarea':
				ctrl.innerText = Str.substring(0,MaxNum-1);
				break;
			default:
				ctrl.value = Str.substring(0,MaxNum-1);
		}
	}
}
// **************************************************************************************

function openNewWindow(fileName,windowName,theWidth,theHeight,theLeft,theTop)
{
	if (windowName == "newMessageWindow") 
		{
		//generate random window ID
		 windowName = new String(Math.round(Math.random() * 100000));
		}
	var childwindow = window.open(fileName,windowName,"dependent, alwaysRaised, toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+theWidth+",height="+theHeight)
	var ScreenWidth = window.screen.width;
	var ScreenHeight = window.screen.height;
	if(theLeft>0 && theTop>0)
		{
		if(theLeft+theWidth>ScreenWidth)
			theLeft = (ScreenWidth-theWidth)/2;
		if(theTop+theHeight>ScreenHeight)
			theTop = (ScreenHeight-theHeight)/2;
		try
			{
			childwindow.moveTo(theLeft, theTop);
			}
		catch(e)
			{
			}
		}
	return childwindow;
}
 
 
function CloseTaxWindow()
    {
    close();
    }
 
 
function openNewWindow3(fileName,windowName,theWidth,theHeight,theLeft,theTop)
{
	if (windowName == "newMessageWindow") 
		{
		//generate random window ID
		 windowName = new String(Math.round(Math.random() * 100000));
		}
	var childwindow = window.open(fileName,windowName,"dependent, alwaysRaised, toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+theWidth+",height="+theHeight)
	var ScreenWidth = window.screen.width;
	var ScreenHeight = window.screen.height;
	if(theLeft>0 && theTop>0)
		{
		if(theLeft+theWidth>ScreenWidth)
			theLeft = (ScreenWidth-theWidth)/2;
		if(theTop+theHeight>ScreenHeight)
			theTop = (ScreenHeight-theHeight)/2;
		try
			{
			childwindow.moveTo(theLeft, theTop);
			}
		catch(e)
			{
			}
		}
	return childwindow;
}

function openNewWindow2(fileName,windowName,theWidth,theHeight,theLeft,theTop)
{
	if (windowName == "newMessageWindow") 
		{
		//generate random window ID
		 windowName = new String(Math.round(Math.random() * 100000));
		}
	var childwindow = window.open(fileName,windowName,"dependent, alwaysRaised, toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+theWidth+",height="+theHeight)
	var ScreenWidth = window.screen.width;
	var ScreenHeight = window.screen.height;
	if(theLeft>0 && theTop>0)
		{
		if(theLeft+theWidth>ScreenWidth)
			theLeft = (ScreenWidth-theWidth)/2;
		if(theTop+theHeight>ScreenHeight)
			theTop = (ScreenHeight-theHeight)/2;
		try
			{
			childwindow.moveTo(theLeft, theTop);
			}
		catch(e)
			{
			}
		}
	return childwindow;
}

//var intTimeOut = 60;
var intTimeOutNew = 120;
var intSessionTimeNew = intTimeOutNew * 60;
function SessionTimer()
{
	if(window.ActiveXObject){	
	intSessionTimeNew--;
	if (intSessionTimeNew == 600)
	{
		alert('You have 10 minutes left on this page before the system will log you out.');
	}
	if (intSessionTimeNew == 0)
	{
		alert('Your session has timed out. You must login to the system.');
		location.href = "/logoff.asp?timeout=1"; //go to the login page
	}
	window.status = "Session Time Remaining..." + parseInt(intSessionTimeNew / 60.0) + ":" + (intSessionTimeNew % 60);
	setTimeout('SessionTimer();',1000);
	}
}

function SessionTimerReset()
{
	intSessionTimeNew = intTimeOutNew * 60;
} 
function openNewWindowFinan(fileName,windowName,theWidth,theHeight,theLeft,theTop)
{
	if (windowName == "newMessageWindow") 
		{
		//generate random window ID
		 windowName = new String(Math.round(Math.random() * 100000));
		}
	var childwindow = window.open(fileName,windowName,"dependent, alwaysRaised, toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width="+theWidth+",height="+theHeight)
	var ScreenWidth = window.screen.width;
	var ScreenHeight = window.screen.height;
	if(theLeft>0 && theTop>0)
		{
		if(theLeft+theWidth>ScreenWidth)
			theLeft = (ScreenWidth-theWidth)/2;
		if(theTop+theHeight>ScreenHeight)
			theTop = (ScreenHeight-theHeight)/2;
		try
			{
			childwindow.moveTo(theLeft, theTop);
			}
		catch(e)
			{
			}
		}
	return childwindow;
}
function getAgentCentralPhoto(agent_id, type, reload){
	var sReloadCode = '';
	if(reload==1)
		sReloadCode = '&reload=1';
	
	var sTypeCode = '';
	if(type!='')
		sTypeCode = '&orig=start&type=' + type;
	
	openNewWindow('http://www.njmls.com/agentcentral/index.cfm?action=frm.uploadagentphoto&uidvalue' + agent_id + '=', 'newMessageWindow',800,600,200,90);
	//openNewWindow('http://agents.readvantage.com/agents/pup/uploadagentphoto.cfm?&UIDVALUE=' + agent_id , 'newMessageWindow',800,600,200,90);
	//openNewWindow('http://agents.readvantage.com/', 'newMessageWindow',800,600,200,90);
	return;
}
	
function getPhoto(agent_id,type,reload)
{
	var sReloadCode = '';
	if(reload==1)
		sReloadCode = '&reload=1';
	
	var sTypeCode = '';
	if(type!='')
		sTypeCode = '&orig=start&type=' + type;
	
	openNewWindow(protocol + domain + '/wizards/photo/wiz_addphotowhich.asp?opcode=add&agent_id=' + agent_id + sReloadCode + sTypeCode,'newMessageWindow',400,400,200,90);
	return;
}

function getPhoto2(agent_id,type,reload)
{
	var sReloadCode = '';
	if(reload==1)
		sReloadCode = '&reload=1';
	
	var sTypeCode = '';
	if(type!='')
		sTypeCode = '&orig=start&type=' + type;
	
	openNewWindow(protocol + domain + '/wizards/photo/wiz_addphotowhich2.asp?opcode=add&agent_id=' + agent_id + sReloadCode + sTypeCode,'newMessageWindow',400,400,200,90);
	return;
}


function getPhoto3(agent_id,office_id,board_id,mls_id)//change to put new photo logic back
{
	var height = 550;
	var width = 495;
	var top = parseInt((screen.height-height)/2) - 30;
	var left = parseInt((screen.width-width)/2);
	var sURL = protocol + domain + '/wizards/photo2/PhotoWizard.aspx?mlsid=' + mls_id + '&boardid=' + board_id + '&officeid=' + office_id + '&agentid=' + agent_id;
		
	//openNewWindow(sURL,'newMessageWindow',width,height,left,top);
	var vReturn = window.showModalDialog(sURL,"center:Yes;dialogHeight:" + height + "px;dialogWidth:" + width + "px;status:no;resizable:no");
	if(vReturn > 0)
		window.location.reload();
}

function BugReport()
{
	openNewWindow(protocol + domain + '/tools/bug_report/bug_report.asp','Finan',405,358,0,0);
}
function SocalCalc()
{
//	openNewWindowFinan(protocol + domain + '/Java/index.html','newMessageWindow',775,600,0,0);
	openNewWindowFinan(protocol + domain + '/Java/index.asp','newMessageWindow',775,600,0,0);//48670 - 3055 track usage can't do that in a htm
}

function OpenTax()
{
	openNewWindowFinan(protocol + domain + '/OpenTax.asp','newMessageWindow',775,600,0,0);
}

function OpenMLSALL()
{
	openNewWindowFinan(protocol + domain + '/OpenMLS.asp','newMessageWindow',750,600,0,0);
}
function OpenAdd() //call rex listing maint add
{
	openNewWindowFinan(protocol + domain + '/OpenAdd.asp','newMessageWindow',775,600,0,0);
}
var xWin=null; var ticks=6;

function CheckPop(){
 StartPopup();
// window.focus();
} 
function StartPopup(){
 xWin=window.open(protocol + domain + "/pop.htm#abc");
 //setTimeout("test_xWin()",700);
 test_xWin()
}
function test_xWin(){
  if ( (xWin==null)
     ||(typeof(xWin)=="undefined")
     ||(typeof(xWin.location.hash)!="string")
     ){
     sMsg="A popup blocker is currently running.\nYou can not perform many Listing Load functions if pop-ups from this site are blocked\nIf you see a yellow bar above, click on it and click on\nAllways Allow Pop-ups from this Site...";  
     alert(sMsg);
     }else{
     xWin.close();
     }
  //window.focus();

}

function OpenPro() //call rex prospect list
{
	CheckPop();
	openNewWindowFinan(protocol + domain + '/OpenPro.asp','newMessageWindow',775,600,0,0);
}

function OpenChg() //call rex listing maint chg
{
	openNewWindowFinan(protocol + domain + '/OpenChg.asp','newMessageWindow',775,600,0,0);
}

function OpenForms()
{
	openNewWindowFinan(protocol + domain + '/OpenForms.asp','newMessageWindow',750,575,0,0);
}

function logoff()
{
	 var a = confirm("Are you sure you want to exit the ParagonXL System? Click OK to logoff, or click Cancel to return to ParagonXL.");
	 if(a)
		top.location.href = protocol + domain + "/Logoff.asp";
}

function openNewMapWindow(fileName,windowName,theWidth,theHeight,theLeft,theTop)
{
	if (windowName == "newMessageWindow") 
		{
		//generate random window ID
		 windowName = new String(Math.round(Math.random() * 100000));
		}
	var childwindow = window.open(fileName,windowName,"dependent, alwaysRaised, toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+theWidth+",height="+theHeight)
	var ScreenWidth = window.screen.width;
	var ScreenHeight = window.screen.height;
	if(theLeft>0 && theTop>0)
		{
		if(theLeft+theWidth>ScreenWidth)
			theLeft = (ScreenWidth-theWidth)/2;
		if(theTop+theHeight>ScreenHeight)
			theTop = (ScreenHeight-theHeight)/2;
		try
			{
			childwindow.moveTo(theLeft, theTop);
			}
		catch(e)
			{
			}
		}
}

function ValidateEmail(thisform)
{
	//alert(thisform.SenderEmail.options[thisform.SenderEmail.selectedIndex].text)
	if(thisform.SenderEmail.type == "text"){
		if(thisform.Email1.value == '' && thisform.Client1.selectedIndex < 1 && thisform.Email2.value == '' && thisform.Client2.selectedIndex < 1)
		{
			alert('Please select a recipient for this report.');
			return false;
		}
		else if(thisform.SenderEmail.value == '')
		{
			alert("Please enter the sender's e-mail address in the Your E-Mail box.");
			return false;
		}
		else
			return true;
	}
	else
	{
		if(thisform.Email1.value == '' && thisform.Client1.selectedIndex < 1 && thisform.Email2.value == '' && thisform.Client2.selectedIndex < 1)
		{
			alert('Please select a recipient for this report.');
			return false;
		}
		if(thisform.SenderEmail.options[thisform.SenderEmail.selectedIndex].text == '')
		{
			alert("Please enter the sender's e-mail address in the Your E-Mail box.");
			return false;
		}
		//added per bug 8162
		if (!CheckEmail(thisform.SenderEmail.options[thisform.SenderEmail.selectedIndex].text))
		{
			alert("Please enter a valid email address in \"Your E-Mail\" box.");
			thisform.SenderEmail.focus();
			return false;
		}
		//end bug 8162
		else
			return true;
	}
}

function Capitalize(ctrl)
{
	if(event.keyCode != 9 && event.keyCode != 8) // only if not <TAB> or <BKSPC>
	{
		//alert('event.keyCode=' + event.keyCode);
		if(Trim(ctrl.value) != '')
		{
			var str = ctrl.value;
			str = str.toUpperCase();
			ctrl.value = str;
		}
	}
}

function CapitalizeTextArea(ctrl)
{
	if(event.keyCode != 9 && event.keyCode != 8) // only if not <TAB> or <BKSPC>
	{
		//alert('event.keyCode=' + event.keyCode);
		//alert('shiftKey=' + event.shiftKey);
		if(Trim(ctrl.innerText) != '')
		{
			var str = ctrl.innerText;
			str = str.toUpperCase();
			ctrl.innerText = str;
		}
	}
}

function ValidateEmailAddr(ctrl)
{
	var sAddress = ctrl.value;
	sAddress = sAddress.toLowerCase();
	if(sAddress.length == 0)
		return true;
	if(sAddress.indexOf("'") > 0)
	{
		alert('Apostrophes and Single Quotes are not valid in email addresses.');
		ctrl.select();
		return false;
	}
	if(sAddress.indexOf("@") < 1)
	{
		alert('The @ must be included in any email address.');
		ctrl.select();
		return false;
	}
	if(sAddress.indexOf(" ") > 0)
	{
		alert('Blank Spaces are not allowed in any email address.');
		ctrl.select();
		return false;
	}
	if(sAddress.indexOf(".com") < 2 && sAddress.indexOf(".cc") < 2 && sAddress.indexOf(".net") < 2 && sAddress.indexOf(".org") < 2 && sAddress.indexOf(".edu") < 2 && sAddress.indexOf(".us") < 2 && sAddress.indexOf(".biz") < 2 && sAddress.indexOf(".info") < 2 && sAddress.indexOf(".tv") < 2 && sAddress.indexOf(".ws") < 2 && sAddress.indexOf(".bz") < 2)
	{
		if(sAddress.indexOf(".") < 1)
		{
			alert('A valid email address must include an extension such as .com or .net.\nPlease verify the address and try again.');
			ctrl.select();
			return false;
		}
		else
		{
			if(confirm("The address you entered, '" + sAddress + "' does not have \na recognized Global or US Top Level Domain extension such as .com or .net.\nIs this an international address?."))
				return true;
			else
			{
				ctrl.select();
				return false;
			}
		}
	}
	return true;
}
function getPhoto2(agent_id,office_id,board_id,mls_id)//change to put new photo logic back
{
	var height = 550;
	var width = 495;
	var top = parseInt((screen.height-height)/2) - 30;
	var left = parseInt((screen.width-width)/2);
	var sURL = protocol + domain + '/wizards/photo2/PhotoWizard.aspx?mlsid=' + mls_id + '&boardid=' + board_id + '&officeid=' + office_id + '&agentid=' + agent_id;
	var vReturn;		
	openNewWindow(sURL,'newMessageWindow',width,height,left,top);
//	var vReturn = window.showModalDialog(sURL,"center:Yes;dialogHeight:" + height + "px;dialogWidth:" + width + "px;status:no;resizable:no");
	if(vReturn > 0)
		window.location.reload();
}
