
function show_hide(x){
	var sign = '';
	var y = x + '_sign';
	if(document.getElementById(x).style.display == 'none'){
		document.getElementById(x).style.display = '';
		sign = '-';
	}
	else{
		document.getElementById(x).style.display = 'none';
		sign = '+';
	}
	document.getElementById(y).innerHTML = sign;
}

function show_requirements(x) {
 if (document.getElementById(x).style.display == "none") {
  document.getElementById(x).style.display = "";
 }
 else {
  document.getElementById(x).style.display = "none";
 }
}

function show_pets(x){
	if(x=="rent" || x=="sub"){
		document.getElementById('pets_div').style.display = '';
		document.property_info.price_type.value='2';
		document.getElementById('pricetype').style.display = '';
	}
	else{
		document.getElementById('pets_div').style.display = 'none';
		document.property_info.price_type.value='3';
		document.getElementById('pricetype').style.display = 'none';
	}
}

function check_form(recid){
	var x=document.property_info;
	var y = document.video_changer;
	if (x.posting_what.value == ""){alert('Please select a type of property');}
	else if(x.posting_what.value != "Blog" && !isZip(x.zip.value)){ 
		alert('Please enter a valid 5-digit zip code');
	}
	else if(x.posting_what.value == "Real_Estate" && x._avail.value == ""){
		alert('Please select an availability for your property');
	}
	else if(x.headline.value == ''){alert('Please enter a headline for your video');}
	else if(y.val.value == ''){alert('Please choose a method of video upload');}
	else if(x.description.value.length>900){alert('Please limit descriptions to 900 characters');}
	else{
		var ch = y.val.value;
		x.action = "/process_property.php?action=prop_app&stp=1&recid="+recid+"&ch="+ch;
    	x.submit();
	}
}

function check_form_edit(y){
	var x=document.property_info;
	if(y != "Blog" && !isZip(x.zip.value)){ 
		alert('Please enter a valid 5-digit zip code');
	}
	else if(x.headline.value == ''){alert('Please enter a headline for your video');}
	else if(x.description.value.length>900){alert('Please limit descriptions to 900 characters');}
	else{x.submit();}
}

function isZip(s){
	reZip = new RegExp(/(^\d{5}$)/);
	if (!reZip.test(s)) {
		return false;
	}
	return true;
}

function change_form(x){
	http.open('get', '/prop_app_ajax.php?action=change_form&ptype=' + x);
	http.onreadystatechange = handleChangeForm; 
	http.send(null);
}

function handleChangeForm(){
	if(http.readyState == 4){
 		var response = http.responseText;
 		document.getElementById('form').innerHTML = response;
	}
}

function change_what_posting(x,y){
	http.open('get', '/prop_app_ajax.php?action=change_big_form&posting=' + x + '&encid=' + y );
	http.onreadystatechange = handleChangePosting;
	http.send(null);
}

function handleChangePosting(){
	if(http.readyState == 4){
		var response = http.responseText;
		document.getElementById('big_form').innerHTML = response;
	}
}

function get_city_state(x){
	http.open('get', '/prop_app_ajax.php?action=city_state&zip=' + x);
	http.onreadystatechange = handleCityState; 
	http.send(null);
}

function handleCityState(){
	if(http.readyState == 4){
 		var response = http.responseText;
 		document.getElementById('city_state').innerHTML = response;
	}
}

function show_form(x){
	http.open('get', '/prop_app_ajax.php?action=change_big_form&recid=' + x );
	http.onreadystatechange = handleChangePosting;
	http.send(null);
}

function change_form_edit(x,y){
	http.open('get', '/prop_app_ajax.php?action=change_form&encid=' + x + '&ptype=' + y);
	http.onreadystatechange = handleChangeForm;
	http.send(null);
}

function change_video(x,y){
	if(x=='print'){
		window.location="/main.php?section=seller&action=addproperty&pg=v&ch=print&recid="+y;
		//document.getElementById('print_div').style.display='';
		//document.getElementById('upload_div').style.display='none';
	}
	else if(x=='upload'){
		window.location="/main.php?section=seller&action=addproperty&pg=v&ch=upload&recid="+y;
		//document.getElementById('print_div').style.display='none';
		//document.getElementById('upload_div').style.display='';
	}
	else if(x=='nothing'){
		window.location="/main.php?section=seller&action=addproperty&pg=2&recid="+y;
	}
}


function send_iam(iam, uid){
	http.open('get', '/prop_app_ajax.php?action=updateiam&iam=' + iam + '&uid=' + uid);
	http.onreadystatechange = handlesendiam; 
	http.send(null);
}

function handlesendiam(){
	if(http.readyState == 4){
 		var response = http.responseText;
 		document.getElementById('msg').innerHTML = "<b><font size=\"+1\" color=\"blue\">Thank you!  You will be forwarded to your dashboard in a few seconds.</font></b>";
	}
}

function activate(x) {
 window.location = "/process_property.php?action=activate&recid="+x;	
}

function add_zipcode(city, state, zip){
	http.open('get', '/prop_app_ajax.php?action=add_zipcode&city=' + city + '&state=' + state + '&zip=' + zip);
	http.onreadystatechange = handlechangezipcode;
	http.send(null);
}

function handlechangezipcode(){
	if(http.readyState == 4){
		var response = http.responseText;
		document.getElementById('zip_message').innerHTML = response;
		document.getElementById('zip_form_body').style.border = '';
		document.getElementById('zip_form_body').innerHTML = '';
	}
}

function javascript_create_blank(){
	http.open('get', '/create_blank.php?vdir=yes');
	http.onreadystatechange = handle_create_blank;
	http.send(null);
}

function handle_create_blank(){
	if(http.readyState == 4){
		response = http.responseText;
		document.property_info._rec_id.value=response;
	}
}
