	/* jsfunctions.js 20/May/2007 9:30am (c) Demetrius R. A. Francis */


	if (document){document.oncontextmenu = function(){return false};}
	//document.oncontextmenu=new Function("return false")

	function clickIE4(){if (event.button==2){return false;	}}

	function clickNS4(e){
		if (document.layers||document.getElementById&&!document.all){
			if (e.which==2||e.which==3){
				return false;
			}
		}
	}

	if (document.layers){
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS4;
	}
	else if (document.all&&!document.getElementById){
		document.onmousedown=clickIE4;
	}



	function showAmortization(_amount) {
   		_draf='resizable=no,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=360,height=250';
		_draf+=',left='+((screen.availWidth/2) - (360/2))+',top='+((screen.availHeight/2) - (250/2));
		modalwindow=window.open("loanamort.htm?"+_amount,"Amortization",_draf)     
		window.onfocus = function(){if (modalwindow.closed == false){modalwindow.focus();};};
	}

	function showGetImageWindow(id) {
  		var _draf='resizable=no,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=500,height=420';
		_draf+=',left='+((screen.availWidth/2) - (500/2))+',top='+((screen.availHeight/2) - (420/2));
		//modalwindow=window.open("cgi-bin/addImageForm.asp?id="+id,"DRAF",_draf)
		modalwindow=window.open("cgi-bin/addMultiImageForm.asp?id="+id,"DRAF",_draf)
		window.onfocus = function(){if (modalwindow.closed == false){modalwindow.focus();};};
	}

	function getAgentPhoto(id) {
	   	_draf='resizable=no,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=500,height=150';
		_draf+=',left='+((screen.availWidth/2) - (500/2))+',top='+((screen.availHeight/2) - (150/2));
		modalwindow=window.open("cgi-bin/addAgentPhotoForm.asp?id="+id,"photowindow",_draf)     
		window.onfocus = function(){if (modalwindow.closed == false){modalwindow.focus();};};
	}


	function getFriendEmail(id) {
	   	_draf='resizable=no,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=560,height=220';
		_draf+=',left='+((screen.availWidth/2) - (560/2))+',top='+((screen.availHeight/2) - (220/2));
		modalwindow=window.open("cgi-bin/getFriendForm.asp?id="+id,"DRAF",_draf)     
		window.onfocus = function(){if (modalwindow.closed == false){modalwindow.focus();};};
	}

	function getFlyer(id,printNotes) {
	   	_draf='resizable=yes,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=900,height=750';
		_draf+=',left='+((screen.availWidth/2) - (900/2))+',top='+((screen.availHeight/2) - (750/2));
		modalwindow=window.open("/cgi-bin/PrintFlyer.asp?o="+printNotes+"&id="+id,"DRAF",_draf)     
		window.onfocus = function(){if (modalwindow.closed == false){modalwindow.focus();};};
	}


	function getWindow(_link) {
	   	_draf='resizable=yes,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=900,height=750';
		_draf+=',left='+((screen.availWidth/2) - (900/2))+',top='+((screen.availHeight/2) - (750/2));
		modalwindow=window.open(_link,"DRAF",_draf)     
		window.onfocus = function(){if (modalwindow.closed == false){modalwindow.focus();};};
	}

	function upload(o){
		switch (o){
			case 26:
				document.forms['transfer_form'].submit_form.value= 'Working...';
				document.forms['transfer_form'].action = 'cgi-bin/add.asp?o=17';
				break;
			case 25:
				document.forms['transfer_form'].submit_form.value= 'Working...';
				document.forms['transfer_form'].action = 'cgi-bin/add.asp?o=15';
				break;
			case 24:
				document.forms['quicksearch_form'].submit_search.value= 'Working...';
				document.forms['quicksearch_form'].action = '?p=1&o=search';
				break;
			case 23:
				document.forms['content_form'].submit_content.value="Saving..."		
				document.forms['content_form'].action="?p=16&f="+document.forms['content_form'].f.value+"&o=2";
				break;
			case 22:
				document.forms['login_form'].submit_login.value= 'Please wait...';
				document.forms['login_form'].action = '?p=10&o=10';
				document.forms['login_form'].submit();
				break;
			case 21:
				document.forms['login_form'].submit_login.value= 'Please wait...';
				document.forms['login_form'].action = 'cgi-bin/login.asp';
				break;
			case 20:
				document.forms['search_form'].submit_search.value= 'Searching...';
				document.forms['search_form'].action = '?p=1&o=7';				
				break;


			case 12:
				document.forms['community_form'].submit_community.value= 'Processing...';
				document.forms['community_form'].action = 'cgi-bin/add.asp?o='+o+'&id='+document.forms['community_form'].id.value;
				document.forms['community_form'].onsubmit();				
				document.forms['community_form'].submit();
				break;
			case 11:
				document.forms['community_form'].submit_community.value= 'Processing...';
				document.forms['community_form'].action = 'cgi-bin/add.asp?o='+o+'&id='+document.forms['community_form'].id.value;
				document.forms['community_form'].onsubmit();
				document.forms['community_form'].submit();
				break;
			case 10:
				document.forms['enquiry_form'].submit_enquiry.value= 'Sending Enquiry...';
				document.forms['enquiry_form'].action = 'cgi-bin/add.asp?o='+o;
				break;

			case 9:
				alert('Nothing defined...');
				break;
			case 8:
				document.forms['branch_form'].submit_branch.value= 'Processing...';
				document.forms['branch_form'].action = 'cgi-bin/add.asp?o='+o+'&id='+document.forms['branch_form'].id.value;
				document.forms['branch_form'].onsubmit();
				document.forms['branch_form'].submit();
				break;			
			case 7:
				document.forms['branch_form'].submit_branch.value= 'Processing...';
				document.forms['branch_form'].action = 'cgi-bin/add.asp?o='+o+'&id='+document.forms['branch_form'].id.value;
				document.forms['branch_form'].onsubmit();
				document.forms['branch_form'].submit();
				break;
			case 4:
				document.forms['user_form'].submit_user.value= 'Processing...';
				document.forms['user_form'].action = 'cgi-bin/add.asp?o='+o+'&l='+document.forms['user_form'].level.value;
				document.forms['user_form'].onsubmit();
				document.forms['user_form'].submit();
				break;
			case 3:
				document.forms['user_form'].submit_user.value= 'Processing...';
				document.forms['user_form'].action = 'cgi-bin/add.asp?o='+o+'&l='+document.forms['user_form'].level.value;
				document.forms['user_form'].onsubmit();
				document.forms['user_form'].submit();
				break;
			case 2:
				document.forms['property_form'].submit_property.value= 'Processing...';
				document.forms['property_form'].action = 'cgi-bin/add.asp?o='+o+'&id='+document.forms['property_form'].id.value;
				document.forms['property_form'].onsubmit();
				document.forms['property_form'].submit();
				break;
			case 1:
				document.forms['property_form'].submit_property.value= 'Processing...';
				document.forms['property_form'].action = 'cgi-bin/add.asp?o='+o;
				document.forms['property_form'].onsubmit();
				document.forms['property_form'].submit();
				break;
			default:

			}
		return(true);
		}


	
	function bookmarksite(){
 		if (document.all){  window.external.AddFavorite(location.href, document.title);}
	        if (window.sidebar) { window.sidebar.addPanel(document.title, location.href, ""); }
	}
	


	function changeEnquiry(user_id, enquiry_id){
		document.forms["enquirytransfer_form"].action = 'cgi-bin/add.asp?o=16&uid='+user_id+'&eid='+enquiry_id;
		document.forms["enquirytransfer_form"].submit();		
		return;
		}
	

	function selectSort(pagingoptions,o){
		//document.forms["selectlistingsort_form"].action = '/?p=2&o=list&s='+o;
		document.forms["selectlistingsort_form"].action = '/'+pagingoptions+'&s='+o;
		document.forms["selectlistingsort_form"].submit();		
		return;
		}
		
	function selectStatusSort(o){
		if (o == "offmarket"){
			document.forms["selectlistingsort_form"].action = '?p=2&o=list&offmarket=1';
		}	
		else {		
			document.forms["selectlistingsort_form"].action = '/?p=2&o=list&status='+o;
		}
		document.forms["selectlistingsort_form"].submit();		
		return;
		}
		

	// automatically add the address information from the title for easier user input.	
	function getTitle(_suggested){
		//_suggested = (String(_suggested) != 'undefined' ? _suggested : );
		document.forms("property_form").property_title.value = document.forms("property_form").property_address.value;
		return;
	}	

	
	function checkform(o){
		var x=String();
		var validEmail = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		document.forms["property_form"].submit_property.value = "Checking...";
		var v ;
		
		// eight fields to check
		for (a=1; a <document.forms["property_form"].length; a++){
			v += "field# "+a+"  "+ document.forms["property_form"][a].name+" =  "+document.forms["property_form"][a].value+"<br/><br/>";

			// 1. check the title
			if (document.forms["property_form"][a].name == "property_title"){
				with (document.forms["property_form"][a].value){
					if(indexOf("@") != -1 ){ x += '\n\nProperty Title.';}
					else if(length <=2 ){ x += "\n\nProperty Title.";}
					else if(substring(0,1) == "@"){ x += '\n\nProperty Title.';}
					else if(lastIndexOf("@") == length-1 ){ x += '\n\nProperty Title.'}
					else if(lastIndexOf(".") == length-1 ){x += '\n\nProperty Title.';}
					
				}
			}	



			//check agent asssignment	
			if (document.forms["property_form"][a].name == "property_agentid"){
				if (!document.forms["property_form"][a].value || document.forms["property_form"][a].value == ""){
					x += "\n\nThe Agent Assigned to this Listing";
				}
			}
			
			
			// check listing no.	
			//if (document.forms["property_form"][a].name == "property_listingno"){
			//	if (!document.forms["property_form"][a].value || document.forms["property_form"][a].value <= 0){
			//		x += "\n\nThe Listing number";
			//	}
			//}


			/* Validate the Building Date */
			if (document.forms["property_form"][a].name == "selectyear"){
				if ((document.forms["property_form"]["selectyear"].value > 0) || (document.forms["property_form"]["selectmonth"].value > 0) || (document.forms["property_form"]["selectday"].value > 0)){
					//if (!isValidDate(document.forms["property_form"]["selectyear"].value, document.forms["property_form"]["selectmonth"].value, document.forms["property_form"]["selectday"].value)){
					if(!isDate(document.forms["property_form"]["selectyear"].value, document.forms["property_form"]["selectmonth"].value, document.forms["property_form"]["selectday"].value)){
						x += "\n\nThe Building Construction Date";				
					}
				}	
			}


			/* Validate the Listing Date*/

			if (document.forms["property_form"][a].name == "selectlistyear"){
				if ((document.forms["property_form"]["selectlistyear"].value > 0) || (document.forms["property_form"]["selectlistmonth"].value > 0) || (document.forms["property_form"]["selectlistday"].value > 0)){
					if (!isDate(document.forms["property_form"]["selectlistyear"].value, document.forms["property_form"]["selectlistmonth"].value, document.forms["property_form"]["selectlistday"].value)){
						x += "\n\nThe Listing End Date";				
					}
				}	
			}



			/* Validate the Appraisal Date */
			if (document.forms["property_form"][a].name == "selectappraisalyear"){
				if ((document.forms["property_form"]["selectappraisalyear"].value > 0) || (document.forms["property_form"]["selectappraisalmonth"].value > 0) || (document.forms["property_form"]["selectappraisalday"].value > 0) ){
					if (!isDate(document.forms["property_form"]["selectappraisalyear"].value, document.forms["property_form"]["selectappraisalmonth"].value, document.forms["property_form"]["selectappraisalday"].value)){
						x += "\n\nThe Appraisal Date";				
					}
				}	
			}


			if (document.forms["property_form"][a].name == "property_price"){
				if (document.forms["property_form"][a].value <= 0){
					x += "\n\nThe Offer or Monthly Rental Price";
				}
			}

			if (document.forms["property_form"][a].name == "property_securitydeposit"){
				if (document.forms["property_form"][a].value < 0 || document.forms["property_form"][a].value == ""){
					x += "\n\nSecurity Deposit, use zero to clear entry.";
				}
			}


			if (document.forms["property_form"][a].name == "property_address"){
				with (document.forms["property_form"][a].value){
					if(indexOf("@") != -1 ){ x += '\n\nListing Street Address.';}					
					else if(length <=2 ){ x += "\n\nListing Street Address.";}
					else if(substring(0,1) == "@"){ x += '\n\nListing Street Address.';}
					else if(lastIndexOf("@") == length-1 ){ x += '\n\nListing Street Address.'}
					else if(lastIndexOf(".") == length-1 ){x += '\n\nListing Street Address.';}
				}
			}
			

			if (document.forms["property_form"][a].name == "property_type"){
				if (document.forms["property_form"][a].value <= 0){
					x += "\n\nYou must enter the property type";
				}
			}
			

			if (document.forms["property_form"][a].name == "property_zoning"){
				if (document.forms["property_form"][a].value <= 0){
					x += "\n\nProperty Zoning";
				}			
			}			
			
		}

		if (!x.length){	
			if (o==1){
				document.forms['property_form'].submit_property.value= 'Processing...';
				document.forms['property_form'].action = 'cgi-bin/add.asp?o=1';
				document.forms['property_form'].onsubmit();
				document.forms['property_form'].submit();
			}
			else{
				var id=document.forms['property_form'].id.value;
				document.forms['property_form'].submit_property.value= 'Processing...';
				document.forms['property_form'].action = 'cgi-bin/add.asp?o=2&id='+document.forms['property_form'].id.value;
				document.forms['property_form'].onsubmit();
				document.forms['property_form'].submit();
				
			}
		}
		else{
			document.forms['property_form'].submit_property.value= ((o == 1) ? 'Add' : 'Update') + " Listing"
			x = "In order to ensure accuracy of data submitted the\nfollowing fields must be correct to proceed:\n"+x
			alert(x);
		}
		return;
	}
		


	function isDate(year,month,day){
		month = month -1; 
	
		var _date = new Date(year, month, day).getTime();
		var _ckdate = new Date();
		_ckdate.setTime(_date);
		//alert(_date+'  '+_ckdate+'  '+_ckdate.getMonth()+'   '+month+'    '+(_ckdate.getMonth()==month));
		
		if (_ckdate.getFullYear() != year)  return false;  
		if (_ckdate.getMonth()    != month) return false;  
		if (_ckdate.getDate()     != day)   return false;  
		return true;
		}	
	

	function QuickSearch(e) {
		if (!e) var e = window.event;
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;

		if (code==13) {
		   document.quicksearch_form.submit();
		}
	} 	



	function checkEnquiryForm(){
		var x=String();
		var validEmail = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		var v ;
		document.forms["enquiry_form"].submit_enquiry.value = "Checking...";
		
		// eight fields to check
		for (a=1; a <document.forms["enquiry_form"].length; a++){
			v += "field# "+a+"  "+ document.forms["enquiry_form"][a].name+" =  "+document.forms["enquiry_form"][a].value+"<br/><br/>";

			// 1. check the title
			if (document.forms["enquiry_form"][a].name == "contact_name"){
				with (document.forms["enquiry_form"][a].value){
				if ((indexOf("@") != -1 ) || (length <=2 ) || (substring(0,1) == "@") || (lastIndexOf("@") == length-1 ) || (lastIndexOf(".") == length-1 )) 
					x+= "\nYour name."
				}
			}	

/*
					if(indexOf("@") != -1 ){ x += '\n\nContact Name.';}
					else if(length <=2 ){ x += "\n\nContact Name.";}
					else if(substring(0,1) == "@"){ x += '\n\nContact Name.';}
					else if(lastIndexOf("@") == length-1 ){ x += '\n\nContact Name.'}
					else if(lastIndexOf(".") == length-1 ){x += '\n\nContact Name.';}
					*/

			//check agent asssignment	
			//if (document.forms["enquiry_form"][a].name == "contact_phone"){
			//	if (!document.forms["enquiry_form"][a].value || document.forms["enquiry_form"][a].value == ""){
			//		x += "\nYour contact phone";
			//	}
			//}
		

			if (document.forms["enquiry_form"][a].name == "contact_email"){
				with (document.forms["enquiry_form"][a].value){
					if ((!match(validEmail)) || (indexOf("@") == -1 ) || (indexOf(" ") != -1) || (substring(0,1) == "@") || (lastIndexOf("@") == length-1 ) || (lastIndexOf(".") == length-1 ))
						x += "\nA valid email address."

				}
			}


			if (document.forms["enquiry_form"][a].name == "contact_referrer"){
				if (!document.forms["enquiry_form"][a].value || document.forms["enquiry_form"][a].value == ""){
					x += "\nHow you were referrered you to this site";
				}			
			}




		}


/*
					if(!match(validEmail)) { x += "\nPlease provide a valid email address.";}
					else if(indexOf("@") == -1 ){ x += "\nPlease provide a valid email address..";}
					else if(indexOf(" ") != -1 ){ x += '\nPlease provide a valid email address.';}
					else if(substring(0,1) == "@"){ x += '\nPlease provide a valid email address.';}
					else if(lastIndexOf("@") == length-1 ){ x += '\nPlease provide a valid email address.'}
					else if(lastIndexOf(".") == length-1 ){x += '\nPlease provide a valid email address.';}
*/

		if (!x.length){	
			upload(10);
			}
		else{
			document.forms['enquiry_form'].submit_enquiry.value= " Send Enquiry "
			x = "In order to ensure accuracy of data submitted the\nfollowing fields must be correct to proceed:\n"+x
			alert(x);
		}
		return;
	}