function castGeneralErrorLib(el,ms,addFunct)
{
	alert(ms);
	if (el != undefined) { el.focus();}
	eval(addFunct);
}


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_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_findObj(n, d) { //v3.0
  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); 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 FormataLoginSenha(Obj, Campo)
{
	if ((Obj.keyCode>=48 && Obj.keyCode<=57) || (Obj.keyCode>=65 && Obj.keyCode<=90) || (Obj.keyCode>=97 && Obj.keyCode<=122))
	{
		
	}
	else Obj.keyCode = "";
}

function CaracteresValidos(Obj, Campo)
{
	if (Obj.keyCode>=35 && Obj.keyCode<=39)
	{
		alert('O caractere\n       '+String.fromCharCode(Obj.keyCode)+'\nNão é válido' );
		Obj.keyCode = "";
	}

}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function ShowDiv(sh,qual)
{
	var oDiv = document.getElementById(qual)//eval('document.all.'+qual)
	if ((sh == 'show')||(sh == 's'))
	{
		oDiv.style.display='';
	}
	else
	{
		oDiv.style.display='none';
	}
}

function ShowHide(qual)
{
	var oDiv = document.getElementById(qual);
	if (oDiv)
	{
		if (oDiv.style.display=='')
		{
			oDiv.style.display='none';
		}
		else
		{
			oDiv.style.display='';
		}
	}
}

function HideDiv(qual)
{
	var oDiv = document.getElementById(qual);
	if (oDiv)
	{
		oDiv.style.display='none';
	}
}

function FormataSenha(Obj, Campo) {
	var Senia = Campo.value;
	//Tamanho da string
	if (Senia.length<8){
		//só numeros e letras
		if ((Obj.keyCode>=48 && Obj.keyCode<=57) || (Obj.keyCode>=65 && Obj.keyCode<=90) || (Obj.keyCode>=97 && Obj.keyCode<=122)){
			switch(Senia.length){
				case 0:  
					if ((Obj.keyCode>=65 && Obj.keyCode<=90) || (Obj.keyCode>=97 && Obj.keyCode<=122)) 
				    { Senia = Senia; }
					else 
					{ alert('A senha deve comecar com letras');
					Obj.keyCode = "";}
				break;

				case 6:  
					if (Obj.keyCode>=48 && Obj.keyCode<=57) 
				    { Senia = Senia; }
					else 
					{ alert('A senha deve terminar com 2 números');
					Obj.keyCode = "";}
				break;

				case 7:  
					if (Obj.keyCode>=48 && Obj.keyCode<=57) 
				    { Senia = Senia; }
					else 
					{ alert('A senha deve terminar com 2 números');
					Obj.keyCode = "";}
				break;

			}
		}else Obj.keyCode = "";
		
	}else Senia = Senia + (Obj.keyCode = "");
				
	Campo.value = Senia;
}

function FormataCep(Obj, Campo){
	var CEP = Campo.value;
	if (CEP.length<9){
		if (Obj.keyCode>=48 && Obj.keyCode<=57){
			switch(CEP.length){
				case 5: CEP = CEP + "-"; break;
				case 9: CEP = CEP + (Obj.keyCode = ""); break;
			}
		}else Obj.keyCode = "";
	}else CEP = CEP + (Obj.keyCode = "");
	Campo.value = CEP;
}

function askExcluir(SCRIPT,ID)
{
	var excluiMesmo = confirm("Deseja realmente exlcuir este registro?\nObs.: Esta operação não poderá ser desfeita.");
	if (excluiMesmo) 
	{ 
	location.href = SCRIPT+'?Acao=Excluir&sTipo=L&ID='+ID;
	}

}

function GlobalAddNewOption(locaParent,FormField,Op,Tx,Sel,clear)
{	
	if (clear == true) GlobalClearList(locaParent,FormField)
	var df = eval(locaParent+"document."+FormField);
	var index = df.options.length;
	df[index] = new Option(Op, Tx, false, Sel);
}
function GlobalClearList(locaParent,FormField)
{
	var df = eval(locaParent+"document."+FormField);
	var index = df.options.length;
	for (i=index-1;i>=0;i--) df.options[i] = null;
}
function GlobalClearOneOption(locaParent,FormField,qual)
{
	var df = eval(locaParent+"document."+FormField);
	var index = df.options.length;
	//for (i=index-1;i>=0;i--) 
	df.options[qual] = null;
}

function FormataLogin(Obj, Campo) {
	var Logini = Campo.value;
	//Tamanho da string
	if (Logini.length<20){
		//só numeros e letras
		if ((Obj.keyCode>=48 && Obj.keyCode<=57) || (Obj.keyCode>=65 && Obj.keyCode<=90) || (Obj.keyCode>=97 && Obj.keyCode<=122) || (Obj.keyCode==46)){
			switch(Logini.length){
				case 0:  
					if ((Obj.keyCode>=65 && Obj.keyCode<=90) || (Obj.keyCode>=97 && Obj.keyCode<=122)) 
				    { Logini = Logini; }
					else 
					{ alert('O Login deve comecar com letra');
					Obj.keyCode = "";}
				break;

			}
		}else Obj.keyCode = "";
		
	}else Logini = Logini + (Obj.keyCode = "");
				
	Campo.value = Logini;
}


function ShowHide(qual)
{
	var oDiv = document.getElementById(qual);
	if (oDiv)
	{
		if (oDiv.style.display=='')
		{
			oDiv.style.display='none';
		}
		else
		{
			oDiv.style.display='';
		}
	}
}

function ShowHideAndCookie(qual, ckname ,ckvalue,ckdays)
{
	var oDiv = document.getElementById(qual);
	if (oDiv)
	{
		if (oDiv.style.display=='')
		{
			oDiv.style.display='none';
		}
		else
		{
			oDiv.style.display='';
		}

	createCookie(ckname,ckvalue,ckdays)
	}
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setaEnqueteOpcao(formObj,IDOpt)
{

	formObj.Opcao[IDOpt].checked = true;

}

