function confirma(msg)
{
	if(confirm(msg))
		return true;
	return false;
}

function resetForm(frm)
{
	var inputs = frm.getElementsByTagName("input");
	for(i=0;i<inputs.length;i++)
		if(inputs[i].type == "text")
			inputs[i].value = "";
}

function submitForm(frm)
{
	if(frm.chk.checked)
		frm.submit();
	else
		alert("Tem que concordar com as condições...'");
}

function passwordMatch(pass1, pass2)
{
	if(pass1 == pass2)
		return true;
	else
		return false;
}

function validaEmail(email)
{
	var reg = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	if(reg.test(email))
		return true;
	return false;
}

function validaTelf()
{
	var reg = /^\d{9}$/;
	if(reg.test(str))
		return true;
	return false;
}

function validaString(str)
{
	var reg = /\w/;
	if(reg.test(str))
		return true;
	return false;
}

function validaInt3(str)
{
	var reg = /^\d{3}$/;
	if(reg.test(str))
		return true;
	return false;
}

function validaInt4(str)
{
	var reg = /^\d{4}$/;
	if(reg.test(str))
		return true;
	return false;
}

function validaInt9(str)
{
	var reg = /^\d{9}$/;
	if(reg.test(str))
		return true;
	return false;
}

function url_encode(str)
{
   var hex_chars = "0123456789ABCDEF";
   var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
   var n, strCode, hex1, hex2, strEncode = "";

   for(n = 0; n < str.length; n++) {
       if (noEncode.test(str.charAt(n))) {
           strEncode += str.charAt(n);
       } else {
           strCode = str.charCodeAt(n);
           hex1 = hex_chars.charAt(Math.floor(strCode / 16));
           hex2 = hex_chars.charAt(strCode % 16);
           strEncode += "%" + (hex1 + hex2);
       }
   }
   return strEncode;
}

function url_decode(str) {
   var n, strCode, strDecode = "";

   for (n = 0; n < str.length; n++) {
       if (str.charAt(n) == "%") {
           strCode = str.charAt(n + 1) + str.charAt(n + 2);
           strDecode += String.fromCharCode(parseInt(strCode, 16));
           n += 2;
       } else {
           strDecode += str.charAt(n);
       }
   }

   return strDecode;
}
//pickup list
function move(fbox, tbox) {
	     var arrFbox = new Array();
	     var arrTbox = new Array();
	     var arrLookup = new Array();
	     var i;
	     for(i=0; i<tbox.options.length; i++) {
	          arrLookup[tbox.options[i].text] = tbox.options[i].value;
	          arrTbox[i] = tbox.options[i].text;
	     }
	     var fLength = 0;
	     var tLength = arrTbox.length
	     for(i=0; i<fbox.options.length; i++) {
	          arrLookup[fbox.options[i].text] = fbox.options[i].value;
	          if(fbox.options[i].selected && fbox.options[i].value != "") {
	               arrTbox[tLength] = fbox.options[i].text;
	               tLength++;
	          } else {
	               arrFbox[fLength] = fbox.options[i].text;
	               fLength++;
	          }
	     }
	     arrFbox.sort();
	     arrTbox.sort();
	     fbox.length = 0;
	     tbox.length = 0;
	     var c;
	     for(c=0; c<arrFbox.length; c++) {
	          var no = new Option();
	          no.value = arrLookup[arrFbox[c]];
	          no.text = arrFbox[c];
	          fbox[c] = no;
	     }
	     for(c=0; c<arrTbox.length; c++) {
	     	var no = new Option();
	     	no.value = arrLookup[arrTbox[c]];
	     	no.text = arrTbox[c];
	     	tbox[c] = no;
	     }
	}

	function selectAll(box) {
	     for(var i=0; i<box.length; i++) {
	     	box[i].selected = true;
	     }
	}

	function selectAllduplex(boxa,boxb) {
	     for(var i=0; i<boxa.length; i++) {
	     boxa[i].selected = true;
	     }
		  for(var i=0; i<boxb.length; i++) {
	     boxb[i].selected = true;
	     }
	}
	
	function sh(ths){
		var sh_obj;
		if(window.event)		
			sh_obj = ths.nextSibling;
		else
			sh_obj = ths.nextSibling.nextSibling;		
	
		if(sh_obj.style.display == "block")
			sh_obj.style.display = "none";
		else
			sh_obj.style.display = "block";
			
		var img = ths.firstChild;
		var img_str = img.src;
		var arr = img_str.split("/");
		var file_name = (arr[arr.length -1]); 
		var arr2 = file_name.split(".");
		var name = arr2[0];
		var image = "";
		for(i=0;i<arr.length-1;i++)
		{
			image += arr[i] + "/";
		}
		if(name == "plus")
		{
			img.title = "Minimizar";
			image += "minus.gif";
		}
		else
		{
			img.title = "Maximizar";
			image += "plus.gif";
		}
		img.src = image;
	}

	function serializeSelectBox(box)
	{
		var arr = new Array();
		for(i=0;i<box.options.length;i++)
			arr[i] = box.options[i].value;
		//retorna uma string separada por virgulas
		return arr.join(",");
	}