var siteID=87;
var scriptBaseURL='http://clientservices.covalentlogic.com/public';

function openFeedbackForm() {
  var referrerURL = document.referrer;
  var pageURL = window.location.href;
  
  var targetURL = scriptBaseURL + "/?md=feedback&tmp=home&sid=" + siteID + "&page=" + escape(pageURL) + "&ref=" + escape(referrerURL);
  
  openWindow(targetURL,"feedback",395,475);
}

function basename (path, suffix) {
    // Returns the filename component of the path  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/basename
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

function getScriptPath(scriptname){
    // Check document for our script
	scriptobjects = document.getElementsByTagName('script');
	for (i=0; i<scriptobjects.length; i++) {
		if(basename(scriptobjects[i].src).indexOf(scriptname) == 0){
			// we found our script.. lets get the path
			return scriptobjects[i].src.substring(0, scriptobjects[i].src.lastIndexOf('/'));
		};
	}
	return "";
}

function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else 
      window.onload = fnc;
  }
}
 
function openWindow (url, winname, w, h) {
	var nScrW = 800;
	var nScrH = 600;
	if (screen) {
	  nScrW = screen.availWidth;
	  nScrH = screen.availHeight;
	}	
	var leftPos = (nScrW-w)/2;
	var topPos = (nScrH-h)/2;
	window.open (url, winname, 'width=' + w + ',height=' + h + ',menu=no,toolbars=no,status=yes,scrollbars=yes,resizable=yes,top=' + topPos + ',left=' + leftPos);
	return;  
}

function createFeedbackButton() {
  //var scriptPath = getScriptPath("feedback_js.cfm");  
  //scriptBaseURL = scriptPath.replace("/scripts","");
  
  var cssNode = document.createElement('style');
  cssNode.type = 'text/css';
  cssNode.nodeValue='#fdbkTab { width:39px; height:128px; position:fixed; right:0px; top:200px; }';
  document.getElementsByTagName("head")[0].appendChild(cssNode);
  
  var divNode = document.createElement('div');
  divNode.setAttribute('style', 'width:39px; height:128px; position:fixed; right:0px; top:200px;');
  var aNode = document.createElement('a');
  aNode.setAttribute('href', 'javascript:openFeedbackForm();');
  aNode.setAttribute('onmouseout', 'MM_swapImgRestore()');
  
  var strOnmouseover="MM_swapImage('btnFdbkTab','','/images/btnFeedbackO.gif',1)";  
  aNode.setAttribute('onmouseover', strOnmouseover);
  
  var imgNode = document.createElement('img');
  var imgSrc="/images/btnFeedback.gif";
  imgNode.setAttribute('src', imgSrc);
  imgNode.setAttribute('alt', 'Feedback');
  imgNode.setAttribute('title', 'Submit Feedback About This Site');
  
  imgNode.setAttribute('name', 'btnFdbkTab');
  imgNode.setAttribute('id', 'btnFdbkTab');
  imgNode.setAttribute('width', '39');
  imgNode.setAttribute('height', '128');
  imgNode.setAttribute('border', '0');
  
  aNode.appendChild(imgNode);
  divNode.appendChild(aNode);  
  document.getElementsByTagName("body")[0].appendChild(divNode);
}

function getScriptBaseURL () {
  var scriptPath = getScriptPath("feedback_js.cfm");  
  scriptBaseURL = scriptPath.replace("/scripts","");
}

addOnloadEvent(createFeedbackButton);
