/* ------------------------------------------------------------------------------ */
/* Copyright Sentido Virtual - http://www.sentidovirtual.com.br ----------------- */
/* contato@sentidovirtual.com.br ------------------------------------------------ */
/* ------------------------------------------------------------------------------ */



window.defaultStatus="Silvia Carlos - confeitaria artística"



/* ------------------------------------------------------------------------------ */
/* Abre janela PopUp ------------------------------------------------------------ */
/* ------------------------------------------------------------------------------ */
function OpenUp(resenha, w, h)
{
	remote = window.open(resenha,'comentario','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,menubar=no,width='+ w + ',height='+ h + '')
}



/* ------------------------------------------------------------------------------ */
/* Verifica campo vazio em formulário ------------------------------------------- */
/* ------------------------------------------------------------------------------ */
function isFieldBlank(theField)
{
	inStr = theField.value;
	inLen = inStr.length;
	for(var i = 0; i < inLen; i++)
	{
		var ch = inStr.substring(i, i+1)
		if (ch != " ")
		return false;   
	}
	theField.Value = "";
	return true;
}



/* ------------------------------------------------------------------------------ */
/* restringe somente caracteres numéricos  -------------------------------------- */
/* ------------------------------------------------------------------------------ */
function key()
{
	theKey = event.keyCode;
	if ((theKey < 48) ||
	(theKey > 57))
	event.returnValue = false;
}



/* ------------------------------------------------------------------------------ */
/* função utilizada em formulário para aceitar somente entrada de números ------- */
/* ------------------------------------------------------------------------------ */
function soNumero(event)
{
	iKey = KeyStroke( event );
	if (!( ( iKey>47 && iKey<58 ) || iKey == 13 || iKey == 0 || iKey == 8 ) )
	{
		return false;
	}
	return true;
}

function KeyStroke( event )
{
	ikey = 0;
	if( event.which == undefined )
	{
		ikey = window.event.keyCode;
	}
	else
	{
		ikey = event.which;
	}
	return ikey;
}



/* ------------------------------------------------------------------------------ */
/* função utilizada para 'saltar' os campos quando o maxlength é atingido ------- */
/* ------------------------------------------------------------------------------ */
function DFchangeField(o,e) {
	if(window.event)key=window.event.keyCode;
	else if(e)key=e.which;
	else return true;
	if (key==9||key==2||key==16) return false;
	// Vai
	if(o.value.length==o.maxLength){
  		for(var i=0;i<o.form.length;i++){
			if(o.form[i]==o && o.form[i+1]){
	    		if (!o.form[i+1].disabled && o.form[i+1].type != "hidden" && o.form[i+1].style.display != "none") {
					o.form[i+1].focus();
					return true;
				}else{
					return false;
				}
	    	}
		}
	}
	// Volta
	if(o.value.length == 0 && key == 8){
  		for(var i=0;i<o.form.length;i++){
    		if(o.form[i]==o && o.form[i-1]){
				if (!o.form[i-1].disabled && o.form[i-1].type != "hidden" && o.form[i+1].style.display != "none") {
					setTimeout("document." + o.form.name + "[" + (i-1) +"].focus()",10);
    				o.form[i-1].value = o.form[i-1].value;
    				return;
    			}else{
					return;
				}
			}
		}
	}
}



/* ------------------------------------------------------------------------------ */
/* função utilizada no calendário com ajax -------------------------------------- */
/* ------------------------------------------------------------------------------ */
var xmlhttp;
function getAjax(Metodo, Endereco, Funcao, Parametros){
	xmlhttp = getObjAjax();
	if(xmlhttp != null || Endereco.length > 0){

		xmlhttp.onreadystatechange = Funcao;
		if(Metodo=="post" && !Parametros==false && Parametros!= ""){
			xmlhttp.open("POST", Endereco, true);
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
			xmlhttp.send(Parametros);
		}else{
			xmlhttp.open("GET", Endereco, true);
			xmlhttp.send(null);
		}
	}
}

function getObjAjax(){
	objXML = null;
	var arrXml = new Array(
	'Msxml2.XMLHTTP.5.0',
	'Msxml2.XMLHTTP.4.0',
	'Msxml2.XMLHTTP.3.0',
	'Msxml2.XMLHTTP',
	'Microsoft.XMLHTTP');
	try {
		objXML = new XMLHttpRequest();
	} catch (e) {
		for (var i = 0; i < arrXml.length; i++) {
			try {
				objXML = new ActiveXObject(arrXml[i]);
			} catch (ee) {
				objXML = null;
			}
		}
	}
	return objXML;
}

function printById(id,texto){
	document.getElementById(id).innerHTML = texto;
}
	
function chamarCalendario(mes,ano,op){
	getAjax('get', 'ajax_calendario.asp?op='+op+'&m='+mes+'&a='+ano, chamarCalendario_fun);
}

function chamarCalendario_fun(){
	if(xmlhttp.readyState==4){ 
		if(parseInt(xmlhttp.status)==200){ 
			$('calendario_box').innerHTML = xmlhttp.responseText;
		}else{
			$('calendario_box').innerHTML = 'Não foi possível carregar o calendário';
		}
	}else{
		$('calendario_box').innerHTML = '<br><br><center><img src=\'img_geral/loading.gif\'><br><br>Carregando...</center><br><br>';
	}
}


function pick(data_sel)
{
	var ficha = window.opener.document.cadastroform;
	ficha.retiraem.value = data_sel;
	window.close();
}



/* ------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------ */