/**
* @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");

/**
* The following global variables (directly below) are NEEDED to support legacy javascript functions - DO NOT REMOVE! see RT#113376 for more details.
* 1. shown
* 2. hidden
*/

var shown = new Image();
shown.src = "/venda-support/images/bulleton.gif";
var hidden = new Image();
hidden.src = "/venda-support/images/bulletoff.gif";

/**
* 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);
}
	if(document.getElementById(dispElem)){
		document.getElementById(dispElem).innerHTML = stringlist.join('<br>');
	}
};


//This function is  for validating  userextendedfiields on registration and edit profile page. You may edit this to suit your user extended fields.
// frmObj is the  form  object in which the user extended fields reside.
Venda.Ebiz.validateUserExtendedFields = function(frmObj) {
	if(frmObj) {
		/*if ( (frmObj.usxtexample1.checked==false) && (frmObj.usxtexample2.checked==false) && (frmObj.usxtexample3.checked==false))  {	
			alert("Please tick at least one checkbox");
			return false;
		}	*/		
		return true;		
	} 
	return false;
}

// Copy over from general.js to prevent JS error
//order confirmation and order receipt page - split the email address on the RHN if too long
function splitEmailAdd(usemail) {
	var stringlist = new Array();
	while (usemail.length > 30) {
	   stringlist.push( usemail.slice(0,30));
	   usemail=usemail.substr(30);
	}
	if (usemail.length) {
	  stringlist.push(usemail);
	}
	document.write(stringlist.join( '<br>' ));
}

//Round down 'you save' to nearest pound
function recalSavingPrice(sprice){
	var spricerel = parseInt(sprice);
	return spricerel;
}

// Function to addClass selected to last td for css support in basket, order summary, order receipt page
$(document).ready(function(){
	$("table.wizrtable tbody").each(function (){
		$(this).find("tr:last td").addClass("selected");
	});
}); 