function addEvent(obj, evtType, fn, useCapture){
	if (obj.addEventListener){
		obj.addEventListener(evtType, fn, useCapture);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evtType, fn);
		return r;
	} else {
		obj['on'+evtType] = fn;
		return true;
	}
}


// Replacement calls. Please see readme.txt for more information.
// sIFR.replaceElement(sSelector, sFlashSrc, sColor, sLinkColor, sHoverColor, sAltColor, sBgColor, nPaddingTop, 
// nPaddingRight, nPaddingBottom, nPaddingLeft, sFlashVars, sCase, sWmode)
// sFlashVars can include any of the folllowing:
// textalign=center: Center text horizontally
// offsetLeft=5: Pushes text 5px to the right. Of course you can use any number here.
// offsetTop=5: Pushes text 5px down.
// underline=true: Adds underline to links on hover.
// details: http://wiki.novemberborn.net/sifr/show/How+to+use

function flashText() {
	if(typeof sIFR == "function") {

	sIFR.replaceElement(named({sSelector:"h1.sifr", sFlashSrc:"/j/sIFR/frut45lt.swf", sColor:"#333333", sLinkColor:"#333333", sBgColor:"#FFFFFF", sHoverColor:"#999999", nPaddingTop:1, nPaddingBottom:0, sFlashVars:null, sWmode:"transparent" }));

	sIFR.replaceElement(named({sSelector:"h2.sifr", sFlashSrc:"/j/sIFR/frut65bo.swf", sColor:"#FFFFFF", sLinkColor:"#333333", sBgColor:"#000000", sHoverColor:"#999999", nPaddingTop:7, nPaddingBottom:6, sFlashVars:"textalign=center", sWmode:"transparent" }));

	};

}

// Retrieve the first ancestor of a given element that matches the given 
// tag name.
function getAncestorByTagName(obj, tag) {
    var s = obj ? obj : null;
    if (s == null) return s;
    var tagName;
    do {
        s  = s.parentNode;
        tagName = s.tagName.toLowerCase();
        if (tagName=='body') return null;
    }
    while (tagName != tag);
    return s;   
}

function setOnClick() {
if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i = anchors.length; i != 0; i--) {
		var a = anchors[i-1];
		if (!a.href) continue;
		
		if ((a.rel.indexOf("external") !=-1)) {
				a.onclick = function(){ newWin(this.href,'700','460','yes','yes','yes','yes','yes','exteranlWin');return false;};
		} else if (a.rel.indexOf("popup") != -1) {
				a.onclick = function(){newWin(this.href,'380','450','no','no','yes','yes','yes','popupWin');return false;};
		} else if (a.rel.indexOf("largepop") != -1) {
				a.onclick = function(){newWin(this.href,'710','720','no','no','yes','yes','yes','popupWin');return false;};
		}
	}
}

function newWin(url,w,h,menubar,toolbar,location,scrollbar,resizable,newWin) {  
	var appWin="appWin";
	if (newWin !=""){
		appWin = newWin;
	}
	
	var appWindow = window.open(url, appWin, "menubar=" + menubar + ", toolbar=" + toolbar + ",location=" + location + ",resizable=" + resizable + ",scrollbars=" + scrollbar + ",left=0,top=0,width=" + w + ",height=" + h);
	appWindow.focus();
	}

window.onload = function(){setOnClick();}


function siteAnalytics() {
	_uacct = "UA-435179-2";
	urchinTracker();
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(flashText);



/* Shadow Box treatment for need help
 * Added by: Kunal Bhatia (kunal.bhatia@compuware.com)
 * Compuware Corporation
 * 
 * The following section of code uses ShadowBox javascript libraries 
 * to create shadow box treatment for cneed help form.
*/
function initShadowBox()
{
	Shadowbox.init();
}



/* Init Functions - The following functions create new domFunction() objects to
 * perform dom methods as the page loads and elements become available.  These 
 * methods must come after all functions that may be referenced by them.
*/

var initSAF = new domFunction(function() {
		if (typeof safHandler == "function") {
			safObj = new safHandler();
			safObj.setSAF();
		}
	}, { 'footer' : 'id' } );

var init = new domFunction(function() {
		initShadowBox();
		siteAnalytics();
		flashText();
	}, { 'footer' : 'id'} );



/* Rico based window shade treatment for check order status
 * Added by: Kunal Bhatia (kunal.bhatia@compuware.com)
 * Compuware Corporation
 * 
 * The following section of code uses Rico javascript libraries 
 * to create window shade treatment for check order status form.
*/
Rico.loadModule('Accordion','Corner');

var panel;
Rico.onLoad( function() {
  panel = Rico.SlidingPanel.top( $('outer-order-status-section'), $('order-status-form-section'));   
});



/* openCloseCheckOrderForm function designed to show check order status form and in the process 
 * hide certain subheader tab items.
 *
 * If resetToShowForm argument is provided as true then the check order status form must be shown
 * and the check order status results section must be hidden. While hidding it, reset the input values also.
 * 
 * Added by: Kunal Bhatia (kunal.bhatia@compuware.com)
 * Compuware Corporation
*/
function openCloseCheckOrderForm(resetToShowForm, orderNumberInitialString, lastNameInitialString)
{
	if (resetToShowForm!=null && resetToShowForm==true)
	{
		if (document.getElementById("check-order-result")!= null)
			document.getElementById("check-order-result").className="dn";

		if (document.getElementById("order-not-found-mesg")!= null 
			&& document.getElementById("order-not-found-mesg").className!="dn")
		{
			hideOrderNotFoundMesg();
			if (orderNumberInitialString!=null)
				document.getElementById("orderNumber").value=orderNumberInitialString;
			if (lastNameInitialString!=null)
				document.getElementById("lastName").value=lastNameInitialString;
		}
		
		document.getElementById("check-order-form").className="db";
	}

	panel.toggle();
	var classNametoSwitch = document.getElementById("subheadertabs").className;
	document.getElementById("subheadertabs").className = document.getElementById("hiddensubheadertab").className;
	document.getElementById("hiddensubheadertab").className = classNametoSwitch;
}

/* simple function that hides row with id as "order-not-found-mesg"
* This function is being reused in different places/functions, thus it was made
* into a separate function.
*/
function hideOrderNotFoundMesg()
{
	if (document.getElementById("order-not-found-mesg")!= null)
		document.getElementById("order-not-found-mesg").className="dn";
}

/* Transmitter form tooltip
 * Added by: Kunal Bhatia (kunal.bhatia@compuware.com)
 * Compuware Corporation
 * 
*/
	function showTooltip(showit) {				
		document.getElementById(showit).style.display="inline";
	}
	
	function hideTooltip(hideit) {
		document.getElementById(hideit).style.display="none";
	}

/* simple function that hides transmitter form's span layer with id as "model_number-not-found-error-mesg" */
function hideModelNumberNotFoundErrorMesg()
{
	if (document.getElementById("model_number-not-found-error-mesg")!= null)
		document.getElementById("model_number-not-found-error-mesg").className="dn";
}	
	
/* createFlashSection function
 * Function creates Flash enclosed section on pages that call it
 * The program_flash_layer_id parameter is id of the div layer where where flash will be enclosed
 * The movie_name_and_path parameter is name and path of the swf flash file to be loaded
 * The movie_width & movie_height parameters are respective width & height values of the swf flash file
 * The movie_base_path is the codebase path. Usually set to the current directory of swf file location 
 *
 * The code within uses ufo.js (which must be referenced separately).
 * It sets wmode:"transparent" so that any other layers go above the flash layer & not under it
 * "base" attribute specifies the base directory or URL used to resolve all relative path statements in the 
 * Flash Player movie. This attribute is helpful when your Flash Player movies are kept in a 
 * different directory from your other files.
 *
 * Added by: Kunal Bhatia (kunal.bhatia@compuware.com)
 * Compuware Corporation
 */
function createFlashSection(program_flash_layer_id, movie_name_and_path, movie_width, movie_height, movie_base_path,movie_flashvars)
{
	
	var FO = { movie:movie_name_and_path, width:movie_width, height:movie_height, flashvars:movie_flashvars, majorversion:"8", build:"0", allowScriptAccess:"always", xi:"true", ximovie:"/m/swf/ufo.swf", wmode:"transparent", base:movie_base_path };
	UFO.create(FO, program_flash_layer_id);
	
}


function showInstruction(code){
	if(UFO.hasFlashVersion('8')){
		var instructions = $$("div.steps");
		instructions.each(function(item){
			if( item.id != code){
				new Effect.Fade(item, { fps:250, duration:0.4 });
			}
		})
		if($(code)){
			new Effect.Appear($(code), { fps:250, duration:0.5, delay:0.4 });
			}
	}


}

function initPrograms(){
	var programs = $("programs");
	if(programs && $(programs.className)){
		showInstruction(programs.className);
	}else{
		showInstruction();
	}
}


Event.observe(window, 'load', initPrograms, false);

/*
 * Simple function utilised in all forms that have default input values 
 * but they need to erased when a user focuses on them.
 * Added by: Kunal Bhatia (kunal.bhatia@compuware.com)
 * Compuware Corporation
 * 
*/
function clearFormValue(formElement)
{
	formElement.value='';
}