var usave=new Array();
var xpan=0;
var ypan=0;
var xstart=4;
var xstartw=4;
var tad=0;
var planelevation=0;
var planimage="none";
var plan1="0"
var xact="stay";


var scrollxx=-500;
var scrollyy=-500;



/* =======================================================================================================================
*********************************************  Elevations   **********************************************************
======================================================================================================================== */

function showElev(plan){
plan1=(plan);
document.getElementById("elevation").style.display="inline";
planimage=("http://custom-house-plan.com/planimage/" + plan + "-fm.jpg");
document.getElementById("ele").src=planimage;
}

function addElev(){
document.getElementById("ele1").src=planimage;
document.getElementById("ele1").style.display="inline";
planelevation=(plan1);
if(planelevation==plan1)
{
swapLayer('elevationbox','elevation');
}
document.getElementById("usethis").innerHTML="Change Exterior Style";
}

function elevMatch()
{
planimage=("http://custom-house-plan.com/planimage/" + planelevation + "-fm.jpg");
document.getElementById("ele").src=(planimage);
plan1=planelevation;
}





/* =======================================================================================================================
*********************************************  CHANGE FLOORS   **********************************************************
======================================================================================================================== */
function changeFloor(nfloor,event) {

if(nfloor == 1 || nfloor == 2)

{
x=nfloor;
}
else
{
x=nfloor.options[nfloor.selectedIndex].value;
}
if(x==1)
{
swapLayer('copythis','copythis2');
xcopy="copythis";
xcopyr="copythis2";
document.getElementById("copythis").className="xcopy";
document.getElementById("statusbar").innerHTML="First Floor";
document.getElementById("firstfloor").style.fontWeight="bold";
document.getElementById("firstfloor").style.color="fff";
document.getElementById("secondfloor").style.fontWeight="normal";
document.getElementById("secondfloor").style.color="ccc";
document.getElementById("nfloor").selectedIndex="0";
document.getElementById("floorname").innerHTML="First Floor Plan";
//document.getElementById("footprint2").style.display="none";
//document.getElementById("footprint1").style.display="inline";
}
if(x==2)
{
swapLayer('copythis2','copythis');
xcopy="copythis2";
xcopyr="copythis";
document.getElementById("copythis2").className="xcopy";
document.getElementById("statusbar").innerHTML="Second Floor";
document.getElementById("secondfloor").style.fontWeight="bold";
document.getElementById("secondfloor").style.color="fff";
document.getElementById("firstfloor").style.fontWeight="normal";
document.getElementById("firstfloor").style.color="ccc";
document.getElementById("nfloor").selectedIndex="1";
document.getElementById("floorname").innerHTML="Second Floor Plan";
//document.getElementById("footprint1").style.display="none";
//document.getElementById("footprint2").style.display="inline";

}
document.getElementById('floorsize').innerHTML="";
checkDimension();
}

// --------- REFERENCE FLOOR ---------------------------------------------------------------------------------------
function showRef()
{
lref=document.getElementById(xcopyr);
lon=document.getElementById(xcopy);


if(lon.className=="xcopy")
{
lref.style.display="inline";
lon.className="xcopy1";
}
else
{
lref.style.display="none";
lon.className="xcopy";
}


}






/* =======================================================================================================================
*********************************************  Automatically insert email addresss*****************************************
======================================================================================================================== */

function udEmail(x)
{
email=document.getElementById(x).value;
document.getElementById("email1").value=(email);
document.getElementById("email2").value=(email);
document.getElementById("email3").value=(email);
document.getElementById("email5").value=(email);
}





/* =======================================================================================================================
*********************************************  new text *****************************************************************
======================================================================================================================== */


function newText(event) {

nroom="text";

x=((event.clientX)-scrollxx);
y=((event.clientY)-scrollyy);
y=(y+30);

tad=(tad+1);

//----------------------------------


inserttext="<table  id=\"txxt" + tad + "\" style=\"position:absolute;left:" + (x) + "px;top:" + (y) + "px;\" class=\"txtable\" cellspacing=\"0\"  cellpadding=\"0\"><tr><td style=\"width:150px\" id=\"td" + tad + "\" onmouseover=\"roomSel('txxt" + tad + "')\"  onmouseout=\"roomUnsel('txxt" + tad + "')\" onmousedown=\"textMove(event,'txxt" + tad + "')\" onmouseup=\"textStop(event,'txxt" + tad + "')\" onmousemove=\"moveText(event,'txxt" + tad + "')\" ondblclick=\"editText('" + tad + "')\"><textarea id=\"tx" + tad + "\" class=\"roomtx\"  onblur=\"updateText('" + tad + "')\">Double click to edit text</textarea><div id=\"tt" + tad + "\" class=\"tt\"></div></td><td class=\"textr\" id=\"tw" + tad + "\" onmousedown=\"moveTextR(event,'" + tad + "')\" onmousemove=\"resizeText(event,'td" + tad + "')\" onmouseup=\"stopTextmove('tw" + tad + "')\" onmouseover=\"textIn('tw" + tad + "')\" onmouseout=\"textOut('tw" + tad + "')\" ></td></tr></table>";




a=document.getElementById(xcopy).innerHTML;
document.getElementById(xcopy).innerHTML=(a + inserttext);

document.getElementById("tx" + tad).select();


}


function editText(text)
{
layer="tx" + (text);

layer=document.getElementById(layer);
layer.style.display="inline";
x="tt" + (text);
layer.select();
x=document.getElementById(x);
x.style.display="none";
}


function updateText(text)
{
layer="tx" + (text);
layer=document.getElementById(layer);
xl=layer.value.length;
txt=("txxt" + text);

if (xl===0)
{
el = document.getElementById(txt);
el.parentNode.removeChild(el);
}
else
{
x="tt" + (text);
x=document.getElementById(x);


y=(layer.value);

x.innerHTML=y;
layer.style.display="none";


y=y.split('  ').join('');




x.style.display="inline";
z="txxt"+text;
z=document.getElementById(z);
z.style.background="transparent";
}
}


function moveTextR(event,x)
{
xstart=(event.clientX);
a=("td" + x);
x=("tw" + x);
x=document.getElementById(x);
moveloop=10;
x.style.background="#ffff00";
a=document.getElementById(a);
xstartw=a.style.width;
xstartw=(xstartw.replace("px","")*1);

}

function stopTextmove(layer)
{
moveloop=0;
document.getElementById(layer).style.background="#ff0000";
}

function textOut(layer)
{
document.getElementById(layer).style.background="none";
}

function textIn(layer)
{
document.getElementById(layer).style.background="#0000ff";
}


// ENLARGE REDUCE TEXT RIGHT -----------------------------------------------------------------------------------------------------

function resizeText(event,mroom) {
if (moveloop==10 && xpan==0)
{
room=document.getElementById(mroom);

x=(event.clientX);
c=(x-xstart);
nwidth=(xstartw+c);
room.style.width=((nwidth) + "px");

}
}





/* =====================================================================================================================
************************************************************************************************************************
************************************************************************************************************************
***********************************************************************************************************************
***********************************************************************************************************************
**************************************                         *******************************************************
**************************************         Plan Save       ********************************************************                        **************************************                         **********************************************************
**************************************                         ***********************************************************     ***********************************************************************************************************************
*************************************************************************************************************************
*************************************************************************************************************************                              ***************************************************************************************************************************  
=====================================================================================================================  */
function planSave(xact)
{
 
xstring="";
xstring2="";
z=1;
var i=0;
for (i=1;i<=ad;i++)
{
room=("room" + z);
a=document.getElementById(room);

if (a !== null)
{
apar=(a.parentNode.id);

roomname=("roomname" + z);
  
roomcl=a.className;
x=a.style.left;
x=(x.replace("px",""));
y=a.style.top;
y=(y.replace("px",""));
wx=a.style.width;
wx=(wx.replace("px",""));
wy=a.style.height;
wy=(wy.replace("px",""));
zindx=a.style.zIndex;

b=document.getElementById(roomname).innerHTML;

if (apar=="copythis")
{
xstring=(xstring + "&qqq&" + room + "&v&" + roomcl + "&v&" + x + "&v&" + y + "&v&" + wx + "&v&" + wy+ "&v&" + b + "&v&" + zindx);
}
if (apar=="copythis2")
{
xstring2=(xstring2 + "&qqq&" + room + "&v&" + roomcl + "&v&" + x + "&v&" + y + "&v&" + wx + "&v&" + wy+ "&v&" + b + "&v&" + zindx);
}



}
z=(z+1);
}

//---- text save ---------------------------------

tstring="";
tstring2="";
z=1;

var i=0;
for (i=1;i<=tad;i++)
{
room=("txxt" + z);
txt=("tx" + z);
xcell=("td" + z);

xcell=document.getElementById(xcell);
txt=document.getElementById(txt);
a=document.getElementById(room);


if (a !== null)
{
apar=(a.parentNode.id);


x=a.style.left;
x=(x.replace("px",""));
y=a.style.top;
y=(y.replace("px",""));
wx=xcell.style.width;
wx=(wx.replace("px",""));

b=txt.value;

if (apar=="copythis")
{
tstring=(tstring + "&qqq&" + room + "&v&" +  x + "&v&" + y + "&v&" + wx + "&v&" + b);
}
if (apar=="copythis2")
{
tstring2=(tstring2 + "&qqq&" + room + "&v&" +  x + "&v&" + y + "&v&" + wx + "&v&" + b);
}

}
z=(z+1);
}


showLayer('saveplan');

savethis=(tstring + xstring);
savethis2=(tstring2 + xstring2);

document.getElementById("plan").value=savethis;
document.getElementById("plan2").value=savethis2;
document.getElementById("planelevation").value=planelevation;

if ((xact)=="leave")
{
document.getElementById("savetitle").innerHTML="Do you want to save your plan before you leave?";
document.getElementById("nothanks").innerHTML="<a href=\"/index.php\" style=\"font-size:12px\">No Thanks</a>";
document.getElementById("leave").value="2";
}

else if ((xact)=="finalize")
{
document.getElementById("savetitle").innerHTML="Finalize Plan<br><br>Step one:";
document.getElementById("nothanks").innerHTML=".";
document.getElementById("leave").value="3";
}


else
{
document.getElementById("savetitle").innerHTML="Save Plan";
document.getElementById("leave").value="0";
document.getElementById("nothanks").innerHTML=".";
}
}












/* =====================================================================================================================
************************************************************************************************************************
************************************************************************************************************************
***********************************************************************************************************************
***********************************************************************************************************************
**************************************                         *******************************************************
**************************************         SCROLLING       ********************************************************                        **************************************                         **********************************************************
**************************************                         ***********************************************************     ***********************************************************************************************************************
*************************************************************************************************************************
*************************************************************************************************************************                              ***************************************************************************************************************************  
=====================================================================================================================  */

 function togglePan()
  {
  if (ypan==1)
  {
ypan=0;
document.getElementById(xcopy).style.cursor="crosshair"; 
document.getElementById('statusbar').innerHTML="You can also use the right mouse button to pan your drawing";
    }      
  else
  {
ypan=1  
document.getElementById(xcopy).style.cursor="pointer";
document.getElementById('statusbar').innerHTML="Pan Drawing"; 
     } 
  }

   
function startpanDrawing(event) 
{
if (ypan==1 && (event.button==1 || event.button==0))
{
zpan=1;
}
else
{ zpan=0;}


if (event.button==2 || event.button==4 || zpan==1)
  {
  xstart=((event.clientX)-scrollxx);
  ystart=((event.clientY)-scrollyy);

document.getElementById(xcopy).style.cursor="pointer";
xpan=1;
clearRoom();        
  }
  

else
{
xpan=0;
clearRoom(); 
}


}


// ---------------------------------------------------------------------------------------------------------------------

function panDrawing(event)
{
 
if (xpan==1)
  {
x=event.clientX;
y=event.clientY;



scrollxx=(x-xstart);
scrollyy=(y-ystart);


layer=document.getElementById(xcopy);
layer.style.top=scrollyy + "px";
layer.style.left=scrollxx + "px";

layer=document.getElementById(xcopyr);
layer.style.top=scrollyy + "px";
layer.style.left=scrollxx + "px";


  }

else
{
xpan=0;
}
 }
 
 
function unpanDrawing(event)
{
if (event.button==2 || event.button==4 || event.button==1 || event.button==0)
  {
if (ypan==0)
{
document.getElementById(xcopy).style.cursor="crosshair";
}
xpan=0;
}

moveloop=0;
rmoveloop=0;
}
 
 
 



/* ******************************************************************************************************************
**************************************  end scrolling *****************************************************************
******************************************************************************************************************  */



// Expand form depending on input -----------------------------------------------

function expForm(value,layer)
{
a=(value);
if (a==1)
{
document.getElementById(layer).style.display="inline";
}
else
{
document.getElementById(layer).style.display="none";
}

}

function contactUs(value)
{
if ((value)=="y")
document.getElementById("wecontact").innerHTML="Please check your email for a message from <a href=\"mailto:info@custom-house-plan.com\">info@custom-house-plan.com</a>";

else
{
document.getElementById("wecontact").innerHTML="";
}

}


function clearRoom()
 // clear any open rooms ----
 
 {
 
if (roomact!="room0" && rmoveloop==0)
{
document.getElementById("statusbar").innerHTML="Lay out your plan...";         
document.getElementById(roomact).style.border="solid 5px #000066";  
document.getElementById(roomact).style.cursor="pointer";
}
hideLayer('modify');            
}


/* *********************************************************************************************************
*****************************   UNDO               ********************************************************
***************************************************************************************************   */

// save for undo
function undoSave()
{

document.getElementById('fscreen').innerHTML=unum;   
x=document.getElementById('maincontent').innerHTML;

usave[unum]=x;  
unum=(unum+1);
}

function undoUse()
{
unum=(unum-1);
if (unum >=0)
{
document.getElementById('maincontent').innerHTML=usave[unum];
}
}


























































function terms()
{
document.getElementById("terms").innerHTML="Terms of use and license agreement:<br>THIS SOFTWARE IS PROVIDED BY RYAN MOE HOME DESIGN \"AS IS\" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL RYAN MOE HOME DESIGN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.";

}