<!--
// Modal Dialog Window
 
var ModalDialogWindow = new Object;
var ModalDialogInterval;
//var ModalDialog;

ModalDialogWindow.value = ''; 
               
 function ModalWindow(url)
 {
    	var X = 0;
    	var Y = 0;
		var W = 325;
		var H = 170;

   	if (screen.availWidth){
        X = (screen.availWidth / 2) - (W / 2);
        Y = (screen.availHeight / 2) - (H / 2);
 }

   var args ='width=' + W + ',height=' + H + ',left=' + X + ',top=' + Y + ',toolbar=0,';
       args +='location=0,status=0,menubar=0,scrollbars=0,resizable=0';  

   ModalDialogWindow = window.open(url,'login',args); 
 }
 
function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()

function verdiv(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	if(obj.visibility=='visible' || obj.visibility=='show') obj.visibility='hidden'
	else obj.visibility='visible'
}

function openWin(url,arg) { 
		window.open(url, 'default', 'width=10px, height=10px, '+arg);
     }

//scroll direita
function scroll_r() {
		document.getElementById('slidex').scrollLeft+=85;
}

function scroll_r_f() {
		document.getElementById('slidex').scrollLeft+=765;
}

function scroll_r_t() {
		document.getElementById('slidex').scrollLeft+=100000;
}
//scroll esquerda
function scroll_l() {
		document.getElementById('slidex').scrollLeft-=85;
}

function scroll_l_f() {
		document.getElementById('slidex').scrollLeft-=765;
}

function scroll_l_t() {
		document.getElementById('slidex').scrollLeft-=100000;
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return "";
	}
}				
//adicionar imagem
function ad_imagem(value) {
//function Set_Cookie( name, , expires, path, domain, secure )// set time, it's in milliseconds

name = "avisfoto";
expires = 3600000;

var oldCookie = Get_Cookie(name);
var newCookie = oldCookie.split( ';' );
newCookie = newCookie.length
	if (newCookie > 40){
		alert('Apenas são permitidas 40 fotos por encomenda!!!');
	}
	else{
		if (confirm('Pretende encomendar?')){
			newCookie = newCookie + 1
			var today = new Date();
			today.setTime( today.getTime() );

			var expires_date = new Date( today.getTime() + (expires) );

			document.cookie = name + "=" + escape( oldCookie + ";" + newCookie + "#" + value ) +
			( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) 
			showEncomenda('slideshow_encomenda.asp');	//return true;
		}
	}
}
//apagar imagem
function del_imagem( img ) {
if (confirm('Tem a certeza que pretende retirar esta foto do carrinho?')){
var today = new Date();
today.setTime( today.getTime() );

name = "avisfoto";
expires = 3600000;

var value = '';
var newCookie
var oldCookie = Get_Cookie(name);
newCookie = oldCookie.split( ';' );
	for ( i = 0; i < newCookie.length; i++ )
	{
	if(newCookie[i] != img && newCookie[i] != ""){
		value = value + ";" + newCookie[i];
		}
	}

var expires_date = new Date( today.getTime() + (expires) );

	if(value == "") {
document.cookie = name + "=" +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}
	else {
		document.cookie = name + "=" + escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) 
		//return true;
		}
showEncomenda('encomendar_encomenda.asp');
//window.location.reload();
	}
}
//apagar todas as imagens
function Delete_Cookie( name ) {
if (confirm('Tem a certeza que pretende limpar o carrinho de encomenda?')){
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	window.location.reload();
	}
}
//mudar tamanho da imagem
function mudar_imagem( img ) {

var today = new Date();
today.setTime( today.getTime() );

name = "avisfoto";
expires = 3600000;

var value = '';
var newCookie
var oldCookie = Get_Cookie(name);
var imagem
newCookie = oldCookie.split( ';' );
	for ( i = 0; i < newCookie.length; i++ )
	{
	imagem = newCookie[i].split( '#' );
	if(newCookie[i] != img && newCookie[i] != ""){
		value = value + ";" + newCookie[i];
		}
	else if(newCookie[i] == img){
		if(imagem[1] == '10x15'){
			value = value + ";" + imagem[0] + "#15x20#" + imagem[2];
			}
		else{
			value = value + ";" + imagem[0] + "#10x15#" + imagem[2];
			}
		}
	}

var expires_date = new Date( today.getTime() + (expires) );

	if(value == "") {
document.cookie = name + "=" +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}
	else {
		document.cookie = name + "=" + escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) 
		//return true;
		}
showEncomenda('encomendar_encomenda.asp');
//window.location.reload();
}

//Mostrar body
// Begin
function loadImages() {
if (document.getElementById) {  // DOM3 = IE5, NS6
document.getElementById('hidepage').style.visibility = 'hidden';
document.getElementById('main').style.display = 'block';
}
else {
if (document.layers) {  // Netscape 4
document.hidepage.visibility = 'hidden';
document.main.visibility = 'block';
}
else {  // IE 4
document.all.hidepage.style.visibility = 'hidden';
document.all.main.visibility = 'block';
      }
   }
}
//  End 
//mostrar opções
function showHide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj2=bw.dom?document.getElementById('img'+div).style:bw.ie4?document.all['img'+div].style:bw.ns4?nest?document[nest].document['img'+div]:document['img'+div]:0;
		if(obj.visibility=='visible' || obj.visibility=='show') {
	obj.visibility='hidden';
	obj2.visibility='visible';
	}
		else {
	obj2.visibility='hidden';
	obj.visibility='visible'; 
	}

}
//end
function showEncomenda(str){ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url=str;
//url=url+"?"+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("POST",url,true);
//xmlHttp.send(null);
xmlHttp.send('');
}

function GetXmlHttpObject(){
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function stateChanged(){ 
	if (xmlHttp.readyState==4){ 
		document.getElementById("encomenda").innerHTML=xmlHttp.responseText;
	}
	//else{
//document.getElementById("encomenda").innerHTML="<table width=100% align=center><tr><td height=50 class=tdtexto><center>A processar aguarde...</center></td></tr></table>";
	//}
}
//-->
