function selectUnselectMatchingOptions(obj,regex,which){if(window.RegExp){if(which == "select"){var selected1=true;var selected2=false;}else if(which == "unselect"){var selected1=false;var selected2=true;}else{return;}var re = new RegExp(regex);for(var i=0;i<obj.options.length;i++){if(re.test(obj.options[i].text)){obj.options[i].selected = selected1;}else{if(only == true){obj.options[i].selected = selected2;}}}}}
function selectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"select",false);}
function selectOnlyMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"select",true);}
function unSelectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"unselect",false);}
function sortSelect(obj){var o = new Array();if(obj.options==null){return;}for(var i=0;i<obj.options.length;i++){o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;}if(o.length==0){return;}o = o.sort(
function(a,b){if((a.text+"") <(b.text+"")){return -1;}if((a.text+"") >(b.text+"")){return 1;}return 0;});for(var i=0;i<o.length;i++){obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);}}
function selectAllOptions(obj){for(var i=0;i<obj.options.length;i++){obj.options[i].selected = true;}}
function moveSelectedOptions(from,to){if(arguments.length>3){var regex = arguments[3];if(regex != ""){unSelectMatchingOptions(from,regex);}}for(var i=0;i<from.options.length;i++){var o = from.options[i];if(o.selected){to.options[to.options.length] = new Option( o.text, o.value, false, false);}}for(var i=(from.options.length-1);i>=0;i--){var o = from.options[i];if(o.selected){from.options[i] = null;}}if((arguments.length<3) ||(arguments[2]==true)){sortSelect(from);sortSelect(to);}from.selectedIndex = -1;to.selectedIndex = -1;}
function copySelectedOptions(from,to){var options = new Object();for(var i=0;i<to.options.length;i++){options[to.options[i].value] = to.options[i].text;}for(var i=0;i<from.options.length;i++){var o = from.options[i];if(o.selected){if(options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text){to.options[to.options.length] = new Option( o.text, o.value, false, false);}}}if((arguments.length<3) ||(arguments[2]==true)){sortSelect(to);}from.selectedIndex = -1;to.selectedIndex = -1;}
function moveAllOptions(from,to){selectAllOptions(from);if(arguments.length==2){moveSelectedOptions(from,to);}else if(arguments.length==3){moveSelectedOptions(from,to,arguments[2]);}else if(arguments.length==4){moveSelectedOptions(from,to,arguments[2],arguments[3]);}}
function copyAllOptions(from,to){selectAllOptions(from);if(arguments.length==2){copySelectedOptions(from,to);}else if(arguments.length==3){copySelectedOptions(from,to,arguments[2]);}}
function swapOptions(obj,i,j){var o = obj.options;var i_selected = o[i].selected;var j_selected = o[j].selected;var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);o[i] = temp2;o[j] = temp;o[i].selected = j_selected;o[j].selected = i_selected;}
function moveOptionUp(obj){for(i=0;i<obj.options.length;i++){if(obj.options[i].selected){if(i != 0 && !obj.options[i-1].selected){swapOptions(obj,i,i-1);obj.options[i-1].selected = true;}}}}
function moveOptionDown(obj){for(i=obj.options.length-1;i>=0;i--){if(obj.options[i].selected){if(i !=(obj.options.length-1) && ! obj.options[i+1].selected){swapOptions(obj,i,i+1);obj.options[i+1].selected = true;}}}}
function removeSelectedOptions(from){for(var i=(from.options.length-1);i>=0;i--){var o=from.options[i];if(o.selected){from.options[i] = null;}}from.selectedIndex = -1;}
function removeAllOptions(from){for(var i=(from.options.length-1);i>=0;i--){from.options[i] = null;}from.selectedIndex = -1;}
function addOption(obj,text,value,selected){if(obj!=null && obj.options!=null){obj.options[obj.options.length] = new Option(text, value, false, selected);}}

function verificaData(Data)
 {
  var dma = -1;
  var data = Array(3);
  var ch = Data.charAt(0); 
  for(i=0; i < Data.length && (( ch >= '0' && ch <= '9' ) || ( ch == '/' && i != 0 ) ); ){
   data[++dma] = '';
   if(ch!='/' && i != 0) return false;
   if(i != 0 ) ch = Data.charAt(++i);
   if(ch=='0') ch = Data.charAt(++i);
   while( ch >= '0' && ch <= '9' ){
    data[dma] += ch;
    ch = Data.charAt(++i);
   } 
  }
  if(ch!='') return false;
  if(data[0] == '' || isNaN(data[0]) || parseInt(data[0]) < 1) return false;
  if(data[1] == '' || isNaN(data[1]) || parseInt(data[1]) < 1 || parseInt(data[1]) > 12) return false;
  if(data[2] == '' || isNaN(data[2]) || ((parseInt(data[2]) < 0 || parseInt(data[2]) > 99 ) && (parseInt(data[2]) < 1900 || parseInt(data[2]) > 9999))) return false;
  if(data[2] < 50) data[2] = parseInt(data[2]) + 2000;
  else if(data[2] < 100) data[2] = parseInt(data[2]) + 1900;
  switch(parseInt(data[1])){
   case 2: { if(((parseInt(data[2])%4!=0 || (parseInt(data[2])%100==0 && parseInt(data[2])%400!=0)) && parseInt(data[0]) > 28) || parseInt(data[0]) > 29 ) return false; break; }
   case 4: case 6: case 9: case 11: { if(parseInt(data[0]) > 30) return false; break;}
   default: { if(parseInt(data[0]) > 31) return false;}
  }
  return true; 
 }

function CheckAll(objRefer, diferente, form) {
	var fmobj = form;
	for (var i=0;i<fmobj.elements.length;i++) {
		var e = fmobj.elements[i];
		if ((e.name != diferente) && (e.type=='checkbox') && (!e.disabled) && (e.name != 'seleciona_todos') && (e.name != 'select_all')) {
			e.checked = objRefer.checked;
		}
	}
}

function MudaCor(CB,cor,cor2) {
	if (CB.checked)
		hL(CB,cor);
	else
		dL(CB,cor2);
}
function hL(E,cor){
	ie = document.all;
	if (ie)
	{
		while (E.tagName!="TR")
			{E=E.parentElement;}
	}
	else {
		while (E.tagName!="TR")
			{E=E.parentNode;}
	}
	E.bgColor = cor;
}
function dL(E,cor){
	ie = document.all;
	if (ie)
	{
		while (E.tagName!="TR")
			{E=E.parentElement;}
	}
	else{
		while (E.tagName!="TR")
			{E=E.parentNode;}
	}
	E.bgColor = cor;
}


var currRow = -1;
var selRow = -1;
function onTrocaBg(obj,bgcolor) {
	if(obj.bgColor.toLowerCase() != "") return;
	else obj.bgColor = bgcolor.toLowerCase();
}
function outTrocaBg(obj,bgcolor,bgcolor2) {
	if(obj.bgColor.toLowerCase() == bgcolor.toLowerCase()) obj.bgColor = bgcolor2.toLowerCase();
}
function clickTrocaBg(obj,bgcolor) {
/*	for(i = 0; i < form1.checkbox.length; i++) {
		if(form1.checkbox[i].checked) return;
	}
*/
	srcElem = window.event.srcElement;
	while (srcElem.tagName != "TR" && srcElem.tagName != "TABLE")
		srcElem = srcElem.parentElement;
	if(srcElem.tagName != "TR") return;
	if(srcElem.rowIndex == 0 ) return;
	if (selRow != -1) selRow.runtimeStyle.backgroundColor = '';
	srcElem.runtimeStyle.backgroundColor = bgcolor;
	selRow = srcElem;
}

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject


function abreImagemNew(urlImg,Largura,Altura,tipoJan) {
	imgOpen = window.open("",
	"ImgOpen",
	"toolbar=no,width=" + Largura + ",height=" + Altura + ",directories=no,status=no,scrollbars=no,resize=yes,menubar=no");
	with (imgOpen.document) { 
		writeln ("<html>");
		writeln ("<head>");
		writeln ("<title>[ " + tipoJan + " ] - CÂMARA DE COMÉRCIO E INDÚSTRIA BRASIL-ALEMANHA</title>");
		writeln ("</head>");
		writeln ("<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onLoad=\"Janela();\">");
		writeln ("<img src='" + urlImg + "' name='img' border='0' onClick='self.close();' alt='Clique na imagem para fechar a janela'>");
		writeln ("</body>");
		writeln ("</html>");
		writeln ("<script language=\"JavaScript\">");
		writeln ("function Janela() {");
		writeln ("//if(document.images[0].complete) {");
		writeln ("	var isNav4, isIE4;");
		writeln ("	isNav4 = (navigator.appName == \"Netscape\") ? 1 : 0;");
		writeln ("	isIE4 = (navigator.appName.indexOf(\"Microsoft\") != -1) ? 1 : 0;");
		writeln ("	if (isNav4) {");
		writeln ("		window.resizeTo(document.images[0].width,document.images[0].height);");
		writeln ("	}");
		writeln ("	");
		writeln ("	if (isIE4) {");
		writeln ("		window.resizeTo(document.images[0].width,document.images[0].height);");
		writeln ("	}");
		writeln ("}");
		writeln ("//}");
		writeln ("</script>");
	}
}
function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
	  return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
	  while (temp.indexOf(fromString) != -1) {
		 var toTheLeft = temp.substring(0, temp.indexOf(fromString));
		 var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
		 temp = toTheLeft + toString + toTheRight;
	  }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
	  var midStrings = new Array("~", "`", "_", "^", "#");
	  var midStringLen = 1;
	  var midString = "";
	  // Find a string that doesn't exist in the inputString to be used
	  // as an "inbetween" string
	  while (midString == "") {
		 for (var i=0; i < midStrings.length; i++) {
			var tempMidString = "";
			for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
			if (fromString.indexOf(tempMidString) == -1) {
			   midString = tempMidString;
			   i = midStrings.length + 1;
			}
		 }
	  } // Keep on going until we build an "inbetween" string that doesn't exist
	  // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
	  while (temp.indexOf(fromString) != -1) {
		 var toTheLeft = temp.substring(0, temp.indexOf(fromString));
		 var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
		 temp = toTheLeft + midString + toTheRight;
	  }
	  // Next, replace the "inbetween" string with the "toString"
	  while (temp.indexOf(midString) != -1) {
		 var toTheLeft = temp.substring(0, temp.indexOf(midString));
		 var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
		 temp = toTheLeft + toString + toTheRight;
	  }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function
function TrocaArroba(l) {
	linkNew = replaceSubstring(l,"(a)","@");
	//alert(linkNew);
	window.open(linkNew,'mail','');
}
function SoNumeros() {
	<!-- 46 = , 44 = . -->
	if ( (event.keyCode < 48 && event.keyCode != 8 && event.keyCode != 13 && event.keyCode != 46 && event.keyCode != 44) || event.keyCode > 57 && event.keyCode != 13 && event.keyCode != 46 && event.keyCode != 44) {
		event.keyCode = 0;
		event.returnValue=false; 
	}
}
function ValidaData(str) {
	splitData = str.split("/");
	dia = parseInt(splitData[0]);
	mes = parseInt(splitData[1]);
	ano = parseInt(splitData[2]);
	erroData = true;
	diaFev = (((ano % 4 == 0) && ((!(ano % 100 == 0)) || (ano % 400 == 0))) ? 29 : 28 );
	if(dia > diaFev && mes == 2) erroData = false;
	else if(dia > 30 && (mes == 4 || mes == 6 || mes == 9 || mes == 11)) erroData = false;
	return erroData;
}
function LimparDados(form,campo) {
	if(confirm("Deseja realmente limpar os campos do formulário?")) {
		for(i = 0; i < document.form.length; i++) {
			if(document.form.elements[i].type != "button" && document.form.elements[i].type != "reset" && document.form.elements[i].type != "submit" && document.form.elements[i].type != "checkbox" && document.form.elements[i].type != "radio") {
				form.elements[i].className = 'campo';
			}
		}
		campo.focus();
		return true;
	}
	else {
		return false;
	}
}
function validaemail(EmailText) {
	if ((EmailText.search(/;/i) == -1) &&
		(EmailText.search(/,/i) == -1) &&
		(EmailText.indexOf("..") == -1) &&
		(EmailText.indexOf(".@") == -1) &&
		(EmailText.indexOf("@.") == -1) &&
		(EmailText.search(/ /i) == -1) &&
		(EmailText.search(/"/i) == -1) &&
		(EmailText.search(/'/i) == -1) &&
		(EmailText.indexOf("^") == -1) &&
		(EmailText.search(/`/i) == -1) &&
		(EmailText.search(/~/i) == -1) &&
		(EmailText.search(/ç/i) == -1) &&
		(EmailText.length != 0) &&
		(EmailText.search(/@/i) >= 1) &&
		(EmailText.substr(0,1) != ".") && /*Não pode começar com ponto*/
		(EmailText.substr(EmailText.length-1) != ".") && /*Não pode terminar com ponto*/
		(EmailText.indexOf("hotmail.com.br") == -1) &&
		(EmailText.indexOf("@aol.com.br") == -1))
		return true;
	else if (EmailText.indexOf("hotmail.com.br") >= 0)
		{
//		alert("Atenção: O E-mail HOTMAIL não termina com .BR\nEle será automaticamente corrigido");
		return false;
		}
	else if (EmailText.indexOf("aol.com.br") >= 0)
		{
//		alert("Atenção: O E-mail AOL não termina com .BR\nEle será automaticamente corrigido");
		return false;
		}
	else if (EmailText.indexOf(" ") >= 0)
		{
/*		alert("Atenção: O E-mail não deve conter espaços em branco\nEle será automaticamente corrigido");
		while(EmailText.indexOf(" ") >= 0)
			EmailText= EmailText.replace(" ", "");*/
		return false;
		}
	else
		{
		return false; 
		}
}
function contaCaracteres(campo, obj, qtd) {
	campoSize = campo.value.length;
	if(campoSize >= qtd) {
		campo.value = campo.value.substring(0,qtd);
		obj.innerHTML = qtd;
	}
	else if(campo.value != "") {
		obj.innerHTML = eval(campo.value.length-1) + 1;
	}
	else {
		obj.innerHTML = 0;
	}
}
 function cgc(pcgc) 
 { 
 	pcgc = pcgc.replace(".","");
	pcgc = pcgc.replace(".","");
	pcgc = pcgc.replace("-","");
	pcgc = pcgc.replace("/","");
	   // verifica o tamanho 
 if (pcgc.length != 14) { 
  sim=false 
  return false; 
  } 
 else {sim=true} 

  if (sim )  // verifica se e numero 
  { 
  for (i=0;((i<=(pcgc.length-1))&& sim); i++) 
  { 
   val = pcgc.charAt(i) 
	   // alert (val) 
   if 
((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") && 
(val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false} 
   } 
   if (sim)  // se for numero continua 
   { 
	m2 = 2 
	soma1 = 0 
	soma2 = 0 
	for (i=11;i>=0;i--) 
	{ 
	 val = eval(pcgc.charAt(i)) 
	   // alert ("Valor do Val: "+val) 
	 m1 = m2 
  if (m2<9) { m2 = m2+1} 
  else {m2 = 2} 
  soma1 = soma1 + (val * m1) 
  soma2 = soma2 + (val * m2) 
	}  // fim do for de soma 

  soma1 = soma1 % 11 
  if (soma1 < 2) {  d1 = 0} 
   else { d1 = 11- soma1} 

	 soma2 = (soma2 + (2 * d1)) % 11 
  if (soma2 < 2) { d2 = 0} 
   else { d2 = 11- soma2} 
		// alert (d1) 
	   // alert (d2) 
	if ((d1==pcgc.charAt(12)) && (d2==pcgc.charAt(13))) 
   { 
	return true;
	} 
   else return false;
   } 
 } 

 } 
 function cpf(pcpf) 
 { 
	pcpf = pcpf.replace(".","");
	pcpf = pcpf.replace(".","");
	pcpf = pcpf.replace("-","");
 if (pcpf.length != 11) {sim=false} 
 else {sim=true} 

  if (sim )  // valida o primeiro digito 
  { 
  for (i=0;((i<=(pcpf.length-1))&& sim); i++) 
  { 
   val = pcpf.charAt(i) 
   if 

 ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") 

 &&    (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false} 
   } 

   if (sim) 
  { 
	soma = 0 
	for (i=0;i<=8;i++) 
	{ 
	 val = eval(pcpf.charAt(i)) 
	 soma = soma + (val*(i+1)) 
	} 

	resto = soma % 11 
	if (resto>9) dig = resto -10 
	else  dig = resto 
	if (dig != eval(pcpf.charAt(9))) { sim=false } 
   else   // valida o segundo digito 
	{ 

	 soma = 0 
	for (i=0;i<=7;i++) 
	 { 
	 val = eval(pcpf.charAt(i+1)) 
	  soma = soma + (val*(i+1)) 
	} 

	 soma = soma + (dig * 9) 
	resto = soma % 11 
	 if (resto>9) dig = resto -10 
	 else  dig = resto 
   if (dig != eval(pcpf.charAt(10))) { sim = false } 
	else sim = true 
   } 
   } 
  } 

  if (sim) { 
  return true;
 } 
  else 
	return false;
 }
