
var mailingPanes = new Array("select_clients", "select_properties", "mail_form");

function appendPicture (seqn){
	tbody = document.getElementById("pictures_tbody");
	img = document.createElement("img"); 
	img.src = document.getElementById("picture_"+seqn).src;
	row = tbody.insertRow(0);
	cell = row.insertCell(0);
	cell.innerHTML = "Current Picture";
	cell.style.verticalAlign = "top";
	cell = row.insertCell(1);
	cell.appendChild(img);
}

function appendBanner (seqn){
	banner = document.getElementById("banner_"+seqn);
	picture = document.getElementById("picture_"+seqn);
}

function changeGalleryPicture (newPath, newCaption){
	document.getElementById("current_picture").src = newPath;
	document.getElementById("current_caption").innerHTML = newCaption;
}

function displayFakeFlash (){
	embeds = document.getElementsByTagName("EMBED");
	for (loop=0;loop<embeds.length;loop++){		
		embeds[loop].parentNode.removeChild( embeds[loop] );			
	}
}

function changeMailingPanes (action){
	
	var current_pane = document.getElementById("current_pane").value;

	if(action == 0){
		if(current_pane == 0) window.location = "admin.php?pg=ac";
		else{
			document.getElementById(mailingPanes[current_pane]).style.display = "none";
			document.getElementById(mailingPanes[parseInt(current_pane)-1]).style.display = "table-cell";
			document.getElementById("current_pane").value = parseInt(current_pane)-1;
		}
	}else if(action == 1){
		if(current_pane == 2) sendMail();
		else{
			document.getElementById(mailingPanes[current_pane]).style.display = "none";
			document.getElementById(mailingPanes[parseInt(current_pane)+1]).style.display = "table-cell";
			document.getElementById("current_pane").value = parseInt(current_pane)+1;
		}
	}
	
}

function changePeriodsDisplay(select){
	if(select.value == "For Sale") document.getElementById('pperiod').style.display = "none";
	if(select.value == "To Let") document.getElementById('pperiod').style.display = "inline";
}

function sendMail(){
	document.getElementById("waiting").style.display = "table";
	showMailingStatus();
}

function isEmailEntered(){
	email = document.getElementById("umail").value;
	alert_value = "";
	if(!isEmail(email)) alert_value = "The Email Address field must be a valid email address."; 
	if(isBlank(email)) alert_value = "Please fill in the Email Address field."; 
	if(alert_value != ""){ 
		alert(alert_value);	
		return false;
	}else{
		return true;
	}
}

function isThisBlank(string) {
	if (string.length == 0)
		return true
	for (var i = 0; i <= string.length-1; i++)
		if (string.charAt(i) != " ")
			return false
		return true
} 

function isThisEmail(string) {
	apos=string.indexOf("@");
	dotpos=string.lastIndexOf(".");
	if (apos<1||dotpos-apos<2)	
		return false
	return true
}
