// JS FILE FOR en2ru



	window.onload = OnLoad;

	function OnLoad(){
		AlignFooterwrap();
		AddSpecialStyles();
		DropdownAlphabeticSorting();
	}

	function AlignFooterwrap()
	{
		try{
			var iMainContentWrap 			= $('#ctl00_maincontentwrap')[0];
			var eOverlayMenuOuterElement 	= $('#sidebaroverlaymenuouterwrap')[0] ;
			var eOerlayContent			 	= $('#sidebaroverlaycontentwrap')[0] ;
			var eCenterPanelElement 		= $('.master_pagebody_maintable')[0];
			var eSidebarOverlay				= $('#sidebaroverlaywrap')[0] ;
			
			if(!iMainContentWrap || !eOverlayMenuOuterElement || !eOerlayContent || !eSidebarOverlay) {
				return;
			}
			
			var iMainContentWrapOT    = GetObjCoordsIE6(iMainContentWrap).y;
			var iSidebarOverlayOT     = GetObjCoordsIE6(eSidebarOverlay).y;
			var iCenterPanelElementOT = GetObjCoordsIE6(eCenterPanelElement).y;
			
			var iSideMenuHeight    =  eOverlayMenuOuterElement.offsetHeight - (iMainContentWrapOT - eSidebarOverlayOT )  
										+ eOerlayContent.offsetHeight;
				
			var msie = 'Microsoft Internet Explorer';
			if (navigator.appName == msie){
				  iMainContentWrapOT =iMainContentWrapOT  +  35;
			}
			
					
			var iCenterPanelHeight = eCenterPanelElementOT + eCenterPanelElement.offsetHeight;
			
			if(	iSideMenuHeight > iCenterPanelHeight){
				var newTop = eSidebarOverlayOT + eSidebarOverlay.offsetHeight + 20;
				$('#ctl00_footerwrap').css('top', newTop);
			}else{
				var newTop = eCenterPanelElementOT + eCenterPanelElement.offsetHeight + 20;
				$('#ctl00_footerwrap').css('top', newTop);
			}
		}catch(e){
			// ignore
		}
	}
	
	
//-----------------------------------------------------------------------------
function AddSpecialStyles ()
//-----------------------------------------------------------------------------
{	
	try {
		var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') != -1;
		var isSafari  = navigator.userAgent.toLowerCase().indexOf('safari') != -1;
		var isMac 	  = navigator.appVersion.indexOf("Mac") != -1;
		var sStyle	  = ".searchboxnavigationfirstli {background:transparent url(/_basethemes/atp_default/images/searchboxnav/center.png) repeat-x scroll 0 5px !important;}"
					+ ".searchboxnavigationli {background:transparent url(/_basethemes/atp_default/images/searchboxnav/center.png) repeat-x scroll 0 5px !important;}"
					+ ".searchboxnavigationhilitemedia {top:-1px !important;}"
					+ ".searchboxnavigationitemlink {top:-5px !important;}"
					+ ".searchboxnavigationleftimage {padding:18px 3px 2px 0 !important;}"
					+ ".searchcontrolswrap {top:-28px  !important;}"
					+ ".searchboxtextbox {height:21px !important; max-height:21px !important; min-height:21px !important; top:3px !important;}"
					+ ".searchboxgobutton {top:4px !important;}"
					+ ".searchboxnavigationul{right:232px !important;}";
					
		if(isFirefox && !isMac) {
			var oStyle  = document.createElement('style'); 
			var content = document.createTextNode(sStyle); 
			var head    = document.getElementsByTagName('head').item(0); 

			oStyle.appendChild(content); 
			oStyle.type = 'text/css'; 
			oStyle.defer = false; 
			head.appendChild(oStyle); 
		}
		if(isSafari && isMac) {
			sStyle		= ".searchcontrolswrap {top:-21px  !important;}";
			var oStyle  = document.createElement('style'); 
			var content = document.createTextNode(sStyle); 
			var head    = document.getElementsByTagName('head').item(0); 

			oStyle.appendChild(content); 
			oStyle.type = 'text/css'; 
			oStyle.defer = false; 
			head.appendChild(oStyle); 
		}
				
	}catch(e) {
		// Ignore this exception
	}
		try {
		var isIE8 = navigator.userAgent.toLowerCase().indexOf('msie 8') != -1;
		
		if(isIE8) {
			var oHead 	= document.getElementsByTagName('head')[0];
			var oStyle	= document.createElement ("style");
			
			oStyle.setAttribute('type', 'text/css');
			oStyle.styleSheet.cssText = "   .stouchbutton{"
										+ "		background: url(/_basethemes/atp_default/images/forms/btn_bg_74x26.jpg) no-repeat 5px center !important;"
										+ " 	width:80px ;"
										+ " } "
										+ " .stouchtitlefieldwrap {	"
										+ "		margin:0 0 0 19px !important;  "
										+ " } ";	
										
			oHead.appendChild (oStyle);
		}
	}catch(e) {
		// Ignore this exception
	}

} // AddSpecialStyles

//-----------------------------------------------------------------------------
function DropdownAlphabeticSorting ()
//-----------------------------------------------------------------------------
{
	var $dd = $('select[id*="Country"]'); // sort 'country'dropdowns only
	$dd.each(function(i, val) {    
		var $options = $('option', val);
		var arrVals = [];
		$options.each(function(){
        // push each option value and text into an array
			arrVals.push({
				val: $(this).val(),
				text: $(this).text()
			});
		});
		
		arrVals.sort(function(a, b){
			if(a.text>b.text){
				return 1;
			}
			else if (a.text==b.text){
				return 0;
			}
			else {
				return -1;
			}
		});
		
		for (var i = 0, l = arrVals.length; i < l; i++) {
			$($options[i]).val(arrVals[i].val).text(arrVals[i].text);
		}
		
	});
} // DropdownAlphabeticSorting

//-----------------------------------------------------------------------------
function GetObjCoordsIE6(element) 
//-----------------------------------------------------------------------------
{
    var res = new Object();
    res.x = 0; res.y = 0;
    if (element !== null) {
        res.x = element.offsetLeft;
        res.y = element.offsetTop;
        var offsetParent = element.offsetParent;
        while (offsetParent !== null) {
            res.x += offsetParent.offsetLeft + offsetParent.clientLeft;
            res.y += offsetParent.offsetTop + offsetParent.clientTop;

            if (offsetParent != document.body && offsetParent != document.documentElement) {
                res.x -= offsetParent.scrollLeft;
                res.y -= offsetParent.scrollTop;
            }
            offsetParent = offsetParent.offsetParent;
        }
    }
    return res;
} // GetObjCoordsIE6


