/**
* @fileoverview ebiz.js: A module used for client specific functionality
*
* This module defines a single symbol named "Venda.Ebiz"
* all ebiz utility functions are stored as properties of this namespace
* functions that are spacific this site shoudl be added to this file only.
*/

//Declare namespace for ebiz
Venda.namespace("Ebiz");

 /**
 * Split a string so it can be displayed on multiple lines so it does not break display layout - used on order confirmation and order receipt page
 * @param {string} strToSplit string that needs to be split 
 * @param {Integer} rowLen length of row which will hold the string
 * @param {string} displayElem the html container which will display the splitted string
 */
Venda.Ebiz.splitString = function(strToSplit, rowLen, dispElem) {
	var stringlist = new Array();
	while (strToSplit.length > rowLen) {
	   stringlist.push( strToSplit.slice(0,rowLen));
	   strToSplit=strToSplit.substr(rowLen);
	}
	if (strToSplit.length) {
		stringlist.push(strToSplit);
	}
	document.getElementById(dispElem).innerHTML = stringlist.join('<br>');
};

 /**
 * A skeleton function for validating user extened fields - needs to be amended by the build team
 * @param {object} frmObj HTML form containing user extended field elements
 */
Venda.Ebiz.validateUserExtendedFields = function(frmObj) {
	if(frmObj) {				
		return true;		
	} 
	return false;
}


// Set up the image files to be used.
function showImage(theImages){

// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array. Rememeber
// to increment the theImages[x] index!

theImages[0] = '//www.fatface.com/content/ebiz/fatface/resources/images/community/tellus1.png'
theImages[1] = '//www.fatface.com/content/ebiz/fatface/resources/images/community/tellus2.png'
theImages[2] = '//www.fatface.com/content/ebiz/fatface/resources/images/community/tellus3.png'
theImages[3] = '//www.fatface.com/content/ebiz/fatface/resources/images/community/tellus4.png'
theImages[4] = '//www.fatface.com/content/ebiz/fatface/resources/images/community/tellus5.png'

// ======================================
// do not change anything below this line
// ======================================

var j = 0
var p = theImages.length;

var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
document.write('<img src="'+theImages[whichImage]+'" style="border: 0px;">');
}


// Show image on page that use gtl layout
function initImage() {
	i = 1;
	while (true) {

		imageId = 'theimg' + i;
		obj = document.getElementById(imageId);
		if (obj == null) break;
		setOpacity(imageId, 0);
		obj.style.visibility = "visible";
		fadeIn(imageId);
		i++;
	}
}
delay = 15;
function fadeIn(objId) {
	opacity = 1;
	if (document.getElementById) {
		while (opacity <= 100) {
			window.setTimeout("setOpacity('"+objId+"',"+opacity+")", delay);
			opacity += 1;
			delay += 3.5; // set image fade delay
		}
	}
}

function setOpacity(objId, opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		opacity = (opacity == 100)?99.999:opacity;
		// IE/Win
		obj.style.filter = "alpha(opacity:"+opacity+")";
		// Safari<1.2, Konqueror
		obj.style.KHTMLOpacity = opacity/100;
		// Older Mozilla and Firefox
		obj.style.MozOpacity = opacity/100;
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		obj.style.opacity = opacity/100;
	}
}
window.onload = function() {initImage()}
