function initcalculatecom() {
var A = 215000;
var com70 = A * .07
var com35 = A * .03
document.getElementById("calcprice").value=formatCurrency(A);
document.getElementById("sevencom").value=formatCurrency(com70);
document.getElementById("threecom").value=formatCurrency(com35);
document.getElementById("fsbohomes").value='$375';
}
function calculatecom(Atext) {
Atext = Atext.toString().replace(/\$|\,/g,'');
var A = parseFloat(Atext);
if ( isNaN(A) ) {
    A = 0;
}
var com70 = A * .07
var com35 = A * .03
document.getElementById("calcprice").value=formatCurrency(A);
document.getElementById("sevencom").value=formatCurrency(com70);
document.getElementById("threecom").value=formatCurrency(com35);
document.getElementById("fsbohomes").value='$375';
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num);
}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}

function toggleElement(proptype, element1, propval) {

  element1 = document.getElementById(element1);
  if (proptype.value == propval) {

    element1.style.display = 'none';

  }
  else {
    element1.style.display = 'inline';
  }

  return;
}
function toggleElementload() {

  element2 = document.getElementById('othertype');
    element2.style.display = 'none';

}

function useBillInfo(form)
{ 
	var idx;
	

	if(form.sameadd.checked)
		{
			form.ShipTo_FName.value = form.BillTo_FName.value;
			form.ShipTo_LName.value = form.BillTo_LName.value;
			form.ShipTo_Address.value = form.BillTo_Address.value;
			form.ShipTo_City.value = form.BillTo_City.value;
			form.ShipTo_State.value = form.BillTo_State.value;
			form.ShipTo_Zip.value = form.BillTo_Zip.value;
			
		}
	else
		{
			form.ShipTo_FName.value = "";
			form.ShipTo_LName.value = "";
			form.ShipTo_Address.value = "";
			form.ShipTo_City.value = "";
			form.ShipTo_State.value = "";
			form.ShipTo_Zip.value = "";
			
		}
}

function useBillInfo2(form)
{ 
	

	if(form.sameadd2.checked)
		{
			form.ShipTo_Address.value = form.BillTo_Address.value;
			form.ShipTo_City.value = form.BillTo_City.value;
			form.ShipTo_State.value = form.BillTo_State.value;
			form.ShipTo_Zip.value = form.BillTo_Zip.value;
			
		}
	else
		{
			form.ShipTo_Address.value = "";
			form.ShipTo_City.value = "";
			form.ShipTo_State.value = "";
			form.ShipTo_Zip.value = "";
			
		}
}
function clearfield(){
    if (document.f1.City_Listing.value =='Search by City, State or Listing ID')
    document.f1.City_Listing.value = '';
}
NewsDelay=10000		//Time each story is displayed for
NewsFadeDelay=1000	//Time taken to fade from one story to the next
NewsFont='Verdana'	//Ticket font family
NewsFontSize='10pt'	//Ticket font size
NewsTextColor=new Array("#444444","#555555","#666666","#777777","#888888","#999999","#aaaaaa","#bbbbbb","#cccccc","#dddddd","#eeeeee","#ffffff")
NewsStory=0		//Working Variable
LastNewsStory=0		//Working Variable
NewsColor=0		//Working Variable
NewsArray=new Array(
'<table cellspacing="0" cellpadding="0"><tr><td align="left">Your company proved to be a success.  We sold our house in one week at full asking price. Appreciate your help!</td></tr><tr><td align="right">- Matt H.</td></tr></table>' , '',
'<table cellspacing="0" cellpadding="0"><tr><td align="left">I really like your site! It was well set up & easy to use...thanks!</td></tr><tr><td align="right">- Audra W.</td></tr></table>' , '',
'<table cellspacing="0" cellpadding="0"><tr><td align="left">The video of our house was great! I loved the aerial map at the beginning and the narration. I will definitely recommend you guys to anyone I know selling by owner. What a great option and service to offer.</td></tr><tr><td align="right">- Jody L.</td></tr></table>' , '',
'<table cellspacing="0" cellpadding="0"><tr><td align="left">The video package sold me.  I’ve never seen anything that professional.  All I can say is WOW!</td></tr><tr><td align="right">- Dan U.</td></tr></table>' , '',
'<table cellspacing="0" cellpadding="0"><tr><td align="left">I wanted to let you know that your website is very nice and easy to navigate.  I am also impressed with your virtual office.  Making changes to my listing is a snap.</td></tr><tr><td align="right">- Dave R.</td></tr></table>' , '',
'')


function DisplayNews(){
	LastNewsStory=NewsStory
	NewsStory++; if( NewsStory>(Math.floor(NewsArray.length/2)) ){NewsStory=1}
	FadeNews()
}



function FadeNews(){
	if (NewsColor<(NewsTextColor.length)/2){var NewsLayer=1}
	else {var NewsLayer=2}
	//Old Story
	if (LastNewsStory>0){
		var NewsText = '<FONT color="'+ NewsTextColor[NewsColor] +'" face="'+ NewsFont +'"><i>'+ NewsArray[(LastNewsStory-1)*2] +'</i></FONT>'
			if(document.layers){ document.eval('newslayer'+(3-NewsLayer)).document.write(NewsText); document.eval('newslayer'+(3-NewsLayer)).document.close() }//NN4
			if(document.all){ eval('newslayer'+(3-NewsLayer)).innerHTML=NewsText }//IE
			if(!document.all && document.getElementById){ document.getElementById('newslayer'+(3-NewsLayer)).innerHTML=NewsText }//NN6
	}
	//New Story
		var NewsText = '<FONT color="'+ NewsTextColor[(NewsTextColor.length)-NewsColor-1] +'" face="'+ NewsFont +'"><i>'+ NewsArray[(NewsStory-1)*2] +'</i></FONT>'
			if(document.layers){ document.eval('newslayer'+NewsLayer).document.write(NewsText); document.eval('newslayer'+NewsLayer).document.close() }//NN4
			if(document.all){ eval('newslayer'+NewsLayer).innerHTML=NewsText }//IE
			if(!document.all && document.getElementById){ document.getElementById('newslayer'+NewsLayer).innerHTML=NewsText; }//NN6
	NewsColor++
	if (NewsColor>=NewsTextColor.length){ NewsColor=0; setTimeout('DisplayNews()',NewsDelay) }
	else { setTimeout('FadeNews()',NewsFadeDelay/NewsTextColor.length) }
}

var swapCodes   = new Array(8211, 8212, 8216, 8217, 8220, 8221, 8226, 8230); // dec codes from char at
var swapStrings = new Array("--", "--", "'",  "'",  '"',  '"',  "*",  "...");  
function cleanWordClipboard(input) {
    // debug for new codes
    // for (i = 0; i < input.length; i++)  alert("'" + input.charAt(i) + "': " + input.charCodeAt(i));
    
    var output = input;
    for (i = 0; i < swapCodes.length; i++) {
        var swapper = new RegExp("\\u" + swapCodes[i].toString(16), "g"); // hex codes
        output = output.replace(swapper, swapStrings[i]);
    }
    return output;
}

function detailslink(vid,list,addr,city,state) {
	var detailstr
	var trimaddr = addr.replace(/^\s+|\s+$/g, '');
	trimaddr = trimaddr.replace(/\s+/g," ");
	trimaddr = trimaddr.replace(/ /g,"-");
	trimaddr = trimaddr.toLowerCase();
	var trimcity = city.replace(/^\s+|\s+$/g, '');
	trimcity = trimcity.replace(/\s+/g," ");
	trimcity = trimcity.replace(/ /g,"-");
	trimcity = trimcity.toLowerCase();
	state = state.toLowerCase();
	var linkstr = 'http://www.fsbohomesiowa.com/property/'+trimaddr+'-'+trimcity+'-'+state+'/'+list+'/';
	var detaillink = 'http://www.fsbohomesiowa.com/details.asp?listing='+list;
	var videolink = 'http://www.fsbohomesiowa.com/video.asp?listing='+list;
	if (vid == 'Yes') {
		detailstr = '<div class="maplinks"><table cellspacing="0" cellpadding="0"><tr><td style="padding-top:5px"><a href="'+detaillink+'" title="View Listing Details"><img border="0" src="http://www.fsbohomesiowa.com/images/listingdetails3.jpg" height="17" style="border:none;"></a></td><td style="padding-top:5px"><a href="'+detaillink+'" title="View Listing Details" style="font: bold 11px verdana; color: #004685; text-decoration:none;">View Details</a></td></tr><tr><td><a href="'+videolink+'" title="Watch Video Tour"><img border="0" src="http://www.fsbohomesiowa.com/images/videotourbutton3.jpg" height="17" style="border:none;"></a></td><td><a href="'+videolink+'" title="Watch Video Tour" style="font: bold 11px verdana; color: #004685; text-decoration:none;">Video Tour</a></td></tr></table></div>';
	}
	else {
		detailstr = '<div class="maplinks"><table cellspacing="0" cellpadding="0"><tr><td style="padding-top:5px"><a href="'+detaillink+'" title="View Listing Details"><img border="0" src="http://www.fsbohomesiowa.com/images/listingdetails3.jpg" height="17" style="border:none;"></a></td><td style="padding-top:5px"><a href="'+detaillink+'" title="View Listing Details" style="font: bold 11px verdana; color: #004685; text-decoration:none;">View Details</a></td></tr></table></div>';
	}	
	return detailstr;
}

function priceit(liststatus,priceamt) {
	var pricestr
	if (liststatus == 'Sold') {
		pricestr = '<font color=#FF0000>SOLD</font>';
	}
	else if (liststatus == 'Pending') {
		pricestr = '<font color=#FF0000>SALE PENDING</font>';
	}
	else {
		pricestr = formatCurrency(priceamt);
	}	
	return pricestr;
}

function photolink(pic,appr,list) {
	var photostr
	if (pic.length > 0 & appr == 'Yes') {
		photostr = 'homes/'+list+'_'+pic+'m.jpg';
	}
	else {
		photostr = 'media/nophotos_m.jpg';
	}	
	return photostr;
}

function createMarker(point,index,html) {
  var marker = new GMarker(point, markerOptions);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}

function nextdesc(n) {
	document.getElementById('infocontent').innerHTML=textstr[n];
}
function prevdesc(n) {
	document.getElementById('infocontent').innerHTML=textstr[n];
}
function loadPopup(d)
{
	setwidth('dialogue');
	showOverlay();
	document.getElementById('dialogue').style.display = "block";
	document.getElementById('infocontent').innerHTML=textstr[d];
	var currentdesc = d;
}
function showOverlay()
{
	document.getElementById('overlay').style.width = screen.width+'px';	
	document.getElementById('overlay').style.display = "block";	
}
function hideOverlay()
{
	document.getElementById('overlay').style.display = "none";
}
function closeDialogue(d)
{
	hideOverlay();
	document.getElementById(d).style.display = "none";
}
function setwidth(str) {
    var curr_width = parseFloat(document.getElementById(str).style.width); // removes the "px" at the end	
	var mw = -(curr_width/2);
	document.getElementById(str).style.marginLeft = mw+'px';
}



