// play sounds
function MM_controlSound(x, _sndObj, sndFile) { //v3.0
  var i, method = "", sndObj = eval(_sndObj);
  if (sndObj != null) {
    if (navigator.appName == 'Netscape') method = "play";
    else {
      if (window.MM_WMP == null) {
        window.MM_WMP = false;
        for(i in sndObj) if (i == "ActiveMovie") {
          window.MM_WMP = true; break;
      } }
      if (window.MM_WMP) method = "play";
      else if (sndObj.FileName) method = "run";
  } }
  if (method) eval(_sndObj+"."+method+"()");
  else window.location = sndFile;
}

function followLInk(urlLink){
	window.location = urlLink;
}

function mmLoadMenus() {
  if (window.mm_menu_0519110646_0) return;
  window.mm_menu_0519110646_0 = new Menu("root",143,18,"Geneva, Arial, Helvetica, sans-serif",12,"#45535C","#FFFFFF","#F3F3F3","#23191A","left","middle",3,0,1000,-5,7,true,true,true,0,true,true);
  mm_menu_0519110646_0.addMenuItem("Category","location='?section=cat_add'");
  mm_menu_0519110646_0.addMenuItem("Sub&nbsp;Category","location='?section=sub_cat_add'");
  mm_menu_0519110646_0.addMenuItem("Sub&nbsp;Sub&nbsp;Category","location='?section=subsub_cat_add'");
   mm_menu_0519110646_0.hideOnMouseOut=true;
   mm_menu_0519110646_0.bgColor='#FFFFFF';
   mm_menu_0519110646_0.menuBorder=1;
   mm_menu_0519110646_0.menuLiteBgColor='#FFFFFF';
   mm_menu_0519110646_0.menuBorderBgColor='#ECECEC';
   mm_menu_0519110646_0.cursor='pointer';
   // menu de produto
   window.mm_menu_0519110647_0 = new Menu("root",143,18,"Geneva, Arial, Helvetica, sans-serif",12,"#45535C","#FFFFFF","#F3F3F3","#23191A","left","middle",3,0,1000,-5,7,true,true,true,0,true,true);
  mm_menu_0519110647_0.addMenuItem("Single&nbsp;products","location='?section=prod_add'");
  mm_menu_0519110647_0.addMenuItem("Multi&nbsp;Insert","location='?section=prod_multi_add'");
   mm_menu_0519110647_0.hideOnMouseOut=true;
   mm_menu_0519110647_0.bgColor='#FFFFFF';
   mm_menu_0519110647_0.menuBorder=1;
   mm_menu_0519110647_0.menuLiteBgColor='#FFFFFF';
   mm_menu_0519110647_0.menuBorderBgColor='#ECECEC';
   mm_menu_0519110647_0.cursor='pointer';

mm_menu_0519110647_0.writeMenus();
} // mmLoadMenus()
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function trocaCorLinha(e) {
    corantiga = e.style.background;
	e.style.background='#DBDBDB';
}

function voltaCorLinha(e) {
	e.style.background=corantiga;
}
	
function VisualizarImagem( imagem, titulo ) {
	PositionX = 0;
	PositionY = 0;
	window.open('includes/see_image.php?imagem=' + imagem + '&title=' + titulo, '', 'resizable=1,scrollbars=no,width=100,height=100,left='+PositionX+',top='+PositionY);		
}
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    if(objTextBox.value.length < 7) {
      var sep = 0;
      var key = '';
      var i = j = 0;
      var len = len2 = 0;
      var strCheck = '0123456789';
      var aux = aux2 = '';
      var whichCode = (window.Event) ? e.which : e.keyCode;
      if (whichCode == 13) return true;
      key = String.fromCharCode(whichCode); // Valor para o código da Chave
      if (strCheck.indexOf(key) == -1) return false; // Chave inválida
      len = objTextBox.value.length;
      for(i = 0; i < len; i++)
          if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
      aux = '';
      for(; i < len; i++)
          if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
      aux += key;
      len = aux.length;
      if (len == 0) objTextBox.value = '';
      if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
      if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
      if (len > 2) {
          aux2 = '';
          for (j = 0, i = len - 3; i >= 0; i--) {
              if (j == 3) {
                  aux2 += SeparadorMilesimo;
                  j = 0;
              }
              aux2 += aux.charAt(i);
              j++;
          }
          objTextBox.value = '';
          len2 = aux2.length;
          for (i = len2 - 1; i >= 0; i--)
          objTextBox.value += aux2.charAt(i);
          objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
      }
      return false;
    }
}

MaskInput = function(f, m){ //v1.0
    function mask(e){
        var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[À-ÿ]/i, "8": /./ },
            rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && patterns[i].test(c))
                    break;
                return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
        addEvent(f, i, mask);
};
addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};
function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
function trimForm(formName) {
    var formulario = formName;
    for(i = 0; formulario.elements[i]; i++) {
        if(formulario.elements[i].type == "text" || formulario.elements[i].type == "password" || formulario.elements[i].type == "textarea")
            formulario.elements[i].value = trimAll(formulario.elements[i].value);
    }
}

function validacaoEmail(emailad){
    var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
    var check=/@[\w\-]+\./;
    var checkend=/\.[a-zA-Z]{2,3}$/;
    if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
        return false;
    }
    else {
        return true;
    }
}

//////////////////////////

// function to set the location of the cursor in a text field. May only work in IE? Intended for use with validation, not implemented at present.
function setSelRange(inputEl, selStart, selEnd) { 
 if (inputEl.setSelectionRange) { 
  inputEl.focus(); 
  inputEl.setSelectionRange(selStart, selEnd); 
 } else if (inputEl.createTextRange) { 
  var range = inputEl.createTextRange(); 
  range.collapse(true); 
  range.moveEnd('character', selEnd); 
  range.moveStart('character', selStart); 
  range.select(); 
 } 
}

// Restrict to letters, numbers & space.
function ValidateInput(id)
{
	var valueValidate = 0;
	var idValue = document.getElementById(id).value;
	if (idValue=="")
	{
		return;
	}
	else
	{
		var reg = /^[A-Za-z0-9 ]+$/; // entire string consists of these characters
		if (idValue.search(reg)!=-1) 
		{
			return;
		}
		else
		{
			var charPos = 0;
			var i = 0;
			while (charPos==0)
			{
				findPos = idValue.substr(0,i);
				if (findPos.search(reg)==-1) 
				{
					charPos = i;
				}
				i++;
			}
			alert("You entered an invalid character. Valid characters are a through z, 0 through 9, and 'space'");
			document.getElementById(id).value = idValue.substr(0, charPos-1) + idValue.substr(charPos, idValue.length -1);
		}
	}
}

// restrict only characters that might break code - eg by closing a tag
function ValidateInput2(id)
{
	var valueValidate = 0;
	var idValue = document.getElementById(id).value;
	if (idValue=="")
	{
		return;
	}
	else
	{
		var reg = /[<>{}"]/; // one of these characters is anywhere in the string
		if (idValue.search(reg)==-1) // note == compared to != in above function.
		{
			return;
		}
		else
		{
			var charPos = 0;
			var i = 0;
			while (charPos==0)
			{
				findPos = idValue.substr(0,i);
				if (findPos.search(reg)==-1) 
				{
					charPos = i;
				}
				i++;
			}
			alert("You entered an invalid character. < > {} and \" may not be used in this field.");
			document.getElementById(id).value = idValue.substr(0, charPos-1) + idValue.substr(charPos, idValue.length -1);
		}
	}
}

//check for valid #html code characters (#000 - #FFFFFF) and update display panel (Advanced style settings)
function ValidateColour(id)
{
	var valueValidate = 0;
	var idValue = document.getElementById(id).value;
	var idDisp = "display_" + id;
	if (idValue=="")
	{
		document.getElementById(idDisp).style.backgroundColor = "#FFFFFF"; 
		return;
	}
	else
	{
		var reg = /^[A-Fa-f0-9]+$/; // entire string consists of these characters
		if (idValue.search(reg)!=-1) 
		{} //continue
		else
		{
			var charPos = 0;
			var i = 0;
			while (charPos==0)
			{
				findPos = idValue.substr(0,i);
				if (findPos.search(reg)==-1) 
				{
					charPos = i;
				}
				i++;
			}
			alert("You entered an invalid character. Valid characters are A through F and 0 through 9.");
			document.getElementById(id).value = idValue.substr(0, charPos-1) + idValue.substr(charPos, idValue.length -1);
			return;
		}
		if (idValue.length != 3 && idValue.length != 6)
		{
			return;
		}
		else
		{
			document.getElementById(idDisp).style.backgroundColor = "#" + idValue; 
		}
	}
}
// check for valid # html css length - 0, 3 or 6 characters (Advanced style settings)
function ValidateLength(id)
{
	var idValue = document.getElementById(id).value;
	if (!(idValue.length == 0 || idValue.length == 3 || idValue.length == 6))
	{
		alert("Colour settings must be 0, 3 or 6 characters in length!");
		//document.getElementById(id).focus();
		var timer = setTimeout(function(){document.getElementById(id).focus(),50}); // to make it work in mozilla browsers, which change focus after the script has been run.
	}
}

// show/hide for info pages
function info_hide()
{
	sections = document.getElementsByTagName('div');
	for(i=0;i<sections.length;i++)
	{
		if (document.getElementById(sections[i].id).className == "info")
		{
			document.getElementById(sections[i].id).style.display = "none";
		}
	}
}

function info_show(id)
{
	info_hide();
	document.getElementById(id).style.display = "block";
}
