<!--

function mFocus(c,p){
	c.bgColor = p;
}

function imgFocus(c,p){
	c.background = p;
}

function closeDiv(div){
	document.getElementById(div).innerText = '';
	document.getElementById(div).style.display = 'none';
}

function abreDiv(url,par,div){
	document.getElementById(div).style.display = '';
	adm_ajax(url, 'GET', 'true', div, par);
}

function divEspere(div){
	if(document.getElementById(div)){
		document.getElementById(div).innerHTML = "<table width='100%' height='100%' border='0' cellspacing='0' cellpadding='0'><tr><td><table align='center' border='0' cellspacing='0' cellpadding='0' class='titulo'><tr><td><img src='img/ajax-loader-8.gif' hspace='6' vspace='6' /></td><td><strong><em>Aguarde...</em></strong></td></tr></table></td></tr></table>";
	}
}

function replaceAll(string, token, newtoken) {
	//txt = replaceAll(txt,' ','[nbsp]');
	while (string.indexOf(token) != -1) {
		string = string.replace(token, newtoken);
	}
	return string;
}

function openPrintBusca(id){
	var tamW = 800;
	var tamH = 500;
	var x = (window.screen.width - tamW) / 2 ;
	var y = (window.screen.height - tamH) / 2 ;
	
	id = id.split('|');
	if(id[0]>0){
		window.open('Comitente_Imprimir_Recolha.asp?id_Estoque='+id[0],'attCabec','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width='+tamW+'px,height='+tamH+'px,top='+y+',left='+x);
	}
	if(id[1]>0){
		window.open('Comitente_Imprimir_Estoque.asp?id_Estoque='+id[1],'attCabec','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width='+tamW+'px,height='+tamH+'px,top='+y+',left='+x);
	}
	
	closeBusca('Buscar');
}

function openBusca(url,div){
	if(url.split('?').length>1){
		var par = url.split('?')[1];
		var url = url.split('?')[0];
	}else{
		var par = 'pTab='+pTab;
	}
	if(url!=''){
		adm_ajax(url,'GET','true',div,par);
		document.getElementById('fundo_principal').style.display = '';
		document.getElementById(div).style.display = '';
	}
}

function closeBusca(div){
		document.getElementById('fundo_principal').innerText = '';
		document.getElementById('fundo_principal').style.display = 'none';
		document.getElementById(div).innerText = '';
		document.getElementById(div).style.display = 'none';
}

function limpaVal(val){
	val = val.replace('R','');
	val = val.replace('$','');
	val = val.replace(' ','');
	val = val.replace('.','');
	val = val.replace('.','');
	val = val.replace('.','');
	val = val.replace('.','');
	val = val.replace('.','');
	val = val.replace('.','');
	val = val.replace('.','');
	val = val.replace('.','');
	val = val.replace(',','.');
	val = val * 1;
	return val;
}

function somaValores(p){
	var L_Lance    = document.addLance.L_Lance.value;
	var L_Despesas = document.addLance.L_Despesas.value;
	var L_Comissao = document.addLance.L_Comissao.value;
	var L_Total    = document.addLance.L_Total.value;
	
	L_Lance    = limpaVal(L_Lance);
	L_Despesas = limpaVal(L_Despesas);
	L_Comissao = limpaVal(L_Comissao);
	L_Total    = limpaVal(L_Total);
	
	// gera porcentagem
	L_Comissao = (L_Lance*(p/100));
	document.addLance.L_Comissao.value = currencyFormate2(L_Comissao);
	
	var L_Lance    = document.addLance.L_Lance.value;
	var L_Despesas = document.addLance.L_Despesas.value;
	var L_Comissao = document.addLance.L_Comissao.value;
	var L_Total    = document.addLance.L_Total.value;
	
	L_Lance    = limpaVal(L_Lance);
	L_Despesas = limpaVal(L_Despesas);
	L_Comissao = limpaVal(L_Comissao);
	L_Total    = limpaVal(L_Total);
	
	L_Total = (L_Lance*1)+(L_Despesas*1)+(L_Comissao*1);
	document.addLance.L_Total.value = currencyFormate2(L_Total);
	
//	alert(limpaVal(L_Lance));
}

/** ------------------------------------------------------------------------------------------------------- **\
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2200;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
	//	alert("O formado da data é: dd/mm/aaaa")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
	//	alert("Por favor, insira um mês válido")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
	//	alert("Por favor, insira um dia válido")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
	//	alert("Por favor, insira um ano de 4 digitos entre "+minYear+" e "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
	//	alert("Por favor, insira uma data válida")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

/** ------------------------------------------------------------------------------------------------------- **\*/

-->
