
   
// Search on main page.
   function checkMainForm(form,type) {
   
        if (! type) { alert('Select an agent or property\n state and submit.'); return; }
        var ind  = form.state;
		var city = form.city;
        if (ind.selectedIndex == 0) { alert('Please select your ' + type + ' state.'); return; }
		if (city.value == 'City \(Optional\)') { city.value=''; }
        form.submit();
		return false;
   }

// Used by all searches.

     function clearField(fld) {
          if (fld.value == 'City \(Optional\)') { fld.value =''; }
     }

// Search on other pages.
     function checkSearch(form,state) {

	    if (! (state.selectedIndex > 0)) { alert('Please select a state to search.'); return; }
        if (form.city.value == 'City \(Optional\)') { form.city.value = ''; }
        form.submit();
        return false;
     }

// Search on advanced page.

     function checkAdvanced(form) {
        var ind     = form.state.selectedIndex;
        var DDval   = eval('form.state.options[' + ind + '].value');
        if (DDval == "none") {
            alert('The state field is the only required field to \n perform an advanced ' + form.type.value + ' search.');
            return;
        }
        else {  form.submit();  }
		return false;
     }
	 
// Contact page.

    function checkContact(form) {
        var requireds = new Array('Name', 'Email');
        var msg = '';

        for (i=0; i<requireds.length; i++) { 
            checkThis = document.getElementById(requireds[i]).value;
            if (checkThis == '') {
                 msg = 'Please provide your ' + requireds[i] + ' before submitting this form.';
                break;
            }
        }
        if ((msg == '') && (document.getElementById('Email').value != '')) {
            var found = false;
            var emailString = document.getElementById('Email').value;
            for (j=0; j < emailString.length; j++) {
                if (emailString.charAt(j) == "@") { found = true; }
            }
            if (found == false) {
                msg = 'Is that your true email address?\n' +
                      'Please enter your correct email address.\n' +
                      'We will not place you on any mailing lists!\n';
            }
        }

        if (msg == '') { form.submit(); }
        else {  alert(msg);  }
        return false;
    }
	
//Listing pages, newWindow is probably now dead.
   function printWindow(){
      bV = parseInt(navigator.appVersion)
      if (bV >= 4) window.print()
   }
   
   function mailpage(url){
     mail_str = 'mailto:?subject=I found this on e-real-estate.com.'+
                '&body=\n\nI thought you might be interested in this listing.\n\n'+
                'You can view it at ' + url; 
     location.href = mail_str;
   }
   
   // CAREFUL WITH QUOTING! Easy to screw this up.
   function getBookmark(url,who) {  
       var ver = navigator.appName
       var num = parseInt(navigator.appVersion);
	   var msg;
       if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
          msg  = '<a href="#" onClick="window.external.AddFavorite(\''+url+'\',\''+who+'\'); return false;">'+
				 '<img src="\/images\/bookmark.gif" width="32" height="32" border="0" alt="Bookmark this Listing"><\/a><br>\n'+
				 '<a class="bold" href="#" onClick="window.external.AddFavorite(\''+url+'\',\''+who+'\'); return false;">Bookmark<\/a>';
       }
	   else { msg = '<img src="\/images\/bookmark.gif" width="32" height="32" border="0" alt="Bookmark this Listing"><\/a><br>\n <strong>Bookmark \- (Ctrl+D)</strong>'; }
       return msg;
   }

   function swapImage(id,wrapid,url,w,h) {
	 var obj  = document.getElementById(id); 
	 var wrap = document.getElementById(wrapid);
	 if (wrap) {
	  wrap.style.width=(w<250)?'290px':parseInt(w+40)+'px'; } // Adjust if you padding and margin change styles!
	 if (obj) {
	  obj.width=w;
	  obj.height=h;
	  obj.src=url;
	 }
	 return false;
   }
   
// need to scour scripts and use this.
    function newWin(url,img,title,w,h) {

	   if (! (url) && ! (img)) { return; }
	   var day= new Date();
	   var id = day.getTime();
	   var ww = w+75;
	   var wh = h+125;
	   var params = 'width='+ww+',height='+wh+',scrollbars,resizable';
	   if (url=='') {
	      var msg='<!DOCTYPE HTML PUBLIC "-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN" "http:\/\/www.w3.org/TR\/html4\/loose.dtd">\n'+
		          '<meta http-equiv="Content-Type" content="text\/html; charset=iso-8859-1">\n'+
		          '<html><head><title>'+img+'<\/title><\/head>'+
		          '<style type="text\/css">\n'+
				  ' html,body { font-family: Arial,Helvetica,Sans-Serif; }\n'+
				  'h3 { text-align: center; }\n'+
				  'td { text-align: center; }\n'+
				  '<\/style><body>\n'+
				  '<h3>'+title+'<\/h3>\n <table align="center" border="0"><tr><td><img src="'+img+'" width="'+w+'" height="'+h+'" border="0" alt="'+title+'"></td></tr>\n'+
				  '<tr><td><hr width="100%" size="1"><form><input type="button" onClick="javascript:window.close();" value="Close Window">\n'+
				  '<hr width="100%" size="1"><\/form><\/td><\/tr><\/table><\/body><\/html>\n';
	      var win = open('',id,params);
		  win.document.write(msg);
		  win.document.close();
	   }
	   else { var win = open(url,id,params); } 
	   return false;
    }

// used only in admin and member ad mamager to preview existing data in selected template.	
function sendTemplate(url) {
   if (document.getElementById('template_num')) {
      var ind = document.getElementById('template_num').selectedIndex;
	  var val = document.getElementById('template_num')[ind].value;
	  url += '&amp;template_num='+val;
      newWin(url,'','Ad Preview',200,300);
   }
   return false;
}

// Used in ad_mgr
function checkLen(str) {
   if (str.length > 255) { alert('The ad message field is only allowed 255 characters.'); }
}   

// used in ad_mgr and mem_ad_mgr

function URLtext() {
	   var day= new Date();
	   var id = day.getTime();
	   var params = 'width=400,height=600,scrollbars,resizable';
	   var msg = '<html><head><title>URL Text<\/title>\n'+
	             '<link rel="stylesheet" href="/data/ere2.css">\n'+
				 '<\/head><body class="nobg" style="margin:12px">\n'+
				 '<h3 class="center">URL Text<\/h3>\n'+
				 '<p>The <em>URL Text<\/em> is the text that appears on a link. for example, in the below code the URL text is \&quot\;Example Site\&quot\;<\/p>\n'+
				 '<p><code>\&lt\;a href="http://www.example.com"\&gt\;Example Site\&lt\;\/a\&gt\;<\/code><\/p>\n'+
				 '<p>While it\'s perfectly fine to enter the website URL for the URL text, some URLs can be quite long and it\'s often\n'+
				 'better to use specialtext instead. For example, for E-Real-Estate,<\/p>\n'+
				 '<p><code>\&lt\;a href="http://www.e-real-estate.com"\&gt\;E-Real-Estate.com\&lt\;\/a\&gt\;<\/code><\/p>\n'+
				 '<p>creates a link like this <\/p>\n'+
				 '<p><a href="http://www.e-real-estate.com">E-Real-Estate.com<\/a><\/p>\n'+
				 '<p>which looks more elegant than<\/p>\n'+
				 '<p><code>\&lt\;a href="http://www.e-real-estate.com"\&gt\;http://www.e-real-estate.com\&lt\;\/a\&gt\;<\/code><\/p>\n'+
				 '<p><a href="http://www.e-real-estate.com">http://www.e-real-estate.com<\/a><\/p>\n'+
				 '<div class="center"><hr width="100%" size="1"><form><input type="button" onClick="javascript:window.close();" value="Close Window">\n'+
				 '<hr width="100%" size="1"><\/form><\/div><br><br><\/body><\/html>\n';
	      var win = open('',id,params);
		  win.document.write(msg);
		  win.document.close();
		  return false;
}

function addBoth() {
	   var day= new Date();
	   var id = day.getTime();
	   var params = 'width=400,height=600,scrollbars,resizable';
	   var msg = '<html><head><title>Add to Other Pages<\/title>\n'+
	             '<link rel="stylesheet" href="/data/ere2.css">\n'+
				 '<\/head><body class="nobg" style="margin:12px">\n'+
				 '<h3 class="center">Add to Other Pages<\/h3>\n'+
				 '<p>Currently you may include ads for either your Member Main page or your Member Listings pages as well as the listings results pages \(if your listings are the only results on the page.\)\n'+
				 'Checking this box will place the current ad in <em>both<\/em> locations so you don\'t have to create two versions of the ad.<\/p>\n'+
				 '<p>This program will attempt to place the ad in the exact same position you have selected for the current ad, but if that position is\n'+
				 'in use, it will place it in the next available slot.<\/p>\n'+
				 '<p><strong>Alternatively,</strong> if this ad was previously added to other pages, this page will load with\n'+
				 'the box <em>checked</em>. Un-checking the box will <strong>delete</strong> this ad from the other pages.<\/p>\n'+
				 '<p><strong>Example:<\/strong> If you are currently editing an ad for slot 1 column 1 of your Member Main page and check the box to place the same ad on other pages, \n'+
				 'this program will attempt to place the same ad in slot 1 column 1 of the Member Listings pages. If that position is currently in use, it will place it in the next available slot for the Member Listings pages.\n'+
				 '<p>You may move that ad as you like by editing the ad positions for the Member Listings pages after updating the ad without affecting the ad placements of you Member Main page.<\/p>\n'+
				 '<p><strong>Please note<\/strong> that if you use this method to include ads on other pages, and changes you make to it will update on the other pages as well \- it cannot be edited as a second ad.\n'+
				 'To do this, you will have to create a second ad manually.<\/p>\n'+
				 '<div class="center"><hr width="100%" size="1"><form><input type="button" onClick="javascript:window.close();" value="Close Window">\n'+
				 '<hr width="100%" size="1"><\/form><\/div><br><br><\/body><\/html>\n';
	      var win = open('',id,params);
		  win.document.write(msg);
		  win.document.close();
		  return false;
}

	 // Delete this after new design is complete
	 
     function checkForm(form) {

        var searchString = '/cgi/search.cgi?function=search_db';
        var type = form.type.options[form.type.selectedIndex].value;
        if (type == '') {
           alert ('Please select a property or an agent search.');
           return;
        }

        var DDval   = form.state.options[form.state.selectedIndex].value;
        var cityVal = form.city.value;

        if (DDval == "none") {
            alert('Please select the ' + type + ' state.');
            return false;
        }

        searchString = searchString + '&type=' + type + '&state=' + DDval;
        if ((cityVal != '') && (cityVal != 'City \(Optional\)')) {
           searchString = searchString + '&city=' + cityVal;
        }
        document.location=searchString;
        return false;
     }

     function clearField(fld) {
          if (fld.value == 'City \(Optional\)') { fld.value =''; }
     }
