﻿// JScript File

var Concierge_showPopupCookieName = "ShowConciergePopup";
var Concierge_showPopupDelayParam = true;

function Concierge_GetUrlReferrer()
{
	return location.href;
}

function Concierge_GetPageTitle()
{
	return document.title;
}

function Concierge_PrepareConciergeBox()
{
	objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++)
	{
		objects[i].outerHTML = objects[i].outerHTML;
	}
    	
	//window.ConciergeFlashClientBox = document.forms[0].ConciergeFlashClientBox;
	window.ConciergeFlashClientBox = document.getElementById('ConciergeFlashClientBox');
	
		
    Concierge_showPopup();
    Concierge_showEffect();
	
	//zIndex("ew", 0);
	//zIndex("WindowMoveEffect", 999);
	//zIndex("PopupWindow", 1000);
}

function Concierge_zIndex(id, z_index) //Not used
{ 
	var obj = document.getElementById(id);
	//alert("obj.style.zIndex = "+obj.style.zIndex);
        if (obj) {
            obj.style.zIndex = z_index;
		}
	//alert("obj.style.zIndex = "+obj.style.zIndex);
}

function Concierge_showPopupDelay()
{
    if (Concierge_showPopupDelayParam == true)
		Concierge_mouseOnClick_popupEffectShow();
}

function Concierge_popupVisibility(bolPopupVisible)
{
   var myPopup = document.getElementById('Concierge_PopupWindow');
   var effectWindow = document.getElementById('Concierge_WindowMoveEffect');
   var myBox = document.getElementById('ConciergeFlashClientBox');
	

   if (bolPopupVisible) 
   {
       myPopup.style.visibility = 'visible';
	   myPopup.style.zIndex = 1000;
	   effectWindow.style.zIndex = 999;
	   myBox.style.zIndex = 998;
	   Concierge_showPopupDelayParam = false;
   }
   else
   {
      myPopup.style.visibility = 'hidden';
	  myPopup.style.Hidden = "true";
	  myPopup.style.zIndex = 998;
	  effectWindow.style.zIndex = 1000;
	  myBox.style.zIndex = 999;
   }
}

function Concierge_showEffect()
{
	var tmpPopup_Window = document.createElement('div');
	tmpPopup_Window.setAttribute('id', 'Concierge_WindowMoveEffect');
	tmpPopup_Window.setAttribute('class', 'Concierge_WindowMoveEffect');
	tmpPopup_Window.innerHTML = "<table border='0px' cellspacing='0' cellpadding='0'><tr><td > &nbsp; </td></tr></table>";

    document.body.appendChild(tmpPopup_Window);
}

function Concierge_showPopup()
{
	var popup_Window = document.createElement('div');
	popup_Window.setAttribute('id', 'Concierge_PopupWindow');
	popup_Window.setAttribute('class', 'Concierge_PopupWindow');
	popup_Window.innerHTML = "<table cellspacing='0' cellpadding='0' align='center'><tr><td onclick='javascript:Concierge_popupVisibility(false);javascript:Concierge_openWindow();' class='Concierge_PopupStyleImage' colspan='2'></td></tr><tr><td class='Concierge_PopupStyleTable'><center>NO THANKS, I'M NOT READY TO CHAT</center></td><td onclick='javascript:Concierge_mouseOnClick_popupEffectHide(); clientX=0; clientY=0;' class='Concierge_PopupWindowCloseButton'></td></tr></table>";
    
		document.body.appendChild(popup_Window);
}

function Concierge_showEffect_old()
{
    document.write("<div id='Concierge_WindowMoveEffect' class='Concierge_WindowMoveEffect'>");
	document.write("<table border='0px' cellspacing='0' cellpadding='0'>");
    document.write("<tr>");
    document.write("<td > &nbsp; </td>");
    document.write("</tr>");
    document.write("</table></div>");
}

function Concierge_showPopup_old()
{
    document.write("<div id='Concierge_PopupWindow' class='Concierge_PopupWindow'>");
	document.write("<table cellspacing='0' cellpadding='0' align='center'>");
    document.write("<tr>");
    document.write("<td onclick='javascript:Concierge_popupVisibility(false);javascript:Concierge_openWindow();' class='Concierge_PopupStyleImage' colspan='2'></td>");
	//document.write("<td class='PopupStyleImage' colspan='2'></td>");
    document.write("</tr>");
    document.write("<tr>");
    document.write("<td class='Concierge_PopupStyleTable'><center>NO THANKS, I'M NOT READY TO CHAT</center></td>");
    document.write("<td onclick='javascript:Concierge_mouseOnClick_popupEffectHide(); clientX=0; clientY=0;' class='Concierge_PopupWindowCloseButton'></td>");
    document.write("</tr>");
    document.write("</table></div>");
}

function Concierge_openWindow()
{
    var popupWindow = window.open("http://beta.websiteconcierge.com/ConciergeLiveChat.aspx?referrer=" + Concierge_GetUrlReferrer() +"&title="+ Concierge_GetPageTitle(), "ConciergeLiveSupportService", "toolbar=0, copyhistory=0 ,menubar=0, scrollbars=0, resizable=0, status=0, location=0, directories=no, height=380, width=480, left=200px, top=200px", "")
    Concierge_popupWindow.focus();
}

function Concierge_mouseOnClick_popupEffectShow()
{
	Concierge_popupEffectShow();
}

function Concierge_mouseOnClick_popupEffectHide()
{
	Concierge_popupEffectHide();
}
 
function Concierge_popupEffectShow() 
{
	Concierge_SetConciergeCookie();
    Concierge_StartMoveUPEffect('ConciergeFlashClientBox', 'Concierge_WindowMoveEffect', 'Concierge_PopupWindow');
}

function Concierge_popupEffectHide()
{
	Concierge_StartMoveDOWNEffect('ConciergeFlashClientBox', 'Concierge_WindowMoveEffect', 'Concierge_PopupWindow');
}

function Concierge_ShouldShowPopup()
{
     var name = "ShowPopupCookieName";
     var bShow = true;
     var myCookie = " " + document.cookie + ";";

     var searchName = " " + name + "=";
     var startOfCookie = myCookie.indexOf(searchName);

     if (startOfCookie != -1)
     {
          startOfCookie += searchName.length;
          endOfCookie = myCookie.indexOf(";", startOfCookie);
          bShow = unescape(myCookie.substring(startOfCookie, endOfCookie));
     }

     return bShow;
}

function Concierge_SetConciergeCookie()
{
     var name = "ShowPopupCookieName";
     var value = "false";
     var oneHour = 1000 * 60 * 60;
     var expDate = new Date();
     expDate.setTime(expDate.getTime() + oneHour);
     document.cookie = name + "=" + escape(value) + "; expires=";// + expDate.toGMTString();
}

////////////////////////////////////
//Variables
		var nmbFULL_OPACITY = 0;
		var nmbNULL_OPACITY = 1;
		var nmbChangeObjOpacity1Step = 0;
		var nmbObjOpacity;
		
		var nmbSTEP_COUNT = 0;
		var strGetParrentWindowID = "";
		var strGetMovingWindowID =	"";
		var strGetMoveToWindowID =	"";
		
		var objParrentWindow;
		var objDriveWindow;
		var objMoveToWindow;
		
		var nmbBeginPosition_X = 0;
		var nmbBeginPosition_Y = 0;
		
		var nmbEndPosition_X = 0;
		var nmbEndPosition_Y = 0;
		
		var nmbMoveObjSizeBeginWidth = 0;
		var nmbMoveObjSizeBeginHeight = 0;
		
		var nmbMoveObjSizeEndWidth = 0;
		var nmbMoveObjSizeEndHeight = 0;
		var nmbMOVE_STEP = 15;
		
		var nmbCoordinateMove1Step_X = 0;
		var nmbCoordinateMove1Step_Y = 0;
		var nmbObjSizeMove1Step_X = 0;
		var nmbObjSizeMove1Step_Y = 0;
		
		var nmbStartMove_Y = 0;
		var nmbStartMove_X = 0;
		
		var nmbStartObjectSize_X = 0;
		var nmbStartObjectSize_Y = 0;
		
		var bolObjShow = false;
				
		//Effect
		//WindowMoveUP
		function Concierge_StartMoveUPEffect(strParrentWindowID, strMovingWindowID, strMoveToWindowID)
		{
			bolObjShow = true;
			
			strGetParrentWindowID = strParrentWindowID;
			strGetMovingWindowID = strMovingWindowID;
			strGetMoveToWindowID = strMoveToWindowID;
			
			objParrentWindow = Concierge_GetObjById(strGetParrentWindowID);
			objDriveWindow = Concierge_GetObjById(strGetMovingWindowID);
			objMoveToWindow = Concierge_GetObjById(strGetMoveToWindowID);
									
			//Start positions object
			nmbBeginPosition_X = Concierge_getElementLeft(objParrentWindow);
			nmbBeginPosition_Y = Concierge_getElementTop(objParrentWindow);
				
			objDriveWindow.style.top = nmbBeginPosition_Y;
			objDriveWindow.style.left = nmbBeginPosition_X;
				
			nmbEndPosition_X = Concierge_getElementLeft(objMoveToWindow); 
			nmbEndPosition_Y = Concierge_getElementTop(objMoveToWindow);
				
			nmbMoveObjSizeBeginWidth = objParrentWindow.offsetWidth;   	//objParrentWindow.clientWidth;
			nmbMoveObjSizeBeginHeight = objParrentWindow.offsetHeight; 	//objParrentWindow.clientHeight;
				
			nmbMoveObjSizeEndWidth = objMoveToWindow.offsetWidth;  		//objMoveToWindow.clientWidth;
			nmbMoveObjSizeEndHeight = objMoveToWindow.offsetHeight; 	//objMoveToWindow.clientHeight;
						
			//Move
			nmbCoordinateMove1Step_X = (nmbEndPosition_X - nmbBeginPosition_X)/nmbMOVE_STEP;
			nmbCoordinateMove1Step_Y = (nmbEndPosition_Y - nmbBeginPosition_Y)/nmbMOVE_STEP;
			nmbObjSizeMove1Step_X = (nmbMoveObjSizeEndWidth - nmbMoveObjSizeBeginWidth)/nmbMOVE_STEP;
			nmbObjSizeMove1Step_Y = (nmbMoveObjSizeEndHeight - nmbMoveObjSizeBeginHeight)/nmbMOVE_STEP;
			
			//Opacity
			nmbChangeObjOpacity1Step = nmbNULL_OPACITY/nmbMOVE_STEP;
										
			nmbStartMove_Y = nmbBeginPosition_Y;
			nmbStartMove_X = nmbBeginPosition_X;
			nmbStartObjectSize_X = nmbMoveObjSizeBeginWidth;
			nmbStartObjectSize_Y = nmbMoveObjSizeBeginHeight;
			
			Concierge_WindowMoving();
		}
				
		function Concierge_StartMoveDOWNEffect( strParrentWindowID, strMovingWindowID, strMoveToWindowID )
		{
			bolObjShow = false;
			Concierge_popupVisibility(bolObjShow);
			
			strGetParrentWindowID = strParrentWindowID;
			strGetMovingWindowID = strMovingWindowID;
			strGetMoveToWindowID = strMoveToWindowID;
			
			objParrentWindow = Concierge_GetObjById(strGetParrentWindowID);
			objDriveWindow = Concierge_GetObjById(strGetMovingWindowID);
			objMoveToWindow = Concierge_GetObjById(strGetMoveToWindowID);
						
			//Start positions object
			nmbBeginPosition_X = Concierge_getElementLeft(objMoveToWindow);
			nmbBeginPosition_Y = Concierge_getElementTop(objMoveToWindow);
						
			objDriveWindow.style.top = nmbBeginPosition_Y;
			objDriveWindow.style.left = nmbBeginPosition_X;
						
			objDriveWindow.style.width = objMoveToWindow.offsetWidth;		//objMoveToWindow.clientWidth;
			objDriveWindow.style.height = objMoveToWindow.offsetHeight;		//objMoveToWindow.clientHeight;
						
			nmbEndPosition_X = Concierge_getElementLeft(objParrentWindow); 
			nmbEndPosition_Y = Concierge_getElementTop(objParrentWindow);
				
			nmbMoveObjSizeBeginWidth = objMoveToWindow.offsetWidth;			//objMoveToWindow.clientWidth;
			nmbMoveObjSizeBeginHeight = objMoveToWindow.offsetHeight;		//objMoveToWindow.clientHeight;
				
			nmbMoveObjSizeEndWidth = objParrentWindow.offsetWidth;			//objParrentWindow.clientWidth;
			nmbMoveObjSizeEndHeight = objParrentWindow.offsetHeight;		//objParrentWindow.clientHeight;
						
			//Move
			nmbCoordinateMove1Step_X = (nmbEndPosition_X - nmbBeginPosition_X)/nmbMOVE_STEP;
			nmbCoordinateMove1Step_Y = (nmbEndPosition_Y - nmbBeginPosition_Y)/nmbMOVE_STEP;
			nmbObjSizeMove1Step_X = (nmbMoveObjSizeEndWidth - nmbMoveObjSizeBeginWidth)/nmbMOVE_STEP;
			nmbObjSizeMove1Step_Y = (nmbMoveObjSizeEndHeight - nmbMoveObjSizeBeginHeight)/nmbMOVE_STEP;
			
			//Opacity
			nmbChangeObjOpacity1Step = nmbNULL_OPACITY/nmbMOVE_STEP;
										
			nmbStartMove_Y = nmbBeginPosition_Y;
			nmbStartMove_X = nmbBeginPosition_X;
			nmbStartObjectSize_X = nmbMoveObjSizeBeginWidth;
			nmbStartObjectSize_Y = nmbMoveObjSizeBeginHeight;
				
			Concierge_WindowMoving();
		}
		
		function Concierge_VariablesCleaner()
		{
			nmbFULL_OPACITY = 0;
			nmbNULL_OPACITY = 1;
			nmbChangeObjOpacity1Step = 0;
			nmbObjOpacity;
		
			nmbSTEP_COUNT = 0;
			strGetParrentWindowID = "";
			strGetMovingWindowID =	"";
			strGetMoveToWindowID =	"";
		
			objParrentWindow;
			objDriveWindow;
			objMoveToWindow;
		
			nmbBeginPosition_X = 0;
			nmbBeginPosition_Y = 0;
		
			nmbEndPosition_X = 0;
			nmbEndPosition_Y = 0;
		
			nmbMoveObjSizeBeginWidth = 0;
			nmbMoveObjSizeBeginHeight = 0;
		
			nmbMoveObjSizeEndWidth = 0;
			nmbMoveObjSizeEndHeight = 0;
			nmbMOVE_STEP = 15;
		
			nmbCoordinateMove1Step_X = 0;
			nmbCoordinateMove1Step_Y = 0;
			nmbObjSizeMove1Step_X = 0;
			nmbObjSizeMove1Step_Y = 0;
		
			nmbStartMove_Y = 0;
			nmbStartMove_X = 0;
		
			nmbStartObjectSize_X = 0;
			nmbStartObjectSize_Y = 0;
		
			bolObjShow = false;
		}
		
		//Out in parameters
		function Concierge_OutInParameters()
		{
			/*var a = "";
			a += "strParrentWindowID = " + strParrentWindowID + "\r\n";
			a += "strMovingWindowID = " + strMovingWindowID + "\r\n";
			a += "strMoveToWindowID = " + strMoveToWindowID + "\r\n";
			
			a += "nmbBeginPosition_X = " + nmbBeginPosition_X + "\r\n";
			a += "nmbBeginPosition_Y = " + nmbBeginPosition_Y + "\r\n";
			
			a += "objDriveWindow.style.top = " + objDriveWindow.style.top + "\r\n";
			a += "objDriveWindow.style.left = " + objDriveWindow.style.left + "\r\n";
			
			a += "nmbEndPosition_X = " + nmbEndPosition_X + "\r\n";
			a += "nmbEndPosition_Y = " + nmbEndPosition_Y + "\r\n";
			
			a += "nmbMoveObjSizeBeginWidth = " + nmbMoveObjSizeBeginWidth + "\r\n";
			a += "nmbMoveObjSizeBeginHeight = " + nmbMoveObjSizeBeginHeight + "\r\n";
			
			a += "nmbMoveObjSizeEndWidth = " + nmbMoveObjSizeEndWidth + "\r\n";
			a += "nmbMoveObjSizeEndHeight = " + nmbMoveObjSizeEndHeight + "\r\n";
			
			alert(a);*/
		}
		
		//WindowMoving
		function Concierge_WindowMoving()
		{
			if(nmbSTEP_COUNT < nmbMOVE_STEP)
			{
				nmbSTEP_COUNT++;
				objDriveWindow.style.visibility = 'visible';	
				
				if(bolObjShow == true)
				{
					nmbFULL_OPACITY += nmbChangeObjOpacity1Step; 
					Concierge_setElementOpacity(objDriveWindow, nmbFULL_OPACITY);
				}
				else
				{
					nmbNULL_OPACITY -= nmbChangeObjOpacity1Step; 
					Concierge_setElementOpacity(objDriveWindow, nmbNULL_OPACITY);
				}	
				
				nmbStartMove_X += nmbCoordinateMove1Step_X;
				nmbStartObjectSize_X += nmbObjSizeMove1Step_X;
				objDriveWindow.style.left = nmbStartMove_X + 'px';
				objDriveWindow.style.width = nmbStartObjectSize_X + 'px';
						
				nmbStartMove_Y += nmbCoordinateMove1Step_Y;
				nmbStartObjectSize_Y += nmbObjSizeMove1Step_Y;
				objDriveWindow.style.top = nmbStartMove_Y + 'px';
				objDriveWindow.style.height = nmbStartObjectSize_Y + 'px';
						
				setTimeout( "Concierge_WindowMoving();", 1);
			}
			else
			{
			    objDriveWindow.style.visibility = 'hidden';
								
				if(bolObjShow == true)
				  Concierge_popupVisibility(bolObjShow);
				  
				Concierge_VariablesCleaner();
			}
		}
			
		//Cross browse get element object
		function Concierge_GetObjById( objID )
		{
		    if (document.getElementById)
		        var returnVar = document.getElementById(objID);
		    else if (document.all)
		        var returnVar = document.all[objID];
		    else if (document.layers)
		        var returnVar = document.layers[objID];
		    return returnVar;
		}
		
		//Show object DOM properties
		function Concierge_showProperties(element)
		{
		  var s = "";
		  for(var prop in element)
		    s += prop +"="+element[prop] +"\r\n";
		  alert(s);
		}
		
		//Element position (Universal function) LEFT
		function Concierge_getElementLeft(elem)
		{
			var xPos = elem.offsetLeft;
			var tempEl = elem.offsetParent;
     
			while (tempEl != null) 
			{
				xPos += tempEl.offsetLeft;
				tempEl = tempEl.offsetParent;
			}

			return xPos;
		}

		//Element position (Universal function) TOP
		function Concierge_getElementTop(elem) 
		{
			var yPos = elem.offsetTop;
			var tempEl = elem.offsetParent;
	     
			while (tempEl != null) 
			{
	          yPos += tempEl.offsetTop;
	          tempEl = tempEl.offsetParent;
			}
	     
		 return yPos;
		}
		
		//Show properties
		function Concierge_showProperties(elem)
		{
		  var s = "";
		  for(var prop in elem)
		    s += prop +"="+ elem[prop] +"\r\n";
			
			//s += "getAttribute() ="+ getAttribute() +"\r\n";
		  alert(s);
		}
		
		//Opacity
		function Concierge_setElementOpacity(oElem, nOpacity)
		{
			var p = Concierge_getOpacityProperty();
			(Concierge_setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;	var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;	if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
		}
		
		function Concierge_getOpacityProperty()
		{
			var p;
			if (typeof document.body.style.opacity == 'string') p = 'opacity';
			else if (typeof document.body.style.MozOpacity == 'string') p =  'MozOpacity';
			else if (typeof document.body.style.KhtmlOpacity == 'string') p =  'KhtmlOpacity';
			else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p =  'filter';
			
			return (Concierge_getOpacityProperty = new Function("return '"+p+"';"))();
		}
		
		//Fix

