var $ = function(p){return typeof p === 'string' ? document.getElementById(p) : p};
var indexTimeout=0;
function showSub(i) {
	clearTimeout(indexTimeout);	
	$('submenu'+(i?i:'')).style.display = ($('submenu'+(i?i:'')).style.display=="block" ? "none" : "block");
	if(i == 1){
		$('submenu2').style.display="none";
	}else if(i == 2){
		$('submenu1').style.display="none";
	}
	clearTimeout(indexTimeout);
}
function closeSub(i) {
	clearTimeout(indexTimeout);
	indexTimeout = setTimeout(function(){$('submenu'+(i?i:'')).style.display = "none";},1000)
}
function checkSubOver() {
	clearTimeout(indexTimeout);
}

var lastsel = 1;

function showProdList(atual,total,nome){
  	for(var i=1;i<=total;i++){
		if(document.getElementById(nome+'0'+i)){
			document.getElementById(nome+'0'+i).style.display='none';
		}
	}
	document.getElementById('itemp'+lastsel).className='off';
	document.getElementById(nome+'0'+atual).style.display='block';
	document.getElementById('itemp'+atual).className='on';
//	alert(elem);
	lastsel=atual;
}
function popUpWindow(URLStr, popName, width, height, left, top, p_scroll)
{
  if(p_scroll=="yes") p_scroll="yes";
  else p_scroll="no";
  vpopName =popName;
  if(!left) left=(screen.availWidth-width)/2;
  if(!top) top=(screen.availHeight-height)/2;
  vpopName = window.open(URLStr, popName, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+p_scroll+',resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
String.prototype.trim = function(param){
	var s;
	s=this;
	if (!s || s=="") return "";  	
	if(param=='left' || param==undefined) while((s.charAt(0)==" ") || (s.charCodeAt(0)==9) || (s.charAt(0)=='\n') || (s.charAt(0,1)=='\r')){s=s.substr(1,s.length-1);}
	if(param=='right' || param==undefined) while((s.charAt(s.length-1)==" ") || (s.charCodeAt(s.length-1)==9) || (s.charAt(s.length-1)=='\n') || (s.charAt(s.length-1)=='\r')){s=s.substr(0,s.length-1);}
	if(param=='br') s = s.split(String.fromCharCode(13)).join("");
	return s;
}

function isEmail(email){
	var res1=!(/(\.\.)+|(__)+|(--)+/.test(email));
	var res2=(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(email));
	return (res1 && res2)
}

function isDate(dateStr,format){
	for (var i=0,fo,ds,d="",m="",y="";i<format.length;ds=dateStr.charAt(i),fs=format.charAt(i),((fs=="D")?d+=ds:(fs=="M")?m+=ds:(fs=="Y")?y+=ds:void(0)),i++);
	return ((!isNaN(d) && !isNaN(m) && !isNaN(y)) ? 
	((d<1||d>31) || (m<1||m>12) || ((m==4||m==6||m==9||m==11)&&d==31) || (y.toString().length<4)) ? false :
	((m == 2) ? ((d>29 || (d==29 && !((y%4)==0&&((y%100)!=0||(y%400)==0)))) ? false : true ) : true ) : false );
}

function PopupPic(sPicURL) {
	window.open( "pop-cestas.htm?"+sPicURL, "", "resizable=1,scrollbars=yes,height=200,width=200");
}

