// JavaScript Document


//<![CDATA[

function show_map(prop_counter, latitude, longitude){
	
	hide_arrange(prop_counter);
	hide_img(prop_counter);
	document.getElementById("prop_map_container_" + prop_counter).style.display = "block";
	if (GBrowserIsCompatible()) {
  		var map = new GMap2(document.getElementById("prop_map_container_" + prop_counter));
		map.setCenter(new GLatLng(latitude, longitude), 13);
		map.addControl(new GSmallMapControl());
		map.addOverlay(new GMarker(new GLatLng(latitude, longitude)));
  	}
}

//]]>

//<![CDATA[

function show_contact_map(prop_counter, latitude, longitude){
	
	hide_img(prop_counter);
	document.getElementById("prop_map_container_" + prop_counter).style.display = "block";
	if (GBrowserIsCompatible()) {
  		var map = new GMap2(document.getElementById("prop_map_container_" + prop_counter));
			map.setCenter(new GLatLng(latitude, longitude), 15);
			map.addControl(new GSmallMapControl());
			map.addOverlay(new GMarker(new GLatLng(latitude, longitude)));
			map.openInfoWindowHtml(map.getCenter(),
			document.createTextNode("New Space"));
  	}
}

//]]>

function hide_map(prop_counter){
	document.getElementById("prop_map_container_" + prop_counter).style.display = "none";
}

function view_news(row_num){

	if(document.getElementById('news_result_' + row_num).style.display == "block"){
		document.getElementById('news_result_' + row_num).style.display = "none";
	}
	else{
		document.getElementById('news_result_' + row_num).style.display = "block";
	}
}

function show_arrange(prop_counter){
	document.getElementById('form_response_' + prop_counter).innerHTML = "";
	document.getElementById('prop_arrange_form_table_' + prop_counter).style.display = "block";
	document.getElementById("prop_arrange_form_container_" + prop_counter).style.display = "block";
	hide_img(prop_counter);
	hide_map(prop_counter);
}


function hide_arrange(prop_counter){
	document.getElementById("prop_arrange_form_container_" + prop_counter).style.display = "none";
}


function show_img(prop_counter){
	hide_arrange(prop_counter);
	hide_map(prop_counter);
	document.getElementById("prop_image_container_" + prop_counter).style.display = "block";
}


function hide_img(prop_counter){
	document.getElementById("prop_image_container_" + prop_counter).style.display = "none";
}


function check_fields(prop_counter){
	
	var bad = "N";
	if(document.getElementById('name_' + prop_counter).value == ""){bad = "Y";}
	if(document.getElementById('tel_' + prop_counter).value == "" && document.getElementById('email_' + prop_counter).value == ""){bad = "Y";}
	if(bad == "Y"){
		document.getElementById("form_msg_" + prop_counter).innerHTML = "Please complete your name and at least one contact detail.";
		return false;
	}
	if(document.getElementById('email_' + prop_counter).value != "" && !valid_email_check(document.getElementById('email_' + prop_counter).value)){
		document.getElementById("form_msg_" + prop_counter).innerHTML = "Please enter a valid email address.";
		return false;
	}
	
	return true;
}


function send_arrange(pid){

	if(check_fields(pid)){
	
		document.getElementById('prop_arrange_form_table_' + pid).style.display = "none";
		document.getElementById('form_response_' + pid).innerHTML = "Sending ... Please wait";
		document.getElementById('form_response_' + pid).style.display = "block";
			
		var request = get_http_object('text/xml');
		if(request){
			request.onreadystatechange = function(){
				if(request.readyState == 4){
					if(request.status == 200 || request.status == 304){
						
						// Capture/manipulate XML data returned from HTTP call
						var doc = request.responseXML.documentElement;
						var status = doc.getElementsByTagName('trans_status');
						var msg = doc.getElementsByTagName('trans_msg');
						
						if(status[0].firstChild.data == 'success'){
							document.getElementById('form_response_' + pid).innerHTML = msg[0].firstChild.data;
							return true;
						}
						else if(status[0].firstChild.data == 'fail'){
							document.getElementById('prop_arrange_form_table_' + pid).style.display = "block";
							document.getElementById('form_response_' + pid).innerHTML = msg[0].firstChild.data;
							return false;
						}
						else{
							document.getElementById('prop_arrange_form_table_' + pid).style.display = "block";
							document.getElementById('form_response_' + pid).innerHTML = "There was a problem sending your request. Please contact a shinynewflat.com representative if this problem persists.";
							return false;
						}
					}
					else{
						// Captures error in trying to talk to server-side script
						alert("Error: returned status code " + request.status + " " + request.statusText);
					}
				}	
			};
			request.open("POST", "/send-arrange.php", true);

			// Compile form parameters
			var params = "whichaction=send&pid=" + pid;
			params += "&name=" + document.getElementById('name_' + pid).value;
			params += "&tel=" + document.getElementById('tel_' + pid).value;
			params += "&email=" + document.getElementById('email_' + pid).value;
			params += "&num_beds=" + document.getElementById('num_beds_' + pid).options[document.getElementById('num_beds_' + pid).selectedIndex].value;
			params += "&budget=" + document.getElementById('budget_' + pid).value;

			//Send the proper header information along with the request
			request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			request.setRequestHeader("Content-length", params.length);
			request.send(params);
		
		}
	}
}


function send_form(){
	
	var request = get_http_object('text/xml');
	if(request){
		request.onreadystatechange = function(){
			if(request.readyState == 4){
				if(request.status == 200 || request.status == 304){
					
					// Capture/manipulate XML data returned from HTTP call
					var doc = request.responseXML.documentElement;
					var status = doc.getElementsByTagName('trans_status');
					var msg = doc.getElementsByTagName('trans_msg');
					
					document.getElementById('send_details_table').style.display = "none";
					document.getElementById('response_div').style.display = "block";
					
					if(status[0].firstChild.data == 'success'){
						document.getElementById('form_response').innerHTML = msg[0].firstChild.data;
						return true;
					}
					else if(status[0].firstChild.data == 'fail'){
						document.getElementById('form_response').innerHTML = msg[0].firstChild.data;
						return false;
					}
					else{
						document.getElementById('form_response').innerHTML = "There was a problem sending your request. Please contact us if this problem persists.";
						return false;
					}
				}
				else{
					// Captures error in trying to talk to server-side script
					alert("Error: returned status code " + request.status + " " + request.statusText);
				}
			}	
		};
		request.open("POST", "/send-details-mailer.php", true);

		// Compile form parameters
		var params = "whichaction=send";
		params += "&name=" + document.getElementById('name').value;
		params += "&telephone=" + document.getElementById('telephone').value;
		params += "&email=" + document.getElementById('email').value;
		params += "&location=" + document.getElementById('location').value;
		params += "&send=" + document.getElementById('send').value;
		params += "&address=" + document.getElementById('address').value;

		//Send the proper header information along with the request
		request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		request.setRequestHeader("Content-length", params.length);
		request.send(params);
	
	}
			
}

function check_lc_fields(){
	
	var bad = "N";
	if(document.getElementById('city').value == ""){bad = "Y";}
	if(document.getElementById('prop_type').value == ""){bad = "Y";}
	if(document.getElementById('name').value == ""){bad = "Y";}
	if(document.getElementById('telephone').value == ""){bad = "Y";}
	if(document.getElementById('email').value == ""){bad = "Y";}

	if(bad == "Y"){
		document.getElementById('form_msg').style.display = "block";
		document.getElementById("form_msg").innerHTML = "Please complete all required (*) fields.";
		return false;
	}
	if(!valid_email_check(document.getElementById('email').value)){
		document.getElementById('form_msg').style.display = "block";
		document.getElementById("form_msg").innerHTML = "Please enter a valid email address.";
		return false;
	}
	
	return true;
}



function send_lc_form(){
	
	if(check_lc_fields()){
			
		var request = get_http_object('text/xml');
		if(request){
			request.onreadystatechange = function(){
				if(request.readyState == 4){
					if(request.status == 200 || request.status == 304){
						
						// Capture/manipulate XML data returned from HTTP call
						var doc = request.responseXML.documentElement;
						var status = doc.getElementsByTagName('trans_status');
						var msg = doc.getElementsByTagName('trans_msg');
						
						document.getElementById('lc_send_details').style.display = "none";
						document.getElementById('lc_submit').style.display = "none";
						document.getElementById('form_msg').style.display = "none";
						document.getElementById('response_div').style.display = "block";
						
						if(status[0].firstChild.data == 'success'){
							document.getElementById('form_response').innerHTML = msg[0].firstChild.data;
							return true;
						}
						else if(status[0].firstChild.data == 'fail'){
							document.getElementById('form_response').innerHTML = msg[0].firstChild.data;
							return false;
						}
						else{
							document.getElementById('form_response').innerHTML = "There was a problem sending your request. Please contact us if this problem persists.";
							return false;
						}
					}
					else{
						// Captures error in trying to talk to server-side script
						alert("Error: returned status code " + request.status + " " + request.statusText);
					}
				}	
			};
			request.open("POST", "/send-details-lc.php", true);
	
			// Compile form parameters
			var params = "whichaction=send";
			params += "&name=" + document.getElementById('name').value;
			params += "&telephone=" + document.getElementById('telephone').value;
			params += "&email=" + document.getElementById('email').value;
			params += "&city=" + document.getElementById('city').value;
			params += "&prop_desc=" + document.getElementById('prop_desc').value;
			params += "&prop_type=" + document.getElementById('prop_type').value;
			params += "&prop_age=" + document.getElementById('prop_age').value;
			params += "&prop_beds=" + document.getElementById('prop_beds').value;
			params += "&prop_symptoms=" + document.getElementById('prop_symptoms').value;
	
			//Send the proper header information along with the request
			request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			request.setRequestHeader("Content-length", params.length);
			request.send(params);
		
		}
		
	}
	
}

function check_rtb_fields(){
	
	var bad = "N";
	if(document.getElementById('rtb_am').value == ""){bad = "Y";}
	if(document.getElementById('rtb_name').value == ""){bad = "Y";}
	if(document.getElementById('rtb_telephone').value == ""){bad = "Y";}
	if(document.getElementById('rtb_email').value == ""){bad = "Y";}

	if(bad == "Y"){
		document.getElementById('rtb_form_msg').style.display = "block";
		document.getElementById("rtb_form_msg").innerHTML = "Please complete all required (*) fields.";
		return false;
	}
	if(!valid_email_check(document.getElementById('rtb_email').value)){
		document.getElementById('rtb_form_msg').style.display = "block";
		document.getElementById("rtb_form_msg").innerHTML = "Please enter a valid email address.";
		return false;
	}
	
	return true;
}



function send_rtb_form(){
	
	if(check_rtb_fields()){
			
		var request = get_http_object('text/xml');
		if(request){
			request.onreadystatechange = function(){
				if(request.readyState == 4){
					if(request.status == 200 || request.status == 304){
						
						// Capture/manipulate XML data returned from HTTP call
						var doc = request.responseXML.documentElement;
						var status = doc.getElementsByTagName('trans_status');
						var msg = doc.getElementsByTagName('trans_msg');
						
						document.getElementById('rtb_send_details').style.display = "none";
						document.getElementById('rtb_submit').style.display = "none";
						document.getElementById('rtb_form_msg').style.display = "none";
						document.getElementById('rtb_response_div').style.display = "block";
						
						if(status[0].firstChild.data == 'success'){
							document.getElementById('rtb_form_response').innerHTML = msg[0].firstChild.data;
							return true;
						}
						else if(status[0].firstChild.data == 'fail'){
							document.getElementById('rtb_form_response').innerHTML = msg[0].firstChild.data;
							return false;
						}
						else{
							document.getElementById('rtb_form_response').innerHTML = "There was a problem sending your request. Please contact us if this problem persists.";
							return false;
						}
					}
					else{
						// Captures error in trying to talk to server-side script
						alert("Error: returned status code " + request.status + " " + request.statusText);
					}
				}	
			};
			request.open("POST", "/send-details-rtb.php", true);
	
			// Compile form parameters
			var params = "whichaction=send";
			params += "&name=" + document.getElementById('rtb_name').value;
			params += "&telephone=" + document.getElementById('rtb_telephone').value;
			params += "&email=" + document.getElementById('rtb_email').value;
			params += "&am=" + document.getElementById('rtb_am').value;
	
			//Send the proper header information along with the request
			request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			request.setRequestHeader("Content-length", params.length);
			request.send(params);
		
		}
		
	}
	
}

function check_cs_fields(){
	
	var bad = "N";
	if(document.getElementById('cs_am').value == ""){bad = "Y";}
	if(document.getElementById('cs_name').value == ""){bad = "Y";}
	if(document.getElementById('cs_telephone').value == ""){bad = "Y";}
	if(document.getElementById('cs_email').value == ""){bad = "Y";}
	if(document.getElementById('cs_company').value == ""){bad = "Y";}

	if(bad == "Y"){
		document.getElementById('cs_form_msg').style.display = "block";
		document.getElementById("cs_form_msg").innerHTML = "Please complete all required (*) fields.";
		return false;
	}
	if(!valid_email_check(document.getElementById('cs_email').value)){
		document.getElementById('cs_form_msg').style.display = "block";
		document.getElementById("cs_form_msg").innerHTML = "Please enter a valid email address.";
		return false;
	}
	
	return true;
}



function send_cs_form(){
	
	if(check_cs_fields()){
			
		var request = get_http_object('text/xml');
		if(request){
			request.onreadystatechange = function(){
				if(request.readyState == 4){
					if(request.status == 200 || request.status == 304){
						
						// Capture/manipulate XML data returned from HTTP call
						var doc = request.responseXML.documentElement;
						var status = doc.getElementsByTagName('trans_status');
						var msg = doc.getElementsByTagName('trans_msg');
						
						document.getElementById('cs_send_details').style.display = "none";
						document.getElementById('cs_submit').style.display = "none";
						document.getElementById('cs_form_msg').style.display = "none";
						document.getElementById('cs_response_div').style.display = "block";
						
						if(status[0].firstChild.data == 'success'){
							document.getElementById('cs_form_response').innerHTML = msg[0].firstChild.data;
							return true;
						}
						else if(status[0].firstChild.data == 'fail'){
							document.getElementById('cs_form_response').innerHTML = msg[0].firstChild.data;
							return false;
						}
						else{
							document.getElementById('cs_form_response').innerHTML = "There was a problem sending your request. Please contact us if this problem persists.";
							return false;
						}
					}
					else{
						// Captures error in trying to talk to server-side script
						alert("Error: returned status code " + request.status + " " + request.statusText);
					}
				}	
			};
			request.open("POST", "/send-details-cs.php", true);
	
			// Compile form parameters
			var params = "whichaction=send";
			params += "&name=" + document.getElementById('cs_name').value;
			params += "&telephone=" + document.getElementById('cs_telephone').value;
			params += "&email=" + document.getElementById('cs_email').value;
			params += "&company=" + document.getElementById('cs_company').value;
			params += "&am=" + document.getElementById('cs_am').value;
	
			//Send the proper header information along with the request
			request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			request.setRequestHeader("Content-length", params.length);
			request.send(params);
		
		}
		
	}
	
}

function check_su_fields(){
	
	var bad = "N";
	if(document.getElementById('su_name').value == ""){bad = "Y";}

	if(bad == "Y"){
		document.getElementById('su_form_text').style.display = "none";
		document.getElementById('su_form_response').style.display = "block";
		document.getElementById("su_form_response").innerHTML = "Please enter your email address";
		return false;
	}
	if(!valid_email_check(document.getElementById('su_name').value)){
		document.getElementById('su_form_text').style.display = "none";
		document.getElementById('su_form_response').style.display = "block";
		document.getElementById("su_form_response").innerHTML = "Please enter a valid email address.";
		return false;
	}
	
	return true;
}


function send_su_form(){
	
	if(check_su_fields()){
			
		var request = get_http_object('text/xml');
		if(request){
			request.onreadystatechange = function(){
				if(request.readyState == 4){
					if(request.status == 200 || request.status == 304){
						
						// Capture/manipulate XML data returned from HTTP call
						var doc = request.responseXML.documentElement;
						var status = doc.getElementsByTagName('trans_status');
						var msg = doc.getElementsByTagName('trans_msg');
						
						document.getElementById('su_form').style.display = "none";
						document.getElementById('su_form_text').style.display = "none";
						document.getElementById('su_form_response').style.display = "block";
						
						if(status[0].firstChild.data == 'success'){
							document.getElementById('su_form_response').innerHTML = msg[0].firstChild.data;
							return true;
						}
						else if(status[0].firstChild.data == 'fail'){
							document.getElementById('su_form_response').innerHTML = msg[0].firstChild.data;
							return false;
						}
						else{
							document.getElementById('su_form_response').innerHTML = "There was a problem sending your request. Please contact us if this problem persists.";
							return false;
						}
					}
					else{
						// Captures error in trying to talk to server-side script
						alert("Error: returned status code " + request.status + " " + request.statusText);
					}
				}	
			};
			request.open("POST", "/send-details-newsletter.php", true);
	
			// Compile form parameters
			var params = "whichaction=send";
			params += "&email=" + document.getElementById('su_name').value;
	
			//Send the proper header information along with the request
			request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			request.setRequestHeader("Content-length", params.length);
			request.send(params);
		
		}
	}
}

function check_cu_fields(){
	
	var bad = "N";
	if(document.getElementById('cu_name').value == "" || document.getElementById('cu_name').value == "name"){bad = "Y";}
	if(document.getElementById('cu_tel').value == ""|| document.getElementById('cu_tel').value == "telephone"){bad = "Y";}

	if(bad == "Y"){
		document.getElementById('cu_form_text').style.display = "none";
		document.getElementById('cu_form_response').style.display = "block";
		document.getElementById("cu_form_response").innerHTML = "Please enter your name and telephone number";
		return false;
	}
		
	return true;
}

function send_cu_form(){
	
	if(check_cu_fields()){

		var request = get_http_object('text/xml');
		if(request){
			request.onreadystatechange = function(){
				if(request.readyState == 4){
					if(request.status == 200 || request.status == 304){
						
						// Capture/manipulate XML data returned from HTTP call
						var doc = request.responseXML.documentElement;
						var status = doc.getElementsByTagName('trans_status');
						var msg = doc.getElementsByTagName('trans_msg');
						
						document.getElementById('cu_form').style.display = "none";
						document.getElementById('cu_form_text').style.display = "none";
						document.getElementById('cu_form_response').style.display = "block";
						
						if(status[0].firstChild.data == 'success'){
							document.getElementById('cu_form_response').innerHTML = msg[0].firstChild.data;
							return true;
						}
						else if(status[0].firstChild.data == 'fail'){
							document.getElementById('cu_form_response').innerHTML = msg[0].firstChild.data;
							return false;
						}
						else{
							document.getElementById('cu_form_response').innerHTML = "There was a problem sending your request. Please contact us if this problem persists.";
							return false;
						}
					}
					else{
						// Captures error in trying to talk to server-side script
						alert("Error: returned status code " + request.status + " " + request.statusText);
					}
				}	
			};
			request.open("POST", "/send-details-contact.php", true);
	
			// Compile form parameters
			var params = "whichaction=send";
			params += "&name=" + document.getElementById('cu_name').value;
			params += "&tel=" + document.getElementById('cu_tel').value;
	
			//Send the proper header information along with the request
			request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			request.setRequestHeader("Content-length", params.length);
			request.send(params);
		
		}
	}
}

function check_rv_fields(){
	
	var bad = "N";
	if(document.getElementById('rv_name').value == ""){bad = "Y";}
	if(document.getElementById('rv_name').value == "name"){bad = "Y";}
	if(document.getElementById('rv_email').value == ""){bad = "Y";}
	if(document.getElementById('rv_tel').value == ""){bad = "Y";}
	if(document.getElementById('rv_tel').value == "telephone"){bad = "Y";}

	if(bad == "Y"){
		document.getElementById('rv_form_text').style.display = "none";
		document.getElementById('rv_form_response').style.display = "block";
		document.getElementById("rv_form_response").innerHTML = "Please enter all fields below";
		return false;
	}
	if(!valid_email_check(document.getElementById('rv_email').value)){
		document.getElementById('rv_form_text').style.display = "none";
		document.getElementById('rv_form_response').style.display = "block";
		document.getElementById("rv_form_response").innerHTML = "Please enter a valid email address.";
		return false;
	}
	
	return true;
}

function send_rv_form(){
	
	if(check_rv_fields()){
			
		var request = get_http_object('text/xml');
		if(request){
			request.onreadystatechange = function(){
				if(request.readyState == 4){
					if(request.status == 200 || request.status == 304){
						
						// Capture/manipulate XML data returned from HTTP call
						var doc = request.responseXML.documentElement;
						var status = doc.getElementsByTagName('trans_status');
						var msg = doc.getElementsByTagName('trans_msg');
						
						document.getElementById('rv_form').style.display = "none";
						document.getElementById('rv_form_text').style.display = "none";
						document.getElementById('rv_form_response').style.display = "block";
						
						if(status[0].firstChild.data == 'success'){
							document.getElementById('rv_form_response').innerHTML = msg[0].firstChild.data;
							return true;
						}
						else if(status[0].firstChild.data == 'fail'){
							document.getElementById('rv_form_response').innerHTML = msg[0].firstChild.data;
							return false;
						}
						else{
							document.getElementById('rv_form_response').innerHTML = "There was a problem sending your request. Please contact us if this problem persists.";
							return false;
						}
					}
					else{
						// Captures error in trying to talk to server-side script
						alert("Error: returned status code " + request.status + " " + request.statusText);
					}
				}	
			};
			request.open("POST", "/send-details-valuation.php", true);
	
			// Compile form parameters
			var params = "whichaction=send";
			params += "&name=" + document.getElementById('rv_name').value;
			params += "&email=" + document.getElementById('rv_email').value;
			params += "&tel=" + document.getElementById('rv_tel').value;
	
			//Send the proper header information along with the request
			request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			request.setRequestHeader("Content-length", params.length);
			request.send(params);
		
		}
	}
}

function swap_img(new_src, new_title, num, img_counter, prop_counter){

	show_img(prop_counter);
//	for(i=1; i<=num; i++){
//		document.getElementById('img_a_' + prop_counter + '_' + i).className = "b";
//	}
	document.getElementById('prop_img_' + prop_counter).src = "http://newspaceuk.com/pi/" + new_src;
//	document.getElementById('img_a_' + prop_counter + '_' + img_counter).className = "c";
	document.getElementById('prop_img_' + prop_counter).title = new_title;
	document.getElementById('prop_img_' + prop_counter).alt = new_title;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function clearText(field){
 
	if (field.defaultValue == field.value) field.value = '';
	else if (field.value == '') field.value = field.defaultValue;

}