﻿function FloatToCurrency(fNumber)
{
	var strCurrency = "" + fNumber.toFixed(2);
	
	var i = 6;
	if ( fNumber < 0 )
		i = 7;
	while ( i < strCurrency.length )
	{
		strCurrency = strCurrency.substring(0, strCurrency.length - i) + "," + strCurrency.substring(strCurrency.length-i,strCurrency.length);
		i += 4;
	}
	
	return "$" + strCurrency;
}

function CurrencyToFloat(cNumber)
{
	
	var strNumber = "" + cNumber;
	
	strNumber = strNumber.replace('$','');
	var iNumberOfCommas = (strNumber.length - 3) / 4;
	var i = 0;	
	while ( i <= iNumberOfCommas ) 
	{
		strNumber = strNumber.replace(',','');
		i++;
	}
	
	return strNumber;	
}

function TrimWhiteSpace(strString)
{
	return strString.replace(/^\s*|\s*$/g,"");
}

function DOTNETROUND(dNumber)
{
	
	
	return dNumber;
}

function hideElementByID(elemName)
{
	if ( document.getElementById(elemName) )
		hideElementByObject(document.getElementById(elemName));
}

function hideElementByObject(elem)
{
	elem.style.visibility = 'hidden';
	elem.style.display = 'none';
}

function showElementByID(elemName)
{	
	if ( document.getElementById(elemName) )
		showElementByObject(document.getElementById(elemName));
}

function showElementByObject(elem)
{
	elem.style.visibility = 'visible';
	elem.style.display = 'block';
}


//Cookie Functions
/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

var arrFurnitureType = ["Chair","Chair Pillow","Sofa","Sofa Pillow 1","Sofa Pillow 2","Sofa Pillow 3","Drapes"]

function clearRoomCookie()
{
    deleteCookie("Floor_Type");
    deleteCookie("Floor_Image");
 
    deleteCookie("Floor_Color");
    deleteCookie("Floor_Color");
    
    
    deleteCookie("Room_Name");
    deleteCookie("EGallery_Products");
    deleteCookie("eGallery_Initialized");
    
    //Do not clear the session id

    for(var i=0; i < arrFurnitureType.length; i++)
    {    
        deleteCookie(arrFurnitureType[i]);
    }
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
} 

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
