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){
	//alert("agentworkstation.dll/menufileload?dbString=" +parent.frames['bulletinwindow'].document.tAgentInfo.dbString.value +"&reportfile=" + filename + "&szWebCode=" + parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value);
	parent.frames["mainwindow"].location.href = "agentworkstation.dll/menufileload?dbString=" +parent.frames['bulletinwindow'].document.tAgentInfo.dbString.value +"&reportfile=" + filename + "&szWebCode=" + parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value;
}
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){

	if (parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value != ""){
		parent.frames['menuWindow'].location.href = newUrl
		parent.frames['mainwindow'].location.href = "blank.html "
	
		
	}
	//alert(parent.frames['menuWindow'].location.href)
}


function setDate(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;
	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){	
	from = datefield.value
	
	if (isEmpty(new String(from))){
	    return true
	}	
	month = from.substr(0,2)
	day = from.substr(3,2)
    year = from.substr(6,4)
    if (((year.length != 2) && (year.length != 4)) || (!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("../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){
	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].OpenHouse)){
		alert("Open House 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;
        
	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 AddListing(){
    //parent.frames["mainwindow"].document.URL="blank.html"; 
    //parent.frames["mainwindow"].document.URL="AddEditListing/AddEditListing.dll/CreateFrame?dbString=" +parent.frames['bulletinwindow'].document.tAgentInfo.dbString.value + "&szWebCode=" + parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value
    openAWindowNS("AddEditListing/AddEditListing.dll/CreateFrame?dbString=" +parent.frames['bulletinwindow'].document.tAgentInfo.dbString.value + "&szWebCode=" + parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value,"AddListingWindow",770,510)
//  document["AddListingWindow"].href = "/AgentWorkstation/AddEditListing/AddEditListing.dll/CreateFrame?szWebCode=" + parent.frames['bulletinwindow'].document.tAgentInfo.tszWebCode.value ;
}

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 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';
        }
	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();

}

function makeAgentVisible(){
	document.all.addAgent.style.pixelLeft = 200
}

function AddAgent() {
    //openAWindowNS("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 ,"AddEditAgentWindow",420,300);
	//parent.frames['AddEditmainwindow'].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 
	//parent.frames['addAgentFrame'].document.all.addAgent.style.pixelLeft = 200
	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
	//agentFrame.top = 10
}

function CancelAgent(){
	parent.document.all.addAgent.style.pixelLeft = -1000		
}

function SaveAgent(){
	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
	 openAWindowNS(urlText,"AddEditBuyerSellerWindow",760,450);
}

function EditBuyerSeller() {
       openAWindowNS("","AddEditBuyerSellerWindow",760,450);
}

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 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(){
	if (document.forms[0].submitType.value != 'edit'){
		document.forms[0].submitType.value = 'Save';
	}
	document.forms[0].action = "saveAppt";
	document.forms[0].companyNumber.value = agentList[index][companyNumber]
	document.forms[0].agentNumber.value =agentList[index][agentNumber]
	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].submit();
}

function resetSearch(){
	document.forms[0].submitType.value = 'init';
	document.forms[0].submit();
}

function getSearchScreen(data){
	parent.frames["searchwindow"].location.href = data
}
function setState(input){
	if (input){
		if (parent.frames['title'].document.forms[0].state.value == 'in'){
			state = true
		}else{
			state = false
		}
	}else {
		state = input
	}
}

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].confirmedCheckBox.checked ){
		document.forms[0].confirmed.value = "Yes"
	}else{
		document.forms[0].confirmed.value = "No"
	}
}

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
}
function isWholeNumber(input){
	data = "0123456789"
	for ( i = 0; i < input.length;i++){
		if (data.indexOf(input.charAt(i)) == -1){
			return false;
		}
	}
	return true;
}

function e () {
}
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;
	}
	checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
	for (i = 0;i < checkBoxList.length; i++){
		if ( checkBoxList[i].checked){
			//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].value)
			openAWindowNS( "fdmweb.dll/bookAppt"+document.forms[0].apptBlankLink.value + checkBoxList[i].value,"",630,530) 
		}
	}
	}catch (ee)
	 {
		
	 
	 }
}


//////////////////////////////////////////////////////////////////////////////////////////////
//	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;
	}
	checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
	for (i = 0;i < checkBoxList.length; i++){
		if ( checkBoxList[i].checked){
			address =  parent.frames['mainwindow'].dataList[checkBoxList[i].tag][addressI]
			//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].value)
			openAWindowNS( "fdmweb.dll/viewAppt"+document.forms[0].apptBlankLink.value + checkBoxList[i].value,"",700,530) 
		}
	}
	}catch (ee)
	 {
		
	 
	 }
}


//////////////////////////////////////////////////////////////////////////////////////////////
//	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;
	}
	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 (ee)
	{ 
	}
}





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;
	}
	checkBoxList = parent.frames['mainwindow'].document.forms[1].cb
	for (i = 0;i < checkBoxList.length; i++){
		if ( checkBoxList[i].checked){
			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) 
		}
	}
	}catch (ee)
	 {
		
	 
	 }
}

function confirmAppt(){
	if (!state) return;
			//alert("fdmweb.dll/"+document.forms[0].apptBlankLink.value + checkBoxList[i].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){
	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)
	editAppt();
	}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)
			
			}
		}
	}
	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){

}
}

//////////////////////////////////////////////////////////////////////////////////////////////
//	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 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,"",500,380)
	//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,380)
}

//Save caller log
function saveCallerLog(){
   //alert('save caller')
    document.forms[0].action = "saveCaller";
    
	if (document.forms[0].submitType.value == 'edit'){	
		document.forms[0].busPhone.value = bsList[index][szBusPhoneI]
		document.forms[0].cellPhone.value = bsList[index][szCellPhoneI]
		document.forms[0].resPhone.value = bsList[index][szResPhoneI]
		document.forms[0].szName.value = document.forms[0].buyerSeller.options[document.forms[0].buyerSeller.selectedIndex].text
	}else {
		document.forms[0].szName.value = document.forms[0].buyerSeller.value
	}
	if( document.forms[0].todoCheck.checked ){
		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)
	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"
	}
	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
	//parent.frames["mainwindow"].location.href =  'fdmweb.dll/searchInputScreen?dbString='+dbS+'&szWebCode='+dbCode
	//alert('fdmweb.dll/viewCaller?dbString='+dbS+'&szWebCode='+dbCode);
	openAWindowWS( 'fdmweb.dll/viewCaller?dbString='+dbS+'&szWebCode='+dbCode,"",630,530)
	//alert('searchInputScreen?dbString='+dbS+'&szWebCode='+dbCode)
}

//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,380)
	
}

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 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){
			editCaller(0,clList[0][clcodeI],clList[0][clcallerLogIDI])
		}
	}else {
		for (i = 0;i < checkBoxList.length; i++){
		if ( checkBoxList[i].checked){
			editCaller(i,clList[i][clcodeI],clList[i][clcallerLogIDI])
		}
		}
	}
	}catch (ee)
	 {
		
	 
	 }
}
state = false
listingDocument = null
