function $(elementId)
{
  return document.getElementById(elementId);
}

function flashDisplay(id, width, height, wmode){
  var currPath = 'http://designcreteofamerica.com/';
  document.write('<object\n');	document.write('type="application/x-shockwave-flash"');
  document.write('data=" '+ currPath + 'flash/' + id + '.swf"');
  document.write('width="' + width + '" height="' + height + '">\n');
  document.write('<param name="loop" value="false" />\n');
  document.write('<param name="wmode" value="' + wmode + '" />\n');
  document.write('<param name="movie" value="' + currPath + 'flash/' + id + '.swf" />\n');
  document.write('</object>\n');
}

function hide(elementId)
{
  $(elementId).style.display = 'none';
}

function show(elementId)
{
  $(elementId).style.display = 'block';
}

/*
 *	Function: charCount
 *
 *  Parameters:
 *  textInput = id of input[type='text'] or id of textarea containing
 *              text to be counted.
 *  displayArea = id of the element to display the character count
 *  maxChars = the maximum amount of characters allowed for this field
 *
 *  When the maximum amount of characters are exceeded by the user,
 *  the display turns dark red, and the size increases.
*/
function charCount(textInput, displayArea, maxChars)
{
	var textElement = document.getElementById(textInput);
	var displayElement = document.getElementById(displayArea);
	
	var totalCharacters = 0;
	
	if (textElement.value != "")
		totalCharacters = textElement.value.length;
	
	displayElement.innerHTML = "Character Count: " + totalCharacters;
	
	if (totalCharacters >= maxChars)
	{
		displayElement.style.color = "#900";
		displayElement.style.fontSize = "12px";
	}
	else
	{
		displayElement.style.color = "#000";
		displayElement.style.fontSize = "11px";
	}
}

function chooseColor(indexNum)
{
  $('color_choice').selectedIndex = indexNum;
}

function nextTip(maxTip)
{
  if (currentTip == maxTip)
    return;
  
  var nextTipNum = ++currentTip;
  var nextTipId = "week_display" + nextTipNum;
  if ($(nextTipId))
    for (i = 1; i < 7; i++)
      if (i == nextTipNum)
      {
        nextTipId = "week_display" + nextTipNum;
        $(nextTipId).style.display = "block";
        nextTipId = "week_content" + nextTipNum;
        $(nextTipId).style.display = "block";
      }
      else
      {
        nextTipId = "week_display" + i;
        if ($(nextTipId))
          $(nextTipId).style.display = "none";
        nextTipId = "week_content" + i;
        if ($(nextTipId))
          $(nextTipId).style.display = "none";
      }
  return;
}

function prevTip()
{
  if (currentTip == 1)
    return;
  
  var prevTipNum = --currentTip;
  var prevTipId = "week_display" + prevTipNum;
  if($(prevTipId))
    for (i = 6; i > 0; i--)
      if (i == prevTipNum)
      {
        prevTipId = "week_display" + prevTipNum;
        $(prevTipId).style.display = "block";
        prevTipId = "week_content" + prevTipNum;
        $(prevTipId).style.display = "block";
      }
      else
      {
        prevTipId = "week_display" + i;
        if ($(prevTipId))
          $(prevTipId).style.display = "none";
        prevTipId = "week_content" + i;
        if ($(prevTipId))
          $(prevTipId).style.display = "none";
      }
  return;
}

var phone_field_length=0;
function tabNext(obj,event,len,next_field)
{
	if (obj.value.length != phone_field_length) 
	{
		phone_field_length=obj.value.length;
		if (phone_field_length == len) 
		{
			next_field.focus();
		}
		else if(isNaN(obj.value))
  	{
      obj.value = ""
      this.focus();
  	}
	}
}

function opacity(value)
{
  $("badlogin").style.opacity = value / 10;
  $("badlogin").style.filter = "alpha(opacity=" + value * 10 + ")";
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function newWin(elementId)
{
  window.open ('http://www.designcreteofamerica.com/images/gallery/bigimage/' + elementId, 'newWindow');
}

function confirmation(href)
{
  var answer = confirm('You are about to leave www.designcreteofamerica.com');
  if(answer)
  {
    window.open(href, 'newWindow');
  }
}

function formSubmit(E, submitBtn)
{
  var char = "";
  
  if (E && E.which)
  {
    char = E.which;
  }
  else
  {
    E = event;
    char = E.keyCode;
  }
  
  if (char == 13)
  {
    $(submitBtn).click();
  }
}