//---

/**
* mage/adminhtml/loader.js
*/
function toggleSelectsUnderBlock(block, flag){
    if(Prototype.Browser.IE){
        var selects = document.getElementsByTagName("select");
        for(var i=0; i<selects.length; i++){
            /**
             * @todo: need check intersection
             */
            if(flag){
                if(selects[i].needShowOnSuccess){
                    selects[i].needShowOnSuccess = false;
                    // Element.show(selects[i])
                    selects[i].style.visibility = '';
                }
            }
            else{
                if(Element.visible(selects[i])){
                    // Element.hide(selects[i]);
                    selects[i].style.visibility = 'hidden';
                    selects[i].needShowOnSuccess = true;
                }
            }
        }
    }
}

//---

function txtBoxFormat(objeto, sMask, evtKeyPress) {
 var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


if(document.all) { // Internet Explorer
 nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
 nTecla = evtKeyPress.which;
} else {
 nTecla = evtKeyPress.which;
 if (nTecla == 8) {
 return true;
 }
}

 sValue = objeto.value;

 // Limpa todos os caracteres de formataçãoo que
 // já estiverem no campo.
 sValue = sValue.toString().replace( "-", "" );
 sValue = sValue.toString().replace( "-", "" );
 sValue = sValue.toString().replace( ".", "" );
 sValue = sValue.toString().replace( ".", "" );
 sValue = sValue.toString().replace( "/", "" );
 sValue = sValue.toString().replace( "/", "" );
 sValue = sValue.toString().replace( ":", "" );
 sValue = sValue.toString().replace( ":", "" );
 sValue = sValue.toString().replace( "(", "" );
 sValue = sValue.toString().replace( "(", "" );
 sValue = sValue.toString().replace( ")", "" );
 sValue = sValue.toString().replace( ")", "" );
 sValue = sValue.toString().replace( " ", "" );
 sValue = sValue.toString().replace( " ", "" );
 fldLen = sValue.length;
 mskLen = sMask.length;

 i = 0;
 nCount = 0;
 sCod = "";
 mskLen = fldLen;

 while (i <= mskLen) {
 bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
 bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

 if (bolMask) {
 sCod += sMask.charAt(i);
 mskLen++; }
 else {
 sCod += sValue.charAt(nCount);
 nCount++;
 }

 i++;
 }

 if(sCod!="("){
 objeto.value = sCod;
 }

 if (nTecla != 8 && nTecla != 0) { // backspace e TAB
 if (sMask.charAt(i-1) == "9") { // apenas números...
 return ((nTecla > 47) && (nTecla < 58)); }
 else { // qualquer caracter...
 return true;
 }
 }
 else {
 return true;
 }
 }

//---

function toggleMenu(el, over)
{
    if (over) {
        Element.addClassName(el, 'over');
    }
    else {
        Element.removeClassName(el, 'over');
    }
}

//---

function plusone_vote( obj ) {
	_gaq.push(['_trackEvent','plusone',obj.state, document.location.href]);
}

//---

// This code is in the public domain. Feel free to link back to http://jan.moesen.nu/
function sprintf()
{
	if (!arguments || arguments.length < 1 || !RegExp)
	{
		return;
	}
	var str = arguments[0];
	var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
	var a = b = [], numSubstitutions = 0, numMatches = 0;
	while (a = re.exec(str))
	{
		var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
		var pPrecision = a[5], pType = a[6], rightPart = a[7];
		
		//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);

		numMatches++;
		if (pType == '%')
		{
			subst = '%';
		}
		else
		{
			numSubstitutions++;
			if (numSubstitutions >= arguments.length)
			{
				alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
			}
			var param = arguments[numSubstitutions];
			var pad = '';
			       if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
			  else if (pPad) pad = pPad;
			var justifyRight = true;
			       if (pJustify && pJustify === "-") justifyRight = false;
			var minLength = -1;
			       if (pMinLength) minLength = parseInt(pMinLength);
			var precision = -1;
			       if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
			var subst = param;
			       if (pType == 'b') subst = parseInt(param).toString(2);
			  else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
			  else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
			  else if (pType == 'u') subst = Math.abs(param);
			  else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
			  else if (pType == 'o') subst = parseInt(param).toString(8);
			  else if (pType == 's') subst = param;
			  else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
			  else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
		}
		str = leftpart + subst + rightPart;
	}
	return str;
}
//---


//---


//---

