   
   var zipDash =  ["ncheck","ncheck","ncheck","ncheck","ncheck","ncheck","ncheck"]
var NextImageName = 'NEW';
var lastobjectName = new Object();

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

function formatPhone(inputString){
	if (isEmpty(inputString)){
		return "";
	}
	inputString = cleanPhone(inputString)
	if (inputString.length >= 10){
		areaCode = inputString.substr(0,3)
		prefix = inputString.substr(3,3)
		postfix = inputString.substr(6,10)
		outputString = '('+areaCode+') '+prefix+'-'+postfix
	}else if (inputString.length == 7) {
		areaCode = ''
		prefix = inputString.substr(0,3)
		postfix = inputString.substr(3,7)
		outputString = '('+areaCode+') '+prefix+'-'+postfix	
	}else{
		outputString = '';
	}
	return outputString
}

function formatPhoneO(input){
	input.value = formatPhone(input.value)
	
}
var phoneformat = ["(DDD) DDD-DDDD"]
function verify(str,index){
	format = phoneformat[index]
	if (isEmpty(str)){
		return true
	}
	if (str.length != format.length){
		return false
	}
	i = 0
	for (i = 0 ;i < str.length; i++){
		fchar = format.charAt(i)
		schar = str.charAt(i)
		if (! isDigit(schar)){
			//alert ("failed is digit " + schar)
		}else {
			//alert ("passwd is digit " + schar)
		}
		if (!(((fchar == 'D') && isDigit(schar)) || (schar == fchar))) {
			return false
		}
	}
	return true
}

function verifyPhone(data){
	if (! verify(data.value,0)){
		alert("Invalid Phone Supplied")
		data.select()
		data.focus()
	}
}
function checkPhone(data,maxLength){
	str = data.value
	if (isEmpty(data.value)){
		return
	}
	strLen = str.length
	change = false
	//alert("test "+strLen)
	if (strLen == 0){
		return
	}
	
	for (var i = 0;i < strLen;i++){
		//alert("test "+i)
		thisChar = str.charAt(i)
		if (thisChar == '('){
				if ((str.charAt(i+1) == '(') || (i > 2)){
					change = true
					str = str.substr(0,i) +  str.substr(i+1,15)
					i-=2;	
				}	
		}else if (thisChar == ')'){
				if ((str.charAt(i+1) == ')') || (i > 5)){
					
					change = true
					str = str.substr(0,i) +  str.substr(i+1,15)
					i-=2;	
				}	
		}else if (thisChar == ' '){
				if ((str.charAt(i+1) == ' ') || (i > 6)){
					change = true
					str = str.substr(0,i) +  str.substr(i+1,15)
					i-=2;	
				}	
		}else if (thisChar == '-'){
				if ((str.charAt(i+1) == '-') || (i > 10)){
					
					change = true
					str = str.substr(0,i) +  str.substr(i+1,15)
					i-=2;	
				}	
		}
		if (( i == 0) && (thisChar != '(')){
				change = true
				str =  '(' + str
				i--;
			
		}else if (( i == 4) && (thisChar != ')')){
				change = true
				str = str.substr(0,i) + ')' + str.substr(i,15);
				i--;
			
		}else if (( i == 5) && (thisChar != ' ')){
				change = true
				str = str.substr(0,i) + ' ' + str.substr(i,15);
				i--;
			
		}else if (( i == 9) && (thisChar != '-')){
				change = true
				str = str.substr(0,i) + '-' + str.substr(i,15);
				i--;
			
		}
	}
	if (str.length > 14){
		change = true
		str = str.substr(0,14)
	}
	if (change){
		data.value = str;	
	}
}


function tabOnload(){
	if (parent.frames['AddEditTabWindow'].document.forms[0].closeType.value  != 'Saved'){
		window.event.returnValue = "Your changes will be discarded.\nPlease use Close."
	}
	//window.event.returnValue = "The changes you have made will be lost."

}

function propertyFocus(){
	//window.sleep(5000)
	//document.form[0].StreetNo.select();
	//document.form[0].StreetNo.focus(); 
}


var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;
function manageZip(dateText,index){
	if (netscape){
		return
	}
	object = dateText
	firstInsert = zipDash[index]
	if (initialZip == object.value){
		return
	}
	str = object.value
	strLen = str.length
	dateText = str
	firstChar = dateText.substr(0,1)
	if ((str.length > 0) && (firstChar >= 0) &&  (firstChar <= 9) ){
		breakPoint = 5
		maxLen = 10
	}else{
		breakPoint = 3
		maxLen = 7
	}
		if ( (strLen == breakPoint) && (strLen > lastLength)){
			firstInsert = "check"
			object.value = dateText + "-"
		}else if ((strLen == breakPoint) && (strLen < lastLength)){
			firstInsert = "ncheck"
			object.value = dateText.substr(0,strLen - 1 )
		
		}else if ((strLen == breakPoint) && (strLen < lastLength)){
			firstInsert = "ncheck"
			object.value = dateText.substr(0,strLen - 1 )
		
		}else if ((strLen > maxLen) &&  (firstInsert == "check")){
			object.value = str.substr(0,maxLen)
		}
	
		if ( (strLen > breakPoint) && (firstInsert == "ncheck") ){
			firstInsert = "check"
			object.value = str.substr(0,breakPoint) + "-" + str.substr(breakPoint,(maxLen-breakPoint)-1)	
		}
	
	lastLength = object.value.length
	zipDash[index]  = firstInsert 
	
}

function changeRef(filename){
	frm = document.forms[0]
	frm.dbString.value = parent.frames['bulletinwindow'].document.tAgentInfo.dbString.value
	frm.reportfile.value = filename
	frm.officeInfo.value = parent.frames['bulletinwindow'].document.tAgentInfo.officeInfo.value
	frm.szWebCode.value =  parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value
	frm.agentName.value = parent.frames['bulletinwindow'].document.tAgentInfo.agentName.value 
	frm.tszAgentCode.value = parent.frames['bulletinwindow'].document.tAgentInfo.tszAgentCode.value
	//Parent.frames["mainwindow"].location.href = "agentworkstation.dll/menufileload?agentName="+parent.frames['bulletinwindow'].document.tAgentInfo.agentName.value +"&tszAgentCode="+parent.frames['bulletinwindow'].document.tAgentInfo.tszAgentCode.value +"&dbString=" +parent.frames['bulletinwindow'].document.tAgentInfo.dbString.value +"&reportfile=" + filename + "&szWebCode=" + parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value + "&officeInfo="+parent.frames['bulletinwindow'].document.tAgentInfo.officeInfo.value;
	
	frm.submit()
}

function LoadfdmPage(filename,args){
//alert("/Agentworkstation/"+ filename + "?szWebCode=" + parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value + args);
	//alert("/Agentworkstation/"+ filename + "?dbString=" +parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value+"&szWebCode=" + parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value + args")
	parent.frames["mainwindow"].location.href = filename + "?dbString=" +parent.frames['bulletinwindow'].document.tAgentInfo.dbString.value+"&szWebCode=" + parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value + args;
}

function checkLogin(newUrl){

	alert('COMMON')

	if (parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value != ""){
		alert(newURL)
		parent.frames['menuWindow'].location.href = newUrl
		parent.frames['mainwindow'].location.href = "blank.html "
	
		
	}
	//alert(parent.frames['menuWindow'].location.href)
}


function checkLogin2(newUrl){

	//if (parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value != ""){
		parent.frames['mainwindow'].location.href = newUrl
		parent.frames['menuWindow'].location.href = "blank.html "
	
		
	//}
	//alert(parent.frames['menuWindow'].location.href)
}

function setDate(input){
	if (input.value != ''){
		return;
	}	
	todaysDate = new Date();	
	day = todaysDate.getDate();
	month = todaysDate.getMonth() + 1;
	year = todaysDate.getYear();
	if (day <= 9){ day = '0' + day; }
	if (month <= 9){month = '0' + month; }
	if (year < 1900 ) { year += 1900; }	
	dateString = month +'/'+ day +'/'+ year;
	input.value = dateString
}

function setTodaysDate(input){
	todaysDate = new Date();	
	day = todaysDate.getDate();
	month = todaysDate.getMonth() + 1;
	year = todaysDate.getYear();
	if (day <= 9){ day = '0' + day; }
	if (month <= 9){month = '0' + month; }
	if (year < 1900 ) { year += 1900; }	
	dateString = month +'/'+ day +'/'+ year;
	document.forms[0].fromDate.value = dateString;
	document.forms[0].toDate.value = dateString;
	if (input == 'mls'){
		document.messagesForm.mlsNumber.focus();
	}else if(input == 'hist' ){
		document.messagesForm.items.focus()
	}else{
		document.messagesForm.fromDate.focus()
	}
	initialDate = dateString
	netscape = (navigator.appName.indexOf("Netscape") >= 0)
}
var netscape = false
var initialDate = 0
var initialZip = 0
var lastLength = '0'
var firstInsert = "notChecked"
var secondInsert = "notChecked"
var tfInsert =	"notChecked"
var tsInsert =	"notChecked"
var ffInsert =	"notChecked"
var fsInsert =	"notChecked"

var firstSlash =  [ "ncheck","ncheck","ncheck","ncheck"]
var secondSlash =  [ "ncheck","ncheck","ncheck","ncheck"]



function manageDate2(dateText,index){
	if (netscape){
		return
	}
	object = dateText
	firstInsert = firstSlash[index]
	secondInsert = secondSlash[index]
	if (initialDate == object.value){
		return;
	}
	str = object.value
	strLen = str.length
	dateText = str
	if (strLen == 0){
		firstSlash[index] = "ncheck"
		secondSlash[index] = "ncheck"
	}else if (strLen > '6' ){
		if ((str.substr(2,1) != '/') && (firstInsert != "ncheck" )){
			firstSlash[index] = "ncheck"
		}
		if ((str.substr(5,1) != '/') && (secondSlash[index] == "ncheck")){
			secondSlash[index] = "ncheck"
		}
		
	}else if (strLen < '5' ){
		secondSlash[index] = "ncheck"
	}else if (strLen < '3' ){
		firstSlash[index] = "ncheck"
	}
	if ( (strLen == "5") && (strLen > lastLength)){
		secondInsert = "check"
		object.value = dateText + "/"
	}else if ( (strLen == "2")  && (strLen > lastLength)){
		firstInsert = "check"
		object.value = dateText + "/"	
	}else if ((strLen == "5") && (strLen < lastLength)){
		secondInsert = "ncheck"
		object.value = dateText.substr(0,strLen)
		
	}else if ((strLen == "2") && (strLen < lastLength)){
		firstInsert = "ncheck"
		object.value = dateText.substr(0,strLen)
		
	}else if ((strLen > 10) &&  (firstInsert == "check") && (secondInsert == "check")){
		object.value = str.substr(0,10)
	}else if ( (strLen > "2") && (firstInsert == "ncheck") ){
		firstInsert = "check"
		object.value = str.substr(0,2) + "/" + str.substr(2,8)
		
	}else if (( strLen > "5") && (secondInsert == "ncheck") ){
		secondInsert = "check"
		object.value = str.substr(0,5) + "/" + str.substr(5,8)
	}
	lastLength = object.value.length
	firstSlash[index]  = firstInsert 
	secondSlash[index] = secondInsert 
	if (lastLength > 10){
		manageDate2(object,index)
	}
}

function manageDate(dateText,obType){
	if (netscape){
		return
	}
	
	if (obType == "from"){
		object = document.messagesForm.fromDate
		firstInsert = ffInsert;
		secondInsert = fsInsert;
		if (initialDate == object.value){
			return;
		}
	}else {
		object = document.messagesForm.toDate
		firstInsert = tfInsert;
		secondInsert = tsInsert;
		if (initialDate == object.value){
			return;
		}
	}
	str = object.value
	strLen = dateText.length
	
	if ( (strLen == "5") && (strLen > lastLength)){
		secondInsert = "checked"
		object.value = dateText + "/"
	}else if ( (strLen == "2")  && (strLen > lastLength)){
		firstInsert = "checked"
		object.value = dateText + "/"	
	}else if ((strLen == "5") && (strLen < lastLength)){
		secondInsert = "notChecked"
		object.value = dateText.substr(0,strLen - 1 )
		
	}else if ((strLen == "2") && (strLen < lastLength)){
		firstInsert = "notChecked"
		object.value = dateText.substr(0,strLen - 1 )
		
	}else if ((strLen > 10) &&  (firstInsert == "checked") && (secondInsert == "checked")){
		object.value = str.substr(0,10)
	}
	
	if ( (strLen > "2") && (firstInsert == "notChecked") ){
		firstInsert = "checked"
		object.value = str.substr(0,2) + "/" + str.substr(2,8)
		
	}
	if (( strLen > "5") && (secondInsert == "notChecked") ){
		secondInsert = "checked"
		object.value = str.substr(0,5) + "/" + str.substr(6,8)
		
	}
	lastLength = object.value.length
	if (obType == "from"){
		ffInsert = firstInsert
		fsInsert = secondInsert
	}else {
		tfInsert = firstInsert
		tsInsert = secondInsert
	}
}
// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function verifyDate(datefield){
        //alert(datefield.value)
		
    from = datefield.value
    datelength = from.length
    //alert(datelength)
	
    if (isEmpty(new String(from))){
	    return true
	}	
    month = from.substr(0,2)
    day = from.substr(3,2)
    year = from.substr(6,4)
    firstslash = from.substr(2,1)
    secondslash = from.substr(5,1)
    if (((year.length != 2) && (year.length != 4) || ((firstslash != '/') ||  (secondslash != '/')) || (datelength !=10)) || (!isInteger(year)) ){
		return false
    	}
	//if ( (day.length != 2) || !isDigit(day.charAt(0)) || !isDigit(day.charAt(1)) ){
	//	return false
	//}  
    
	if (!isDate(year,month,day)){
		return false
	}else {
		return true
	}
}

function verifyAndSubmit(myForm,formName){
	from = myForm.fromDate.value
	to	=	myForm.toDate.value
	month = from.substr(0,2)
	day = from.substr(3,2)
	year = from.substr(5,4)
	montht = to.substr(0,2)
	dayt = to.substr(3,2)
	yeart = to.substr(5,4)
	if (!verifyDate(myForm.fromDate)){
		alert("Invalid from date specified!")
		myForm.fromDate.select()
	}else if (!verifyDate(myForm.toDate)){
		myForm.toDate.select()
		alert("Invalid To date specified!")
	}else{
		openAWindowWS_tb("../waiting.html","reportWindow",770,470)
		
		myForm.submit();
		resetTimer()
	}
				
}


function verifyTime(data){
	
	str = data.value;
	if (isEmpty(str)){
		return true
	}
	hr = str.substr(0,2)
	min = str.substr(3,2)
	noon = str.substr(5,2)
	if ((min.lenth < 2 || hr.length < 2)){
		return false;
	}
	if ((isIntegerInRange(min,0,59)) && ( isIntegerInRange(hr,0,12) && ( (noon == 'AM') || (noon == 'PM')))){
		return true
	}else {
		alert("Invalid Time Supplied")
		data.select()
		data.focus()
	}
}

function confirmDate(dateField){
	if (!verifyDate(dateField)){
		alert("Date field invalid!!!")
		dateField.select()
		dateField.focus();
	}

}
function checkDate(data,maxLength){
	str = data.value
	strLen = str.length
	change = false
	//alert("test "+strLen)
	if (strLen == 0){
		return
	}
	
	for (var i = 0;i < strLen;i++){
		//alert("test "+i)
		thisChar = str.charAt(i)
		if (thisChar == '/'){
				if ((str.charAt(i+1) == '/') || (i > 5)){
					
					change = true
					//alert("first "+str.substr(0,i))
					//alert("second "+str.substr(i+1,10))
					str = str.substr(0,i) +  str.substr(i+1,10)
					i-=2;	
				}	
		}
		if ( i == 2 || i == 5){
			if (thisChar != '/'){
				change = true
				str = str.substr(0,i) + '/' + str.substr(i,10);
				i--;
			}
		}
	}
	if (str.length > 10){
		change = true
		str = str.substr(0,10)
	}
	if (change){
		data.value = str;	
	}
}

function checkTime(data,maxLength){
	str = data.value
	str = str.toUpperCase();
	strLen = str.length
	if (str != data.value){
		change = true
	}else {
		change = false
	}
	//alert("test "+strLen)
	if (strLen == 0){
		return
	}
	
	for (var i = 0;i < strLen;i++){
		//alert("test "+i)
		thisChar = str.charAt(i)
		if (thisChar == ':'){
				if ((str.charAt(i+1) == ':') || (i > 2)){
					
					change = true
					//alert("first "+str.substr(0,i))
					//alert("second "+str.substr(i+1,10))
					str = str.substr(0,i) +  str.substr(i+1,10)
					i-=2;	
				}	
		}
		if ( i == 2){
			if (thisChar != ':'){
				change = true
				str = str.substr(0,i) + ':' + str.substr(i,10);
				i--;
			}
		}

	}
	if (str.length > 7){
		change = true
		str = str.substr(0,7)
	}
	if (change){
		data.value = str;	
	}
}

function justSubmit(myForm,formName){

	openAWindowWS("../waiting.html","reportWindow",770,470)
	myForm.submit();
	resetTimer()
	
}

lastState = "unknown"
function checkRadio(radioButton){
	
	if ( lastState == "unknown" ){
		lastState = "checked"
	}else if (lastState == "checked"){
		lastState = "unchecked"
		radioButton.checked = false
	}else {
		lastState = "checked"
		radioButton.checked = true
	}
}

function check(textObject){
	str = new String(textObject.value)
	if ((str.length = '2') || (str.length = '5' )){
		textObject.value = textObject.value + "/"
	}
}

timer = ""
//timeoutValue = 5000
timeoutValue = 1500000 
function resetTimer(){
	clearTimeout(timer);
	timer = setTimeout('formTimeOut()',timeoutValue)
	//timer = setTimeout('formTimeOut()',6000)
}

function setTimeOut(){
	timer = setTimeout('formTimeOut()',timeoutValue)
	//timer = setTimeout('formTimeOut()',6000)
}

function formTimeOut(){
	clearTimeout(timer)
	top.location ="../index.html"
}

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}


// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}



// Returns true if character c is a letter or digit.

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}




// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.


function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);
	
    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, true)) return false;
	
    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    if (s.charAt(0) == '0'){
		s = s.substr(1,1)
	}
    var num = parseInt(s);
    var anum = parseInt(a);
    var bnum = parseInt(b)
    
	
    if ((num >= anum) && (num <= bnum)){
		return true
	}else {
		return false
	}
}






// isDate (STRING year, STRING month, STRING day)
//
// isDate returns true if string arguments year, month, and day 
// form a valid date.
// 


 function isDate (year, month, day)
 {   // catch invalid years (not 2- or 4-digit) and invalid months and days.
     if (! (isYear(year, true) && isMonth(month, true) && isDay(day, true))) return false;
	
     // Explicitly change type to integer to make code work in both
     // JavaScript 1.1 and JavaScript 1.2.
     var intYear = parseInt(year);
     var intMonth = parseInt(month);
    var intDay = parseInt(day);

     // catch invalid days, except for February
     if (intDay > daysInMonth[intMonth]) return false; 
     if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

     return true;
 }


// daysInFebruary (INTEGER year)
// 
// Given integer argument year,
// returns number of days in February of that year.

function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}


// isMonth (STRING s [, BOOLEAN emptyOK])
// 
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}



// isDay (STRING s [, BOOLEAN emptyOK])
// 
// isDay returns true if string s is a valid 
// day number between 1 and 31.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}



function isYear (s)
{   if (isEmpty(s))
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    return ((s.length == 2) || (s.length == 4));
}


var zipDash =  [ "ncheck","ncheck","ncheck","ncheck","ncheck","ncheck","ncheck"]
var timeDash =  [ "ncheck","ncheck","ncheck","ncheck","ncheck","ncheck","ncheck"]

function manageTime(dateText,index){
	if (netscape){
		return
	}
	object = dateText
	firstInsert = timeDash[index]
	if (initialZip == object.value){
		return
	}
	str = object.value
	strLen = str.length
	dateText = str
	firstChar = dateText.substr(0,1)
	maxLen = 8
	breakPoint = 2

		if ( (strLen == breakPoint) && (strLen > lastLength)){
			firstInsert = "check"
			object.value = dateText + ":"
		}else if ((strLen == breakPoint) && (strLen < lastLength)){
			firstInsert = "ncheck"
			object.value = dateText.substr(0,strLen - 1 )
		
		}else if ((strLen == breakPoint) && (strLen < lastLength)){
			firstInsert = "ncheck"
			object.value = dateText.substr(0,strLen - 1 )
		
		}else if ((strLen > maxLen) &&  (firstInsert == "check")){
			object.value = str.substr(0,maxLen)
		}
	
		if ( (strLen > breakPoint) && (firstInsert == "ncheck") ){
			firstInsert = "check"
			object.value = str.substr(0,breakPoint) + ":" + str.substr(breakPoint,(maxLen-breakPoint)-1)	
		}
		if ( (object.value.length > 6) && (strLen > lastLength) ){
			str = object.value
			tmStr = str.substr(0,5)
			chr = str.substr(6,1)
			//alert(chr)
			if ((chr == 'A') ||(chr == 'a')) {
				object.value = tmStr + " " + 'AM'
			}else if  ((chr == 'P') ||(chr == 'p')){
				object.value = tmStr + " " + 'PM'
			}else{
				object.value = tmStr + " " 
			}
		}
	lastLength = object.value.length
	timeDash[index]  = firstInsert 	
}
var curCom1 =  [ "ncheck","ncheck","ncheck","ncheck","ncheck","ncheck","ncheck"]
var curCom2 =  [ "ncheck","ncheck","ncheck","ncheck","ncheck","ncheck","ncheck"]
var curCom3 =  [ "ncheck","ncheck","ncheck","ncheck","ncheck","ncheck","ncheck"]
var curCom4 =  [ "ncheck","ncheck","ncheck","ncheck","ncheck","ncheck","ncheck"]
var curCom5 =  [ "ncheck","ncheck","ncheck","ncheck","ncheck","ncheck","ncheck"]
var initialCom = 0
function manageCur(dateText,index){
	if (netscape){
		return
	}
	object = dateText
	firstInsert = curCom1[index]
	secondInsert = curCom2[index]
	thirdInsert =  curCom3[index]
	forthInsert =  curCom4[index]
	fifthInsert =  curCom5[index]
	if (initialDate == object.value){
		return;
	}
	str = object.value
	strLen = str.length
	dateText = str
	
	if ( (strLen == "1") && (strLen > lastLength)){
		firstInsert = "check"
		object.value = "$" + dateText
	}else if ( (strLen == "4") && (strLen > lastLength)){
		secondInsert = "check"
		object.value = dateText + ","
	}else if ( (strLen == "8")  && (strLen > lastLength)){
		thirdInsert = "check"
		object.value = dateText + ","	
	}else if ( (strLen == "12")  && (strLen > lastLength)){
		forthInsert = "check"
		object.value = dateText + ","	
	}else if ((strLen == "1") && (strLen < lastLength)){
		firstInsert = "ncheck"
		object.value= ""
	}else if ((strLen == "4") && (strLen < lastLength)){
		secondInsert = "ncheck"
		object.value = dateText.substr(0,strLen - 1 )	
	}else if ((strLen == "8") && (strLen < lastLength)){
		thirdInsert = "ncheck"
		object.value = dateText.substr(0,strLen - 1 )
	}else if ((strLen == "12") && (strLen < lastLength)){
		forthInsert = "ncheck"
		object.value = dateText.substr(0,strLen - 1 )
	}else if ((strLen > 16) &&  (firstInsert == "check") && (firstInsert == "check")
		&& (secondInsert == "check")  && (thirdInsert == "check")){
		object.value = str.substr(0,16)
	}
	
	if ( (strLen > "1") && (firstInsert == "ncheck") ){
		firstInsert = "check"
		object.value = "$" + str.substr(0,14)
		
	}
	if (( strLen > "4") && (secondInsert == "ncheck") ){
		secondInsert = "check"
		object.value = str.substr(0,4) + "," + str.substr(5,14)
	}
	if (( strLen > "8") && (thirdInsert == "ncheck") ){
		thirdInsert = "check"
		object.value = str.substr(0,8) + "," + str.substr(9,14)
	}
	if (( strLen > "12") && (thirdInsert == "ncheck") ){
		thirdInsert = "check"
		object.value = str.substr(0,12) + "," + str.substr(13,14)
	}
	lastLength = object.value.length
	curCom1[index]  = firstInsert 
	curCom2[index] = secondInsert 
	curCom3[index] = thirdInsert 
	curCom4[index] = forthInsert 
}

function cleanNumber(strNum)
{
	if (!strNum) return strNum;
	strNum = replace(strNum, '$', '', 0);
	strNum = replace(strNum, ',', '', 0);
	strNum = replace(strNum, '%', '', 0);	
	return strNum;
}

function replace(szBuf, szFind, szReplace, lStart)
{
	var lFind = 0;
	if (!lStart) lStart = 0;
	
	while (lFind != -1) {
		lFind = szBuf.indexOf(szFind, lStart);

		

		if (lFind != -1) {
			szBuf = szBuf.substring(0,lFind) + szReplace + szBuf.substring(lFind + szFind.length);
			lStart = lFind + szReplace.length;
		}
	}
	return szBuf;
}
function numFormat(elem, lead, sep)
{
	//alert("formatting")
	
	if (elem.value == '') return true;
	
	var value = parseInt(cleanNumber("0"+elem.value), 10);
        //alert(value);
	if (0 > value) value = 0;
	if (isNumer(value)) {
		alert('You may have entered an incorrect character or exceeded the range for some information on this tab. \nPlease check your information and try again.');
		elem.value = '';
		elem.focus();
		return false;
	}
	elem.value = format(value, lead, sep);
	return true;
}

function split(s,sep)
{
	if (s == '') return null;
	var a = new Array();
	if (s.substring(1,s.length-1)==sep) s = s.substring(0,s.length-1);
	var lStart = 0;
	var lEnd = 0;
	
	while (lEnd != -1) {
		lEnd = s.indexOf(sep,lStart);
		if (lEnd != -1) {
			a[a.length] = s.substring(lStart, lEnd);
			lStart = lEnd + sep.length;
		}
		else {
			a[a.length] = s.substring(lStart);
		}
	}
	return a;
}
function numField(elem)
{
	if (elem.value == '') return true;
	
	var test = true;
	var s = elem.value;
	for (var i = 0; i < s.length && test; i++){
		var c = s.charAt(i);
		if (c != '\'') {
			if (eval('\'' + parseInt(c) + '\'')!= eval('\'' + c + '\'')){
				test = false;
			}
			else if (!(c >= 0) && !(c <= 9))
			{
				test = false;
			}
		}
		else {
			test = false;
		}
	}
	if (test == false) {
		alert('You may have entered an incorrect character or exceeded the range for some information on this tab. \nPlease check your information and try again.');
		elem.value = '';
		elem.focus();
		return false;
	}
	else {
		return true;
	}
}
function format(value, lead, sep)
{
	var strValue = new String(value);
	var len = strValue.length;
	var n;
	var strRet = '';
	var ctChar = 3 - (len%3);
	if (ctChar == 3) ctChar =0;
	for (n=0; len > n; n++) {
		if (ctChar == 3) {
			strRet += sep;
			ctChar = 0;
		}
		ctChar++;
		strRet += strValue.substring(n,n+1)		
	}
	if (lead == '%') {
		return strRet + lead;
	}
	else {
		return lead + strRet;
	}
}

function isNumer(c)
{
	if (!c) return false;
	return (('0' <= c) && (c <= '9'));
}

function LSopenNewWindow(myForm,formName){
  openAWindowWS("waiting.html","DetailsWindow",0,0);
  myForm.submit();
				
}

function checkInputDate(newDate){
	//alert(newDate.value)
	str = newDate.value
	if (isEmpty(str)){
		return
	}else if (!verifyDate(newDate)){
		alert("Bad Date field Entered");
		newDate.select()
		newDate.focus()
	}
}

function LSOpenDW(myForm,formName){
	openAWindowWS("waiting.html","DetailsWindow",0,0);
}

function clearNumber(str){
	if (isEmpty(str)){
		return ""
	}
	i = str.length
	newStr = ""
	for(j = 0;j < str.length; j++){
                //alert(str.charAt(j))   
		if ((isDigit(str.charAt(j))) || (str.charAt(j) == '.')) {
                        
			newStr = newStr + str.charAt(j)
		}
                
	}
	return newStr;
}

function calCommission(elem,elem1,elem2) {
	if (elem1.value == '') return true;
	
	validNum = clearNumber(elem1.value)
	validNum1 = clearNumber(elem.value)
	if (validNum == ""){
		validNum = "0"
	}
	if (validNum1 == ""){
		validNum1 = "0"
	}

	var value = parseFloat(validNum);
        var spvalue = parseFloat(validNum1);
       
	if (0 > value) value = 0;

	//if (isNumer(value)) {
	//	alert('You may have entered an incorrect character or exceeded the range for some information in on this field. \nPlease check your information and try again.');
		//elem1.value = '0';
    //            elem2.value = "0000";
    //          	elem1.focus();
	//	return false;
	//}
    fvalue = (spvalue * value) / 100                  
	elem1.value = format(value, '%', '');
    elem2.value = format(fvalue, '$', ',');

	return true;
    
}
//===========================================================================================
//AddEdit and listing functions

function checkPropertyDates(){
        //alert("Checking!")
	if (!verifyDate(parent.frames["AddEditmainwindow"].document.forms[0].ListDate)) {
		alert("List Date is not valid!")	
		return false
	}	
	
	if (!verifyDate(parent.frames["AddEditmainwindow"].document.forms[0].ExpiryDate)){
		alert("Expiry Date is not valid!")	
		return false
	}
	if (!verifyDate(parent.frames["AddEditmainwindow"].document.forms[0].ConditionExpiryDate)){
		alert("Pending Date is not valid!")	
		return false
	}
	
	if (!verifyDate(parent.frames["AddEditmainwindow"].document.forms[0].SoldDate)){
		alert("Sold Date is not valid!")	
		return false
	}
	
		
	return true
}
function SetCurrentPageLoaded() {
  parent.frames['AddEditTabWindow'].document.forms[0].szCurrentPage.value = "Loaded";
}

function BuySellZero() {
  //position on buysell tab.
 if  (confirm("Seller / Buyer / Contact should have at least one item Entered. Are you sure you want to close?"))
 {
    	parent.frames['AddEditTabWindow'].document.forms[0].closeType.value = 'Saved'
        parent.frames['AddEditmainwindow'].document.forms[0].szNextPage.value = 'SaveListingBS';
  
	parent.frames['AddEditmainwindow'].document.forms[0].submit();
  }else{  
    
    aeChangeImageNS(parent.frames['AddEditTabWindow'].document.forms[0].document.MSFPnav5,'/AgentWorkstation/AddEditListing/images/V_TabSelBuyCont.gif','/AgentWorkstation/AddEditListing/images/NV_TabSelBuyCont.gif');
    parent.frames['AddEditTabWindow'].document.forms[0].szCurrentPage.value = "Loaded";   
  }
}
function aeChangeImageNS(MsfpValue,sMsfpValue,nMsfpValue) {

  
  if (MsfpValue.src != sMsfpValue) {
      if (NextImageName != 'NEW') {
        lastobjectName.src = NextImageName;
      }else{
         parent.frames['AddEditTabWindow'].document.MSFPnav1.src = 'images/NV_TabProperty.gif';
      }

      MsfpValue.src = sMsfpValue;
      lastobjectName = MsfpValue;
      NextImageName = nMsfpValue;
  }

}



function aeChangeImage(MsfpValue,sMsfpValue,nMsfpValue) {
var ii= 0;
var ic= 0;



  if (document.fdmAddEditTabs.szCurrentPage.value == "") {
     return;
  }
  document.fdmAddEditTabs.szCurrentPage.value = "";

	
  if (NextImageName == 'NEW') {
        if (!checkPropertyDates()) {

            document.fdmAddEditTabs.szCurrentPage.value = "Loaded";    
          return;
        }  
  }else{
      curIName =  lastobjectName.src;

      ii = curIName.indexOf("_");
      curPage = curIName.substring(ii + 4,curIName.length); 
      ic = curPage.indexOf(".");
      curIName = curPage.substring(0,ic);

     if (curIName == 'Property') {
        if (!checkPropertyDates()) {
           document.fdmAddEditTabs.szCurrentPage.value = "Loaded";
           return;
        }  
     }
      
  }  

   
  if (MsfpValue.src != sMsfpValue) {
      if (NextImageName != 'NEW') {
        lastobjectName.src = NextImageName;
      }else{
         document.MSFPnav1.src = 'images/NV_TabProperty.gif';
      }
      
      MsfpValue.src = sMsfpValue;
      lastobjectName = MsfpValue;
      NextImageName = nMsfpValue;

      ii = sMsfpValue.indexOf("_");
      ic = sMsfpValue.indexOf(".");

	nextPage = sMsfpValue.substring(ii+4,ic);
	
	parent.frames['AddEditmainwindow'].document.forms[0].szNextPage.value = nextPage;
        fixListingData()
	parent.frames['AddEditmainwindow'].document.forms[0].submit();

  }

}

function exitForm(){
    //parent.frames['AddEditmainwindow'].document.forms[0].szNextPage.value = "CLOSELISTING"
	CloseAddEdit()
    //parent.frames['AddEditmainwindow'].document.forms[0].submit()
	//alert(parent.frames['AddEditmainwindow'].document.forms[0].szNextPage.value);
	//alert("An attempt has been made to save your data.\nPlease use close button in the future")
	//window.open();
	
	return true
}

function ReloadAgent(){
    parent.document.location.reload()
}

function ReloadBuyerSeller(){
   parent.frames['AddEditmainwindow'].history.back()
   parent.frames['AddEditmainwindow'].history.back()
   parent.frames['AddEditmainwindow'].history.back()
   parent.frames['AddEditmainwindow'].history.back()
   //parent.frames['AddEditmainwindow'].history.back()
   parent.frames['AddEditmainwindow'].document.location.reload()
   //parent.frames['AddEditmainwindow'].document.forms[0].szNextPage.value = "SELBUYCONT"
   //parent.frames['AddEditmainwindow'].document.forms[0].submit()
   //self.close();
}

function GetAssistantName() {

     agInfo = document.forms[0].szAgentName.options[document.forms[0].szAgentName.selectedIndex].value;
 
     a = agInfo.split(':'); 
     document.forms[0].DBS_IOFFICEID.value = a[1];
     document.forms[0].DBS_SZASSISTANTNAME.value = a[3];
}

function GetItemDetails() {
     //alert('Item Details')

     agInfo = document.forms[0].szItemCode.options[document.forms[0].szItemCode.selectedIndex].value;
 
     a = agInfo.split(':'); 
     document.forms[0].szItemDescription.value = a[1];
     document.forms[0].cQuantity.value = a[2];
     document.forms[0].dCost.value = a[3];
     document.forms[0].szAccount.value = a[4];

     BillCalcTotal();
}


function BillCalcTotal() {

     //alert("test")
     if (document.forms[0].dpSurcharge.value == 0) {
     document.forms[0].dSubtotal.value = (document.forms[0].dCost.value * document.forms[0].cQuantity.value);
     document.forms[0].dAmount.value = (document.forms[0].dCost.value * document.forms[0].cQuantity.value);
     }else {
     document.forms[0].dSubtotal.value = (document.forms[0].dCost.value * document.forms[0].cQuantity.value) + (document.forms[0].dCost.value * document.forms[0].cQuantity.value * document.forms[0].dpSurcharge.value/100)
     document.forms[0].dAmount.value = (document.forms[0].dCost.value * document.forms[0].cQuantity.value) + (document.forms[0].dCost.value * document.forms[0].cQuantity.value * document.forms[0].dpSurcharge.value/100);
     }

}


function AddListing(){
	if (!state) return;
	dbS = parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	openAWindowNS("AddEditListing/AddEditListing.dll/CreateFrame?dbString=" +dbS + "&szWebCode=" +dbCode,"AddListingWindow",770,510)
}


function EditListing(){
    parent.frames["mainwindow"].document.URL="AddEditListing/AddEditListing.dll/AddEditSearchInput?dbString=" +parent.frames['bulletinwindow'].document.tAgentInfo.dbString.value +"&reportfile=" +  "&szWebCode=" + parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value;  
}

function SearchAll(){

   // parent.frames["mainwindow"].document.URL="AddEditListing/AddEditListing.dll/AddEditSearchInput?dbString=" +parent.frames['bulletinwindow'].document.tAgentInfo.dbString.value +"&reportfile=" +  "&szWebCode=" + parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value;
   //alert("ListingSearch/ListingSearch.dll/SearchInputScreen?dbString=" +parent.frames['bulletinwindow'].document.tAgentInfo.dbString.value) 
   parent.frames["mainwindow"].document.URL="ListingSearch/ListingSearch.dll/SearchInputScreen?dbString=" +parent.frames['bulletinwindow'].document.tAgentInfo.dbString.value

}

function fixListingData(){
	thisForm =   parent.frames['AddEditmainwindow'].document.forms[0]
	page = thisForm.szListPage.value.toUpperCase()
	if ( page == 'PROPERTY') {
		thisForm.LegalDescription.value = thisForm.LegalDescription_data.value
		thisForm.ShowingInstructions.value = thisForm.ShowingInstructions_data.value
	}else if (page == 'FEATURES') {
		thisForm.Features.value = thisForm.Features_data.value
	}else if (page == 'DESCRIPTION') {
		thisForm.Remarks.value = thisForm.Remarks_data.value
	}else if (page == 'ADCOPY') {
		thisForm.AdCopy.value = thisForm.AdCopy_data.value
	}
	
}
function SaveAddEdit(AddEditMode) {

	parent.frames['AddEditTabWindow'].document.forms[0].closeType.value = 'Saved'
        if (AddEditMode == 'EDIT') {
	       parent.frames['AddEditmainwindow'].document.forms[0].szNextPage.value = 'SaveListingE';
        }else{
               parent.frames['AddEditmainwindow'].document.forms[0].szNextPage.value = 'SaveListing'; 
        }
        fixListingData()
	
	parent.frames['AddEditmainwindow'].document.forms[0].submit();
}

function CloseAddEdit(AddEditMode) {
	parent.frames['AddEditTabWindow'].document.forms[0].closeType.value = 'Saved'
        if (AddEditMode == 'EDIT') {
	     parent.frames['AddEditmainwindow'].document.forms[0].szNextPage.value = 'CloseListingE';
        }else{
             parent.frames['AddEditmainwindow'].document.forms[0].szNextPage.value = 'CloseListing';
        }
	parent.frames['AddEditmainwindow'].document.forms[0].submit();
	window.close()
}

function makeAgentVisible(){
	document.all.addAgent.style.pixelLeft = 200
}

function AddAgent() {
	document.frames['addAgentFrame'].location.href = "AddEditAgents?dbString=" +document.agentForm.dbString.value +"&reportfile=" + "&iAgentListId=0&fCompanyAgent=0&szAgentUnits=1&szWebCode=" + document.agentForm.szWebCode.value + "&stateiListNo="+ document.agentForm.stateiListNo.value + "&szSalesAmount=" + document.agentForm.szSalesAmount.value 
	document.all.addAgent.style.pixelLeft = 200
	
}
function deleteBuyerSeller(){
		
	   try{
		checkBoxList = document.forms[0].cb
		deleteList = "'-999'";
		if (checkBoxList.length == null){
			if ( checkBoxList.checked){
				deleteList += ",'"+checkBoxList.value+ "'"	
			}else {
				alert('Contact must be selected');
			}
		}else {
			
			for (i = 0;i < checkBoxList.length; i++){
				if ( checkBoxList[i].checked){
					deleteList += ",'"+checkBoxList[i].value+ "'"
					 checkBoxList[i].checked = false
				}
			}
		}
		if ( deleteList != "'-999'" ) {
			if (confirm("Are you sure?")){
			    document.forms[0].target = '_self'
			    document.forms[0].deleteList.value = deleteList
			    //document.forms[0].submitType.value = 'delete'
			    document.forms[0].szNextPage.value = 'SelBuyCont'
			    document.forms[0].submit()
			}
		}else {
			alert('A contact must be selected');
		}
	}catch(e){
		alert('Error occurred while Deleting Agent.')
		 var buf="Exception properties:\n"
	   /* for(var prop in e)
	        buf+=prop+"="+e[prop]+"\n"
	    alert(buf)*/
	
	}
	
}

function deleteListingAgent(){
		
	   try{
		checkBoxList = document.forms[0].cb
		deleteList = "'-999'";
		if (checkBoxList.length == null){
			if ( checkBoxList.checked){
				deleteList += ",'"+checkBoxList.value+ "'"	
			}else {
				alert('An agent must be selected');
			}
		}else {
			
			for (i = 0;i < checkBoxList.length; i++){
				if ( checkBoxList[i].checked){
					deleteList += ",'"+checkBoxList[i].value+ "'"
					 checkBoxList[i].checked = false
				}
			}
		}
		if ( deleteList != "'-999'" ) {
			if (confirm("Are you sure?")){
			    document.forms[0].target = '_self'
			    document.forms[0].deleteList.value = deleteList
			    //alert(document.forms[0].deleteList.value)
			    //document.forms[0].submitType.value = 'delete'
			    document.forms[0].szNextPage.value = 'Agents'
			    document.forms[0].submit()
			}
		}else {
			alert('An agent must be selected');
		}
	}catch(e){
		alert('Error occurred while Deleting Agent.')
		 var buf="Exception properties:\n"
	   /* for(var prop in e)
	        buf+=prop+"="+e[prop]+"\n"
	    alert(buf)*/
	
	}
	
}


function CancelAgent(){
	parent.document.all.addAgent.style.pixelLeft = -1000		
}

function SaveAgent(){
	//window.blur()
	document.forms[0].submit()
	//parent.document.all.addAgent.style.pixelLeft = -1000		
}
function AddAgentOutside() {
    //openAWindowNS("AddEditAgents?dbString=" +document.agentForm.dbString.value +"&reportfile=" + "&iAgentListId=0&fCompanyAgent=1&szAgentUnits=1&szWebCode=" + document.agentForm.szWebCode.value + "&stateiListNo="+ document.agentForm.stateiListNo.value+ "&szSalesAmount=" + document.agentForm.szSalesAmount.value ,"AddEditAgentWindow",420,300);
	//parent.frames['AddEditmainwindow'].location.href = 
	document.frames['addAgentFrame'].location.href = "AddEditAgents?dbString=" +document.agentForm.dbString.value +"&reportfile=" + "&iAgentListId=0&fCompanyAgent=1&szAgentUnits=1&szWebCode=" + document.agentForm.szWebCode.value + "&stateiListNo="+ document.agentForm.stateiListNo.value+ "&szSalesAmount=" + document.agentForm.szSalesAmount.value 
	document.all.addAgent.style.pixelLeft = 200
}

function AddBuyerSeller() {
	//urlText = "AddEditBuyerSeller?dbString=" +document.agentForm.dbString.value +"&reportfile="  + "&iBuyerID=0&szWebCode=" + document.agentForm.szWebCode.value + "&stateiListNo="+ document.agentForm.stateiListNo.value
	urlText = "../fdmweb.dll/addBuyerSeller?report=bsl.html&dbString=" +document.agentForm.dbString.value +"&reportfile="  + "&iBuyerID=0&szWebCode=" + document.agentForm.szWebCode.value + "&stateiListNo="+ document.agentForm.stateiListNo.value
	openAWindowWS(urlText,"AddEditBuyerSellerWindow",670,545);
}

function EditBuyerSeller() {
       openAWindowWS("","AddEditBuyerSellerWindow",670,545);
}

function BuyerSellerPrevious() {
        document.forms[0].szPage.value = '1'+document.forms[0].szPage.value;
	document.forms[0].submit();       
}

function BuyerSellerNext() {
        
	document.forms[0].submit();       
}
 
function BuyerSellerszName() {
        document.forms[0].szPage.value = '3';
	document.forms[0].submit();       
}

function BuyerSellerSave() {
        document.forms[0].szPage.value = '5';
	document.forms[0].submit();       
}

function AddEditSaveVendors(jszWebCode,jiListNo) {
        if (jiListNo != "0") { 
             openAWindowNS("/AgentWorkstation/AddEditListing/AddEditListing.dll/DoVendorQuesionsQ?szWebCode=" + jszWebCode + "&stateiListNo="+ jiListNo +"&iVendorID=0","vquestionsWindow",620,330);
                
        }
        parent.close();

}

function AddEditSaveVendorsE(jszWebCode,jiListNo) {
        if (jiListNo != "0") { 
             openAWindowNS("/AgentWorkstation/AddEditListing/AddEditListing.dll/DoVendorQuesionsQ?szWebCode=" + jszWebCode + "&stateiListNo="+ jiListNo +"&iVendorID=0","vquestionsWindow",620,330);
                
        }

 fdmBacktoSearch();                
}

function fdmBacktoSearch() {
	
	parent.close()
}

function SaveVendor() {
	document.forms[0].szNextPage.value = 'SaveVendor';
	document.forms[0].submit();
        
}

function CloseVendor() {
	document.forms[0].szNextPage.value = 'CloseVendor';
	document.forms[0].submit();
        close();
}

function manageDate(dateText,obType){
	if (netscape){
		return
	}
	
	if (obType == "from"){
		object = document.messagesForm.fromDate
		firstInsert = ffInsert;
		secondInsert = fsInsert;
		if (initialDate == object.value){
			return;
		}
	}else {
		object = document.messagesForm.toDate
		firstInsert = tfInsert;
		secondInsert = tsInsert;
		if (initialDate == object.value){
			return;
		}
	}
	str = object.value
	strLen = dateText.length
	
	if ( (strLen == "5") && (strLen > lastLength)){
		secondInsert = "checked"
		object.value = dateText + "/"
	}else if ( (strLen == "2")  && (strLen > lastLength)){
		firstInsert = "checked"
		object.value = dateText + "/"	
	}else if ((strLen == "5") && (strLen < lastLength)){
		secondInsert = "notChecked"
		object.value = dateText.substr(0,strLen - 1 )
		
	}else if ((strLen == "2") && (strLen < lastLength)){
		firstInsert = "notChecked"
		object.value = dateText.substr(0,strLen - 1 )
		
	}else if ((strLen > 10) &&  (firstInsert == "checked") && (secondInsert == "checked")){
		object.value = str.substr(0,10)
	}
	
	if ( (strLen > "2") && (firstInsert == "notChecked") ){
		firstInsert = "checked"
		object.value = str.substr(0,2) + "/" + str.substr(2,8)
		
	}
	if (( strLen > "5") && (secondInsert == "notChecked") ){
		secondInsert = "checked"
		object.value = str.substr(0,5) + "/" + str.substr(6,8)
		
	}
	lastLength = object.value.length
	if (obType == "from"){
		ffInsert = firstInsert
		fsInsert = secondInsert
	}else {
		tfInsert = firstInsert
		tsInsert = secondInsert
	}
}

function centerScreenR(wwidth,wheight)
{
    
    xposition=0; 
    yposition=0;
    

    if (parseInt(navigator.appVersion) >= 4 )
    {
    
	xposition = (screen.width - wwidth) / 2;
	yposition = (screen.height - wheight) / 2;
       
    }

    window.resizeTo(wwidth,wheight);

    window.moveTo(xposition,yposition);
}

function PropertyLoad(wwidth,wheight)
{
	parent.resizeTo(wwidth,wheight);
        parentcenterScreen(wwidth,wheight);
        SetCurrentPageLoaded();

}

function parentcenterScreen(wwidth,wheight)
{
    
    xposition=0; 
    yposition=0;
    
    if (parseInt(navigator.appVersion) >= 4 )
    {
    
	xposition = (screen.width - wwidth) / 2;
	yposition = (screen.height - wheight) / 2;
       
    }
    
    parent.window.moveTo(xposition,yposition);
}

function centerScreen(wwidth,wheight)
{
    
    xposition=0; 
    yposition=0;
    
    if (parseInt(navigator.appVersion) >= 4 )
    {
    
	xposition = (screen.width - wwidth) / 2;
	yposition = (screen.height - wheight) / 2;
       
    }
    
    window.moveTo(xposition,yposition);
}
function openAWindowNS(pageToLoad,awinName,wwidth,wheight)
{
    xposition=0; 
    yposition=0;
    
    if (parseInt(navigator.appVersion) >= 4 )
    {
    
	xposition = (screen.width - wwidth) / 2;
	yposition = (screen.height - wheight) / 2;
       
    }
    args = "width=" + wwidth + "," + "height=" + wheight + ",location=0,menubar=0,resizable=1,scrollbars=0,status=0,titlebar=0,toolbar=0,hotkeys=0,screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + ","  + "top=" + yposition;   
    window.open(pageToLoad,awinName,args);
    //parent.frames["mainwindow"].location.href = pageToLoad	

}
function openAWindowWS(pageToLoad,awinName,wwidth,wheight)
{
    xposition=0; 
    yposition=0;
    
    if (parseInt(navigator.appVersion) >= 4 )
    {
    
	xposition = (screen.width - wwidth) / 2;
	yposition = (screen.height - wheight) / 2;
       
    }
    args = "width=" + wwidth + "," + "height=" + wheight + ",location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0,hotkeys=0,screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + ","  + "top=" + yposition;   
    window.open(pageToLoad,awinName,args);
    //parent.frames["mainwindow"].location.href = pageToLoad

}

function openAWindowWS_tb(pageToLoad,awinName,wwidth,wheight)
{
    xposition=0; 
    yposition=0;
    
    if (parseInt(navigator.appVersion) >= 4 )
    {
    
	xposition = (screen.width - wwidth) / 2;
	yposition = (screen.height - wheight) / 2;
       
    }
    args = "width=" + wwidth + "," + "height=" + wheight + ",location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,hotkeys=0,screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + ","  + "top=" + yposition;   
    window.open(pageToLoad,awinName,args);
    //parent.frames["mainwindow"].location.href = pageToLoad

}



function setListMask(data){
	parent.frames['title'].document.perm.listMask.value = data
}


//Save the current position in the title area
function savePosition(){
	//parent.frames['title'].document.forms[0].history.value = parent.frames['mainwindow'].location.href
	//alert(parent.frames['mainwindow'].document.location.href)
	//parent.frames['title'].document.forms[0].history.value = 'fdmSearch?dbString='+document.SearchForm.dbString.value+'&code='+document.SearchForm.szAgentCode.value
	
	}
	
function loadAgentData(){
	//parent.frames["admin"].location.href = 'fdmData?dbString='+document.SearchForm.dbString.value
}

//Save appointment screen
function saveAppt(){
	//alert(document.forms[0].enteredBy.value)
	//alert(document.forms[0].fConfirmedShowAgent.value)

	//VERIFY APPTAGENTCODE
	if (document.forms[0].apptAgentCode.value == ''){
         alert('An Agent Code must be entered')
  	   document.forms[0].apptAgentCode.focus()
	   return;
	}
	//alert('agentcode')
	//VERIFY FROMTIME
	if (!verifyTime(document.forms[0].fromTime.value)){
         alert('From time is not valid!')
  	   document.forms[0].fromTime.focus()
	   return;
	}
	//alert('fromtime')
	//VERIFY TOTIME
	if (!verifyTime(document.forms[0].toTime.value)){
         alert('To time is not valid!')
  	   document.forms[0].toTime.focus()
	   return;
	}
	//alert('fromtime')


	editTag = 'F'
	if (document.forms[0].submitType.value != 'edit'){
		editTag = 'T'
		document.forms[0].submitType.value = 'Save';
	}
	cDoc = document.forms[0]
	//alert('Agent Code: '+ document.forms[0].apptAgentCode.value +' Company Name: '+document.forms[0].companyName.value)
	document.forms[0].action = "saveAppt";
	document.forms[0].companyNumber.value = cleanPhone(cDoc.companyNumber.value)
	document.forms[0].agentNumber.value = cleanPhone(cDoc.agentNumber.value)
	document.forms[0].apptAgentName.value = document.forms[0].agentName.value
	fromTOD = document.forms[0].fromTimeTOD.options[document.forms[0].fromTimeTOD.selectedIndex].value
	toTOD = document.forms[0].toTimeTOD.options[document.forms[0].toTimeTOD.selectedIndex].value
	document.forms[0].fromTime.value = document.forms[0].fromTime.value + ' ' + fromTOD
	document.forms[0].toTime.value = document.forms[0].toTime.value + ' ' + toTOD
	setConfirmedState()
	document.forms[0].showingInstructions.value = '';
	document.forms[0].listing.value = '';
	document.forms[0].buyerSeller.value = '';
	document.forms[0].listingAgent.value = '';

		currentDate = new Date()
	correctMonth = currentDate.getMonth()+1
	//alert(correctMonth + '/' + currentDate.getDate() + '/' + currentDate.getYear() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes() + ':' + currentDate.getSeconds())
	document.forms[0].localDateTime.value = correctMonth + '/' + currentDate.getDate() + '/' + currentDate.getYear() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes() + ':' + currentDate.getSeconds()


	document.forms[0].submit();
	window.blur()
	/*if ( editTag == 'T' ) {
		window.blur()
	}*/
}

function saveBuyerSeller(){
	
	cDoc = document.forms[0]
	cDoc.busPhone.value = cleanPhone(cDoc.busPhone.value)
	cDoc.cellPhone.value = cleanPhone(cDoc.cellPhone.value)
	cDoc.resPhone.value = cleanPhone(cDoc.resPhone.value)
	cDoc.pagerPhone.value = cleanPhone(cDoc.pagerPhone.value)
	cDoc.faxPhone.value = cleanPhone(cDoc.faxPhone.value)
	cDoc.nightLine.value = cleanPhone(cDoc.nightLine.value)

	currentDate = new Date()
	correctMonth = currentDate.getMonth()+1
	//alert(correctMonth + '/' + currentDate.getDate() + '/' + currentDate.getYear() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes() + ':' + currentDate.getSeconds())
	cDoc.localDateTime.value = correctMonth + '/' + currentDate.getDate() + '/' + currentDate.getYear() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes() + ':' + currentDate.getSeconds()

	cDoc.submit();
	//window.close()
	
}



function resetSearch(){
	document.forms[0].submitType.value = 'init';
	document.forms[0].submit();
}

function getSearchScreen(data){
	parent.frames["searchwindow"].location.href = data
}
function setState(input){
	
	//alert(parent.frames['title'].document.forms[0].state.value)
	if (input){
		if (parent.frames['title'].document.forms[0].state.value == 'in'){
			state = true
		}else{
			state = false
		}
	}else {
		state = input
	}
//alert(state)
}

function setState2(input){
	if (input){
		if (opener.parent.frames['title'].document.forms[0].state.value == 'in'){
			state = true
		}else{
			state = false
		}
	}else {
		state = input
	}
}


function setConfirmedState(){
	if (document.forms[0].apptType.value != 'request'){	
		if( document.forms[0].confirmedCheckBox.checked ){
			document.forms[0].confirmed.value = "Yes"
		}else{
			document.forms[0].confirmed.value = "No"
		}
	}
	if (document.forms[0].apptType.value != 'request'){	
		if( document.forms[0].fconfirmedShowAgent.checked ){
			document.forms[0].fconfirmedShowAgent.value = "Yes"
		}else{
			document.forms[0].fconfirmedShowAgent.value = "No"
		}
	}
	//alert(document.forms[0].confirmed.value)
	//alert(document.forms[0].fconfirmedShowAgent.value)

}

function formatTime(timeObject){
	text = timeObject.value
	if (text.length == 4){
		hour= text.substr(0,2)
		minute = text.substr(2,2)
	}else if (text.length == 5){
		hour= text.substr(0,2)
		minute = text.substr(3,2)	
		if (text.substr(2,1) != ':'){
			alert("Invalid Time!")
			timeObject.focus()
			return
		}	
	//}else if (text.length == 3){
	//	hour= text.substr(0,1)
	//	minute = text.substr(1,2)		
	}else {
		alert("Time data not valid!")
		timeObject.focus()
		return	
	}
	if (hour > 12 || hour < 1){
			alert("Hour is out of range")
			timeObject.focus()
			return
		}
	if (minute > 59 || hour < 0){
			alert("Minute is out of range.")
			timeObject.focus()
			return
	}
	if ( !isWholeNumber(minute) || !isWholeNumber(hour)){
		alert("Invalid Time!")
		timeObject.focus()
		return
	}
	text = hour + ':' + minute	
	timeObject.value = text
	//alert(text)
}

function isWholeNumber(input){
	data = "0123456789"
	for ( i = 0; i < input.length;i++){
		if (data.indexOf(input.charAt(i)) == -1){
			return false;
		}
	}
	return true;
}

function setConfirmedPerson(input){
  try{
	if (input.checked){
		data = split(document.forms[0].szWebCode.value,":")
		document.forms[0].confirmedBy.value = data[1]
	}
	}catch (ee){
	
	}
}

function bookAppt(){
	try{
	if (!state) return;
	
	if (parent.frames['mainwindow'].document.forms['data'] != null || parent.frames['mainwindow'].document.forms[1].cb == null){
		alert("Listing must be selected!")
		return;
	}
	//alert('test')
	if (parent.frames['mainwindow'].document.forms[0].resultCount.value == 0){
		if ( parent.frames['mainwindow'].document.forms[1].cb.checked){
			checkBox = parent.frames['mainwindow'].document.forms[1].cb
			officeName = parent.frames['mainwindow'].dataList[checkBox.tag][iofficeidI]
			tmpStr = parent.frames['mainwindow'].code 
			tmpArray = tmpStr.split(':')
			
			if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
				alert('You do not have permission to perform this operation.')	
				return
			}
			//alert(officeName)	
			openAWindowWS( "fdmweb.dll/bookAppt"+document.forms[0].apptBlankLink.value + checkBox.value+'&listingOffice='+officeName,"",630,520) 			
		}else {
			alert("Listing must be selected!")
		}
	}else if (parent.frames['mainwindow'].document.forms[0].resultCount.value > 0 ){
		checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
		itemFound = false
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				itemFound = true
				officeName = parent.frames['mainwindow'].dataList[checkBoxList[i].tag][iofficeidI]
				tmpStr = parent.frames['mainwindow'].code 
				tmpArray = tmpStr.split(':')
	
				if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
					urlText = "fdmweb.dll/bookAppt"+document.forms[0].apptBlankLink.value + checkBoxList[i].value + '&apptType=request'+'&listingOffice='+officeName
					windowWidth = 270
				}else{
					urlText = "fdmweb.dll/bookAppt"+document.forms[0].apptBlankLink.value + checkBoxList[i].value+'&listingOffice='+officeName
					windowWidth = 530
				}
				//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].value)
				openAWindowWS( urlText,"",630,windowWidth) 
			}
		}
		if ( ! itemFound){
			alert("Listing must be selected!")
		}
	}
	}catch (ee)
	 {
		alert("Listing must be selected!")	
	 }
}


//////////////////////////////////////////////////////////////////////////////////////////////
//	Function called when the view appointment menu item is clicked
//////////////////////////////////////////////////////////////////////////////////////////////
function viewAppt(){
	try{
	if (!state) return;
	if (parent.frames['mainwindow'].document.forms['data'] != null || parent.frames['mainwindow'].document.forms[1].cb == null){
		alert("Listing must be selected!")
		return;
	}
	if (parent.frames['mainwindow'].document.forms[0].resultCount.value == 0){
		if ( parent.frames['mainwindow'].document.forms[1].cb.checked){
			 
			checkBox = parent.frames['mainwindow'].document.forms[1].cb
			officeName = parent.frames['mainwindow'].dataList[checkBox.tag][iofficeidI]
				     
			tmpStr = parent.frames['mainwindow'].code 
			tmpArray = tmpStr.split(':')
			if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
				alert('You may not view appointments for another office.')	
				return
			}		
			//alert(officeName)
			openAWindowWS( "fdmweb.dll/viewAppt"+document.forms[0].apptBlankLink.value + checkBox.value+'&listingOffice='+officeName,"",700,530) 
		}else {
			alert("Listing must be selected!")
			return;	
		}
		//checkBox = parent.frames['mainwindow'].document.forms[1].cb 
		//if ( parent.frames['mainwindow'].document.forms[1].cb.checked){
		//	openAWindowNS( "fdmweb.dll/viewAppt"+document.forms[0].apptBlankLink.value + checkBox.value+'&listingOffice='+officeName,"",700,530) 
		//}
	}else if (parent.frames['mainwindow'].document.forms[0].resultCount.value > 0 ){
		checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
		itemFound = false
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				itemFound = true
				officeName = parent.frames['mainwindow'].dataList[checkBoxList[i].tag][iofficeidI]
				tmpStr = parent.frames['mainwindow'].code 
				tmpArray = tmpStr.split(':')
	
				if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
					alert('You may not view  another office\'s appointments.')	
					continue
				}
				address =  parent.frames['mainwindow'].dataList[checkBoxList[i].tag][addressI]
				//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].value)
				openAWindowWS( "fdmweb.dll/viewAppt"+document.forms[0].apptBlankLink.value + checkBoxList[i].value+'&listingOffice='+officeName,"",700,530) 
			}
		}
		if ( ! itemFound){
			alert("Listing must be selected!")
		}
	}
	}catch (ee)
	 {
		alert("Listing must be selected!")
	 
	 }
}

//////////////////////////////////////////////////////////////////////////////////////////////
//	Function called when the upload image menu item is clicked
//////////////////////////////////////////////////////////////////////////////////////////////
function uploadImage(){
	try{
	if (!state) return;
	uploadList = ''
	
	if (parent.frames['mainwindow'].document.forms['data'] != null || parent.frames['mainwindow'].document.forms[1].cb == null){
		alert("Listing must be selected!")
		return;
	}
	if (parent.frames['mainwindow'].document.forms[0].resultCount.value == 0){
		if ( parent.frames['mainwindow'].document.forms[1].cb.checked){
			 
			checkBox = parent.frames['mainwindow'].document.forms[1].cb
			officeName = parent.frames['mainwindow'].dataList[checkBox.tag][iofficeidI]
				     
			tmpStr = parent.frames['mainwindow'].code 
			tmpArray = tmpStr.split(':')
			if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
				alert('You cannot delete  another office\'s listings')	
				return
			}		
			uploadList = checkBox.value
		  }else {
			alert("Listing must be selected!")
			return;	
		}
		
	}else if (parent.frames['mainwindow'].document.forms[0].resultCount.value > 0 ){
		checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
		itemFound = false
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				//checkBoxList[i].checked = false
				itemFound = true
				officeName = parent.frames['mainwindow'].dataList[checkBoxList[i].tag][iofficeidI]
				mlsNo = parent.frames['mainwindow'].dataList[checkBoxList[i].tag][1]
				ImageName = mlsNo + ".JPG"
				tmpStr = parent.frames['mainwindow'].dbString
				tmpArray = tmpStr.split(':')
				
				dbPrefix = tmpArray[0]
				tmpStr = parent.frames['mainwindow'].code 
				
				tmpArray = tmpStr.split(':')
	                        szUser = tmpArray[1]

				if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
					alert('You cannot upload an image for  another office\'s listings.')	
					continue
				}



				if ( uploadList != '' ){
					uploadList = checkBoxList[i].value
				}else {

					uploadList = 	checkBoxList[i].value				
				}	
			}
		}
		if ( ! itemFound){
			alert("Listing must be selected!")
		}
	}
	if ( uploadList != '' ){
		//alert('Deleting'+uploadList)
		//alert('test '+ dbPrefix+' '+uploadList +' '+ ImageName)
		//alert("postfile.asp?ilistNo="+uploadList+"&OfficeID="+officeName+"&szUser="+szUser+"&mlsNo="+mlsNo+"&dbPrefix="+dbPrefix)
		openAWindowNS( "postfile.asp?ilistNo="+uploadList+"&OfficeID="+officeName+"&szUser="+szUser+"&mlsNo="+mlsNo+"&dbPrefix="+dbPrefix,"update",450,150) 
		//UpdateImageName(dbPrefix,uploadList,ImageName)			

	}
	}catch (e)
	 {
	 	alert("Listing must be selected !")
		 /*alert('Update Image Error')
			 var buf="Exception properties:\n"
  	 for(var prop in e)
    	    buf+=prop+"="+e[prop]+"\n"
  	  alert(buf)*/
	
	 
	 }
}

function UpdateImageName(dbPrefix,uploadList,ImageName) {
        if (uploadList != "0") { 
	alert('test')
             openAWindowNS("fdmweb.dll/UpdateImageName?szdbName=" + dbPrefix + "&jiListNo="+ uploadList + "&ImageNme="+ImageName,"UploadImageName.html",620,330);
                
        }
        //parent.close();

}



//////////////////////////////////////////////////////////////////////////////////////////////
//	Function called when the delete Listing menu item is clicked
//////////////////////////////////////////////////////////////////////////////////////////////
function deleteListing(){
	try{
	if (!state) return;
	deleteList = ''
	parent.frames['searchwindow'].document.forms[0].deleteList.value = deleteList
	if (parent.frames['mainwindow'].document.forms['data'] != null || parent.frames['mainwindow'].document.forms[1].cb == null){
		alert("Listing must be selected!")
		return;
	}
	if (parent.frames['mainwindow'].document.forms[0].resultCount.value == 0){
		if ( parent.frames['mainwindow'].document.forms[1].cb.checked){
			 
			checkBox = parent.frames['mainwindow'].document.forms[1].cb
			officeName = parent.frames['mainwindow'].dataList[checkBox.tag][iofficeidI]
				     
			tmpStr = parent.frames['mainwindow'].code 
			tmpArray = tmpStr.split(':')
			if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
				alert('You cannot delete  another office\'s listings')	
				return
			}		
			deleteList = checkBox.value
		  }else {
			alert("Listing must be selected!")
			return;	
		}
		
	}else if (parent.frames['mainwindow'].document.forms[0].resultCount.value > 0 ){
		checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
		itemFound = false
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				itemFound = true
				officeName = parent.frames['mainwindow'].dataList[checkBoxList[i].tag][iofficeidI]
				tmpStr = parent.frames['mainwindow'].code 
				tmpArray = tmpStr.split(':')
	
				if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
					alert('You cannot delete  another office\'s listings.')	
					continue
				}
				if ( deleteList != '' ){
					deleteList += ','+checkBoxList[i].value
				}else {

					deleteList = 	checkBoxList[i].value				
				}	
			}
		}
		if ( ! itemFound){
			alert("Listing must be selected!")
		}
	}
	
	if ( deleteList != '' && confirm("Are you sure?") ){
		//alert('Deleting'+deleteList)
		parent.frames['searchwindow'].document.forms[0].deleteList.value = deleteList
		parent.frames['searchwindow'].document.forms[0].submit()
	}
	}catch (ee)
	 {
		alert('delete Listing Error')
	 
	 }
}


function ViewListingActivity(){
	try{
	if (!state) return;
	if (parent.frames['mainwindow'].document.forms['data'] != null || parent.frames['mainwindow'].document.forms[1].cb == null){
		alert("Listing must be selected!")
		return;
	}
	if (parent.frames['mainwindow'].document.forms[0].resultCount.value == 0){
		if ( parent.frames['mainwindow'].document.forms[1].cb.checked){
			 
			checkBox = parent.frames['mainwindow'].document.forms[1].cb
			officeName = parent.frames['mainwindow'].dataList[checkBox.tag][iofficeidI]
			tmpStr = parent.frames['mainwindow'].code 
			tmpArray = tmpStr.split(':')
	
			if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
				alert('You may not view appointments for another office.')	
				return
			}
			address =  parent.frames['mainwindow'].dataList[checkBox.tag][addressI]	
			openAWindowWS( "fdmweb.dll/viewActivity"+document.forms[0].apptBlankLink.value + checkBox.value+'&listingOffice='+officeName+'&listNo='+checkBox.value+'&listingAddress='+address,"",700,530) 
		}else {
			alert("Listing must be selected!")
			return;	
		}
		//checkBox = parent.frames['mainwindow'].document.forms[1].cb 
		//if ( parent.frames['mainwindow'].document.forms[1].cb.checked){
		//	openAWindowNS( "fdmweb.dll/viewActivity"+document.forms[0].apptBlankLink.value + checkBox.value+'&listingOffice='+officeName,"",700,530) 
		//}
	}else if (parent.frames['mainwindow'].document.forms[0].resultCount.value > 0 ){
		checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
		itemFound = false
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				itemFound = true
				officeName = parent.frames['mainwindow'].dataList[checkBoxList[i].tag][iofficeidI]
				tmpStr = parent.frames['mainwindow'].code 
				tmpArray = tmpStr.split(':')
	
				if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
					alert('You may not view  another office\'s appointments.')	
					continue
				}
				address =  parent.frames['mainwindow'].dataList[checkBoxList[i].tag][addressI]
				//alert(address)
				//alert("fdmweb.dll/viewActivity"+document.forms[0].apptBlankLink.value + checkBoxList[i].value+'&listingOffice='+officeName+'&listNo='+checkBoxList[i].value)
				openAWindowWS( "fdmweb.dll/viewActivity"+document.forms[0].apptBlankLink.value + checkBoxList[i].value+'&listingOffice='+officeName+'&listNo='+checkBoxList[i].value+'&listingAddress='+address,"",700,530) 
			}
		}
		if ( ! itemFound){
			alert("Listing must be selected!")
		}
	}
	}catch (ee)
	 {
		alert("Listing must be selected!")
	 
	 }
}


//////////////////////////////////////////////////////////////////////////////////////////////
//	Function called when to get Listing no for caller log
//////////////////////////////////////////////////////////////////////////////////////////////
function getListingNo(){
try{
	if (document.forms[0].callerLogId.value != ''){
		listWindow = opener.opener.parent.frames['mainwindow']		
	}else {
		listWindow = opener.parent.frames['mainwindow']	
	}
	if (listWindow.document.forms['data'] != null || listWindow.document.forms[1].cb == null){
		alert("Listing must be selected!")
		return;
	}
	//alert(listWindow.document.forms[0].resultCount.value)
	if (listWindow.document.forms[0].resultCount.value == 0){
		if ( listWindow.document.forms[1].cb.checked){
			 
			checkBox = listWindow.document.forms[1].cb
			address =  listWindow.dataList[checkBox.tag][addressI]
			document.forms[0].listNo.value = checkBox.value
		  }
		
	}else if (listWindow.document.forms[0].resultCount.value > 0 ){
	
		checkBoxList = listWindow.document.forms[1].cb
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				address =  listWindow.dataList[checkBoxList[i].tag][addressI]
				document.forms[0].listNo.value = checkBoxList[i].value
				return;
			}
		}
	}
	
	}catch (e)
	{ 
		
	}
}





function cma(){
	try{
	baseURL="http://siborlistings.marketlinx.com/SearchDetail/Scripts/Cma/Custom/BuyerCma.asp?prp=Res&AgentId=bolt&UidList="	
	if (!state) return;
	mlsList = ''
	if (parent.frames['mainwindow'].document.forms['data'] != null || parent.frames['mainwindow'].document.forms[1].cb == null){
		alert("Listing must be selected!")
		return;
	}
	checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
	for (i = 0;i < checkBoxList.length; i++){
		if ( checkBoxList[i].checked){
			mlsList +=  parent.frames['mainwindow'].dataList[checkBoxList[i].tag][mlsNoI] +','
			
		}
	}
	if (mlsList != '' ){
		//alert(mlsList.substr(0,mlsList.length - 1))
		mlsList = mlsList.substr(0,mlsList.length - 1)
		openAWindowNS( baseURL+mlsList,"",800,600) 
	}
	}catch (ee)
	 {
		
	 
	 }
}

function editListing(){
	try{
	if (!state) return;
	if (parent.frames['mainwindow'].document.forms['data'] != null || parent.frames['mainwindow'].document.forms[1].cb == null){
		alert("Listing must be selected!")
		return;
	}
	if (parent.frames['mainwindow'].document.forms[0].resultCount.value == 0){
		if ( parent.frames['mainwindow'].document.forms[1].cb.checked){
			 
			checkBox = parent.frames['mainwindow'].document.forms[1].cb
			officeName = parent.frames['mainwindow'].dataList[checkBox.tag][iofficeidI]
			tmpStr =  parent.frames['mainwindow'].code  
			tmpArray = tmpStr.split(':')
	
			if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
				alert("You do not have permission to perform this operation.")	
				return;
			}	
			openAWindowNS( "AddEditListing/AddEditListing.dll/EditFrame"+document.forms[0].apptBlankLink.value + checkBox.value,"",700,530) 
	
		}else {
			alert("Listing must be selected!")
			return;	
		}
		//checkBox = parent.frames['mainwindow'].document.forms[1].cb 
		//if ( parent.frames['mainwindow'].document.forms[1].cb.checked){
		//	openAWindowNS( "fdmweb.dll/viewAppt"+document.forms[0].apptBlankLink.value + checkBox.value,"",700,530) 
		//}
	}else if (parent.frames['mainwindow'].document.forms[0].resultCount.value > 0 ){
		if (parent.frames['mainwindow'].document.forms['data'] != null || parent.frames['mainwindow'].document.forms[1].cb == null){
			alert("Listing must be selected!")
			return;
		}
		checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
		itemFound = false
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				checkBox = checkBoxList[i]
				itemFound = true
				officeName = parent.frames['mainwindow'].dataList[checkBox.tag][iofficeidI]
				tmpStr =  parent.frames['mainwindow'].code  
				tmpArray = tmpStr.split(':')
				
				if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
					alert("You do not have permission to perform this operation.")	
					continue;
				}	
				address =  parent.frames['mainwindow'].dataList[checkBoxList[i].tag][addressI]
			//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].value)
				openAWindowNS( "AddEditListing/AddEditListing.dll/EditFrame"+document.forms[0].apptBlankLink.value + checkBoxList[i].value,"",700,530) 
			}
		}
		if ( ! itemFound){
			alert("Listing must be selected!")
		}
	}
	
	}catch (ee)
	 {
		
		alert("Listing must be selected!")
	 }
}

function confirmAppt(){
	if (!state) return;
		//alert("fdmweb.dll/confirmAppt"+document.forms[0].apptBlankLink.value )
		openAWindowWS( "fdmweb.dll/confirmAppt"+document.forms[0].apptBlankLink.value ,"",700,530) 
}



function editAppt(){
	if (!state) return;
	checkBoxList = document.forms[0].cb
	try{
	if (checkBoxList.length == null  ){
		if ( checkBoxList.checked){
			agentName =  apptList[checkBoxList.tag][1]
			document.forms[0].agentName.value = agentName
			document.forms[0].apptNo.value = apptList[checkBoxList.tag][0]
			document.forms[0].ilistNo.value = apptList[checkBoxList.tag][2]
			document.forms[0].target = apptList[checkBoxList.tag][0];
			//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].value)
			openAWindowWS( "",apptList[checkBoxList.tag][0],630,530) 
			document.forms[0].submit()
		}
	}else {
		for (i = 0;i < checkBoxList.length; i++){
		if ( checkBoxList[i].checked){
			agentName =  apptList[checkBoxList[i].tag][1]
			document.forms[0].agentName.value = agentName
			document.forms[0].apptNo.value = apptList[checkBoxList[i].tag][0] //appointment no
			document.forms[0].ilistNo.value = apptList[checkBoxList[i].tag][2] //listno
			document.forms[0].apptAgentCode.value = apptList[checkBoxList[i].tag][4] //agentcode
			document.forms[0].target = apptList[checkBoxList[i].tag][0];
			//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].value)
			openAWindowWS( "",apptList[checkBoxList[i].tag][0],630,530) 
			document.forms[0].submit()
		
		}
		}
	}
	}catch (ee)
	 {
	
	 
	 }
}
function editApptLink(apptRef,officeNo){
	try{
	checkBoxList = document.forms[0].cb
	if (checkBoxList.length == null){
		checkBoxList.checked = true;
	}else {
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].tag == apptRef){
				 checkBoxList[i].checked = true
			}
		}
	}
	
	setState2(true)
	document.forms[0].listingOffice.value = officeNo
	editAppt();
	}catch (ee)
	 {
		
	 
	 }
}

function editActivityLink(activityRef){
	//try{
	checkBoxList = document.forms[0].cb
	if (checkBoxList.length == null){
		checkBoxList.checked = true;
	}else {
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].tag == activityRef){
				 checkBoxList[i].checked = true
			}
		}
	}
	
	setState2(true)
	editActivity();
	//}catch (ee)
	//{
		
	 
	//}
}
function editActivity(){
	if (!state) return;
	thisFrm = document.forms[0]
	checkBoxList = document.forms[0].cb
	
	//try{
	if (checkBoxList.length == null  ){
		if ( checkBoxList.checked){
			
			
			thisFrm.iActivityLogID.value = checkBoxList.value
			document.forms[0].target = checkBoxList.tag;
			openAWindowNS( "",checkBoxList.tag,400,300) 
			document.forms[0].submit()
		}
	}else {
		for (i = 0;i < checkBoxList.length; i++){
		if ( checkBoxList[i].checked){
			
			thisFrm.iActivityLogID.value = checkBoxList[i].value
			//thisFrm.iListno.value = checkBoxList[i].tag2 
			document.forms[0].target = checkBoxList[i].tag;
			//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].value)
			openAWindowNS( "",checkBoxList[i].tag,400,300) 
			document.forms[0].submit()
		}
		}
	}
	//}catch (ee)
	// {
		
	 
	// }
}



function editContactList(){
	if (!state) return;
	thisFrm = document.forms[0]
	checkBoxList = document.forms[0].cb
	
	//try{
	if (checkBoxList.length == null  ){
		if ( checkBoxList.checked){
			editContact(checkBoxList.value)
			checkBoxList.checked = false
		}
	}else {
		for (i = 0;i < checkBoxList.length; i++){
		if ( checkBoxList[i].checked){
			
			editContact( checkBoxList[i].value)
			 checkBoxList[i].checked = false
		}
		}
	}
	//}catch (ee)
	// {
		
	 
	// }
}

function deleteAppt(){
	if (!state) return;
   try{
	checkBoxList = document.forms[0].cb
	deleteList = '-999';
	if (checkBoxList.length == null){
		if ( checkBoxList.checked){
			deleteList += ','+apptList[checkBoxList.tag][0]		
		}
	}else {
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				deleteList += ','+apptList[checkBoxList[i].tag][0]
			//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].value)
			
			}
		}
	}
	if ( confirm("Are you sure?") ){
		document.forms[0].target = '_self'
		document.forms[0].action = 'viewAppt'
		document.forms[0].deleteList.value = deleteList
		document.forms[0].submitType.value = 'delete'
		document.forms[0].submit()
	}
}catch(ee){

}
}


function deleteContact(){
	if (!state) return;
	
   try{
	checkBoxList = document.forms[0].cb
	deleteList = "'-999'";
	if (checkBoxList.length == null){
		if ( checkBoxList.checked){
			deleteList += ",'"+checkBoxList.value+ "'"	
		}else {
			alert('A contact must be selected');
		}
	}else {
		
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				deleteList += ",'"+checkBoxList[i].value+ "'"
				 checkBoxList[i].checked = false
			}
		}
	}
	if ( deleteList != "'-999'" ) {
		if (confirm("Are you sure?")){
		    document.forms[0].target = '_self'
		    document.forms[0].deleteList.value = deleteList
		    document.forms[0].submitType.value = 'delete'
		    document.forms[0].submit()
		}
	}else {
		alert('A contact must be selected');
	}
}catch(e){
	alert('Error occurred while Deleting Contact.')
	 var buf="Exception properties:\n"
   /* for(var prop in e)
        buf+=prop+"="+e[prop]+"\n"
    alert(buf)*/

}
}

function deleteAgent(){
	if (!state) return;
	
   try{
	checkBoxList = document.forms[0].cb
	deleteList = "'-999'";
	if (checkBoxList.length == null){
		if ( checkBoxList.checked){
			deleteList += ",'"+checkBoxList.value+ "'"	
		}
	}else {
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				deleteList += ",'"+checkBoxList[i].value+ "'"
			//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].value)
			
			}
		}
	}
	if (confirm("Are you sure?")){
	    document.forms[0].target = '_self'
	    document.forms[0].deleteList.value = deleteList
	    document.forms[0].submitType.value = 'delete'
	    document.forms[0].submit()
	}

}catch(e){
	alert('Error occurred while Deleting Agent.')
	 var buf="Exception properties:\n"
   /* for(var prop in e)
        buf+=prop+"="+e[prop]+"\n"
    alert(buf)*/

}
}


function editAgentTrigger(){
	if (!state) return;
	
   try{
	checkBoxList = document.forms[0].cb
	deleteList = "'-999'";
	if (checkBoxList.length == null){
		if ( checkBoxList.checked){
			editAgent(checkBoxList.value)	
		}
	}else {
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				editAgent(checkBoxList[i].value)
				checkBoxList[i].checked = false
			
			
			}
		}
	}
	
}catch(e){
	alert('Error occurred while triggering edit agent.')
	 var buf="Exception properties:\n"
   /* for(var prop in e)
        buf+=prop+"="+e[prop]+"\n"
    alert(buf)*/

}
}


function UploadPhoto(){
   if (!state) return;
   try{
	checkBoxList = document.forms[0].cb
	deleteList = "'-999'";
	if (checkBoxList.length != null){
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				itemFound = true
				AgentCode = checkBoxList[i].value
				ImageName = AgentCode + ".JPG"
				tmpStr = document.forms[0].szWebCode.value
				tmpStr2 = document.forms[0].dbString.value
				tmpArray = tmpStr.split(':')
				tmpArray2 = tmpStr2.split(':')
   				dbPrefix = tmpArray2[1]
				//alert(AgentCode+' '+dbPrefix + ' '+ImageName)				
				//alert("postphoto.asp?AgentCode="+AgentCode+"&dbPrefix="+dbPrefix)
				openAWindowNS( "../postphoto.asp?AgentCode="+AgentCode+"&dbPrefix="+dbPrefix,"update",450,150) 
				checkBoxList[i].checked = false
				return;
				}
		}
	}	

	
    }catch(e){
	alert('Error: Check only one Agent and try again!')
	var buf="Exception properties:\n"
   	/* for(var prop in e)
        buf+=prop+"="+e[prop]+"\n"
    	alert(buf)*/
	}
}


function deleteActivity(){
	if (!state) return;
   try{
	checkBoxList = document.forms[0].cb
	deleteList = '-999';
	if (checkBoxList.length == null){
		if ( checkBoxList.checked){
			deleteList += ','+checkBoxList.value		
		}
	}else {
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				deleteList += ','+checkBoxList[i].value
			
			}
		}
	}
	if (confirm("Are you sure?")){
	    document.forms[0].target = '_self'
	    document.forms[0].action = 'viewActivity'
	    document.forms[0].deleteList.value = deleteList
	    document.forms[0].submitType.value = 'delete'
	    document.forms[0].submit()
	}
}catch(ee){

}
}


//////////////////////////////////////////////////////////////////////////////////////////////
//	Puts the advance search screen in the main window
//////////////////////////////////////////////////////////////////////////////////////////////
function advanceSearch(){
	if (!state) return;
	dbS= parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	
	parent.frames["mainwindow"].location.href =  'fdmweb.dll/searchInputScreen?dbString='+dbS+'&szWebCode='+dbCode
	//alert('searchInputScreen?dbString='+dbS+'&szWebCode='+dbCode)
	

}


//////////////////////////////////////////////////////////////////////////////////////////////
//	Puts the advance search screen in the main window
//////////////////////////////////////////////////////////////////////////////////////////////
function addContact(){
	if (!state) return;
	dbS= document.forms[0].dbString.value 
	dbCode = document.forms[0].szWebCode.value
	//parent.frames["mainwindow"].location.href =  'fdmweb.dll/searchInputScreen?dbString='+dbS+'&szWebCode='+dbCode
	urlText = "addBuyerSeller?report=bsl.html&dbString=" +dbS +"&reportfile="  + "&submitType=edit&iBuyerID=&szWebCode=" + dbCode 
	openAWindowWS(urlText,"AddEditBuyerSellerWindow",670,510);	

//openAWindowWS( 'callerLog?dbString='+dbS+'&szWebCode='+dbCode,"",500,425)
	//alert('searchInputScreen?dbString='+dbS+'&szWebCode='+dbCode)
}


//////////////////////////////////////////////////////////////////////////////////////////////
//	Puts the advance search screen in the main window
//////////////////////////////////////////////////////////////////////////////////////////////
function callerLog(){
	if (!state) return;
	dbS= parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	//parent.frames["mainwindow"].location.href =  'fdmweb.dll/searchInputScreen?dbString='+dbS+'&szWebCode='+dbCode
	openAWindowWS( 'fdmweb.dll/callerLog?dbString='+dbS+'&szWebCode='+dbCode,"",510,425)
	//alert('searchInputScreen?dbString='+dbS+'&szWebCode='+dbCode)
}

function addCaller(){
	openCallerLog(document.forms[0].szWebCode.value,document.forms[0].dbString.value)
}


function openCallerLog(aCode,dbCode){

	openAWindowWS( 'callerLog?dbString='+dbCode+'&szWebCode='+aCode,"",500,475)
}

//Save caller log
function saveCallerLog(){
   //alert('save caller')
    document.forms[0].action = "saveCaller";
	if( document.forms[0].todoCheck.checked ){
	    if( document.forms[0].dtRemind.Value > '' ){	
		document.forms[0].nextTime.options[document.forms[0].nextTime.selectedIndex].value
		if (document.forms[0].nextTime.options[document.forms[0].nextTime.selectedIndex].value == '' ){
			alert('Remind time is required if Todo checkbox is checked');
			document.forms[0].nextTime.focus()
			return;
		    }
		}
		document.forms[0].todo.value = "T"
	}else{
		document.forms[0].todo.value = "F"
	}
	
	document.forms[0].busPhone.value = cleanPhone(document.forms[0].busPhone.value)
	document.forms[0].cellPhone.value = cleanPhone(document.forms[0].cellPhone.value)
	document.forms[0].resPhone.value = cleanPhone(document.forms[0].resPhone.value)
	document.forms[0].szName.value = document.forms[0].contact.value
	if( document.forms[0].completedCheck.checked ){
		document.forms[0].completed.value = "T"
		if (document.forms[0].completedDate.value == '' ){
			alert('Completion date is required if completed checkbox is checked');
			document.forms[0].completedDate.focus()
			return;
		}
	}else{
		document.forms[0].completed.value = "F"
	}

	currentDate = new Date()
	correctMonth = currentDate.getMonth()+1
	//alert(correctMonth + '/' + currentDate.getDate() + '/' + currentDate.getYear() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes() + ':' + currentDate.getSeconds())
	document.forms[0].localDateTime.value = correctMonth + '/' + currentDate.getDate() + '/' + currentDate.getYear() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes() + ':' + currentDate.getSeconds()

	document.forms[0].submit();
	//alert('save caller')
	//window.close();
}

function addManagement(){
	//checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
	//getMAListingNo()
	//alert(document.forms[0].iListNo.value)
	openManagement(document.forms[0].szWebCode.value)
}

function openManagement(aCode,dbCode,iListNo){

	openAWindowWS( 'editManagement?dbString='+dbCode+'&szWebCode='+aCode +'&iListno='+ iListNo,"",510,325)
}



function editManagement(iTradeActivityID){
	
	dbS= document.forms[0].dbString.value 
	dbCode = document.forms[0].szWebCode.value
	openAWindowWS( 'editManagement?dbString='+dbS+'&szWebCode='+dbCode+'&submitType=edit&iTradeActivityID='+iTradeActivityID,"",510,325)
	
}


function Management(){
	try{
	if (!state) return;
	if (parent.frames['mainwindow'].document.forms['data'] != null || parent.frames['mainwindow'].document.forms[1].cb == null){
		alert("Listing must be selected!")
		return;
	}
	if (parent.frames['mainwindow'].document.forms[0].resultCount.value == 0){
		if ( parent.frames['mainwindow'].document.forms[1].cb.checked){
			 
			checkBox = parent.frames['mainwindow'].document.forms[1].cb
			officeName = parent.frames['mainwindow'].dataList[checkBox.tag][iofficeidI]
				     
			tmpStr = parent.frames['mainwindow'].code 
			tmpArray = tmpStr.split(':')
			if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
				alert('You may not view Transaction Management items for another office.')	
				return
			}		
			//alert(officeName)
			//openAWindowWS( "fdmweb.dll/viewAppt"+document.forms[0].apptBlankLink.value + checkBox.value+'&listingOffice='+officeName,"",700,530) 
			dbS= parent.frames["searchwindow"].document.forms[0].dbString.value 
			dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
			openAWindowWS( 'fdmweb.dll/Management?dbString='+dbS+'&szWebCode='+dbCode+'&iListno='+checkBoxList[i].value,"",730,550)
		}else {
			alert("Listing must be selected!")
			return;	
		}
	}else if (parent.frames['mainwindow'].document.forms[0].resultCount.value > 0 ){
		checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
		itemFound = false
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				itemFound = true
				officeName = parent.frames['mainwindow'].dataList[checkBoxList[i].tag][iofficeidI]
				tmpStr = parent.frames['mainwindow'].code 
				tmpArray = tmpStr.split(':')
	
				if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
					alert('You may not view  another office\'s Transaction Managemnet.')	
					continue
				}
				address =  parent.frames['mainwindow'].dataList[checkBoxList[i].tag][addressI]
				//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].value)
				//openAWindowWS( "fdmweb.dll/viewAppt"+document.forms[0].apptBlankLink.value + checkBoxList[i].value+'&listingOffice='+officeName,"",700,530) 
				dbS= parent.frames["searchwindow"].document.forms[0].dbString.value 
				dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
				openAWindowWS( 'fdmweb.dll/Management?dbString='+dbS+'&szWebCode='+dbCode+'&iListno='+checkBoxList[i].value,"",730,550)
			}
		}
		if ( ! itemFound){
			alert("Listing must be selected!")
		}
	}
	}catch (ee)
	 {
		alert("Listing must be selected!")
	 
	 }

///////
	//if (!state) return;
	//dbS= parent.frames["searchwindow"].document.forms[0].dbString.value 
	//dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	//openAWindowWS( 'fdmweb.dll/Management?dbString='+dbS+'&szWebCode='+dbCode+'&CashReceipt=T',"",730,550)
}

//////////////////////////////////////////////////////////////////////////////////////////////
//	Function called when to get Listing no for ManagementActivity
//////////////////////////////////////////////////////////////////////////////////////////////
function getMAListingNo(){
try{
	if (document.forms[0].iTradeActivityID.value != ''){
		listWindow = opener.opener.parent.frames['mainwindow']		
	}else {
		listWindow = opener.opener.parent.frames['mainwindow']		
		//listWindow = opener.parent.frames['mainwindow']	
	}
	if (listWindow.document.forms['data'] != null || listWindow.document.forms[1].cb == null){
		alert("Listing must be selected!")
		return;
	}
	//alert(listWindow.document.forms[0].resultCount.value)
	if (listWindow.document.forms[0].resultCount.value == 0){
		if ( listWindow.document.forms[1].cb.checked){
			 
			checkBox = listWindow.document.forms[1].cb
			address =  listWindow.dataList[checkBox.tag][addressI]
			document.forms[0].iListNo.value = checkBox.value
		  }
		
	}else if (listWindow.document.forms[0].resultCount.value > 0 ){
	
		checkBoxList = listWindow.document.forms[1].cb
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				address =  listWindow.dataList[checkBoxList[i].tag][addressI]
				document.forms[0].iListNo.value = checkBoxList[i].value
				//alert(document.forms[0].iListNo.value)
				return;
			}
		}
	}
	
	}catch (e)
	{ 
		
	}
}



function saveManagementActivity(){

    document.forms[0].action = "saveManagementActivity";
	if( document.forms[0].fCompleted.checked ){
		document.forms[0].fCompleted.value = "T"
	}else{
		document.forms[0].fCompleted.value = "F"
	}
	
	document.forms[0].submit();

}

//////////////////////////////////////////////////////////////////////////////////////////////
//	Displays callerLog window.
//////////////////////////////////////////////////////////////////////////////////////////////
function todoList(){
	if (!state) return;
	dbS= parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	openAWindowWS( 'fdmweb.dll/viewCaller?dbString='+dbS+'&szWebCode='+dbCode+'&toDo=T&completed=F',"",630,450)
}

//ToDo list search
function todoSearch(){
   //alert('save caller')
 
	if( document.forms[0].todoCheck.checked ){
		document.forms[0].todo.value = "T"
	}else{
		document.forms[0].todo.value = "F"
	}
	
	if( document.forms[0].completedCheck.checked ){
		document.forms[0].completed.value = "T"
	}else{
		document.forms[0].completed.value = "F"
	}
}

function setToDoSeachDetails(input){
	data = split(input,',')
	document.forms[0].fromDate.value = data[0]
	document.forms[0].toDate.value = data[1]
	if (data[3] == 'T'){
		document.forms[0].todoCheck.checked = true
	}else {
		document.forms[0].todoCheck.checked = false
	}
	
	if (data[4] == 'T'){
		document.forms[0].completedCheck.checked = true
	}else {
		document.forms[0].completedCheck.checked = false
	}
	options = document.forms[0].source.options
	for ( i = 0;i < document.forms[0].source.length;i++){
		if ( options[i].text == data[5] ){
			options[i].selected = true;
			break;
		}
	}
	options = document.forms[0].agentCode.options
	for ( i = 0;i < document.forms[0].source.length;i++){
		if ( options[i].value == data[2] ){
			options[i].selected = true;
			break;
		}
	}
}





function editCaller(clCount,contactCode,callId){
	
	dbS= document.forms[0].dbString.value 
	dbCode = document.forms[0].szWebCode.value
	//parent.frames["mainwindow"].location.href =  'fdmweb.dll/searchInputScreen?dbString='+dbS+'&szWebCode='+dbCode
	//alert('callerLog?dbString='+dbS+'&szWebCode='+dbCode+'&submitType=edit&callerLogId='+callId+'&buyerSeller='+contactCode);
	openAWindowWS( 'callerLog?dbString='+dbS+'&szWebCode='+dbCode+'&submitType=edit&callerLogId='+callId+'&buyerSeller='+contactCode,"",500,475)
	//alert( 'callerLog?dbString='+dbS+'&szWebCode='+dbCode+'&submitType=edit&callerLogId='+callId+'&buyerSeller='+contactCode,"",500,380)
	
}





function emailCaller(contactCode){
	dbS= document.forms[0].dbString.value 
	dbCode = document.forms[0].szWebCode.value
	contactCode = document.forms[0].buyerSellerCode.value
	//alert("code:"+document.forms[0].buyerSellerCode.value+'dbCode:'+dbCode)
	callid=""
	//parent.frames["mainwindow"].location.href =  'fdmweb.dll/searchInputScreen?dbString='+dbS+'&szWebCode='+dbCode
	//alert('callerLog?dbString='+dbS+'&szWebCode='+dbCode+'&submitType=edit&callerLogId='+callId+'&buyerSeller='+contactCode);
	openAWindowWS( 'callerLog?dbString='+dbS+'&szWebCode='+dbCode+'&submitType=email&buyerSeller='+contactCode,"",500,450)
	//alert( 'callerLog?dbString='+dbS+'&szWebCode='+dbCode+'&submitType=email&buyerSeller='+contactCode)
		
}


function cleanPhone(input){
	rString = '';
	if (input == '' ) return '';
	for (i = 0;i < input.length;i++){
		if (isDigit(input.charAt(i))){
			rString += input.charAt(i)
		}
	}
	return rString;
}

function setCompletedDate(){
	if (document.forms[0].completedCheck.checked){
		setDate(document.forms[0].completedDate)
	}else {
		document.forms[0].completedDate.value =  ''
		
	}
}

function setdtDateCompleted(){
	if (document.forms[0].fCompleted.checked){
		setDate(document.forms[0].dtCompleted)
	}else {
		document.forms[0].dtCompleted.value =  ''
		
	}
}


function setNextTime(){
	if (document.forms[0].todoCheck.checked){
		document.forms[0].nextTime.selectedIndex = 1
	}else {
		document.forms[0].nextTime.selectedIndex = 0
		
	}
}

function editCallerList(){	
	checkBoxList = document.forms[0].cb
	try{
	if (checkBoxList.length == null  ){
		if ( checkBoxList.checked){
			
			myId=checkBoxList.value
			myNumber=checkBoxList.tag
			editCaller(0,myNumber,myId)
		}
	}else {
		for (i = 0;i < checkBoxList.length; i++){
		if ( checkBoxList[i].checked){
			myId=checkBoxList[i].value
			myNumber=checkBoxList[i].tag
			editCaller(i,myNumber,myId)
		}
		}
	}
	}catch (ee)
	 {
		
	 	alert('Error occured while editing caller.');
	 }
}

//////////////////////////////////////////////////////////////////////////////////////////////
//	Function called when the street number is clicked on a listing search result.
//////////////////////////////////////////////////////////////////////////////////////////////
function viewTodaysAppt(apptNo,listNo){
	doc = document.forms[0]
	myLink = "?dbString="+doc.dbString.value+"&ilistNo="+listNo+"&submitType=edit"
	openAWindowWS( "viewAppt"+myLink,"",700,230) 
	//alert( "viewAppt"+myLink,"",700,230)  


}

function openListingSearch(){
	//alert('teste')
	//alert(document.forms[0].ListNo.value)
	//alert("searchListing?SearchName="+ document.forms[0].ListNo.value + "&dbString=" +document.forms[0].dbString.value +"&submitType=search&szWebCode=" + document.forms[0].szWebCode.value)
	tUrl = 	"searchListing?SearchName="+ document.forms[0].ListNo.value + "&dbString=" +document.forms[0].dbString.value +"&submitType=search&szWebCode=" + document.forms[0].szWebCode.value
	//alert(tUrl)
	openAWindowWS( tUrl ,"",575,280) 
}


function openAgentSearch(){
	tUrl = 	"searchAgent?SearchName="+ document.forms[0].agentName.value + "&dbString=" +document.forms[0].dbString.value +"&submitType=search&szWebCode=" + document.forms[0].szWebCode.value
	//alert(tUrl)
	openAWindowWS( tUrl ,"",575,280) 
}

function openAgentSearch(){
	tUrl = 	"searchAgent?SearchName="+ document.forms[0].agentName.value + "&dbString=" +document.forms[0].dbString.value +"&submitType=search&szWebCode=" + document.forms[0].szWebCode.value
	//alert(tUrl)
	openAWindowWS( tUrl ,"",575,280) 
}



function openShortAgentSearch(){
	theFrm= document.forms[0]
	
	tUrl = 	"searchAgent?SearchName="+ document.forms[0].agentName.value + "&dbString=" +document.forms[0].dbString.value +"&submitType=search&szWebCode=" + document.forms[0].szAgentCode.value
	//alert(tUrl)
	openAWindowWS( tUrl ,"",575,280) 
}

function openBuyerSellerSearch(){
	tUrl = 	"buyerSellerSearch?buyerSeller="+ document.forms[0].contact.value + "&dbString=" +document.forms[0].dbString.value +"&submitType=search&szWebCode=" + document.forms[0].szWebCode.value
	//alert(tUrl)
	openAWindowWS( tUrl ,"",500,280) 
}

function openBuyerSellerSearchBSL(){
	tUrl = 	"../fdmweb.dll/buyerSellerSearch?buyerSeller="+ document.forms[0].contact.value + "&dbString=" +document.forms[0].dbString.value +"&submitType=search&szWebCode=" + document.forms[0].szWebCode.value
	//alert(tUrl)
	openAWindowWS( tUrl ,"",500,280) 
}

function transferAgentInfo(agentName,agentID,agentCode,companyName,companyNumber,agentNumber,email){
	pdoc = opener.document.forms[0]  //parent form
	
	if ( pdoc.name == 'ShortSearchForm'){
		pdoc.agentName.value  =  agentCode
	
	}else {
		cdoc = document.forms[0]  //current form
		pdoc.agentName.value  =  agentName
		pdoc.apptAgentName.value =  agentName
		pdoc.agentNumber.value = formatPhone(agentNumber)
		pdoc.companyName.value =  companyName
		pdoc.companyNumber.value =  formatPhone(companyNumber)
		pdoc.apptAgentCode.value =  agentCode
		pdoc.agentEmail.value = email
	}
	window.close()
}

function transferListingInfo(ListNo){
	pdoc = opener.document.forms[0]  //parent form
	pdoc.ListNo.value  =  ListNo
	window.close()
}


function transferContactInfo(szName,bsID,cellPhone,busPhone,resPhone,agentCode,email1,source){
	pdoc = opener.document.forms[0]  //parent form
	cdoc = document.forms[0]  //current form
	pdoc.buyerSellerName.value  =  decodeData(szName)
	pdoc.contact.value =  decodeData(szName)
	pdoc.busPhone.value = formatPhone(busPhone)
	pdoc.resPhone.value =  formatPhone(resPhone)
	pdoc.cellPhone.value =  formatPhone(cellPhone)
	pdoc.buyerSellerCode.value =  bsID
	pdoc.emailAddress.value =  email1
	
	options = pdoc.agentCode.options
	for ( i = 0;i < options.length;i++){
		optionValue = options[i].value
		optionValue = optionValue.replace(/ /,'')                 
		if ( optionValue == agentCode ){
			options[i].selected = true;
			break;
		}		
	}
	options = pdoc.source.options
	for ( i = 0;i < options.length;i++){
		optionValue = options[i].value          
		if ( optionValue == source ){
			options[i].selected = true;
			break;
		}		
	}
	window.close()
}

function ReportSubmit(myForm,formName){
	openAWindowWS("../waiting.html","reportWindow",770,470)
	myForm.submit();
				
}


function reportsMenu(filename){
	
	if (!state) return;
	dbS = parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	officeInfo = parent.frames['title'].document.forms[0].officeInfo.value
	//alert('fdmweb.dll/reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode)
	openAWindowNS('fdmweb.dll/reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode+'&officeInfo='+officeInfo,"reports",320,160)	
	//alert('/fdm/fdmweb.dll/reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode+'&officeInfo='+officeInfo,"reports",320,120)		
	//alert('alert')
	//openAWindowNS("reportlist.html",'Reports',320,100)		
}


function prefMenu(filename){
	
	if (!state) return;
	dbS = parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	officeInfo = parent.frames['title'].document.forms[0].officeInfo.value
	//alert('fdmweb.dll/reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode)
	openAWindowNS('fdmweb.dll/reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode+'&officeInfo='+officeInfo,"preference",520,160)	
		
}

function reportsMenu3(filename){
	dbS = parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	officeInfo = parent.frames['title'].document.forms[0].officeInfo.value
	alert('fdmweb.dll/reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode)
	openAWindowNS('/fdm/fdmweb.dll/reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode+'&officeInfo='+officeInfo,"Reports",320,430)		
	//alert('alert')
	//openAWindowNS("../reportlist.html",'Reports',320,200)		
}

function reportsMenu4(filename){
	dbS = parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	officeInfo = parent.frames['title'].document.forms[0].officeInfo.value
	alert('fdmweb.dll/reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode)
	openAWindowNS('/fdm/fdmweb.dll/reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode+'&officeInfo='+officeInfo,"Reports",320,430)		
	//alert('alert')
	//openAWindowNS("../reportlist.html",'Reports',320,200)		
}


function reportsFeature(filename){
	alert('alert')
	openAWindowNS("../reportlist.html",'Reports',320,200)		
}



function selectReport(filename){
	
	document.forms[0].report.value = filename
	document.forms[0].submit();
}

function reportsMenu2(filename,officeData,height){
	
	dbS = opener.parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = opener.parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	
	//alert('reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode+'&officeInfo='+officeData)
	
	openAWindowNS('reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode+'&officeInfo='+officeData,'Reports',340,height)		
	window.close()
}

function reportsMenu3(filename,officeData,height){
	
	dbS = opener.parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = opener.parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	
	//alert('reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode)
	
	openAWindowNS('reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode+'&officeInfo='+officeData,'Reports',595,height)		
	window.close()
}

function reportsMenu4(filename,officeData,height){
	
	dbS = opener.parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = opener.parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	openAWindowNS('reports?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode+'&officeInfo='+officeData,'Reports',400,height)		
	window.close()
}



function sndMessage(input){
	alert(input)

}

function setAgentName(){
	document.forms[0].agentName.value = document.forms[0].listingAgent.options[document.forms[0].listingAgent.selectedIndex].text
	
}

function setCallerName(){
	document.forms[0].callerName.value = document.forms[0].caller.options[document.forms[0].caller.selectedIndex].text	
}

function setDefaultOffice(){
	tmpString = code
	multiple = false
	list = split(tmpString,":");
	myOffices = list[0]
	list = split(list[0],",");
	if (list.length > 1 )  {
		multiple = true
	}
	list = split(list[0],"'");
			
	officeName = list[1]
	options = document.forms[0].office.options
	if ( multiple ){
		options[1].selected = true
		return
	}
	for ( i = 0;i < document.forms[0].office.length;i++){
		optionValue = options[i].value
		optionValue = optionValue.replace(/ /,'')                 
		if ( optionValue == officeName ){
			options[i].selected = true;
			break;
		}
		
	}
	
}

function cleanPrices(){
	aForm = document.forms[0]
	aForm.currentPrice.value = cleanNumber(aForm.currentPrice.value)
	alert(aForm.currentPrice.value )
	aForm.OriginalListPrice.value = cleanNumber(aForm.OriginalListPrice.value)
}

function addEditContacts() {
	if (!state) return;
	dbS = parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	openAWindowWS('fdmweb.dll/contactList?dbString='+dbS+'&submitType=init&szWebCode='+dbCode,'AddEditContact',700,530)			
}

function addEditContacts2() {
	dbS = document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	openAWindowWS('fdmweb.dll/contactList?dbString='+dbS+'&szWebCode='+dbCode,'AddEditContact',550,410)			
}


function addEditAgent() {
	if (!state) return;
	dbS = parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	openAWindowWS('fdmweb.dll/searchAgentList?dbString='+dbS+'&szWebCode='+dbCode,'AddEditAgent',730,550)			
}

function addAgent() {
	dbS = document.forms[0].dbString.value 
	dbCode = document.forms[0].szWebCode.value
	openAWindowWS('addAgent?dbString='+dbS+'&szWebCode='+dbCode,'',670,480)
}

function saveAgent() {

	cDoc = document.forms[0]
	cDoc.sztResPhone.value = cleanPhone(cDoc.sztResPhone.value)
	cDoc.sztBusPhone.value = cleanPhone(cDoc.sztBusPhone.value)
	cDoc.sztCellPhone.value = cleanPhone(cDoc.sztCellPhone.value)
	cDoc.sztFaxPhone.value = cleanPhone(cDoc.sztFaxPhone.value)
	cDoc.sztAltPhone.value = cleanPhone(cDoc.sztAltPhone.value)
	cDoc.sztSpousePhone.value = cleanPhone(cDoc.sztSpousePhone.value)


	theFrm =  document.forms[0]
	if( theFrm.szAgentCode.value == '' ){
		alert("Agent code cannot be blank")
		theFrm.szAgentCode.focus()
		return
	}

	if ( new String(theFrm.szAgentCode.value).indexOf(' ') == -1){
			}else{
			alert("Agent Code may not contain a SPACE.")
			theFrm.szAgentCode.focus()
			return
	}

	if( theFrm.mlsCode1.value == '' ){
		alert("MLS CODE 1  cannot be blank")
		theFrm.mlsCode1.focus()
		return
	}

	if ( new String(theFrm.mlsCode1.value).indexOf(' ') == -1){
			}else{
			alert("MLS Code may not contain a SPACE.")
			theFrm.mlsCode1.focus()
			return
	}

	
	if( theFrm.szName.value == '' ){
		alert("Name  cannot be blank")
		theFrm.szName.focus()
		return
	}
	
	window.blur()
	
	document.forms[0].szAgentCode.disabled = false
	if( document.forms[0].fEmail_f.checked ){

		document.forms[0].fEmail.value = "T"
	}else{
		document.forms[0].fEmail.value = "F"
	}
	
	if ( document.forms[0].fEmail.value == 'T') {
		if (theFrm.szPostOffice.value == ''){
			alert("Email address must be entered")
			theFrm.szPostOffice.focus()
			return
		}else if ( new String(theFrm.szPostOffice.value).indexOf('@') == -1){
			alert("Valid email must be entered.")
			theFrm.szPostOffice.focus()
			return
		}
	}


	if( document.forms[0].fIndependentContract_f.checked ){

		document.forms[0].fIndependentContract.value = "T"
	}else{
		document.forms[0].fIndependentContract.value = "F"
	}

	if( document.forms[0].fRestrictFDM_f.checked ){

		document.forms[0].fRestrictFDM.value = "T"
	}else{
		document.forms[0].fRestrictFDM.value = "F"
	}

	if( document.forms[0].fRestrictAgent_f.checked ){

		document.forms[0].fRestrictAgent.value = "T"
	}else{
		document.forms[0].fRestrictAgent.value = "F"
	}

	if( document.forms[0].fNoReturnFeedback_f.checked ){

		document.forms[0].fNoReturnFeedback.value = "T"
	}else{
		document.forms[0].fNoReturnFeedback.value = "F"
	}



	//if( document.forms[0].fCopyToBoard_f.checked ){

	//	document.forms[0].fCopyToBoard.value = "T"
	//}else{
	//	document.forms[0].fCopyToBoard.value = "F"
	//}

	//if( document.forms[0].fPager_f.checked ){
        //
	//	document.forms[0].fPager.value = "T"
	//}else{
	//	document.forms[0].fPager.value = "F"
	//}
	//if( document.forms[0].fPagerAlternate_f.checked ){

	//	document.forms[0].fPagerAlternate.value = "T"
	//}else{
	//	document.forms[0].fPagerAlternate.value = "F"
	//}

	//alert('Email value:'+document.forms[0].fEmail.value)

	
	document.forms[0].submit() 
}

function editAgent(agentCode) {
	
	dbS = document.forms[0].dbString.value 
	dbCode = document.forms[0].szWebCode.value
	//alert('fdmweb.dll/editAgent?dbString='+dbS+'&szWebCode='+dbCode+'&agentCode='+agentCode)
	openAWindowWS('editAgent?dbString='+dbS+'&szWebCode='+dbCode+'&agentCode='+agentCode,'',670,480)
 }

function editContact(code) {
	
	dbS = document.forms[0].dbString.value 
	dbCode = document.forms[0].szWebCode.value
	//alert('fdmweb.dll/editAgent?dbString='+dbS+'&szWebCode='+dbCode+'&agentCode='+agentCode)
	openAWindowWS('editBuyerSeller?dbString='+dbS+'&szWebCode='+dbCode+'&code='+code,'',660,510)
 }



function AddMessage(filename){
	if (!state) return;
	dbS = parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	officeInfo = parent.frames['title'].document.forms[0].officeInfo.value
	openAWindowNS('/fdm/fdmweb.dll/AddMessage?dbString='+dbS+'&report='+filename+'&szWebCode='+dbCode+'&officeInfo='+officeInfo,"Reports",480,450)		

}

function saveMessage(){
	currentForm = document.forms[0]
	selectionValues = ''
	if (currentForm.AgentCode.value == '') {
         alert('An Agent must be selected')
  	   document.forms[0].AgentCode.focus()
	   return;
	   }	
	for (var i = 0; i < currentForm.AgentCode.length; i++) {
          if (currentForm.AgentCode.options[i].selected) {
		  if (selectionValues == '') {
              	selectionValues += "'" + currentForm.AgentCode.options[i].value + "'"
		  }else {
			selectionValues += ",'" + currentForm.AgentCode.options[i].value + "'"

		  }
          }
	} 
	//alert(selectionValues)
	currentForm.selectedAgentCode.value = selectionValues
	currentDate = new Date()
	correctMonth = currentDate.getMonth()+1
	//alert(correctMonth + '/' + currentDate.getDate() + '/' + currentDate.getYear() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes() + ':' + currentDate.getSeconds())
	document.forms[0].localDateTime.value = correctMonth + '/' + currentDate.getDate() + '/' + currentDate.getYear() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes() + ':' + currentDate.getSeconds()
	document.forms[0].submit();
}


function saveBillingLog(){
	currentForm = document.forms[0]
	selectionValues = ''
	if (currentForm.Agents.value == '') {
         alert('An Agent must be selected')
  	   document.forms[0].Agents.focus()
	   return;
	   }	
	for (var i = 0; i < currentForm.Agents.length; i++) {
          if (currentForm.Agents.options[i].selected) {
		  if (selectionValues == '') {
              	selectionValues += "'" + currentForm.Agents.options[i].value + "'"
		  }else {
			selectionValues += ",'" + currentForm.Agents.options[i].value + "'"

		  }
          }
	} 
	currentForm.selectedAgentCode.value = selectionValues
	currentDate = new Date()
	correctMonth = currentDate.getMonth()+1
	//alert(correctMonth + '/' + currentDate.getDate() + '/' + currentDate.getYear() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes() + ':' + currentDate.getSeconds())
	document.forms[0].localDateTime.value = correctMonth + '/' + currentDate.getDate() + '/' + currentDate.getYear() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes() + ':' + currentDate.getSeconds()
	document.forms[0].submit();
}


function ViewBillingLog(){
	if (!state) return;
	dbS= parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	openAWindowWS( 'fdmweb.dll/ViewBillingLog?dbString='+dbS+'&szWebCode='+dbCode+'&CashReceipt=T',"",630,450)
}



function ListingActivity(){
	if (!state) return;
	try{
	dbS= parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	code = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	activityBlankLink = '?dbString='+dbS+'&szWebCode='+code +'&listNo='
	//openAWindowWS( 'fdmweb.dll/ListingActivity?dbString='+dbS+'&szWebCode='+dbCode,"",400,300)
	//alert('searchInputScreen?dbString='+dbS+'&szWebCode='+dbCode)
	
	
	
	if (parent.frames['mainwindow'].document.forms['data'] != null || parent.frames['mainwindow'].document.forms[1].cb == null){
		alert("Listing must be selected!")
		return;
	}
	
	if (parent.frames['mainwindow'].document.forms[0].resultCount.value == 0){
		if ( parent.frames['mainwindow'].document.forms[1].cb.checked){
			checkBox = parent.frames['mainwindow'].document.forms[1].cb
			officeName = parent.frames['mainwindow'].dataList[checkBox.tag][iofficeidI]
			tmpStr = parent.frames['mainwindow'].code 
			tmpArray = tmpStr.split(':')
	
			if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
				alert('You rmission to perform this operation.')	
				return
			}	
			openAWindowNS( "fdmweb.dll/ListingActivity"+activityBlankLink + checkBox.value+'&listingOffice='+officeName,"",400,300) 			
		}else {
			alert("Listing must be selected!")
		}
	}else if (parent.frames['mainwindow'].document.forms[0].resultCount.value > 0 ){
		checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
		itemFound=false
		for (i = 0;i < checkBoxList.length; i++){
			if ( checkBoxList[i].checked){
				itemFound=true
				officeName = parent.frames['mainwindow'].dataList[checkBoxList[i].tag][iofficeidI]
				tmpStr = parent.frames['mainwindow'].code 
				tmpArray = tmpStr.split(':')
	
				if ( tmpArray[0].indexOf("'"+officeName+"'") == -1 ){
					//urlText = "fdmweb.dll/ListingActivity"+activityBlankLink + checkBoxList[i].value + '&apptType=request'+'&listingOffice='+officeName
					//windowWidth = 270
					alert('You may not add a listing activity for another office\\\'s listing.\'')
				}else{
					urlText = "fdmweb.dll/ListingActivity"+ activityBlankLink + checkBoxList[i].value+'&listingOffice='+officeName
					windowWidth = 300
				}
			
				//alert(urlText)
				openAWindowNS( urlText,"",400,windowWidth) 
			}
		}
		if ( ! itemFound){
			alert("Listing must be selected!")
		}
	}
	}catch (ee)
	 {
		alert("Listing must be selected!")
	 }
}

function saveListingActivity(){
   //alert('save caller')
    document.forms[0].action = "SaveActivity";
	if( document.forms[0].fIncludeExclude.checked ){
		document.forms[0].fIncludeExclude.value = "T"
	}else{
		document.forms[0].fIncludeExclude.value = "F"
	}
	fromTOD = document.forms[0].fromTimeTOD.options[document.forms[0].fromTimeTOD.selectedIndex].value
	toTOD = document.forms[0].toTimeTOD.options[document.forms[0].toTimeTOD.selectedIndex].value
	document.forms[0].FromTime.value = document.forms[0].FromTime.value + ' ' + fromTOD
	document.forms[0].ToTime.value = document.forms[0].ToTime.value + ' ' + toTOD

	document.forms[0].submit();
	//alert('save caller')
	//window.close();
}

function loadMessages(){
	document.location.href = "Messages?agentName=" +document.forms[0].agentName.value +"&dbString=" +document.forms[0].dbString.value +"&szWebCode=" + document.forms[0].szAgentCode.value
}

function HelpItem(filename){
	helptext = "./AgentWorkstationHelp.htm"
	openAWindowWS(helptext,"",640,480)		
}

function BillAgent(){

	if (!state) return;
	dbS= parent.frames["searchwindow"].document.forms[0].dbString.value 
	dbCode = parent.frames["searchwindow"].document.forms[0].szAgentCode.value
	openAWindowWS( 'fdmweb.dll/BillAgent?dbString='+dbS+'&szWebCode='+dbCode,"",655,460)

}



function setOffice(){
	frm = document.forms[0]
	officeValue = frm.listingAgent.options[frm.listingAgent.selectedIndex].value
	if ( officeValue != "" ) {
		
		agentValue = officeValue.split(":")
		officeName = agentValue[1]
		//frm.listingAgent.options[frm.listingAgent.selectedIndex].value = agentValue[0]
		officeOptions = frm.office.options
		for (i = 0; i < officeOptions.length;i++){
			officeValues = officeOptions[i].value.split(":")
			if ( officeValues[10] == officeName){
				frm.officeInfo.value = officeOptions[i].value
				//frm.office.value = officeOptions[i].value
					
			}
		}		
	}else {
		
		if (frm.office.selectedIndex != 0){
			
			frm.officeInfo.value = frm.office.options[frm.office.selectedIndex].value
			//officeValue = frm.office.options[frm.office.selectedIndex].value
			//selectedofficeValue = officeValue.split(":")
			//alert(selectedofficeValue[10])
			//frm.office.value = selectedofficeValue[10]
			//alert(frm.office.value)
			
		}
	}

}

function setOfficeGen(officeObject){
	frm = document.forms[0]
	if (frm.office.selectedIndex != 0){
	   frm.officeInfo.value = officeObject.options[officeObject.selectedIndex].value
	}else {
		frm.officeInfo.value = officeObject.options[1].value
	}

}
function commentLength(){
	
	frm = document.forms[0]
	//comment = frm.comment.value
	//alert("testing length" + comment.length )
	comment = new String(frm.Comment.value)
	if ( comment.length > 200){
		alert("Comment connot be more than 200 characters. The current Length is "+comment.length)
		frm.comment.focus()
	}
	
}

function sendPreference(dataType,dataTable,column){
	frm = document.forms[0]
	frm.prefType.value = dataType
	frm.tb.value = dataTable
	//alert('table:'+table)
	frm.tcName.value = column	
	frm.submit()
}

function RefreshWindow(){
	parent.document.location.reload()
}

//=======================================================================================================
//=======================================================================================================
//required function and should be placed in the common.js
//information required for processing the CSV
// This allows some dynamic record selection when calling the dll
// the "DATAVIEW=BSLMAILMERGE" element in the query is used to access the XMLCSVTAGLIST.INI file. The entries
//contained in that part of the ini file allows the proper selection of the the data required.
function mailMerge(contactCode){
	
	dbS= document.forms[0].dbString.value 
	dbCode = document.forms[0].szWebCode.value
	contactCode = document.forms[0].buyerSellerCode.value
	callid=""
	openAWindowWS('csvDataRequest?DATAVIEW=BSLMAILMERGE&dbString='+dbS+'&szWebCode='+dbCode+'&buyerSeller='+contactCode+'&csvFileName='+contactCode+'&docMask=doc',"",500,450)
	
}

state = false
listingDocument = null
