
// validate first then submit form named "profile"   (all forms)
function submitprofile() { if (validateall()) { document.profile.submit(); } }

// universal validator
function validateall() {
	try {
		if (document.profile.firstname.value!="") 
			{
			if (document.profile.firstname.value.length>28)  {
				alert('Your first name is too long.');
				return false;
			}
		}
	}
	catch(e) {}
	try {
		if (document.profile.firstname.value == ""){
       		alert('Please enter your FIRST NAME before continuing.');
       		return false;
        }
	}
	catch(e) {}
	try {
		if (document.profile.lastname.value!="") {
			if (document.profile.lastname.value.length>48) {
				alert('Your last name is too long.');
				return false;
			}
		}
	}
	catch(e) {}
	try {
		if (document.profile.lastname.value == ""){
    	   	alert('Please enter your LAST NAME before continuing.');
    	   	return false;
        }
	}
	catch(e) {}
	try {
		if (document.profile.day_telephone.value!="") {
			if (document.profile.day_telephone.value.length<10) {
				alert('The DAY TELEPHONE # you entered appears to be too short. Please include your Area Code and Phone Number with no spaces or dashes.');
				return false;
			}
		}

	}
	catch(e) {}
	try {
		if (document.profile.day_telephone.value == ""){
       		alert('Please enter your DAY TELEPHONE # before continuing. Please include your Area Code and Phone Number with no spaces or dashes.');
       		return false;
        } 
	}
	catch(e) {}
	try {

		if (document.profile.email.value == ""){
       		alert('You must enter an e-mail ADDRESS before continuing.');
       		return false;
        }
	}
	catch(e) {}
	try {
		if (document.profile.email.value.indexOf("@") ==-1 || document.profile.email.value.indexOf(".") ==-1 || document.profile.email.value.indexOf(" ") !=-1 || document.profile.email.value.length <6) {
			alert('Please make sure your e-mail ADDRESS is valid before continuing.');
			return false;
		}                  
	}
	catch(e) {}
	try {
		if (document.profile.bedrooms.options[0].selected) {
	       	alert('You must select the minimum number of BEDROOMS you are looking for.');
    	   	return false;
        }     
	}
	catch(e) {}
	try {
		if (document.profile.maxrent.options[0].selected) {
	       	alert('Please indicate the MAXIMUM APARTMENT RENT you will be willing to pay.');
    	   	return false;
        }		
	}
	catch(e) {}
	try {
		if (document.profile.movedate.options[0].selected) {
       		alert('Please indicate your intended MOVE DATE.');
	       	return false;
        }    	
	}
	catch(e) {}
	try {
		if (document.profile.reference.options[0].selected) {
	        alert('Please indicate HOW YOU FOUND US.');
    	    return false;
        } 
	}
	catch(e) {}
	try {
		if ((document.profile.z999.checked) || (document.profile.z998.checked) || (document.profile.z150.checked) || (document.profile.z151.checked) || (document.profile.z152.checked) || (document.profile.z153.checked) || (document.profile.z109.checked) || (document.profile.z107.checked) || (document.profile.z997.checked) || (document.profile.z996.checked) || (document.profile.z995.checked) || (document.profile.z994.checked)) {
			return true;
		}
		else { 
			alert('You must select at least one NEIGHBORHOOD DESIRED before continuing.');
			return false;
		}          	         	          	         
	}
	catch(e) {}
		try {
		if ( (document.profile.z999.checked) || (document.profile.z150.checked) || (document.profile.z151.checked) || (document.profile.z152.checked) || (document.profile.z107.checked) || (document.profile.z109.checked) || (document.profile.z153.checked) || (document.profile.z995.checked) || (document.profile.z541.checked) || (document.profile.z542.checked) || (document.profile.z543.checked) || (document.profile.z544.checked) || (document.profile.z545.checked) || (document.profile.z998.checked) || (document.profile.z241.checked) || (document.profile.z242.checked) || (document.profile.z243.checked) || (document.profile.z997.checked) || (document.profile.z341.checked) || (document.profile.z342.checked) || (document.profile.z343.checked) || (document.profile.z994.checked) || (document.profile.z996.checked) ) {
			return true;
		}
		else { 
			alert('You must select at least one NEIGHBORHOOD DESIRED before continuing.');
			return false;
		}          	         	          	         
	}
	catch(e) {}


return true;
}
//end uni valid


// dreamwv swap stuff
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// pop-up win that cn be id'd ... 
function gen_pop(url, wd, ht, idd) {
	try {
		newwindow = window.open(url, idd,"width=" + wd + ",height=" + ht + ",resizable=no,scrollbars=yes");
		if (window.focus) {newwindow.focus();}	
	} catch(e) {
//	alert (e);   //debug
	}
}


function load_rand(ad) {
var b = new Array();
n = 0;
b[n++] = "apartments-for-rent-tl00.jpg";
b[n++] = "apartments-for-rent-tl01.jpg";
rnd = Math.floor(Math.random() * n);
randimage = '/nyc-apartments/' + b[rnd];
document.getElementById('apartments-NYC').src = randimage;
var bg = new Array();
var n = 0;
bg[n++] = "apartments-for-rent-t00.jpg";
bg[n++] = "apartments-for-rent-t01.jpg";
bg[n++] = "apartments-for-rent-t02.jpg";
bg[n++] = "apartments-for-rent-t03.jpg";
bg[n++] = "apartments-for-rent-t04.jpg";
bg[n++] = "apartments-for-rent-t05.jpg";
rnd = Math.floor(Math.random() * n);
if (ad) {
randimage = 'url(/nyc-apartments/' + bg[rnd] + ')'; // with dot
}
else {
randimage = 'url(/apartments-in-nyc/' + bg[rnd] + ')'; // no dot, no ad
document.getElementById("subscribe-to-RDNY").innerHTML="";
}
document.getElementById('Apartments-in-New-York-City').style.backgroundImage = randimage;
}
