//
//
// This is the code to launch the Showroom. It is placed here
// in the api.js file so it can be referenced by any page on the site
//
//

var showroom = null

function launchShowroom()
{   if (showroom == null)
    {   launchWindow()
    }
    else if (showroom.closed)
    {   launchWindow()
    }
    else
    {   showroom.focus()
    }
}

function launchWindow()
{   x = (screen.availWidth - 630) / 2
    y = ((screen.availHeight - 390) / 2 ) - 30

    attribs = "width=630,height=390,left=" + x + ",top=" + y + ",scrollbars=no,toolbar=1"
    showroom = window.open("/resshowroomna/showroom.html","showroomWindow",attribs)
    showroom.focus();
}

//
//
// This is the code to launch the Showcase. It is placed here
// in the api.js file so it can be referenced by any page on the site
//
//

var showcase = null

function launchShowcase()
{   if (showcase == null)
    {   launchShowcaseWindow()
    }
    else if (showcase.closed)
    {   launchShowcaseWindow()
    }
    else
    {   showcase.focus()
    }
}

function launchShowcaseWindow()
{   x = (screen.availWidth - 630) / 2
    y = ((screen.availHeight - 460) / 2 ) - 30

    attribs = "width=630,height=460,left=" + x + ",top=" + y + ",scrollbars=no,toolbar=1"
    showcase = window.open("/resshowcasena/showcase.html","showcaseWindow",attribs)
    showcase.focus();
}



//
//
// This is the code to launch any ad. It is placed here
// in the api.js file so it can be referenced by any page on the site
//
//

var ad = null

function launchAd(url) {
    if (ad == null) {
        launchAdWindow(url)
    }
    else if (ad.closed) {
        launchAdWindow(url)
    }
    else {
        ad.focus()
    }
}

function launchAdWindow(url){
    x = (screen.availWidth - 630) / 2
    y = ((screen.availHeight - 380) / 2 ) - 30

    attribs = "width=800,height=600,left=" + x + ",top=" + y + ",scrollbars=yes,toolbar=1"
    ad = window.open(url,"adWindow",attribs)
    ad.focus();
}

/*
Live person chat
*/
function launchClgChat(){
	window.open('http://server.iad.liveperson.net/hc/46246545/?cmd=file&amp;file=visitorWantsToChat&amp;site=46246545&amp;imageUrl=http://www.armstrong.com/resceilingsna/images/liveperson&amp;referrer='+escape(document.location),'chat46246545','width=472,height=320');
}

//
//
// This file contains miscellaneous Dynamic HTML routines
// that takes into account different browsers and platforms
//
//


function getObj(obj)
{
    var compLayr

    if (dom1)
    {   compLayr = document.getElementById(obj).style
    }
    else if (is.nav4)
    {   compLayr = document.layers[obj]
    }
    else
    {   compLayr = document.all[obj].style
    }
    return compLayr
}

function show(layr)
{   var obj = getObj(layr)
    obj.visibility = "visible"
}

function hide(layr)
{   var obj = getObj(layr)
    obj.visibility = "hidden"
}

function setZindex(layr,num)
{   var obj = getObj(layr)
    obj.zIndex = num
}

function setTop(layr,num)
{   var obj = getObj(layr)
    obj.top = num
}

function setLeft(layr,num)
{   var obj = getObj(layr)
    obj.left = num
}

function incTop(layr,num)
{   var obj = getObj(layr)
    obj.top = getTop(layr) + num
}

function incLeft(layr,num)
{   var obj = getObj(layr)
    obj.left = getLeft(layr) + num
}

function getTop(layr)
{   var obj = getObj(layr)
    if (dom1)
    {   return (document.getElementById(layr).offsetTop)
    }
    else if (is.nav4)
    {   return (obj.top)
    }
    else
    {   return (obj.posTop)
    }
}

function getLeft(layr)
{   var obj = getObj(layr)
    if (dom1)
    {   return (document.getElementById(layr).offsetLeft)
    }
    else if (is.nav4)
    {   return (obj.left)
    }
    else
    {   return (obj.posLeft)
    }
}

function getWidth(layr)
{   if ((dom1) && (!is.opera5up))
    {   return (document.getElementById(layr).offsetWidth)
    }
    else if (is.opera5up)
    {   return (document.getElementById(layr).style.pixelWidth)
    }
    else if (is.nav4)
    {   return eval("document." + layr + ".document.width")
    }
    else
    {   return (document.all[layr].scrollWidth)
    }
}

function getHeight(layr)
{   if ((dom1) && (!is.opera5up))
    {   return (document.getElementById(layr).offsetHeight)
    }
    else if (is.opera5up)
    {   return (document.getElementById(layr).style.pixelHeight)
    }
    else if (is.nav4)
    {   return eval("document." + layr + ".document.height")
    }
    else
    {   return (document.all[layr].scrollHeight)
    }
}

function layerClip(layr,topA,rightA,bottomA,leftA)
{   var obj = getObj(layr)
    if (dom1 || (is.ie4 && !is.mac))
    {   obj.clip = "rect(" + topA + " " + rightA + " " + bottomA + " " + leftA + ")"
    }
    else if (is.nav4)
    {   obj.clip.top = topA
        obj.clip.left = leftA
        obj.clip.bottom = bottomA
        obj.clip.right = rightA
    }
    else if (is.ie4 && is.mac)
    {   obj.clip = "rect(0 100% 100% 0)"
    }
}

function browserWidth()
{   if (is.nav)
    {   return (window.innerWidth)
    }
    else
    {   return (document.body.clientWidth)
    }
}

function browserHeight()
{   if (is.nav)
    {   return (window.innerHeight)
    }
    else
    {   return (document.body.clientHeight)
    }
}


/* Prepare to launch roomviewer, but first show the Design My Room Landing  */
function launchRV(RV_silo, RV_itemId, RV_lineId) {
	var uri = "/dmr/dmr.jsp?";
    if (RV_silo) {
        uri += ("type=" + RV_silo);
    }
    if (RV_itemId) {
        uri += ("&itemId=" + RV_itemId);
    }
    if (RV_lineId) {
        uri += ("&lineId=" + RV_lineId);
    }
    location.href = uri;
}


/*
	Ok - now really launch Roomviewer
	Called from /dmr/dmr.jsp
*/
function reallyLaunchRV(connectionType, RV_silo, RV_itemId, RV_lineId) {

    var uri = "/roomviewer/imagebuilder_controller.jsp?connectionType=" + connectionType;
    setOmnitureEvents(RV_silo, RV_itemId, RV_lineId);
    if (RV_silo) {
        uri += ("type=" + RV_silo);
    }
    if (RV_itemId) {
        uri += ("&itemId=" + RV_itemId);
    }

    if (RV_lineId) {
        uri += ("&lineId=" + RV_lineId);
    }

    var darWindow = window.open(uri, 'DAR', "top=0,left=0,titlebar,scrollbars=yes,resizable=yes,toolbar=yes");
    darWindow.focus();
    try {
	    darWindow.resizeTo(screen.availWidth,screen.availHeight);
	} catch(e){}
}

/*
* function to gather omniture data for DAR
*/
function setOmnitureEvents(){
    if(self.s_gs){
        s_events="event7";
        s_eVar3="DAR";
        suiteId="afpusres";

        var arg1Exists = setOmnitureEvents.arguments.length>=1 &&
                            setOmnitureEvents.arguments[0]!=null &&
                            setOmnitureEvents.arguments[0].length>0;
        var arg2Exists = setOmnitureEvents.arguments.length>=2 &&
                            setOmnitureEvents.arguments[1]!=null &&
                            setOmnitureEvents.arguments[1].length>0;

        if(arg1Exists){
            var silo=setOmnitureEvents.arguments[0];
            if(arg2Exists){
                s_products="i"+setOmnitureEvents.arguments[1];
            }else{
                if(silo=='ressheetna'){
                    s_products="Armstrong;Vinyl Sheet Floors"
                }else if(silo=='restilena'){
                    s_products="Armstrong;Vinyl Tile Floors"
                }else if(silo=='reslaminatena'){
                    s_products="Armstrong;Laminate Floors"
                }else if(silo=='reslinoleumna'){
                    s_products="Armstrong;Linoleum Floors"
                }else if(silo=='resriverstonena'){
                    s_products="Armstrong;RiverStone"
                }else if(silo=='resceramicna'){
                    s_products="Armstrong;Ceramic"
                }else if(silo=='resbrucewoodna'){
                    s_products="Bruce;Hardwood Flooring"
                }else if(silo=='reshartcona'){
                    s_products="Hartco;Hardwood Flooring"
                }else if(silo=='resrobbinsna'){
                    s_products="Robbins;Hardwood Flooring"
                }else if(silo=='resceilingsna'){
                    suiteId="abpusres";
                }
            }
        }
        //gather omniture data
        s_gs(suiteId);
    }
}

// function for adding bookmarks from any page for IE
function addBookmark(url, title) {
    if (document.all)
        window.external.AddFavorite(url,title);
}

/* Open the Cart window in the specific URL */
function doCartAction(theUrl) {
	var width = 625;
	var height = 580;
	var x = (screen.availWidth - width) / 2
    var y = ((screen.availHeight - height) / 2 ) - 30;

	var w = window.open('',
						'CART',
						"status=yes,width="+width+
							",height="+height+
							",left="+x+",top="+y+",titlebar,scrollbars=yes,resizable=yes,toolbar=yes");
	w.focus();

	try {
		w.document.close();
		w.document.open();
		w.document.writeln("Loading ... ");
	} catch(e){}

	w.location.href=theUrl;


}

/* view the Cart */
function viewCart() {
	return doCartAction('/resna/cart_action.jsp?command=view');
}

/* Add an item number to cart */
function addCart(itemId) {
	s_events="scAdd";
	s_products=";" + itemId + ";1;";
	try {
		s_gs("armecommerceus");
	}catch(e){/*doh!*/}

	return doCartAction('/resna/cart_action.jsp?command=add&itemId=' + itemId);
}

/*
	Open a window of a given size and put in it's contents "Loading"
	It's up to the caller to replace it's contents.

	Typical usage: (use this.target to not have to worry about harcoding the frame name)
	<a href="foo.html"
	   target="bar"
	   onClick="A_openWindow(this.target, 500, 500)"> Foo </a>
*/
function A_openWindow(frameName, width, height, toolbar, text) {
    var winStyle = "titlebar,scrollbars=yes,resizable=yes"
    if (toolbar!=null && toolbar.length>0) {
	    winStyle+=(",toolbar=" + toolbar);
    }
    if (width>0) {
	    winStyle+= (",left="+((screen.availWidth - width) / 2));
	    winStyle+= (",width="+width);
	}
    if (height>0) {
	    winStyle+= (",top="+(((screen.availHeight - height) / 2 ) - 30));
	    winStyle+= (",height="+height);
    }
	var w = window.open('', frameName, winStyle);

	try {
		w.document.close();
		w.document.open();

		if (text!=null && text.length>0) {
			w.document.writeln(text);
		} else {
			w.document.writeln("Loading ... ");
		}
	} catch(e){}

	w.focus();

}
