
//****************************************************************************//
/**
* add an event listener to an object
* @param object object to add event to
* @param string event type to add
* @param object function to execute
*/
function addEvent(obj, evType, fn)
{
    if (obj)
    {
        if (obj.addEventListener)
        {
            obj.addEventListener(evType, fn, true);
            return true;
        }
        else if (obj.attachEvent)
        {
            var r = obj.attachEvent("on" + evType, fn);
            return r;
        }
        else
        {
            return false;
        }
    }
}

//****************************************************************************//

//Spanish Site Switch Over Code Start
var MP = {
<!-- mp_trans_disable_start --> 
  Version: '1.0.22',
  Domains: {'es':'espanol.asfurniture.com'},	
  SrcLang: 'en',

<!-- mp_trans_disable_end -->
  UrlLang: 'mp_js_current_lang',
  SrcUrl: unescape('mp_js_orgin_url'),

<!-- mp_trans_disable_start --> 	
  init: function(){
    if (MP.UrlLang.indexOf('p_js_')==1) {
      MP.SrcUrl=window.top.document.location.href;
      MP.UrlLang=MP.SrcLang;
  }
},

getCookie: function(name){
  var start=document.cookie.indexOf(name+'=');
  if(start < 0) return null;
  start=start+name.length+1;
  var end=document.cookie.indexOf(';', start);
  if(end < 0) end=document.cookie.length;
  while (document.cookie.charAt(start)==' '){ start++; }
  return unescape(document.cookie.substring(start,end));
},

setCookie: function(name,value,path,domain){
  var cookie=name+'='+escape(value);
  if(path)cookie+='; path='+path;
  if(domain)cookie+='; domain='+domain;
  var now=new Date();
  now.setTime(now.getTime()+1000*60*60*24*365);
  cookie+='; expires='+now.toUTCString();
  document.cookie=cookie;
},

switchLanguage: function(lang){
  if(lang!=MP.SrcLang){
    var script=document.createElement('SCRIPT');
    script.src=location.protocol+'//'+MP.Domains[lang]+'/'+MP.SrcLang+lang+'/?1023749632;'+encodeURIComponent(MP.SrcUrl);
	document.body.appendChild(script);
  } else if(lang==MP.SrcLang && MP.UrlLang!=MP.SrcLang){
    var script=document.createElement('SCRIPT');
    script.src=location.protocol+'//'+MP.Domains[MP.UrlLang]+'/'+MP.SrcLang+MP.UrlLang+'/?1023749634;'+encodeURIComponent(location.href);
	document.body.appendChild(script);
  }
  return false;
},

switchToLang: function(url) {
  window.top.location.href=url; 
}
<!-- mp_trans_disable_end -->   
};
//Spanish Site Switch Over Code End

//****************************************************************************//

// Dropdown Navigation Settings and Functions Start
var DDSPEED = 2;
var DDTIMER = 35;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}
// Dropdown Navigation Settings and Functions End

//****************************************************************************//

// Input Search Bar and Form Data Functions Start

// Input Search Text Onclick Clear Out
function searchSiteOnClick(id)
{
	if (!id){id= "search";}
        var el =  document.getElementById(id);	
        if ((el.value == "" )||( el.value == "Enter Keyword or Search Phrase" )|| (el.value == "Search") || (el.value == null )|| (el.value == "null")|| (el.value == " ")) {
			alert("Please Enter A Valid Search Term");
			el.value = "";
			el.focus();
			return false;
		}else{
			return true;
		}
}

function searchSiteOnBlur(id)
{
    if (!id){id= "search";}
    var el =  document.getElementById(id);
    if (el.value == "") {
        //el.style.color = "#5E6464";
        el.value = "";
    }
}

function checkHeaderStoreLocatorForm(formId)
{
	var errorsList = new Array();
	var form = document.getElementById(formId);
	var zipCode = getHFormElement(form, "find_store_zip").value;

	var size =zipCode.length  ;

	if ((isEmpty(zipCode) ||  !isNumber(zipCode) || ( size < 5)  || ( size > 5)) )
	{
		alert("Please enter a valid zip code.");
		return false;
	}

	else
	{
		form.submit();
	}

}
//whitespace only or empty
function isEmpty(inputValue)
{
	if (inputValue.match(/^s+$/) || inputValue == "")
    {
    	return true;
	}
	else
	{
		return false;
	}
}
   
function isNumber(inputValue)
{
	var i;
	if (inputValue.length = 5) 
	{
		for (i=0; i<inputValue.length; i++)
		{
			// Check that current character is number.
			var c = inputValue.charAt(i);
			if ((c < "0") || (c > "9"))
			{
				return false;
			}
		}
        // All characters are numbers.
        return true;
		}
		else {
			return false;
		}
}

function searchSiteOnBlur2(id)
{
    if (!id){id= "search";}
    var el =  document.getElementById(id);
    if (el.value == "") {
        el.style.color = "#5E6464";
        el.value = "";
    }
}
// Input Search Bar and Form Data Functions End

// Detect Mobile Browsers and Adjust Design to Remove Social Links Above Page
/*window.setTimeout(checkSocialAPI, 400);

function checkSocialAPI(){
	var twfollowers = document.getElementById('tw_count').innerHTML;
	var fbfans = document.getElementById('fb_count').innerHTML;
	var fbcounts = fbfans.length;
	var twcounts = twfollowers.length;
	var fbstr = fbfans.substring(0, fbfans.length-3);
	
	if(fbcounts <= 1){
		document.getElementById('fb_count').innerHTML = "9K people";
	}
	
	if(fbcounts > 2){
		document.getElementById('fb_count').innerHTML ="";
		document.getElementById('fb_count').innerHTML +=fbstr;
		document.getElementById('fb_count').innerHTML +="K people";
	}
	if(twcounts < 1){
		document.getElementById('tw_count').innerHTML = "170 people";
	}
	if(twcounts >= 2){
		document.getElementById('tw_count').innerHTML +=" people";
	}
	
}

if(
	(navigator.userAgent.match(/iPhone/i)) || 
	(navigator.userAgent.match(/iPod/i)) || 
	(navigator.userAgent.match(/iPad/i)) || 
	(navigator.userAgent.match(/iPod/i)) || 
	(navigator.userAgent.match(/android/i)) ||
	(navigator.userAgent.match(/BlackBerry/i)) ||
	(navigator.userAgent.match(/WebOS/i)) ||
	(navigator.userAgent.match(/Nokia/i)) ||
	(navigator.userAgent.match(/Symbian/i)) ||
	(navigator.userAgent.match(/windows ce/i))
	){
	window.setTimeout(detectBrowser, 400);
}
function detectBrowser(){
	document.getElementById('fbSocial').style.visibility="hidden";
	document.getElementById('twSocial').style.visibility="hidden";
}
*/
//****************************************************************************//
