window.onload = initForms;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function InsertFlashObject(objID, flashLocation, width, height, flashString) {
  var flashObject;
  flashObject = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + width + "' height='" + height + "'>";
  flashObject = flashObject + "<param name='wmode' value='transparent'>";
  flashObject = flashObject + "<param name='movie' value='" + flashLocation + "' />";
  flashObject = flashObject + "<param name='quality' value='high' />";
  if(typeof(flashString) == "undefined") {
    flashObject = flashObject + "<embed src='" + flashLocation + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' wmode='transparent'";
  } else {
    flashObject = flashObject + "<param name='FlashVars' value='" + flashString + "'";
    flashObject = flashObject + "<embed src='" + flashLocation + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' wmode='transparent' ";
    flashObject = flashObject + "FlashVars='" + flashString + "'";
  }
  flashObject = flashObject + "></embed></object>";
  if(document.getElementById(objID)) {
    document.getElementById(objID).innerHTML = flashObject;
  }
}

function initForms() {
  if(document.getElementById('qc_form')) {
    document.getElementById('name').onfocus = clearfield;
    document.getElementById('name').onblur = reinstatefield;
	document.getElementById('company').onfocus = clearfield;
    document.getElementById('company').onblur = reinstatefield;
    document.getElementById('tel').onfocus = clearfield;
    document.getElementById('tel').onblur = reinstatefield;
    document.getElementById('email').onfocus = clearfield;
    document.getElementById('email').onblur = reinstatefield;
    document.getElementById('message').onfocus = clearfield;
    document.getElementById('message').onblur = reinstatefield;
  }
}

function trim(str, chars) {
  var replaceLeft, replaceRight;
  chars = chars || "\\s";
  replaceLeft = str.replace(new RegExp("^[" + chars + "]+", "g"), "");
  replaceRight = replaceLeft.replace(new RegExp("[" + chars + "]+$", "g"), "");
  return replaceRight;
}

function clearfield() {
  switch(this.id) {
    case 'name':
      trimValue = trim(this.value);
      if(trimValue == 'Name:') {
        this.value = '';
      }
    break;
	case 'company':
      trimValue = trim(this.value);
      if(trimValue == 'Company:') {
        this.value = '';
      }
    break;
    
    case 'email':
      trimValue = trim(this.value);
      if(trimValue == 'Email:') {
        this.value = '';
      }
    break;
    
    case 'tel':
      trimValue = trim(this.value);
      if(trimValue == 'Phone:') {
        this.value = '';
      }
    break;
    
    case 'message':
      trimValue = trim(this.value);
      if(trimValue == 'Message:') {
        this.value = '';
      }
    break;
  }
}

function reinstatefield() {
  switch(this.id) {
    case 'name':
      trimValue = trim(this.value);
      if(trimValue == '') {
        this.value = 'Name:';
      }
    break;
	case 'company':
      trimValue = trim(this.value);
      if(trimValue == '') {
        this.value = 'Company:';
      }
    break;
    
    case 'email':
      trimValue = trim(this.value);
      if(trimValue == '') {
        this.value = 'Email:';
      }
    break;
    
    case 'tel':
      trimValue = trim(this.value);
      if(trimValue == '') {
        this.value = 'Phone:';
      }
    break;
    
    case 'message':
      trimValue = trim(this.value);
      if(trimValue == '') {
        this.value = 'Message:';
      }
    break;
  }
}
