/***************************************************************************
* iPop: Automatic Image Popup
* Copyright (c) 2003-2005 by David Schontzler | www.stilleye.com
* Use allowed under the Academic Free License 2.1
*  http://opensource.org/licenses/afl-2.1.php
* Description:  Automate your image popup windows (centered and sized)
* Compatibility: Win/IE5+, Mozilla/Netscape, degrades otherwise
***************************************************************************
* Version: 2.6 + AutoApply 1.0
***************************************************************************/

///////////////// USER SETTINGS /////////////////
// Set the target for browsers that don't support the script.  By default,
// target is "_self" which will open in the same window as the link.  Change
// it to whatever target you like.  The built in targets (_blank, _self,
// _top, and _parent) are supported.
iPop.DegradeTarget = "_self";

// Set this to true if you want to be able to click on the image to close
// the popup window
iPop.ClickImageToClose = true;

// Set this to true if you want to close the last open popup image when you click
// on a new popup (like window reuse)
iPop.CloseOpenWindows = false;

///////////////// FUNCTIONALITY /////////////////
/////////////////  DO NOT EDIT  /////////////////
iPop.Version = 2.6;
iPop.imgWin = null;
iPop.ieSp2 = (navigator.appName.toLowerCase().indexOf("internet explorer") > -1
	&& navigator.appMinorVersion.toLowerCase().indexOf("sp2") > -1);

function iPop(img, imgTitle) {

	function degrade() {
		switch(iPop.DegradeTarget) {
			case "_blank" : open(img); break;
			case "_self" : location = img; break;
			case "_top" : top.location = img; break;
			case "_parent" : parent.location = img; break;
			default : open(img, iPop.DegradeTarget);
		}
		return false;
	}
	
	// just follow the link in browsers that do not support images or the DOM
	// or launch in specified target if that's what you wanted it to do
	if(!document.images || !document.getElementById) return degrade();
	
	// check to close open popups (if set to do so)
	if(iPop.CloseOpenWindows && iPop.imgWin) {
		if(iPop.imgWin.close) iPop.imgWin.close();
		iPop.imgWin = null;
	}
	
	// initial (small) window with loading screen
	var width = 584, height = 420
	if(iPop.ieSp2) { height += 20; }
	var left = (screen.availWidth - width)/2, top = (screen.availHeight - height)/ 2;
	var imgWin = window.open("about:blank", "", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);
	// when moz disables all popups, imgWin will be false
	if(!imgWin) return degrade();
	
	// user can pass an image title if they wish.  by default,
	// window title will display: "Image (img source)"
	imgTitle = imgTitle || "Image (" + img + ")";
	
	// html generated for use in our popup
	// note on the javascript functions:
	// wrapper functions with timeouts because sometimes the image is loaded
	// before the script is loaded, at least in Win/IE when doing local testing;
	// timeout should (presumably) prevent that
	var html = '<!--\niPop Script ()'
		+ '\niPop.Version = ' + iPop.Version + '\n-->'
		+ '\n<html><head><title>Filipe Motoshow - Veículos Motorizados, Lda.</title><meta http-equiv="imagetoolbar" content="no">'
		+ '\n<script type="text/javascript">\nvar _e = null;'
		+ '\nvar ip = window.opener.iPop;'
		+ '\nvar _pageLoaded = false;'
		+ '\nvar _title = "' + imgTitle + '"'
		+ '\nonload = function(e) { _pageLoaded = true; }'
		+ '\nfunction imgLoad(e) { ip.ImageLoaded(e, window); }'
		+ '\nfunction imgError(e) { ip.ErrorLoading(e, window); }'
		+ '\nimgShow = ip.ImageShow;'
		+ '\nimgManualPopup = ip.ImageLoadedManualPopup;'
		+ '\n</script>'
		+ '\n<style type="text/css">'
		+ '\nhtml, body { font : 12px Arial; margin : 0; overflow : hidden; } h1 { font-size : 1.5em; }'
		+ '\n h2 { font-size : 1.2em; } a { color : blue; } img { border-color : black; }'
		+ '\n .message { position : absolute; left : 0px; top : 0px; width : 150px; height : 100px; background : white; text-align : center; }'
		+ '\n .message .main-message { font-weight : bold; display : block; }'
		+ '\n .message .secondary-message { color : #999; font-size : 11px; }'
		+ '\n .main-message.loading { margin-top : 35px; } .main-message.loaded { margin-top : 33px; } .main-message.error { margin-top : 25px; }'
		+ '\n #loading { z-index : 50; } #resize { z-index : 30; } #error { z-index : 40; }'
		+ '\n #image { position : absolute; left : 0px; top : 0px; width : 100%; height : 100%; z-index : 20; padding : 10px; background : #6c6c6c; }'
		+ '\n</style>'
		+ '\n</head>\n<body bgcolor="#6c6c6c">'
		+ '\n<div id="loading" class="message"><span class="main-message loading">A carregar imagem.</span> <span class="secondary-message">Por favor aguarde...</span></div>'
		+ '\n<div id="error" class="message"><span class="main-message error">Imagem não encontrada.</span> <span class="secondary-message">Erro ao carregar.<br><a href="javascript:window.close()">Fechar Janela</a></span></div>'
		+ '\n<div id="resize" class="message"><span class="main-message error">Imagem carregada.</span> <span class="secondary-message">O seu browser não suporta redimensionamento de janelas.<br><a href="javascript:imgManualPopup(_e, window)">Visualizar imagem</a></span></div>'
		+ '\n<div id="image">';
	if(iPop.ClickImageToClose) html += '\n<a href="javascript:window.close()" title="Fechar Janela">';
	html += '\n<img src="' + img + '" border="1" onload="imgLoad(this)" onerror="imgError(this)">';
	if(iPop.ClickImageToClose) html += '</a>';
	html += '\n</div>'
		+ '\n</body></html>';
	
	imgWin.document.open();
	imgWin.document.write(html);
	imgWin.document.close();
	
	iPop.imgWin = imgWin;
	
	return false;
}

iPop.ImageLoaded = function(e, win) {
	if(!e || !win) return;
	e.onload = null;
	e.onerror = null;
	if( win._pageLoaded ) {
		function show() {
			win.imgShow(e, win);
		}
		win.setTimeout(show, 100);
	} else {
		function noShow() {
			win.imgLoad(e, win);
		}
		win.setTimeout(noShow, 100);
	}
}

iPop.ImageShow = function(e, win) {
	if(!e || !win) return;
	e.onload = null; e.onerror = null;
	
	var doc = win.document;
	var width = e.width + 30,
		height = e.height + 55;
	if(iPop.ieSp2 || (win.statusbar && win.statusbar.visible)) { height += 20; }

	var tooLarge = false;
	
	if(width > screen.availWidth) {
		width = screen.availWidth - 20;
		tooLarge = true;
	}
	if(height > screen.availHeight) {
		height = screen.availHeight - 20;
		tooLarge = true;
	}
	if(tooLarge) {
		doc.getElementById("image").style.overflow = "auto";
	}
	
	var tooSmall = false;
	if( e.width < doc.body.clientWidth && e.height < doc.body.clientHeight ) {
		tooSmall = true;
	}
	
	var left = (screen.availWidth - width)/2, top = (screen.availHeight - height)/ 2;
	win.moveTo(left, top);
	win.resizeTo(width, height);
	
	var docElm = doc.documentElement || {};
	var winWidth = docElm.clientWidth||doc.body.clientWidth, winHeight = docElm.clientHeight||doc.body.clientHeight;
	if( (tooLarge && (winWidth < 200 || winHeight < 200) )
		|| !tooLarge && !tooSmall && (e.width > 150 && winWidth <= 150 || e.height > 100 && winHeight <= 100) ) {
		win._e = {
			src : e.src,
			width : e.width,
			height : e.height,
			tooLarge : tooLarge
		}
		doc.getElementById("loading").style.display = "none";
		doc.getElementById("error").style.display = "none";
		doc.getElementById("image").style.display = "none";
		doc.title = "Image Loaded";
	} else { // can resize
		doc.getElementById("loading").style.display = "none";
		doc.getElementById("error").style.display = "none";
		doc.getElementById("resize").style.display = "none";
		doc.title = win._title;
	}
}

iPop.ErrorLoading = function(e, win) {
	if(!e || !win) return;
	var doc = win.document;
	e.onload = null; e.onerror = null;
	
	doc.getElementById("loading").style.display = "none";
	doc.getElementById("resize").style.display = "none";
	doc.getElementById("image").style.display = "none";
	doc.title = "Image not found";
}

iPop.ImageLoadedManualPopup = function(e, win) {
	if(!e || !win) return;
	var width = e.width + 20, height = e.height + 20;
	if(width > screen.availWidth) width = screen.availWidth - 20;
	if(height > screen.availHeight) height = screen.availHeight - 100;
	var left = (screen.availWidth - width)/2, top = (screen.availHeight - height)/ 2;
	win.open(e.src, "ManualImageViewer", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + (e.tooLarge ? ",scrollbars" : ""));
	win.close();
}

///////////////// EXTENSIONS /////////////////

iPop.AutoApply = function(container) {
	if(!container) container = document;
	var a = container.getElementsByTagName("A");
	for(var i = 0; i < a.length; i++) {
		if( a[i].href.match(/\.(gif|jpg|jpeg|png|bmp)$/i) ) {
			applyPopup(a[i]);
		}
	}
	
	function applyPopup(link) {
		// check to see if link holds *just* a thumbnail and get
		// the thumbnail's alternate text for image popup title
		var n, imgs = 0, whitespace = 0, alt = null;
		for(var i = 0; n = link.childNodes[i]; i++) {
			if(n.tagName == "IMG") {
				imgs++;
				alt = n.alt;
			} else if(n.nodeValue) {
				var val = n.nodeValue;
				if( val.replace(/\s+/g, "") == "" ) whitespace++;
			}
		}
		n = null;
		if(!alt) { alt = link.title; }
		
		// apply iPop to link
		link.onclick = function(e) { return iPop(this.href, alt); }
	}
}


////////////////////////////////////////////////////

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_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_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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 popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function formButtonFever(formName,action){
	var myString = "document."+formName+"."+action+"();";
	eval(myString);
	}
	
	function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='Insira um e-mail válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '* '+nm+' é um campo de preenchimento obrigatório.\n'; }
  } if (errors) alert('Filipe Motoshow, Lda.\nwww.filipemotoshow.com\n\nPor favor corrija os seguintes erros:\n'+errors);
  document.MM_returnValue = (errors == '');
}

var dayarray=new Array("Domingo","Segunda-feira","Terça-feira","Quarta-feira","Quinta-feira","Sexta-feira","Sábado")
var montharray=new Array("Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro")

function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate="<font color='999999' face='Arial'>"+dayarray[day]+", "+daym+" de "+montharray[month]+" de "+year+"</font>"
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function goforit(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}
