function showHelp(divId,xid){
	el = document.getElementById(divId);
	if(el.style.display == 'block'){
		el.style.display = 'none';
		xid.innerHTML = '+ expand';
	}else{
		el.style.display='block';
		xid.innerHTML = '- collapse';
	}
}
	
	
	



function validate(){

	good=1;
	required = new Array("first_name","last_name","password1","password2");
	required_txt = new Array("First Name","Last Name","Choose a password","Confirm your password");
	myform=document.forms['theform'];
	msg="The following fields are required: \n";
	for(i=0;i<required.length;i++){
		if(myform[required[i]].value==''){
			good=0;
			msg+=required_txt[i]+", \n";
		}
	}	
	//check phone
		if(myform['work_phone1'].value=='' || myform['work_phone2'].value=='' || myform['work_phone3'].value==''){
			good=0;
			msg+="Work Phone with area code, \n";
		}
		
		var str=myform["email"].value;
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str))){
			good=0;
			 msg+="Please enter a valid email address.\n";
		}
		var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
		if (str.match(illegalChars)) {
			good=0;
		    msg+="The email address contains illegal characters.\n";
		
		}	
	if(myform['password1'].value != myform['password2'].value){good=0;msg+="Your passwords don't match! \n"}	
	if(myform['password1'].value.length < 6){good=0;msg+="Password must be at least 6 characters. \n"}	
	//spam test
	if(myform['human'].value != 7){good=0;msg+="Check your answer to the math equation. \n"}	
	if(good==1){return true;}else{alert(msg);return false;}			
}


// --------------------------------------------------------------------
// --------------------------------------------------------------------
// --------------------------------------------------------------------


function validate_profile(){
	good=1;
	required = new Array("first_name","last_name");
	required_txt = new Array("First Name","Last Name");
	myform=document.forms['theform'];
	msg="The following fields are required: \n";
	for(i=0;i<required.length;i++){
		if(myform[required[i]].value==''){
			good=0;
			msg+=required_txt[i]+", \n";
		}
	}	
	
	//check phone
		if(myform['work_phone1'].value=='' || myform['work_phone2'].value=='' || myform['work_phone3'].value==''){
			good=0;
			msg+="Work Phone with area code, \n";
		}
		
	//check for changed password
	if(myform['password1']){
		if(myform['password1'].value != myform['password2'].value){good=0;msg+="Your passwords don't match! \n"}	
	}
	
	//handle headshot
	if(good==1){return true;}else{alert(msg);return false;}	
		
}

// --------------------------------------------------------------------
// --------------------------------------------------------------------
// --------------------------------------------------------------------


function validate_brokerage(){
	good=1;
	required = new Array("brokerage","branch","street","city","state","zip");
	required_txt = new Array("Brokerage Name","Branch Name","Street Address","City","State","Zip");
	myform=document.forms['theform'];
	msg="The following fields are required: \n";
	for(i=0;i<required.length;i++){
		if(myform[required[i]].value==''){
			good=0;
			msg+=required_txt[i]+", \n";
		}
	}	
	//check phone
		if(myform['work_phone1'].value=='' || myform['work_phone2'].value=='' || myform['work_phone3'].value==''){
			good=0;
			msg+="Phone with area code, \n";
		}
	if(good==1){return true;}else{alert(msg);return false;}	
		
}

// --------------------------------------------------------------------
// --------------------------------------------------------------------
// --------------------------------------------------------------------



function validateBilling(){
	document.getElementById('submit').disabled=true;
	good=1;
	required = new Array("firstname","lastname","address","city","state","zip","phone","x_card_num","x_exp_date","x_card_code");
	required_txt = new Array("First Name","Last Name","Address","City","State","Zip","Phone","Credit Card Number","Credit Card Expiration Date","CVV2 Code");
	myform=document.forms['theform'];
	msg="The following fields are required: \n";
	for(i=0;i<required.length;i++){
		if(myform[required[i]].value==''){
			good=0;
			msg+=required_txt[i]+", \n";
		}
	}	
	
	if(typeof(checkShipping)!='undefined'){
		if(myform['sameas'].checked != true){
			required = new Array("sh_firstname","sh_lastname","sh_address","sh_city","sh_state","sh_zip");
			required_txt = new Array("Shipping First Name","Shipping Last Name","Shipping Address","Shipping City","Shipping State","Shipping Zip");
			for(i=0;i<required.length;i++){
				if(myform[required[i]].value==''){
					good=0;
					msg+=required_txt[i]+", \n";
				}
			}
		}
	}
	
	
	if(good==1){return true;}else{alert(msg);document.getElementById('submit').disabled=false;return false;}	
		
}

// --------------------------------------------------------------------
// --------------------------------------------------------------------
// --------------------------------------------------------------------


function verifyTour(){
var msg='';

if(document.getElementById('mls').value==''){
	msg+='- MLS\n\n';}

if(document.getElementById('street').value==''){
	msg+='- Street\n\n';}

if(document.getElementById('city').value==''){
	msg+='- City\n\n';}

if(document.getElementById('state').value==''){
	msg+='- State\n\n';}

if(document.getElementById('zip').value==''){
	msg+='- Zip\n\n';}

if(document.getElementById('price1').value < 1){
	msg+='- Price \n\n';}

if(msg!=''){
	alert('The following fields are empty or invalid:\n\n'+msg);
	return false
}else{
	return true }

}


// --------------------------------------------------------------------
// --------------------------------------------------------------------
// --------------------------------------------------------------------


function spamwhy(){
	document.getElementById('spamexplain').style.display='block';
}



// --------------------------------------------------------------------
// --------------------------------------------------------------------
// --------------------------------------------------------------------


function warnDelete(msg){
	var r=confirm(msg);
if (r==true)
  {
  return true
  }
else
  {
  return false
  }
}



// --------------------------------------------------------------------
// --------------------------------------------------------------------
// --------------------------------------------------------------------


function deletepicWarn(picId){
	var r=confirm("Are you sure you want to delete this photo?");
if (r==true)
  {
  theform=document.getElementById('scriptForm');
	theform["deleteme"].value=picId;
	theform.submit();
  }
else
  {
  return false
  }
}

// --------------------------------------------------------------------
// --------------------------------------------------------------------
// --------------------------------------------------------------------


function replacepicWarn(picId){
	//check file field
	filefield = document.forms[0]["rpic_"+picId].value //document.getElementById("rpic_"+picId);
	//alert(document.forms[0]["rpic_"+picId].value);
	if(filefield.value == ''){
		alert('First click Browse to choose an image file to replace this one.'+picId);
		return false
		}else{
	var r=confirm("Are you sure you want to replace this photo?");
	if (r==true)
	  {
		theform=document.getElementById('scriptForm');
		theform["replaceme"].value=picId;
		theform.submit();
		thediv= document.getElementById('overlay-'+picId);
		thediv.innerHTML += '<div class="ft">uploading...</div>';
	  }
	else
	  {
	  return false
	  }
	}
}


// --------------------------------------------------------------------
// --------------------------------------------------------------------
// --------------------------------------------------------------------


function win(x){
	window.open(x,"email","status=1,toolbar=0,location=0,scrollbars=0,resizable=1,width=350,height=400"); 
	
	
}




function padout(number) { return (number < 10) ? '0' + number : number; }