
var slideCache = new Array();
function RunSlideShow(pictureName,textName,imageFiles,RelText,displaySecs)
{
	var imageSeparator = imageFiles.indexOf(';');
	var textSeparator = RelText.indexOf(';');   
	
	var nextImage = imageFiles.substring(0,imageSeparator);
	var nextPrice = RelText.substring(0,textSeparator);
	
	if (document.all)
	{
		document.getElementById(pictureName).style.filter=
			'blendTrans(duration=2)';
		document.getElementById(pictureName).filters.blendTrans.Apply();
	}
	document.getElementById(pictureName).src = nextImage;
    document.getElementById(textName).innerHTML = '<div align="center" class="style9">' +  nextPrice + '</div>';
	//<div align="center" class="style15">* &euro; 375.00 *</div>
	
	if (document.all)
	{
		document.getElementById(pictureName).filters.blendTrans.Play();
	}
	
	var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length)
		+ ';' + nextImage;
	var futureText= RelText.substring(textSeparator+1,RelText.length)
		+ ';' + nextPrice;
			
	setTimeout("RunSlideShow('"+pictureName+"','"+textName+"','"+futureImages+"','"+futureText+"',"+displaySecs+")",
		displaySecs*1000);
	// Cache the next image to improve performance.
	imageSeparator = futureImages.indexOf(';');
	nextImage = futureImages.substring(0,imageSeparator);
	if (slideCache[nextImage] == null) {
		slideCache[nextImage] = new Image;
		slideCache[nextImage].src = nextImage;
	}		
}

// The scroller script ------------------------------------------------------------------------------------------------------------------------------------------------


// Script by RuiSoft               //
// If you like it, Cut and Paste   //

var TheTimeout = 200; // Not used in first function... but you could use it
var MyMessage = 'Tuga Modelismo'; 
var MessPos = 0;
var LeftChars = 0;
var StartLength = 0;        // Length of panel 
var NextFunction = 0;
var TimesToBlink = 3;       // Blink 3 times
var Flicker = 0;            // On and OFF times (Counter)
var State = 0;              // Blink State - On or OFF
var BlinkTime = 1000;       // Blink Delay

function TugaBanner(PanelWidth)
{

	if (StartLength == 0)
	{
		StartLength = PanelWidth;
	}
	
	FrontPart = '';
	TotMessage = '';
	BackPart = '';
	FrontPart = MyMessage.substr(0,LeftChars);
 
	for (var x = LeftChars + 1; x <= PanelWidth; x++)
	{
   		FrontPart = FrontPart + ' ';
	}
 
 	FrontPart = FrontPart + MyMessage.substr(MessPos,1);

	for (var x = PanelWidth + 1; x <= StartLength -1 ; x++)
	{
   		FrontPart = FrontPart + ' ';
	}

	TotMessage = FrontPart;
	window.status = TotMessage;
	PanelWidth = PanelWidth - 1;

	if (PanelWidth==LeftChars)
	{
		PanelWidth = StartLength;
		MessPos = MessPos + 1;
		LeftChars = LeftChars + 1;
		if (MessPos > MyMessage.length)
		{
			MessPos = 0;
			LeftChars = 0;
			NextFunction = 1;           // Comment this out if you dont use another function
			document.title = MyMessage; // Set the title bar too... What the heck :)
		}
	}


	if (NextFunction == 1) 
	{
		NextFunction = 0;
		// Call next function
		Flicker = 0;
		State = 0;
		cmd = 'Blinka(' + TimesToBlink + ')';
		TheTimer= setTimeout(cmd,1); 
	}
	else
	{
		cmd ='TugaBanner('+PanelWidth+')';
		//TheTimer= setTimeout(cmd,TheTimeout);         // Not used... but you could use it :)
		TheTimer= setTimeout(cmd,PanelWidth - MessPos); // Tried this one for fancier effect	
	}
}


function Blinka(Times)
{
	
	if (Flicker==0)
	{
		Flicker = Times * 2;
	}
			
	if (State==0)
	{
		BlinkMess=' ';
		State = 1;
	}
	else
	{
		BlinkMess = MyMessage;
		State = 0;
	}
	
	window.status = BlinkMess; 
	Flicker = Flicker - 1;
   
    if (Times==0)
	{
		// Call next function or go to first one
		cmd ='TugaBanner('+StartLength+')';
		TheTimer= setTimeout(cmd,1);
	}
	else
	{
		cmd ='Blinka('+Flicker+')';
		TheTimer= setTimeout(cmd,BlinkTime);		
	}
}


function TheFoto(ShowMe) {
document.fotopreview.src = ShowMe;
}

function PopQuote(formname){
	msgWindow=window.open(formname ,'QUOTE','toolbar=0,width=540,height=510,directories=0,status=0,scrollbars=1,resizeable=0,top='+((screen.availHeight - 510) / 2)+',left='+((screen.availWidth - 540) / 2)+',menubar=0')
}

function PopScale(formname){
	msgWindow=window.open(formname ,'SCALE','toolbar=0,width=400,height=500,directories=0,status=0,scrollbars=0,resizeable=0,top='+((screen.availHeight - 500) / 2)+',left='+((screen.availWidth - 400) / 2)+',menubar=0')
}

function PopVideo(formname){
	msgWindow=window.open(formname ,'VIDEO','toolbar=0,width=350,height=330,directories=0,status=0,scrollbars=0,resizeable=0,top='+((screen.availHeight - 330) / 2)+',left='+((screen.availWidth - 350) / 2)+',menubar=0')
}

function PopPart(formname){
	msgWindow=window.open(formname ,'PART','toolbar=0,width=360,height=330,directories=0,status=0,scrollbars=1,resizeable=0,top='+((screen.availHeight - 330) / 2)+',left='+((screen.availWidth - 360) / 2)+',menubar=0')
}


//--------------------------------------------------------------------------------------------------------------------------------------------------------------------//

// FORM STUFF

// COMMON FUNCTIONS 

function ValidatePasswords(){

var TestPass = 1;
var To_Be_Tested1 = document.getElementById('u_passsword1').value;
var To_Be_Tested2 = document.getElementById('u_passsword2').value;

	if (To_Be_Tested1==To_Be_Tested2)
		{
			TestPass = 1;
		}
		else
		{
			TestPass = 0;
		}
		
		if (To_Be_Tested1.length < 6){ TestPass = 0; }
		
		if (TestPass==0)
		{
			document.getElementById('u_passsword2_R').innerHTML = "<SPAN STYLE=\"color:#FF0000\">Confirm.<\/SPAN>";
		}
		else
		{
			document.getElementById('u_passsword2_R').innerHTML = "<SPAN STYLE=\"color:#349234\">Confirm.<\/SPAN>";
		}
		
	return TestPass;

}

function ValidateField(TheField){
	
	var TheTempField = document.getElementById(TheField).value;
	var TheRelativeField = TheField + '_R';
	var FieldIsOk = 1;
	
	if (TheTempField.length == 0)
	{ 
		document.getElementById(TheRelativeField).innerHTML = "<SPAN STYLE=\"color:#FF0000\">.o0o.<\/SPAN>";
		FieldIsOk = 0;
	}
	else
	{
		document.getElementById(TheRelativeField).innerHTML = "<SPAN STYLE=\"color:#349234\">.o0o.<\/SPAN>";
		FieldIsOk = 1;
	}
	
	return FieldIsOk;
	
}

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------


function ValidateQuoteFields(Lang){
	
var TheURL = '';
var TheError = '';
var ConditionsMet = 1;

// $Lang = 1; // 0 - Port, 1 - Eng //

	if (Lang==0){
		TheError = '<font color="#FF0000"><strong>.o0o. ERRO - Faltam Campos Obrigatórios .o0o.</strong></font>';
	}
	else
	{
		TheError = '<font color="#FF0000"><strong>.o0o. ERROR - Fill All Mandatory Fields .o0o.</strong></font>';
	}

	var To_Be_Quoted_Name = document.getElementById('quote_name').value;
	var To_Be_Quoted_Company = document.getElementById('quote_company').value;
	var To_Be_Quoted_Tax = document.getElementById('quote_tax').value;
	var To_Be_Quoted_Address = document.getElementById('quote_address').value;
	var To_Be_Quoted_Postal = document.getElementById('quote_postal').value;	
	var To_Be_Quoted_City = document.getElementById('quote_city').value;
	var To_Be_Quoted_Country = document.getElementById('quote_country').value;
	
	if (To_Be_Quoted_Name.length == 0) { ConditionsMet = 0; }
	if (To_Be_Quoted_Address.length == 0) { ConditionsMet = 0; }
	if (To_Be_Quoted_Postal.length == 0) { ConditionsMet = 0; }
	if ( To_Be_Quoted_City.length == 0) { ConditionsMet = 0; }
	if (To_Be_Quoted_Country.length == 0) { ConditionsMet = 0; }

	if (ConditionsMet == 0){
			document.getElementById('Quote_Error').innerHTML = TheError;
	}
	else
	{
		TheURL = 'functions/quote.php?quote_name=' + To_Be_Quoted_Name + '&quote_company=' + To_Be_Quoted_Company +
		         '&quote_tax=' + To_Be_Quoted_Tax + '&quote_address=' + To_Be_Quoted_Address + '&quote_postal=' + To_Be_Quoted_Postal +
				 '&quote_city=' + To_Be_Quoted_City + '&quote_country=' + To_Be_Quoted_Country;
		PopQuote(TheURL);
	}
	
}


function CheckRegisterForm(Lang){

	var TheResultIs = 0;
	var TheState = 1;
	var PassTest = 0;
	
	if (Lang==0){
		TheError = '<font color="#FF0000"><strong>.o0o. ERRO - Faltam Campos Obrigatórios .o0o.</strong></font>';
	}
	else
	{
		TheError = '<font color="#FF0000"><strong>.o0o. ERROR - Fill All Mandatory Fields .o0o.</strong></font>';
	}
	
	BMandatoryFields = new Array
	BMandatoryFields[1] = 'u_lang';
	BMandatoryFields[2] = 'u_country';
	BMandatoryFields[3] = 'u_username';
	BMandatoryFields[4] = 'u_passsword1';
	BMandatoryFields[5] = 'u_email';
	BMandatoryFields[6] = 'u_name';
	BMandatoryFields[7] = 'u_age';
	BMandatoryFields[8] = 'u_add1';
	BMandatoryFields[9] = 'u_add2';
	BMandatoryFields[10] = 'u_postalcode';
	BMandatoryFields[11] = 'u_city';
	BMandatoryFields[12] = 'u_tel';
	BMandatoryFields[13] = 'u_confirm';
	

	for (var x = 1; x <= 13 ; x++)
	{
   		TheResultIs = ValidateField(BMandatoryFields[x]);
		if (TheResultIs == 0){ TheState=0; }
	}
	
	
	PassTest = ValidatePasswords();
	if ((PassTest==0) && (TheState==1)){
		if (Lang==0){
			TheError = '<font color="#FF0000"><strong>.o0o. ERRO - Password (Confirmação ou Comprimento) .o0o.</strong></font>';
		}
		else
		{
			TheError = '<font color="#FF0000"><strong>.o0o. ERROR - Password (Confirmation or Length) .o0o.</strong></font>';
		}
	}
	
	if (PassTest==0){ TheState=0; }
	
	
	if (TheState==0){ 
		//document.getElementById('RegisterButton').disabled=true;
		document.getElementById('Quote_Error').innerHTML = TheError;
		//document.RegistrationForm.RegisterButton.disabled = true;
		
		document.getElementById('RegButton').disabled = true;
		document.getElementById('RegButton').onclick = 'return false;';
	}
	else
	{
		//document.getElementById('RegisterButton').disabled=false;
		document.getElementById('Quote_Error').innerHTML = '';
		//document.RegistrationForm.RegisterButton.disabled = false;
		
		document.getElementById('RegButton').disabled = false;
		document.getElementById('RegButton').onclick = 'return true;';
	}
	
}



function CheckOrderForm(Lang){
	
	var TheResultIs = 0;
	var TheState = 1;
	var TheError = '';
	
	if (Lang==0){
		TheError = '<font color="#FF0000"><strong>.o0o. ERRO - Faltam Campos Obrigatórios .o0o.</strong></font>';
	}
	else
	{
		TheError = '<font color="#FF0000"><strong>.o0o. ERROR - Blank Mandatory Fields .o0o.</strong></font>';
	}
	
	MandatoryFields = new Array
	MandatoryFields[1] = 'quote_name';
	MandatoryFields[2] = 'quote_address';
	MandatoryFields[3] = 'quote_postal';
	MandatoryFields[4] = 'quote_city';
	MandatoryFields[5] = 'quote_country';
	
	for (var x = 1; x <= 5 ; x++)
	{
   		TheResultIs = ValidateField(MandatoryFields[x]);
		if (TheResultIs == 0){ TheState=0; }
	}
	
	
	if (TheState==0){ 
		//document.getElementById('RegisterButton').disabled=true;
		document.getElementById('Quote_Error').innerHTML = TheError;
	}
	else
	{
		//document.getElementById('RegisterButton').disabled=false;
		document.getElementById('Quote_Error').innerHTML = '';
	}
	
	
}



// ----------------------------------------------------------------------------------------------------------------------------------
// LOGIN

function ValidateLoginFields(Lang){


	var TheResultIs = 0;
	var TheState = 1;
	var TheError = '';


	if (Lang==0){
		TheError = '<font color="#FF0000"><strong>.o0o. ERRO - Faltam Campos Obrigatórios .o0o.</strong></font>';
	}
	else
	{
		TheError = '<font color="#FF0000"><strong>.o0o. ERROR - Blank Mandatory Fields .o0o.</strong></font>';
	}


	MandatoryFields = new Array
	MandatoryFields[1] = 'LoginName';
	MandatoryFields[2] = 'LoginPass';
	
	for (var x = 1; x <= 2 ; x++)
	{
   		TheResultIs = ValidateField(MandatoryFields[x]);
		if (TheResultIs == 0){ TheState=0; }
	}
	
	if (TheState==1){
		var ThePassLength = document.getElementById('LoginPass').value;
		if (ThePassLength.length < 6){ 
			TheState=0;
			if (Lang==0){
				TheError = '<font color="#FF0000"><strong>.o0o. ERRO - Password (Min. 6 chars.) .o0o.</strong></font>';
			}
			else
			{
				TheError = '<font color="#FF0000"><strong>.o0o. ERROR - Password (Min. 6 chars.) .o0o.</strong></font>';
			}
		}
		else
		{
			TheState=1;
		}
	}
	
	if (TheState==0){ 
		//document.getElementById('RegisterButton').disabled=true;
		document.getElementById('Quote_Error').innerHTML = TheError;
		//document.VerifyUserLogin.Login.disabled = true;
		
		// Dont use enable disable button because of firefox
		//document.getElementById('LoginButton').disabled = true;
		//document.getElementById('LoginButton').onclick = 'return false;';
	}
	else
	{
		//document.getElementById('RegisterButton').disabled=false;
		document.getElementById('Quote_Error').innerHTML = '';
		//document.VerifyUserLogin.Login.disabled = false;
		
		// Dont use enable disable button because of firefox
		//document.getElementById('LoginButton').disabled = false;
		//document.getElementById('LoginButton').onclick = 'return true;';
	}
	
}

// ----------------------------------------------------------------------------------------------------------------------------------
// UPDATE TOP PANEL WITH LOGGED USER

function DisplayLoggedUser(TheUser)
{
	document.getElementById('DTugaUser').innerHTML = '.o0{ ' + TheUser + ' }0o.';	
	
	TmNo = TheUser;

	if (TmNo.length == 0)
	{
		document.getElementById('DLogState').innerHTML = 'LOGIN';
		document.getElementById('TopQty').innerHTML = '0';
		document.getElementById('TopTot').innerHTML = '€ 0.00';
	}
	else
	{
		document.getElementById('DLogState').innerHTML = 'LOGOUT';
	}

}

// ----------------------------------------------------------------------------------------------------------------------------------
// UPDATE TOP CART VALUES
function DisplayTopCart(TheQty,TheTotal)
{
	document.getElementById('TopQty').innerHTML = TheQty;	
	document.getElementById('TopTot').innerHTML = TheTotal;		
}



