//js script
//by: jpdelatorre
//validate form




window.onload = function() {

    /*
	var xForm = document.getElementById('main-form');
	if(xForm != null) {
		xForm.onsubmit = function() {
			return validate_form(1);
		}
	}
	*/
	
	start_slideshow(1, 5, 3000);
}

function showform() {
    Effect.SlideUp('contact-container2');
    setTimeout(null,800);
    Effect.SlideDown('contact-container');
}

function start_slideshow(start_frame, end_frame, delay) {
    setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
}
                            
function switch_slides(frame, start_frame, end_frame, delay) {
    return (function() {
        Effect.Fade('slideshow' + frame);
        if(frame == end_frame) { 
            frame = start_frame; 
        } else { 
            frame = frame + 1; 
        }
        setTimeout("Effect.Appear('slideshow" + frame + "');", 850);
        setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 850);
    })
}

function validate_form(flag) {
	var inputs = document.getElementsByTagName("input");
	var error_msg = '<strong>Required field(s):</strong> ';
	var ctr = 0;
	var flg = false;
	
	for(var i=0; i<inputs.length; i++) {
		if(inputs[i].className == "required_input" || inputs[i].className == "required_input attention") {
			if(inputs[i].value == "") {
				inputs[i].className = "required_input attention";
				error_msg = error_msg + "<br /> - " + inputs[i].title;
				ctr++;
				flg = true;
			} else {
				if(inputs[i].className == "required_input attention") {
					inputs[i].className = "required_input";
					ctr--;
				}
			}
		}
	}
	if(flg) {
		if(ctr > -1) {
			if(flag == 1) {
				//alert("Please fill up name and email field.");		
				//document.getElementById("error_msg").innerHTML = error_msg;
				return false;
			}
		} else {
			return true;
		}
	} else {
		if(ctr > 0) {
			if(flag == 1) {
				//alert("Please make sure all required fields are filled-up.");		
				//document.getElementById("error_msg").innerHTML = error_msg;
				return false;
			}
		} else {
			return true;
		}
	}
}

function openStaticPage(src) {
	window.open(src, 'blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=640,height=480,left=50,top=50');
}

function checkform_alert(form)
{
	 validate_form(1);
	 
	 if (form.firstname.value == "") {
	   alert( "Please give us your first name. \n Your information is safe with us - we won't share it without your permission." );
	   form.firstname.focus();
	   return false ;
	 }
	 if (form.lastname.value == "") {
	   alert( "Please give us your last name. \n Your information is safe with us - we won't share it without your permission." );
	   form.lastname.focus();
	   return false ;
	 }
	 if (form.email.value == "") {
	   alert( "Please enter an email address -  if you'd prefer we contact you via phone, just specify that in the comment box. \n Your information is safe with us - we won't share it without your permission." );
	   form.email.focus();
	   return false ;
	}
	 if (form.email.value.indexOf('@',0) == -1) {
	   alert( "Please enter a VALID email address -  if you'd prefer we contact you via phone, just specify that in the comment box. \n Your information is safe with us - we won't share it without your permission." );
	   form.email.focus();
	   return false ;
	}	
	 if (form.phone.value == "") {
	   alert( "Please give us your phone number - if you'd prefer we contact you via email, just specify that in the comment box. \n Your information is safe with us - we won't share it without your permission." );
	   form.phone.focus();
	   return false ;
	 }
	 if ( ( form.manualsearch[0].checked == false )
     && ( form.manualsearch[1].checked == false ) 
     && ( form.manualsearch[2].checked == false ) )
    {
        alert ( "Please tell us if you'd like us to contact you with available properties." );
        return false;
    }
	 if ( ( form.haverealtor[0].checked == false )
     && ( form.haverealtor[1].checked == false ) 
     && ( form.haverealtor[2].checked == false ) )
    {
        alert ( "Please tell us whether you have a Realtor or not (or if you are a Realtor)." );
        return false;
    }
	 
  return true ;
}

