function trim(s) {
	return s.replace(/^\s+/, '').replace(/\s+$/, '');
}

function ShowLoginError(DivError, DivLogin, DivPassword, ErrorCssClass, DivErrorDefaultContent, DivErrorDefaultContent2)
{
	MyDiv = document.getElementById(DivError);

	if (MyDiv != null)
	{
		content = trim(MyDiv.innerHTML);

		if (content != DivErrorDefaultContent && content != DivErrorDefaultContent2)
		{
			emailDiv = document.getElementById(DivLogin);
			passwordDiv = document.getElementById(DivPassword);

			emailDiv.className+= ErrorCssClass;
			passwordDiv.className+= ErrorCssClass;
		}
	}
}

function enableStates(StateDropDownName, CountryDropDownName, DivId)
{
	StateDropDown = GetElementsByName(StateDropDownName);
	CountryDropDown = GetElementsByName(CountryDropDownName);
	MyDiv = document.getElementById(DivId);

	if (MyDiv != null)
	{
		if (CountryDropDown[0].value == 'US')
		{		
			MyDiv.style.visibility = 'visible';
			StateDropDown[0].disabled = false;
		} 
		else 
		{
			MyDiv.style.visibility = 'hidden';
			StateDropDown[0].disabled = true;
			StateDropDown[0].selectedIndex = 0;
		}
	}
}

function GetElementsByName(SearchName)
{
	var MainForm = document.forms[0];
	var ResultElements = new Array();

	for(i=0; i < MainForm.elements.length; i++)
	{
		if (MainForm.elements[i].name.indexOf(SearchName) != -1)
			ResultElements.push(MainForm.elements[i]);
	}
	return ResultElements;
}

function SetClassToControl(className, controlName)
{
    Controls = GetElementsByName(controlName);

    if (Controls != null)
    {
        for (i=0; i < Controls.length; i++)
        {
            Controls[i].className = className;
        }
    }
}

function changeDisplay(divId, newDisplay)
{
	myPopup = document.getElementById(divId);

	if (myPopup != null)
		myPopup.style.display= newDisplay;
}

function showLayer(layerId)
{
    myDiv = document.getElementById(layerId);
    myDiv.style.display='block';
    $('#' + layerId).animate( {left: 0}, 1500 );
}

function showLayer2(layerId, leftValue)
{
    myDiv = document.getElementById(layerId);
    myDiv.style.display='block';
    $('#' + layerId).animate( {left: leftValue}, 1500 );
}

function hideLayer(layerId)
{
    myDiv = document.getElementById(layerId);
    myDiv.style.display='none';
}


function setElementHeight (id, myTop, myMarginTop)
{
    document.getElementById(id).style.marginTop = myMarginTop;
    document.getElementById(id).style.top = myTop;
}

function setElementWidth (id, myLeft, myMarginLeft)
{
    document.getElementById(id).style.marginLeft = myMarginLeft;
    document.getElementById(id).style.left = myLeft;
}

function resize ()
{
    var windowWidth;
    var windowHeight;
    
    var A;
    if(self.innerWidth!=undefined)
    {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }
    else{
        var D = document.documentElement;
        windowWidth = D.clientWidth;
        windowHeight = D.clientHeight;
    }
    
    if (windowWidth > 966)
        setElementWidth ('bale-mainContainer', ((windowWidth - 966) / 2)+'px', '0px');
    else
        setElementWidth ('bale-mainContainer', '0px', '5px');
        
    
    if(windowHeight < 562){
        setElementHeight ('bale-mainContainer', '0px', '5px');	
    }else{
	    setElementHeight ('bale-mainContainer', '50%', '-290px');
    }    
}