/** Triumph Javascript - JDG **/
/* Javascript stylesheet */
document.write("<link rel=\"StyleSheet\" href=\"../includes/triumphjs.css\" type=\"text/css\" media=\"screen\" />");

/* General Functions */
function fnPrint (n) {
 window.print()
}
function fnPrintIFrame(n) {
        frames[n].focus();
        frames[n].print();        
}        
function fnSubmit(formName) { 
 eval("document.forms['" + formName + "'].submit();");
}  
function fnPopUp(filePath,height,width,attributes){
 var sScreenX = screen.width
 var sScreenY = screen.height
 var x = sScreenX - width
 var y = sScreenY - height
 var winLeft = x/2
 var winTop =  y/2 
 window.open(filePath,"","width=" + width + ",height=" + height + "," + attributes + ",left=" + winLeft + ",top=" + winTop)
}

/*--// Chromeless popups */
function fnChromeless(showTarget, classToHide, iFrameToHide) {
 //if macie or Opera
 if ((navigator.appVersion.indexOf("Mac") != -1) && (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0) || navigator.userAgent.indexOf("Opera") != -1)  {    
   var ofrs = document.getElementsByTagName("IFRAME");
   for (i=0; i< ofrs.length; i++) { 
   ofrs[i].style.visibility = "hidden";
   }
   // Hide all
   var oDivs = document.getElementsByTagName("DIV");
   for (i=0; i< oDivs.length; i++) {  
    if (oDivs[i].className == classToHide) {
     oDivs[i].style.display = "none";
    }   
   }
   //If declared, show a layer
   if (showTarget) {  
            var oShow = document.getElementById(showTarget);
            oShow.style.display = "block";    
                oShow.style.top = "383px";  
                
                var ofrs = oShow.getElementsByTagName("IFRAME");
                   for (i=0; i< ofrs.length; i++) { 
                          ofrs[i].style.visibility = "visible";   
                   }
                                 
   } else {
   var ofrs = document.getElementsByTagName("IFRAME");
   for (i=0; i< ofrs.length; i++) { 
                  ofrs[i].style.visibility = "visible";   
   }
   
     } 
 } else {
 
  // Hide all chromeless, show all iframes
  var oDivs = document.getElementsByTagName("DIV");
  var oIFrames = document.getElementsByTagName("IFRAME");
  
  for (i=0; i< oDivs.length; i++) {  
   if (oDivs[i].className == classToHide) {
   oDivs[i].style.top = "-300px";
   }  
  } 
  for (i=0; i< oIFrames.length; i++) {  
    oIFrames[i].style.visibility = "visible";    
  }
   
  //If declared, show a layer
  if (showTarget) {
 
   if (iFrameToHide) { //hide iframe containing form
    document.getElementById(iFrameToHide).style.visibility = "hidden";   
   }  
    var oShow = document.getElementById(showTarget);         
   oShow.style.top = "383px";
  }  
 }
}  

  function getObj(name)
{
  if (document.getElementById)
  {
   this.obj = document.getElementById(name);
 this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
 this.obj = document.all[name];
 this.style = document.all[name].style;
  }
  else if (document.layers)
  {
 this.obj = getObjNN4(document,name);
 this.style = this.obj;
  }
}
function getObjNN4(obj,name)
{
 var x = obj.layers;
 var foundLayer;
 for (var i=0;i<x.length;i++)
 {
  if (x[i].id == name)
    foundLayer = x[i];
  else if (x[i].layers.length)
   var tmp = getObjNN4(x[i],name);
  if (tmp) foundLayer = tmp;
 }
 return foundLayer;
}

function fnSetScrollHeight(sTargetFrame,sType,iImageHeight){
 var sPopUpHeight;
 
 if(sType == "large"){
  sPopUpHeight = 410
 }else{
  sPopUpHeight = 300
 }
 
 var iHeight = sPopUpHeight - (iImageHeight)
 
 if (iHeight > 0){
  var oScrollingLayer = new getObj(sTargetFrame);
  oScrollingLayer.style.height = iHeight;
 }
}
/*----------------------------------------------------------*/
/* add arrows to links inside 'content' div */

function fnLinks() {
 
 var oContent = document.getElementById("content");
 if(oContent != null) {
  var oATags = oContent.getElementsByTagName("A"); 
 
  for (i=0; i< oATags.length; i++) {
  
   //**Don't Display arrow if a tag contains the following class**//
   if(oATags[i].className.indexOf("noArrowLink") == -1 && oATags[i].className != "pdf"){
    oATags[i].innerHTML += "";
   }     
  } 
 }
}


/*----------------------------------------------------------*/
/**Highlight a Search Result**/
function fnHighLightResult(iResult){
 var sElement;
 var oResult;
 
 for(i=1;i<11;i++){
  sElement = "result" + i
  oResult = document.getElementById(sElement)
  
  if(i == iResult){
   oResult.className = "selectedResult" 
  }else{
   oResult.className = "result"    
  } 
 }
}
/*----------------------------------------------------------*/
/**Link to a page(where the link is retrieved from a form element)**/
function fnLinkFromForm(oFormElement){
 document.location.href = oFormElement.value
}
function fnDisplayResultWithPopUp(sInfoFrame, sInfoHref, sPopupFrame, sPopupHref) { 
 parent.frames[sInfoFrame].document.location.href=sInfoHref;
 parent.frames[sPopupFrame].document.location.href=sPopupHref;

}

function fnUpdateIFrameContents(sDetails){
 var aFrames = sDetails.split(",")
 var sDetails;
 
 for (i=0;i<aFrames.length;i++){
  if (aFrames[i] != ""){
   sDetails = aFrames[i].split("|");
   if ((sDetails[0] != "") && (sDetails[1] != "")){
    parent.frames[sDetails[0]].document.location.href=sDetails[1];
   }
  }  
 }
}

function fnChangeDropdown(){
        document.forms[0].action="?";
        document.forms[0].target = "";
        document.forms[0].submit();

}

function fnGetResults(sType, sSection) {
 
        var sList;
         var sTarget;
         
         switch (sType) {
                  case "ratpacks": 
                          sList = "ratPacksList.aspx";
                          sHome  = "ratpacks.aspx";
                          break;
                  case "dealers":
                          sList = "dealersList.aspx";
                          sHome = "dealers.aspx";
                          break;
                  case "clothing":
                          sList = "clothingList.aspx";
                          sHome = "clothing.aspx";
                     break;
                case "accessories":
                        sList = "accessoryList.aspx";
                        sHome = "accessories.aspx";
                        break;
          }  
          
   if (sSection == "list") {
           document.forms[0].action = sList
           document.forms[0].target = "eventsFrame";
   } else {
           document.forms[0].action = sHome;
   }
        
        document.forms[0].submit();
}

function showClothingPopup(iID, sType, showTarget, classToHide, iFrameToHide){
        
        parent.frames["popUpFrame"].document.location.href="clothingPopup.aspx@id=" + iID + "&amp;type=" + sType;
        fnChromeless(showTarget, classToHide, iFrameToHide        );        
        
}

/********************************************************************************

Name:                                 Flash embed
Description:                Writeout flash code. Fixes Eolas update for IE as well.
@param        swf                String path to swf file
@param        width                Number value of movie width
@param        height        Number value of movie height

*********************************************************************************/
function fnEolasFix() {
        if(navigator.userAgent.toLowerCase().indexOf("msie 6") != -1) {        
        
                obj = document.getElementsByTagName("OBJECT"); // Find <object> tags and...
                numberOfMovies = obj.length-1; // ...count them
                
                for(i=numberOfMovies; i>=0; i--) {                                                                                                                
                                        
                        // For each object, make an <embed> with same dimensions                        
                        f                                         = document.createElement("embed");                                                                        
                        f.width                        = obj[i].width;
                        f.height                        = obj[i].height;        
                        f.type                        = "application/x-shockwave-flash";
                        
                                
                        // Copy parameters of <object> to <embed>        
                        params                         = obj[i].getElementsByTagName("PARAM");                                        
                        for(j in params) {
                		if(params[j].name == "movie" ) {				
					aPath 	= params[j].value.split("?")
					file 		= aPath[0];							
					if(aPath.length>1) {		
						query = aPath[1].replace(new RegExp(/\./g), "%2E");
					} else {
						query 	= "";
					}							
					f.setAttribute("src",file+"?"+query);	
				} else {
					f.setAttribute(params[j].name, params[j].value);
				}				
			}																						
			
			// Replace object with new flash <embed>
			obj[i].parentNode.replaceChild(f,obj[i]);	
		
		}
	}
}
