// JScript File

function rc_getElementById(id) 
{
   if ( document.all )
      return document.all[id];
   else 
      return document.getElementById(id);
}

function rc_PreLoadImage(imageId, imageUrl)
{
   if ( document.images )
   {
      eval("var img" + imageId.toString() + " = new Image(); img" + imageId.toString() + ".src = '" + imageUrl + "';")
   }
}

function rc_ImageSwap(destImgId, imgLink)
{
var img;

   img = rc_getElementById(destImgId);
   
   if ( img != null )
   {
      img.src = imgLink;
   }
}

function rc_Clear(textBoxId)
{
var txtBox;
   
   txtBox = rc_getElementById(textBoxId);
   
	txtBox.value = "";
}

function rc_Clear2(textBoxId, textToClear)
{
var txtBox;
   
   txtBox = rc_getElementById(textBoxId);
   
   if ( txtBox.value == textToClear )
   {
		txtBox.value = "";
   }
}

function rc_ShowPagePopup(page, width, height)
{
	var hWnd = window.open(page, "Window", "width=" + width.toString() + ",height=" + height.toString() + ",resizable=yes,scrollbars=yes");
	
	hWnd.focus();
	
	if ((document.window != null) && (!hWnd.opener))
		hWnd.opener = document.window;
}

function rc_PopupPartDetail(siteRoot, partNumber, accessory)
{
 	var hWnd = window.open(siteRoot + "/SSPartOnly.aspx?PPStack=0&pop=1&ShHd=0&ShFt=0&PartID=" + partNumber + "&Acc=" + accessory,"Window","width=570,height=600,resizable=yes,scrollbars=yes");
   
   hWnd.focus();
   
	if ((document.window != null) && (!hWnd.opener))
		hWnd.opener = document.window;
}

function rc_PopupPartDetail2(siteRoot, partNumber, accessory, cartToNewWindow, additionalArgs)
{
   var url = 
      siteRoot + 
      "/SSPartOnly.aspx?PPStack=0&pop=1&ShHd=0&ShFt=0&PartID=" + 
      partNumber + "&Acc=" + accessory + "&CartToNewWindow=" + cartToNewWindow + additionalArgs;
   
 	var hWnd = window.open(url,"Window","width=570,height=600,resizable=yes,scrollbars=yes");
   
   hWnd.focus();
   
	if ((document.window != null) && (!hWnd.opener))
		hWnd.opener = document.window;
}

function rc_CopyToClipboard(controlId)
{
   window.clipboardData.setData("Text", rc_getElementById(controlId).innerText);
}

function rc_SetCookie( name, value, expires, path, domain, secure ) 
{
   // set time, it's in milliseconds
   var today = new Date();
   today.setTime( today.getTime() );

   /*
   if the expires variable is set, make the correct 
   expires time, the current script below will set 
   it for x number of days, to make it for hours, 
   delete * 24, for minutes, delete * 60 * 24
   */
   if ( expires )
   {
	   expires = expires * 1000 * 60 * 60 * 24;
   }
   
   var expires_date = new Date( today.getTime() + (expires) );

   document.cookie = name + "=" +escape( value ) +
	   ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	   ( ( path ) ? ";path=" + path : "" ) + 
	   ( ( domain ) ? ";domain=" + domain : "" ) +
	   ( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function rc_GetCookie( name ) 
{
   var cookieValue = null;

   if ( document.cookie.length > 0 )
   {
      var extractExp = new RegExp("(?:^|;)\\s*" + name + "=(.*?)(?:$|;)");
      var match = document.cookie.match(extractExp);
      
      if ( match != null )
      {
         cookieValue = unescape(match[1]);
      }
   }
   
   return cookieValue;
}

// this deletes the cookie when called
function rc_DeleteCookie( name, path, domain ) 
{
   if ( Get_Cookie( name ) ) 
   {
   	document.cookie = name + "=" +
		   ( ( path ) ? ";path=" + path : "") +
		   ( ( domain ) ? ";domain=" + domain : "" ) +
		   ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
   }
}

function rc_DetermineVersion()
{
   var versionNeeded = rc_GetCookie("VersionNeeded");
  
   if (self == top && versionNeeded == null )
   {
      rc_SetCookie("VersionNeeded", "1", 180, "/", "", "");

      if ( rc_GetCookie("VersionNeeded") != null )
      {
         window.location.reload(true);
      }
   }
}

function rc_CountVisit()
{
   var visit = rc_GetCookie("Visit");
   
   if ( self == top && visit == null )
   {
      rc_SetCookie("Visit", "X&X&12312020000000", 3650, "/", "", "");
      
      if ( rc_GetCookie("Visit") != null )
      {
         window.location.reload(true);
      }
   }
}

function rc_GetRef(pageTracker)
{
	ref = document.referrer;
	re = /(\?|&)(q|p)=([^&]*)/;
	searchq = re.exec(ref);
	if(searchq) 
	{
		pageTracker._setVar(searchq[3]);
	}
}

function rc_Sleuth(pageTracker)
{
	if (document.cookie.indexOf("__utmz=") != -1)
	{
		z = rc_GetCookie('__utmz');
		za = z.split('|');
		t = za[0].split('.');
		za[0] = t[t.length - 1];
		for (i = 0; i < za.length; i++)
		{	
			t2 = za[i].split('=');
			if (t2[0] == 'utmgclid' || t2[1] == 'cpc' || t2[1] == 'ppc')	
			{
				rc_GetRef(pageTracker);
			}
		}
	}
}

function rc_getOffsetTop(id)
{
	var e = rc_getElementById(id);
	var offset = 0;
	
	if (e != null)
	{
		var p = e.offsetParent;
		
		while ( p != null )
		{
			offset += p.offsetTop;
			
			p = p.offsetParent;
		}
	}
	
	return offset;
}

function rc_getOffsetLeft(id)
{
	var e = rc_getElementById(id);
	var offset = 0;
	
	if (e != null)
	{
		var p = e.offsetParent;
		
		while ( p != null )
		{
			offset += p.offsetLeft;
			
			p = p.offsetParent;
		}
	}
	
	return offset;
}

function rc_getViewportHeight()
{
	var viewportHeight = 0;

	if ( window.innerHeight ) // non-IE
	{
		viewportHeight = window.innerHeight;
	}
	else // Handle IE
	{
		viewportHeight = document.documentElement.clientHeight;
	}
	
	return viewportHeight;
}

function rc_resizePaneToFitRemainingHeight(splitterId, paneId, heightModifier)
{
	var pane = $find(splitterId).getPaneById(paneId);
	var paneOffset = rc_getOffsetTop(pane.GetContentElement().id);
	var viewportHeight = rc_getViewportHeight();
	var newHeight = viewportHeight - paneOffset + heightModifier;

	pane.set_height(newHeight);
}

function rc_resizePaneToContentHeight(splitterId, paneId)
{
    var pane = $find(splitterId).getPaneById(paneId);
    var parentContent = pane.getContentElement();
    var contentHeight = parentContent.scrollHeight;
    pane.set_height(contentHeight);    
}

function rc_resizeGridRelative(grid, controlToFit, heightModifier)
{
	var newScrollHeight = controlToFit.clientHeight;

	if ( grid.GridHeaderDiv != null )
	{
		newScrollHeight -= grid.GridHeaderDiv.offsetHeight;
	}
	
	if ( grid.GridFooterDiv != null )
	{
		newScrollHeight -= grid.GridFooterDiv.offsetHeight;
	}
	
	if ( grid.PagerControl != null )
	{
		newScrollHeight -= grid.PagerControl.offsetHeight;
	}
	
	grid.GridDataDiv.style.height = newScrollHeight + heightModifier + "px";
}

function rc_getPreviousSiblingsOffset(controlToFit)
{
	var totalOffset = 0;
	var previous = controlToFit.previousSibling;
	
	while ( previous != null )
	{
		if ( previous.offsetHeight )
		{
			totalOffset += previous.offsetHeight;
		}
		
		previous = previous.previousSibling;
	}
	
	return totalOffset;
}

function rc_getParentOffsets(id)
{
	var e = rc_getElementById(id);
	var offset = 0;
	
	if (e != null)
	{
		var p = e.parentNode;
		
		while ( p != null )
		{
			if ( p.offsetTop )
			{
				offset += p.offsetTop;
			}
			
			p = p.parentNode;
		}
	}
	
	return offset;
}

function rc_resizeControlToFitRemainingSpace(controlToFit, heightModifier)
{
	var viewportHeight = rc_getViewportHeight();
	var newHeight = 
		viewportHeight - rc_getParentOffsets(controlToFit.id) - 
		rc_getPreviousSiblingsOffset(controlToFit) + heightModifier;
	
	controlToFit.style.height = newHeight + "px";
}

function rc_isBlank(s)
{
	var nIdx;	
	for (nIdx = 0; nIdx < s.length; nIdx ++)
		if (s.charAt(nIdx) != ' ')
			return false;
	return true;
}

function rc_scrollGridToSelectedRow(gridId)
{
   var grid = $find(gridId);
  
   if (grid)
   {
      var row = grid.get_masterTableView().get_selectedItems()[0];

      if (row)
      {
         setTimeout( function(){
            var rowElement = row.get_element();
            //get the main table scrollArea HTML element
            var scrollArea = grid.GridDataDiv;
                 
            //check if the selected row is below the viewable grid area
            if((rowElement.offsetTop - scrollArea.scrollTop) +
             rowElement.offsetHeight + 20 > scrollArea.offsetHeight)
            {
            //scroll down to selected row
            scrollArea.scrollTop = //rowElement.offsetTop - rowElement.offsetHeight;
            scrollArea.scrollTop +
              (rowElement.offsetTop - scrollArea.scrollTop) +
              (rowElement.offsetHeight - scrollArea.offsetHeight) +
              rowElement.offsetHeight;
            }
            //chck if the selected row is above the viewable grid area
            else if((rowElement.offsetTop - scrollArea.scrollTop) < 0)
            {
            //scroll the selected row to the top
            scrollArea.scrollTop = rowElement.offsetTop;
            }
         }, 200);
      }
   }
}

function rc_submitUrl(formId, actionUrl)
{
   var form = $get(formId);
   
   if ( form )
   {
      form.action = actionUrl;
      form.submit();
   }
}

function rc_clearFormValue(formId, elementId)
{
   var form = $get(formId);

   if ( form )   
   {
      form[elementId].value = null;
   }
}

function rc_renameElement(id, newName)
{
   var e = $get(id);
   
   if ( e )
   {
      e.name = newName;
   }
}

function rc_renameElementId(id, newName)
{
   var e = $get(id);
   
   if ( e )
   {
      e.id = newName;
   }
}

function rc_createHiddenElement(formId, id, name, value)
{
   var form = rc_getElementById(formId);
   
   if ( form )
   {
      var e = document.createElement("input");
      
      e.type = "hidden";
      e.name = name;
      e.value = value;
      e.id = id;
      
      form.appendChild(e);
   }
}

function rc_createForm(id, name, action, method)
{
   var form = document.createElement("form");
   
   form.id = id;
   form.name = name;
   form.action = action;
   form.method = method;
   
   document.body.appendChild(form);
}

function rc_menuNavigate(url)
{
   var tabSelectedHidden = $get('tabSelectedIndex');
   document.location.href = String.format(url, tabSelectedHidden.value);
}

function rc_enableDisableButton(ItemID, enable)
{
   var item;
   item = $get(ItemID);
   if (enable == true)
   {
      item.disabled = false;
      item.className = 'webAppButton';
   }
   else
   {
      item.disabled = true;
      item.className = 'webAppButtonDisabled';
   }
}

function rc_countChecked(element)
{
   var count = 0;
   var inputs = element.getElementsByTagName('input');
   if (inputs == null)
      return 0;
   for (var i = 0; i < inputs.length; i ++)
     if (inputs[i].type == 'checkbox')
        if (inputs[i].checked == true)
           count ++;
   return count;
}

function rc_setSelectedIndex(index)
{
   var tabSelectedHidden = $get('tabSelectedIndex');

   this.href = this.href.replace(/tabSelectedIndex=(\d)/, 'tabSelectedIndex=' + tabSelectedHidden.value);
}

function openCloseMessage(blockId, headerId, openMsg, closeMsg, imageId, imagePath)
{
   if ( $("#" + blockId).is(":hidden")) 
   {
      $("#" + blockId).slideDown("normal");
      $("#" + headerId).text(closeMsg);
      $("#" + imageId).attr("src", imagePath + "images/collapse.jpg");
      if ( typeof(pageTracker) != "undefined" )
      {
         pageTracker._trackEvent("Clicks", "SS View Messages");
      }
   } 
   else 
   {
      $("#" + blockId).slideUp("normal");
      $("#" + headerId).text(openMsg);
      $("#" + imageId).attr("src", imagePath + "images/expand.jpg");
      if ( typeof(pageTracker) != "undefined" )
      {
         pageTracker._trackEvent("Clicks", "SS Hide Messages");
      }
   }
}

function onSearchClicked(id, formatString)
{
   var searchTextValue = $get(id).value;
   
   searchTextValue = encodeURIComponent(searchTextValue);   

   window.location.href = String.format(formatString, searchTextValue);
}

function dropDownClick()
{

if ( $(".dropDown_body").is(":hidden"))
{
    $(".dropDown").css("height", "231px");
    $(".dropDown_body").show();    
}
else
{
   $(".dropDown").css("height", "17px");
   $(".dropDown_body").hide();
}
}

function swc_LinkClick(ID,dropText)
{
   document.getElementById(ID).innerHTML = dropText;
}

function taf_EmptyFields(email, first, last, friendEmail)
{
if(rc_isBlank(email.value) || rc_isBlank(first.value) || rc_isBlank(last.value) || rc_isBlank(friendEmail.value))
{
 alert("Please make sure that you have entered all required fields (marked with '*').");
 return false;
}
else
   return true;
}

function pr_ConfDropDownHide()
{
   $(".infoAddedDropDown").stop().slideUp("fast");
}

function pr_ConfDropDownShow(id)
{
   $("#" + id).slideDown("normal").fadeTo(3000, 1).slideUp("fast");
}

function showUSPSDetails()
{
   $(".uspsReportBlock").slideDown("fast");
}

function closeUSPSDetails()
{
   $(".uspsReportBlock").slideUp("fast");
}