function warnuser(){
	
	alert('Estes são os dados com que ficou registado. Pode alterá-los na área de clientes usando a password que recebeu por email.');
	
}

/*
function updatePrice(){
		//percorred as select boxes apanhar o valor do selected index e somar ao preço original
		//falta contar com os preços por omissão
		var current = parseFloat($F('finalprice'));
		
		alert(current);
		var variation = parseFloat(item.value);
		
		alert(item.value);
		var newprice = current + variation;
		
		$('price').innerHTML = newprice + '&euro;';
		
		$('finalprice').value = newprice;
		
		alert($F('finalprice'));
	}
*/	






// JavaScript Document
var erros='';

function write_nonspammers_email(user_part,domain_part, type_link)
{
	var mail = type_link + user_part + '@'+ domain_part;
	return mail;
}

function ENumero(campo, nome) {
	if (campo && campo.value == "") return(true);
	expr = /[^\d]/;
	if (campo && campo.value.match(expr)) {
		erros += "Por favor preencha somente com numeros o campo " + nome + ". \n";

	}
}

// Verifica campo vazio
function vazio(campo, nome) {
	if (campo && campo.value == "") {
		erros += "Por favor preencha o campo " + nome + ". \n";
		return false;
	}else{
		return true;
	}
}

// Verifica comprimento de campo
function comprimento(comp, campo, nome) {
	if (campo && campo.value.length < comp) {
		erros += "O campo " + nome + " tem que ter no mínimo "+comp+" letras. \n";

	}
}

// Verifica select parado
function validaSelect(campo, nome) {
	if (campo && campo.selectedIndex == 0) {
		erros += "Por favor selecione o campo " + nome + ". \n";
	}

}

//verifica radio boxes eg (sexo, sexo, 2)
function validaVarios(campo, nome, total_radios) {
	one_is_checked = false;
	for(i=1;i<=total_radios;i++) {
		if(document.getElementById(campo+i) && document.getElementById(campo+i).checked == true)
		{
			one_is_checked = true;
		}
	}
	if(one_is_checked == false) {
		erros += "Indique uma opção no campo " + nome + ". \n";
	}
}

function getSelectedValue(campo)
{
	elem = document.getElementById(campo);
	return elem.options[elem.selectedIndex].value;
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function validaData(ano,mes,dia, nome)
{
	if(dia.length==0 || mes.length==0 || ano.length !=4)
	{
		erros += "A " + nome + " é inválida. \n";
	}
	else
	//deviam ser numeros
	if(isNaN(dia) || isNaN(mes) || isNaN(ano))
	{
		erros += "A " + nome + " é inválida. \n";
	}
	else
	//meses de 30 dias
	if(mes==4 || mes==6 || mes==9 || mes==11)
	{
		if(dia == 31)
		{
			erros += "Preencha correctamente o campo " + nome + " (mes escolhido tem 30 dias). \n";
		}
	}
	else
	//ano bissexto
	if(mes==2)
	{
		if ((ano % 4) == 0){
			if (dia > 29){
				erros += "Preencha correctamente o campo " + nome + " (mes escolhido tem 29 dias). \n";
			}
		}else{
			if (dia > 28){
				erros += "Preencha correctamente o campo " + nome + " (mes escolhido tem 28 dias). \n";
			}
		}
	}

}

// valida campo de email
function validaEmail(campo, nome)
{
	apos=campo.value.indexOf("@");
	dotpos=campo.value.lastIndexOf(".");
	comp = campo.value.length;
	if (campo && apos<1 || dotpos-apos<2 || comp-dotpos<3) {
		erros += "Preencha correctamente o campo " + nome + ". \n";
	}
}

function getElement(id){
	if (document.all) return document.all[id];
	return document.getElementById(id);
}

function changeDisplay(id, on) {
	elemento = getElement(id);
    if (on) {
		elemento.style.display = "";
	}
	else {
		elemento.style.display = "none";
	}
}

function toggle(id){

	var status = $(id).style.display;
	if(status == 'none'){
		
		$(id).style.display = 'block';
				
	}else{
		$(id).style.display = 'none';
	}
	
}

function tabs(active_nr)
{
	var nr=active_nr;
	if(nr==2)
	{
		document.getElementById('destaqueHome'+1).style.display ='none';
		document.getElementById('destaqueHome'+3).style.display ='none';
	}else if(nr==3){
		document.getElementById('destaqueHome'+1).style.display ='none';
		document.getElementById('destaqueHome'+2).style.display ='none';
	}else{
		document.getElementById('destaqueHome'+3).style.display ='none';
		document.getElementById('destaqueHome'+2).style.display ='none';
	}

	document.getElementById('destaqueHome'+nr).style.display ='block';

}
////////////////////////////////form functions

function init()
{
	document.getElementById('feedback').style.display='none';
	for(i=2;i<7;i++)
	{
		document.getElementById('step'+i).style.display='none';
	}
}

function zeropad(campo) {
    return (parseInt(campo) < 10) ? '0' + campo : campo;
}

function clear()
{
	erros = '';
	//document.getElementById('feedback').innerHtml = '';
	//changeDisplay('feedback',false);
}

function showErrors()
{
	//changeDisplay('feedback',true);
	//s = erros.replace(/\n/g,"<br>");
	//document.getElementById('feedback').innerHTML = '<p style="background-color:#D84F00;color:#FFF;padding:5px">'+s+'</p>';
	alert(erros);
}

//validations for form sections //////////////////////
function validaNewsletter() {
	clear();

	vazio(document.form_newsletter.email_letter, "Email");
	validaEmail(document.form_newsletter.email_letter, "Email");

	if(erros.length > 0)
	{
		showErrors();
		return false;
	}else{
		clear();
		return true;
	}
}

function validaLogin() {
	clear();

	vazio(document.form_login.email, "Email");
	validaEmail(document.form_login.email, "Email");
	vazio(document.form_login.password, "Palavra-Passe");

	if(erros.length > 0)
	{
		showErrors();
		return false;
	}else{
		clear();
		return true;
	}
}

function validaRegisto() {
	clear();

	vazio(document.form_register.email, "Email");
	validaEmail(document.form_register.email, "Email");
	vazio(document.form_register.user, "Utilizador");
	vazio(document.form_register.phone, "Telefone");

	if(erros.length > 0)
	{
		showErrors();
		return false;
	}else{
		clear();
		return true;
	}
}

function validaContactos() {
	clear();

	vazio(document.form_contactos.user, "Nome");
	vazio(document.form_contactos.phone, "Telefone");
	if(vazio(document.form_contactos.email, "Email")){
		validaEmail(document.form_contactos.email, "Email");
	}
	vazio(document.form_contactos.message, "Mensagem");
	//vazio(document.form_contactos.message, "Mensagem");
	vazio(document.form_contactos.captcha_phrase, "Texto de Segurança");


	if(erros.length > 0)
	{
		showErrors();
		return false;
	}else{
		clear();
		return true;
	}
}



function validaRecomenda() {
	clear();

	vazio(document.form_recomenda.user, "Nome");
	if(vazio(document.form_recomenda.email, "Email")){
		validaEmail(document.form_recomenda.email, "Email");
	}
	vazio(document.form_recomenda.friend, "Nome de Amigo");
	if(vazio(document.form_recomenda.email_friend, "Email de Amigo")){
		validaEmail(document.form_recomenda.email_friend, "Email de Amigo");
	}
	vazio(document.form_recomenda.message, "Mensagem");
	vazio(document.form_recomenda.captcha_phrase, "Texto de Segurança");


	if(erros.length > 0)
	{
		showErrors();
		return false;
	}else{
		clear();
		return true;
	}
}

function validaEnviaNoticia() {
	clear();

	vazio(document.form_recomenda.user, "Nome");
	if(vazio(document.form_recomenda.email, "Email")){
		validaEmail(document.form_recomenda.email, "Email");
	}
//	vazio(document.form_recomenda.nome_receptor, "Nome de Amigo");
//	vazio(document.form_recomenda.email_receptor, "Email de Amigo");
//	validaEmail(document.form_recomenda.email_receptor, "Email de Amigo");
//	vazio(document.form_recomenda.mensagem, "Mensagem");
	vazio(document.form_recomenda.captcha_phrase, "Texto de Segurança");

	if(erros.length > 0)
	{
		showErrors();
		return false;
	}else{
		clear();
		return true;
	}
}


function validaRecuperaSenha() {
	clear();

	vazio(document.form_pass.email, "Email");
	validaEmail(document.form_pass.email, "Email");

	if(erros.length > 0)
	{
		showErrors();
		return false;
	}else{
		clear();
		return true;
	}
}


function validaServicos()
{
	clear();

	vazio(document.servicos_maisinfo.user, "Nome");
	vazio(document.servicos_maisinfo.email, "Email");
	validaEmail(document.servicos_maisinfo.email, "Email");
	vazio(document.servicos_maisinfo.phone, "Telefone");
	ENumero(document.servicos_maisinfo.phone, "Telefone");
	vazio(document.servicos_maisinfo.message, "Mensagem");
	vazio(document.servicos_maisinfo.message, "Mensagem");
	vazio(document.servicos_maisinfo.captcha_phrase, "Texto de Segurança");


	if(erros.length > 0)
	{
		showErrors();
		return false;
	}else{
		clear();
		return true;
	}
}




function validaRecrutamento() {
	clear();

	validaSelect(document.form_recrutamento.job_opportunities, "Candidato a");
	vazio(document.getElementById('name'), "Nome");
	validaSelect(document.form_recrutamento.sex, "Sexo");
	vazio(document.form_recrutamento.bi, "BI");
	var ano = document.form_recrutamento.birthyear.value;
	var mes = getSelectedValue('birthmonth');
	var dia = getSelectedValue('birthday');
	validaData(ano,mes,dia, 'Data de Nascimento');
	vazio(document.form_recrutamento.nationality, "Nacionalidade");
	vazio(document.form_recrutamento.address, "Morada");
	vazio(document.form_recrutamento.zipcode1, "Código Postal");
	ENumero(document.form_recrutamento.zipcode1, "Código Postal");
	comprimento(4, document.form_recrutamento.zipcode1, "Código Postal");
	vazio(document.form_recrutamento.city, "Localidade");
	vazio(document.form_recrutamento.country, "País");
	vazio(document.form_recrutamento.cellphone, "Telemóvel");
	vazio(document.form_recrutamento.email, "Email");
	validaEmail(document.form_recrutamento.email, "Email");


	if(erros.length > 0)
	{
		showErrors();
		return false;
	}else{
		clear();
		return true;
	}
}

function popupEnviaNoticia(url, title) {
	newWindow = window.open(url, title,"left=200,top=200,width=564,height=520,statusbar=no,menubar=no,titlebar=no,locationbar=no,resize=yes");
}




/*
function addFavorite()
{
	if (window.external)
		external.AddFavorite(location.href, document.title)
	if (window.sidebar)
			window.sidebar.addPanel(document.title, location.href,"");
}
*/

function addBookmark(title,url) {
if (window.sidebar) {
window.sidebar.addPanel(title, url,"");
} else if( document.all ) {
window.external.AddFavorite( url, title);
} else if( window.opera && window.print ) {
return true;
}
}

var newwindow;
function popup(url,title) {
	newwindow=window.open(url,"title",'height=440,width=564');
	if (window.focus) {newwindow.focus()}
	return false;
}

function popupa(url,title) {
	newwindow=window.open(url,"title",'height=259,width=330');
	if (window.focus) {newwindow.focus()}
	return false;
}

function googlemap(url,title) {
	newwindow=window.open(url,"title",'height=350,width=350');
	if (window.focus) {newwindow.focus()}
	return false;
}




function remover_de_carrinho(prod_id) {
	if (confirm("Tem certeza que deseja excluir este item?")) {
		location.href='carrinho.php?excluirID=' + id;
	}
}

function limpaDadosEntrega(path)
{
	$('loading').style.display = 'block';
	//pretendo levantar a encomenda na loja
	//esconde ou mostra div dados_de_entrega
	elem = document.getElementById('dados_de_entrega');
	if(elem.style.display=='none')
	{
		changeDisplay('dados_de_entrega', true);
	}else{
		changeDisplay('dados_de_entrega', false);
	}


	if(document.getElementById('to_atstore').checked)
	{
		$('montagem').style.display = 'block';
		var cobranca = 'no';
	}else{
		$('montagem').style.display = 'none';
		var cobranca='yes';
	}

	var url=path;
	new Ajax.Updater('payment_types', url+cobranca, {
	  method:'get'
	});
	$('loading').style.display = 'none';
	return true;
}

function validaPasso2()
{
	clear();

	vazio(document.form_order_client_info.username, "Nome");
	vazio(document.form_order_client_info.email, "Email");
	validaEmail(document.form_order_client_info.email, "Email");
	vazio(document.form_order_client_info.phone, "Phone");
	vazio(document.form_order_client_info.address, "Morada");
	vazio(document.form_order_client_info.zipcode1, "Código Postal");
	ENumero(document.form_order_client_info.zipcode1, "Código Postal");
	comprimento(4, document.form_order_client_info.zipcode1, "Código Postal");
	vazio(document.form_order_client_info.city, "Localidade");
	vazio(document.form_order_client_info.country, "País");
	
		vazio(document.form_order_client_info.to_user, "Nome de Destinatário");
		vazio(document.form_order_client_info.to_phone, "Telefone de Destinatário");
		vazio(document.form_order_client_info.to_zipcode1, "Código Postal de Destinatário");
		ENumero(document.form_order_client_info.to_zipcode1, "Código Postal de Destinatário");
		comprimento(4, document.form_order_client_info.to_zipcode1, "Código Postal de Destinatário");
		vazio(document.form_order_client_info.to_city, "Localidade de Destino");
		vazio(document.form_order_client_info.to_address, "Morada de Destino");
		vazio(document.form_order_client_info.to_region, "Zona de entrega");
	
	
	//if(document.getElementById('copy_client_info_to_factura').checked==true)
	//{

		vazio(document.form_order_client_info.invoice_desigsocial, "Designação Social");
		vazio(document.form_order_client_info.invoice_nif, "Nr. de Contribuinte");
		ENumero(document.form_order_client_info.invoice_nif, "Nr. de Contribuinte");
		vazio(document.form_order_client_info.invoice_address, "Morada (Factura)");
		vazio(document.form_order_client_info.invoice_zipcode1, "Código Postal (Factura)");
		ENumero(document.form_order_client_info.zipcode1, "Código Postal (Factura)");
		vazio(document.form_order_client_info.invoice_city, "Localidade (Factura)");
		vazio(document.form_order_client_info.invoice_country, "País (Factura)");
	
	//}
	

	validaSelect(document.form_order_client_info.payment_type, "Método de Pagamento");

	if(erros.length > 0)
	{
		showErrors();
		return false;
	}else{
		clear();
		return true;
	}


}

function copiaDadosCliente(value) {

    if(value == 'entrega')
    {
    	elem = document.getElementById('copy_client_info');
    	if (elem.checked) {
			//copy values
	        document.form_order_client_info.to_user.value = document.form_order_client_info.username.value;
	        document.form_order_client_info.to_phone.value = document.form_order_client_info.phone.value;
	        document.form_order_client_info.to_address.value = document.form_order_client_info.address.value;
	        document.form_order_client_info.to_zipcode1.value = document.form_order_client_info.zipcode1.value;
	        document.form_order_client_info.to_zipcode2.value = document.form_order_client_info.zipcode2.value;
	        document.form_order_client_info.to_city.value = document.form_order_client_info.city.value;

	    }else{
	        document.form_order_client_info.to_user.value = '';
	        document.form_order_client_info.to_phone.value = '';
	        document.form_order_client_info.to_address.value = '';
	        document.form_order_client_info.to_zipcode1.value = '';
	        document.form_order_client_info.to_zipcode2.value = '';
	        document.form_order_client_info.to_city.value = '';
	    }
    }else{
    	elem = document.getElementById('copy_client_info_to_factura');
    	if (elem.checked) {
			//copy values to dados de factura
	        document.form_order_client_info.invoice_address.value = document.form_order_client_info.address.value;
	        document.form_order_client_info.invoice_zipcode1.value = document.form_order_client_info.zipcode1.value;
	        document.form_order_client_info.invoice_zipcode2.value = document.form_order_client_info.zipcode2.value;
	        document.form_order_client_info.invoice_city.value = document.form_order_client_info.city.value;
	        document.form_order_client_info.invoice_country.value = getSelectedValue('country');

	    }else{
	        document.form_order_client_info.invoice_address.value = '';
	        document.form_order_client_info.invoice_zipcode1.value = '';
	        document.form_order_client_info.invoice_zipcode2.value = '';
	        document.form_order_client_info.invoice_city.value = '';
	        document.form_order_client_info.invoice_country.value = '';
	    }
    }

}

function validaCartaoCredito()
{
	clear();

	vazio(document.form_passo4.credit_card, "Cartão de Crédito");
	ENumero(document.form_passo4.credit_card, "Cartão de Crédito");

	vazio(document.form_passo4.check_digit, "Digito de Verificação");
	ENumero(document.form_passo4.check_digit, "Digito de Verificação");
	comprimento(3, document.form_passo4.check_digit, "Digito de Verificação");

	validaSelect(document.form_passo4.valid_until_month, "Data de Validade (Mês)");
	validaSelect(document.form_passo4.valid_until_year, "Data de Validade (Ano)");

	if(erros.length > 0)
	{
		showErrors();
		return false;
	}else{
		clear();
		return true;
	}
}


//ajax functions

function vote(path)
{
	$('loadingsurvey').style.display = 'block';
	var question_id = $('question').value;
	var chosen_answer = getCheckedValue(document.forms['form_inquerito'].elements['answer']);
	var url = path+'?question='+question_id+'&answer='+chosen_answer;

	new Ajax.Updater('inquerito', url, { method:'get' });
}

function verinquerito(path)
{
	$('loadingsurvey').style.display = 'block';
	var url = path;
	new Ajax.Updater('inquerito', url, {
	  method:'get'
	  });
}

function get_availablepayment_types(path)
{
	$('loading').style.display = 'block';
	var url = path;
	new Ajax.Updater('payment_types', url, {
	  method:'get'
	  });
}




function updatepaymentmessage(payid){
	
	//alert(payid);
//	 $(element).addClassName(className);
	if(payid==1){
		
		$('paymentmessage').style.display = 'block';
		$('paymentmessage').innerHTML = '<h5>Cheque</h5>A sua encomenda será enviada depois de o seu cheque ter sido recebido e validado';

	}else if(payid == 2){
		
		$('paymentmessage').style.display = 'block';
		$('paymentmessage').innerHTML = '<h5>Transferência</h5>A sua encomenda será enviada depois de recebermos o comprovativo da transferência.';		

	}else if(payid == 3) {
		
		$('paymentmessage').style.display = 'block';
		$('paymentmessage').innerHTML = '<h5>Envio à Cobrança</h5>A sua encomenda será enviada e pagará no acto da recepção.';				

	}else if(payid == 4) {
		
		$('paymentmessage').style.display = 'block';
		$('paymentmessage').innerHTML = '<h5>Cartão de Crédito</h5>Tenha o seu cartão de crédito (Visa ou Mastercard) pronto para inserir os dados no próximo passo.';				
		
	}else if(payid == 5) {

		$('paymentmessage').style.display = 'block';
		$('paymentmessage').innerHTML = '<h5>Cartão de crédito</h5>Através do serviço Paypal pode usar o seu cartão de crédito ou uma conta Paypal para efectuar o pagamento.<br /><p><img src="https://www.paypalobjects.com/WEBSCR-490-20071026-1/en_US/i/logo/logo_ccVisa.gif" alt="" /><img src="https://www.paypalobjects.com/WEBSCR-490-20071026-1/en_US/i/logo/logo_ccMC.gif" alt="" /><img src="https://www.paypalobjects.com/WEBSCR-490-20071026-1/en_US/i/logo/logo_ccAmex.gif" alt="" /><img src="https://www.paypalobjects.com/WEBSCR-490-20071026-1/en_US/i/logo/PayPal_mark_37x23.gif" alt="" /></p>';
	}else{
		$('paymentmessage').style.display = 'block';
		$('paymentmessage').innerHTML = '<h5>Pagamento</h5> Deve escolher um dos meios de pagamento disponíveis.';
	}
	
}


//
//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

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 = '';
  if (isIE && isWin && !isOpera)
  {
    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 += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }

  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":
      case "id":
        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 "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;
}

